Skip to content

Instructions

Sceptre edited this page Jun 18, 2019 · 2 revisions

To create a custom dialog, use the CDS_fnc_createDialog function in a scheduled enviroment with the supported parameters of your choosing. The function requires 2 primary parameters, with further sub-parameters to define each control:

Index Variable Description Necessity Acceptable Data Types
0 _title Dialog title Required STRING
1 _controls Array of control arrays Required ARRAY

For each type of control, you will need to use the subsequent parameters to define a control array. A control array consists of the following:

Index Variable Description Necessity Acceptable Data Types
0 _ctrlType Type of control Required STRING
1 _ctrlText Control text / description. Use array format to add tooltip Required STRING,ARRAY
2 _ctrlValues Usable values (slider & combobox only, use [] for other controls) Required* ARRAY
3 _ctrlDefault Default value / control selection Required* BOOL,SCALAR,STRING
4 _useDefault Use supplied default (false to use a cached value) Optional BOOL
5 _ctrlCondition Show / enable condition Optional CODE
6 _ctrlModFunction Modifier function (special variable: _this = control's current value) Optional CODE
7 _ctrlArgs Arguments that may be used in _ctrlCondition and ctrlModFunction as _this # 1 Optional ANY

There are currently 4 supported control types:

  • "CHECKBOX"
  • "EDITBOX"
  • "SLIDER"
  • "COMBOBOX"

Checkboxes & Editboxes

For a "CHECKBOX", leave the _ctrlValues parameter as an empty array [], then define the default boolean value.

For a "EDITBOX", leave the _ctrlValues parameter as an empty array [], then use an empty string "" or a custom string as the default value.

Sliders

For a "SLIDER", use the _ctrlValues parameter to define the range and allowed decimals of the slider (max decimals: 5). Use an array with the following values: [_min,_max,_decimalsAllowed]

Example:

["Slider Dialog",[
    ["SLIDER","My slider",[0,10,1],5] // Range min is 0, max is 10. Decimals allowed is 1.
]] call CDS_fnc_createDialog;

Combobox

For a "COMBOBOX", use the _ctrlValues parameter to define the list items in the menu. Simply define the array with strings (["A","B","C"]), then define which list item should be selected by default (using a zero-based index).

Example:

["Combobox Dialog",[
    ["COMBOBOX","Faction combobox",["NATO","CSAT","AAF"],0] // Default of 0 will pick the 1st option.
]] call CDS_fnc_createDialog;

Using the information

When the dialog is closed with the OK button, the CDS_fnc_createDialog function will return an array with the selected values from every control. If the dialog is cancelled, the function will return an empty array [].

Control Type What's Returned Data Type
"CHECKBOX" Returns true if checked, false otherwise BOOLEAN
"EDITBOX" Returns the entered text STRING
"SLIDER" Returns the slider position value SCALAR
"COMBOBOX" Returns what was selected as a zero-based index of the supplied values array SCALAR

Below is an example of a standard usage of the function, utilizing returned values. Please note how we check if the dialog is cancelled to stop the script. Try this out in the debug console.

[] spawn {
    // Create a dialog
    private _dialogValues = ["My Custom Dialog",[
        ["CHECKBOX","Checkbox Control",[],true],
        ["EDITBOX","Editbox Control",[],"123"],
        ["SLIDER","Slider Control",[0,10,1],2.5],
        ["COMBOBOX","Combobox Control",["Option 1","Option 2","Option 3"],0]
    ]] call CDS_fnc_createDialog;

    // Check if the dialog was cancelled
    if (_dialogValues isEqualTo []) exitWith {};

    // Create a hint displaying what we picked in the dialog
    _dialogValues params ["_checkboxValue","_editboxText","_sliderNumber","_comboSelection"];
    hint parseText format ["
        Checkbox Result: %1<br />
        Editbox Result: %2<br />
        Slider Result: %3<br />
        Combobox Result: %4
    ",_checkboxValue,_editboxText,_sliderNumber,_comboSelection];
};

Example01

Advanced functionality

There are a couple more advanced features you can use to add more utlility to the controls. For a full example showing all the functionality, please see example.sqf.

Value caching

The _useDefault parameter is true by default. This will force the default value you set when the dialog opens. If you set this to false, the default control value will use the last cached value used. The cached value is overwritten whenever a dialog containing the same control is closed successfully (by pressing OK).

Control disabling

With the _ctrlCondition parameter, the condition evaluating in the code determines if the control will be grayed out/disabled or not. Default arguments passed to the code are:

0: Current control value
1: Custom arguments set with the _ctrlArgs parameter

Modifier function

With the _ctrlModFunction parameter, you can set code that is executed whenever the control's value is modified. Default arguments passed to the code are:

0: Current control value
1: Custom arguments set with the _ctrlArgs parameter

This can allow you to change other control data with the following additional functions:

CDS_fnc_setCtrlText

Sets the text/description of a control.
Parameters:
0: Control index <SCALAR>
1: New text/description <STRING,ARRAY>
CDS_fnc_setCtrlValues

Sets the new selected/default value and the available values of a control.
Parameters:
0: Control index <SCALAR>
1: New selected/default value <BOOL,SCALAR,STRING>
2: New values <ARRAY>
CDS_fnc_setCtrlCondition

Sets the condition to enable the use of a control.
Parameters:
0: Control index <SCALAR>
1: New condition <CODE>
CDS_fnc_setCtrlModFunction

Sets the modifier function of a control that executes when the value of it has changed.
Parameters:
0: Control index <SCALAR>
1: New modifier function <CODE>
Clone this wiki locally
You can’t perform that action at this time.