Skip to content

Commit

Permalink
Add sub-categories to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
PabstMirror committed Jan 7, 2018
1 parent 092a7f2 commit 070b82c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
7 changes: 4 additions & 3 deletions addons/settings/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ ADDON = false;
["Test_Padding", "LIST", "Padding test", "My Category", [[0,1,2,3,4,5,6,7,8,9,10], []]] call cba_settings_fnc_init;

["Test_1", "EDITBOX", "setting 1", "Test Category", "null", nil, {systemChat str [1, _this]}] call cba_settings_fnc_init;
["Test_2", "EDITBOX", "setting 2", "Test Category", "null", nil, {systemChat str [2, _this]}] call cba_settings_fnc_init;
["Test_2", "EDITBOX", "setting 2", ["Test Category", "Evens"], "null", nil, {systemChat str [2, _this]}] call cba_settings_fnc_init;
["Test_3", "EDITBOX", "setting 3", "Test Category", "null", nil, {systemChat str [3, _this]}] call cba_settings_fnc_init;
["Test_4", "EDITBOX", "setting 4", "Test Category", "null", nil, {systemChat str [4, _this]}] call cba_settings_fnc_init;
["Test_4", "EDITBOX", "setting 4", ["Test Category", "Evens"], "null", nil, {systemChat str [4, _this]}] call cba_settings_fnc_init;
["Test_5", "EDITBOX", "setting 5", "Test Category", "null", 1, {systemChat str [5, _this]}] call cba_settings_fnc_init;
["Test_6", "EDITBOX", "setting 6", "Test Category", "null", 2, {systemChat str [6, _this]}] call cba_settings_fnc_init;
["Test_6", "EDITBOX", "setting 6", ["Test Category", "Evens"], "null", 2, {systemChat str [6, _this]}] call cba_settings_fnc_init;
["Test_6", "EDITBOX", "setting 7", ["Test Category", "Seven"], "null", 2, {systemChat str [7, _this]}] call cba_settings_fnc_init;

["Test_A", "EDITBOX", "setting 1", "Test Category 1", "a", nil, {systemChat str [1, _this]}] call cba_settings_fnc_init;
["Test_B", "EDITBOX", "setting 2", "Test Category 1", "b", nil, {systemChat str [2, _this]}] call cba_settings_fnc_init;
Expand Down
7 changes: 4 additions & 3 deletions addons/settings/fnc_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Parameters:
_setting - Unique setting name. Matches resulting variable name <STRING>
_settingType - Type of setting. Can be "CHECKBOX", "EDITBOX", "LIST", "SLIDER" or "COLOR" <STRING>
_title - Display name or display name + tooltip (optional, default: same as setting name) <STRING, ARRAY>
_category - Category for the settings menu <STRING>
_category - Category for the settings menu + optional sub-category <STRING, ARRAY>
_valueInfo - Extra properties of the setting depending of _settingType. See examples below <ANY>
_isGlobal - 1: all clients share the same setting, 2: setting can't be overwritten (optional, default: 0) <ARRAY>
_script - Script to execute when setting is changed. (optional) <CODE>
Expand Down Expand Up @@ -53,7 +53,7 @@ params [
["_setting", "", [""]],
["_settingType", "", [""]],
["_title", [], ["", []]],
["_category", "", [""]],
["_categoryArg", "", ["", []]],
["_valueInfo", []],
["_isGlobal", false, [false, 0]],
["_script", {}, [{}]]
Expand All @@ -64,6 +64,7 @@ if (_setting isEqualTo "") exitWith {
1
};

_categoryArg params [["_category", "", [""]], ["_subCategory", "", [""]]];
if (_category isEqualTo "") exitWith {
WARNING_1("Empty menu category for setting %1",_setting);
1
Expand Down Expand Up @@ -148,7 +149,7 @@ if (isNil {GVAR(default) getVariable _setting}) then {
GVAR(allSettings) pushBack _setting;
};

GVAR(default) setVariable [_setting, [_defaultValue, _setting, _settingType, _settingData, _category, _displayName, _tooltip, _isGlobal, _script]];
GVAR(default) setVariable [_setting, [_defaultValue, _setting, _settingType, _settingData, _category, _displayName, _tooltip, _isGlobal, _script, _subCategory]];

// --- read previous setting values from profile
private _settingInfo = GVAR(userconfig) getVariable _setting;
Expand Down
32 changes: 32 additions & 0 deletions addons/settings/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,38 @@ class GVAR(Row_Empty): RscText {
h = POS_H(0);
};

class GVAR(subCat): RscControlsGroupNoScrollbars {
x = POS_W(1);
y = POS_H(0);
w = POS_W(37);
h = POS_H(0.75);
class controls {
class Background: RscText {
colorBackground[] = {0.25,0.25,0.25,0.4};
x = POS_W(0);
y = POS_H(0);
w = POS_W(36);
h = POS_H(1);
};
class Name: RscText {
idc = IDC_SETTING_NAME;
style = ST_LEFT;
SizeEx = POS_H(0.75);
x = POS_W(0);
y = POS_H(0);
w = POS_W(15.5);
h = POS_H(0.75);
};
class Bar: RscText {
colorBackground[] = {1,1,1,1};
style = ST_LEFT;
x = POS_W(0);
y = POS_H(0.75) - 2 * pixelH;
w = POS_W(36);
h = pixelH;
};
};
};
class GVAR(Row_Base): RscControlsGroupNoScrollbars {
GVAR(script) = "";
x = POS_W(1);
Expand Down
36 changes: 33 additions & 3 deletions addons/settings/gui_createCategory.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,30 @@ private _fnc_controlSetTablePosY = {

private _lists = _display getVariable QGVAR(lists);

{
(GVAR(default) getVariable _x) params ["_defaultValue", "_setting", "_settingType", "_settingData", "_category", "_displayName", "_tooltip", "_isGlobal"];
private _categorySettings = [];

{
(GVAR(default) getVariable _x) params ["", "_setting", "", "", "_category", "", "", "", "", "_subCategory"];
if (_category == _selectedAddon) then {
_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 (true) then { // remove
if (isLocalized _displayName) then {
_displayName = localize _displayName;
};
Expand Down Expand Up @@ -71,6 +91,16 @@ private _lists = _display getVariable QGVAR(lists);
_ctrlOptionsGroup = _display getVariable _list;
};

// Add sub-category header:
if (_createHeader) then {
private _header = _display ctrlCreate [QGVAR(subCat), -1, _ctrlOptionsGroup];
(_header controlsGroupCtrl IDC_SETTING_NAME) ctrlSetText format ["%1:", _subCategory];

private _tablePosY = (_ctrlOptionsGroup getVariable [QGVAR(tablePosY), TABLE_LINE_SPACING/2]);
_tablePosY = [_header, _tablePosY] call _fnc_controlSetTablePosY;
_ctrlOptionsGroup setVariable [QGVAR(tablePosY), _tablePosY];
};

// ----- create setting group
private _ctrlSettingGroup = switch (toUpper _settingType) do {
case "CHECKBOX": {
Expand Down Expand Up @@ -143,4 +173,4 @@ private _lists = _display getVariable QGVAR(lists);
};
} forEach ["client", "mission", "server"];
};
} forEach GVAR(allSettings);
} forEach _categorySettings;

0 comments on commit 070b82c

Please sign in to comment.