From ca3b77e2a53591a1a739f432408c3e1e0641c1c9 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Sun, 27 Aug 2017 21:18:01 +0100 Subject: [PATCH 1/2] Initial attempt to create settings per-category I totally floundered my way through adjusting the code here, but the settings menu does seem to succesfully load into an initial category and it's quick to load on the ace settings conversion branch. Side effect is that there are a load of duplicate categories listed now. --- addons/settings/fnc_gui_addonChanged.sqf | 2 + .../settings/fnc_initDisplayGameOptions.sqf | 11 +- addons/settings/gui_createCategory.sqf | 124 +++++++++++++++++ addons/settings/gui_createMenu.sqf | 125 ------------------ 4 files changed, 131 insertions(+), 131 deletions(-) create mode 100644 addons/settings/gui_createCategory.sqf delete mode 100644 addons/settings/gui_createMenu.sqf diff --git a/addons/settings/fnc_gui_addonChanged.sqf b/addons/settings/fnc_gui_addonChanged.sqf index 3525fe836..ce74d4ec8 100644 --- a/addons/settings/fnc_gui_addonChanged.sqf +++ b/addons/settings/fnc_gui_addonChanged.sqf @@ -8,6 +8,8 @@ private _display = ctrlParent _control; private _selectedAddon = _display getVariable (_control lbData _index); +#include "gui_createCategory.sqf" + if (_selectedAddon isEqualType "") then { uiNamespace setVariable [QGVAR(addon), _selectedAddon]; }; diff --git a/addons/settings/fnc_initDisplayGameOptions.sqf b/addons/settings/fnc_initDisplayGameOptions.sqf index 60bcafe9d..241233fe2 100644 --- a/addons/settings/fnc_initDisplayGameOptions.sqf +++ b/addons/settings/fnc_initDisplayGameOptions.sqf @@ -46,18 +46,17 @@ private _ctrlAddonList = _display ctrlCreate [QGVAR(AddonsList), -1, _ctrlAddons _ctrlAddonList ctrlAddEventHandler ["LBSelChanged", {_this call FUNC(gui_addonChanged)}]; -private _categories = []; - -// ----- create settings lists -#include "gui_createMenu.sqf" +// ----- Add lists +_display setVariable [QGVAR(lists),[]]; // ----- fill addons list { - private _category = _x; + (GVAR(default) getVariable _x) params ["", "", "", "", "_category"]; + private _index = _ctrlAddonList lbAdd _category; _ctrlAddonList lbSetData [_index, str _index]; _display setVariable [str _index, _category]; -} forEach _categories; +} forEach GVAR(allSettings); lbSort _ctrlAddonList; _ctrlAddonList lbSetCurSel (uiNamespace getVariable [QGVAR(addonIndex), 0]); diff --git a/addons/settings/gui_createCategory.sqf b/addons/settings/gui_createCategory.sqf new file mode 100644 index 000000000..2bfe43cf6 --- /dev/null +++ b/addons/settings/gui_createCategory.sqf @@ -0,0 +1,124 @@ +// inline function, don't include script_component.hpp + +private _fnc_controlSetTablePosY = { + params ["_control", "_tablePosY"]; + + private _config = configFile >> ctrlClassName _control; + + private _posX = getNumber (_config >> "x"); + private _posY = getNumber (_config >> "y") + _tablePosY; + private _posH = getNumber (_config >> "h"); + + _control ctrlSetPosition [_posX, _posY]; + _control ctrlCommit 0; + + _posY + _posH +}; + +private _lists = _display getVariable QGVAR(lists); + +{ + (GVAR(default) getVariable _x) params ["_defaultValue", "_setting", "_settingType", "_settingData", "_category", "_displayName", "_tooltip", "_isGlobal"]; + + if (_category == _selectedAddon) then { + if (isLocalized _category) then { + _category = localize _category; + }; + + if (isLocalized _displayName) then { + _displayName = localize _displayName; + }; + + if (isLocalized _tooltip) then { + _tooltip = localize _tooltip; + }; + + private _settingControlsGroups = []; + + { + private _source = toLower _x; + private _currentValue = [_setting, _source] call FUNC(get); + private _currentPriority = [_setting, _source] call FUNC(priority); + + // ----- 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; + }; + + // ----- 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] + }; + default {controlNull}; + }; + + _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]; + + // ----- set setting name + private _ctrlSettingName = _ctrlSettingGroup controlsGroupCtrl IDC_SETTING_NAME; + _ctrlSettingName ctrlSetText format ["%1:", _displayName]; + _ctrlSettingName ctrlSetTooltip _tooltip; + + // ----- 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 GVAR(allSettings); diff --git a/addons/settings/gui_createMenu.sqf b/addons/settings/gui_createMenu.sqf deleted file mode 100644 index fea682068..000000000 --- a/addons/settings/gui_createMenu.sqf +++ /dev/null @@ -1,125 +0,0 @@ -// inline function, don't include script_component.hpp - -private _fnc_controlSetTablePosY = { - params ["_control", "_tablePosY"]; - - private _config = configFile >> ctrlClassName _control; - - private _posX = getNumber (_config >> "x"); - private _posY = getNumber (_config >> "y") + _tablePosY; - private _posH = getNumber (_config >> "h"); - - _control ctrlSetPosition [_posX, _posY]; - _control ctrlCommit 0; - - _posY + _posH -}; - -private _lists = []; -_display setVariable [QGVAR(lists), _lists]; - -{ - (GVAR(default) getVariable _x) params ["_defaultValue", "_setting", "_settingType", "_settingData", "_category", "_displayName", "_tooltip", "_isGlobal"]; - - if (isLocalized _category) then { - _category = localize _category; - }; - - if (isLocalized _displayName) then { - _displayName = localize _displayName; - }; - - if (isLocalized _tooltip) then { - _tooltip = localize _tooltip; - }; - - _categories pushBackUnique _category; - - private _settingControlsGroups = []; - - { - private _source = toLower _x; - private _currentValue = [_setting, _source] call FUNC(get); - private _currentPriority = [_setting, _source] call FUNC(priority); - - // ----- 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; - }; - - // ----- 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] - }; - default {controlNull}; - }; - - _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]; - - // ----- set setting name - private _ctrlSettingName = _ctrlSettingGroup controlsGroupCtrl IDC_SETTING_NAME; - _ctrlSettingName ctrlSetText format ["%1:", _displayName]; - _ctrlSettingName ctrlSetTooltip _tooltip; - - // ----- 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 GVAR(allSettings); From 3bb5f3fd8d072d70a904d2e695a16c94b69fe3e6 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Mon, 28 Aug 2017 19:45:53 +0100 Subject: [PATCH 2/2] Fix duplicate setting categories and controls --- addons/settings/fnc_gui_addonChanged.sqf | 7 +++++-- addons/settings/fnc_initDisplayGameOptions.sqf | 11 ++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/settings/fnc_gui_addonChanged.sqf b/addons/settings/fnc_gui_addonChanged.sqf index ce74d4ec8..378511049 100644 --- a/addons/settings/fnc_gui_addonChanged.sqf +++ b/addons/settings/fnc_gui_addonChanged.sqf @@ -8,8 +8,6 @@ private _display = ctrlParent _control; private _selectedAddon = _display getVariable (_control lbData _index); -#include "gui_createCategory.sqf" - if (_selectedAddon isEqualType "") then { uiNamespace setVariable [QGVAR(addon), _selectedAddon]; }; @@ -19,6 +17,11 @@ uiNamespace setVariable [QGVAR(addonIndex), _index]; // toggle lists private _selectedSource = uiNamespace getVariable QGVAR(source); +if !(_display getVariable [_selectedAddon, false]) then { + #include "gui_createCategory.sqf" + _display setVariable [_selectedAddon, true]; +}; + { (_x splitString "$") params ["", "_addon", "_source"]; diff --git a/addons/settings/fnc_initDisplayGameOptions.sqf b/addons/settings/fnc_initDisplayGameOptions.sqf index 241233fe2..6b41c8fd6 100644 --- a/addons/settings/fnc_initDisplayGameOptions.sqf +++ b/addons/settings/fnc_initDisplayGameOptions.sqf @@ -50,12 +50,17 @@ _ctrlAddonList ctrlAddEventHandler ["LBSelChanged", {_this call FUNC(gui_addonCh _display setVariable [QGVAR(lists),[]]; // ----- fill addons list +private _categories = []; { (GVAR(default) getVariable _x) params ["", "", "", "", "_category"]; - private _index = _ctrlAddonList lbAdd _category; - _ctrlAddonList lbSetData [_index, str _index]; - _display setVariable [str _index, _category]; + if !(_category in _categories) then { + private _index = _ctrlAddonList lbAdd _category; + _ctrlAddonList lbSetData [_index, str _index]; + _display setVariable [str _index, _category]; + + _categories pushBack _category; + }; } forEach GVAR(allSettings); lbSort _ctrlAddonList;