S2ENGINE HD
1.4.6
Official manual about S2Engine HD editor and programming
|
S2Engine GUI system is based on widgets. A widget is a screen element that can have a text, an image, dimensions and a position.
To Create a widget You must use the function CreateWidget. There are many different types of widget you can create in S2Engine GUI system.
Every widget can have its own script file, you can use script for programming widget behaviour, even if some basic widgets like buttons, progressBars, sliders, can already have their own predefined behaviour.
Widget are organized into hierachies, every widget can comunicate with its subwidgets or its parent widget by messages (see also SendMessageSubWidget, SendMessageParentWidget, SendMessageWidget, SendMessageWidgetHUD). All Widgets can be grayed by setting the flag w_grayed with SetFlags, ResetFlags, SetSubWidgetFlags, ResetSubWidgetFlags functions.
They can also be showed/hided (see ShowWidget) and actived-deactived (see ActiveWidget).
Like Objects, widgets have params that can you can set/get by SetParam, SetSubWidgetParam, GetParam and GetSubWidgetParam functions.
Thw widget is the base element of a GUI. All GUI elements are widgets.
Following are parameters common to al widgets.
pos | the position of the widget respect its parent (if it has no parents the position is in screen coordinates). |
width | width of the widget. |
height | height of the widget. |
name | name of the widget, it is used to recognize the widget from its parent. |
Texture | the filename of picture of the widget, can also be empty. |
Font | the filename of the font. All Fonts are inside Fonts folder and have .ft2 as extension. |
Fontsize | the size of the font characters. |
Fontcolor | the color of the font characters. |
Fontspace | the space, in pixels, between characters |
TextAlign | alignment of the text inside widget. This param has integer values: -1 means text at left, 0 means text at center, 1 means text at right. |
Valign | vertical alignment of the widget respect to its parent (screen if no parents): This param has integer values: -1 means widget at bottom of its parent, 0 means widget at center of its parent, 1 means widget at top of its parent. |
Halign | horizontal alignment of the widget respect to its parent (screen if no parents): This param has integer values: -1 means widget at left of its parent, 0 means widget at center of its parent, 1 means widget at right of its parent. |
Litcolor | color that text has when cursor stays over the widget (used expecially for buttons). It must be specified as a triple of scalar values between 0 and 1. For example grey color is "0.5,0.5,0.5", white is "1,1,1", balck is "0,0,0". |
text | string that contains the text that shall appear on the widget. |
Extended | This is a boolean flag. If true the widget dimensions begin equal to the screen dimensions. |
Script | the filename of the script to assign to the widget. Remember that the script files are inside scripts folder, when specify the script filename, you must write script\ before the filename. |
LitTexture | The filename of the texture the widget has when cursor stays over it |
GrayedTexture | The filename of the texture the widget has when it is grayed. |
Wextended | |
Hextended | |
border | |
borderColor | |
dockTop | |
dockBottom | |
dockRight | |
dockLeft | |
data | |
icon | |
iconSize | |
Lextended | |
WLextended | |
HLextended | |
grayedColor | |
texColor | |
texAlpha | |
fadeSpeed |
For a detailed description of available widget classes see GUI Core Classes
A Container is a widgets that can contain other widgets. We have already said that widgets are organized into hierarchy. In fact the container is the parent of the contained widgets, and these last are the childs of the container widget, if some of the child widgets are container they can have other childs, and so on.... When programming a widget that contains other widgets you must create the subwidgets inside the init() entry point function using the CreateWidget function, and implement the message() entry point function to process messages coming from the subwidgets.
The GUI Script is the script of the game GUI container widget, i.e. The widget that contains all other widget inside the game GUI. GUI main widget can contain the cursor. You can Show/Hide the cursor by calling ShowCursor action. To associate a script to the GUI widget you have to specify its filename into the S2Engine.ini file:
where mainGame.s2 is the filename of the GUI widget script. If you want to test your main script you have to execute the S2Frontend.exe application after setting the S2Engine.ini file. Here is a example of a simple main script that you can use to load a scene level:
the HUD script is the script of the main HUD container widget, i.e. The widget that contains all other widgets inside the HUD gui. HUD main widget can contain the cursor.
You can Show/Hide the cursor by calling ShowCursor action. The HUD main widget, instead, must be created inside the loaded game level using the CreateHUD function. It can be created in one of the object scripts of the level, you could also create an helper object containing exclusively the HUD script. It also could be useful to create HUD script inside the player character script.
There is another main widget, it is the Loading Screen container widget, that contains all the widgets appearing on the loading screen, during the loading level time, it also can be scripted. The loading screen main widget is always associated to the loading.sc2 script. So if you want to modify loading screen behaviour you have to modify that script file. Here is an example of Loading screen script: