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

Cache config UI #4234

Merged
merged 6 commits into from
Aug 18, 2016
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
4 changes: 0 additions & 4 deletions addons/ui/ACE_UI.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#define ANYWHERE 0
#define GROUND_ONLY 1
#define VEHICLE_ONLY 2

class ACE_UI {
class weaponName {
idd = 300;
Expand Down
2 changes: 1 addition & 1 deletion addons/ui/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PREP(findSetElement);
PREP(compileConfigUI);
PREP(moduleInit);
PREP(setAdvancedElement);
PREP(setElements);
Expand Down
20 changes: 14 additions & 6 deletions addons/ui/XEH_clientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
// Exit on Headless
if (!hasInterface) exitWith {};

// Compile and cache config UI
GVAR(configCache) = call CBA_fnc_createNamespace;
call FUNC(compileConfigUI);

// Scripted API namespace
GVAR(elementsSet) = call CBA_fnc_createNamespace;

// Attach all event handlers where UI has to be updated
["ace_settingsInitialized", {
// Initial settings
[false] call FUNC(setElements);
Expand All @@ -13,9 +21,8 @@ if (!hasInterface) exitWith {};
// Defaults must be set in this EH to make sure controls are activated and advanced settings can be modified
private _force = [true, false] select (GVAR(allowSelectiveUI));
{
private _name = configName _x;
[_name, missionNamespace getVariable (format [QGVAR(%1), _name]), false, _force] call FUNC(setAdvancedElement);
} forEach ("true" configClasses (configFile >> "ACE_UI"));
[_x, missionNamespace getVariable (format [QGVAR(%1), _x]), false, _force] call FUNC(setAdvancedElement);
} forEach (allVariables GVAR(configCache));

// Execute local event for when it's safe to modify UI through this API
// infoDisplayChanged can execute multiple times, make sure it only happens once
Expand All @@ -32,10 +39,11 @@ if (!hasInterface) exitWith {};
if (_name in ELEMENTS_BASIC) then {
[true] call FUNC(setElements);
} else {
if (isClass (configFile >> "ACE_UI" >> _name select [7])) then {
[_name select [7], missionNamespace getVariable _name, true] call FUNC(setAdvancedElement);
private _nameNoPrefix = toLower (_name select [7]);
private _cachedElement = GVAR(configCache) getVariable _nameNoPrefix;
if (!isNil "_cachedElement") then {
[_nameNoPrefix, missionNamespace getVariable _name, true] call FUNC(setAdvancedElement);
};
};
}] call CBA_fnc_addEventHandler;

}] call CBA_fnc_addEventHandler;
1 change: 0 additions & 1 deletion addons/ui/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ ADDON = false;

#include "XEH_PREP.hpp"

GVAR(elementsSet) = [];
GVAR(interfaceInitialized) = false;

ADDON = true;
45 changes: 45 additions & 0 deletions addons/ui/functions/fnc_compileConfigUI.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Author: Jonpas
* Compiles and caches UI from ACE_UI config.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_ui_fnc_compileConfigUI
*
* Public: No
*/
#include "script_component.hpp"

{
private _failure = false;
private _class = toLower (configName _x);

private _idd = getNumber (_x >> "idd");

private _elements = getArray (_x >> "elements");
if (_elements isEqualTo []) then {
ACE_LOGERROR_1("Failed compiling ACE_UI for Element: %1 - missing elements",_class);
_failure = true;
};

private _location = getNumber (_x >> "location");
if !(_location in [ANYWHERE, GROUND_ONLY, VEHICLE_ONLY]) then {
ACE_LOGERROR_2("Failed compiling ACE_UI for Element: %1 - missing or invalid location %2",_class,_location);
_failure = true;
};

if (!_failure) then {
private _conditions = [];
{
_conditions pushBack [compile (getText _x), configName _x];
TRACE_1("Caching Condition",_x);
} forEach (configProperties [_x >> "conditions"]);

GVAR(configCache) setVariable [_class, [_idd, _elements, _location, _conditions]];
};
} forEach ("true" configClasses (configFile >> "ACE_UI"));
25 changes: 0 additions & 25 deletions addons/ui/functions/fnc_findSetElement.sqf

This file was deleted.

34 changes: 16 additions & 18 deletions addons/ui/functions/fnc_setAdvancedElement.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,48 @@
* Successfully Set <BOOL>
*
* Example:
* ["ace_ui_ammoCount", true, false] call ace_ui_fnc_setAdvancedElement
* _successfullySet = ["ammoCount", true, false] call ace_ui_fnc_setAdvancedElement
*
* Public: No
*/
#include "script_component.hpp"

params ["_element", "_show", ["_showHint", false, [true]], ["_force", false, [true]] ];

private _cachedElement = GVAR(configCache) getVariable _element;
if (isNil "_cachedElement") exitWith {};

if (!_force && {!GVAR(allowSelectiveUI)}) exitWith {
[LSTRING(Disallowed), 2] call EFUNC(common,displayTextStructured);
false
};

private _config = configFile >> "ACE_UI" >> _element;
_cachedElement params ["_idd", "_elements", "_location", "_conditions"];

// Exit if main vehicle type condition not fitting
private _location = getNumber (_config >> "location"); // (0-both, 1-ground, 2-vehicle)
private _canUseWeapon = ACE_player call CBA_fnc_canUseWeapon;
if ((_canUseWeapon && _location == 2) || (!_canUseWeapon && _location == 1)) exitWith {false};

private _idd = getNumber (_config >> "idd");
private _elements = getArray (_config >> "elements");
if ((_canUseWeapon && {_location == 2}) || {!_canUseWeapon && {_location == 1}}) exitWith {false};

// Get setting from config API
{
private _condition = call compile (getText _x);
if !(_condition) exitWith {
if (!call (_x select 0)) exitWith {
// Display and print info which component forced the element except for default vehicle check
if (_showHint) then {
[LSTRING(Disabled), 2] call EFUNC(common,displayTextStructured);
ACE_LOGINFO_2("Attempted modification of a forced User Interface element '%1' by '%2'",_element,configName _x);
ACE_LOGINFO_2("Attempted modification of a forced User Interface element '%1' by '%2'.",_element,_x select 1);
};
_show = false;
};
} forEach (configProperties [_config >> "conditions"]);
} count _conditions;

// Get setting from scripted API
if (!_force) then {
private _setElement = [_element] call FUNC(findSetElement);
_setElement params ["_indexSet", "_sourceSet", "_showSet"];

if (_indexSet != -1) then {
private _setElement = GVAR(elementsSet) getVariable _element;
if (!isNil "_setElement") then {
_setElement params ["_sourceSet", "_showSet"];
if (_showHint) then {
[LSTRING(Disabled), 2] call EFUNC(common,displayTextStructured);
ACE_LOGINFO_2("Attempted modification of a forced User Interface element '%1' by '%2'",_element,_sourceSet);
ACE_LOGINFO_2("Attempted modification of a forced User Interface element '%1' by '%2'.",_element,_sourceSet);
};
_show = _showSet;
};
Expand All @@ -79,7 +76,8 @@ private _success = false;

_success = true;
};
} forEach (uiNamespace getVariable "IGUI_displays");
} forEach _elements;
} count (uiNamespace getVariable "IGUI_displays");
nil
} count _elements;

_success
45 changes: 22 additions & 23 deletions addons/ui/functions/fnc_setElementVisibility.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* 3: Show/Hide Element <BOOL> (default: false)
*
* Return Value:
* None
* Successfully Modified <BOOL>
*
* Example:
* ["ace_reload", true, "ace_ui_ammoCount", false] call ace_ui_fnc_setElementVisibility
* _successfullyModified = ["ace_reload", true, "ammoCount", false] call ace_ui_fnc_setElementVisibility
*
* Public: Yes
*/
Expand All @@ -25,45 +25,44 @@ params [
["_show", false, [true]]
];

// Verify element is bound
if (!isClass (configFile >> "ACE_UI" >> _element)) exitWith {
ACE_LOGWARNING_1("Element '%1' does not exist",_element);
};

if (_source == "" || {_element == ""}) exitWith {
ACE_LOGWARNING("Source or Element may not be empty strings!");
};

private _return = false;
_element = toLower _element;

private _setElement = [_element] call FUNC(findSetElement);
_setElement params ["_indexSet", "_sourceSet"];
// Verify element is bound
private _cachedElement = GVAR(configCache) getVariable _element;
if (isNil "_cachedElement") exitWith {
ACE_LOGWARNING_2("Element '%1' does not exist - modification by '%2' failed.",_element,_source);
};

if (_set) then {
// Exit if element has been set from another component, print warning if after interface initialization
if (_indexSet != -1) exitWith {
if (GVAR(interfaceInitialized)) then {
ACE_LOGWARNING_2("Element '%1' already set by %2",_element,_sourceSet);
};
};
private _setElement = GVAR(elementsSet) getVariable _element;
private _return = false;

TRACE_4("Setting element",_source,_element,_show,GVAR(elementsSet));
if (isNil "_setElement") then {
TRACE_3("Setting element",_source,_element,_show);
private _success = [_element, _show, false, true] call FUNC(setAdvancedElement);

if (_success) then {
GVAR(elementsSet) pushBack [_source, _element, _show];
GVAR(elementsSet) setVariable [_element, [_source, _show]];
_return = true;
};
} else {
if (_indexSet != -1) then {
TRACE_4("Unsetting element",_sourceSet,_element,_show,GVAR(elementsSet));
_setElement params ["_sourceSet"];

GVAR(elementsSet) deleteAt _indexSet;
if (_set) then {
if (GVAR(interfaceInitialized)) then {
ACE_LOGWARNING_3("Element '%1' already set by '%2' - modification by '%3' failed.",_element,_sourceSet,_source);
};
} else {
TRACE_3("Unsetting element",_sourceSet,_element,_show);
GVAR(elementsSet) setVariable [_element, nil];

[_element, _show, false, true] call FUNC(setAdvancedElement);
_return = true;
};
};

TRACE_2("Visibility set",_return,GVAR(elementsSet));
TRACE_2("Visibility set",_element,_return);
_return
5 changes: 5 additions & 0 deletions addons/ui/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
// Basic Elements
#define ELEMENTS_BASIC [QGVAR(soldierVehicleWeaponInfo), QGVAR(vehicleRadar), QGVAR(vehicleCompass), QGVAR(commandMenu), QGVAR(groupBar)]

// Locations
#define ANYWHERE 0
#define GROUND_ONLY 1
#define VEHICLE_ONLY 2

/*
RscUnitInfo = 300
--------------------
Expand Down