Skip to content

Commit

Permalink
add CBA settings
Browse files Browse the repository at this point in the history
  • Loading branch information
commy2 committed Apr 28, 2016
1 parent 099cfc3 commit 318fbbf
Show file tree
Hide file tree
Showing 35 changed files with 1,321 additions and 12 deletions.
11 changes: 6 additions & 5 deletions addons/events/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 9 additions & 5 deletions addons/keybinding/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -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));
};
};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "script_component.hpp"
SCRIPT(XEH_preInit);

if (!hasInterface) exitWith {};

ADDON = false;

// Load DIK to string conversion table.
Expand Down
2 changes: 0 additions & 2 deletions addons/keybinding/gui/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions addons/settings/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x\cba\addons\settings
29 changes: 29 additions & 0 deletions addons/settings/CBA_Settings.hpp
Original file line number Diff line number Diff line change
@@ -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 {};
};
25 changes: 25 additions & 0 deletions addons/settings/Cfg3DEN.hpp
Original file line number Diff line number Diff line change
@@ -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]]";
};
};
};
};
};
};
};
18 changes: 18 additions & 0 deletions addons/settings/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -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));
};
};
15 changes: 15 additions & 0 deletions addons/settings/CfgFunctions.hpp
Original file line number Diff line number Diff line change
@@ -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);
};
};
};
24 changes: 24 additions & 0 deletions addons/settings/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 30 additions & 0 deletions addons/settings/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -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;
21 changes: 21 additions & 0 deletions addons/settings/config.cpp
Original file line number Diff line number Diff line change
@@ -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"
34 changes: 34 additions & 0 deletions addons/settings/fnc_forceSetting.sqf
Original file line number Diff line number Diff line change
@@ -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 <STRING>
_force - true: force, false: release <BOOLEAN>
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
57 changes: 57 additions & 0 deletions addons/settings/fnc_getSetting.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* ----------------------------------------------------------------------------
Function: CBA_fnc_getSetting
Description:
Returns a setting.
Parameters:
_setting - Name of the setting <STRING>
_source - Can be "current", "server", "mission", "client" or "default" (optional, default: "current") <STRING>
Returns:
Value of the setting <ANY>
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 }
Loading

0 comments on commit 318fbbf

Please sign in to comment.