From 070b82cf6ee9ff5fc07a288b6603a3b882abe85f Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sat, 6 Jan 2018 21:14:18 -0600 Subject: [PATCH] Add sub-categories to settings --- addons/settings/XEH_preInit.sqf | 7 ++--- addons/settings/fnc_init.sqf | 7 ++--- addons/settings/gui.hpp | 32 +++++++++++++++++++++++ addons/settings/gui_createCategory.sqf | 36 +++++++++++++++++++++++--- 4 files changed, 73 insertions(+), 9 deletions(-) diff --git a/addons/settings/XEH_preInit.sqf b/addons/settings/XEH_preInit.sqf index 179bbcd23..c16f8d323 100644 --- a/addons/settings/XEH_preInit.sqf +++ b/addons/settings/XEH_preInit.sqf @@ -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; diff --git a/addons/settings/fnc_init.sqf b/addons/settings/fnc_init.sqf index bc7801276..2d0562b38 100644 --- a/addons/settings/fnc_init.sqf +++ b/addons/settings/fnc_init.sqf @@ -8,7 +8,7 @@ Parameters: _setting - Unique setting name. Matches resulting variable name _settingType - Type of setting. Can be "CHECKBOX", "EDITBOX", "LIST", "SLIDER" or "COLOR" _title - Display name or display name + tooltip (optional, default: same as setting name) - _category - Category for the settings menu + _category - Category for the settings menu + optional sub-category _valueInfo - Extra properties of the setting depending of _settingType. See examples below _isGlobal - 1: all clients share the same setting, 2: setting can't be overwritten (optional, default: 0) _script - Script to execute when setting is changed. (optional) @@ -53,7 +53,7 @@ params [ ["_setting", "", [""]], ["_settingType", "", [""]], ["_title", [], ["", []]], - ["_category", "", [""]], + ["_categoryArg", "", ["", []]], ["_valueInfo", []], ["_isGlobal", false, [false, 0]], ["_script", {}, [{}]] @@ -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 @@ -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; diff --git a/addons/settings/gui.hpp b/addons/settings/gui.hpp index 082766150..938d039fb 100644 --- a/addons/settings/gui.hpp +++ b/addons/settings/gui.hpp @@ -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); diff --git a/addons/settings/gui_createCategory.sqf b/addons/settings/gui_createCategory.sqf index e9a1bee8f..8526125f5 100644 --- a/addons/settings/gui_createCategory.sqf +++ b/addons/settings/gui_createCategory.sqf @@ -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; }; @@ -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": { @@ -143,4 +173,4 @@ private _lists = _display getVariable QGVAR(lists); }; } forEach ["client", "mission", "server"]; }; -} forEach GVAR(allSettings); +} forEach _categorySettings;