diff --git a/addons/events/XEH_postInit.sqf b/addons/events/XEH_postInit.sqf index 5c9c3354a..39b4855a8 100644 --- a/addons/events/XEH_postInit.sqf +++ b/addons/events/XEH_postInit.sqf @@ -1,12 +1,13 @@ #include "script_component.hpp" // execute JIP events after post init to guarantee execution of events added during postInit -{ +[{ { private _event = GVAR(eventNamespaceJIP) getVariable _x; - - if ((_event select 0) isEqualTo EVENT_PVAR_STR) then { - (_event select 1) call CBA_fnc_localEvent; + if (_event isEqualType []) then { + if ((_event select 0) isEqualTo EVENT_PVAR_STR) then { + (_event select 1) call CBA_fnc_localEvent; + }; }; } forEach allVariables GVAR(eventNamespaceJIP); -} call CBA_fnc_execNextFrame; +}, []] call CBA_fnc_execNextFrame; diff --git a/addons/keybinding/CfgEventHandlers.hpp b/addons/keybinding/CfgEventHandlers.hpp index e4cc840f7..a5a470efd 100644 --- a/addons/keybinding/CfgEventHandlers.hpp +++ b/addons/keybinding/CfgEventHandlers.hpp @@ -1,8 +1,12 @@ -class Extended_PreInit_EventHandlers -{ - class ADDON - { - clientInit = QUOTE(call COMPILE_FILE(XEH_preClientInit)); + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); }; }; +class Extended_DisplayLoad_EventHandlers { + class RscDisplayConfigure { + ADDON = QUOTE(_this call COMPILE_FILE(XEH_configureDisplayLoad)); + }; +}; diff --git a/addons/keybinding/gui/initDisplay.sqf b/addons/keybinding/XEH_configureDisplayLoad.sqf similarity index 100% rename from addons/keybinding/gui/initDisplay.sqf rename to addons/keybinding/XEH_configureDisplayLoad.sqf diff --git a/addons/keybinding/XEH_preClientInit.sqf b/addons/keybinding/XEH_preInit.sqf similarity index 98% rename from addons/keybinding/XEH_preClientInit.sqf rename to addons/keybinding/XEH_preInit.sqf index f456d4d20..4cb0be2e4 100644 --- a/addons/keybinding/XEH_preClientInit.sqf +++ b/addons/keybinding/XEH_preInit.sqf @@ -1,6 +1,8 @@ #include "script_component.hpp" SCRIPT(XEH_preInit); +if (!hasInterface) exitWith {}; + ADDON = false; // Load DIK to string conversion table. diff --git a/addons/keybinding/gui/gui.hpp b/addons/keybinding/gui/gui.hpp index e9005f850..cc84c134e 100644 --- a/addons/keybinding/gui/gui.hpp +++ b/addons/keybinding/gui/gui.hpp @@ -25,8 +25,6 @@ class RscListBoxKeys; /////////////////////////////////////////////////////////////////////////////// class RscDisplayConfigure { - onLoad = "[""onLoad"",_this,""RscDisplayConfigure"",'GUI'] call compile preprocessfilelinenumbers ""A3\ui_f\scripts\initDisplay.sqf""; _this call compile preprocessfilelinenumbers ""\x\cba\addons\keybinding\gui\initDisplay.sqf"""; - class controls { class CA_ButtonCancel: RscButtonMenuCancel { onButtonClick = "_this call cba_keybinding_fnc_onButtonClick_cancel"; diff --git a/addons/settings/$PBOPREFIX$ b/addons/settings/$PBOPREFIX$ new file mode 100644 index 000000000..9795e7d6d --- /dev/null +++ b/addons/settings/$PBOPREFIX$ @@ -0,0 +1 @@ +x\cba\addons\settings diff --git a/addons/settings/CBA_Settings.hpp b/addons/settings/CBA_Settings.hpp new file mode 100644 index 000000000..c04fab822 --- /dev/null +++ b/addons/settings/CBA_Settings.hpp @@ -0,0 +1,29 @@ + +class CBA_Setting_Boolean_base { + type = "BOOLEAN"; + displayName = ""; + tooltip = ""; + defaultValue = 0; +}; + +class CBA_Setting_List_base { + type = "LIST"; + displayName = ""; + tooltip = ""; + values[] = {0,1}; + //valueNames[] = {"disabled","enabled"}; + defaultIndex = 0; +}; + +class CBA_Setting_Slider_base { + type = "SLIDER"; + displayName = ""; + tooltip = ""; + min = 0; + max = 100; + defaultValue = 50; +}; + +class CBA_Settings { + class CBA {}; +}; diff --git a/addons/settings/Cfg3DEN.hpp b/addons/settings/Cfg3DEN.hpp new file mode 100644 index 000000000..18f629e29 --- /dev/null +++ b/addons/settings/Cfg3DEN.hpp @@ -0,0 +1,25 @@ + +class Cfg3DEN { + class Mission { + class Scenario { + class AttributeCategories { + class Presentation { // any existing + class Attributes { + class BriefingName; + class Author; // needed, to put blank space at the end. for looks + class GVAR(missionSettings) { + property = QGVAR(missionSettings); + value = 0; + control = "Default"; // blank space. not editable by hand + displayName = ""; + tooltip = ""; + defaultValue = "[]"; + expression = "missionNamespace setVariable ['%s',_value,true]"; + wikiType = "[[Array]]"; + }; + }; + }; + }; + }; + }; +}; diff --git a/addons/settings/CfgEventHandlers.hpp b/addons/settings/CfgEventHandlers.hpp new file mode 100644 index 000000000..3d419f755 --- /dev/null +++ b/addons/settings/CfgEventHandlers.hpp @@ -0,0 +1,18 @@ + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; + +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; + +class Extended_DisplayLoad_EventHandlers { + class RscDisplayGameOptions { + ADDON = QUOTE(_this call COMPILE_FILE(init_display)); + }; +}; diff --git a/addons/settings/CfgFunctions.hpp b/addons/settings/CfgFunctions.hpp new file mode 100644 index 000000000..b18b69e13 --- /dev/null +++ b/addons/settings/CfgFunctions.hpp @@ -0,0 +1,15 @@ + +#define F_FILEPATH(func) class func {\ + file = QUOTE(PATHTOF(DOUBLES(fnc,func).sqf));\ +} + +class CfgFunctions { + class CBA { + class Settings { + F_FILEPATH(setSetting); + F_FILEPATH(setSettingProfile); + F_FILEPATH(getSetting); + F_FILEPATH(forceSetting); + }; + }; +}; diff --git a/addons/settings/XEH_postInit.sqf b/addons/settings/XEH_postInit.sqf new file mode 100644 index 000000000..9f0bbb4ad --- /dev/null +++ b/addons/settings/XEH_postInit.sqf @@ -0,0 +1,24 @@ +#include "script_component.hpp" +SCRIPT(XEH_postInit); + +if (!isServer) then { + #include "init_settings.sqf" +}; + +// init mission settings +GVAR(missionSettings) params [["_missionSettings", []], ["_missionValues", []]]; + +{ + // values are set only locally, because GVAR(missionSettings) is already a global var + missionNamespace setVariable [SETTING_KEY_MISSION(_x), _missionValues select _forEachIndex]; + missionNamespace setVariable [SETTING_KEY_MISSION_FORCE(_x), true]; +} forEach _missionSettings; + +// refresh all settings after postInit to guarantee that events are added +{ + GVAR(settingsInit) = true; + + { + [QGVAR(refreshSetting), _x] call CBA_fnc_localEvent; + } forEach allVariables GVAR(settingsDefault); +} call CBA_fnc_execNextFrame; diff --git a/addons/settings/XEH_preInit.sqf b/addons/settings/XEH_preInit.sqf new file mode 100644 index 000000000..8b3f3641c --- /dev/null +++ b/addons/settings/XEH_preInit.sqf @@ -0,0 +1,30 @@ +#include "script_component.hpp" +SCRIPT(XEH_preInit); + +ADDON = false; + +GVAR(settingsInit) = false; + +[QGVAR(refreshSetting), { + params ["_setting"]; + private _value = _setting call CBA_fnc_getSetting; + + missionNamespace setVariable [_setting, _value]; + + if (GVAR(settingsInit)) then { + ["CBA_SettingChanged", [_setting, _value]] call CBA_fnc_localEvent; + }; +}] call CBA_fnc_addEventHandler; + +if (isServer) then { + [QGVAR(setSettingRemote), { + _this call CBA_fnc_setSettingProfile; + _this call CBA_fnc_setSetting; + }] call CBA_fnc_addEventHandler; + + [QGVAR(forceSettingRemote), CBA_fnc_forceSetting] call CBA_fnc_addEventHandler; + + #include "init_settings.sqf" +}; + +ADDON = true; diff --git a/addons/settings/config.cpp b/addons/settings/config.cpp new file mode 100644 index 000000000..1f7fe059e --- /dev/null +++ b/addons/settings/config.cpp @@ -0,0 +1,21 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"CBA_common", "A3_UI_F"}; + version = VERSION; + author[] = {"commy2"}; + authorUrl = "https://github.com/CBATeam/CBA_A3"; + }; +}; + +#include "CfgEventHandlers.hpp" +#include "CfgFunctions.hpp" + +#include "CBA_Settings.hpp" +#include "Cfg3DEN.hpp" + +#include "gui.hpp" diff --git a/addons/settings/fnc_forceSetting.sqf b/addons/settings/fnc_forceSetting.sqf new file mode 100644 index 000000000..376f63db6 --- /dev/null +++ b/addons/settings/fnc_forceSetting.sqf @@ -0,0 +1,34 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_forceSetting + +Description: + Force a setting. Use "client" to set as not forced. Has to be executed on the server machine. + +Parameters: + _setting - Name of the setting + _force - true: force, false: release + +Returns: + None + +Examples: + (begin example) + ["CBA_TestSetting", "server"] call CBA_fnc_forceSetting + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" + +if (!isServer) exitWith {}; + +params [["_setting", "", [""]], ["_force", true, [false]]]; + +missionNamespace setVariable [SETTING_KEY_SERVER_FORCE(_setting), _force, true]; +profileNamespace setVariable [SETTING_KEY_SERVER_FORCE(_setting), _force]; + +// send changed event, because the current active setting could have changed +[QGVAR(refreshSetting), _setting] call CBA_fnc_globalEvent; + +nil diff --git a/addons/settings/fnc_getSetting.sqf b/addons/settings/fnc_getSetting.sqf new file mode 100644 index 000000000..9287445f8 --- /dev/null +++ b/addons/settings/fnc_getSetting.sqf @@ -0,0 +1,57 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_getSetting + +Description: + Returns a setting. + +Parameters: + _setting - Name of the setting + _source - Can be "current", "server", "mission", "client" or "default" (optional, default: "current") + +Returns: + Value of the setting + +Examples: + (begin example) + _result = "CBA_TestSetting" call CBA_fnc_getSetting + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" + +params [["_setting", "", [""]], ["_source", "current", [""]]]; + +// change source to whatever should take precedence +if (_source == "current") then { + if (missionNamespace getVariable [SETTING_KEY_SERVER_FORCE(_setting), false]) exitWith { _source = "server" }; + if (missionNamespace getVariable [SETTING_KEY_MISSION_FORCE(_setting), false]) exitWith { _source = "mission" }; + _source = "client"; +}; + +private "_return"; + +if (_source == "client") then { + _return = profileNamespace getVariable SETTING_KEY_CLIENT(_setting); +}; + +if (_source == "server") then { + _return = missionNamespace getVariable SETTING_KEY_SERVER(_setting); +}; + +if (_source == "mission") then { + _return = missionNamespace getVariable SETTING_KEY_MISSION(_setting); + + if (isNil "_return") then { + _source = "default"; + }; // use default for undefined mission settings +}; + +if (_source == "default") then { + _return = (GVAR(settingsDefault) getVariable _setting) select 0; +}; + +// copy array to prevent overwriting +if (isNil "_return") exitWith { nil }; +if (_return isEqualType []) then { +_return } else { _return } diff --git a/addons/settings/fnc_onButtonClick_configure.sqf b/addons/settings/fnc_onButtonClick_configure.sqf new file mode 100644 index 000000000..02baa1e8b --- /dev/null +++ b/addons/settings/fnc_onButtonClick_configure.sqf @@ -0,0 +1,121 @@ +#include "script_component.hpp" + +// Get button +params ["_control"]; + +// Get dialog +private _display = ctrlParent _control; + +private _ctrlGeneralGroup = _display displayCtrl 2300; +private _ctrlColorsGroup = _display displayCtrl 2301; +private _ctrlDifficultyGroup = _display displayCtrl 2302; +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 _ctrlDifficultyButton = _display displayCtrl 304; +private _ctrlGeneralButton = _display displayCtrl 2402; +private _ctrlGUIButton = _display displayCtrl 2404; +private _ctrlLayoutButton = _display displayCtrl 2405; +private _ctrlTitle = _display displayCtrl 1000; + +// Toggle displayed groups and buttons. +if !(ctrlEnabled _ctrlAddonsGroup) then { + // Hide general group + _ctrlGeneralGroup ctrlEnable false; + _ctrlGeneralGroup ctrlShow false; + + // Hide colors group + _ctrlColorsGroup ctrlEnable false; + _ctrlColorsGroup ctrlShow false; + + // Hide difficulty group + _ctrlDifficultyGroup ctrlEnable false; + _ctrlDifficultyGroup ctrlShow false; + + // Hide Presets button + private _control = _display displayCtrl 114; + _control ctrlEnable false; + _control ctrlShow false; + + // Hide Default button + _control = _display displayCtrl 101; + _control ctrlEnable false; + _control ctrlShow false; + + // Hide difficulty, general, gui, and layout buttons + _ctrlDifficultyButton ctrlEnable false; + _ctrlDifficultyButton ctrlShow false; + _ctrlGeneralButton ctrlEnable false; + _ctrlGeneralButton ctrlShow false; + _ctrlGUIButton ctrlEnable false; + _ctrlGUIButton ctrlShow false; + _ctrlLayoutButton ctrlEnable false; + _ctrlLayoutButton ctrlShow false; + + // Show general buttons + _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; + + // Show Addons group + _ctrlAddonsGroup ctrlEnable true; + _ctrlAddonsGroup ctrlShow true; + + // Change button text + _ctrlToggleButton ctrlSetText localize LSTRING(configureBase); + + // emulate default scope selection + ([_ctrlClientButton, _ctrlServerButton] select !CAN_VIEW_CLIENT_SETTINGS) call COMPILE_FILE(fnc_onButtonClick_scope); +} else { + // Switch back to vanilla keyboard config. + // Hide Addons group + _ctrlAddonsGroup ctrlEnable false; + _ctrlAddonsGroup ctrlShow false; + _ctrlToggleButton ctrlSetText localize LSTRING(configureAddons); + + //--- Enable General + _ctrlGeneralGroup ctrlEnable true; + _ctrlGeneralGroup ctrlShow true; + + //--- Disable Colors + _ctrlColorsGroup ctrlEnable false; + _ctrlColorsGroup ctrlShow false; + + //--- Disable Difficulty + _ctrlDifficultyGroup ctrlEnable false; + _ctrlDifficultyGroup ctrlShow false; + + // Hide general buttons + _ctrlClientButton ctrlEnable false; + _ctrlClientButton ctrlShow false; + _ctrlServerButton ctrlEnable false; + _ctrlServerButton ctrlShow false; + _ctrlMissionButton ctrlEnable false; + _ctrlMissionButton ctrlShow false; + + // Show difficulty, general, gui, and layout buttons + _ctrlDifficultyButton ctrlEnable true; + _ctrlDifficultyButton ctrlShow true; + _ctrlGeneralButton ctrlEnable true; + _ctrlGeneralButton ctrlShow true; + _ctrlGUIButton ctrlEnable true; + _ctrlGUIButton ctrlShow true; + _ctrlLayoutButton ctrlEnable true; + _ctrlLayoutButton ctrlShow true; + + //--- Show Presets button + private _control = _display displayCtrl 114; + _control ctrlEnable true; + _control ctrlShow true; + + //--- Hide Default button + _control = _display displayCtrl 101; + _control ctrlEnable false; + _control ctrlShow false; +}; diff --git a/addons/settings/fnc_onButtonClick_scope.sqf b/addons/settings/fnc_onButtonClick_scope.sqf new file mode 100644 index 000000000..a3865c395 --- /dev/null +++ b/addons/settings/fnc_onButtonClick_scope.sqf @@ -0,0 +1,30 @@ +#include "script_component.hpp" + +// Get button +params ["_control"]; + +// Get dialog +private _display = ctrlParent _control; + +private _selectedScope = _control getVariable "scope"; +_display setVariable ["scope", _selectedScope]; + +private _selectedAddon = _display getVariable "addon"; + +{ + (_x splitString "$") params ["_addon", "_scope"]; + private _ctrlOptionsGroup = _display getVariable _x; + + private _isSelected = _scope == _selectedScope && {_addon == _selectedAddon}; + + _ctrlOptionsGroup ctrlEnable _isSelected; + _ctrlOptionsGroup ctrlShow _isSelected; +} forEach (_display getVariable "lists"); + +{ + 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]; + +(_display displayCtrl IDC_TXT_FORCE) ctrlShow (_selectedScope != "client"); diff --git a/addons/settings/fnc_onLBSelChanged_addon.sqf b/addons/settings/fnc_onLBSelChanged_addon.sqf new file mode 100644 index 000000000..20644d742 --- /dev/null +++ b/addons/settings/fnc_onLBSelChanged_addon.sqf @@ -0,0 +1,24 @@ +#include "script_component.hpp" + +// Get button +params ["_control", "_index"]; + +// Get dialog +private _display = ctrlParent _control; + +private _selectedScope = _display getVariable "scope"; + +private _selectedAddon = _control getVariable (_control lbData _index); +_display setVariable ["addon", _selectedAddon]; + +{ + (_x splitString "$") params ["_addon", "_scope"]; + private _ctrlOptionsGroup = _display getVariable _x; + + private _isSelected = _scope == _selectedScope && {_addon == _selectedAddon}; + + _ctrlOptionsGroup ctrlEnable _isSelected; + _ctrlOptionsGroup ctrlShow _isSelected; +} forEach (_display getVariable "lists"); + +uiNamespace setVariable [QGVAR(addonIndex), _index]; diff --git a/addons/settings/fnc_saveTemporaryData.sqf b/addons/settings/fnc_saveTemporaryData.sqf new file mode 100644 index 000000000..26e956dbd --- /dev/null +++ b/addons/settings/fnc_saveTemporaryData.sqf @@ -0,0 +1,55 @@ +#include "script_component.hpp" + +{ + // can be used in main menu. use ui copy of function + [_x, GVAR(settingsTempClient) getVariable _x] call (uiNamespace getVariable "CBA_fnc_setSettingProfile"); + [_x, GVAR(settingsTempClient) getVariable _x] call (uiNamespace getVariable "CBA_fnc_setSetting"); +} forEach allVariables GVAR(settingsTempClient); + +{ + [QGVAR(setSettingRemote), [_x, GVAR(settingsTempServer) getVariable _x]] call CBA_fnc_serverEvent; +} forEach allVariables GVAR(settingsTempServer); + +{ + [QGVAR(forceSettingRemote), [_x, GVAR(settingsForceTempServer) getVariable _x]] call CBA_fnc_serverEvent; +} forEach allVariables GVAR(settingsForceTempServer); + +// save mission settings in mission.sqm if they are set as forced +if (is3DEN) then { + { + missionNamespace setVariable [SETTING_KEY_MISSION(_x), GVAR(settingsTempMission) getVariable _x]; + } forEach allVariables GVAR(settingsTempMission); + + { + private _setting = toLower _x; + + if (GVAR(settingsForceTempMission) getVariable _x) then { + missionNamespace setVariable [SETTING_KEY_MISSION_FORCE(_setting), true]; + + private _value = [_setting, "mission"] call CBA_fnc_getSetting; + + ("Scenario" get3DENMissionAttribute QGVAR(missionSettings)) params [["_missionSettings", []], ["_missionValues", []]]; + private _index = _missionSettings find _setting; + + if (_index < 0) then { + _index = count _missionSettings; + }; + + _missionSettings set [_index, _setting]; + _missionValues set [_index, _value]; + + set3DENMissionAttributes [["Scenario", QGVAR(missionSettings), [_missionSettings, _missionValues]]]; + } else { + missionNamespace setVariable [SETTING_KEY_MISSION_FORCE(_setting), false]; + + // remove setting from mission.sqm + ("Scenario" get3DENMissionAttribute QGVAR(missionSettings)) params [["_missionSettings", []], ["_missionValues", []]]; + private _index = _missionSettings find _setting; + + _missionSettings deleteAt _index; + _missionValues deleteAt _index; + + set3DENMissionAttributes [["Scenario", QGVAR(missionSettings), [_missionSettings, _missionValues]]]; + }; + } forEach allVariables GVAR(settingsForceTempMission); +}; diff --git a/addons/settings/fnc_setSetting.sqf b/addons/settings/fnc_setSetting.sqf new file mode 100644 index 000000000..8a7b0e133 --- /dev/null +++ b/addons/settings/fnc_setSetting.sqf @@ -0,0 +1,37 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_setSetting + +Description: + Set a setting. + +Parameters: + _setting - Name of the setting + _value - Value of the setting + +Returns: + None + +Examples: + (begin example) + ["CBA_TestSetting", 1] call CBA_fnc_setSetting + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" + +params [["_setting", "", [""]], "_value"]; + +if (isServer) then { + missionNamespace setVariable [SETTING_KEY_SERVER(_setting), _value, true]; + + // if the setting is forced, send changed event to remote machines + if (missionNamespace getVariable [SETTING_KEY_SERVER_FORCE(_setting), false]) then { + [QGVAR(refreshSetting), [_setting, _value]] call CBA_fnc_remoteEvent; + }; +}; + +[QGVAR(refreshSetting), [_setting, _setting call CBA_fnc_getSetting]] call CBA_fnc_localEvent; + +nil diff --git a/addons/settings/fnc_setSettingProfile.sqf b/addons/settings/fnc_setSettingProfile.sqf new file mode 100644 index 000000000..0323bf105 --- /dev/null +++ b/addons/settings/fnc_setSettingProfile.sqf @@ -0,0 +1,34 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_setSettingProfile + +Description: + Overwrite a setting in the profileNamespace. + +Parameters: + _setting - Name of the setting + _value - Value of the setting + +Returns: + None + +Examples: + (begin example) + ["CBA_TestSetting", 1] call CBA_fnc_setSettingProfile + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" + +params [["_setting", "", [""]], "_value"]; + +if (isNil "_value") then { + _value = [_setting, "default"] call CBA_fnc_getSetting; +}; + +profileNamespace setVariable [SETTING_KEY_CLIENT(_setting), _value]; + +diag_log text format ["[CBA]: Saved setting to profile. (%1 = %2)", _setting, _value]; + +nil diff --git a/addons/settings/gui.hpp b/addons/settings/gui.hpp new file mode 100644 index 000000000..5c52130bc --- /dev/null +++ b/addons/settings/gui.hpp @@ -0,0 +1,120 @@ + +class RscControlsGroup { + class VScrollbar; + class HScrollbar; +}; + +class RscText; +class RscCombo; +class RscListNBox; +class RscButtonMenu; + +class GVAR(OptionsGroup): RscControlsGroup { + class HScrollbar: HScrollbar { + height = 0; + }; + x = "0.5 * (((safezoneW / safezoneH) min 1.2) / 40)"; + y = "3.5 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + w = "35 * (((safezoneW / safezoneH) min 1.2) / 40)"; + h = "13.8 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + lineHeight = "1 *((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + + 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 = "12 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + x = "4.5 * (((safezoneW / safezoneH) min 1.2) / 40)"; + y = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + w = "21 * (((safezoneW / safezoneH) min 1.2) / 40)"; + h = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; +}; + +class RscDisplayGameOptions { + class controls { + class CBA_ButtonConfigureAddons: RscButtonMenu { + idc = IDC_BTN_CONFIGURE_ADDONS; + text = CSTRING(configureAddons); + x = "20.15 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX)"; + y = "23 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))"; + w = "12.5 * (((safezoneW / safezoneH) min 1.2) / 40)"; + h = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + }; + + class CBA_ButtonClient: RscButtonMenu { + idc = IDC_BTN_CLIENT; + text = CSTRING(ButtonClient); + tooltip = CSTRING(ButtonClient_tooltip); + x = "1 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX)"; + y = "2.1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))"; + w = "8 * (((safezoneW / safezoneH) min 1.2) / 40)"; + h = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + }; + + class CBA_ButtonServer: CBA_ButtonClient { + idc = IDC_BTN_SERVER; + text = CSTRING(ButtonServer); + tooltip = CSTRING(ButtonServer_tooltip); + x = "9 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX)"; + }; + + class CBA_ButtonMission: CBA_ButtonClient { + idc = IDC_BTN_MISSION; + text = CSTRING(ButtonMission); + tooltip = CSTRING(ButtonMission_tooltip); + x = "17 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX)"; + }; + + class CBA_AddonsGroup: RscControlsGroup { + class VScrollbar: VScrollbar { + width = 0; + }; + class HScrollbar: HScrollbar { + height = 0; + }; + idc = IDC_ADDONS_GROUP; + enableDisplay = 0; + x = "1 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX)"; + y = "3.1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))"; + w = "38 * (((safezoneW / safezoneH) min 1.2) / 40)"; + h = "19.6 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + + class controls { + class CBA_AddonsEmptyBackground: RscText { + idc = -1; + type = 0; + text = ""; + colorBackground[] = {0,0,0,0.4}; + x = "0.5 * (((safezoneW / safezoneH) min 1.2) / 40)"; + y = "3.5 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + w = "35 * (((safezoneW / safezoneH) min 1.2) / 40)"; + h = "13.8 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + }; + class CBA_AddonsCA_ControlsPageText: RscText { + sizeEx = "(((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1)"; + style = 1; + idc = 2002; + text = "Addon:"; + x = "0.5 * (((safezoneW / safezoneH) min 1.2) / 40)"; + y = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + w = "4 * (((safezoneW / safezoneH) min 1.2) / 40)"; + h = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + }; + class CBA_ForceSettingText: RscText { + style = 1; + idc = IDC_TXT_FORCE; + text = ""; + tooltip = CSTRING(force_tooltip); + x = "25 * (((safezoneW / safezoneH) min 1.2) / 40)"; + y = "2.5 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + w = "10 * (((safezoneW / safezoneH) min 1.2) / 40)"; + h = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + }; + }; + }; + }; +}; diff --git a/addons/settings/init_display.sqf b/addons/settings/init_display.sqf new file mode 100644 index 000000000..b47f67a69 --- /dev/null +++ b/addons/settings/init_display.sqf @@ -0,0 +1,317 @@ +// Extra initialization steps for the vanilla RscDisplayConfigure dialog +// needed to support mod settings system. +#include "script_component.hpp" + +#include "init_settings.sqf" + +params ["_display"]; + +////////// +// dyncamically create gui +private _lists = []; +private _addons = []; + +private _allSettings = []; + +{ + { + _allSettings pushBackUnique configName _x; + } forEach ("true" configClasses _x); +} forEach ("true" configClasses (configFile >> "CBA_Settings")); + +{ + private _setting = _x; + (GVAR(settingsDefault) getVariable _setting) params ["_defaultValue", "_addon", "_settingType", "_values", "_valueNames", "_displayName", "_tooltip"]; + + private _addon = toLower _addon; + _addons pushBackUnique _addon; + + { + private _scope = toLower _x; + private _list = [_addon, _scope] joinString "$"; + + private "_ctrlOptionsGroup"; + if !(_list in _lists) then { + _ctrlOptionsGroup = _display ctrlCreate [QGVAR(OptionsGroup), -1, _display displayCtrl IDC_ADDONS_GROUP]; + _ctrlOptionsGroup ctrlEnable false; + _ctrlOptionsGroup ctrlShow false; + _lists pushBack _list; + _display setVariable [_list, _ctrlOptionsGroup]; + } else { + _ctrlOptionsGroup = _display getVariable _list; + }; + + private _offsetY = _ctrlOptionsGroup getVariable ["offsetY", 0]; + private _currentValue = [_setting, _scope] call (uiNamespace getVariable "CBA_fnc_getSetting"); + + private _ctrlSettingName = _display ctrlCreate ["RscText", -1, _ctrlOptionsGroup]; + + _ctrlSettingName ctrlSetText _displayName; + _ctrlSettingName ctrlSetTooltip _tooltip; + _ctrlSettingName ctrlSetPosition [ + POS_X(1), + POS_Y(_offsetY), + POS_X(10), + POS_Y(1) + ]; + _ctrlSettingName ctrlCommit 0; + + private _enabled = call { + if (_scope == "client") exitWith { + CAN_SET_CLIENT_SETTINGS && {!(missionNamespace getVariable [SETTING_KEY_SERVER_FORCE(_setting), false])} && {!(missionNamespace getVariable [SETTING_KEY_MISSION_FORCE(_setting), false])} + }; + if (_scope == "server") exitWith { + CAN_SET_SERVER_SETTINGS + }; + if (_scope == "mission") exitWith { + CAN_SET_MISSION_SETTINGS && {!(missionNamespace getVariable [SETTING_KEY_SERVER_FORCE(_setting), false])} + }; + false + }; + + if (_settingType == "BOOLEAN") then { + private _ctrlSetting = _display ctrlCreate ["RscCheckBox", -1, _ctrlOptionsGroup]; + + _ctrlSetting ctrlSetPosition [ + POS_X(20), + POS_Y(_offsetY), + POS_X(1), + POS_Y(1) + ]; + _ctrlSetting ctrlCommit 0; + + _ctrlSetting cbSetChecked _currentValue; + _ctrlSetting setVariable ["setting", _setting]; + + if (_enabled) then { + _ctrlSetting ctrlAddEventHandler ["CheckedChanged", { + params ["_ctrl", "_state"]; + private _value = _state == 1; + + private _tempNamespace = (ctrlParent _ctrl getVariable "scope") call { + if (_this == "client") exitWith {GVAR(settingsTempClient)}; + if (_this == "server") exitWith {GVAR(settingsTempServer)}; + if (_this == "mission") exitWith {GVAR(settingsTempMission)}; + }; + _tempNamespace setVariable [_ctrl getVariable "setting", _value]; + }]; + } else { + _ctrlSettingName ctrlSetTextColor COLOR_TEXT_DISABLED; + _ctrlSetting ctrlEnable false; + }; + }; + + if (_settingType == "LIST") then { + private _ctrlSetting = _display ctrlCreate ["RscCombo", -1, _ctrlOptionsGroup]; + + _ctrlSetting ctrlSetPosition [ + POS_X(20), + POS_Y(_offsetY), + POS_X(10), + POS_Y(1) + ]; + _ctrlSetting ctrlCommit 0; + + { + private _index = _ctrlSetting lbAdd (_valueNames select _forEachIndex); + _ctrlSetting lbSetData [_index, str _index]; + _ctrlSetting setVariable [str _index, _x]; + } forEach _values; + + _ctrlSetting lbSetCurSel (_values find _currentValue); + _ctrlSetting setVariable ["setting", _setting]; + + if (_enabled) then { + _ctrlSetting ctrlAddEventHandler ["LBSelChanged", { + params ["_ctrl", "_index"]; + private _value = _ctrl getVariable str _index; + + private _tempNamespace = (ctrlParent _ctrl getVariable "scope") call { + if (_this == "client") exitWith {GVAR(settingsTempClient)}; + if (_this == "server") exitWith {GVAR(settingsTempServer)}; + if (_this == "mission") exitWith {GVAR(settingsTempMission)}; + }; + _tempNamespace setVariable [_ctrl getVariable "setting", _value]; + }]; + } else { + _ctrlSettingName ctrlSetTextColor COLOR_TEXT_DISABLED; + _ctrlSetting ctrlEnable false; + }; + }; + + if (_settingType == "SLIDER") then { + private _ctrlSetting = _display ctrlCreate ["RscXSliderH", -1, _ctrlOptionsGroup]; + + _ctrlSetting ctrlSetPosition [ + POS_X(20), + POS_Y(_offsetY), + POS_X(8), + POS_Y(1) + ]; + _ctrlSetting ctrlCommit 0; + + private _ctrlSettingEdit = _display ctrlCreate ["RscEdit", -1, _ctrlOptionsGroup]; + + _ctrlSettingEdit ctrlSetPosition [ + POS_X(28), + POS_Y(_offsetY), + POS_X(2), + POS_Y(1) + ]; + _ctrlSettingEdit ctrlCommit 0; + + _ctrlSetting sliderSetRange _values; + _ctrlSetting sliderSetPosition _currentValue; + _ctrlSetting setVariable ["setting", _setting]; + + _ctrlSettingEdit ctrlSetText str round _currentValue; + _ctrlSettingEdit setVariable ["setting", _setting]; + + if (_enabled) then { + _ctrlSetting ctrlAddEventHandler ["SliderPosChanged", { + params ["_ctrl", "_value"]; + + (_ctrl getVariable "link") ctrlSetText str round _value; + + private _tempNamespace = (ctrlParent _ctrl getVariable "scope") call { + if (_this == "client") exitWith {GVAR(settingsTempClient)}; + if (_this == "server") exitWith {GVAR(settingsTempServer)}; + if (_this == "mission") exitWith {GVAR(settingsTempMission)}; + }; + _tempNamespace setVariable [_ctrl getVariable "setting", _value]; + }]; + + _ctrlSettingEdit ctrlAddEventHandler ["KeyUp", { + params ["_ctrl"]; + private _value = parseNumber ctrlText _ctrl; + + (_ctrl getVariable "link") sliderSetPosition _value; + + private _tempNamespace = (ctrlParent _ctrl getVariable "scope") call { + if (_this == "client") exitWith {GVAR(settingsTempClient)}; + if (_this == "server") exitWith {GVAR(settingsTempServer)}; + if (_this == "mission") exitWith {GVAR(settingsTempMission)}; + }; + _tempNamespace setVariable [_ctrl getVariable "setting", sliderPosition (_ctrl getVariable "link")]; + }]; + + _ctrlSettingEdit ctrlAddEventHandler ["KillFocus", { + params ["_ctrl"]; + _ctrl ctrlSetText str round sliderPosition (_ctrl getVariable "link"); + }]; + + _ctrlSetting setVariable ["link", _ctrlSettingEdit]; + _ctrlSettingEdit setVariable ["link", _ctrlSetting]; + } else { + _ctrlSettingName ctrlSetTextColor COLOR_TEXT_DISABLED; + _ctrlSetting ctrlEnable false; + _ctrlSettingEdit ctrlEnable false; + }; + }; + + // force setting toggle + if (_scope != "client") then { + private _ctrlSettingForce = _display ctrlCreate ["RscCheckBox", -1, _ctrlOptionsGroup]; + + _ctrlSettingForce ctrlSetPosition [ + POS_X(33), + POS_Y(_offsetY), + POS_X(1), + POS_Y(1) + ]; + _ctrlSettingForce ctrlCommit 0; + + _ctrlSettingForce cbSetChecked (missionNamespace getVariable [[SETTING_KEY_SERVER_FORCE(_setting), SETTING_KEY_MISSION_FORCE(_setting)] select (_scope == "mission"), false]); + _ctrlSettingForce setVariable ["setting", _setting]; + + if (_enabled) then { + _ctrlSettingForce ctrlAddEventHandler ["CheckedChanged", { + params ["_ctrl", "_value"]; + _value = _value == 1; + + private _tempNamespace = (ctrlParent _ctrl getVariable "scope") call { + if (_this == "server") exitWith {GVAR(settingsForceTempServer)}; + if (_this == "mission") exitWith {GVAR(settingsForceTempMission)}; + }; + _tempNamespace setVariable [_ctrl getVariable "setting", _value]; + }]; + } else { + _ctrlSettingForce ctrlEnable false; + }; + }; + + _ctrlOptionsGroup setVariable ["offsetY", _offsetY + 1.2]; + } forEach ["client", "server", "mission"]; +} forEach _allSettings; + +_display setVariable ["lists", _lists]; + +////////// +// default + +// group buttons +private _fnc_onClick = COMPILE_FILE(fnc_onButtonClick_scope); + +private _ctrlClientButton = _display displayCtrl IDC_BTN_CLIENT; +_ctrlClientButton ctrlEnable false; +_ctrlClientButton ctrlShow false; +_ctrlClientButton ctrlAddEventHandler ["ButtonClick", _fnc_onClick]; +_ctrlClientButton setVariable ["scope", "client"]; + +private _ctrlServerButton = _display displayCtrl IDC_BTN_SERVER; +_ctrlServerButton ctrlEnable false; +_ctrlServerButton ctrlShow false; +_ctrlServerButton ctrlAddEventHandler ["ButtonClick", _fnc_onClick]; +_ctrlServerButton setVariable ["scope", "server"]; + +private _ctrlMissionButton = _display displayCtrl IDC_BTN_MISSION; +_ctrlMissionButton ctrlEnable false; +_ctrlMissionButton ctrlShow false; +_ctrlMissionButton ctrlAddEventHandler ["ButtonClick", _fnc_onClick]; +_ctrlMissionButton setVariable ["scope", "mission"]; + +if (!isNil QGVAR(settingsTempClient)) then { + GVAR(settingsTempClient) call (uiNamespace getVariable "CBA_fnc_deleteNamespace"); + GVAR(settingsTempServer) call (uiNamespace getVariable "CBA_fnc_deleteNamespace"); + GVAR(settingsTempMission) call (uiNamespace getVariable "CBA_fnc_deleteNamespace"); + GVAR(settingsForceTempServer) call (uiNamespace getVariable "CBA_fnc_deleteNamespace"); + GVAR(settingsForceTempMission) call (uiNamespace getVariable "CBA_fnc_deleteNamespace"); +}; + +GVAR(settingsTempClient) = [] call (uiNamespace getVariable "CBA_fnc_createNamespace"); +GVAR(settingsTempServer) = [] call (uiNamespace getVariable "CBA_fnc_createNamespace"); +GVAR(settingsTempMission) = [] call (uiNamespace getVariable "CBA_fnc_createNamespace"); +GVAR(settingsForceTempServer) = [] call (uiNamespace getVariable "CBA_fnc_createNamespace"); +GVAR(settingsForceTempMission) = [] call (uiNamespace getVariable "CBA_fnc_createNamespace"); + +(_display displayCtrl IDC_BTN_CONFIGURE_ADDONS) ctrlAddEventHandler ["ButtonClick", COMPILE_FILE(fnc_onButtonClick_configure)]; + +// list of addons +private _ctrlAddonsGroup = _display displayctrl IDC_ADDONS_GROUP; +private _ctrlAddonList = _display ctrlCreate [QGVAR(AddonsList), -1, _ctrlAddonsGroup]; + +_ctrlAddonsGroup ctrlEnable false; +_ctrlAddonsGroup ctrlShow false; + +_ctrlAddonList ctrlAddEventHandler ["LBSelChanged", COMPILE_FILE(fnc_onLBSelChanged_addon)]; + +{ + private _displayName = getText (configFile >> "CBA_Settings" >> _x >> "displayName"); + + if (_displayName isEqualTo "") then { + _displayName = _x; + }; + + private _index = _ctrlAddonList lbAdd _displayName; + _ctrlAddonList lbSetData [_index, str _index]; + _ctrlAddonList setVariable [str _index, _x]; +} forEach _addons; + +lbSort _ctrlAddonList; +_ctrlAddonList lbSetCurSel (uiNamespace getVariable [QGVAR(addonIndex), 0]); + +// OK button +(_display displayCtrl 999) ctrlAddEventHandler ["ButtonClick", COMPILE_FILE(fnc_saveTemporaryData)]; + +// set this per script to avoid it being all upper case +(_display displayCtrl IDC_TXT_FORCE) ctrlSetText localize LSTRING(force); diff --git a/addons/settings/init_settings.sqf b/addons/settings/init_settings.sqf new file mode 100644 index 000000000..bb1210344 --- /dev/null +++ b/addons/settings/init_settings.sqf @@ -0,0 +1,78 @@ + +if (isNil QGVAR(settingsDefault)) then { + // settings can be set in the main menu. have to use ui namespace copies of the functions + GVAR(settingsDefault) = [] call (uiNamespace getVariable "CBA_fnc_createNamespace"); + + { + private _addon = configName _x; + + { + private _setting = configName _x; + private _settingType = getText (_x >> "type"); + private _displayName = getText (_x >> "displayName"); + private _tooltip = getText (_x >> "tooltip"); + + if (_displayName isEqualTo "") then { + _displayName = _setting; + }; + + private ["_defaultValue", "_values", "_valueNames"]; + + if (_settingType == "BOOLEAN") then { + _defaultValue = getNumber (_x >> "defaultValue") == 1; + _values = [_defaultValue, !_defaultValue]; + }; + + if (_settingType == "LIST") then { + _values = getArray (_x >> "values"); + _valueNames = getArray (_x >> "valueNames"); + _valueNames resize count _values; + { + if (isNil "_x") then { _x = _values select _forEachIndex }; + if !(_x isEqualType "") then { _x = str _x }; + _valueNames set [_forEachIndex, _x]; + } forEach _valueNames; + + _defaultValue = _values param [getNumber (_x >> "defaultIndex"), 0]; + }; + + if (_settingType == "SLIDER") then { + _values = [getNumber (_x >> "min"), getNumber (_x >> "max")]; + _defaultValue = getNumber (_x >> "defaultValue"); + }; + + // set new setting to profile + private _clientValue = [_setting, "client"] call (uiNamespace getVariable "CBA_fnc_getSetting"); + + if (isNil "_clientValue" || {!(_clientValue isEqualType _defaultValue)}) then { + [_setting, _defaultValue] call (uiNamespace getVariable "CBA_fnc_setSettingProfile"); + }; + + private _value = _setting call (uiNamespace getVariable "CBA_fnc_getSetting"); + + // set value if not defined in profile or the type changed + if (isNil "_value" || {!(_value isEqualType _defaultValue)}) then { + _value = _defaultValue; + }; + + GVAR(settingsDefault) setVariable [_setting, [_defaultValue, _addon, _settingType, _values, _valueNames, _displayName, _tooltip]]; + + [_setting, _value] call (uiNamespace getVariable "CBA_fnc_setSetting"); + + if (isMultiplayer) then { + if (profileNamespace getVariable [SETTING_KEY_SERVER_FORCE(_setting), false]) then { + [_setting, true] call (uiNamespace getVariable "CBA_fnc_forceSetting"); + }; + }; + } forEach ("true" configClasses _x); + } forEach ("true" configClasses (configFile >> "CBA_Settings")); +}; + +// re-init mission settings when returning to 3den from a preview +("Scenario" get3DENMissionAttribute QGVAR(missionSettings)) params [["_missionSettings", []], ["_missionValues", []]]; + +{ + // values are set only locally, because GVAR(missionSettings) is already a global var + missionNamespace setVariable [SETTING_KEY_MISSION(_x), _missionValues select _forEachIndex]; + missionNamespace setVariable [SETTING_KEY_MISSION_FORCE(_x), true]; +} forEach _missionSettings; diff --git a/addons/settings/license.txt b/addons/settings/license.txt new file mode 100644 index 000000000..434712527 --- /dev/null +++ b/addons/settings/license.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 CBA Project, Ryan Schultz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/addons/settings/script_component.hpp b/addons/settings/script_component.hpp new file mode 100644 index 000000000..c4a4139dd --- /dev/null +++ b/addons/settings/script_component.hpp @@ -0,0 +1,41 @@ +#define COMPONENT settings +#include "\x\cba\addons\main\script_mod.hpp" +#include "\x\cba\addons\main\script_macros.hpp" + +//#define DEBUG_ENABLED_SETTINGS + +#ifdef DEBUG_ENABLED_SETTINGS + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_SETTINGS + #define DEBUG_SETTINGS DEBUG_SETTINGS_SETTINGS +#endif + +#define SETTING_KEY_CLIENT(setting) ([setting, "C"] joinString "$") +#define SETTING_KEY_SERVER(setting) ([setting, "S"] joinString "$") +#define SETTING_KEY_SERVER_FORCE(setting) ([setting, "SF"] joinString "$") +#define SETTING_KEY_MISSION(setting) ([setting, "M"] joinString "$") +#define SETTING_KEY_MISSION_FORCE(setting) ([setting, "MF"] joinString "$") + +#define IDC_ADDONS_GROUP 4301 +#define IDC_BTN_CONFIGURE_ADDONS 4302 +#define IDC_BTN_CLIENT 9000 +#define IDC_BTN_SERVER 9001 +#define IDC_BTN_MISSION 9002 +#define IDC_TXT_FORCE 327 + +#define POS_X(N) (N * (((safezoneW / safezoneH) min 1.2) / 40)) +#define POS_Y(N) (N * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)) + +#define COLOR_TEXT_DISABLED [1,1,1,0.3] +#define COLOR_BUTTON_ENABLED [1,1,1,1] +#define COLOR_BUTTON_DISABLED [0,0,0,1] + +#define CAN_SET_CLIENT_SETTINGS (!isMultiplayer || !isServer) +#define CAN_SET_SERVER_SETTINGS (isMultiplayer && {isServer || serverCommandAvailable "#logout"}) +#define CAN_SET_MISSION_SETTINGS is3den + +#define CAN_VIEW_CLIENT_SETTINGS CAN_SET_CLIENT_SETTINGS +#define CAN_VIEW_SERVER_SETTINGS (CAN_SET_SERVER_SETTINGS || isMultiplayer) +#define CAN_VIEW_MISSION_SETTINGS (missionVersion >= 15) diff --git a/addons/settings/stringtable.xml b/addons/settings/stringtable.xml new file mode 100644 index 000000000..399d205dd --- /dev/null +++ b/addons/settings/stringtable.xml @@ -0,0 +1,45 @@ + + + + Configure Addons + Modifikationen anpassen + Konfiguracja addonów + + + Configure Base + Hauptspiel anpassen + Konfiguracja bazy + + + Client + Lokal + + + Edit your local settings. Greyed out settings are overwritten by the server. + Lokale Einstellungen wählen. Ausgegraute Einstellungen werden vom Server überschrieben. + + + Server + Server + + + 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. + + + Mission + Mission + + + Edit the missions settings. 'Forced' settings overwrite the clients settings. + Missions-Einstellungen wählen. 'Erzwungene' Einstellungen überschreiben lokale. + + + Force? + Erzwingen? + + + Check to overwrite this setting for all connected players. + Wählen, um diese Einstellung für alle verbunden Spieler zu überschreiben. + + diff --git a/addons/settings_test_nametags/$PBOPREFIX$ b/addons/settings_test_nametags/$PBOPREFIX$ new file mode 100644 index 000000000..56d1329fd --- /dev/null +++ b/addons/settings_test_nametags/$PBOPREFIX$ @@ -0,0 +1 @@ +x\cba\addons\settings_test_nametags diff --git a/addons/settings_test_nametags/CBA_Settings.hpp b/addons/settings_test_nametags/CBA_Settings.hpp new file mode 100644 index 000000000..a42ff3759 --- /dev/null +++ b/addons/settings_test_nametags/CBA_Settings.hpp @@ -0,0 +1,30 @@ + +class CBA_Setting_Boolean_base; +class CBA_Setting_List_base; +class CBA_Setting_Slider_base; + +class CBA_Settings { + class A_TEST { + displayName = "A Nametag Test Addon"; + class CBA_Nametag_Enabled: CBA_Setting_Boolean_base { + displayName = "Enable Nametags"; + defaultValue = 1; + }; + class CBA_Nametag_Color: CBA_Setting_List_base { + displayName = "Nametag Color"; + values[] = {{1,1,1,1},{1,0,0,1},{0,1,0,1},{0,0,1,1},{1,1,0,1}}; + valueNames[] = {"white","red","green","blue","yellow"}; + defaultIndex = 1; + }; + class CBA_Nametag_Font: CBA_Setting_List_base { + displayName = "Nametag Font"; + values[] = {"PuristaMedium","TahomaB","RobotoCondensed"}; + }; + class CBA_Nametag_Opacity: CBA_Setting_Slider_base { + displayName = "Nametag Opacity"; + min = 0; + max = 100; + defaultValue = 80; + }; + }; +}; diff --git a/addons/settings_test_nametags/CfgEventHandlers.hpp b/addons/settings_test_nametags/CfgEventHandlers.hpp new file mode 100644 index 000000000..0cd959a04 --- /dev/null +++ b/addons/settings_test_nametags/CfgEventHandlers.hpp @@ -0,0 +1,12 @@ + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; + +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; diff --git a/addons/settings_test_nametags/XEH_postInit.sqf b/addons/settings_test_nametags/XEH_postInit.sqf new file mode 100644 index 000000000..be7f53075 --- /dev/null +++ b/addons/settings_test_nametags/XEH_postInit.sqf @@ -0,0 +1,12 @@ +#include "script_component.hpp" +SCRIPT(XEH_postInit); + +["CBA_SettingChanged", { + params ["_setting", "_value"]; + + if (_setting == "CBA_Nametag_Enabled") then { + FUNC(onDraw) = [{}, FUNC(DrawNametag)] select _value; + }; +}] call CBA_fnc_addEventHandler; + +addMissionEventHandler ["Draw3D", {call FUNC(onDraw)}]; diff --git a/addons/settings_test_nametags/XEH_preInit.sqf b/addons/settings_test_nametags/XEH_preInit.sqf new file mode 100644 index 000000000..f64f1f231 --- /dev/null +++ b/addons/settings_test_nametags/XEH_preInit.sqf @@ -0,0 +1,21 @@ +#include "script_component.hpp" +SCRIPT(XEH_preInit); + +ADDON = false; + +FUNC(DrawNametag) = { + private _target = cursorTarget; + + if (!isNull _target) then { + private _string = name _target; + private _position = position _target vectorAdd [0, 0, 2]; + private _color = CBA_Nametag_Color; + private _alpha = CBA_Nametag_Opacity / 100; + _color set [3, _alpha]; + private _font = CBA_Nametag_Font; + + drawIcon3D ["", _color, _position, 0, 0, 0, _string, 1, 0.05, _font]; + }; +}; + +ADDON = true; diff --git a/addons/settings_test_nametags/config.cpp b/addons/settings_test_nametags/config.cpp new file mode 100644 index 000000000..389c5efbb --- /dev/null +++ b/addons/settings_test_nametags/config.cpp @@ -0,0 +1,17 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"CBA_common"}; + version = VERSION; + author[] = {"commy2"}; + authorUrl = "https://github.com/CBATeam/CBA_A3"; + }; +}; + +#include "CfgEventHandlers.hpp" + +#include "CBA_Settings.hpp" diff --git a/addons/settings_test_nametags/license.txt b/addons/settings_test_nametags/license.txt new file mode 100644 index 000000000..434712527 --- /dev/null +++ b/addons/settings_test_nametags/license.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 CBA Project, Ryan Schultz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/addons/settings_test_nametags/script_component.hpp b/addons/settings_test_nametags/script_component.hpp new file mode 100644 index 000000000..72eb4d8fc --- /dev/null +++ b/addons/settings_test_nametags/script_component.hpp @@ -0,0 +1,13 @@ +#define COMPONENT settings_test_nametags +#include "\x\cba\addons\main\script_mod.hpp" +#include "\x\cba\addons\main\script_macros.hpp" + +//#define DEBUG_ENABLED_SETTINGS + +#ifdef DEBUG_ENABLED_SETTINGS + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_SETTINGS + #define DEBUG_SETTINGS DEBUG_SETTINGS_SETTINGS +#endif