-
Notifications
You must be signed in to change notification settings - Fork 149
/
gui_createCategory.sqf
224 lines (182 loc) · 9 KB
/
gui_createCategory.sqf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// inline function, don't include script_component.hpp
private _fnc_controlSetTablePosY = {
params ["_control", "_tablePosY", "_height"];
private _config = configFile >> ctrlClassName _control;
private _posX = getNumber (_config >> "x");
private _posY = getNumber (_config >> "y") + _tablePosY;
private _width = getNumber (_config >> "w");
if (isNil "_height") then {
_height = getNumber (_config >> "h");
};
_control ctrlSetPosition [_posX, _posY, _width, _height];
_control ctrlCommit 0;
_posY + _height
};
private _lists = _display getVariable QGVAR(lists);
private _categorySettings = [];
{
(GVAR(default) getVariable _x) params ["", "_setting", "", "", "_category", "", "", "", "", "_subCategory"];
if (_category == _selectedAddon) then {
if (isLocalized _subCategory) then {
_subCategory = localize _subCategory;
};
_categorySettings pushBack [_subCategory, _forEachIndex, _setting];
};
} forEach GVAR(allSettings);
_categorySettings sort true;
private _lastSubCategory = "$START";
{
_x params ["_subCategory", "", "_setting"];
private _createHeader = false;
if (_subCategory != _lastSubCategory) then {
_lastSubCategory = _subCategory;
if (_subCategory == "") exitWith {};
_createHeader = true;
};
(GVAR(default) getVariable _setting) params ["_defaultValue", "", "_settingType", "_settingData", "_category", "_displayName", "_tooltip", "_isGlobal"];
if (isLocalized _displayName) then {
_displayName = localize _displayName;
};
if (isLocalized _tooltip) then {
_tooltip = localize _tooltip;
};
if (_tooltip != _setting) then { // Append setting name to bottom line
if (_tooltip isEqualTo "") then {
_tooltip = _setting;
} else {
_tooltip = format ["%1\n%2", _tooltip, _setting];
};
};
private _settingControlsGroups = [];
{
private _source = toLower _x;
private _currentValue = GET_TEMP_NAMESPACE_VALUE(_setting,_source);
private _wasEdited = false;
if (isNil "_currentValue") then {
_currentValue = [_setting, _source] call FUNC(get);
} else {
_wasEdited = true;
};
private _currentPriority = GET_TEMP_NAMESPACE_PRIORITY(_setting,_source);
if (isNil "_currentPriority") then {
_currentPriority = [_setting, _source] call FUNC(priority);
} else {
_wasEdited = true;
};
// ----- create or retrieve options "list" controls group
private _list = [QGVAR(list), _category, _source] joinString "$";
private _ctrlOptionsGroup = controlNull;
if !(_list in _lists) then {
_ctrlOptionsGroup = _display ctrlCreate [QGVAR(OptionsGroup), -1, _display displayCtrl IDC_ADDONS_GROUP];
_ctrlOptionsGroup ctrlEnable false;
_ctrlOptionsGroup ctrlShow false;
_lists pushBack _list;
_display setVariable [_list, _ctrlOptionsGroup];
} else {
_ctrlOptionsGroup = _display getVariable _list;
};
// Add sub-category header
if (_createHeader) then {
private _ctrlHeaderGroup = _display ctrlCreate [QGVAR(subCat), -1, _ctrlOptionsGroup];
private _ctrlHeaderName = _ctrlHeaderGroup controlsGroupCtrl IDC_SETTING_NAME;
_ctrlHeaderName ctrlSetText format ["%1:", _subCategory];
private _tablePosY = (_ctrlOptionsGroup getVariable [QGVAR(tablePosY), TABLE_LINE_SPACING/2]);
_tablePosY = [_ctrlHeaderGroup, _tablePosY] call _fnc_controlSetTablePosY;
_ctrlOptionsGroup setVariable [QGVAR(tablePosY), _tablePosY];
};
// ----- create setting group
private _ctrlSettingGroup = switch (toUpper _settingType) do {
case "CHECKBOX": {
_display ctrlCreate [QGVAR(Row_Checkbox), IDC_SETTING_CONTROLS_GROUP, _ctrlOptionsGroup]
};
case "EDITBOX": {
_display ctrlCreate [QGVAR(Row_Editbox), IDC_SETTING_CONTROLS_GROUP, _ctrlOptionsGroup]
};
case "LIST": {
_display ctrlCreate [QGVAR(Row_List), IDC_SETTING_CONTROLS_GROUP, _ctrlOptionsGroup]
};
case "SLIDER": {
_display ctrlCreate [QGVAR(Row_Slider), IDC_SETTING_CONTROLS_GROUP, _ctrlOptionsGroup]
};
case "COLOR": {
_display ctrlCreate [[QGVAR(Row_Color), QGVAR(Row_ColorAlpha)] select (count _defaultValue > 3), IDC_SETTING_CONTROLS_GROUP, _ctrlOptionsGroup]
};
case "TIME": {
_display ctrlCreate [QGVAR(Row_Time), IDC_SETTING_CONTROLS_GROUP, _ctrlOptionsGroup]
};
default {controlNull};
};
// ----- determine display string for default value
private _defaultValueToolTip = switch (toUpper _settingType) do {
case "LIST": {
private _label = (_settingData param [1, []]) param [_defaultValue, ""];
if (isLocalized _label) then {
_label = localize _label;
};
_label
};
case "SLIDER": {
if (_settingData param [3, false]) then {
format [localize "STR_3DEN_percentageUnit", round (_defaultValue * 100), "%"]
} else {
_defaultValue
};
};
case "COLOR": {
private _template = (["R: %1","%G: %2", "B: %3", "A: %4"] select [0, count _defaultValue]) joinString "\n";
format ([_template] + _defaultValue)
};
case "TIME": {
_defaultValue call CBA_fnc_formatElapsedTime
};
default {_defaultValue};
};
// ----- set tooltip on "Reset to default" button
private _ctrlDefault = _ctrlSettingGroup controlsGroupCtrl IDC_SETTING_DEFAULT;
_ctrlDefault ctrlSetTooltip (format ["%1\n%2", localize LSTRING(default_tooltip), _defaultValueToolTip]);
_ctrlSettingGroup setVariable [QGVAR(setting), _setting];
_ctrlSettingGroup setVariable [QGVAR(source), _source];
_ctrlSettingGroup setVariable [QGVAR(params), _settingData];
_ctrlSettingGroup setVariable [QGVAR(groups), _settingControlsGroups];
_settingControlsGroups pushBack _ctrlSettingGroup;
// ----- adjust y position in table
private _tablePosY = _ctrlOptionsGroup getVariable [QGVAR(tablePosY), TABLE_LINE_SPACING/2];
_tablePosY = [_ctrlSettingGroup, _tablePosY] call _fnc_controlSetTablePosY;
_ctrlOptionsGroup setVariable [QGVAR(tablePosY), _tablePosY];
// ----- padding to make listboxes work
if (_settingType == "LIST") then {
private _ctrlEmpty = _display ctrlCreate [QGVAR(Row_Empty), -1, _ctrlOptionsGroup];
private _height = POS_H(count (_settingData select 0)) + TABLE_LINE_SPACING;
[_ctrlEmpty, _tablePosY, _height] call _fnc_controlSetTablePosY;
};
// ----- set setting name
private _ctrlSettingName = _ctrlSettingGroup controlsGroupCtrl IDC_SETTING_NAME;
_ctrlSettingName ctrlSetText format ["%1:", _displayName];
_ctrlSettingName ctrlSetTooltip _tooltip;
// change color if setting was edited
if (_wasEdited) then {
_ctrlSettingName ctrlSetTextColor COLOR_TEXT_ENABLED_WAS_EDITED;
};
// ----- execute setting script
private _script = getText (configFile >> ctrlClassName _ctrlSettingGroup >> QGVAR(script));
[_ctrlSettingGroup, _setting, _source, _currentValue, _settingData] call (uiNamespace getVariable _script);
// ----- default button
[_ctrlSettingGroup, _setting, _source, _currentValue, _defaultValue] call FUNC(gui_settingDefault);
// ----- priority list
[_ctrlSettingGroup, _setting, _source, _currentPriority, _isGlobal] call FUNC(gui_settingOverwrite);
// ----- check if setting can be altered
private _enabled = switch (_source) do {
case "client": {CAN_SET_CLIENT_SETTINGS && {isNil {GVAR(userconfig) getVariable _setting}}};
case "mission": {CAN_SET_MISSION_SETTINGS && {isNil {GVAR(missionConfig) getVariable _setting}}};
case "server": {CAN_SET_SERVER_SETTINGS && {isNil {GVAR(serverConfig) getVariable _setting}}};
};
if !(_enabled) then {
_ctrlSettingName ctrlSetTextColor COLOR_TEXT_DISABLED;
//private _ctrlSettingGroupControls = allControls ctrlParent _ctrlSettingGroup select {ctrlParentControlsGroup _x == _ctrlSettingGroup};
private _ctrlSettingGroupControls = "true" configClasses (configFile >> ctrlClassName _ctrlSettingGroup >> "controls") apply {_ctrlSettingGroup controlsGroupCtrl getNumber (_x >> "idc")};
{
_x ctrlEnable false;
} forEach _ctrlSettingGroupControls;
};
} forEach ["client", "mission", "server"];
} forEach _categorySettings;