The Desktop can contain information and definitions that are referenced throughout the GUI (and also information that can be referenced outside of the GUI by the game code). Floats are values that are often used in if statements as checks. Definevec4 defines a 4-component value (a color or a size value) and gives it a name that’s easier to reference throughout the GUI. namedEvent defines a set of actions to be performed when the namedEvent is referenced in a script or from the GUI itself.
Finally, the desktop will usually also contain two other scripts: onInit and onESC. Both of these define actions to happen when the GUI is loaded and when it is closed, respectively.
Floats and Definevec4
The syntax for these items are as follows:
float “valuename” “0”
This defines a variable named valuename and sets it to 0.
definevec4 “yellowtext” “1,1,0,1”
This defines a vec4 called “yellowtext” and sets its RGB + Alpha value to 1,1,0,1. This is extremely usefull when used in conjunction with transitions as it allows transitions to reference colors specified as a float rather than hard coded values. If you have a bunch of places you want to transition a color and decide later that you want to change this color, you only have to adjust the desktop float rather than every single place in your onTime animation.
namedEvent
The syntax for this command is identical to all other scripting functions. namedEvents are usually defined after the floats and vec4s in the Desktop using the onNamedEvent function, but they can also be placed in any windowDef in the GUI. When the namedEvent command is used (either by the GUI itself or from code), it the statements in the corresponding onNamedEvent function are executed.
The following is a named event defined in the Desktop that sets a windowDef's backcolor:
onNamedEvent SetBackcolor { set "foo::backcolor" "1,0,0,1" ; }
The following example sends the command to execute that named event when the player selects the windowDef:
windowDef foo2 { rect 0,0,300,300 visible 1 onAction { namedEvent "SetBackcolor" ; } }
The following example does the same thing, but references a named event that is defined in the windowDef named "foo3" and not in the Desktop:
windowDef foo2 { rect 0,0,300,300 visible 1 onAction { namedEvent "foo3::SetBackcolor" ; } }
An Example Desktop Script
Floats, vec4s, namedEvents, and onInit and onESC are defined in the Desktop just as other scripts are for other windowDefs – hit ctrl + Enter to bring up the scripting window and enter them in. The following would be an example Desktop script. Note that the values defined at the top of the Desktop do not end with a semicolon as all other scripting commands do.
definevec4 “yellowtext_on” “1,1,0,1” definevec4 “yellowtext_off” “1,1,0,0.5” float “check1” “0” float “check2” “0” onInit { set “button1::matcolor” “1,1,1,0.5” ; } onESC { set “cmd” “close” ; } onNamedEvent Foo { set “button2::matcolor” “1,0,1,1” ; }
Referencing Vec4s and Floats
Referencing floats defined in the Desktop is very simple. If statements often use floats to choose when to perform other actions:
if (“desktop::check1” == 0) { // performs an action }
Floats can also be changed using the set command:
set “desktop::check1” “1” ;
The syntax for using vec4s is slightly different, but straightforward. The following example uses the “yellowtext_on” and “yellowtext_off” vec4s we defined in our example Desktop script:
transition “button1::forecolor” “$desktop::yellowtext_off” “$desktop::yellowtext_on” “200” ;