Add public setter function, Optimize some checks

This commit is contained in:
jonpas 2016-03-08 18:12:01 +01:00
parent 9b46e8856e
commit 64fe944b0f
6 changed files with 75 additions and 11 deletions

View File

@ -1,3 +1,4 @@
PREP(moduleInit);
PREP(setAdvancedElement);
PREP(setElements);
PREP(setElementVisibility);

View File

@ -4,4 +4,6 @@ ADDON = false;
#include "XEH_PREP.hpp"
GVAR(elementsSet) = [];
ADDON = true;

View File

@ -18,18 +18,18 @@ params ["_logic", "_units", "_activated"];
if (!_activated) exitWith {};
// Exit if HUD visibility is hardcoded in mission config and showHUD command is overriden
if (isArray (missionConfigFile >> "showHUD")) exitWith {
ACE_LOGINFO("User Interface Module Failed to Initialize - showHUD overriden in mission config!");
};
// Basic
[_logic, QGVAR(allowSelectiveUI), "allowSelectiveUI"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(soldierVehicleWeaponInfo), "soldierVehicleWeaponInfo"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(vehicleRadar), "vehicleRadar"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(vehicleCompass), "vehicleCompass"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(commandMenu), "commandMenu"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(groupBar), "groupBar"] call EFUNC(common,readSettingFromModule);
if (isArray (missionConfigFile >> "showHUD")) then {
// HUD visibility is hardcoded in mission config and showHUD command is overriden
ACE_LOGINFO("User Interface Module Failed to Initialize Basic settings - showHUD overriden in mission config!");
} else {
[_logic, QGVAR(allowSelectiveUI), "allowSelectiveUI"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(soldierVehicleWeaponInfo), "soldierVehicleWeaponInfo"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(vehicleRadar), "vehicleRadar"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(vehicleCompass), "vehicleCompass"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(commandMenu), "commandMenu"] call EFUNC(common,readSettingFromModule);
[_logic, QGVAR(groupBar), "groupBar"] call EFUNC(common,readSettingFromModule);
};
// Advanced
[_logic, QGVAR(weaponName), "weaponName"] call EFUNC(common,readSettingFromModule);

View File

@ -21,6 +21,8 @@
params ["_elementInfo", ["_force", false, [true]] ];
if (_elementInfo in GVAR(elementsSet)) exitWith {};
if (!_force && {!GVAR(allowSelectiveUI)}) exitWith {
[LSTRING(Disallowed), 2] call EFUNC(common,displayTextStructured)
};
@ -34,6 +36,7 @@ if (typeName _show == "STRING") then {
_show = [1, 0] select _show;
// Disable/Enable elements
private _success = false;
{
private _idc = _x;
@ -44,6 +47,10 @@ _show = [1, 0] select _show;
(_x displayCtrl _idc) ctrlSetFade _show;
(_x displayCtrl _idc) ctrlCommit 0;
_success = true;
};
} forEach (uiNamespace getVariable "IGUI_displays");
} forEach _elements;
_success

View File

@ -0,0 +1,52 @@
/*
* Author: Jonpas
* Wrapper for setting advanced element visibility.
*
* Arguments:
* 0: Set/Unset <BOOL> (default: true)
* 1: Element info <ARRAY>
* 0: Show/Hide Element OR Element Variable <BOOL/STRING>
* 1: Element IDD <NUMBER>
* 2: Element IDCs <ARRAY>
*
* Return Value:
* None
*
* Example:
* [false] call ace_ui_fnc_setElementVisibility
*
* Public: Yes
*/
#include "script_component.hpp"
params [
["_set", true, [true]],
["_elementInfo", [true, 0, []], [[]], 3]
];
_elementInfo params [
["_show", false, [true, ""]],
["_idd", 0, [0]],
["_elements", [], [[]]]
];
if (_set) then {
if ([_idd, _elements] in GVAR(elementsSet)) exitWith { TRACE_2("Element already set",_elementInfo,GVAR(elementsSet)); };
TRACE_2("Setting element",_elementInfo,GVAR(elementsSet));
private _success = [_elementInfo] call FUNC(setAdvancedElement);
if (_success) then {
GVAR(elementsSet) pushBack [_idd, _elements];
};
} else {
if ([_idd, _elements] in GVAR(elementsSet)) then {
TRACE_2("Unsetting element",_elementInfo,GVAR(elementsSet));
TRACE_2("Toggling element",_elementInfo,GVAR(elementsSet));
[_elementInfo] call FUNC(setAdvancedElement);
private _index = GVAR(elementsSet) find [_idd, _elements];
GVAR(elementsSet) deleteAt _index;
};
};

View File

@ -15,6 +15,8 @@
*/
#include "script_component.hpp"
if (isArray (missionConfigFile >> "showHUD")) exitWith {};
params [ ["_force", false, [true]] ];
if (!_force && {!GVAR(allowSelectiveUI)}) exitWith {