From e277b05afff3cd810054470dc9d20b04b88fd0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Badano?= Date: Fri, 30 Jan 2015 18:56:45 -0300 Subject: [PATCH] ace_settings: first draft --- addons/common/CfgEventHandlers.hpp | 1 - addons/common/XEH_preInit.sqf | 8 +- addons/common/config.cpp | 10 ++- .../functions/fnc_loadSettingsOnServer.sqf | 74 ++++++++++++++++++ addons/common/functions/fnc_setSetting.sqf | 40 ++++++++++ .../functions/fnc_setSettingFromConfig.sqf | 76 +++++++++++++++++++ addons/common/scripts/readParameters.sqf | 55 -------------- addons/nametags/config.cpp | 42 +++++++--- 8 files changed, 235 insertions(+), 71 deletions(-) create mode 100644 addons/common/functions/fnc_loadSettingsOnServer.sqf create mode 100644 addons/common/functions/fnc_setSetting.sqf create mode 100644 addons/common/functions/fnc_setSettingFromConfig.sqf delete mode 100644 addons/common/scripts/readParameters.sqf diff --git a/addons/common/CfgEventHandlers.hpp b/addons/common/CfgEventHandlers.hpp index 7ea3b1e1f9..b9c5d7e4ce 100644 --- a/addons/common/CfgEventHandlers.hpp +++ b/addons/common/CfgEventHandlers.hpp @@ -2,7 +2,6 @@ class Extended_PreInit_EventHandlers { class ADDON { init = QUOTE(call COMPILE_FILE(XEH_preInit)); - serverInit = QUOTE(call COMPILE_FILE(scripts\readParameters)); disableModuload = true; }; }; diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 1bd305fa02..6cd1c4ce61 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -85,6 +85,7 @@ PREP(isInBuilding); PREP(isPlayer); PREP(isTurnedOut); PREP(letterToCode); +PREP(loadSettingsOnServer); PREP(map); PREP(moduleCheckPBOs); PREP(moduleLSDVehicles); @@ -115,6 +116,8 @@ PREP(setName); PREP(setParameter); PREP(setPitchBankYaw); PREP(setVariableJIP); +PREP(setSetting); +PREP(setSettingFromConfig); PREP(stringToColoredText); PREP(subString); PREP(toBin); @@ -163,6 +166,10 @@ PREP(hashListSet); PREP(hashListPush); +// Load settings +if (isServer) {} + call FUNC(loadSettingsOnServer); +}; ACE_player = player; @@ -183,7 +190,6 @@ if (hasInterface) then { }, 0, []] call cba_fnc_addPerFrameHandler; }; - PREP(stringCompare); PREP(string_removeWhiteSpace); PREP(isHC); diff --git a/addons/common/config.cpp b/addons/common/config.cpp index 2be05e6b57..0189facd47 100644 --- a/addons/common/config.cpp +++ b/addons/common/config.cpp @@ -57,10 +57,16 @@ class ACE_canInteractConditions { }; }; -class ACE_Options { +class ACE_Settings { + class GVAR(forceAllSettings) { + value = 0; + typeName = "BOOL"; + }; class GVAR(enableNumberHotkeys) { + value = 1; + typeName = "BOOL"; + isClientSetable = 1; displayName = "$STR_ACE_Common_EnableNumberHotkeys"; - default = 1; }; }; diff --git a/addons/common/functions/fnc_loadSettingsOnServer.sqf b/addons/common/functions/fnc_loadSettingsOnServer.sqf new file mode 100644 index 0000000000..000d8f69cc --- /dev/null +++ b/addons/common/functions/fnc_loadSettingsOnServer.sqf @@ -0,0 +1,74 @@ +/* + * Author: CAA-Picard + * Load the parameters on the server. + * Config < Server UserConfig < Mission Config + * + * Arguments: + * None + * + * Return Value: + * None + * + * Public: No + */ +#include "script_component.hpp" + +GVAR(settingsList) = []; + +// Load settings from main config +_countOptions = count (configFile >> "ACE_Settings"); +for "_index" from 0 to (_countOptions - 1) do { + _optionEntry = (configFile >> "ACE_Settings") select _index; + + _name = configName _optionEntry; + _valueEntry = _optionEntry >> "value"; + _typeEntry = _optionEntry >> "typeName"; + + [_name, _valueEntry, _typeEntry] call FUNC(setSettingFromConfig); +}; +// Check if all settings should be forced +if (GVAR(forceAllSettings)) then { + { + if !(missionNamespace getVariable format ["%1_forced", _x]) then { + missionNamespace setVariable format ["%1_forced", _x, true]; + publicVariable format ["%1_forced", _name]; + }; + } forEach GVAR(settingsList); +}; + + +// Load settings from server userconfig +DFUNC(common,serverUserConfig) = compile preprocessFileLineNumbers "\userconfig\ACE\ACE_Settings.hpp"; +if !(isNil QFUNC(common,serverUserConfig)) then { + [] call FUNC(serverUserConfig); +}; +// Check if all settings should be forced +if (GVAR(forceAllSettings)) then { + { + if !(missionNamespace getVariable format ["%1_forced", _x]) then { + missionNamespace setVariable format ["%1_forced", _x, true]; + publicVariable format ["%1_forced", _name]; + }; + } forEach GVAR(settingsList); +}; + + +// Load settings from mission config +_countOptions = count (missionConfigFile >> "ACE_Settings"); +for "_index" from 0 to (_countOptions - 1) do { + _optionEntry = (missionConfigFile >> "ACE_Settings") select _index; + + _name = configName _optionEntry; + _valueEntry = _optionEntry >> "value"; + + [_name, _valueEntry] call FUNC(setSettingFromConfig); +}; +// Check if all settings should be forced +if (GVAR(forceAllSettings)) then { + { + if !(missionNamespace getVariable format ["%1_forced", _x]) then { + missionNamespace setVariable format ["%1_forced", _x, true]; + publicVariable format ["%1_forced", _name]; + }; + } forEach GVAR(settingsList); +}; \ No newline at end of file diff --git a/addons/common/functions/fnc_setSetting.sqf b/addons/common/functions/fnc_setSetting.sqf new file mode 100644 index 0000000000..5a570d618a --- /dev/null +++ b/addons/common/functions/fnc_setSetting.sqf @@ -0,0 +1,40 @@ +/* + * Author: CAA-Picard + * Set a setting if it was not previosuly forced. Force if neccesary. + * + * Arguments: + * 0: Setting name (String) + * 1: Value (Any) + * 2: Force it? (Bool) (Optional) + * + * Return Value: + * None + * + * Public: No + */ +#include "script_component.hpp" + +EXPLODE_2_PVT(_this,_name,_value); + +if !(isServer) exitWith {}; + +private ["force"]; +_force = false; +if (count _this > 2) then { + _force = _this select 2; +}; + +// Check if it's already forced and quit +if (missionNamespace getVariable [format ["%1_forced", _name], false]) exitWith {}; + +// Check if the variable is already defined +if (isNil _name) then { + // Add the variable to a list on the server + GVAR(settingsList) pushBack _name; +}; + +// Update the variable and publish it +missionNamespace setVariable [_name, _value]; +publicVariable _name; +missionNamespace setVariable [format ["%1_forced", _name], _force]; +publicVariable format ["%1_forced", _name]; diff --git a/addons/common/functions/fnc_setSettingFromConfig.sqf b/addons/common/functions/fnc_setSettingFromConfig.sqf new file mode 100644 index 0000000000..8423a16bef --- /dev/null +++ b/addons/common/functions/fnc_setSettingFromConfig.sqf @@ -0,0 +1,76 @@ +/* + * Author: CAA-Picard + * Load a setting from config if it was not previosuly forced. Force if neccesary. + * + * Arguments: + * 0: Setting name (String) + * 1: Config entry (config entry) + * + * Return Value: + * None + * + * Public: No + */ +#include "script_component.hpp" + +EXPLODE_2_PVT(_this,_name,_optionEntry); + +_fnc_getValueWithType = { + EXPLODE_2_PVT(_this,_optionEntry,_typeName); + + _value = getNumber (_optionEntry >> "value"); + if (_typeName == "BOOL") exitWith { + _value = _value > 0; + }; + if (_typeName == "STRING") exitWith { + _value = getText (_optionEntry >> "value"); + }; + if (_typeName == "ARRAY") exitWith { + _value = getArray (_optionEntry >> "value"); + }; + _value +}; + +// Check if the variable is already defined +if (isNil _name) exitWith { + // That setting was not loaded yet + + //diag_log text format ["[ACE]: Mission setting '%1' doesn't exist", _name]; + + _typeEntry = _this select 2; + _typeName = getText _typeEntry; + + _value = [_optionEntry, _typeName] call _fnc_getValueWithType; + + // Init the variable and publish it + missionNamespace setVariable [_name, _value]; + publicVariable _name; + // Set the variable to not forced + missionNamespace setVariable [format ["%1_forced", _name], false]; + publicVariable format ["%1_forced", _name]; + + // Add the variable to a list on the server + GVAR(settingsList) pushBack _name; + +} else { + // The setting already exists. + + // Check if it's already forced and quit + if (missionNamespace getVariable format ["%1_forced", _name]) exitWith {}; + + // The setting is not forced, so update the value + + // Get the type from the existing variable + _typeName = typeName missionNamespace getVariable _name; + _value = [_optionEntry, _typeName] call _fnc_getValueWithType; + + // Update the variable and publish it + missionNamespace setVariable [_name, _value]; + publicVariable _name; + + // Check if it needs forcing + if (getNumber (_optionEntry >> "force") > 0) then { + missionNamespace setVariable [format ["%1_forced", _name], true]; + publicVariable format ["%1_forced", _name]; + }; +}; diff --git a/addons/common/scripts/readParameters.sqf b/addons/common/scripts/readParameters.sqf deleted file mode 100644 index 3b17ea7f1f..0000000000 --- a/addons/common/scripts/readParameters.sqf +++ /dev/null @@ -1,55 +0,0 @@ -// by CAA-Picard -#include "script_component.hpp" - -// Read ACE_Parameters from config and set them on the mission namespace -_config = configFile >> "ACE_Parameters_Numeric"; -_count = count _config; -for "_index" from 0 to (_count - 1) do { - _x = _config select _index; - - _name = configName _x; - _value = _x call bis_fnc_getcfgdata; - [_name, _value] call FUNC(setParameter); -}; - -_config = configFile >> "ACE_Parameters_Boolean"; -_count = count _config; -for "_index" from 0 to (_count - 1) do { - _x = _config select _index; - - _name = configName _x; - _value = _x call bis_fnc_getcfgdata; - [_name, _value > 0] call FUNC(setParameter); -}; - - -// Read ACE_Parameters from mission and set them on the mission namespace, replacing defaults if necesary -_config = missionConfigFile >> "ACE_Parameters"; -_count = count _config; -for "_index" from 0 to (_count - 1) do { - _x = _config select _index; - - _name = configName _x; - _value = _x call bis_fnc_getcfgdata; - [_name, _value] call FUNC(setParameter); -}; - -_config = missionConfigFile >> "ACE_Parameters_Numeric"; -_count = count _config; -for "_index" from 0 to (_count - 1) do { - _x = _config select _index; - - _name = configName _x; - _value = _x call bis_fnc_getcfgdata; - [_name, _value] call FUNC(setParameter); -}; - -_config = missionConfigFile >> "ACE_Parameters_Boolean"; -_count = count _config; -for "_index" from 0 to (_count - 1) do { - _x = _config select _index; - - _name = configName _x; - _value = _x call bis_fnc_getcfgdata; - [_name, _value > 0] call FUNC(setParameter); -}; diff --git a/addons/nametags/config.cpp b/addons/nametags/config.cpp index 1846cd616e..58440192c0 100644 --- a/addons/nametags/config.cpp +++ b/addons/nametags/config.cpp @@ -15,29 +15,47 @@ class CfgPatches { #include "CfgEventHandlers.hpp" #include "CfgVehicles.hpp" -class ACE_Options { +class ACE_Settings { class GVAR(showPlayerNames) { + value = 1; + typeName = "SCALAR"; + isClientSetable = 1; displayName = "$STR_ACE_NameTags_ShowPlayerNames"; values[] = {"Disabled", "Enabled", "Only Cursor", "Only On Keypress", "Only Cursor and KeyPress"}; - default = 1; }; class GVAR(showPlayerRanks) { + value = 1; + typeName = "BOOL"; + isClientSetable = 1; displayName = "$STR_ACE_NameTags_ShowPlayerRanks"; - default = 1; }; class GVAR(showVehicleCrewInfo) { + value = 1; + typeName = "BOOL"; + isClientSetable = 1; displayName = "$STR_ACE_CrewInfo_ShowVehicleCrewInfo"; - default = 1; }; -}; -class ACE_Parameters_Numeric { - GVAR(PlayerNamesViewDistance) = 5; - GVAR(PlayerNamesMaxAlpha) = 0.8; - GVAR(CrewInfoVisibility) = 0; -}; -class ACE_Parameters_Boolean { - GVAR(ShowNamesForAI) = 0; + class GVAR(PlayerNamesViewDistance) { + value = 5; + typeName = "SCALAR"; + isClientSetable = 0; + }; + class GVAR(PlayerNamesMaxAlpha) { + value = 0.8; + typeName = "SCALAR"; + isClientSetable = 0; + }; + class GVAR(CrewInfoVisibility) { + value = 0; + typeName = "BOOL"; + isClientSetable = 0; + }; + class GVAR(ShowNamesForAI) { + value = 0; + typeName = "BOOL"; + isClientSetable = 0; + }; }; #include