Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve settings #606

Merged
merged 3 commits into from
Apr 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/main/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
};
};
};
Expand Down
2 changes: 1 addition & 1 deletion addons/main/script_mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 :)
Expand Down
17 changes: 14 additions & 3 deletions addons/settings/Cfg3DEN.hpp
Original file line number Diff line number Diff line change
@@ -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";
};
};
Expand All @@ -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]]";
};
};
};
};
Expand Down
7 changes: 5 additions & 2 deletions addons/settings/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)'));
};
};
6 changes: 0 additions & 6 deletions addons/settings/CfgFunctions.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion addons/settings/Display3DEN.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
26 changes: 17 additions & 9 deletions addons/settings/XEH_PREP.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
13 changes: 6 additions & 7 deletions addons/settings/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
38 changes: 20 additions & 18 deletions addons/settings/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
//#define DEBUG_MODE_FULL
#include "script_component.hpp"

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
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
11 changes: 8 additions & 3 deletions addons/settings/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
1 change: 0 additions & 1 deletion addons/settings/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class CfgPatches {
};

#include "CfgEventHandlers.hpp"
#include "CfgFunctions.hpp"

#include "Cfg3DEN.hpp"
#include "Display3DEN.hpp"
Expand Down
17 changes: 10 additions & 7 deletions addons/settings/fnc_check.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Loading