Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-09-2010, 05:07 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
GOptionPane (Incomplete)

I normally wouldn't release unfinished projects but I know that I won't have time to finish it, so hopefully other scripters looking for something to do will feel like picking up this project and finishing it, since I think it could be valuable for playerworlds to use once finished. With that said, this script, though incomplete, still has some pretty nice points to learn from (such as my sortArrayByArray function and the different conditional statements that I manipulated).

My main goal with this project was to convert as much of the JOptionPane class to GScript as possible, simply because it's fairly easy to create GUIs with Java. A lot of times, with simple message boxes, having to put a bunch of GUI code into a script is not only time-consuming but can make the code look like a mess. What the GOptionPane is intended to do is to allow scripters to create GUIs through flexible commands (I know that there is a GUI editor, but even with the GUI editor, you still have to copy and paste the clutter of code generated by it).

Special Functions

. showMessageDialog(framePos, frameSize, options, message, title) - public function called to create a message dialog box. framePos is the screen position that the GUI will be drawn in; frameSize is the size of the GUI that will be drawn; options are the GUI variable options; message is the message that will be displayed in the GUI box; title is the title of the GUI.

Currently, there is no text control so the message parameter is practically useless. The only thing that this specific function is missing is a text control but that should be fairly easy to add.

Also, framePos {width, height} and frameSize {x, y} should each be sent as an array, for example:

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
join("classNameHere");
  
showMessageDialog({screenwidth/2screenheight/2}, {13090}, nullnull"My GUI");

. sortArrayByArray(arrayToSort, arrayToCompare) - sorts an array (arrayToSort) based on the order of another array (arrayToCompare). Basically, it will order arrayToSort in the same order as arrayToCompare depending on the values contained in arrayToSort. You can use the true boolean in place of a value in the arrayToSort and the function will automatically replace the true boolean with the appropriate value as determined by arrayToCompare. This function works in sorting arrays with integers, but because the integer '1' is considered to be true by the compiler, the function will have trouble sorting arrays that contain the integer '1'. Perhaps someone can make a workaround for this?

About the options Parameter

The variable options are as follows: "canclose", "canmaximize", "canminimize", "closequery", "destroyonhide", "maximized", "minimized", "tile"

If you send null parameters as the options, the system will automatically create a GUI using defaults that I established in the code (I commented where this is set in the code itself).

If you wish to send options, you must do so as an array. You can use boolean values or exact string values, or a mixture of both as such:

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
join("classNameHere");
  
showMessageDialog(nullnull, {"canclose"truefalse"minimized""closequery"}, nullnull);

As you can see, it's rather flexible when it comes to specifying options. You do not need to send an array with 8 values each time that you create a GUI, any option values that you do not send will automatically be set to false.

Code

PHP Code:
/*
 *GOptionPane
 *@author Gambet
*/

//#CLIENTSIDE
public function showMessageDialog(framePosframeSizeoptionsmessagetitle) {
  
/*For frameOptions and variableOptions: The second parameter is the default parameter that the system
                                          will use if the user leaves the options parameter empty (null)
  */                                      
  
temp.frameOptions    = {
                          {
"x"screenwidth/3framePos[0]}, {"y"screenheight/2framePos[1]}, {"width"160frameSize[0]}, 
                          {
"height"80frameSize[1]}, {"text""Message"title}
                         };                         
                       
  
temp.variableOptions = {
                          {
"canclose"true}, {"canmaximize"true}, {"canminimize"true}, 
                          {
"closequery"true}, {"destroyonhide"false}, {"maximized"false}, 
                          {
"minimized"false}, {"tile"false}
                         };
                          
  
temp.allowedOptions  = {"canclose""canmaximize""canminimize""closequery""destroyonhide",
                          
"maximized""minimized""tile"};
  
  
//Create GUI object
  
new GuiWindowCtrl("MessageDialog_Window") {
    
profile GuiBlueWindowProfile;
  } 
 
  
//Fill-in empty options parameters with false value and sort array
  
if (options != NULL) {
    while(
options.size() < 8) {
      
options.add(false);
    }
    
//Sort options array
    
options sortArrayByArray(optionsallowedOptions); 
  }  

  for (
temp.0temp.8temp.i++) {
    if (
5) {
      
MessageDialog_Window.(@frameOptions[i][0]) = (frameOptions[i][2] != "") ? frameOptions[i][2] : frameOptions[i][1];
    }
    
MessageDialog_Window.(@variableOptions[i][0]) = (options != "") ? 
                         ((
variableOptions[i][0] == options[i]) ? true options[i]) : variableOptions[i][1];
  }
}

//Sorts an array based on the order of another array.
//If one of the values of the array to sort is true,
//then the function will automatically convert the
//true boolean to the proper value.
function sortArrayByArray(arrayToSortarrayToCompare) {
  
temp.sortedArray = new[arrayToCompare.size()]; 
     
  for (
temp.0temp.arrayToCompare.size(); temp.i++) {
    if (
arrayToSort[i] == truearrayToSort[i] = arrayToCompare[i];
    
sortedArray[arrayToCompare.index(arrayToSort[i])] = arrayToSort[i];
    
arrayToSort[i] = "";
  }
    
  return 
sortedArray;
}

function 
MessageDialog_Window.onCloseQuery() {
  
MessageDialog_Window.destroy();

Reply With Quote
  #2  
Old 05-09-2010, 06:01 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Tried editing my last post but my browser kept freezing on me; just wanted to add that this will be my last release. I would actually be surprised to see the PC version of this game lasting another 5-10 years (assuming that we don't all die in 2012 ) since the focus of this game has clearly shifted to a different platform.

This project that I started will more than likely never be touched by anyone again, and that's perfectly fine since there isn't enough development happening at this point that would make this totally convenient (and the GDT probably have better things to do), but hopefully the sorting function proves useful to someone (though that '1' integer problem still needs a workaround).

Last edited by Gambet; 05-09-2010 at 06:38 AM..
Reply With Quote
  #3  
Old 05-09-2010, 07:13 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Sad to see another developer leave.

Thanks for the release.
Reply With Quote
  #4  
Old 05-09-2010, 11:24 AM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Quote:
Originally Posted by Gambet View Post
. showMessageDialog(framePos, frameSize, options, message, title) - public function called to create a message dialog box. framePos is the screen position that the GUI will be drawn in; frameSize is the size of the GUI that will be drawn; options are the GUI variable options; message is the message that will be displayed in the GUI box; title is the title of the GUI.
I think it should guess a good position and size.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:03 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.