diff --git a/addons/main/config.cpp b/addons/main/config.cpp index 2bbb8e040..5df490a9e 100644 --- a/addons/main/config.cpp +++ b/addons/main/config.cpp @@ -56,7 +56,7 @@ class CfgSettings { }; class Registry { class PREFIX { - removed[] = {"cba_linux"}; + removed[] = {"cba_linux","cba_static_settings_addon","cba_auto_load_settings_file"}; }; }; }; diff --git a/addons/main/script_mod.hpp b/addons/main/script_mod.hpp index ba17b579c..68c328443 100644 --- a/addons/main/script_mod.hpp +++ b/addons/main/script_mod.hpp @@ -12,7 +12,7 @@ // MINIMAL required version for the Mod. Components can specify others.. -#define REQUIRED_VERSION 1.64 +#define REQUIRED_VERSION 1.68 /* // Defined DEBUG_MODE_NORMAL in a few CBA_fncs to prevent looped logging :) diff --git a/addons/settings/Cfg3DEN.hpp b/addons/settings/Cfg3DEN.hpp index 6c82ea12d..4b4e1bfcc 100644 --- a/addons/settings/Cfg3DEN.hpp +++ b/addons/settings/Cfg3DEN.hpp @@ -1,7 +1,8 @@ + class Cfg3DEN { class Attributes { class Default; - class CBA_CategoryHider: Default { + class GVAR(CategoryHider): Default { onLoad = "(ctrlParentControlsGroup ctrlParentControlsGroup (_this select 0)) ctrlShow false"; }; }; @@ -17,13 +18,23 @@ class Cfg3DEN { class GVAR(hash) { property = QGVAR(hash); value = 0; - control = "CBA_CategoryHider"; + control = QGVAR(CategoryHider); displayName = ""; tooltip = ""; - defaultValue = QUOTE(NULL_HASH); + defaultValue = QUOTE(HASH_NULL); expression = ""; wikiType = "[[Array]]"; }; + class GVAR(hasSettingsFile) { + property = QGVAR(hasSettingsFile); + value = 0; + control = QGVAR(CategoryHider); + displayName = ""; + tooltip = ""; + defaultValue = "false"; + expression = ""; + wikiType = "[[BOOL]]"; + }; }; }; }; diff --git a/addons/settings/CfgEventHandlers.hpp b/addons/settings/CfgEventHandlers.hpp index 275f3dad9..36b38d2f4 100644 --- a/addons/settings/CfgEventHandlers.hpp +++ b/addons/settings/CfgEventHandlers.hpp @@ -18,10 +18,13 @@ class Extended_PostInit_EventHandlers { }; class Extended_DisplayLoad_EventHandlers { + class RscDisplayMain { + ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplayMain)')); + }; class RscDisplayGameOptions { - ADDON = QUOTE(if (isNil 'ADDON') then {_this call (uiNamespace getVariable 'FUNC(gui_initDisplay_disabled)')} else {_this call (uiNamespace getVariable 'FUNC(gui_initDisplay)')};); + ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplayGameOptions)')); }; class Display3DEN { - ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(init3DEN)')); + ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplay3DEN)')); }; }; diff --git a/addons/settings/CfgFunctions.hpp b/addons/settings/CfgFunctions.hpp deleted file mode 100644 index 74c366818..000000000 --- a/addons/settings/CfgFunctions.hpp +++ /dev/null @@ -1,6 +0,0 @@ - -class CfgFunctions { - class CBA { - class Settings {}; - }; -}; diff --git a/addons/settings/Display3DEN.hpp b/addons/settings/Display3DEN.hpp index d692798f6..7f8785156 100644 --- a/addons/settings/Display3DEN.hpp +++ b/addons/settings/Display3DEN.hpp @@ -9,7 +9,7 @@ class Display3DEN { items[] += {QUOTE(ADDON)}; }; class ADDON { - text = CSTRING(shortcut); + text = CSTRING(3den_shortcut); action = QUOTE(findDisplay 313 call COMPILE_FILE(openSettingsMenu)); data = QUOTE(ADDON); shortcuts[] = {INPUT_CTRL_OFFSET + INPUT_ALT_OFFSET + DIK_S}; diff --git a/addons/settings/XEH_PREP.sqf b/addons/settings/XEH_PREP.sqf index 82b61ac8e..b1678701e 100644 --- a/addons/settings/XEH_PREP.sqf +++ b/addons/settings/XEH_PREP.sqf @@ -7,13 +7,21 @@ PREP(parse); PREP(import); PREP(export); PREP(clear); -PREP(saveTempData); -PREP(isForced); -PREP(isOverwritten); +PREP(priority); -PREP(gui_addonChanged); -PREP(gui_sourceChanged); -PREP(gui_configure); -PREP(gui_closeMenu); -PREP(gui_refresh); -PREP(gui_preset); +if (hasInterface) then { + PREP(gui_addonChanged); + PREP(gui_sourceChanged); + PREP(gui_configure); + PREP(gui_refresh); + PREP(gui_preset); + PREP(gui_saveTempData); + + PREP(gui_settingCheckbox); + PREP(gui_settingEditbox); + PREP(gui_settingList); + PREP(gui_settingSlider); + PREP(gui_settingColor); + PREP(gui_SettingDefault); + PREP(gui_settingOverwrite); +}; diff --git a/addons/settings/XEH_postInit.sqf b/addons/settings/XEH_postInit.sqf index 607a53fb2..95fbbc051 100644 --- a/addons/settings/XEH_postInit.sqf +++ b/addons/settings/XEH_postInit.sqf @@ -2,27 +2,26 @@ // --- refresh all settings after postInit to guarantee that events are added and settings are recieved from server { - if (isNil QGVAR(serverSettings)) then { + if (isNull GVAR(server)) then { ERROR("No server settings after postInit phase."); }; //Event to read modules ["CBA_beforeSettingsInitialized", []] call CBA_fnc_localEvent; - GVAR(ready) = true; - { - [QGVAR(refreshSetting), _x] call CBA_fnc_localEvent; - } forEach GVAR(allSettings); + // --- refresh all settings now + GVAR(ready) = true; // enable setting init script and CBA_SettingChanged event + QGVAR(refreshAllSettings) call CBA_fnc_localEvent; LOG("Settings Initialized"); ["CBA_settingsInitialized", []] call CBA_fnc_localEvent; } call CBA_fnc_execNextFrame; // --- autosave mission and server presets -private _presetsHash = profileNamespace getVariable [QGVAR(presetsHash), NULL_HASH]; +private _presetsHash = profileNamespace getVariable [QGVAR(presetsHash), HASH_NULL]; private _autosavedPresets = profileNamespace getVariable [QGVAR(autosavedPresets), [[],[]]]; -if !(allVariables GVAR(missionSettings) isEqualTo []) then { +if !(allVariables GVAR(mission) isEqualTo []) then { private _preset = "mission" call FUNC(export); private _presetName = format ["Autosave: %1 (%2)", localize LSTRING(ButtonMission), missionName]; diff --git a/addons/settings/XEH_preInit.sqf b/addons/settings/XEH_preInit.sqf index fc2115847..7ebda11c2 100644 --- a/addons/settings/XEH_preInit.sqf +++ b/addons/settings/XEH_preInit.sqf @@ -1,4 +1,3 @@ -//#define DEBUG_MODE_FULL #include "script_component.hpp" ADDON = false; @@ -6,10 +5,19 @@ ADDON = false; #include "XEH_PREP.sqf" #ifdef DEBUG_MODE_FULL -["Test_Setting_1", "CHECKBOX", ["-test checkbox-", "-tooltip-"], "My Category", true] call cba_settings_fnc_init; +["Test_Setting_0", "CHECKBOX", ["-test checkbox-", "-tooltip-"], "My Category", true] call cba_settings_fnc_init; +["Test_Setting_1", "EDITBOX", ["-test editbox-", "-tooltip-"], "My Category", "null"] call cba_settings_fnc_init; ["Test_Setting_2", "LIST", ["-test list-", "-tooltip-"], "My Category", [[1,0], ["enabled","disabled"], 1]] call cba_settings_fnc_init; ["Test_Setting_3", "SLIDER", ["-test slider-", "-tooltip-"], "My Category", [0, 10, 5, 0]] call cba_settings_fnc_init; ["Test_Setting_4", "COLOR", ["-test color-", "-tooltip-"], "My Category", [1,1,0], false, {diag_log text format ["Color Setting Changed: %1", _this];}] call cba_settings_fnc_init; + +["Test_Setting_5", "COLOR", ["-test alpha-", "-tooltip-"], "My Category", [1,0,0,0.5], false] call cba_settings_fnc_init; +["Test_Setting_1", "EDITBOX", "setting 1", "My Category", "null", nil, {systemChat str [1, _this]}] call cba_settings_fnc_init; +["Test_Setting_2", "EDITBOX", "setting 2", "My Category", "null", nil, {systemChat str [2, _this]}] call cba_settings_fnc_init; +["Test_Setting_3", "EDITBOX", "setting 3", "My Category", "null", nil, {systemChat str [3, _this]}] call cba_settings_fnc_init; +["Test_Setting_4", "EDITBOX", "setting 4", "My Category", "null", nil, {systemChat str [4, _this]}] call cba_settings_fnc_init; +["Test_Setting_5", "EDITBOX", "setting 5", "My Category", "null", 1, {systemChat str [5, _this]}] call cba_settings_fnc_init; +["Test_Setting_6", "EDITBOX", "setting 6", "My Category", "null", 2, {systemChat str [6, _this]}] call cba_settings_fnc_init; #endif // --- init settings namespaces @@ -24,7 +32,7 @@ ADDON = false; if (isNil QGVAR(ready)) exitWith {}; - private _script = NAMESPACE_GETVAR(GVAR(defaultSettings),_setting,[]) param [8, {}]; + private _script = (GVAR(default) getVariable [_setting, []]) param [8, {}]; [_value, _script] call { private ["_setting", "_value", "_script"]; // prevent these variables from being overwritten (_this select 0) call (_this select 1); @@ -33,7 +41,7 @@ ADDON = false; ["CBA_SettingChanged", [_setting, _value]] call CBA_fnc_localEvent; }] call CBA_fnc_addEventHandler; -// event to refresh all settings at once - saves bandwith +// --- event to refresh all settings at once - saves bandwith [QGVAR(refreshAllSettings), { { [QGVAR(refreshSetting), _x] call CBA_fnc_localEvent; @@ -51,30 +59,24 @@ addMissionEventHandler ["Loaded", { private _message = format ["%1 = %2", _setting, _value]; systemChat _message; - LOG(_message); + //LOG(_message); }] call CBA_fnc_addEventHandler; #endif -// event to modify settings on a dedicated server as admin +// --- event to modify settings on a dedicated server as admin if (isServer) then { [QGVAR(setSettingServer), { - params ["_setting", "_value", "_forced"]; - [_setting, _value, _forced, "server"] call FUNC(set); + params ["_setting", "_value", ["_priority", 0], ["_store", false]]; + + [_setting, _value, _priority, "server", _store] call FUNC(set); }] call CBA_fnc_addEventHandler; }; -// event to modify mission settings +// --- event to modify mission settings [QGVAR(setSettingMission), { - params ["_setting", "_value", ["_forced", false, [false]]]; - - if ([_setting, "mission"] call FUNC(isForced)) exitWith { - LOG_1("Setting %1 already forced, ignoring setSettingMission.",str _setting); - }; - if (!([_setting, _value] call FUNC(check))) exitWith { - WARNING_2("Value %1 is invalid for setting %2.",_value,str _setting); - }; + params ["_setting", "_value", ["_priority", 0], ["_store", false]]; - GVAR(missionSettings) setVariable [_setting, [_value, _forced]]; + [_setting, _value, _priority, "mission", _store] call FUNC(set); }] call CBA_fnc_addEventHandler; ADDON = true; diff --git a/addons/settings/XEH_preStart.sqf b/addons/settings/XEH_preStart.sqf index 1ae37f38a..6e5b51830 100644 --- a/addons/settings/XEH_preStart.sqf +++ b/addons/settings/XEH_preStart.sqf @@ -2,6 +2,11 @@ #include "XEH_PREP.sqf" -PREP(gui_initDisplay); -PREP(gui_initDisplay_disabled); -PREP(init3DEN); +PREP(initDisplayMain); + +if (hasInterface) then { + PREP(initDisplayGameOptions); + PREP(initDisplay3DEN); +} else { + [displayNull] call FUNC(initDisplayMain); +}; diff --git a/addons/settings/config.cpp b/addons/settings/config.cpp index d6f4e5f5a..60594764b 100644 --- a/addons/settings/config.cpp +++ b/addons/settings/config.cpp @@ -15,7 +15,6 @@ class CfgPatches { }; #include "CfgEventHandlers.hpp" -#include "CfgFunctions.hpp" #include "Cfg3DEN.hpp" #include "Display3DEN.hpp" diff --git a/addons/settings/fnc_check.sqf b/addons/settings/fnc_check.sqf index 8e2f6b9ea..e1a80a00d 100644 --- a/addons/settings/fnc_check.sqf +++ b/addons/settings/fnc_check.sqf @@ -20,21 +20,24 @@ params [["_setting", "", [""]], "_value"]; if (isNil "_value") exitWith {false}; -NAMESPACE_GETVAR(GVAR(defaultSettings),_setting,[]) params ["_defaultValue", "", ["_settingType", ""], "_settingData"]; +(GVAR(default) getVariable [_setting, []]) params ["_defaultValue", "", ["_settingType", ""], "_settingData"]; switch (toUpper _settingType) do { - case ("CHECKBOX"): { + case "CHECKBOX": { _value isEqualType false }; - case ("LIST"): { + case "EDITBOX": { + _value isEqualType "" + }; + case "LIST": { _settingData params ["_values"]; _value in _values }; - case ("SLIDER"): { - _settingData params ["_min", "_max"]; - _value isEqualType 0 && {_value >= _min} && {_value <= _max} + case "SLIDER": { + _settingData params ["_min", "_max", "_trailingDecimals"]; + _value isEqualType 0 && {_value >= _min} && {_value <= _max} && {(_trailingDecimals >= 0) || {(round _value) == _value}} }; - case ("COLOR"): { + case "COLOR": { _value isEqualType [] && {count _value == count _defaultValue} && {_value isEqualTypeAll 0} && {{_x < 0 || _x > 1} count _value == 0} }; default {false}; diff --git a/addons/settings/fnc_clear.sqf b/addons/settings/fnc_clear.sqf index 345f43e8f..e3b1ea90a 100644 --- a/addons/settings/fnc_clear.sqf +++ b/addons/settings/fnc_clear.sqf @@ -5,7 +5,7 @@ Description: Clear all settings from profile or mission. Parameters: - _source - Can be "client", "server" or "mission" (optional, default: "client") + _source - Can be "client", "mission" or "server" (optional, default: "client") Returns: None @@ -18,33 +18,91 @@ Author: params [["_source", "client", [""]]]; switch (toLower _source) do { - case ("client"): { - profileNamespace setVariable [QGVAR(hash), NULL_HASH]; - GVAR(clientSettings) call CBA_fnc_deleteNamespace; - GVAR(clientSettings) = [] call CBA_fnc_createNamespace; - }; - case ("server"): { - if (!isServer) exitWith {}; + case "client": { + if (isServer) exitWith { + "server" call FUNC(clear); + }; + + profileNamespace setVariable [QGVAR(hash), HASH_NULL]; + GVAR(client) call CBA_fnc_deleteNamespace; + GVAR(client) = [] call CBA_fnc_createNamespace; + + { + private _setting = _x; + + if (!isNil {GVAR(userconfig) getVariable _setting}) then { + (GVAR(userconfig) getVariable _setting) params ["_value", "_priority"]; + + if !([_setting, _value] call FUNC(check)) then { + _value = [_setting, "default"] call FUNC(get); + }; + + // convert boolean to number + _priority = [0,1,2] select _priority; - profileNamespace setVariable [QGVAR(hash), NULL_HASH]; - GVAR(serverSettings) call CBA_fnc_deleteNamespace; - GVAR(serverSettings) = isMultiplayer call CBA_fnc_createNamespace; - publicVariable QGVAR(serverSettings); + GVAR(client) setVariable [_setting, [_value, _priority]]; + }; + } forEach GVAR(allSettings); + + QGVAR(refreshAllSettings) call CBA_fnc_localEvent; }; - case ("mission"): { + case "mission": { if (!is3DEN) exitWith {}; - set3DENMissionAttributes [["Scenario", QGVAR(hash), NULL_HASH]]; - GVAR(missionSettings) call CBA_fnc_deleteNamespace; - GVAR(missionSettings) = [] call CBA_fnc_createNamespace; + set3DENMissionAttributes [["Scenario", QGVAR(hash), HASH_NULL]]; + findDisplay 313 setVariable [QGVAR(hash), HASH_NULL]; + GVAR(mission) call CBA_fnc_deleteNamespace; + GVAR(mission) = [] call CBA_fnc_createNamespace; + + { + private _setting = _x; + + if (!isNil {GVAR(missionConfig) getVariable _setting}) then { + (GVAR(missionConfig) getVariable _setting) params ["_value", "_priority"]; + + if !([_setting, _value] call FUNC(check)) then { + _value = [_setting, "default"] call FUNC(get); + }; + + // convert boolean to number + _priority = [0,1,2] select _priority; + + GVAR(mission) setVariable [_setting, [_value, _priority]]; + }; + } forEach GVAR(allSettings); + + QGVAR(refreshAllSettings) call CBA_fnc_localEvent; }; - default {}; -}; + case "server": { + if (!isServer) exitWith {}; + + profileNamespace setVariable [QGVAR(hash), HASH_NULL]; + GVAR(client) call CBA_fnc_deleteNamespace; + GVAR(client) = [] call CBA_fnc_createNamespace; + GVAR(server) call CBA_fnc_deleteNamespace; + missionNamespace setVariable [QGVAR(server), true call CBA_fnc_createNamespace, true]; + + { + private _setting = _x; -if (isServer) then { - QGVAR(refreshAllSettings) call CBA_fnc_globalEvent; -} else { - QGVAR(refreshAllSettings) call CBA_fnc_localEvent; + if (!isNil {GVAR(userconfig) getVariable _setting}) then { + (GVAR(userconfig) getVariable _setting) params ["_value", "_priority"]; + + if !([_setting, _value] call FUNC(check)) then { + _value = [_setting, "default"] call FUNC(get); + }; + + // convert boolean to number + _priority = [0,1,2] select _priority; + + GVAR(client) setVariable [_setting, [_value, _priority]]; + GVAR(server) setVariable [_setting, [_value, _priority], true]; + }; + } forEach GVAR(allSettings); + + QGVAR(refreshAllSettings) call CBA_fnc_globalEvent; + }; + default {}; }; nil diff --git a/addons/settings/fnc_export.sqf b/addons/settings/fnc_export.sqf index d2453b3a8..715828919 100644 --- a/addons/settings/fnc_export.sqf +++ b/addons/settings/fnc_export.sqf @@ -5,7 +5,7 @@ Description: Export all setting info to string. Parameters: - _source - Can be "client", "server" or "mission" (optional, default: "client") + _source - Can be "client", "mission" or "server" (optional, default: "client") Returns: Formatted setting info. @@ -15,9 +15,6 @@ Author: ---------------------------------------------------------------------------- */ #include "script_component.hpp" -#define NEWLINE toString [10] -#define KEYWORD_FORCE "force" - params [["_source", "client", [""]]]; private _info = ""; @@ -30,18 +27,13 @@ private _info = ""; _value = [_setting, _source] call FUNC(get); }; - private _forced = GET_TEMP_NAMESPACE_FORCED(_setting,_source); - - if (isNil "_forced") then { - _forced = [_setting, _source] call FUNC(isForced); - }; + private _priority = GET_TEMP_NAMESPACE_PRIORITY(_setting,_source); - // not displayed for client settings - assume it's not forced - if (_source == "client") then { - _forced = false; + if (isNil "_priority") then { + _priority = [_setting, _source] call FUNC(priority); }; - _info = _info + ((["", KEYWORD_FORCE + " "] select _forced) + _setting + " = " + format ["%1", _value] + ";" + NEWLINE); + _info = _info + ((["", "force ", "force force "] select _priority) + _setting + " = " + str _value + ";" + NEWLINE); } forEach GVAR(allSettings); _info diff --git a/addons/settings/fnc_get.sqf b/addons/settings/fnc_get.sqf index d646c2acb..875845a14 100644 --- a/addons/settings/fnc_get.sqf +++ b/addons/settings/fnc_get.sqf @@ -6,7 +6,7 @@ Description: Parameters: _setting - Name of the setting - _source - Can be "server", "mission", "client", "forced" or "default" (optional, default: "forced") + _source - Can be "client", "mission", "server", "priority" or "default" (optional, default: "priority") Returns: Value of the setting @@ -21,36 +21,28 @@ Author: ---------------------------------------------------------------------------- */ #include "script_component.hpp" -params [["_setting", "", [""]], ["_source", "forced", [""]]]; +params [["_setting", "", [""]], ["_source", "priority", [""]]]; private _value = switch (toLower _source) do { - case ("client"): { - GET_VALUE(clientSettings,_setting); + case "client": { + GVAR(client) getVariable [_setting, [nil, nil]] select 0 }; - case ("server"): { - GET_VALUE(serverSettings,_setting); + case "mission": { + GVAR(mission) getVariable [_setting, [nil, nil]] select 0 }; - case ("mission"): { - GET_VALUE(missionSettings,_setting); + case "server": { + GVAR(server) getVariable [_setting, [nil, nil]] select 0 }; - case ("default"): { - GET_VALUE(defaultSettings,_setting); + case "priority": { + private _source = _setting call FUNC(priority); + [_setting, _source] call FUNC(get) }; - case ("forced"): { - private _value = [_setting, "client"] call FUNC(get); - - if ([_setting, "mission"] call FUNC(isForced)) then { - _value = [_setting, "mission"] call FUNC(get); - }; - - if ([_setting, "server"] call FUNC(isForced)) then { - _value = [_setting, "server"] call FUNC(get); - }; - - if (isNil "_value") then {nil} else {_value}; + case "default": { + GVAR(default) getVariable [_setting, [nil, nil]] select 0 }; default { _source = "default"; // exit + nil }; }; @@ -61,5 +53,5 @@ if (isNil "_value") exitWith { [_setting, "default"] call FUNC(get); }; -// copy array to prevent overwriting +// copy array to prevent accidental overwriting if (_value isEqualType []) then {+_value} else {_value} diff --git a/addons/settings/fnc_gui_closeMenu.sqf b/addons/settings/fnc_gui_closeMenu.sqf deleted file mode 100644 index 5bf8ca4be..000000000 --- a/addons/settings/fnc_gui_closeMenu.sqf +++ /dev/null @@ -1,31 +0,0 @@ -/* ---------------------------------------------------------------------------- -Internal Function: CBA_settings_fnc_gui_closeMenu - -Description: - Save settings and clean up temporary data. - -Parameters: - _save - Name of the setting - -Returns: - None - -Author: - commy2 ----------------------------------------------------------------------------- */ -#include "script_component.hpp" - -params [["_save", false, [false]]]; - -if (_save) then { - call FUNC(saveTempData); -}; - -GVAR(clientSettingsTemp) call CBA_fnc_deleteNamespace; -GVAR(clientSettingsTemp) = nil; - -GVAR(serverSettingsTemp) call CBA_fnc_deleteNamespace; -GVAR(serverSettingsTemp) = nil; - -GVAR(missionSettingsTemp) call CBA_fnc_deleteNamespace; -GVAR(missionSettingsTemp) = nil; diff --git a/addons/settings/fnc_gui_configure.sqf b/addons/settings/fnc_gui_configure.sqf index ddc8a30fe..e6ece48a7 100644 --- a/addons/settings/fnc_gui_configure.sqf +++ b/addons/settings/fnc_gui_configure.sqf @@ -9,24 +9,23 @@ private _display = ctrlParent _control; private _ctrlGeneralGroup = _display displayCtrl 2300; private _ctrlColorsGroup = _display displayCtrl 2301; private _ctrlDifficultyGroup = _display displayCtrl 2302; - +private _ctrlPresetsButton = _display displayCtrl 114; +private _ctrlDefaultButton = _display displayCtrl 101; private _ctrlDifficultyButton = _display displayCtrl 304; private _ctrlGeneralButton = _display displayCtrl 2402; private _ctrlGUIButton = _display displayCtrl 2404; private _ctrlLayoutButton = _display displayCtrl 2405; -private _ctrlTitle = _display displayCtrl 1000; -private _ctrlPresetsButton = _display displayCtrl 114; -private _ctrlDefaultButton = _display displayCtrl 101; +private _ctrlButtonOK = _display displayCtrl IDC_OK; private _ctrlAddonsGroup = _display displayCtrl IDC_ADDONS_GROUP; -private _ctrlToggleButton = _display displayCtrl IDC_BTN_CONFIGURE_ADDONS; -private _ctrlClientButton = _display displayCtrl IDC_BTN_CLIENT; private _ctrlServerButton = _display displayCtrl IDC_BTN_SERVER; private _ctrlMissionButton = _display displayCtrl IDC_BTN_MISSION; +private _ctrlClientButton = _display displayCtrl IDC_BTN_CLIENT; private _ctrlButtonImport = _display displayCtrl IDC_BTN_IMPORT; private _ctrlButtonExport = _display displayCtrl IDC_BTN_EXPORT; private _ctrlButtonSave = _display displayCtrl IDC_BTN_SAVE; private _ctrlButtonLoad = _display displayCtrl IDC_BTN_LOAD; +private _ctrlToggleButton = _display displayCtrl IDC_BTN_CONFIGURE_ADDONS; // Toggle displayed groups and buttons. if !(ctrlShown _ctrlAddonsGroup) then { @@ -49,16 +48,18 @@ if !(ctrlShown _ctrlAddonsGroup) then { _ctrlGUIButton ctrlShow false; _ctrlLayoutButton ctrlEnable false; _ctrlLayoutButton ctrlShow false; + _ctrlButtonOK ctrlEnable false; + _ctrlButtonOK ctrlShow false; //--- show and enable custom buttons _ctrlAddonsGroup ctrlEnable true; _ctrlAddonsGroup ctrlShow true; - _ctrlClientButton ctrlEnable CAN_VIEW_CLIENT_SETTINGS; - _ctrlClientButton ctrlShow true; _ctrlServerButton ctrlEnable CAN_VIEW_SERVER_SETTINGS; _ctrlServerButton ctrlShow true; _ctrlMissionButton ctrlEnable CAN_VIEW_MISSION_SETTINGS; _ctrlMissionButton ctrlShow true; + _ctrlClientButton ctrlEnable CAN_VIEW_CLIENT_SETTINGS; + _ctrlClientButton ctrlShow true; _ctrlButtonImport ctrlEnable true; _ctrlButtonImport ctrlShow true; _ctrlButtonExport ctrlEnable true; @@ -72,11 +73,17 @@ if !(ctrlShown _ctrlAddonsGroup) then { _ctrlToggleButton ctrlSetText localize LSTRING(configureBase); //--- emulate default scope selection - ([ - _ctrlClientButton, _ctrlServerButton, _ctrlMissionButton - ] param [[ - CAN_VIEW_CLIENT_SETTINGS, CAN_VIEW_SERVER_SETTINGS, CAN_VIEW_MISSION_SETTINGS - ] find true]) call FUNC(gui_sourceChanged); + switch (true) do { + case CAN_SET_SERVER_SETTINGS: { + _ctrlServerButton call FUNC(gui_sourceChanged); + }; + case CAN_SET_MISSION_SETTINGS: { + _ctrlMissionButton call FUNC(gui_sourceChanged); + }; + case CAN_SET_CLIENT_SETTINGS: { + _ctrlClientButton call FUNC(gui_sourceChanged); + }; + }; } else { //--- enable and show default menu _ctrlGeneralGroup ctrlEnable true; @@ -97,16 +104,18 @@ if !(ctrlShown _ctrlAddonsGroup) then { _ctrlGUIButton ctrlShow true; _ctrlLayoutButton ctrlEnable true; _ctrlLayoutButton ctrlShow true; + _ctrlButtonOK ctrlEnable true; + _ctrlButtonOK ctrlShow true; //--- hide and disable custom buttons _ctrlAddonsGroup ctrlEnable false; _ctrlAddonsGroup ctrlShow false; - _ctrlClientButton ctrlEnable false; - _ctrlClientButton ctrlShow false; _ctrlServerButton ctrlEnable false; _ctrlServerButton ctrlShow false; _ctrlMissionButton ctrlEnable false; _ctrlMissionButton ctrlShow false; + _ctrlClientButton ctrlEnable false; + _ctrlClientButton ctrlShow false; _ctrlButtonImport ctrlEnable false; _ctrlButtonImport ctrlShow false; _ctrlButtonExport ctrlEnable false; diff --git a/addons/settings/fnc_gui_initDisplay_disabled.sqf b/addons/settings/fnc_gui_initDisplay_disabled.sqf deleted file mode 100644 index db2752ae8..000000000 --- a/addons/settings/fnc_gui_initDisplay_disabled.sqf +++ /dev/null @@ -1,16 +0,0 @@ -#include "script_component.hpp" - -params ["_display"]; - -private _ctrlAddonsGroup = _display displayCtrl IDC_ADDONS_GROUP; -private _ctrlToggleButton = _display displayCtrl IDC_BTN_CONFIGURE_ADDONS; -private _ctrlClientButton = _display displayCtrl IDC_BTN_CLIENT; -private _ctrlServerButton = _display displayCtrl IDC_BTN_SERVER; -private _ctrlMissionButton = _display displayCtrl IDC_BTN_MISSION; - -_ctrlToggleButton ctrlEnable false; - -{ - _x ctrlEnable false; - _x ctrlShow false; -} forEach [_ctrlAddonsGroup, _ctrlClientButton, _ctrlServerButton, _ctrlMissionButton]; diff --git a/addons/settings/fnc_gui_preset.sqf b/addons/settings/fnc_gui_preset.sqf index 8b1f348ba..4d4a347d2 100644 --- a/addons/settings/fnc_gui_preset.sqf +++ b/addons/settings/fnc_gui_preset.sqf @@ -20,9 +20,9 @@ if (_mode == "save") then { // --- generate default name _ctrlEdit ctrlSetText format ["New: %1", localize ([ - LSTRING(ButtonClient), LSTRING(ButtonServer), LSTRING(ButtonMission) + LSTRING(ButtonServer), LSTRING(ButtonMission), LSTRING(ButtonClient) ] param [[ - "client", "server", "mission" + "server", "mission", "client" ] find (uiNamespace getVariable QGVAR(source))]) ]; @@ -47,7 +47,7 @@ if (_mode == "save") then { }; // --- fill listbox with profile stored presets -private _presetsHash = profileNamespace getVariable [QGVAR(presetsHash), NULL_HASH]; +private _presetsHash = profileNamespace getVariable [QGVAR(presetsHash), HASH_NULL]; [_presetsHash, { private _index = _ctrlValue lbAdd _key; @@ -65,12 +65,12 @@ if (_mode == "save") then { private _presetName = ctrlText _ctrlEdit; private _preset = [uiNamespace getVariable QGVAR(source)] call FUNC(export); - private _presetsHash = profileNamespace getVariable [QGVAR(presetsHash), NULL_HASH]; + private _presetsHash = profileNamespace getVariable [QGVAR(presetsHash), HASH_NULL]; [_presetsHash, _presetName, _preset] call CBA_fnc_hashSet; profileNamespace setVariable [QGVAR(presetsHash), _presetsHash]; - _display closeDisplay 1; + _display closeDisplay IDC_OK; }]; } else { _ctrlOK ctrlAddEventHandler ["ButtonClick", { @@ -83,7 +83,7 @@ if (_mode == "save") then { [_preset, uiNamespace getVariable QGVAR(source)] call FUNC(import); - _display closeDisplay 1; + _display closeDisplay IDC_OK; }]; }; @@ -91,7 +91,7 @@ _ctrlCancel ctrlAddEventHandler ["ButtonClick", { params ["_control"]; private _display = ctrlParent _control; - _display closeDisplay 2; + _display closeDisplay IDC_CANCEL; }]; _ctrlDelete ctrlAddEventHandler ["ButtonClick", { @@ -104,7 +104,7 @@ _ctrlDelete ctrlAddEventHandler ["ButtonClick", { _ctrlValue lbDelete _index; - private _presetsHash = profileNamespace getVariable [QGVAR(presetsHash), NULL_HASH]; + private _presetsHash = profileNamespace getVariable [QGVAR(presetsHash), HASH_NULL]; [_presetsHash, _presetName] call CBA_fnc_hashRem; profileNamespace setVariable [QGVAR(presetsHash), _presetsHash]; diff --git a/addons/settings/fnc_gui_refresh.sqf b/addons/settings/fnc_gui_refresh.sqf index 629e86d3b..99951c7e1 100644 --- a/addons/settings/fnc_gui_refresh.sqf +++ b/addons/settings/fnc_gui_refresh.sqf @@ -1,85 +1,40 @@ -#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Internal Function: CBA_settings_fnc_gui_refresh -private _display = uiNamespace getVariable [QGVAR(display), displayNull]; -private _ctrlOptionsGroup = ((_display getVariable [QGVAR(controls), []]) select {ctrlShown _x}) param [0, controlNull]; -private _controls = _ctrlOptionsGroup getVariable [QGVAR(controls), []]; +Description: + Resets all settings controls to their current (temporary) value. -{ - private _linkedControls = _x getVariable QGVAR(linkedControls); - (_x getVariable QGVAR(data)) params ["_setting", "_source"]; - (GVAR(defaultSettings) getVariable _setting) params ["_defaultValue", "", "_settingType", "_settingData"]; +Parameters: + None - private _value = GET_TEMP_NAMESPACE_VALUE(_setting,_source); +Returns: + None - // --- reset settings controls to current state - if (!isNil "_value") then { - switch (toUpper _settingType) do { - case ("CHECKBOX"): { - _linkedControls params ["_ctrlSetting", "_defaultControl"]; - - _ctrlSetting cbSetChecked _value; - - _defaultControl ctrlEnable !(_value isEqualTo _defaultValue); - }; - case ("LIST"): { - _settingData params ["_values"]; - _linkedControls params ["_ctrlSetting", "_defaultControl"]; +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" - _ctrlSetting lbSetCurSel (_values find _value); +private _display = uiNamespace getVariable [QGVAR(display), displayNull]; +private _controls = allControls _display select {ctrlIDC _x isEqualTo IDC_SETTING_CONTROLS_GROUP}; - _defaultControl ctrlEnable !(_value isEqualTo _defaultValue); - }; - case ("SLIDER"): { - _settingData params ["", "", "_trailingDecimals"]; - _linkedControls params ["_ctrlSetting", "_ctrlSettingEdit", "_defaultControl"]; +{ + private _setting = _x getVariable QGVAR(setting); + private _source = _x getVariable QGVAR(source); - _ctrlSetting sliderSetPosition _value; - _ctrlSettingEdit ctrlSetText ([_value, 1, _trailingDecimals] call CBA_fnc_formatNumber); - - _defaultControl ctrlEnable !(_value isEqualTo _defaultValue); - }; - case ("COLOR"): { - _linkedControls params ["_ctrlSettingPreview", "_settingControls", "_defaultControl"]; + private _value = GET_TEMP_NAMESPACE_VALUE(_setting,_source); - _value params [ - ["_r", 0, [0]], - ["_g", 0, [0]], - ["_b", 0, [0]], - ["_a", 1, [0]] - ]; - private _color = [_r, _g, _b, _a]; - _ctrlSettingPreview ctrlSetBackgroundColor _color; + if (isNil "_value") then { + _value = [_setting, _source] call FUNC(get); + }; - { - _x params ["_ctrlSetting", "_ctrlSettingEdit"]; - private _valueX = _value select _forEachIndex; + [_x, _value] call (_x getVariable QFUNC(updateUI)); - _ctrlSetting sliderSetPosition _valueX; - _ctrlSettingEdit ctrlSetText ([_valueX, 1, 2] call CBA_fnc_formatNumber); - } forEach _settingControls; + private _priority = GET_TEMP_NAMESPACE_PRIORITY(_setting,_source); - _defaultControl ctrlEnable !(_value isEqualTo _defaultValue); - }; - default {}; - }; + if (isNil "_priority") then { + _priority = [_setting, _source] call FUNC(priority); }; - private _forced = GET_TEMP_NAMESPACE_FORCED(_setting,_source); - - // --- reset force buttons to current state - if (!isNil "_forced") then { - switch (toUpper _settingType) do { - case ("CHECKBOX"); - case ("LIST"): { - private _ctrlSettingForce = _linkedControls param [2, controlNull]; - _ctrlSettingForce cbSetChecked _forced; - }; - case ("SLIDER"); - case ("COLOR"): { - private _ctrlSettingForce = _linkedControls param [3, controlNull]; - _ctrlSettingForce cbSetChecked _forced; - }; - default {}; - }; - }; + [_x, _priority] call (_x getVariable QFUNC(updateUI_priority)); } forEach _controls; diff --git a/addons/settings/fnc_saveTempData.sqf b/addons/settings/fnc_gui_saveTempData.sqf similarity index 62% rename from addons/settings/fnc_saveTempData.sqf rename to addons/settings/fnc_gui_saveTempData.sqf index fd2eca57a..55593438c 100644 --- a/addons/settings/fnc_saveTempData.sqf +++ b/addons/settings/fnc_gui_saveTempData.sqf @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Internal Function: CBA_settings_fnc_saveTempData +Internal Function: CBA_settings_fnc_gui_saveTempData Description: Saves temporary settings after closing the ingame settings editor. @@ -21,18 +21,18 @@ Author: { private _source = _x; - if (toLower _setting in allVariables GET_TEMP_NAMESPACE(_source)) then { - (GET_TEMP_NAMESPACE(_source) getVariable _setting) params ["_value", "_forced"]; + if (!isNil {GET_TEMP_NAMESPACE(_source) getVariable _setting}) then { + (GET_TEMP_NAMESPACE(_source) getVariable _setting) params ["_value", "_priority"]; if (isNil "_value") then { _value = [_setting, _source] call FUNC(get); }; - if (isNil "_forced") then { - _forced = [_setting, _source] call FUNC(isForced); + if (isNil "_priority") then { + _priority = [_setting, _source] call FUNC(priority); }; - [_setting, _value, _forced, _source] call FUNC(set); + [_setting, _value, _priority, _source, true] call FUNC(set); }; - } forEach ["client", "server", "mission"]; + } forEach ["client", "mission", "server"]; } forEach GVAR(allSettings); diff --git a/addons/settings/fnc_gui_settingCheckbox.sqf b/addons/settings/fnc_gui_settingCheckbox.sqf new file mode 100644 index 000000000..1298d40e2 --- /dev/null +++ b/addons/settings/fnc_gui_settingCheckbox.sqf @@ -0,0 +1,34 @@ +#include "script_component.hpp" + +params ["_controlsGroup", "_setting", "_source", "_currentValue", "_settingData"]; + +private _ctrlCheckbox = _controlsGroup controlsGroupCtrl IDC_SETTING_CHECKBOX; +_ctrlCheckbox cbSetChecked _currentValue; + +_ctrlCheckbox setVariable [QGVAR(params), [_setting, _source]]; +_ctrlCheckbox ctrlAddEventHandler ["CheckedChanged", { + params ["_ctrlCheckbox", "_state"]; + (_ctrlCheckbox getVariable QGVAR(params)) params ["_setting", "_source"]; + + private _value = _state == 1; + SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source); + + // if new value is same as default value, grey out the default button + private _controlsGroup = ctrlParentControlsGroup _ctrlCheckbox; + private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + private _defaultValue = [_setting, "default"] call FUNC(get); + _ctrlDefault ctrlEnable !(_value isEqualTo _defaultValue); +}]; + +// set setting ui manually to new value +_controlsGroup setVariable [QFUNC(updateUI), { + params ["_controlsGroup", "_value"]; + + private _ctrlCheckbox = _controlsGroup controlsGroupCtrl IDC_SETTING_CHECKBOX; + _ctrlCheckbox cbSetChecked _value; + + // if new value is same as default value, grey out the default button + private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + private _defaultValue = [_setting, "default"] call FUNC(get); + _ctrlDefault ctrlEnable !(_value isEqualTo _defaultValue); +}]; diff --git a/addons/settings/fnc_gui_settingColor.sqf b/addons/settings/fnc_gui_settingColor.sqf new file mode 100644 index 000000000..2ab38dd5e --- /dev/null +++ b/addons/settings/fnc_gui_settingColor.sqf @@ -0,0 +1,120 @@ +#include "script_component.hpp" + +params ["_controlsGroup", "_setting", "_source", "_currentValue", "_settingData"]; + +_currentValue params [ + ["_r", 0, [0]], + ["_g", 0, [0]], + ["_b", 0, [0]], + ["_a", 1, [0]] +]; + +private _color = [_r, _g, _b, _a]; + +for "_index" from 0 to ((count _currentValue max 3 min 4) - 1) do { + private _ctrlColor = _controlsGroup controlsGroupCtrl (IDCS_SETTING_COLOR select _index); + + _ctrlColor sliderSetRange [0, 1]; + _ctrlColor sliderSetPosition (_currentValue param [_index, 0]); + + _ctrlColor setVariable [QGVAR(params), [_setting, _source, _currentValue, _color, _index]]; + _ctrlColor ctrlAddEventHandler ["SliderPosChanged", { + params ["_ctrlColor", "_value"]; + (_ctrlColor getVariable QGVAR(params)) params ["_setting", "_source", "_currentValue", "_color", "_index"]; + + private _controlsGroup = ctrlParentControlsGroup _ctrlColor; + private _ctrlColorEdit = _controlsGroup controlsGroupCtrl (IDCS_SETTING_COLOR_EDIT select _index); + _ctrlColorEdit ctrlSetText ([_value, 1, 2] call CBA_fnc_formatNumber); + + _currentValue set [_index, _value]; + _color set [_index, _value]; + + private _ctrlColorPreview = _controlsGroup controlsGroupCtrl IDC_SETTING_COLOR_PREVIEW; + _ctrlColorPreview ctrlSetBackgroundColor _color; + + SET_TEMP_NAMESPACE_VALUE(_setting,_currentValue,_source); + + // if new value is same as default value, grey out the default button + private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + private _defaultValue = [_setting, "default"] call FUNC(get); + _ctrlDefault ctrlEnable !(_currentValue isEqualTo _defaultValue); + }]; + + private _ctrlColorEdit = _controlsGroup controlsGroupCtrl (IDCS_SETTING_COLOR_EDIT select _index); + _ctrlColorEdit ctrlSetText ([_currentValue param [_index, 0], 1, 2] call CBA_fnc_formatNumber); + + _ctrlColorEdit setVariable [QGVAR(params), [_setting, _source, _currentValue, _color, _index]]; + _ctrlColorEdit ctrlAddEventHandler ["KeyUp", { + params ["_ctrlColorEdit"]; + (_ctrlColorEdit getVariable QGVAR(params)) params ["_setting", "_source", "_currentValue", "_color", "_index"]; + + private _value = parseNumber ctrlText _ctrlColorEdit; + + private _controlsGroup = ctrlParentControlsGroup _ctrlColorEdit; + private _ctrlColor = _controlsGroup controlsGroupCtrl (IDCS_SETTING_COLOR select _index); + + _ctrlColor sliderSetPosition _value; + _value = sliderPosition _ctrlColor; + + _currentValue set [_index, _value]; + _color set [_index, _value]; + + private _ctrlColorPreview = _controlsGroup controlsGroupCtrl IDC_SETTING_COLOR_PREVIEW; + _ctrlColorPreview ctrlSetBackgroundColor _color; + + SET_TEMP_NAMESPACE_VALUE(_setting,_currentValue,_source); + + // if new value is same as default value, grey out the default button + private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + private _defaultValue = [_setting, "default"] call FUNC(get); + _ctrlDefault ctrlEnable !(_currentValue isEqualTo _defaultValue); + }]; + + _ctrlColorEdit ctrlAddEventHandler ["KillFocus", { + params ["_ctrlColorEdit"]; + (_ctrlColorEdit getVariable QGVAR(params)) params ["_setting", "_source", "_currentValue", "_color", "_index"]; + + private _controlsGroup = ctrlParentControlsGroup _ctrlColorEdit; + private _ctrlColor = _controlsGroup controlsGroupCtrl (IDCS_SETTING_COLOR select _index); + + private _value = sliderPosition _ctrlColor; + + _currentValue set [_index, _value]; + _color set [_index, _value]; + + _ctrlColorEdit ctrlSetText ([_value, 1, 2] call CBA_fnc_formatNumber); + + // if new value is same as default value, grey out the default button + private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + private _defaultValue = [_setting, "default"] call FUNC(get); + _ctrlDefault ctrlEnable !(_currentValue isEqualTo _defaultValue); + }]; +}; + +private _ctrlColorPreview = _controlsGroup controlsGroupCtrl IDC_SETTING_COLOR_PREVIEW; +_ctrlColorPreview ctrlSetBackgroundColor _color; +_ctrlColorPreview setVariable [QGVAR(color), _color]; + +// set setting ui manually to new value +_controlsGroup setVariable [QFUNC(updateUI), { + params ["_controlsGroup", "_value"]; + + private _ctrlColorPreview = _controlsGroup controlsGroupCtrl IDC_SETTING_COLOR_PREVIEW; + private _color = _ctrlColorPreview getVariable QGVAR(color); + + { + _color set [_forEachIndex, _x]; + + private _ctrlColor = _controlsGroup controlsGroupCtrl (IDCS_SETTING_COLOR select _forEachIndex); + _ctrlColor sliderSetPosition _x; + + private _ctrlColorEdit = _controlsGroup controlsGroupCtrl (IDCS_SETTING_COLOR_EDIT select _forEachIndex); + _ctrlColorEdit ctrlSetText ([_x, 1, 2] call CBA_fnc_formatNumber); + } forEach _value; + + _ctrlColorPreview ctrlSetBackgroundColor _color; + + private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + private _defaultValue = [_setting, "default"] call FUNC(get); + _ctrlDefault ctrlEnable !(_value isEqualTo _defaultValue); +}]; diff --git a/addons/settings/fnc_gui_settingDefault.sqf b/addons/settings/fnc_gui_settingDefault.sqf new file mode 100644 index 000000000..a2bb3d9ae --- /dev/null +++ b/addons/settings/fnc_gui_settingDefault.sqf @@ -0,0 +1,25 @@ +#include "script_component.hpp" + +params ["_controlsGroup", "_setting", "_source", "_currentValue", "_defaultValue"]; + +private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + +_ctrlDefault setVariable [QGVAR(params), [_setting, _source]]; +_ctrlDefault ctrlAddEventHandler ["ButtonClick", { + params ["_ctrlDefault"]; + (_ctrlDefault getVariable QGVAR(params)) params ["_setting", "_source"]; + + private _defaultValue = [_setting, "default"] call FUNC(get); + SET_TEMP_NAMESPACE_VALUE(_setting,_defaultValue,_source); + + // can disable button as the setting will now be the default + _ctrlDefault ctrlEnable false; + ctrlSetFocus (ctrlParent _ctrlDefault displayCtrl 999); + + private _controlsGroup = ctrlParentControlsGroup _ctrlDefault; + [_controlsGroup, _defaultValue] call (_controlsGroup getVariable QFUNC(updateUI)); +}]; + +if (_currentValue isEqualTo _defaultValue) then { + _ctrlDefault ctrlEnable false; +}; diff --git a/addons/settings/fnc_gui_settingEditbox.sqf b/addons/settings/fnc_gui_settingEditbox.sqf new file mode 100644 index 000000000..51484b136 --- /dev/null +++ b/addons/settings/fnc_gui_settingEditbox.sqf @@ -0,0 +1,34 @@ +#include "script_component.hpp" + +params ["_controlsGroup", "_setting", "_source", "_currentValue", "_settingData"]; + +private _ctrlEditbox = _controlsGroup controlsGroupCtrl IDC_SETTING_EDITBOX; +_ctrlEditbox ctrlSetText _currentValue; + +_ctrlEditbox setVariable [QGVAR(params), [_setting, _source]]; +_ctrlEditbox ctrlAddEventHandler ["KeyUp", { + params ["_ctrlEditbox"]; + (_ctrlEditbox getVariable QGVAR(params)) params ["_setting", "_source"]; + + private _value = ctrlText _ctrlEditbox; + SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source); + + // if new value is same as default value, grey out the default button + private _controlsGroup = ctrlParentControlsGroup _ctrlEditbox; + private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + private _defaultValue = [_setting, "default"] call FUNC(get); + _ctrlDefault ctrlEnable !(_value isEqualTo _defaultValue); +}]; + +// set setting ui manually to new value +_controlsGroup setVariable [QFUNC(updateUI), { + params ["_controlsGroup", "_value"]; + + private _ctrlEditbox = _controlsGroup controlsGroupCtrl IDC_SETTING_EDITBOX; + _ctrlEditbox ctrlSetText _value; + + // if new value is same as default value, grey out the default button + private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + private _defaultValue = [_setting, "default"] call FUNC(get); + _ctrlDefault ctrlEnable !(_value isEqualTo _defaultValue); +}]; diff --git a/addons/settings/fnc_gui_settingList.sqf b/addons/settings/fnc_gui_settingList.sqf new file mode 100644 index 000000000..ccfbb6648 --- /dev/null +++ b/addons/settings/fnc_gui_settingList.sqf @@ -0,0 +1,53 @@ +#include "script_component.hpp" + +params ["_controlsGroup", "_setting", "_source", "_currentValue", "_settingData"]; +_settingData params ["_values", "_labels"]; + +private _ctrlList = _controlsGroup controlsGroupCtrl IDC_SETTING_LIST; + +private _lbData = []; + +{ + private _label = _labels select _forEachIndex; + + if (isLocalized _label) then { + _label = localize _label; + }; + + private _index = _ctrlList lbAdd _label; + _lbData set [_index, _x]; +} forEach _values; + +_ctrlList lbSetCurSel (_values find _currentValue); + +_ctrlList setVariable [QGVAR(params), [_setting, _source, _lbData]]; +_ctrlList ctrlAddEventHandler ["LBSelChanged", { + EXIT_LOCKED; + params ["_ctrlList", "_index"]; + (_ctrlList getVariable QGVAR(params)) params ["_setting", "_source", "_lbData"]; + + private _value = _lbData select _index; + SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source); + + // if new value is same as default value, grey out the default button + private _controlsGroup = ctrlParentControlsGroup _ctrlList; + private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + private _defaultValue = [_setting, "default"] call FUNC(get); + _ctrlDefault ctrlEnable !(_value isEqualTo _defaultValue); +}]; + +// set setting ui manually to new value +_controlsGroup setVariable [QFUNC(updateUI), { + params ["_controlsGroup", "_value"]; + (_controlsGroup getVariable QGVAR(params)) params ["_values", "_labels"]; + + private _ctrlList = _controlsGroup controlsGroupCtrl IDC_SETTING_LIST; + LOCK; + _ctrlList lbSetCurSel (_values find _value); + UNLOCK; + + // if new value is same as default value, grey out the default button + private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + private _defaultValue = [_setting, "default"] call FUNC(get); + _ctrlDefault ctrlEnable !(_value isEqualTo _defaultValue); +}]; diff --git a/addons/settings/fnc_gui_settingOverwrite.sqf b/addons/settings/fnc_gui_settingOverwrite.sqf new file mode 100644 index 000000000..d44d22c3b --- /dev/null +++ b/addons/settings/fnc_gui_settingOverwrite.sqf @@ -0,0 +1,138 @@ +#include "script_component.hpp" + +params ["_controlsGroup", "_setting", "_source", "_currentPriority", "_isGlobal"]; + +private _ctrlOverwriteClient = _controlsGroup controlsGroupCtrl IDC_SETTING_OVERWRITE_CLIENT; +private _ctrlOverwriteMission = _controlsGroup controlsGroupCtrl IDC_SETTING_OVERWRITE_MISSION; + +if (_source isEqualTo "client") then { + _ctrlOverwriteClient ctrlEnable false; + _ctrlOverwriteClient ctrlSetPosition [0,0,-1,-1]; + _ctrlOverwriteClient ctrlCommit 0; +}; + +if !(_source isEqualTo "server") then { + _ctrlOverwriteMission ctrlEnable false; + _ctrlOverwriteMission ctrlSetPosition [0,0,-1,-1]; + _ctrlOverwriteMission ctrlCommit 0; +}; + +_ctrlOverwriteClient ctrlAddEventHandler ["CheckedChanged", { + params ["_ctrlOverwriteClient", "_state"]; + private _controlsGroup = ctrlParentControlsGroup _ctrlOverwriteClient; + private _ctrlOverwriteMission = _controlsGroup controlsGroupCtrl IDC_SETTING_OVERWRITE_MISSION; + private _setting = _controlsGroup getVariable QGVAR(setting); + private _source = _controlsGroup getVariable QGVAR(source); + + SET_TEMP_NAMESPACE_PRIORITY(_setting,_state,_source); + + _controlsGroup call (_controlsGroup getVariable QFUNC(updateUI_locked)); +}]; + +_ctrlOverwriteMission ctrlAddEventHandler ["CheckedChanged", { + params ["_ctrlOverwriteMission", "_state"]; + private _controlsGroup = ctrlParentControlsGroup _ctrlOverwriteMission; + private _ctrlOverwriteClient = _controlsGroup controlsGroupCtrl IDC_SETTING_OVERWRITE_CLIENT; + private _setting = _controlsGroup getVariable QGVAR(setting); + private _source = _controlsGroup getVariable QGVAR(source); + + if (_state isEqualTo 1) then { + _ctrlOverwriteClient setVariable [QGVAR(state), cbChecked _ctrlOverwriteClient]; + _ctrlOverwriteClient cbSetChecked true; + _ctrlOverwriteClient ctrlEnable false; + + SET_TEMP_NAMESPACE_PRIORITY(_setting,2,_source); + } else { + private _wasChecked = _ctrlOverwriteClient getVariable QGVAR(state); + _ctrlOverwriteClient cbSetChecked _wasChecked; + _ctrlOverwriteClient ctrlEnable (_ctrlOverwriteClient getVariable [QGVAR(enabled), true]); + + _state = [0,1] select _wasChecked; + SET_TEMP_NAMESPACE_PRIORITY(_setting,_state,_source); + }; + + _controlsGroup call (_controlsGroup getVariable QFUNC(updateUI_locked)); +}]; + +// update overwrite checkboxes +_controlsGroup setVariable [QFUNC(updateUI_priority), { + params ["_controlsGroup", "_priority"]; + + private _ctrlOverwriteClient = _controlsGroup controlsGroupCtrl IDC_SETTING_OVERWRITE_CLIENT; + private _ctrlOverwriteMission = _controlsGroup controlsGroupCtrl IDC_SETTING_OVERWRITE_MISSION; + + if (_priority > 1) then { + _ctrlOverwriteMission cbSetChecked true; + + _ctrlOverwriteClient cbSetChecked true; + _ctrlOverwriteClient ctrlEnable false; + } else { + _ctrlOverwriteMission cbSetChecked false; + + _ctrlOverwriteClient cbSetChecked (_priority > 0); + _ctrlOverwriteClient ctrlEnable (_ctrlOverwriteClient getVariable [QGVAR(enabled), true]); + }; + + _controlsGroup call (_controlsGroup getVariable QFUNC(updateUI_locked)); +}]; + +// update "locked" ui icon +_controlsGroup setVariable [QFUNC(updateUI_locked), { + params ["_controlsGroup"]; + private _setting = _controlsGroup getVariable QGVAR(setting); + private _priority = TEMP_PRIORITY(_setting); + + { + private _source = _x getVariable QGVAR(source); + private _ctrlLocked = _x controlsGroupCtrl IDC_SETTING_LOCKED; + + if (_source isEqualTo _priority) then { + _ctrlLocked ctrlSetText ""; + _ctrlLocked ctrlSetTooltip ""; + } else { + switch [_source, _priority] do { + case ["client","server"]; + case ["mission","server"]: { + _ctrlLocked ctrlSetText QPATHTOF(locked_ca.paa); + _ctrlLocked ctrlSetTooltip localize LSTRING(overwritten_by_server_tooltip); + }; + case ["client","mission"]; + case ["server","mission"]: { + _ctrlLocked ctrlSetText QPATHTOF(locked_ca.paa); + _ctrlLocked ctrlSetTooltip localize LSTRING(overwritten_by_mission_tooltip); + }; + case ["mission","client"]: { + _ctrlLocked ctrlSetText QPATHTOF(locked_ca.paa); + _ctrlLocked ctrlSetTooltip localize LSTRING(overwritten_by_client_tooltip); + }; + case ["server","client"]: { + if (isServer) then { + _ctrlLocked ctrlSetText ""; + _ctrlLocked ctrlSetTooltip ""; + } else { + _ctrlLocked ctrlSetText QPATHTOF(locked_ca.paa); + _ctrlLocked ctrlSetTooltip localize LSTRING(overwritten_by_client_tooltip_server); + }; + }; + }; + }; + } forEach (_controlsGroup getVariable QGVAR(groups)); +}]; + +[_controlsGroup, _currentPriority] call (_controlsGroup getVariable QFUNC(updateUI_priority)); +_ctrlOverwriteClient setVariable [QGVAR(state), cbChecked _ctrlOverwriteClient]; + +// disable certain checkboxes +if (_isGlobal > 0) then { + _ctrlOverwriteClient ctrlEnable false; + _ctrlOverwriteClient setVariable [QGVAR(enabled), false]; + + if (_isGlobal > 1) then { + _ctrlOverwriteClient ctrlSetPosition [0,0,-1,-1]; + _ctrlOverwriteClient ctrlCommit 0; + + _ctrlOverwriteMission ctrlEnable false; + _ctrlOverwriteMission ctrlSetPosition [0,0,-1,-1]; + _ctrlOverwriteMission ctrlCommit 0; + }; +}; diff --git a/addons/settings/fnc_gui_settingSlider.sqf b/addons/settings/fnc_gui_settingSlider.sqf new file mode 100644 index 000000000..4c6dd0107 --- /dev/null +++ b/addons/settings/fnc_gui_settingSlider.sqf @@ -0,0 +1,96 @@ +#include "script_component.hpp" + +params ["_controlsGroup", "_setting", "_source", "_currentValue", "_settingData"]; +_settingData params ["_min", "_max", "_trailingDecimals"]; + +private _ctrlSlider = _controlsGroup controlsGroupCtrl IDC_SETTING_SLIDER; + +_ctrlSlider sliderSetRange [_min, _max]; +_ctrlSlider sliderSetPosition _currentValue; + +_ctrlSlider setVariable [QGVAR(params), [_setting, _source, _trailingDecimals]]; +_ctrlSlider ctrlAddEventHandler ["SliderPosChanged", { + params ["_ctrlSlider", "_value"]; + (_ctrlSlider getVariable QGVAR(params)) params ["_setting", "_source", "_trailingDecimals"]; + + if (_trailingDecimals < 0) then { + _value = round _value; + }; + + private _controlsGroup = ctrlParentControlsGroup _ctrlSlider; + private _ctrlSliderEdit = _controlsGroup controlsGroupCtrl IDC_SETTING_SLIDER_EDIT; + _ctrlSliderEdit ctrlSetText ([_value, 1, _trailingDecimals] call CBA_fnc_formatNumber); + + SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source); + + // if new value is same as default value, grey out the default button + private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + private _defaultValue = [_setting, "default"] call FUNC(get); + _ctrlDefault ctrlEnable !(_value isEqualTo _defaultValue); +}]; + +private _ctrlSliderEdit = _controlsGroup controlsGroupCtrl IDC_SETTING_SLIDER_EDIT; +_ctrlSliderEdit ctrlSetText ([_currentValue, 1, _trailingDecimals] call CBA_fnc_formatNumber); + +_ctrlSliderEdit setVariable [QGVAR(params), [_setting, _source, _trailingDecimals]]; +_ctrlSliderEdit ctrlAddEventHandler ["KeyUp", { + params ["_ctrlSliderEdit"]; + (_ctrlSliderEdit getVariable QGVAR(params)) params ["_setting", "_source", "_trailingDecimals"]; + + private _value = parseNumber ctrlText _ctrlSliderEdit; + + if (_trailingDecimals < 0) then { + _value = round _value; + }; + + private _controlsGroup = ctrlParentControlsGroup _ctrlSliderEdit; + private _ctrlSlider = _controlsGroup controlsGroupCtrl IDC_SETTING_SLIDER; + + _ctrlSlider sliderSetPosition _value; + _value = sliderPosition _ctrlSlider; + + SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source); + + // if new value is same as default value, grey out the default button + private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + private _defaultValue = [_setting, "default"] call FUNC(get); + _ctrlDefault ctrlEnable !(_value isEqualTo _defaultValue); +}]; + +_ctrlSliderEdit ctrlAddEventHandler ["KillFocus", { + params ["_ctrlSliderEdit"]; + (_ctrlSliderEdit getVariable QGVAR(params)) params ["_setting", "_source", "_trailingDecimals"]; + + private _controlsGroup = ctrlParentControlsGroup _ctrlSliderEdit; + private _ctrlSlider = _controlsGroup controlsGroupCtrl IDC_SETTING_SLIDER; + + private _value = sliderPosition _ctrlSlider; + + if (_trailingDecimals < 0) then { + _value = round _value; + }; + + _ctrlSliderEdit ctrlSetText ([_value, 1, _trailingDecimals] call CBA_fnc_formatNumber); + + // if new value is same as default value, grey out the default button + private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + private _defaultValue = [_setting, "default"] call FUNC(get); + _ctrlDefault ctrlEnable !(_value isEqualTo _defaultValue); +}]; + +// set setting ui manually to new value +_controlsGroup setVariable [QFUNC(updateUI), { + params ["_controlsGroup", "_value"]; + (_controlsGroup getVariable QGVAR(params)) params ["_min", "_max", "_trailingDecimals"]; + + private _ctrlSlider = _controlsGroup controlsGroupCtrl IDC_SETTING_SLIDER; + private _ctrlSliderEdit = _controlsGroup controlsGroupCtrl IDC_SETTING_SLIDER_EDIT; + + _ctrlSlider sliderSetPosition _value; + _ctrlSliderEdit ctrlSetText ([_value, 1, _trailingDecimals] call CBA_fnc_formatNumber); + + // if new value is same as default value, grey out the default button + private _ctrlDefault = _controlsGroup controlsGroupCtrl IDC_SETTING_DEFAULT; + private _defaultValue = [_setting, "default"] call FUNC(get); + _ctrlDefault ctrlEnable !(_value isEqualTo _defaultValue); +}]; diff --git a/addons/settings/fnc_gui_sourceChanged.sqf b/addons/settings/fnc_gui_sourceChanged.sqf index 04af776d7..7023c32ea 100644 --- a/addons/settings/fnc_gui_sourceChanged.sqf +++ b/addons/settings/fnc_gui_sourceChanged.sqf @@ -6,7 +6,7 @@ params ["_control"]; // get dialog private _display = ctrlParent _control; -private _selectedSource = ["client", "server", "mission"] param [[IDC_BTN_CLIENT, IDC_BTN_SERVER, IDC_BTN_MISSION] find ctrlIDC _control]; +private _selectedSource = ["server", "mission", "client"] param [[IDC_BTN_SERVER, IDC_BTN_MISSION, IDC_BTN_CLIENT] find ctrlIDC _control]; uiNamespace setVariable [QGVAR(source), _selectedSource]; @@ -28,24 +28,19 @@ private _selectedAddon = uiNamespace getVariable QGVAR(addon); private _ctrlX = _display displayCtrl _x; _ctrlX ctrlSetTextColor ([COLOR_BUTTON_ENABLED, COLOR_BUTTON_DISABLED] select (_control == _ctrlX)); _ctrlX ctrlSetBackgroundColor ([COLOR_BUTTON_DISABLED, COLOR_BUTTON_ENABLED] select (_control == _ctrlX)); -} forEach [IDC_BTN_CLIENT, IDC_BTN_SERVER, IDC_BTN_MISSION]; +} forEach [IDC_BTN_SERVER, IDC_BTN_MISSION, IDC_BTN_CLIENT]; -(_display displayCtrl IDC_TXT_FORCE) ctrlShow (_selectedSource != "client"); +(_display displayCtrl IDC_TXT_OVERWRITE_CLIENT) ctrlShow !(_selectedSource isEqualTo "client"); +(_display displayCtrl IDC_TXT_OVERWRITE_MISSION) ctrlShow (_selectedSource isEqualTo "server"); // enable / disable IMPORT and LOAD buttons private _ctrlButtonImport = _display displayCtrl IDC_BTN_IMPORT; private _ctrlButtonLoad = _display displayCtrl IDC_BTN_LOAD; private _enabled = switch (_selectedSource) do { - case ("client"): { - CAN_SET_CLIENT_SETTINGS - }; - case ("server"): { - CAN_SET_SERVER_SETTINGS - }; - case ("mission"): { - CAN_SET_MISSION_SETTINGS - }; + case "server": {CAN_SET_SERVER_SETTINGS}; + case "mission": {CAN_SET_MISSION_SETTINGS}; + case "client": {CAN_SET_CLIENT_SETTINGS}; }; _ctrlButtonImport ctrlEnable _enabled; diff --git a/addons/settings/fnc_import.sqf b/addons/settings/fnc_import.sqf index f651ba849..0a59f4843 100644 --- a/addons/settings/fnc_import.sqf +++ b/addons/settings/fnc_import.sqf @@ -5,8 +5,8 @@ Description: Import all setting info from string. Parameters: - _info - Formated settings info, (from CBA_settings_fnc_export), (optional, default: clipboard) - _source - Can be "client", "server" or "mission" (optional, default: "client") + _info - Formated settings info, (from CBA_settings_fnc_export) + _source - Can be "client", "mission" or "server" (optional, default: "client") Returns: None @@ -18,13 +18,15 @@ Author: params [["_info", "", [""]], ["_source", "client", [""]]]; -_info = _info call FUNC(parse); +_info = [_info, true] call FUNC(parse); { - _x params ["_setting", "_value", "_force"]; + _x params ["_setting", "_value", "_priority"]; + + _priority = _priority min ([0,1,2] param [["client", "mission", "server"] find toLower _source, 0]); SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source); - SET_TEMP_NAMESPACE_FORCED(_setting,_force,_source); + SET_TEMP_NAMESPACE_PRIORITY(_setting,_priority,_source); } forEach _info; if (!isNull (uiNamespace getVariable [QGVAR(display), displayNull])) then { diff --git a/addons/settings/fnc_init.sqf b/addons/settings/fnc_init.sqf index db94907e8..dd03daee2 100644 --- a/addons/settings/fnc_init.sqf +++ b/addons/settings/fnc_init.sqf @@ -1,24 +1,22 @@ /* ---------------------------------------------------------------------------- -Internal Function: CBA_settings_fnc_init +Function: CBA_settings_fnc_init Description: Creates a new setting for that session. Parameters: _setting - Unique setting name. Matches resulting variable name - _settingType - Type of setting. Can be "CHECKBOX", "LIST", "SLIDER" or "COLOR" + _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 _valueInfo - Extra properties of the setting depending of _settingType. See examples below - _isGlobal - true: all clients share the same state of the setting (optional, default: false) - _script - Script to execute when setting is changed or forced. (optional) + _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) Returns: _return - Error code 0: Success, no error - 1: Empty setting name - 2: Empty menu category - 3: Wrong setting type (couldn't find correct default value) + 1: Failure, error Examples: (begin example) @@ -54,12 +52,19 @@ params [ ["_title", [], ["", []]], ["_category", "", [""]], ["_valueInfo", []], - ["_isGlobal", false, [false]], + ["_isGlobal", false, [false, 0]], ["_script", {}, [{}]] ]; -if (_setting isEqualTo "") exitWith {1}; -if (_category isEqualTo "") exitWith {2}; +if (_setting isEqualTo "") exitWith { + WARNING("Empty setting name"); + 1 +}; + +if (_category isEqualTo "") exitWith { + WARNING_1("Empty menu category for setting %1",_setting); + 1 +}; // --- setting title and tooltip _title params [["_displayName", "", [""]], ["_tooltip", "", [""]]]; @@ -68,15 +73,21 @@ if (_displayName isEqualTo "") then { _displayName = _setting; }; +// --- who can edit the setting +_isGlobal = [0,1,2] select _isGlobal; + // --- setting possible values and default ("data") private "_defaultValue"; private _settingData = []; switch (toUpper _settingType) do { - case ("CHECKBOX"): { + case "CHECKBOX": { _defaultValue = _valueInfo param [0, false, [false]]; // don't use params - we want these variables to be private to the main scope }; - case ("LIST"): { + case "EDITBOX": { + _defaultValue = _valueInfo param [0, "", [""]]; // don't use params - we want these variables to be private to the main scope + }; + case "LIST": { _valueInfo params [["_values", [], [[]]], ["_labels", [], [[]]], ["_defaultIndex", 0, [0]]]; if (_values isEqualTo []) then { @@ -102,58 +113,74 @@ switch (toUpper _settingType) do { _defaultValue = _values param [_defaultIndex]; _settingData append [_values, _labels]; }; - case ("SLIDER"): { + case "SLIDER": { _valueInfo params [["_min", 0, [0]], ["_max", 1, [0]], ["_default", 0, [0]], ["_trailingDecimals", 2, [0]]]; _defaultValue = _default; _settingData append [_min, _max, _trailingDecimals]; }; - case ("COLOR"): { + case "COLOR": { _defaultValue = [_valueInfo] param [0, [1,1,1], [[]], [3,4]]; }; default {/* _defaultValue undefined, exit below */}; }; -if (isNil "_defaultValue") exitWith {3}; +if (isNil "_defaultValue") exitWith { + WARNING_1("Wrong type for setting %1 (couldn't find default value)",_setting); + 1 +}; // --- add setting info to settings namespace -GVAR(defaultSettings) setVariable [_setting, [_defaultValue, _setting, _settingType, _settingData, _category, _displayName, _tooltip, _isGlobal, _script]]; -GVAR(allSettings) pushBackUnique _setting; +if (isNil {GVAR(default) getVariable _setting}) then { + GVAR(allSettings) pushBack _setting; +}; + +GVAR(default) setVariable [_setting, [_defaultValue, _setting, _settingType, _settingData, _category, _displayName, _tooltip, _isGlobal, _script]]; // --- read previous setting values from profile -private _settingsHash = profileNamespace getVariable [QGVAR(hash), NULL_HASH]; -private _settingInfo = [_settingsHash, toLower _setting] call CBA_fnc_hashGet; +private _settingInfo = GVAR(userconfig) getVariable _setting; + +if (isNil "_settingInfo") then { + private _settingsHash = profileNamespace getVariable [QGVAR(hash), HASH_NULL]; + _settingInfo = [_settingsHash, toLower _setting] call CBA_fnc_hashGet; +}; if (!isNil "_settingInfo") then { - _settingInfo params ["_value", "_forced"]; + _settingInfo params ["_value", "_priority"]; if !([_setting, _value] call FUNC(check)) then { + WARNING_2("Invalid value %1 for setting %2. Fall back to default value.",TO_STRING(_value),_setting); _value = [_setting, "default"] call FUNC(get); - [_setting, _value, _forced, "client"] call FUNC(set); - WARNING_1("Invalid value for setting %1. Fall back to default value.",str _setting); }; - GVAR(clientSettings) setVariable [_setting, [_value, _forced]]; + // convert boolean to number + _priority = [0,1,2] select _priority; - if (isServer && isMultiplayer) then { - GVAR(serverSettings) setVariable [_setting, [_value, _forced], true]; + GVAR(client) setVariable [_setting, [_value, _priority]]; + + if (isServer) then { + GVAR(server) setVariable [_setting, [_value, _priority], true]; }; }; // --- read previous setting values from mission -_settingsHash = getMissionConfigValue QGVAR(hash); +_settingInfo = GVAR(missionConfig) getVariable _setting; -if (isNil "_settingsHash") then { - _settingsHash = NULL_HASH; +if (isNil "_settingInfo") then { + private _settingsHash = getMissionConfigValue [QGVAR(hash), HASH_NULL]; + _settingInfo = [_settingsHash, toLower _setting] call CBA_fnc_hashGet; }; -_settingInfo = [_settingsHash, toLower _setting] call CBA_fnc_hashGet; - if (!isNil "_settingInfo") then { - _settingInfo params ["_value", "_forced"]; + _settingInfo params ["_value", "_priority"]; + + // convert boolean to number + _priority = [0,1,2] select _priority; if ([_setting, _value] call FUNC(check)) then { - GVAR(missionSettings) setVariable [_setting, [_value, _forced]]; + GVAR(mission) setVariable [_setting, [_value, _priority]]; + } else { + WARNING_2("Value %1 is invalid for setting %2.",TO_STRING(_value),_setting); }; }; diff --git a/addons/settings/fnc_init3DEN.sqf b/addons/settings/fnc_init3DEN.sqf deleted file mode 100644 index c6f4da5b5..000000000 --- a/addons/settings/fnc_init3DEN.sqf +++ /dev/null @@ -1,15 +0,0 @@ -#include "script_component.hpp" - -private _fnc_resetMissionSettings = { - // --- delete settings from previous mission - GVAR(missionSettings) call CBA_fnc_deleteNamespace; - GVAR(missionSettings) = [] call CBA_fnc_createNamespace; - - GVAR(hash) = nil; - - // --- initialize settings of new mission - #include "initMissionSettings.sqf" -}; - -add3DENEventHandler ["onMissionNew", _fnc_resetMissionSettings]; -add3DENEventHandler ["onMissionLoad", _fnc_resetMissionSettings]; diff --git a/addons/settings/fnc_initDisplay3DEN.sqf b/addons/settings/fnc_initDisplay3DEN.sqf new file mode 100644 index 000000000..7358d9974 --- /dev/null +++ b/addons/settings/fnc_initDisplay3DEN.sqf @@ -0,0 +1,102 @@ +#include "script_component.hpp" + +private _fnc_resetMissionSettings = { + GVAR(mission) call CBA_fnc_deleteNamespace; + GVAR(mission) = [] call CBA_fnc_createNamespace; + + // --- read mission settings file + GVAR(missionConfig) call CBA_fnc_deleteNamespace; + GVAR(missionConfig) = [] call CBA_fnc_createNamespace; + + private _missionConfig = ""; + + if (getMissionConfigValue [QGVAR(hasSettingsFile), false]) then { + INFO("Loading mission settings file ..."); + _missionConfig = preprocessFile MISSION_SETTINGS_FILE; + }; + + { + _x params ["_setting", "_value", "_priority"]; + + GVAR(missionConfig) setVariable [_setting, [_value, _priority]]; + } forEach ([_missionConfig, false] call FUNC(parse)); + + { + private _setting = _x; + private _settingInfo = GVAR(missionConfig) getVariable _setting; + + if (isNil "_settingInfo") then { + private _settingsHash = findDisplay 313 getVariable [QGVAR(hash), HASH_NULL]; + _settingInfo = [_settingsHash, toLower _setting] call CBA_fnc_hashGet; + }; + + if (!isNil "_settingInfo") then { + _settingInfo params ["_value", "_priority"]; + + // convert boolean to number + _priority = [0,1,2] select _priority; + + if ([_setting, _value] call FUNC(check)) then { + GVAR(mission) setVariable [_setting, [_value, _priority]]; + }; + }; + } forEach GVAR(allSettings); + + QGVAR(refreshAllSettings) call CBA_fnc_localEvent; +}; + +add3DENEventHandler ["OnMissionPreview", _fnc_resetMissionSettings]; +add3DENEventHandler ["OnMissionPreviewEnd", compile format ["0 spawn {isNil %1}", _fnc_resetMissionSettings]]; // delay a bit for preInit to run + +private _fnc_resetMissionSettingsMissionChanged = compile format [ + 'findDisplay 313 setVariable [QGVAR(hash), "Scenario" get3DENMissionAttribute QGVAR(hash)]; call %1', + _fnc_resetMissionSettings +]; + +add3DENEventHandler ["OnMissionNew", _fnc_resetMissionSettingsMissionChanged]; +add3DENEventHandler ["OnMissionLoad", _fnc_resetMissionSettingsMissionChanged]; + +// Missions crash on dedicated servers if there is a file missing during init. +// Thus we check if the mission settings file exists when saving / exporting +// the mission instead and set a flag. The 3den eventhandlers for saving a +// mission fire after the mission was saved, so we have to repeat the action +// after we update the flag. +#define MESSGAE_SAVED 0 +#define MESSGAE_AUTOSAVED 1 +#define MESSAGE_EXPORTED_SP 5 +#define MESSAGE_EXPORTED_MP 6 + +#define FILE_EXISTS(file) \ +call {\ + private _control = findDisplay 313 ctrlCreate ["RscHTML", -1];\ + _control htmlLoad file;\ + private _return = ctrlHTMLLoaded _control;\ + ctrlDelete _control;\ + _return\ +}; + +add3DENEventHandler ["OnMessage", { + params ["_message"]; + + if !(_message in [MESSGAE_SAVED, MESSAGE_EXPORTED_SP, MESSAGE_EXPORTED_MP]) exitWith {}; + + INFO("Checking mission settings file ..."); + private _fileExists = FILE_EXISTS(MISSION_SETTINGS_FILE); + private _fileExistedPreviously = "Scenario" get3DENMissionAttribute QGVAR(hasSettingsFile); + + if !(_fileExists isEqualTo _fileExistedPreviously) then { + set3DENMissionAttributes [["Scenario", QGVAR(hasSettingsFile), _fileExists]]; + + switch (_message) do { + case MESSGAE_SAVED: { + do3DENAction "MissionSave"; + }; + case MESSAGE_EXPORTED_SP: { + do3DENAction "MissionExportSP"; + }; + case MESSAGE_EXPORTED_MP: { + do3DENAction "MissionExportMP"; + }; + }; + }; +}]; diff --git a/addons/settings/fnc_gui_initDisplay.sqf b/addons/settings/fnc_initDisplayGameOptions.sqf similarity index 52% rename from addons/settings/fnc_gui_initDisplay.sqf rename to addons/settings/fnc_initDisplayGameOptions.sqf index 03a861f78..60bcafe9d 100644 --- a/addons/settings/fnc_gui_initDisplay.sqf +++ b/addons/settings/fnc_initDisplayGameOptions.sqf @@ -1,30 +1,60 @@ #include "script_component.hpp" params ["_display"]; - uiNamespace setVariable [QGVAR(display), _display]; -// ----- create addons list (filled later) private _ctrlAddonsGroup = _display displayCtrl IDC_ADDONS_GROUP; -private _ctrlAddonList = _display ctrlCreate [QGVAR(AddonsList), -1, _ctrlAddonsGroup]; +private _ctrlServerButton = _display displayCtrl IDC_BTN_SERVER; +private _ctrlMissionButton = _display displayCtrl IDC_BTN_MISSION; +private _ctrlClientButton = _display displayCtrl IDC_BTN_CLIENT; + +// ----- hide and disable the custom controls by default +{ + _x ctrlEnable false; + _x ctrlShow false; +} forEach [_ctrlAddonsGroup, _ctrlServerButton, _ctrlMissionButton, _ctrlClientButton]; + +// ----- disable in main menu +if (isNil QUOTE(ADDON)) exitWith { + private _ctrlToggleButton = _display displayCtrl IDC_BTN_CONFIGURE_ADDONS; + + _ctrlToggleButton ctrlEnable false; +}; -_ctrlAddonsGroup ctrlEnable false; -_ctrlAddonsGroup ctrlShow false; +// ----- situational tooltips +if (!isMultiplayer) then { + _ctrlServerButton ctrlSetTooltip localize LSTRING(ButtonClient_tooltip); +}; + +if (is3DEN) then { + _ctrlMissionButton ctrlSetTooltip localize LSTRING(ButtonMission_tooltip_3den); +}; + +if (isServer) then { + _ctrlClientButton ctrlSetTooltip ""; +}; + +// ----- create temporary setting namespaces +with uiNamespace do { + GVAR(clientTemp) = _display ctrlCreate ["RscText", -1]; + GVAR(missionTemp) = _display ctrlCreate ["RscText", -1]; + GVAR(serverTemp) = _display ctrlCreate ["RscText", -1]; +}; -_ctrlAddonList ctrlAddEventHandler ["LBSelChanged", FUNC(gui_addonChanged)]; +// ----- create addons list (filled later) +private _ctrlAddonList = _display ctrlCreate [QGVAR(AddonsList), -1, _ctrlAddonsGroup]; + +_ctrlAddonList ctrlAddEventHandler ["LBSelChanged", {_this call FUNC(gui_addonChanged)}]; private _categories = []; // ----- create settings lists - #include "gui_createMenu.sqf" // ----- fill addons list { private _category = _x; - private _index = _ctrlAddonList lbAdd _category; - _ctrlAddonList lbSetData [_index, str _index]; _display setVariable [str _index, _category]; } forEach _categories; @@ -65,13 +95,13 @@ _ctrlButtonLoad ctrlEnable false; _ctrlButtonLoad ctrlShow false; _ctrlButtonLoad ctrlAddEventHandler ["ButtonClick", {[ctrlParent (_this select 0), "load"] call FUNC(gui_preset)}]; +// ----- create export and import buttons // copyFromClipboard has no effect in MP, so only add button in SP if (!isMultiplayer) then { - // ----- create export and import buttons private _ctrlButtonImport = _display ctrlCreate ["RscButtonMenu", IDC_BTN_IMPORT]; _ctrlButtonImport ctrlSetPosition [ - POS_X(24.4), + POS_X(26.4), POS_Y(20.5), POS_W(6), POS_H(1) @@ -82,44 +112,41 @@ if (!isMultiplayer) then { _ctrlButtonImport ctrlSetTooltip localize LSTRING(ButtonImport_tooltip); _ctrlButtonImport ctrlEnable false; _ctrlButtonImport ctrlShow false; - _ctrlButtonImport ctrlAddEventHandler ["ButtonClick", {[copyFromClipboard, uiNamespace getVariable QGVAR(source)] call FUNC(import)}]; - - uiNamespace setVariable [QGVAR(ctrlButtonImport), _ctrlButtonImport]; + _ctrlButtonImport ctrlAddEventHandler ["ButtonClick", { + [copyFromClipboard, uiNamespace getVariable QGVAR(source)] call FUNC(import); + }]; }; -private _ctrlButtonExport = _display ctrlCreate ["RscButtonMenu", IDC_BTN_EXPORT]; - -_ctrlButtonExport ctrlSetPosition [ - POS_X(30.5), - POS_Y(20.5), - POS_W(6), - POS_H(1) -]; +// copyToClipboard only works in SP or on the server, so only add button if isServer +if (isServer) then { + private _ctrlButtonExport = _display ctrlCreate ["RscButtonMenu", IDC_BTN_EXPORT]; -_ctrlButtonExport ctrlCommit 0; -_ctrlButtonExport ctrlSetText localize LSTRING(ButtonExport); -_ctrlButtonExport ctrlSetTooltip localize LSTRING(ButtonExport_tooltip); -_ctrlButtonExport ctrlEnable false; -_ctrlButtonExport ctrlShow false; -_ctrlButtonExport ctrlAddEventHandler ["ButtonClick", {copyToClipboard ([uiNamespace getVariable QGVAR(source)] call FUNC(export))}]; + _ctrlButtonExport ctrlSetPosition [ + POS_X(32.5), + POS_Y(20.5), + POS_W(6), + POS_H(1) + ]; -uiNamespace setVariable [QGVAR(ctrlButtonExport), _ctrlButtonExport]; + _ctrlButtonExport ctrlCommit 0; + _ctrlButtonExport ctrlSetText localize LSTRING(ButtonExport); + _ctrlButtonExport ctrlSetTooltip localize LSTRING(ButtonExport_tooltip); + _ctrlButtonExport ctrlEnable false; + _ctrlButtonExport ctrlShow false; + _ctrlButtonExport ctrlAddEventHandler ["ButtonClick", { + copyToClipboard ([uiNamespace getVariable QGVAR(source)] call FUNC(export)); + }]; +}; -// ----- source buttons (client, server, mission) +// ----- source buttons (server, mission, client) { - _x ctrlEnable false; - _x ctrlShow false; _x ctrlAddEventHandler ["ButtonClick", FUNC(gui_sourceChanged)]; -} forEach [_display displayCtrl IDC_BTN_CLIENT, _display displayCtrl IDC_BTN_SERVER, _display displayCtrl IDC_BTN_MISSION]; +} forEach [_ctrlServerButton, _ctrlMissionButton, _ctrlClientButton]; -GVAR(clientSettingsTemp) = [] call CBA_fnc_createNamespace; -GVAR(serverSettingsTemp) = [] call CBA_fnc_createNamespace; -GVAR(missionSettingsTemp) = [] call CBA_fnc_createNamespace; - -(_display displayCtrl IDC_BTN_CONFIGURE_ADDONS) ctrlAddEventHandler ["ButtonClick", FUNC(gui_configure)]; +(_display displayCtrl IDC_BTN_CONFIGURE_ADDONS) ctrlAddEventHandler ["ButtonClick", {_this call FUNC(gui_configure)}]; // ----- scripted OK button -(_display displayCtrl 999) ctrlAddEventHandler ["ButtonClick", {true call FUNC(gui_closeMenu)}]; - -// set this per script to avoid it being all upper case -(_display displayCtrl IDC_TXT_FORCE) ctrlSetText localize LSTRING(force); +(_display displayCtrl 999) ctrlAddEventHandler ["ButtonClick", { + call FUNC(gui_saveTempData); + ctrlParent (_this select 0) closeDisplay IDC_OK; +}]; diff --git a/addons/settings/fnc_initDisplayMain.sqf b/addons/settings/fnc_initDisplayMain.sqf new file mode 100644 index 000000000..8243ee1f1 --- /dev/null +++ b/addons/settings/fnc_initDisplayMain.sqf @@ -0,0 +1,36 @@ +#include "script_component.hpp" + +// --- load userconfig file +params ["_display"]; + +private _file = ""; + +if (isClass (configFile >> "CfgPatches" >> QGVAR(userconfig))) then { + _file = USERCONFIG_SETTINGS_FILE_ADDON; +} else { + if (isFilePatchingEnabled) then { + _file = USERCONFIG_SETTINGS_FILE; + }; +}; + +private _userconfig = ""; + +if (_file != "") then { + INFO("Loading userconfig file ..."); + private _fileExists = false; + + if (!isNull _display) then { + private _control = _display ctrlCreate ["RscHTML", -1]; + _control htmlLoad USERCONFIG_SETTINGS_FILE; + _fileExists = ctrlHTMLLoaded _control; + ctrlDelete _control; + } else { + _fileExists = loadFile USERCONFIG_SETTINGS_FILE != ""; + }; + + if (_fileExists) then { + _userconfig = preprocessFile USERCONFIG_SETTINGS_FILE; + }; +}; + +uiNamespace setVariable [QGVAR(userconfig), compileFinal str _userconfig]; diff --git a/addons/settings/fnc_isForced.sqf b/addons/settings/fnc_isForced.sqf deleted file mode 100644 index 0a675d0a1..000000000 --- a/addons/settings/fnc_isForced.sqf +++ /dev/null @@ -1,32 +0,0 @@ -/* ---------------------------------------------------------------------------- -Internal Function: CBA_settings_fnc_isForced - -Description: - Check if setting is forced. - -Parameters: - _setting - Name of the setting - _source - Can be "client", "server" or "mission" (optional, default: "client") - -Returns: - _forced - Whether or not the setting is forced - -Author: - commy2 ----------------------------------------------------------------------------- */ -#include "script_component.hpp" - -params [["_setting", "", [""]], ["_source", "client", [""]]]; - -switch (toLower _source) do { - case ("client"): { - GET_FORCED(clientSettings,_setting); - }; - case ("server"): { - GET_FORCED(serverSettings,_setting) || {(!GET_FORCED(missionSettings,_setting)) && {(isMultiplayer && {NAMESPACE_GETVAR(GVAR(defaultSettings),_setting,[]) param [7, false]})}}; - }; - case ("mission"): { - GET_FORCED(missionSettings,_setting); - }; - default {nil}; -}; diff --git a/addons/settings/fnc_isOverwritten.sqf b/addons/settings/fnc_isOverwritten.sqf deleted file mode 100644 index 79bd8bde5..000000000 --- a/addons/settings/fnc_isOverwritten.sqf +++ /dev/null @@ -1,32 +0,0 @@ -/* ---------------------------------------------------------------------------- -Internal Function: CBA_settings_fnc_isOverwritten - -Description: - Check if setting is overwritten by higher priority source. - -Parameters: - _setting - Name of the setting - _source - Can be "client", "server" or "mission" (optional, default: "client") - -Returns: - _overwritten - Whether or not the setting is overwritten - -Author: - commy2 ----------------------------------------------------------------------------- */ -#include "script_component.hpp" - -params [["_setting", "", [""]], ["_source", "client", [""]]]; - -switch (toLower _source) do { - case ("client"): { - [_setting, "mission"] call FUNC(isForced) || {[_setting, "server"] call FUNC(isForced)} - }; - case ("server"): { - (!([_setting, "server"] call FUNC(isForced))) && {[_setting, "mission"] call FUNC(isForced)} - }; - case ("mission"): { - (!([_setting, "mission"] call FUNC(isForced))) || {[_setting, "server"] call FUNC(isForced)} - }; - default {nil}; -}; diff --git a/addons/settings/fnc_parse.sqf b/addons/settings/fnc_parse.sqf index ac16290ab..9a6a3e56e 100644 --- a/addons/settings/fnc_parse.sqf +++ b/addons/settings/fnc_parse.sqf @@ -2,111 +2,90 @@ Internal Function: CBA_settings_fnc_parse Description: - Copy all setting info into clipboard. + Convert settings in file format into array. Parameters: - _info - Content of file or clipboard to parse. + _info - Content of file or clipboard to parse. + _validate - Check if settings are valid. (optional, default: false) Returns: - Settings with values and forced states. + Settings with values and priority states. Author: commy2 ---------------------------------------------------------------------------- */ #include "script_component.hpp" -#define ASCII_NEWLINE 10 -#define ASCII_CARRIAGE_RETURN 13 -#define ASCII_TAB 9 -#define ASCII_SPACE 32 +// parses bool, number, string +private _fnc_parseAny = { + params ["_string"]; -#define WHITE_SPACE [ASCII_NEWLINE, ASCII_CARRIAGE_RETURN, ASCII_TAB, ASCII_SPACE] + // Remove whitespace so parseSimpleArray can handle arrays. + // Means that strings inside arrays don't support white space chars, but w/e. + // No such setting exists atm anyway. + if (_string find """" != 0) then { + _string = _string splitString WHITESPACE joinString ""; + }; -#define KEYWORD_FORCE "force" -#define QUOTE_MARKS toArray """'" -#define ALL_NUMBERS toArray "0123456789" -#define ASCII_ARRAY_OPEN (toArray "[" select 0) -#define ASCII_ARRAY_CLOSE (toArray "]" select 0) + parseSimpleArray format ["[%1]", _string] select 0 +}; -private _fnc_parseArray = { - params [["_array", "", [""]]]; - _array = _array call CBA_fnc_trim; +params [["_info", "", [""]], ["_validate", false, [false]]]; - if ((_array select [0,1]) isEqualTo "[" && {(_array select [count _array - 1]) isEqualTo "]"}) then { - _array = (_array select [1, count _array - 2]) splitString ","; +// remove whitespace at start and end of each line +private _result = []; - // parse numbers and strings - _array = _array apply { - _x = _x call CBA_fnc_trim; +{ + _result pushBack (_x call CBA_fnc_trim); +} forEach (_info splitString NEWLINE); - if ((_x select [0,1]) isEqualTo """") then { - _x select [1, count _x - 2] - } else { - parseNumber _x; - }; - }; +_info = (_result joinString NEWLINE) + NEWLINE; - _array - } else { - [] - }; -}; +// separate statements (setting = value) +_result = []; -params [["_info", "", [""]]]; +{ + private _indexEqualSign = _x find "="; -private _result = []; + private _setting = (_x select [0, _indexEqualSign]) call CBA_fnc_rightTrim; + private _value = ((_x select [_indexEqualSign + 1]) call CBA_fnc_trim) call _fnc_parseAny; + private _priority = 0; -{ - private _statement = _x; + if (_setting select [0, count "force"] == "force") then { + _setting = _setting select [count "force"] call CBA_fnc_leftTrim; + _priority = _priority + 1; + }; - private _force = false; - if ((_statement splitString toString WHITE_SPACE) param [0, ""] == KEYWORD_FORCE) then { - _force = true; - _statement = _statement select [(toLower _statement find KEYWORD_FORCE) + count KEYWORD_FORCE]; + if (_setting select [0, count "force"] == "force") then { + _setting = _setting select [count "force"] call CBA_fnc_leftTrim; + _priority = _priority + 1; }; - _setting = (_statement select [0, _statement find "="]) call CBA_fnc_trim; - _value = (_statement select [(_statement find "=") + 1]) call CBA_fnc_trim; + if !(_setting isEqualTo "") then { + if !(_validate) then { + _result pushBack [_setting, _value, _priority]; + } else { + if (isNil {[_setting, "default"] call FUNC(get)}) exitWith { + ERROR_1("Error parsing settings file. Setting %1 does not exist.",_setting); + }; - if (_setting != "") then { - private _value0 = toArray (_value select [0,1]) select 0; - private _valueE = toArray (_value select [count _value - 1]) select 0; + if !([_setting, _value] call FUNC(check)) exitWith { + ERROR_2("Error parsing settings file. Value %1 is invalid for setting %2.",TO_STRING(_value),_setting); + }; - _value = switch (true) do { - //--- boolean - case (_value == "true"): { - true - }; - case (_value == "false"): { - false - }; - //--- number - case (_value0 in ALL_NUMBERS): { - parseNumber _value - }; - //--- string - case (_value0 in QUOTE_MARKS && {_valueE in QUOTE_MARKS}): { - _value select [1, count _value - 2] - }; - //--- array - case (_value0 == ASCII_ARRAY_OPEN && {_valueE == ASCII_ARRAY_CLOSE}): { - _value call _fnc_parseArray - }; - default {nil}; - }; + private _isGlobal = GVAR(default) getVariable [_setting, []] param [7, 0]; - private _currentValue = [_setting, "default"] call FUNC(get); + if (_isGlobal isEqualTo 1) then { + _priority = _priority max 1; + }; - if (isNil "_currentValue") then { - ERROR_1("Error parsing settings file. Setting %1 does not exist.",str _setting); - } else { - if ([_setting, _value] call FUNC(check)) then { - _result pushBack [_setting, _value, _force]; - } else { - ERROR_2("Error parsing settings file. Value %1 is invalid for setting %2.",_value,str _setting); + if (_isGlobal isEqualTo 2) then { + _priority = _priority min 0; }; + + _result pushBack [_setting, _value, _priority]; }; }; -} forEach (_info splitString ";"); +} forEach ([_info, ";" + NEWLINE] call CBA_fnc_split); _result diff --git a/addons/settings/fnc_priority.sqf b/addons/settings/fnc_priority.sqf new file mode 100644 index 000000000..a9338acb4 --- /dev/null +++ b/addons/settings/fnc_priority.sqf @@ -0,0 +1,64 @@ +/* ---------------------------------------------------------------------------- +Internal Function: CBA_settings_fnc_priority + +Description: + Check which source of the setting is set to the highest priority. + +Parameters: + _setting - Name of the setting + _source - Can be "client", "mission", "server" or "priority" (optional, default: "priority") + +Returns: + _source - + If _source = "priority": source with highest priority + Otherwise: priority of given _source + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" + +params [["_setting", "", [""]], ["_source", "priority", [""]]]; + +private _isGlobal = GVAR(default) getVariable [_setting, []] param [7, 0]; + +switch (toLower _source) do { + case "client": { + (GVAR(client) getVariable [_setting, [nil, 0]] select 1) min 0 + }; + case "mission": { + private _priority = (GVAR(mission) getVariable [_setting, [nil, 0]] select 1) min 1; + + if (_isGlobal isEqualTo 1) exitWith { + _priority max 1 + }; + + if (_isGlobal isEqualTo 2) exitWith { + _priority min 0 + }; + + _priority + }; + case "server": { + private _priority = (GVAR(server) getVariable [_setting, [nil, 0]] select 1) min 2; + + if (_isGlobal isEqualTo 1) exitWith { + _priority max 1 + }; + + if (_isGlobal isEqualTo 2) exitWith { + _priority min 0 + }; + + _priority + }; + case "priority": { + private _arr = [ + [_setting, "client"] call FUNC(priority), + [_setting, "mission"] call FUNC(priority), + [_setting, "server"] call FUNC(priority) + ]; + ["client", "mission", "server"] select (_arr find selectMax _arr) + }; + default {0}; +}; diff --git a/addons/settings/fnc_set.sqf b/addons/settings/fnc_set.sqf index c3f98c5e8..356f2d88b 100644 --- a/addons/settings/fnc_set.sqf +++ b/addons/settings/fnc_set.sqf @@ -5,20 +5,14 @@ Description: Set the value of a setting. Parameters: - _setting - Name of the setting - _value - Value of the setting - _forced - Force setting? - _source - Can be "client", "server" or "mission" (optional, default: "client") + _setting - Name of the setting + _value - Value of the setting + _priority - New setting priority + _source - Can be "client", "mission" or "server" (optional, default: "client") + _store - Store changed setting in profile or mission (optional, default: false) Returns: - _return - Error code - 0: succes - 1: invalid value for setting - 2: new setting and forced state are the same as the previous ones - 10: invalid source - 11: server source, but in SP - 12: server source, but no access - 13: mission source, but not in 3DEN editor + _return - Success Examples: (begin example) @@ -30,74 +24,96 @@ Author: ---------------------------------------------------------------------------- */ #include "script_component.hpp" -params [["_setting", "", [""]], "_value", ["_forced", nil, [false]], ["_source", "client", [""]]]; +// prevent race conditions. function could be called from scheduled env. +if (canSuspend) exitWith { + [FUNC(set), _this] call CBA_fnc_directCall; +}; + +params [["_setting", "", [""]], "_value", ["_priority", 0, [false, 0]], ["_source", "client", [""]], ["_store", false, [false]]]; + +if (isNil "_value") then { + _value = [_setting, "default"] call FUNC(get); +}; -if (!isNil "_value" && {!([_setting, _value] call FUNC(check))}) exitWith { - WARNING_2("Value %1 is invalid for setting %2.",_value,str _setting); - 1 +if !([_setting, _value] call FUNC(check)) exitWith { + WARNING_2("Value %1 is invalid for setting %2.",TO_STRING(_value),_setting); + false }; private _currentValue = [_setting, _source] call FUNC(get); -private _currentForced = [_setting, _source] call FUNC(isForced); +private _currentPriority = [_setting, _source] call FUNC(priority); -if (isNil "_forced") then { - _forced = _currentForced; +if (_value isEqualTo _currentValue && {_priority isEqualTo _currentPriority}) exitWith { + WARNING_3("Value %1 and priority %2 are the same as previously for setting %3.",TO_STRING(_value),_priority,_setting); + false }; -if (!isNil "_currentValue" && {_value isEqualTo _currentValue} && {_forced isEqualTo _currentForced}) exitWith {2}; - -private _return = 0; +private _return = true; switch (toLower _source) do { - case ("client"): { - // flag is used for server settings exclusively, keep previous state - _forced = [_setting, _source] call FUNC(isForced); + case "client": { + GVAR(client) setVariable [_setting, [_value, _priority]]; - GVAR(clientSettings) setVariable [_setting, [_value, _forced]]; + if (_store) then { + if (!isNil {GVAR(userconfig) getVariable _setting}) exitWith { + WARNING_1("Cannot change setting %1 defined in userconfig file.",_setting); + }; - private _settingsHash = profileNamespace getVariable [QGVAR(hash), NULL_HASH]; - [_settingsHash, toLower _setting, [_value, _forced]] call CBA_fnc_hashSet; - profileNamespace setVariable [QGVAR(hash), _settingsHash]; + private _settingsHash = profileNamespace getVariable [QGVAR(hash), HASH_NULL]; + [_settingsHash, toLower _setting, [_value, _priority]] call CBA_fnc_hashSet; + profileNamespace setVariable [QGVAR(hash), _settingsHash]; + }; [QGVAR(refreshSetting), _setting] call CBA_fnc_localEvent; }; - case ("server"): { - if (!isMultiplayer) exitWith { - _return = 11; + case "mission": { + GVAR(mission) setVariable [_setting, [_value, _priority]]; + + if (_store) then { + if (!is3DEN) exitWith { + WARNING_1("Source is mission, but not in 3DEN editor. Setting: %1",_setting); + }; + + if (!isNil {GVAR(missionConfig) getVariable _setting}) exitWith { + WARNING_1("Cannot change setting %1 defined in mission settings file.",_setting); + }; + + private _settingsHash = "Scenario" get3DENMissionAttribute QGVAR(hash); + [_settingsHash, toLower _setting, [_value, _priority]] call CBA_fnc_hashSet; + set3DENMissionAttributes [["Scenario", QGVAR(hash), _settingsHash]]; + findDisplay 313 setVariable [QGVAR(hash), _settingsHash]; }; + [QGVAR(refreshSetting), _setting] call CBA_fnc_localEvent; + }; + case "server": { if (isServer) then { - GVAR(clientSettings) setVariable [_setting, [_value, _forced]]; - GVAR(serverSettings) setVariable [_setting, [_value, _forced], true]; + GVAR(client) setVariable [_setting, [_value, _priority]]; + GVAR(server) setVariable [_setting, [_value, _priority], true]; - private _settingsHash = profileNamespace getVariable [QGVAR(hash), NULL_HASH]; - [_settingsHash, toLower _setting, [_value, _forced]] call CBA_fnc_hashSet; - profileNamespace setVariable [QGVAR(hash), _settingsHash]; + if (_store) then { + if (!isNil {GVAR(serverConfig) getVariable _setting}) exitWith { + WARNING_1("Cannot change setting %1 defined in server config file.",_setting); + }; + + private _settingsHash = profileNamespace getVariable [QGVAR(hash), HASH_NULL]; + [_settingsHash, toLower _setting, [_value, _priority]] call CBA_fnc_hashSet; + profileNamespace setVariable [QGVAR(hash), _settingsHash]; + }; [QGVAR(refreshSetting), _setting] call CBA_fnc_globalEvent; } else { if (IS_ADMIN_LOGGED) then { - [QGVAR(setSettingServer), [_setting, _value, _forced]] call CBA_fnc_serverEvent; + [QGVAR(setSettingServer), [_setting, _value, _priority, _store]] call CBA_fnc_serverEvent; } else { - _return = 12; + WARNING_1("Source is server, but no admin access. Setting: %1",_setting); + _return = false; }; }; }; - case ("mission"): { - if (!is3DEN) exitWith { - _return = 13; - }; - - GVAR(missionSettings) setVariable [_setting, [_value, _forced]]; - - private _settingsHash = "Scenario" get3DENMissionAttribute QGVAR(hash); - [_settingsHash, toLower _setting, [_value, _forced]] call CBA_fnc_hashSet; - set3DENMissionAttributes [["Scenario", QGVAR(hash), _settingsHash]]; - - [QGVAR(refreshSetting), _setting] call CBA_fnc_localEvent; - }; default { - _return = 10; + WARNING_2("Invalid source %1 for setting %2",_source,_setting); + _return = false; }; }; diff --git a/addons/settings/gui.hpp b/addons/settings/gui.hpp index c7a241f77..be23292b1 100644 --- a/addons/settings/gui.hpp +++ b/addons/settings/gui.hpp @@ -1,62 +1,7 @@ -class RscControlsGroup { - class VScrollbar; - class HScrollbar; -}; - -class RscTitle; -class RscText; -class CBA_Rsc_SettingText: RscText { - style = 0x01; -}; - -class RscEdit; -class RscCombo; -class RscListBox; class RscButtonMenu; - -// can't set the colorDisable with SQF, so we have to create our own base classes when we want to use these with ctrlCreate -class RscXSliderH; -class CBA_Rsc_Slider_R: RscXSliderH { - color[] = {1,0,0,0.6}; - colorActive[] = {1,0,0,1}; - colorDisable[] = {1,0,0,0.4}; -}; -class CBA_Rsc_Slider_G: RscXSliderH { - color[] = {0,1,0,0.6}; - colorActive[] = {0,1,0,1}; - colorDisable[] = {0,1,0,0.4}; -}; -class CBA_Rsc_Slider_B: RscXSliderH { - color[] = {0,0,1,0.6}; - colorActive[] = {0,0,1,1}; - colorDisable[] = {0,0,1,0.4}; -}; - -class GVAR(OptionsGroup): RscControlsGroup { - class HScrollbar: HScrollbar { - height = 0; - }; - x = POS_W(0.5); - y = POS_H(3.5); - w = POS_W(35); - h = POS_H(13.8); - lineHeight = POS_H(1); - - class controls {}; // auto generated -}; - -// have to create to dynamically for every options group, because they would interfere with the controls groups otherwise -// has to be done, because scripted controls are always placed below regular (config) ones. -class GVAR(AddonsList): RscCombo { - linespacing = 1; - text = ""; - wholeHeight = POS_H(12); - x = POS_W(4.5); - y = POS_H(1); - w = POS_W(21); - h = POS_H(1); -}; +class RscControlsGroupNoScrollbars; +class RscText; class RscDisplayGameOptions { class controls { @@ -69,37 +14,31 @@ class RscDisplayGameOptions { h = POS_H(1); }; - class CBA_ButtonClient: RscButtonMenu { - idc = IDC_BTN_CLIENT; - text = CSTRING(ButtonClient); - tooltip = CSTRING(ButtonClient_tooltip); + class CBA_ButtonServer: RscButtonMenu { + idc = IDC_BTN_SERVER; + text = CSTRING(ButtonServer); + tooltip = CSTRING(ButtonServer_tooltip); x = POS_X(1); y = POS_Y(2.1); w = POS_W(8); h = POS_H(1); }; - class CBA_ButtonServer: CBA_ButtonClient { - idc = IDC_BTN_SERVER; - text = CSTRING(ButtonServer); - tooltip = CSTRING(ButtonServer_tooltip); - x = POS_X(9); - }; - - class CBA_ButtonMission: CBA_ButtonClient { + class CBA_ButtonMission: CBA_ButtonServer { idc = IDC_BTN_MISSION; text = CSTRING(ButtonMission); tooltip = CSTRING(ButtonMission_tooltip); + x = POS_X(9); + }; + + class CBA_ButtonClient: CBA_ButtonServer { + idc = IDC_BTN_CLIENT; + text = CSTRING(ButtonClient); + tooltip = CSTRING(ButtonClient_tooltip); x = POS_X(17); }; - class CBA_AddonsGroup: RscControlsGroup { - class VScrollbar: VScrollbar { - width = 0; - }; - class HScrollbar: HScrollbar { - height = 0; - }; + class CBA_AddonsGroup: RscControlsGroupNoScrollbars { idc = IDC_ADDONS_GROUP; enableDisplay = 0; x = POS_X(1); @@ -108,19 +47,17 @@ class RscDisplayGameOptions { h = POS_H(17.3); class controls { - class CBA_AddonsEmptyBackground: RscText { + class Background: RscText { idc = -1; - type = 0x00; - text = ""; colorBackground[] = {0,0,0,0.4}; x = POS_W(0.5); y = POS_H(3.5); - w = POS_W(35); + w = POS_W(37); h = POS_H(13.8); }; - class CBA_AddonsCA_ControlsPageText: RscText { - style = 0x01; - idc = 2002; + class AddonText: RscText { + idc = -1; + style = ST_RIGHT; text = "Addon:"; x = POS_W(0.5); y = POS_H(1); @@ -128,24 +65,31 @@ class RscDisplayGameOptions { h = POS_H(1); sizeEx = POS_H(1); }; - class CBA_ForceSettingText: RscText { - style = 0x01; - idc = IDC_TXT_FORCE; - text = ""; - tooltip = CSTRING(force_tooltip); - x = POS_W(25); - y = POS_H(2.5); - w = POS_W(10); - h = POS_H(1); + class OverwriteClientText: RscText { + // Set tooltip per script to avoid it being all upper case. + // Disable multiline text to make in unselectable. + onLoad = QUOTE((_this select 0) ctrlSetText localize QUOTE(LSTRING(overwrite_clients)); (_this select 0) ctrlEnable false;); + idc = IDC_TXT_OVERWRITE_CLIENT; + style = ST_MULTI + ST_CENTER; + x = POS_W(30); + y = POS_H(2); + w = POS_W(4); + h = POS_H(2*3/4); + sizeEx = POS_H(3/4); + }; + class OverwriteMissionText: OverwriteClientText { + onLoad = QUOTE((_this select 0) ctrlSetText localize QUOTE(LSTRING(overwrite_mission)); (_this select 0) ctrlEnable false;); + idc = IDC_TXT_OVERWRITE_MISSION; + x = POS_W(33); }; }; }; }; }; -class CBA_ButtonConfigureSettings_base: RscButtonMenu { +class GVAR(ButtonConfigure_base): RscButtonMenu { onButtonClick = QUOTE(ctrlParent (_this select 0) call COMPILE_FILE(openSettingsMenu)); - idc = IDC_BTN_SETTINGS; + idc = IDC_BTN_CONFIGURE; text = CSTRING(configureAddons); x = POS_X_LOW(11.1); y = POS_Y_LOW(23); @@ -156,29 +100,325 @@ class CBA_ButtonConfigureSettings_base: RscButtonMenu { class RscDisplayMainMap; class RscDisplayGetReady: RscDisplayMainMap { class controls { - class CBA_ButtonConfigureSettings: CBA_ButtonConfigureSettings_base {}; + class GVAR(ButtonConfigure): GVAR(ButtonConfigure_base) {}; }; }; class RscDisplayServerGetReady: RscDisplayGetReady { class controls { - class CBA_ButtonConfigureSettings: CBA_ButtonConfigureSettings_base {}; + class GVAR(ButtonConfigure): GVAR(ButtonConfigure_base) {}; }; }; class RscDisplayClientGetReady: RscDisplayGetReady { class controls { - class CBA_ButtonConfigureSettings: CBA_ButtonConfigureSettings_base {}; + class GVAR(ButtonConfigure): GVAR(ButtonConfigure_base) {}; + }; +}; + +class RscControlsGroupNoHScrollbars; +class GVAR(OptionsGroup): RscControlsGroupNoHScrollbars { + x = POS_W(0); + y = POS_H(3.5); + w = POS_W(37.5); + h = POS_H(13.8); + lineHeight = POS_H(1); +}; + +// Has to be created dynamically for every options group, because they would +// interfere with the controls groups otherwise. Scripted controls are always +// placed below config controls. +class RscCombo; +class GVAR(AddonsList): RscCombo { + linespacing = 1; + text = ""; + wholeHeight = POS_H(12); + x = POS_W(4.5); + y = POS_H(1); + w = POS_W(21); + h = POS_H(1); +}; + +class RscButton; +class RscPicture; + +class RscCheckBox; +class GVAR(CheckboxSound): RscCheckBox { + soundEnter[] = {"\A3\ui_f\data\sound\RscButtonMenu\soundEnter",0.090000004,1}; + soundPush[] = {"\A3\ui_f\data\sound\RscButtonMenu\soundPush",0.090000004,1}; + soundClick[] = {"\A3\ui_f\data\sound\RscButtonMenu\soundClick",0.090000004,1}; + soundEscape[] = {"\A3\ui_f\data\sound\RscButtonMenu\soundEscape",0.090000004,1}; +}; + +class GVAR(Row_Base): RscControlsGroupNoScrollbars { + GVAR(script) = ""; + x = POS_W(1); + y = POS_H(0); + w = POS_W(37); + h = POS_H(1) + TABLE_LINE_SPACING; + + class controls { + class Background: RscText { + idc = IDC_SETTING_BACKGROUND; + colorBackground[] = {0,0,0,0.4}; + x = POS_W(0); + y = POS_H(0) + TABLE_LINE_SPACING/2; + w = POS_W(36); + h = POS_H(1); + }; + class Name: RscText { + idc = IDC_SETTING_NAME; + style = ST_RIGHT; + x = POS_W(0); + y = POS_H(0) + TABLE_LINE_SPACING/2; + w = POS_W(15.5); + h = POS_H(1); + }; + class Default: RscButton { + idc = IDC_SETTING_DEFAULT; + style = ST_PICTURE; + text = ICON_DEFAULT; + tooltip = CSTRING(default_tooltip); + x = POS_W(26.5); + y = POS_H(0) + TABLE_LINE_SPACING/2; + w = POS_W(1); + h = POS_H(1); + }; + class Locked: RscPicture { + idc = IDC_SETTING_LOCKED; + text = QPATHTOF(locked_ca.paa); + colorText[] = {1,0,0,1}; + x = POS_W(28); + y = POS_H(0) + TABLE_LINE_SPACING/2; + w = POS_W(1); + h = POS_H(1); + }; + class OverwriteClients: GVAR(CheckboxSound) { + idc = IDC_SETTING_OVERWRITE_CLIENT; + x = POS_W(30.5); + y = POS_H(0) + TABLE_LINE_SPACING/2; + w = POS_W(1); + h = POS_H(1); + }; + class OverwriteMission: OverwriteClients { + idc = IDC_SETTING_OVERWRITE_MISSION; + x = POS_W(33.5); + }; + }; +}; + +class GVAR(Row_Checkbox): GVAR(Row_Base) { + GVAR(script) = QFUNC(gui_settingCheckbox); + + class controls: controls { + class Name: Name {}; + class Checkbox: GVAR(CheckboxSound) { + idc = IDC_SETTING_CHECKBOX; + x = POS_W(16); + y = POS_H(0) + TABLE_LINE_SPACING/2; + w = POS_W(1); + h = POS_H(1); + }; + class Default: Default {}; + class Locked: Locked {}; + class OverwriteClients: OverwriteClients {}; + class OverwriteMission: OverwriteMission {}; }; }; +class RscEdit; + +class GVAR(Row_Editbox): GVAR(Row_Base) { + GVAR(script) = QFUNC(gui_settingEditbox); + + class controls: controls { + class Name: Name {}; + class Editbox: RscEdit { + idc = IDC_SETTING_EDITBOX; + x = POS_W(16); + y = POS_H(0) + TABLE_LINE_SPACING/2; + w = POS_W(10); + h = POS_H(1); + }; + class Default: Default {}; + class Locked: Locked {}; + class OverwriteClients: OverwriteClients {}; + class OverwriteMission: OverwriteMission {}; + }; +}; + +class GVAR(Row_List): GVAR(Row_Base) { + GVAR(script) = QFUNC(gui_settingList); + + class controls: controls { + class Name: Name {}; + class List: RscCombo { + idc = IDC_SETTING_LIST; + x = POS_W(16); + y = POS_H(0) + TABLE_LINE_SPACING/2; + w = POS_W(10); + h = POS_H(1); + }; + class Default: Default {}; + class Locked: Locked {}; + class OverwriteClients: OverwriteClients {}; + class OverwriteMission: OverwriteMission {}; + }; +}; + +class RscXSliderH; + +class GVAR(Row_Slider): GVAR(Row_Base) { + GVAR(script) = QFUNC(gui_settingSlider); + + class controls: controls { + class Name: Name {}; + class Slider: RscXSliderH { + idc = IDC_SETTING_SLIDER; + x = POS_W(16); + y = POS_H(0) + TABLE_LINE_SPACING/2; + w = POS_W(8); + h = POS_H(1); + }; + class Edit: RscEdit { + idc = IDC_SETTING_SLIDER_EDIT; + x = POS_W(24); + y = POS_H(0) + TABLE_LINE_SPACING/2; + w = POS_W(2); + h = POS_H(1); + }; + class Default: Default {}; + class Locked: Locked {}; + class OverwriteClients: OverwriteClients {}; + class OverwriteMission: OverwriteMission {}; + }; +}; + +class GVAR(Row_Color): GVAR(Row_Base) { + GVAR(script) = QFUNC(gui_settingColor); + h = POS_H(3) + TABLE_LINE_SPACING; + + class controls: controls { + class Name: Name { + y = POS_H(0.5) + TABLE_LINE_SPACING/2; + }; + class Preview: RscText { + idc = IDC_SETTING_COLOR_PREVIEW; + x = POS_W(9.5); + y = POS_H(1.5) + TABLE_LINE_SPACING/2; + w = POS_W(6); + h = POS_H(1); + }; + class Red: RscXSliderH { + idc = IDC_SETTING_COLOR_RED; + color[] = {1,0,0,0.6}; + colorActive[] = {1,0,0,1}; + colorDisable[] = {1,0,0,0.4}; + x = POS_W(16); + y = POS_H(0) + TABLE_LINE_SPACING/2; + w = POS_W(8); + h = POS_H(1); + }; + class Red_Edit: RscEdit { + idc = IDC_SETTING_COLOR_RED_EDIT; + x = POS_W(24); + y = POS_H(0) + TABLE_LINE_SPACING/2; + w = POS_W(2); + h = POS_H(1); + }; + class Green: Red { + idc = IDC_SETTING_COLOR_GREEN; + color[] = {0,1,0,0.6}; + colorActive[] = {0,1,0,1}; + colorDisable[] = {0,1,0,0.4}; + y = POS_H(1) + TABLE_LINE_SPACING/2; + }; + class Green_Edit: Red_Edit { + idc = IDC_SETTING_COLOR_GREEN_EDIT; + y = POS_H(1) + TABLE_LINE_SPACING/2; + }; + class Blue: Red { + idc = IDC_SETTING_COLOR_BLUE; + color[] = {0,0,1,0.6}; + colorActive[] = {0,0,1,1}; + colorDisable[] = {0,0,1,0.4}; + y = POS_H(2) + TABLE_LINE_SPACING/2; + }; + class Blue_Edit: Red_Edit { + idc = IDC_SETTING_COLOR_BLUE_EDIT; + y = POS_H(2) + TABLE_LINE_SPACING/2; + }; + class Default: Default { + y = POS_H(1) + TABLE_LINE_SPACING/2; + }; + class Locked: Locked { + y = POS_H(1) + TABLE_LINE_SPACING/2; + }; + class OverwriteClients: OverwriteClients { + y = POS_H(1) + TABLE_LINE_SPACING/2; + }; + class OverwriteMission: OverwriteMission { + y = POS_H(1) + TABLE_LINE_SPACING/2; + }; + }; +}; + +class GVAR(Row_ColorAlpha): GVAR(Row_Color) { + h = POS_H(4) + TABLE_LINE_SPACING; + + class controls: controls { + class Name: Name { + y = POS_H(1) + TABLE_LINE_SPACING/2; + }; + class Preview: Preview { + y = POS_H(2) + TABLE_LINE_SPACING/2; + }; + class Red: Red {}; + class Red_Edit: Red_Edit {}; + class Green: Green {}; + class Green_Edit: Green_Edit {}; + class Blue: Blue {}; + class Blue_Edit: Blue_Edit {}; + class Alpha: RscXSliderH { + idc = IDC_SETTING_COLOR_ALPHA; + x = POS_W(16); + y = POS_H(3) + TABLE_LINE_SPACING/2; + w = POS_W(8); + h = POS_H(1); + }; + class Alpha_Edit: RscEdit { + idc = IDC_SETTING_COLOR_ALPHA_EDIT; + x = POS_W(24); + y = POS_H(3) + TABLE_LINE_SPACING/2; + w = POS_W(2); + h = POS_H(1); + }; + class Default: Default { + y = POS_H(1.5) + TABLE_LINE_SPACING/2; + }; + class Locked: Locked { + y = POS_H(1.5) + TABLE_LINE_SPACING/2; + }; + class OverwriteClients: OverwriteClients { + y = POS_H(1.5) + TABLE_LINE_SPACING/2; + }; + class OverwriteMission: OverwriteMission { + y = POS_H(1.5) + TABLE_LINE_SPACING/2; + }; + }; +}; + +class RscControlsGroup; +class RscTitle; +class RscListBox; + class GVAR(presets) { idd = -1; movingEnable = 1; enableSimulation = 0; class controls { - class CBA_Presets: RscControlsGroup { + class Presets: RscControlsGroup { idc = IDC_PRESETS_GROUP; x = POS_X(10); y = POS_Y(0.9); @@ -186,9 +426,13 @@ class GVAR(presets) { h = POS_H(22.2); class controls { - class CBA_Title: RscTitle { - style = 0; - colorBackground[] = {"(profilenamespace getvariable ['GUI_BCG_RGB_R',0.77])","(profilenamespace getvariable ['GUI_BCG_RGB_G',0.51])","(profilenamespace getvariable ['GUI_BCG_RGB_B',0.08])","(profilenamespace getvariable ['GUI_BCG_RGB_A',0.8])"}; + class Title: RscTitle { + colorBackground[] = { + "(profileNamespace getVariable ['GUI_BCG_RGB_R',0.77])", + "(profileNamespace getVariable ['GUI_BCG_RGB_G',0.51])", + "(profileNamespace getVariable ['GUI_BCG_RGB_B',0.08])", + "(profileNamespace getVariable ['GUI_BCG_RGB_A',0.8])" + }; idc = IDC_PRESETS_TITLE; text = ""; x = POS_W(0); @@ -196,7 +440,7 @@ class GVAR(presets) { w = POS_W(20); h = POS_H(1); }; - class CBA_Background: RscText { + class Background: RscText { idc = -1; colorBackground[] = {0,0,0,0.8}; x = POS_W(0); @@ -204,9 +448,9 @@ class GVAR(presets) { w = POS_W(20); h = POS_H(20); }; - class CBA_TextName: RscText { - style = 1; + class TextName: RscText { idc = IDC_PRESETS_NAME; + style = ST_RIGHT; text = "$STR_DISP_INTEL_NAME"; x = POS_W(0.5); y = POS_H(19.6); @@ -214,7 +458,7 @@ class GVAR(presets) { h = POS_H(1); sizeEx = POS_H(0.8); }; - class CBA_EditName: RscEdit { + class EditName: RscEdit { idc = IDC_PRESETS_EDIT; x = POS_W(6); y = POS_H(19.6); @@ -222,7 +466,7 @@ class GVAR(presets) { h = POS_H(1); sizeEx = POS_H(0.8); }; - class CBA_ValueName: RscListBox { + class ValueName: RscListBox { idc = IDC_PRESETS_VALUE; colorBackground[] = {1,1,1,0.2}; x = POS_W(0.5); @@ -231,7 +475,7 @@ class GVAR(presets) { h = POS_H(17.5); sizeEx = POS_H(0.8); }; - class CBA_ButtonOK: RscButtonMenu { + class ButtonOK: RscButtonMenu { idc = IDC_PRESETS_OK; text = "$STR_DISP_OK"; x = POS_W(15); @@ -239,7 +483,7 @@ class GVAR(presets) { w = POS_W(5); h = POS_H(1); }; - class CBA_ButtonCancel: RscButtonMenu { + class ButtonCancel: RscButtonMenu { idc = IDC_PRESETS_CANCEL; text = "$STR_DISP_CANCEL"; x = POS_W(0); @@ -247,7 +491,7 @@ class GVAR(presets) { w = POS_W(5); h = POS_H(1); }; - class CBA_ButtonDelete: RscButtonMenu { + class ButtonDelete: RscButtonMenu { idc = IDC_PRESETS_DELETE; text = "$STR_DISP_DELETE"; x = POS_W(9.9); diff --git a/addons/settings/gui_createMenu.sqf b/addons/settings/gui_createMenu.sqf index dff959339..fea682068 100644 --- a/addons/settings/gui_createMenu.sqf +++ b/addons/settings/gui_createMenu.sqf @@ -1,11 +1,25 @@ // 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]; -_display setVariable [QGVAR(controls), []]; { - (GVAR(defaultSettings) getVariable _x) params ["_defaultValue", "_setting", "_settingType", "_settingData", "_category", "_displayName", "_tooltip", "_isGlobal"]; + (GVAR(default) getVariable _x) params ["_defaultValue", "_setting", "_settingType", "_settingData", "_category", "_displayName", "_tooltip", "_isGlobal"]; if (isLocalized _category) then { _category = localize _category; @@ -21,9 +35,12 @@ _display setVariable [QGVAR(controls), []]; _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 "$"; @@ -35,74 +52,74 @@ _display setVariable [QGVAR(controls), []]; _ctrlOptionsGroup ctrlEnable false; _ctrlOptionsGroup ctrlShow false; - (_display getVariable QGVAR(controls)) pushBack _ctrlOptionsGroup; - _ctrlOptionsGroup setVariable [QGVAR(controls), []]; - _ctrlOptionsGroup setVariable [QGVAR(offsetY), MENU_OFFSET_INITIAL]; - _lists pushBack _list; _display setVariable [_list, _ctrlOptionsGroup]; } else { _ctrlOptionsGroup = _display getVariable _list; }; - private _offsetY = _ctrlOptionsGroup getVariable QGVAR(offsetY); + // ----- 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; - // ----- create setting name text - private _ctrlSettingName = _display ctrlCreate ["CBA_Rsc_SettingText", -1, _ctrlOptionsGroup]; + // ----- 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; - _ctrlSettingName ctrlSetPosition [ - POS_W(1), - POS_H(_offsetY), - POS_W(15), - POS_H(1) - ]; - _ctrlSettingName ctrlCommit 0; - // ----- check if setting can be altered - private _enabled = switch (_source) do { - case ("client"): { - CAN_SET_CLIENT_SETTINGS - }; - case ("server"): { - CAN_SET_SERVER_SETTINGS - }; - case ("mission"): { - CAN_SET_MISSION_SETTINGS - }; - }; + // ----- execute setting script + private _script = getText (configFile >> ctrlClassName _ctrlSettingGroup >> QGVAR(script)); + [_ctrlSettingGroup, _setting, _source, _currentValue, _settingData] call (uiNamespace getVariable _script); - // ----- check if altering setting would have no effect - private _isOverwritten = [_setting, _source] call FUNC(isOverwritten); + // ----- default button + [_ctrlSettingGroup, _setting, _source, _currentValue, _defaultValue] call FUNC(gui_settingDefault); - // ----- create setting changer control - private _controls = _ctrlOptionsGroup getVariable QGVAR(controls); - private _linkedControls = []; + // ----- priority list + [_ctrlSettingGroup, _setting, _source, _currentPriority, _isGlobal] call FUNC(gui_settingOverwrite); - switch (toUpper _settingType) do { - case ("CHECKBOX"): { - #include "gui_createMenu_checkbox.sqf" - }; - case ("LIST"): { - #include "gui_createMenu_list.sqf" - }; - case ("SLIDER"): { - #include "gui_createMenu_slider.sqf" - }; - case ("COLOR"): { - #include "gui_createMenu_color.sqf" - }; - default {}; + // ----- 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}}}; }; - #include "gui_createMenu_default.sqf" + if !(_enabled) then { + _ctrlSettingName ctrlSetTextColor COLOR_TEXT_DISABLED; - // ----- handle "force" button - if (_source != "client") then { - #include "gui_createMenu_force.sqf" - }; + //private _ctrlSettingGroupControls = allControls ctrlParent _ctrlSettingGroup select {ctrlParentControlsGroup _x == _ctrlSettingGroup}; + private _ctrlSettingGroupControls = "true" configClasses (configFile >> ctrlClassName _ctrlSettingGroup >> "controls") apply {_ctrlSettingGroup controlsGroupCtrl getNumber (_x >> "idc")}; - _ctrlOptionsGroup setVariable [QGVAR(offsetY), _offsetY + MENU_OFFSET_SPACING]; - } forEach ["client", "server", "mission"]; + { + _x ctrlEnable false; + } forEach _ctrlSettingGroupControls; + }; + } forEach ["client", "mission", "server"]; } forEach GVAR(allSettings); diff --git a/addons/settings/gui_createMenu_checkbox.sqf b/addons/settings/gui_createMenu_checkbox.sqf deleted file mode 100644 index a6e9b172c..000000000 --- a/addons/settings/gui_createMenu_checkbox.sqf +++ /dev/null @@ -1,44 +0,0 @@ -// inline function, don't include script_component.hpp - -private _ctrlSetting = _display ctrlCreate ["RscCheckBox", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup]; -_controls pushBack _ctrlSetting; - -_ctrlSetting ctrlSetPosition [ - POS_W(16), - POS_H(_offsetY), - POS_W(1), - POS_H(1) -]; -_ctrlSetting ctrlCommit 0; -_ctrlSetting cbSetChecked _currentValue; - -private _data = [_setting, _source]; - -_ctrlSetting setVariable [QGVAR(linkedControls), _linkedControls]; -_ctrlSetting setVariable [QGVAR(data), _data]; - -_ctrlSetting ctrlAddEventHandler ["CheckedChanged", { - params ["_control", "_state"]; - - (_control getVariable QGVAR(data)) params ["_setting", "_source"]; - - private _value = _state == 1; - SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source); - - //If new setting is same as default value, grey out the default button - (_control getVariable QGVAR(linkedControls)) params ["", "_defaultControl"]; - (_defaultControl getVariable QGVAR(data)) params ["", "", "_defaultValue"]; - _defaultControl ctrlEnable (!(_value isEqualTo _defaultValue)); -}]; - -_linkedControls pushBack _ctrlSetting; - -if (_isOverwritten) then { - _ctrlSettingName ctrlSetTextColor COLOR_TEXT_OVERWRITTEN; - _ctrlSetting ctrlSetTooltip localize LSTRING(overwritten_tooltip); -}; - -if !(_enabled) then { - _ctrlSettingName ctrlSetTextColor COLOR_TEXT_DISABLED; - _ctrlSetting ctrlEnable false; -}; diff --git a/addons/settings/gui_createMenu_color.sqf b/addons/settings/gui_createMenu_color.sqf deleted file mode 100644 index e54726381..000000000 --- a/addons/settings/gui_createMenu_color.sqf +++ /dev/null @@ -1,141 +0,0 @@ -// inline function, don't include script_component.hpp - -private _ctrlSettingPreview = _display ctrlCreate ["RscText", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup]; -_controls pushBack _ctrlSettingPreview; - -_ctrlSettingPreview ctrlSetPosition [ - POS_W(9.5), - POS_H(_offsetY + MENU_OFFSET_COLOR), - POS_W(6), - POS_H(1) -]; -_ctrlSettingPreview ctrlCommit 0; - -_currentValue params [ - ["_r", 0, [0]], - ["_g", 0, [0]], - ["_b", 0, [0]], - ["_a", 1, [0]] -]; -private _color = [_r, _g, _b, _a]; -_ctrlSettingPreview ctrlSetBackgroundColor _color; - -private _data = [_setting, _source, _currentValue, _color]; - -_ctrlSettingPreview setVariable [QGVAR(linkedControls), _linkedControls]; -_ctrlSettingPreview setVariable [QGVAR(data), _data]; - -_linkedControls append [_ctrlSettingPreview, []]; - -for "_index" from 0 to (((count _defaultValue max 3) min 4) - 1) do { - private _ctrlSetting = _display ctrlCreate [SLIDER_TYPES param [_index, "RscXSliderH"], count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup]; - _controls pushBack _ctrlSetting; - - _ctrlSetting ctrlSetPosition [ - POS_W(16), - POS_H(_offsetY), - POS_W(8), - POS_H(1) - ]; - _ctrlSetting ctrlCommit 0; - - _ctrlSetting sliderSetRange [0, 1]; - _ctrlSetting sliderSetPosition (_currentValue param [_index, 0]); - - _ctrlSetting setVariable [QGVAR(linkedControls), _linkedControls]; - _ctrlSetting setVariable [QGVAR(data), _data]; - _ctrlSetting setVariable [QGVAR(index), _index]; - - _ctrlSetting ctrlAddEventHandler ["SliderPosChanged", { - params ["_control", "_value"]; - - (_control getVariable QGVAR(data)) params ["_setting", "_source", "_currentValue", "_color"]; - private _index = _control getVariable QGVAR(index); - - (_control getVariable QGVAR(linkedControls)) params ["_ctrlSettingPreview", "_linkedControls", "_defaultControl"]; - private _linkedControl = _linkedControls select _index select 1; - _linkedControl ctrlSetText ([_value, 1, 2] call CBA_fnc_formatNumber); - - _currentValue set [_index, _value]; - _color set [_index, _value]; - _ctrlSettingPreview ctrlSetBackgroundColor _color; - SET_TEMP_NAMESPACE_VALUE(_setting,_currentValue,_source); - - //If new setting is same as default value, grey out the default button - (_defaultControl getVariable QGVAR(data)) params ["", "", "_defaultValue"]; - _defaultControl ctrlEnable (!(_currentValue isEqualTo _defaultValue)); - }]; - - private _ctrlSettingEdit = _display ctrlCreate ["RscEdit", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup]; - _controls pushBack _ctrlSettingEdit; - - _ctrlSettingEdit ctrlSetPosition [ - POS_W(24), - POS_H(_offsetY), - POS_W(2), - POS_H(1) - ]; - _ctrlSettingEdit ctrlCommit 0; - - //_ctrlSettingEdit ctrlSetTextColor (SLIDER_COLORS param [_index, 0]); - _ctrlSettingEdit ctrlSetActiveColor (SLIDER_COLORS param [_index, 0]); - _ctrlSettingEdit ctrlSetText ([_currentValue param [_index, 0], 1, 2] call CBA_fnc_formatNumber); - - _ctrlSettingEdit setVariable [QGVAR(linkedControls), _linkedControls]; - _ctrlSettingEdit setVariable [QGVAR(data), _data]; - _ctrlSettingEdit setVariable [QGVAR(index), _index]; - - _ctrlSettingEdit ctrlAddEventHandler ["KeyUp", { - params ["_control"]; - - private _value = parseNumber ctrlText _control; - - (_control getVariable QGVAR(data)) params ["_setting", "_source", "_currentValue", "_color"]; - private _index = _control getVariable QGVAR(index); - - (_control getVariable QGVAR(linkedControls)) params ["_ctrlSettingPreview", "_linkedControls", "_defaultControl"]; - - private _linkedControl = _linkedControls select _index select 0; - _linkedControl sliderSetPosition _value; - - _currentValue set [_index, sliderPosition _linkedControl]; - _color set [_index, _value]; - _ctrlSettingPreview ctrlSetBackgroundColor _color; - SET_TEMP_NAMESPACE_VALUE(_setting,_currentValue,_source); - - //If new setting is same as default value, grey out the default button - (_defaultControl getVariable QGVAR(data)) params ["", "", "_defaultValue"]; - _defaultControl ctrlEnable (!(_currentValue isEqualTo _defaultValue)); - }]; - - _ctrlSettingEdit ctrlAddEventHandler ["KillFocus", { - params ["_control"]; - - private _index = _control getVariable QGVAR(index); - - (_control getVariable QGVAR(linkedControls)) params ["", "_linkedControls"]; - private _linkedControl = _linkedControls select _index select 0; - - private _value = sliderPosition _linkedControl; - - _control ctrlSetText ([_value, 1, 2] call CBA_fnc_formatNumber); - }]; - - (_linkedControls select 1) pushBack [_ctrlSetting, _ctrlSettingEdit]; - - if (_isOverwritten) then { - _ctrlSettingName ctrlSetTextColor COLOR_TEXT_OVERWRITTEN; - _ctrlSetting ctrlSetTooltip localize LSTRING(overwritten_tooltip); - _ctrlSettingEdit ctrlSetTooltip localize LSTRING(overwritten_tooltip); - }; - - if !(_enabled) then { - _ctrlSettingName ctrlSetTextColor COLOR_TEXT_DISABLED; - _ctrlSetting ctrlEnable false; - _ctrlSettingEdit ctrlEnable false; - }; - - _offsetY = _offsetY + MENU_OFFSET_COLOR; -}; - -_offsetY = _offsetY + MENU_OFFSET_COLOR_NEG; diff --git a/addons/settings/gui_createMenu_default.sqf b/addons/settings/gui_createMenu_default.sqf deleted file mode 100644 index ca0121772..000000000 --- a/addons/settings/gui_createMenu_default.sqf +++ /dev/null @@ -1,79 +0,0 @@ -// inline function, don't include script_component.hpp - -private _ctrlSettingDefault = _display ctrlCreate ["RscButtonMenu", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup]; -_controls pushBack _ctrlSettingDefault; - -_ctrlSettingDefault ctrlSetPosition [ - POS_W(27), - POS_H(_ctrlOptionsGroup getVariable QGVAR(offsetY)), - POS_W(5), - POS_H(1) -]; -_ctrlSettingDefault ctrlCommit 0; -_ctrlSettingDefault ctrlSetText localize LSTRING(Default); - -private _data = [_setting, _source, _defaultValue, _settingType, _settingData]; - -_ctrlSettingDefault setVariable [QGVAR(linkedControls), _linkedControls]; -_ctrlSettingDefault setVariable [QGVAR(data), _data]; - -_ctrlSettingDefault ctrlAddEventHandler ["ButtonClick", { - params ["_control"]; - - (_control getVariable QGVAR(data)) params ["_setting", "_source", "_defaultValue", "_settingType", "_settingData"]; - SET_TEMP_NAMESPACE_VALUE(_setting,_defaultValue,_source); - - // Can disable button as the setting will now be the default - _control ctrlEnable false; - - private _linkedControls = _control getVariable QGVAR(linkedControls); - - // reset buttons to default state - switch (toUpper _settingType) do { - case ("CHECKBOX"): { - _linkedControls params ["_ctrlSetting"]; - - _ctrlSetting cbSetChecked _defaultValue; - }; - case ("LIST"): { - _settingData params ["_values"]; - _linkedControls params ["_ctrlSetting"]; - - _ctrlSetting lbSetCurSel (_values find _defaultValue); - }; - case ("SLIDER"): { - _settingData params ["", "", "_trailingDecimals"]; - _linkedControls params ["_ctrlSetting", "_ctrlSettingEdit"]; - - _ctrlSetting sliderSetPosition _defaultValue; - _ctrlSettingEdit ctrlSetText ([_defaultValue, 1, _trailingDecimals] call CBA_fnc_formatNumber); - }; - case ("COLOR"): { - _linkedControls params ["_ctrlSettingPreview", "_settingControls"]; - - _defaultValue params [ - ["_r", 0, [0]], - ["_g", 0, [0]], - ["_b", 0, [0]], - ["_a", 1, [0]] - ]; - private _color = [_r, _g, _b, _a]; - _ctrlSettingPreview ctrlSetBackgroundColor _color; - - { - _x params ["_ctrlSetting", "_ctrlSettingEdit"]; - private _value = _defaultValue select _forEachIndex; - - _ctrlSetting sliderSetPosition _value; - _ctrlSettingEdit ctrlSetText ([_value, 1, 2] call CBA_fnc_formatNumber); - } forEach _settingControls; - }; - default {}; - }; -}]; - -_linkedControls pushBack _ctrlSettingDefault; - -if ((!_enabled) || {_currentValue isEqualTo _defaultValue}) then { - _ctrlSettingDefault ctrlEnable false; -}; diff --git a/addons/settings/gui_createMenu_force.sqf b/addons/settings/gui_createMenu_force.sqf deleted file mode 100644 index 41c153f9e..000000000 --- a/addons/settings/gui_createMenu_force.sqf +++ /dev/null @@ -1,33 +0,0 @@ -// inline function, don't include script_component.hpp - -private _ctrlSettingForce = _display ctrlCreate ["RscCheckBox", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup]; -_controls pushBack _ctrlSettingForce; - -_ctrlSettingForce ctrlSetPosition [ - POS_W(33), - POS_H(_ctrlOptionsGroup getVariable QGVAR(offsetY)), - POS_W(1), - POS_H(1) -]; -_ctrlSettingForce ctrlCommit 0; -_ctrlSettingForce cbSetChecked ([_setting, _source] call FUNC(isForced)); - -private _data = [_setting, _source]; - -_ctrlSettingForce setVariable [QGVAR(linkedControls), _linkedControls]; -_ctrlSettingForce setVariable [QGVAR(data), _data]; - -_ctrlSettingForce ctrlAddEventHandler ["CheckedChanged", { - params ["_control", "_state"]; - - private _value = _state == 1; - - (_control getVariable QGVAR(data)) params ["_setting", "_source"]; - SET_TEMP_NAMESPACE_FORCED(_setting,_value,_source); -}]; - -_linkedControls pushBack _ctrlSettingForce; - -if !(_enabled) then { - _ctrlSettingForce ctrlEnable false; -}; diff --git a/addons/settings/gui_createMenu_list.sqf b/addons/settings/gui_createMenu_list.sqf deleted file mode 100644 index 335ca02d8..000000000 --- a/addons/settings/gui_createMenu_list.sqf +++ /dev/null @@ -1,59 +0,0 @@ -// inline function, don't include script_component.hpp - -private _ctrlSetting = _display ctrlCreate ["RscCombo", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup]; -_controls pushBack _ctrlSetting; - -_ctrlSetting ctrlSetPosition [ - POS_W(16), - POS_H(_offsetY), - POS_W(10), - POS_H(1) -]; -_ctrlSetting ctrlCommit 0; - -_settingData params ["_values", "_labels"]; - -private _data = [_setting, _source, []]; - -{ - private _label = _labels select _forEachIndex; - - if (isLocalized _label) then { - _label = localize _label; - }; - - private _index = _ctrlSetting lbAdd _label; - _ctrlSetting lbSetData [_index, str _index]; - (_data select 2) set [_index, _x]; -} forEach _values; - -_ctrlSetting lbSetCurSel (_values find _currentValue); - -_ctrlSetting setVariable [QGVAR(linkedControls), _linkedControls]; -_ctrlSetting setVariable [QGVAR(data), _data]; - -_ctrlSetting ctrlAddEventHandler ["LBSelChanged", { - params ["_control", "_index"]; - - (_control getVariable QGVAR(data)) params ["_setting", "_source", "_data"]; - - private _value = _data select _index; - SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source); - - //If new setting is same as default value, grey out the default button - (_control getVariable QGVAR(linkedControls)) params ["", "_defaultControl"]; - (_defaultControl getVariable QGVAR(data)) params ["", "", "_defaultValue"]; - _defaultControl ctrlEnable (!(_value isEqualTo _defaultValue)); -}]; - -_linkedControls pushBack _ctrlSetting; - -if (_isOverwritten) then { - _ctrlSettingName ctrlSetTextColor COLOR_TEXT_OVERWRITTEN; - _ctrlSetting ctrlSetTooltip localize LSTRING(overwritten_tooltip); -}; - -if !(_enabled) then { - _ctrlSettingName ctrlSetTextColor COLOR_TEXT_DISABLED; - _ctrlSetting ctrlEnable false; -}; diff --git a/addons/settings/gui_createMenu_slider.sqf b/addons/settings/gui_createMenu_slider.sqf deleted file mode 100644 index f69f06cf7..000000000 --- a/addons/settings/gui_createMenu_slider.sqf +++ /dev/null @@ -1,95 +0,0 @@ -// inline function, don't include script_component.hpp - -private _ctrlSetting = _display ctrlCreate ["RscXSliderH", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup]; -_controls pushBack _ctrlSetting; - -_ctrlSetting ctrlSetPosition [ - POS_W(16), - POS_H(_offsetY), - POS_W(8), - POS_H(1) -]; -_ctrlSetting ctrlCommit 0; - -_settingData params ["_min", "_max", "_trailingDecimals"]; - -_ctrlSetting sliderSetRange [_min, _max]; -_ctrlSetting sliderSetPosition _currentValue; - -private _data = [_setting, _source, _trailingDecimals]; - -_ctrlSetting setVariable [QGVAR(linkedControls), _linkedControls]; -_ctrlSetting setVariable [QGVAR(data), _data]; - -_ctrlSetting ctrlAddEventHandler ["SliderPosChanged", { - params ["_control", "_value"]; - - (_control getVariable QGVAR(data)) params ["_setting", "_source", "_trailingDecimals"]; - - (_control getVariable QGVAR(linkedControls)) params ["", "_linkedControl", "_defaultControl"]; - _linkedControl ctrlSetText ([_value, 1, _trailingDecimals] call CBA_fnc_formatNumber); - - SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source); - - //If new setting is same as default value, grey out the default button - (_defaultControl getVariable QGVAR(data)) params ["", "", "_defaultValue"]; - _defaultControl ctrlEnable (!(_value isEqualTo _defaultValue)); -}]; - -private _ctrlSettingEdit = _display ctrlCreate ["RscEdit", count _controls + IDC_OFFSET_SETTING, _ctrlOptionsGroup]; -_controls pushBack _ctrlSettingEdit; - -_ctrlSettingEdit ctrlSetPosition [ - POS_W(24), - POS_H(_offsetY), - POS_W(2), - POS_H(1) -]; -_ctrlSettingEdit ctrlCommit 0; -_ctrlSettingEdit ctrlSetText ([_currentValue, 1, _trailingDecimals] call CBA_fnc_formatNumber); - -_ctrlSettingEdit setVariable [QGVAR(linkedControls), _linkedControls]; -_ctrlSettingEdit setVariable [QGVAR(data), _data]; - -_ctrlSettingEdit ctrlAddEventHandler ["KeyUp", { - params ["_control"]; - - (_control getVariable QGVAR(data)) params ["_setting", "_source", "_trailingDecimals"]; - - private _value = parseNumber ctrlText _control; - - (_control getVariable QGVAR(linkedControls)) params ["_linkedControl", "", "_defaultControl"]; - _linkedControl sliderSetPosition _value; - - _value = sliderPosition _linkedControl; - SET_TEMP_NAMESPACE_VALUE(_setting,_value,_source); - - //If new setting is same as default value, grey out the default button - (_defaultControl getVariable QGVAR(data)) params ["", "", "_defaultValue"]; - _defaultControl ctrlEnable (!(_value isEqualTo _defaultValue)); -}]; - -_ctrlSettingEdit ctrlAddEventHandler ["KillFocus", { - params ["_control"]; - - (_control getVariable QGVAR(data)) params ["", "", "_trailingDecimals"]; - - private _linkedControl = _control getVariable QGVAR(linkedControls) select 0; - private _value = sliderPosition _linkedControl; - - _control ctrlSetText ([_value, 1, _trailingDecimals] call CBA_fnc_formatNumber); -}]; - -_linkedControls append [_ctrlSetting, _ctrlSettingEdit]; - -if (_isOverwritten) then { - _ctrlSettingName ctrlSetTextColor COLOR_TEXT_OVERWRITTEN; - _ctrlSetting ctrlSetTooltip localize LSTRING(overwritten_tooltip); - _ctrlSettingEdit ctrlSetTooltip localize LSTRING(overwritten_tooltip); -}; - -if !(_enabled) then { - _ctrlSettingName ctrlSetTextColor COLOR_TEXT_DISABLED; - _ctrlSetting ctrlEnable false; - _ctrlSettingEdit ctrlEnable false; -}; diff --git a/addons/settings/initMissionSettings.sqf b/addons/settings/initMissionSettings.sqf deleted file mode 100644 index e3fa37a42..000000000 --- a/addons/settings/initMissionSettings.sqf +++ /dev/null @@ -1,21 +0,0 @@ -// inline function, don't include script_component.hpp - -0 = 0 spawn { - { - // --- read previous setting values from mission - private _settingsHash = getMissionConfigValue QGVAR(hash); - - if (isNil "_settingsHash") then { - _settingsHash = NULL_HASH; - }; - - [_settingsHash, { - _value params ["_value", "_forced"]; - - GVAR(missionSettings) setVariable [_key, [_value, _forced]]; - }] call CBA_fnc_hashEachPair; - - // --- refresh all settings now - QGVAR(refreshAllSettings) call CBA_fnc_localEvent; - } call CBA_fnc_directCall; -}; diff --git a/addons/settings/initSettings.sqf b/addons/settings/initSettings.sqf index 024cff6e9..24f3aaefd 100644 --- a/addons/settings/initSettings.sqf +++ b/addons/settings/initSettings.sqf @@ -1,21 +1,57 @@ // inline function, don't include script_component.hpp -if (isNil QGVAR(defaultSettings)) then { - GVAR(defaultSettings) = [] call CBA_fnc_createNamespace; +if (isNil QGVAR(default)) then { GVAR(allSettings) = []; + GVAR(default) = [] call CBA_fnc_createNamespace; - GVAR(clientSettings) = [] call CBA_fnc_createNamespace; + // --- main setting sources + GVAR(client) = [] call CBA_fnc_createNamespace; + GVAR(mission) = [] call CBA_fnc_createNamespace; + + if (isNil QGVAR(server)) then { + GVAR(server) = NAMESPACE_NULL; + }; + + if (isServer) then { + missionNamespace setVariable [QGVAR(server), true call CBA_fnc_createNamespace, true]; + }; + + // --- read userconfig file + GVAR(userconfig) = [] call CBA_fnc_createNamespace; + + if (isNil QGVAR(serverConfig)) then { + GVAR(serverConfig) = NAMESPACE_NULL; + }; + + if (isServer) then { + missionNamespace setVariable [QGVAR(serverConfig), true call CBA_fnc_createNamespace, true]; + }; + + private _userconfig = call (uiNamespace getVariable QGVAR(userconfig)); + + { + _x params ["_setting", "_value", "_priority"]; + + GVAR(userconfig) setVariable [_setting, [_value, _priority]]; - if (isMultiplayer) then { if (isServer) then { - GVAR(serverSettings) = true call CBA_fnc_createNamespace; - publicVariable QGVAR(serverSettings); + GVAR(serverConfig) setVariable [_setting, true, true]; }; - } else { - GVAR(serverSettings) = false call CBA_fnc_createNamespace; + } forEach ([_userconfig, false] call FUNC(parse)); + + // --- read mission settings file + GVAR(missionConfig) = [] call CBA_fnc_createNamespace; + + private _missionConfig = ""; + + if (getMissionConfigValue [QGVAR(hasSettingsFile), false]) then { + INFO("Loading mission settings file ..."); + _missionConfig = preprocessFile MISSION_SETTINGS_FILE; }; - GVAR(missionSettings) = [] call CBA_fnc_createNamespace; + { + _x params ["_setting", "_value", "_priority"]; - #include "initMissionSettings.sqf" + GVAR(missionConfig) setVariable [_setting, [_value, _priority]]; + } forEach ([_missionConfig, false] call FUNC(parse)); }; diff --git a/addons/settings/locked_ca.paa b/addons/settings/locked_ca.paa new file mode 100644 index 000000000..156b8d556 Binary files /dev/null and b/addons/settings/locked_ca.paa differ diff --git a/addons/settings/openSettingsMenu.sqf b/addons/settings/openSettingsMenu.sqf index 73719154d..c0efdd082 100644 --- a/addons/settings/openSettingsMenu.sqf +++ b/addons/settings/openSettingsMenu.sqf @@ -1,9 +1,12 @@ #include "script_component.hpp" -disableSerialization; - params [["_display", findDisplay 46, [displayNull]]]; +// hide diary (usually on players list) +if (ctrlIDD _display in [IDD_INTEL_GETREADY, IDD_SERVER_GET_READY, IDD_CLIENT_GET_READY]) then { + (_display displayCtrl 1001) lnbSetCurSelRow 0; +}; + private _dlgSettings = _display createDisplay "RscDisplayGameOptions"; // switch to custom addons tab now @@ -14,30 +17,11 @@ _ctrlConfigureAddons call FUNC(gui_configure); _ctrlConfigureAddons ctrlEnable false; _ctrlConfigureAddons ctrlShow false; -// then switch right to missions tab -if (ctrlIDD _display == 313) then { +// then switch right to missions tab if in 3den +if (ctrlIDD _display isEqualTo 313) then { private _ctrlMissionButton = _dlgSettings displayCtrl IDC_BTN_MISSION; - _ctrlMissionButton call FUNC(gui_sourceChanged); -}; - -if (ctrlIDD _display in [37, 52, 53]) then { - private _ctrlButtonCancel = _display displayCtrl 2; - private _ctrlButtonSettings = _display displayCtrl IDC_BTN_SETTINGS; - - _ctrlButtonCancel ctrlEnable false; - _ctrlButtonCancel ctrlShow false; - _ctrlButtonSettings ctrlEnable false; - _ctrlButtonSettings ctrlShow false; - - [_dlgSettings, "unload", { - _thisArgs params ["_display"]; - - private _ctrlButtonCancel = _display displayCtrl 2; - private _ctrlButtonSettings = _display displayCtrl IDC_BTN_SETTINGS; - _ctrlButtonCancel ctrlEnable true; - _ctrlButtonCancel ctrlShow true; - _ctrlButtonSettings ctrlEnable true; - _ctrlButtonSettings ctrlShow true; - }, [_display]] call CBA_fnc_addBISEventHandler; + if (ctrlEnabled _ctrlMissionButton) then { + _ctrlMissionButton call FUNC(gui_sourceChanged); + }; }; diff --git a/addons/settings/script_component.hpp b/addons/settings/script_component.hpp index 2bc43cb8e..4068b7abd 100644 --- a/addons/settings/script_component.hpp +++ b/addons/settings/script_component.hpp @@ -3,6 +3,7 @@ #include "\a3\ui_f\hpp\defineDIKCodes.inc" #include "\a3\ui_f\hpp\defineCommonGrids.inc" +#include "\a3\ui_f\hpp\defineResincl.inc" //#define DEBUG_ENABLED_SETTINGS @@ -14,20 +15,46 @@ #define DEBUG_SETTINGS DEBUG_SETTINGS_SETTINGS #endif +#define DEBUG_SYNCHRONOUS #include "\x\cba\addons\main\script_macros.hpp" #define IDC_ADDONS_GROUP 4301 #define IDC_BTN_CONFIGURE_ADDONS 4302 -#define IDC_BTN_CLIENT 9000 -#define IDC_BTN_SERVER 9001 +#define IDC_BTN_CLIENT 9001 #define IDC_BTN_MISSION 9002 +#define IDC_BTN_SERVER 9003 #define IDC_BTN_IMPORT 9010 #define IDC_BTN_EXPORT 9011 #define IDC_BTN_SAVE 9020 #define IDC_BTN_LOAD 9021 -#define IDC_TXT_FORCE 327 -#define IDC_OFFSET_SETTING 10000 -#define IDC_BTN_SETTINGS 7000 +#define IDC_BTN_CONFIGURE 9030 +#define IDC_TXT_OVERWRITE_CLIENT 9040 +#define IDC_TXT_OVERWRITE_MISSION 9041 + +#define IDC_SETTING_CONTROLS_GROUP 5000 +#define IDC_SETTING_BACKGROUND 5001 +#define IDC_SETTING_NAME 5010 +#define IDC_SETTING_DEFAULT 5020 +#define IDC_SETTING_LOCKED 5030 +#define IDC_SETTING_OVERWRITE_CLIENT 5040 +#define IDC_SETTING_OVERWRITE_MISSION 5041 +#define IDC_SETTING_CHECKBOX 5100 +#define IDC_SETTING_EDITBOX 5101 +#define IDC_SETTING_LIST 5110 +#define IDC_SETTING_SLIDER 5120 +#define IDC_SETTING_SLIDER_EDIT 5121 +#define IDC_SETTING_COLOR_PREVIEW 5130 +#define IDC_SETTING_COLOR_RED 5131 +#define IDC_SETTING_COLOR_RED_EDIT 5132 +#define IDC_SETTING_COLOR_GREEN 5133 +#define IDC_SETTING_COLOR_GREEN_EDIT 5134 +#define IDC_SETTING_COLOR_BLUE 5135 +#define IDC_SETTING_COLOR_BLUE_EDIT 5136 +#define IDC_SETTING_COLOR_ALPHA 5137 +#define IDC_SETTING_COLOR_ALPHA_EDIT 5138 + +#define IDCS_SETTING_COLOR [IDC_SETTING_COLOR_RED, IDC_SETTING_COLOR_GREEN, IDC_SETTING_COLOR_BLUE, IDC_SETTING_COLOR_ALPHA] +#define IDCS_SETTING_COLOR_EDIT [IDC_SETTING_COLOR_RED_EDIT, IDC_SETTING_COLOR_GREEN_EDIT, IDC_SETTING_COLOR_BLUE_EDIT, IDC_SETTING_COLOR_ALPHA_EDIT] #define IDC_PRESETS_GROUP 8000 #define IDC_PRESETS_TITLE 8001 @@ -46,44 +73,62 @@ #define POS_X_LOW(N) ((N) * GUI_GRID_W + GUI_GRID_X) #define POS_Y_LOW(N) ((N) * GUI_GRID_H + GUI_GRID_Y) -#define COLOR_TEXT_DISABLED [1,1,1,0.3] +#define TABLE_LINE_SPACING POS_H(0.4) + +#define COLOR_TEXT_ENABLED [1,1,1,1] +#define COLOR_TEXT_DISABLED [1,1,1,0.4] #define COLOR_BUTTON_ENABLED [1,1,1,1] #define COLOR_BUTTON_DISABLED [0,0,0,1] -#define COLOR_TEXT_OVERWRITTEN [1,0.3,0.3,1] - -#define SLIDER_TYPES ["CBA_Rsc_Slider_R", "CBA_Rsc_Slider_G", "CBA_Rsc_Slider_B"] -#define SLIDER_COLORS [[1,0,0,1], [0,1,0,1], [0,0,1,1], [1,1,1,1]] - -#define MENU_OFFSET_INITIAL 0.3 -#define MENU_OFFSET_SPACING 1.4 -#define MENU_OFFSET_COLOR 1.0 -#define MENU_OFFSET_COLOR_NEG -0.7 - -#define CAN_SET_CLIENT_SETTINGS (!isMultiplayer || {!isServer}) // in singleplayer or as client in multiplayer -#define CAN_SET_SERVER_SETTINGS (isMultiplayer && {isServer || IS_ADMIN_LOGGED}) // in multiplayer and host (local server) or logged in (not voted) admin (dedicated) -#define CAN_SET_MISSION_SETTINGS is3den // duh - -#ifndef DEBUG_MODE_FULL - #define CAN_VIEW_CLIENT_SETTINGS (!isMultiplayer || {!isServer}) // hide for local hosted MP client to not confuse - #define CAN_VIEW_SERVER_SETTINGS isMultiplayer // everyone can peak at those in multiplayer - #define CAN_VIEW_MISSION_SETTINGS (is3den || missionVersion >= 15) // can view those in 3den or 3den missions -#else - #define CAN_VIEW_CLIENT_SETTINGS true - #define CAN_VIEW_SERVER_SETTINGS true - #define CAN_VIEW_MISSION_SETTINGS true -#endif - -// replacement for "LOCATION getVariable [STRING, ANY]" -#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]) - -#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])])] -#define SET_TEMP_NAMESPACE_FORCED(setting,forced,source) GET_TEMP_NAMESPACE(source) setVariable [ARR_2(setting,[ARR_2((GET_TEMP_NAMESPACE(source) getVariable setting) param [0],forced)])] - -#define GET_TEMP_NAMESPACE_VALUE(setting,source) ((GET_TEMP_NAMESPACE(source) getVariable setting) param [0]) -#define GET_TEMP_NAMESPACE_FORCED(setting,source) ((GET_TEMP_NAMESPACE(source) getVariable setting) param [1]) -#define NULL_HASH ([] call CBA_fnc_hashCreate) +#define ICON_DEFAULT "\a3\3den\Data\Displays\Display3DEN\ToolBar\undo_ca.paa" + +#define CAN_SET_SERVER_SETTINGS ((isServer || {IS_ADMIN_LOGGED}) && {!isNull GVAR(server)}) // in single player, as host (local server) or as logged in (not voted) admin connected to a dedicated server +#define CAN_SET_CLIENT_SETTINGS !isServer // in multiplayer as dedicated client +#define CAN_SET_MISSION_SETTINGS (is3den && {!(missionName in ["", "tempMissionSP", "tempMissionMP"])}) // in editor with existing mission.sqm + +#define CAN_VIEW_SERVER_SETTINGS !isNull GVAR(server) // everyone can peak at those in multiplayer +#define CAN_VIEW_CLIENT_SETTINGS !isServer // in multiplayer as dedicated client +#define CAN_VIEW_MISSION_SETTINGS ((is3den || {missionVersion >= 15}) && {!(missionName in ["", "tempMissionSP", "tempMissionMP"])}) // can view those in 3den or 3den missions + +#define HASH_NULL ([] call CBA_fnc_hashCreate) +#define NAMESPACE_NULL objNull + +#define GET_TEMP_NAMESPACE(source) ((with uiNamespace do {[GVAR(clientTemp), GVAR(missionTemp), GVAR(serverTemp)]}) param [["client", "mission", "server"] find toLower source, NAMESPACE_NULL]) +#define GET_TEMP_NAMESPACE_VALUE(setting,source) (GET_TEMP_NAMESPACE(source) getVariable [setting, [nil, nil]] select 0) +#define GET_TEMP_NAMESPACE_PRIORITY(setting,source) (GET_TEMP_NAMESPACE(source) getVariable [setting, [nil, nil]] select 1) + +#define SET_TEMP_NAMESPACE_VALUE(setting,value,source) (GET_TEMP_NAMESPACE(source) setVariable [setting, [value, GET_TEMP_NAMESPACE_PRIORITY(setting,source)]]) +#define SET_TEMP_NAMESPACE_PRIORITY(setting,priority,source) (GET_TEMP_NAMESPACE(source) setVariable [setting, [GET_TEMP_NAMESPACE_VALUE(setting,source), priority]]) + +#define TEMP_PRIORITY(setting) (call {private _arr = [\ + (uiNamespace getVariable QGVAR(clientTemp)) getVariable [setting, [nil, [setting, "client"] call FUNC(priority)]] select 1,\ + (uiNamespace getVariable QGVAR(missionTemp)) getVariable [setting, [nil, [setting, "mission"] call FUNC(priority)]] select 1,\ + (uiNamespace getVariable QGVAR(serverTemp)) getVariable [setting, [nil, [setting, "server"] call FUNC(priority)]] select 1\ +]; ["client", "mission", "server"] select (_arr find selectMax _arr)}) + +#define TEMP_VALUE(setting) ([\ + (uiNamespace getVariable QGVAR(clientTemp)) getVariable [setting, [[setting, "client"] call FUNC(get), nil]] select 0,\ + (uiNamespace getVariable QGVAR(missionTemp)) getVariable [setting, [[setting, "mission"] call FUNC(get), nil]] select 0,\ + (uiNamespace getVariable QGVAR(serverTemp)) getVariable [setting, [[setting, "server"] call FUNC(get), nil]] select 0\ +] select (["client", "mission", "server"] find TEMP_PRIORITY(setting))) + +#define ASCII_NEWLINE 10 +#define ASCII_CARRIAGE_RETURN 13 +#define ASCII_TAB 9 +#define ASCII_SPACE 32 +#define NEWLINE toString [ASCII_NEWLINE] +#define WHITESPACE toString [ASCII_NEWLINE, ASCII_CARRIAGE_RETURN, ASCII_TAB, ASCII_SPACE] + +#define USERCONFIG_SETTINGS_FILE "userconfig\cba_settings.sqf" +#define USERCONFIG_SETTINGS_FILE_ADDON "\cba_settings_userconfig\cba_settings.sqf" +#define MISSION_SETTINGS_FILE "cba_settings.sqf" + +// lbSetCurSel triggers the LBSelChanged event. Sometimes we don't want that. +// This is a mutex to exit the eventhandler code. +#define LOCK GVAR(lock) = true +#define UNLOCK GVAR(lock) = nil +#define EXIT_LOCKED if (!isNil QGVAR(lock)) exitWith {} + +// Keep quote marks for strings, but also print "" if undefined. +// str and format ["%1", ] on their own can only do either. +#define TO_STRING(var) (call {private _str = var; if (_str isEqualType "") then {_str = str _str}; format ["%1", _str]}) diff --git a/addons/settings/stringtable.xml b/addons/settings/stringtable.xml index 958db46cd..b8dfd282c 100644 --- a/addons/settings/stringtable.xml +++ b/addons/settings/stringtable.xml @@ -16,15 +16,10 @@ Konfiguracja bazy 基本設定 - - Client - Lokal - クライアント - - - Edit your local settings. Red colored settings are overwritten by the server or mission. - Lokale Einstellungen bearbeiten. Rot geschriebene Einstellungen werden vom Server oder der Mission überschrieben. - ローカル設定を編集します。赤色はサーバーかミッションによって上書きされる設定です。 + + Addon Options... + Mod-Optionen... + アドオン オプション... Server @@ -32,9 +27,9 @@ サーバー - Look at the servers settings. 'Forced' settings overwrite the client and mission settings. Log in as admin to change. - Server-Einstellungen ansehen. 'Erzwungene' Einstellungen überschreiben lokale und Missionseinstellungen. Als Admin einloggen, um zu ändern. - サーバー設定を確認します。'フォース'設定はクライアントかミッションによる設定を上書きします。管理者が変更すると記録します。 + Look at the servers settings. Log in as admin to change. + Server-Einstellungen ansehen. Als Admin einloggen, um zu ändern. + サーバー設定を確認します。管理者が変更すると記録します。 Mission @@ -42,19 +37,39 @@ ミッション - Edit the missions settings. 'Forced' settings overwrite the clients settings. - Missionseinstellungen bearbeiten. 'Erzwungene' Einstellungen überschreiben lokale. - ミッションの設定を編集します。'フォース'設定はクライアント設定を上書きします。 + Look at the missions settings. + Missionseinstellungen ansehen. + ミッションの設定を確認します。 + + + Edit the missions settings. + Missionseinstellungen bearbeiten. + ミッションの設定を編集します。 + + + Client + Client + クライアント - - Force - Erzwingen - フォース + + Edit your local settings. + Lokale Einstellungen bearbeiten. + ローカル設定を編集します。 + + + Local + Lokal + ローカル + + + Save current settings as preset. + Derzeitige Einstellungen als Vorlage speichern. + 現在の設定をプリセットとして保存します。 - - Check to overwrite this setting for all connected players. - Wählen, um diese Einstellung für alle verbunden Spieler zu überschreiben. - 接続している全プレイヤーの設定を上書きします。 + + Load settings from preset. + Einstellungen aus Vorlage laden. + プリセットから設定を読み込みます。 Import @@ -76,37 +91,37 @@ Einstellungen in Zwischenablage speichern. クリップボードに設定を出力します。 - - Default - Výchozí - Voreinst. - По умолчанию - Domyślnie - Predefinito - Predet. - Par défaut - デフォルト - 기본값 - Padrão - - - Setting is overwritten. Check 'Server' or 'Mission' tab. - Einstellung ist überschrieben. Überprüfe 'Server' oder 'Mission'-Reiter. - 設定を上書きします。'サーバー'か'ミッション'タブを確認してください。 - - - Game Options (Addons) - Optionen (Modifikationen) - ゲーム オプション (アドオン) + + Reset to default value. + Zur Standardeinstellung zurücksetzen. + デフォルトにリセットします。 - - Save current settings as preset. - Derzeitige Einstellungen als Vorlage speichern. - 現在の設定をプリセットとして保存します。 + + Overwrite\nClients + Clients\nüberschreiben - - Load settings from preset. - Einstellungen aus Vorlage laden. - プリセットから設定を読み込みます。 + + Overwrite\nMission + Mission\nüberschreiben + + + Overwrite\nServer + Server\nüberschreiben + + + This setting is overwritten by the clients. + Diese Einstellung wird von den Clients überschrieben. + + + This setting is overwritten by the mission. + Diese Einstellung wird von der Mission überschrieben. + + + This setting is overwritten by the server. + Diese Einstellung wird vom Server überschrieben. + + + This setting is overwritten by the clients and only applies to the server. + Diese Einstellung wird von den Clients überschrieben und betrifft nur den Server. diff --git a/optionals/auto_load_settings_file/$PBOPREFIX$ b/optionals/auto_load_settings_file/$PBOPREFIX$ deleted file mode 100644 index 2ded54d25..000000000 --- a/optionals/auto_load_settings_file/$PBOPREFIX$ +++ /dev/null @@ -1 +0,0 @@ -x\cba\addons\auto_load_settings_file diff --git a/optionals/auto_load_settings_file/CfgEventHandlers.hpp b/optionals/auto_load_settings_file/CfgEventHandlers.hpp deleted file mode 100644 index f0a9f14d9..000000000 --- a/optionals/auto_load_settings_file/CfgEventHandlers.hpp +++ /dev/null @@ -1,6 +0,0 @@ - -class Extended_PreInit_EventHandlers { - class ADDON { - init = QUOTE(call COMPILE_FILE(XEH_preInit)); - }; -}; diff --git a/optionals/auto_load_settings_file/XEH_preInit.sqf b/optionals/auto_load_settings_file/XEH_preInit.sqf deleted file mode 100644 index a45666c5d..000000000 --- a/optionals/auto_load_settings_file/XEH_preInit.sqf +++ /dev/null @@ -1,12 +0,0 @@ -#include "script_component.hpp" - -ADDON = false; - -// frame after preInit, but before postInit -0 spawn { - { - #include "loadSettingsFile.sqf" - } call CBA_fnc_directCall; -}; - -ADDON = true; diff --git a/optionals/auto_load_settings_file/config.cpp b/optionals/auto_load_settings_file/config.cpp deleted file mode 100644 index f1368fcce..000000000 --- a/optionals/auto_load_settings_file/config.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "script_component.hpp" - -class CfgPatches { - class ADDON { - author = "$STR_CBA_Author"; - name = ECSTRING(settings,component); - url = "$STR_CBA_URL"; - units[] = {}; - weapons[] = {}; - requiredVersion = REQUIRED_VERSION; - requiredAddons[] = {"cba_settings"}; - version = VERSION; - authors[] = {"commy2"}; - }; -}; - -#include "CfgEventHandlers.hpp" diff --git a/optionals/auto_load_settings_file/loadSettingsFile.sqf b/optionals/auto_load_settings_file/loadSettingsFile.sqf deleted file mode 100644 index 4cacf4612..000000000 --- a/optionals/auto_load_settings_file/loadSettingsFile.sqf +++ /dev/null @@ -1,21 +0,0 @@ - -if (isFilePatchingEnabled) then { - private _source = ["client", "server"] select (isMultiplayer && isServer); - private _info = loadFile PATH_SETTINGS_FILE; - - if (_info != "") then { - _info = _info call EFUNC(settings,parse); - - { - _x params ["_setting", "_value", "_force"]; - - [_setting, _value, _force, _source] call EFUNC(settings,set); - } forEach _info; - - LOG("Settings file loaded."); - } else { - WARNING("Settings file not loaded. File empty or does not exist."); - }; -} else { - WARNING("Cannot load settings file. File patching disabled. Use -filePatching flag."); -}; diff --git a/optionals/auto_load_settings_file/script_component.hpp b/optionals/auto_load_settings_file/script_component.hpp deleted file mode 100644 index cf81d3488..000000000 --- a/optionals/auto_load_settings_file/script_component.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#define COMPONENT auto_load_settings_file -#include "\x\cba\addons\main\script_mod.hpp" - -//#define DEBUG_ENABLED_AUTO_LOAD_SETTINGS_FILE - -#ifdef DEBUG_ENABLED_AUTO_LOAD_SETTINGS_FILE - #define DEBUG_MODE_FULL -#endif - -#ifdef DEBUG_SETTINGS_AUTO_LOAD_SETTINGS_FILE - #define DEBUG_SETTINGS DEBUG_SETTINGS_AUTO_LOAD_SETTINGS_FILE -#endif - -#include "\x\cba\addons\main\script_macros.hpp" - -#define PATH_SETTINGS_FILE "userconfig\cba\settings.sqf" diff --git a/template/static_settings_addon/userconfig/cba/settings.sqf b/template/cba_settings_userconfig/cba_settings.sqf similarity index 100% rename from template/static_settings_addon/userconfig/cba/settings.sqf rename to template/cba_settings_userconfig/cba_settings.sqf diff --git a/template/static_settings_addon/config.cpp b/template/cba_settings_userconfig/config.cpp similarity index 52% rename from template/static_settings_addon/config.cpp rename to template/cba_settings_userconfig/config.cpp index f1368fcce..fbd45cbb2 100644 --- a/template/static_settings_addon/config.cpp +++ b/template/cba_settings_userconfig/config.cpp @@ -1,17 +1,14 @@ -#include "script_component.hpp" class CfgPatches { - class ADDON { + class cba_settings_userconfig { author = "$STR_CBA_Author"; - name = ECSTRING(settings,component); + name = "$STR_CBA_Settings_Component"; url = "$STR_CBA_URL"; units[] = {}; weapons[] = {}; - requiredVersion = REQUIRED_VERSION; + requiredVersion = 1.0; requiredAddons[] = {"cba_settings"}; - version = VERSION; + version = 1.0; authors[] = {"commy2"}; }; }; - -#include "CfgEventHandlers.hpp" diff --git a/template/static_settings_addon/$PBOPREFIX$ b/template/static_settings_addon/$PBOPREFIX$ deleted file mode 100644 index 26fd0300c..000000000 --- a/template/static_settings_addon/$PBOPREFIX$ +++ /dev/null @@ -1 +0,0 @@ -x\cba\addons\static_settings_addon diff --git a/template/static_settings_addon/CfgEventHandlers.hpp b/template/static_settings_addon/CfgEventHandlers.hpp deleted file mode 100644 index f0a9f14d9..000000000 --- a/template/static_settings_addon/CfgEventHandlers.hpp +++ /dev/null @@ -1,6 +0,0 @@ - -class Extended_PreInit_EventHandlers { - class ADDON { - init = QUOTE(call COMPILE_FILE(XEH_preInit)); - }; -}; diff --git a/template/static_settings_addon/XEH_preInit.sqf b/template/static_settings_addon/XEH_preInit.sqf deleted file mode 100644 index a45666c5d..000000000 --- a/template/static_settings_addon/XEH_preInit.sqf +++ /dev/null @@ -1,12 +0,0 @@ -#include "script_component.hpp" - -ADDON = false; - -// frame after preInit, but before postInit -0 spawn { - { - #include "loadSettingsFile.sqf" - } call CBA_fnc_directCall; -}; - -ADDON = true; diff --git a/template/static_settings_addon/loadSettingsFile.sqf b/template/static_settings_addon/loadSettingsFile.sqf deleted file mode 100644 index 0d67412d8..000000000 --- a/template/static_settings_addon/loadSettingsFile.sqf +++ /dev/null @@ -1,16 +0,0 @@ - -// do nothing if auto loaded settings file is present -if (isClass (configFile >> "CfgPatches" >> "cba_auto_load_settings_file")) exitWith {}; - -private _source = ["client", "server"] select (isMultiplayer && isServer); -private _info = loadFile PATH_SETTINGS_FILE_PBO; - -_info = _info call EFUNC(settings,parse); - -{ - _x params ["_setting", "_value", "_force"]; - - [_setting, _value, _force, _source] call EFUNC(settings,set); -} forEach _info; - -LOG("Settings file loaded from PBO."); diff --git a/template/static_settings_addon/script_component.hpp b/template/static_settings_addon/script_component.hpp deleted file mode 100644 index 5e7d63404..000000000 --- a/template/static_settings_addon/script_component.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#define COMPONENT static_settings_addon -#include "\x\cba\addons\main\script_mod.hpp" - -//#define DEBUG_ENABLED_STATIC_SETTINGS_ADDON - -#ifdef DEBUG_ENABLED_STATIC_SETTINGS_ADDON - #define DEBUG_MODE_FULL -#endif - -#ifdef DEBUG_SETTINGS_STATIC_SETTINGS_ADDON - #define DEBUG_SETTINGS DEBUG_SETTINGS_STATIC_SETTINGS_ADDON -#endif - -#include "\x\cba\addons\main\script_macros.hpp" - -#define PATH_SETTINGS_FILE_PBO QPATHTOF(userconfig\cba\settings.sqf) diff --git a/userconfig/cba_settings.sqf b/userconfig/cba_settings.sqf new file mode 100644 index 000000000..e69de29bb