ACE3/addons/ui/functions/fnc_setAdvancedElement.sqf

95 lines
3.0 KiB
Plaintext
Raw Normal View History

#include "..\script_component.hpp"
2015-10-28 22:23:02 +00:00
/*
* Author: Jonpas
* Sets advanced visible element of the UI using displays and controls.
*
* Arguments:
* 0: Element Name <STRING>
* 1: Show/Hide Element <BOOL>
* 2: Show Hint <BOOL> (default: false)
* 3: Force change even when disallowed <BOOL> (default: false)
2015-10-28 22:23:02 +00:00
*
* Return Value:
* Successfully Set <BOOL>
2015-10-28 22:23:02 +00:00
*
* Example:
* _successfullySet = ["ammoCount", true, false] call ace_ui_fnc_setAdvancedElement
2015-10-28 22:23:02 +00:00
*
* Public: No
*/
params ["_element", "_show", ["_showHint", false, [true]], ["_force", false, [true]]];
_element = toLowerANSI _element;
private _cachedElement = GVAR(configCache) get _element;
if (isNil "_cachedElement") exitWith {TRACE_1("nil element",_this)};
if (!_force && {!GVAR(allowSelectiveUI)}) exitWith {
TRACE_1("not allowed",_this);
[LSTRING(Disallowed), 2] call EFUNC(common,displayTextStructured);
false
};
_cachedElement params ["_idd", "_elements", "_location", "_conditions"];
// Exit if main vehicle type condition not fitting
private _canUseWeaponOrInCargo = ACE_player call CBA_fnc_canUseWeapon || {-1 < vehicle ACE_player getCargoIndex ACE_player};
private _inUAVCamera = !isNull getConnectedUAVUnit player; // explictly using player
if (
(_canUseWeaponOrInCargo && {!_inUAVCamera} && {_location == VEHICLE_ONLY})
|| {(!_canUseWeaponOrInCargo || {_inUAVCamera}) && {_location == GROUND_ONLY}}
) exitWith {
TRACE_3("skip location",_this,_canUseWeaponOrInCargo,_location);
false
};
// Get setting from config API
{
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);
INFO_2("Attempted modification of a forced User Interface element '%1' by '%2'.",_element,_x select 1);
};
_show = false;
};
} forEach _conditions;
// Get setting from scripted API
if (!_force) then {
private _setElement = GVAR(elementsSet) get _element;
if (!isNil "_setElement") then {
_setElement params ["_sourceSet", "_showSet"];
if (_showHint) then {
[LSTRING(Disabled), 2] call EFUNC(common,displayTextStructured);
INFO_2("Attempted modification of a forced User Interface element '%1' by '%2'.",_element,_sourceSet);
};
_show = _showSet;
};
2015-10-28 22:23:02 +00:00
};
private _displays = ((uiNamespace getVariable "IGUI_displays") + [findDisplay IDD_MISSION]) select {_idd == ctrlIDD _x};
private _fade = parseNumber !_show;
2015-10-28 22:23:02 +00:00
// Disable/Enable elements
private _success = false;
2015-10-28 22:23:02 +00:00
{
2016-03-06 11:50:16 +00:00
private _idc = _x;
2015-10-28 22:23:02 +00:00
// Loop through IGUI displays as they can be present several times for some reason
{
_success = true;
2015-10-28 22:23:02 +00:00
private _control = _x displayCtrl _idc;
if (ctrlFade _control == _fade) then {continue};
TRACE_4("Setting Element Visibility",_element,_fade,_idd,_idc);
_control ctrlSetFade _fade;
_control ctrlCommit 0;
} forEach _displays;
} forEach _elements;
_success