From 958b2e6d7b5204c9e2c1d028092561a39fe2e48f Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 7 Apr 2019 09:00:56 +0200 Subject: [PATCH] add CBA_fnc_addSettings (#1111) --- addons/settings/CfgFunctions.hpp | 7 +++++ addons/settings/config.cpp | 1 + addons/settings/fnc_addSetting.sqf | 48 ++++++++++++++++++++++++++++++ addons/settings/fnc_init.sqf | 2 +- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 addons/settings/CfgFunctions.hpp create mode 100644 addons/settings/fnc_addSetting.sqf diff --git a/addons/settings/CfgFunctions.hpp b/addons/settings/CfgFunctions.hpp new file mode 100644 index 000000000..5bab9f6b1 --- /dev/null +++ b/addons/settings/CfgFunctions.hpp @@ -0,0 +1,7 @@ +class CfgFunctions { + class CBA { + class Settings { + PATHTO_FNC(addSetting); + }; + }; +}; diff --git a/addons/settings/config.cpp b/addons/settings/config.cpp index f696bf332..7d7f92c1a 100644 --- a/addons/settings/config.cpp +++ b/addons/settings/config.cpp @@ -15,6 +15,7 @@ class CfgPatches { }; #include "CfgEventHandlers.hpp" +#include "CfgFunctions.hpp" #include "Cfg3DEN.hpp" #include "Display3DEN.hpp" #include "gui.hpp" diff --git a/addons/settings/fnc_addSetting.sqf b/addons/settings/fnc_addSetting.sqf new file mode 100644 index 000000000..f252dddcf --- /dev/null +++ b/addons/settings/fnc_addSetting.sqf @@ -0,0 +1,48 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_addSetting + +Description: + Creates a new setting for that session. + +Parameters: + _setting - Unique setting name. Matches resulting variable name + _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 + optional sub-category + _valueInfo - Extra properties of the setting depending of _settingType. See examples below + _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) + _needRestart - Setting will be marked as needing mission restart after being changed. (optional, default false) + +Returns: + _return - Error code + true: Success, no error + false: Failure, error + +Examples: + (begin example) + // CHECKBOX --- extra argument: default value + ["Test_Setting_1", "CHECKBOX", ["-test checkbox-", "-tooltip-"], "My Category", true] call CBA_fnc_addSetting; + + // LIST --- extra arguments: [_values, _valueTitles, _defaultIndex] + ["Test_Setting_2", "LIST", ["-test list-", "-tooltip-"], "My Category", [[1, 0], ["enabled","disabled"], 1]] call CBA_fnc_addSetting; + + // SLIDER --- extra arguments: [_min, _max, _default, _trailingDecimals] + ["Test_Setting_3", "SLIDER", ["-test slider-", "-tooltip-"], "My Category", [0, 10, 5, 0]] call CBA_fnc_addSetting; + + // COLOR PICKER --- extra argument: _color + ["Test_Setting_4", "COLOR", ["-test color-", "-tooltip-"], "My Category", [1, 1, 0]] call CBA_fnc_addSetting; + + // EDITBOX --- extra argument: default value + ["Test_Setting_5", "EDITBOX", ["-test editbox-", "-tooltip-"], "My Category", "defaultValue"] call CBA_fnc_addSetting; + + // TIME PICKER (time in seconds) --- extra arguments: [_min, _max, _default] + ["Test_Setting_6", "TIME", ["-test time-", "-tooltip-"], "My Category", [0, 3600, 60]] call CBA_fnc_addSetting; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ + +call (uiNamespace getVariable QFUNC(init)) == 0 diff --git a/addons/settings/fnc_init.sqf b/addons/settings/fnc_init.sqf index 7ca31a075..9946b6895 100644 --- a/addons/settings/fnc_init.sqf +++ b/addons/settings/fnc_init.sqf @@ -1,6 +1,6 @@ #include "script_component.hpp" /* ---------------------------------------------------------------------------- -Function: CBA_settings_fnc_init +Internal Function: CBA_settings_fnc_init Description: Creates a new setting for that session.