Arma: GUI Configuration: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
Line 8: Line 8:


Dialogs are one way to provide custom graphical user interface in your missions and allow interaction with the player aswell as they are able to run [[Code|code]]. They are defined as classes in the [[Description.ext|description.ext]] file.
Dialogs are one way to provide custom graphical user interface in your missions and allow interaction with the player aswell as they are able to run [[Code|code]]. They are defined as classes in the [[Description.ext|description.ext]] file.
'''Notice:''' If you change your description.ext file while the mission is still open in the editor, you will have to restart the editor and load the mission again so the changes actually take effect.
'''Warning:''' If there are syntactic errors in your description.ext file (e.g. incorrect spelling of keywords), then the game will simply crash while processing the file, stating the nature and location of the error that caused it.


Most of these definitions work with numeric constants, which are presented in [[#Constants|the following section]]. For readability purposes you should consider favoring them instead of the actual integers.
Most of these definitions work with numeric constants, which are presented in [[#Constants|the following section]]. For readability purposes you should consider favoring them instead of the actual integers.


'''Notice:''' If you change your description.ext file while the mission is still open in the editor, you will have to restart the editor and load the mission again so the changes actually take effect.
* Positions and dimensions (x, y, w, h) aswell as font sizes are '''relative''' to the screen (and '''not''' pixel values), ranging from 0.0 to 1.0; 0.0 means 0% of the screen width (e.g. the left side of the screen in the context of x or y, or 0% length in the context of width and height). This makes font sizes usually a very small number (~0.02). Keep this in mind.
* Colors are usually defined in the following convention: <tt>{ Red, Green, Blue, Alpha }</tt>, each ranging from 0.0 to 1.0 aswell.
* Sounds are usually defined in the following convention: <tt>{ "file.ogg", volume, <span style="color: #ff0000; font-weight: bold">???</span> }</tt>, whereas volume ranges from 0.0 to 1.0.
 
<!-- I have no idea. Someone please correct the sound convention. -->
 
You can find a complete list of scripting related GUI functions in [[:Category:Command Group: GUI Control]].
 
== Constants ==
 
These are constants generally used to maintain a certain degree of readability. They represent integer values for use with ''type'' and ''style'' properties of controls. You can also define other constants, e.g. the font name.
 
<code><nowiki>// Control types
#define CT_STATIC          0
#define CT_BUTTON          1
#define CT_EDIT            2
#define CT_SLIDER          3
#define CT_COMBO            4
#define CT_LISTBOX          5
#define CT_TOOLBOX          6
#define CT_CHECKBOXES      7
#define CT_PROGRESS        8
#define CT_HTML            9
#define CT_STATIC_SKEW      10
#define CT_ACTIVETEXT      11
#define CT_TREE            12
#define CT_STRUCTURED_TEXT  13
#define CT_CONTEXT_MENU    14
#define CT_CONTROLS_GROUP  15
#define CT_XKEYDESC        40
#define CT_XBUTTON          41
#define CT_XLISTBOX        42
#define CT_XSLIDER          43
#define CT_XCOMBO          44
#define CT_ANIMATED_TEXTURE 45
#define CT_OBJECT          80
#define CT_OBJECT_ZOOM      81
#define CT_OBJECT_CONTAINER 82
#define CT_OBJECT_CONT_ANIM 83
#define CT_LINEBREAK        98
#define CT_USER            99
#define CT_MAP              100
#define CT_MAP_MAIN        101
 
 
// Static styles
#define ST_POS            0x0F
#define ST_HPOS          0x03
#define ST_VPOS          0x0C
#define ST_LEFT          0x00
#define ST_RIGHT          0x01
#define ST_CENTER        0x02
#define ST_DOWN          0x04
#define ST_UP            0x08
#define ST_VCENTER        0x0c


'''Warning:''' If there are syntactic errors in your description.ext file (e.g. incorrect spelling of keywords), then the game will simply crash while processing the file, stating the nature and location of the error that caused it.
#define ST_TYPE          0xF0
#define ST_SINGLE        0
#define ST_MULTI          16
#define ST_TITLE_BAR      32
#define ST_PICTURE        48
#define ST_FRAME          64
#define ST_BACKGROUND    80
#define ST_GROUP_BOX      96
#define ST_GROUP_BOX2    112
#define ST_HUD_BACKGROUND 128
#define ST_TILE_PICTURE  144
#define ST_WITH_RECT      160
#define ST_LINE          176
#define FontM            "TahomaB"</nowiki></code>


== Dialogs ==
== Dialogs ==
Line 54: Line 125:




Example of a dialog that will only display ''Hello world'' in the top right corner of the screen. If you get confused by the ''MyHelloText'' class, just ignore it for the moment until you have read details on the definition of controls  in the following chapter, [[#Controls|Controls]].
Setting the ''idd'' property to a non-negative (i.e. "useful") number is only required if you want to access the dialog itself via the [[findDisplay]] function. Accessing the dialog itself via the ''idd'' property though does not mean that you can implicitely access the controls within the dialog. For that you will have to rely on the control's ''idc'' properties. Hence, in most basic cases you won't need it and -1 should be sufficient.
 
Here's an example of a dialog that will only display ''Hello world'' in the top right corner of the screen. If you get confused by the ''MyHelloText'' class, just ignore it for the moment until you have read details on the definition of controls  in the following chapter, [[#Controls|Controls]].


<code><nowiki>class MyHelloWorldDialog {
<code><nowiki>class MyHelloWorldDialog {
Line 64: Line 137:
class MyHelloText {
class MyHelloText {
type = 0;  // CT_STATIC constant
idc = -1;  // set to -1, unneeded
style = 0;  // ST_LEFT constant
type = CT_STATIC;  // constant
style = ST_LEFT;  // constant
text = "Hello world";
text = "Hello world";
font = "TahomaB";
font = FontM;
sizeEx = 0.023;
sizeEx = 0.023;


Line 89: Line 163:


''A few words about controls, as well as defining one. Crossreference to [[#Best Practice]]. IDCs, usage, etc.''
''A few words about controls, as well as defining one. Crossreference to [[#Best Practice]]. IDCs, usage, etc.''
{| border="1" align="center" cellpadding="3" cellspacing="0" |
! colspan="3" bgcolor="#bbbbff" | Common properties
|-
! bgcolor="#ddddff" | Name
! bgcolor="#ddddff" | Type
! bgcolor="#ddddff" | Remark
|-
| '''idc'''
| integer
| the unique ID number of this control. can be -1 if you don't require access to the control itself from within a script.
|-
| '''type'''
| integer (constant)
| control type [[#Constants|constant]].
|-
| '''style'''
| integer (constant)
| style [[#Constants|constant]].
|-
| '''x'''
| float
| the offset from the left side of the window (0..1; 0.0 = left side; 1.0 = right side)
|-
| '''y'''
| float
| the offset from the top side of the window (0..1; 0.0 = left side; 1.0 = right side)
|-
| '''w'''
| float
| the width of the control (0..1)
|-
| '''h'''
| float
| the height of the control (0..1)
|-
|}


=== Static ===
=== Static ===

Revision as of 16:38, 6 May 2007

Template:Stub

This article is classified as work in progress and is likely to change very often before it will be moved or merged to Dialogs once it has reached a certain degree of maturity.

Feel free to make changes though, even if it currently resides in Manny's personal namespace.

-- Manny 15:49, 6 May 2007 (CEST)

Introduction

Dialogs are one way to provide custom graphical user interface in your missions and allow interaction with the player aswell as they are able to run code. They are defined as classes in the description.ext file.

Notice: If you change your description.ext file while the mission is still open in the editor, you will have to restart the editor and load the mission again so the changes actually take effect.

Warning: If there are syntactic errors in your description.ext file (e.g. incorrect spelling of keywords), then the game will simply crash while processing the file, stating the nature and location of the error that caused it.

Most of these definitions work with numeric constants, which are presented in the following section. For readability purposes you should consider favoring them instead of the actual integers.

  • Positions and dimensions (x, y, w, h) aswell as font sizes are relative to the screen (and not pixel values), ranging from 0.0 to 1.0; 0.0 means 0% of the screen width (e.g. the left side of the screen in the context of x or y, or 0% length in the context of width and height). This makes font sizes usually a very small number (~0.02). Keep this in mind.
  • Colors are usually defined in the following convention: { Red, Green, Blue, Alpha }, each ranging from 0.0 to 1.0 aswell.
  • Sounds are usually defined in the following convention: { "file.ogg", volume, ??? }, whereas volume ranges from 0.0 to 1.0.


You can find a complete list of scripting related GUI functions in Category:Command Group: GUI Control.

Constants

These are constants generally used to maintain a certain degree of readability. They represent integer values for use with type and style properties of controls. You can also define other constants, e.g. the font name.

// Control types #define CT_STATIC 0 #define CT_BUTTON 1 #define CT_EDIT 2 #define CT_SLIDER 3 #define CT_COMBO 4 #define CT_LISTBOX 5 #define CT_TOOLBOX 6 #define CT_CHECKBOXES 7 #define CT_PROGRESS 8 #define CT_HTML 9 #define CT_STATIC_SKEW 10 #define CT_ACTIVETEXT 11 #define CT_TREE 12 #define CT_STRUCTURED_TEXT 13 #define CT_CONTEXT_MENU 14 #define CT_CONTROLS_GROUP 15 #define CT_XKEYDESC 40 #define CT_XBUTTON 41 #define CT_XLISTBOX 42 #define CT_XSLIDER 43 #define CT_XCOMBO 44 #define CT_ANIMATED_TEXTURE 45 #define CT_OBJECT 80 #define CT_OBJECT_ZOOM 81 #define CT_OBJECT_CONTAINER 82 #define CT_OBJECT_CONT_ANIM 83 #define CT_LINEBREAK 98 #define CT_USER 99 #define CT_MAP 100 #define CT_MAP_MAIN 101 // Static styles #define ST_POS 0x0F #define ST_HPOS 0x03 #define ST_VPOS 0x0C #define ST_LEFT 0x00 #define ST_RIGHT 0x01 #define ST_CENTER 0x02 #define ST_DOWN 0x04 #define ST_UP 0x08 #define ST_VCENTER 0x0c #define ST_TYPE 0xF0 #define ST_SINGLE 0 #define ST_MULTI 16 #define ST_TITLE_BAR 32 #define ST_PICTURE 48 #define ST_FRAME 64 #define ST_BACKGROUND 80 #define ST_GROUP_BOX 96 #define ST_GROUP_BOX2 112 #define ST_HUD_BACKGROUND 128 #define ST_TILE_PICTURE 144 #define ST_WITH_RECT 160 #define ST_LINE 176 #define FontM "TahomaB"

Dialogs

Dialogs are parent containers for the actual controls it contains. Their definition contains several properties on the controls it contains, how the dialog can be addressed, and whether or not the player is able to continue regular movement while the dialog is shown.

They can be defined in the description.ext file or externalized to seperate hpp-files, which are included in the description.ext file using the #include preprocessor directive. The latter method is generally a good idea to split a large description.ext file into several small chunks in order to keep track of what's where.

Most often, controls of a dialog are defined within the definition of the dialog itself, though it's a good practice to generalize common controls in a base definition in the global scope. See best practice for details. For simplicity we won't apply this practice in the following code examples.


Properties
Name Type Remark
idd integer the unique ID number of this dialog. can be -1 if you don't require access to the dialog itself from within a script.
movingEnable boolean sets whether or not the player is hindered from aiming or moving while the dialog is open.
controlsBackground array contains class names of all background controls associated to this dialog.
controls array contains class names of all foreground controls associated to this dialog.
objects array


Setting the idd property to a non-negative (i.e. "useful") number is only required if you want to access the dialog itself via the findDisplay function. Accessing the dialog itself via the idd property though does not mean that you can implicitely access the controls within the dialog. For that you will have to rely on the control's idc properties. Hence, in most basic cases you won't need it and -1 should be sufficient.

Here's an example of a dialog that will only display Hello world in the top right corner of the screen. If you get confused by the MyHelloText class, just ignore it for the moment until you have read details on the definition of controls in the following chapter, Controls.

class MyHelloWorldDialog { idd = -1; // set to -1, because we don't require a unique ID movingEnable = false; // no movement while the dialog is shown controlsBackground[] = { }; // no background controls needed objects[] = { }; // no objects needed controls[] = { MyHelloText }; // our Hello World text as seen below: class MyHelloText { idc = -1; // set to -1, unneeded type = CT_STATIC; // constant style = ST_LEFT; // constant text = "Hello world"; font = FontM; sizeEx = 0.023; colorBackground[] = { 1, 1, 1, 0.3 }; colorText[] = { 0, 0, 0, 1 }; x = 0.8; y = 0.1; w = 0.2; h = 0.05; }; };

Once you have defined (or prototyped) dialogs you want to use, be sure to reload the mission in the editor if it is already running.

Dialogs can then be created and shown using the createDialog function. If you do so by script and await a responsive action from the user, you might also want to wait until the user has closed the dialog by using the dialog function, if you intend to handle the dialog result in the same script: _ok = createDialog "MyHelloWorldDialog"; waitUntil { !dialog };

Controls

A few words about controls, as well as defining one. Crossreference to #Best Practice. IDCs, usage, etc.

Common properties
Name Type Remark
idc integer the unique ID number of this control. can be -1 if you don't require access to the control itself from within a script.
type integer (constant) control type constant.
style integer (constant) style constant.
x float the offset from the left side of the window (0..1; 0.0 = left side; 1.0 = right side)
y float the offset from the top side of the window (0..1; 0.0 = left side; 1.0 = right side)
w float the width of the control (0..1)
h float the height of the control (0..1)

Static

Text

Hello world text with semi-transparent background

Solid rectangles

Semi-transparent background

Pictures

Button

Active text

Structured text

Text box

Slider

Combobox

Listbox

Toolbox

Checkbox

Progress bar

Context menu

HTML

Tree

Static skew

Controls group

Animated texture

3D Objects

Map

Best practice

Polymorphism