From c6a24dc7adb772ce638c56218e8521e4ad335c3e Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 15 Jul 2016 12:40:23 -0500 Subject: [PATCH 1/2] Rework Settings --- addons/settings/XEH_postInit.sqf | 8 +++++++- addons/settings/XEH_preInit.sqf | 14 ++++++++++++++ addons/settings/fnc_init.sqf | 19 ++++++++++++++++++- addons/settings/fnc_isForced.sqf | 2 +- addons/settings/fnc_isOverwritten.sqf | 4 ++-- addons/settings/gui_createMenu_force.sqf | 5 ----- addons/settings/script_component.hpp | 5 +++-- addons/settings/stringtable.xml | 9 +++++++++ 8 files changed, 54 insertions(+), 12 deletions(-) diff --git a/addons/settings/XEH_postInit.sqf b/addons/settings/XEH_postInit.sqf index 031726f61..72b28f073 100644 --- a/addons/settings/XEH_postInit.sqf +++ b/addons/settings/XEH_postInit.sqf @@ -6,10 +6,16 @@ diag_log text "[CBA] (settings): No server settings after postInit phase."; }; + //Event to read modules + ["CBA_preSettingsInit", []] call CBA_fnc_localEvent; + GVAR(ready) = true; { [QGVAR(refreshSetting), _x] call CBA_fnc_localEvent; - } forEach GVAR(allSettings); + } forEach GVAR(allSettings); + + diag_log text format ["[CBA] (settings): Settings Initialized"]; + ["CBA_settingsInitialized", []] call CBA_fnc_localEvent; } call CBA_fnc_execNextFrame; // --- autosave mission and server presets diff --git a/addons/settings/XEH_preInit.sqf b/addons/settings/XEH_preInit.sqf index 5af03c6d8..5eaea7002 100644 --- a/addons/settings/XEH_preInit.sqf +++ b/addons/settings/XEH_preInit.sqf @@ -63,4 +63,18 @@ if (isServer) then { }] call CBA_fnc_addEventHandler; }; +// event to modify mission settings +[QGVAR(setSettingMission), { + params ["_setting", "_value", ["_forced", false, [false]]]; + + if ([_setting, "mission"] call FUNC(isForced)) exitWith { + diag_log text format ["[CBA] (settings): Setting %1 already forced, ignoring setSettingMission.", _setting]; + }; + if (!([_setting, _value] call FUNC(check))) exitWith { + diag_log text format ["[CBA] (settings): Value %1 is invalid for setting %2.", _value, _setting]; + }; + + GVAR(missionSettings) setVariable [_setting, [_value, _forced]]; +}] call CBA_fnc_addEventHandler; + ADDON = true; diff --git a/addons/settings/fnc_init.sqf b/addons/settings/fnc_init.sqf index 3579e76ac..975f5f364 100644 --- a/addons/settings/fnc_init.sqf +++ b/addons/settings/fnc_init.sqf @@ -75,6 +75,10 @@ private _settingData = []; switch (toUpper _settingType) do { case ("CHECKBOX"): { _defaultValue = _valueInfo param [0, false, [false]]; // don't use params - we want these variables to be private to the main scope + + if (isNumber (configFile >> "CBA_settings" >> _setting)) then { // See if custom default value is set in config + _defaultValue = (getNumber (configFile >> "CBA_settings" >> _setting)) > 0; + }; }; case ("LIST"): { _valueInfo params [["_values", [], [[]]], ["_labels", [], [[]]], ["_defaultIndex", 0, [0]]]; @@ -99,17 +103,30 @@ switch (toUpper _settingType) do { _labels set [_forEachIndex, _x]; } forEach _labels; + + if (isNumber (configFile >> "CBA_settings" >> _setting)) then { // See if custom default value is set in config + _defaultIndex = getNumber (configFile >> "CBA_settings" >> _setting); + }; + _defaultValue = _values param [_defaultIndex]; _settingData append [_values, _labels]; }; case ("SLIDER"): { _valueInfo params [["_min", 0, [0]], ["_max", 1, [0]], ["_default", 0, [0]], ["_trailingDecimals", 2, [0]]]; + if (isNumber (configFile >> "CBA_settings" >> _setting)) then { // See if custom default value is set in config + _default = getNumber (configFile >> "CBA_settings" >> _setting); + }; + _defaultValue = _default; _settingData append [_min, _max, _trailingDecimals]; }; case ("COLOR"): { _defaultValue = [_valueInfo] param [0, [1,1,1], [[]], [3,4]]; + + if (isArray (configFile >> "CBA_settings" >> _setting)) then { // See if custom default value is set in config + _defaultValue = getArray (configFile >> "CBA_settings" >> _setting); + }; }; default {/* _defaultValue undefined, exit below */}; }; @@ -161,7 +178,7 @@ if (!isNil "_settingInfo") then { if (isServer) then { [QGVAR(refreshSetting), _setting] call CBA_fnc_globalEvent; } else { - [QGVAR(refreshSetting), _setting] call CBA_fnc_localEvent; + [QGVAR(refreshSetting), _setting] call CBA_fnc_localEvent; }; 0 diff --git a/addons/settings/fnc_isForced.sqf b/addons/settings/fnc_isForced.sqf index bfa6bf0cd..0a675d0a1 100644 --- a/addons/settings/fnc_isForced.sqf +++ b/addons/settings/fnc_isForced.sqf @@ -23,7 +23,7 @@ switch (toLower _source) do { GET_FORCED(clientSettings,_setting); }; case ("server"): { - GET_FORCED(serverSettings,_setting); + GET_FORCED(serverSettings,_setting) || {(!GET_FORCED(missionSettings,_setting)) && {(isMultiplayer && {NAMESPACE_GETVAR(GVAR(defaultSettings),_setting,[]) param [7, false]})}}; }; case ("mission"): { GET_FORCED(missionSettings,_setting); diff --git a/addons/settings/fnc_isOverwritten.sqf b/addons/settings/fnc_isOverwritten.sqf index 84157b209..79bd8bde5 100644 --- a/addons/settings/fnc_isOverwritten.sqf +++ b/addons/settings/fnc_isOverwritten.sqf @@ -23,10 +23,10 @@ switch (toLower _source) do { [_setting, "mission"] call FUNC(isForced) || {[_setting, "server"] call FUNC(isForced)} }; case ("server"): { - false + (!([_setting, "server"] call FUNC(isForced))) && {[_setting, "mission"] call FUNC(isForced)} }; case ("mission"): { - [_setting, "server"] call FUNC(isForced) + (!([_setting, "mission"] call FUNC(isForced))) || {[_setting, "server"] call FUNC(isForced)} }; default {nil}; }; diff --git a/addons/settings/gui_createMenu_force.sqf b/addons/settings/gui_createMenu_force.sqf index 3a7fb7597..992d1fb0c 100644 --- a/addons/settings/gui_createMenu_force.sqf +++ b/addons/settings/gui_createMenu_force.sqf @@ -17,11 +17,6 @@ private _data = [_setting, _source]; _ctrlSettingForce setVariable [QGVAR(linkedControls), _linkedControls]; _ctrlSettingForce setVariable [QGVAR(data), _data]; -if (_isGlobal) then { - _ctrlSettingForce ctrlSetChecked true; - _ctrlSettingForce ctrlEnable false; -}; - _ctrlSettingForce ctrlAddEventHandler ["CheckedChanged", { params ["_control", "_state"]; diff --git a/addons/settings/script_component.hpp b/addons/settings/script_component.hpp index e362e4376..430c4aa7f 100644 --- a/addons/settings/script_component.hpp +++ b/addons/settings/script_component.hpp @@ -1,6 +1,5 @@ #define COMPONENT settings #include "\x\cba\addons\main\script_mod.hpp" -#include "\x\cba\addons\main\script_macros.hpp" #include "\a3\ui_f\hpp\defineDIKCodes.inc" #include "\a3\ui_f\hpp\defineCommonGrids.inc" @@ -15,6 +14,8 @@ #define DEBUG_SETTINGS DEBUG_SETTINGS_SETTINGS #endif +#include "\x\cba\addons\main\script_macros.hpp" + #define IDC_ADDONS_GROUP 4301 #define IDC_BTN_CONFIGURE_ADDONS 4302 #define IDC_BTN_CLIENT 9000 @@ -76,7 +77,7 @@ #define NAMESPACE_GETVAR(namespace,varname,default) ([namespace getVariable varname] param [0, default]) #define GET_VALUE(namespace,setting) ((GVAR(namespace) getVariable setting) param [0]) -#define GET_FORCED(namespace,setting) ((NAMESPACE_GETVAR(GVAR(namespace),setting,[]) param [1, false]) || {isMultiplayer && {NAMESPACE_GETVAR(GVAR(defaultSettings),setting,[]) param [7, false]}}) +#define GET_FORCED(namespace,setting) (NAMESPACE_GETVAR(GVAR(namespace),setting,[]) param [1, false]) #define GET_TEMP_NAMESPACE(source) ([ARR_3(GVAR(clientSettingsTemp),GVAR(serverSettingsTemp),GVAR(missionSettingsTemp))] param [[ARR_3('client','server','mission')] find toLower source]) #define SET_TEMP_NAMESPACE_VALUE(setting,value,source) GET_TEMP_NAMESPACE(source) setVariable [ARR_2(setting,[ARR_2(value,(GET_TEMP_NAMESPACE(source) getVariable setting) param [1])])] diff --git a/addons/settings/stringtable.xml b/addons/settings/stringtable.xml index 4961adbb6..15c5b629a 100644 --- a/addons/settings/stringtable.xml +++ b/addons/settings/stringtable.xml @@ -63,7 +63,16 @@ Default + Výchozí Voreinst. + По умолчанию + Domyślnie + Predefinito + Predet. + Par défaut + デフォルト + 기본값 + Padrão Setting is overwritten. Check 'Server' or 'Mission' tab. From d6ef65be9d78bf7989de1e5b69540eeb673cb1aa Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 31 Jul 2016 15:02:43 -0500 Subject: [PATCH 2/2] Change event name, remove config reading --- addons/settings/XEH_postInit.sqf | 2 +- addons/settings/fnc_init.sqf | 17 ----------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/addons/settings/XEH_postInit.sqf b/addons/settings/XEH_postInit.sqf index 72b28f073..d5475be79 100644 --- a/addons/settings/XEH_postInit.sqf +++ b/addons/settings/XEH_postInit.sqf @@ -7,7 +7,7 @@ }; //Event to read modules - ["CBA_preSettingsInit", []] call CBA_fnc_localEvent; + ["CBA_beforeSettingsInitialized", []] call CBA_fnc_localEvent; GVAR(ready) = true; { diff --git a/addons/settings/fnc_init.sqf b/addons/settings/fnc_init.sqf index 975f5f364..fddb6bbf7 100644 --- a/addons/settings/fnc_init.sqf +++ b/addons/settings/fnc_init.sqf @@ -75,10 +75,6 @@ private _settingData = []; switch (toUpper _settingType) do { case ("CHECKBOX"): { _defaultValue = _valueInfo param [0, false, [false]]; // don't use params - we want these variables to be private to the main scope - - if (isNumber (configFile >> "CBA_settings" >> _setting)) then { // See if custom default value is set in config - _defaultValue = (getNumber (configFile >> "CBA_settings" >> _setting)) > 0; - }; }; case ("LIST"): { _valueInfo params [["_values", [], [[]]], ["_labels", [], [[]]], ["_defaultIndex", 0, [0]]]; @@ -103,30 +99,17 @@ switch (toUpper _settingType) do { _labels set [_forEachIndex, _x]; } forEach _labels; - - if (isNumber (configFile >> "CBA_settings" >> _setting)) then { // See if custom default value is set in config - _defaultIndex = getNumber (configFile >> "CBA_settings" >> _setting); - }; - _defaultValue = _values param [_defaultIndex]; _settingData append [_values, _labels]; }; case ("SLIDER"): { _valueInfo params [["_min", 0, [0]], ["_max", 1, [0]], ["_default", 0, [0]], ["_trailingDecimals", 2, [0]]]; - if (isNumber (configFile >> "CBA_settings" >> _setting)) then { // See if custom default value is set in config - _default = getNumber (configFile >> "CBA_settings" >> _setting); - }; - _defaultValue = _default; _settingData append [_min, _max, _trailingDecimals]; }; case ("COLOR"): { _defaultValue = [_valueInfo] param [0, [1,1,1], [[]], [3,4]]; - - if (isArray (configFile >> "CBA_settings" >> _setting)) then { // See if custom default value is set in config - _defaultValue = getArray (configFile >> "CBA_settings" >> _setting); - }; }; default {/* _defaultValue undefined, exit below */}; };