Skip to content

Commit

Permalink
Improve selective UI API, Disable ammo count when reload component is…
Browse files Browse the repository at this point in the history
… loaded, Fix stance UI
  • Loading branch information
jonpas committed May 21, 2016
1 parent f67b356 commit 5a2f1c0
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 31 deletions.
4 changes: 4 additions & 0 deletions addons/common/RscInfoType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@ class RscInGameUI {
class RscStaminaBar {
onLoad = QUOTE([ARR_4(""onLoad"",_this,""RscStaminaBar"",'IGUI')] call (uinamespace getvariable 'BIS_fnc_initDisplay'); uiNamespace setVariable [ARR_2(QUOTE(QGVAR(dlgStaminaBar)),_this select 0)]);
};

class RscStanceInfo {
onLoad = QUOTE([ARR_4(""onLoad"",_this,""RscStanceInfo"",'IGUI')] call (uinamespace getvariable 'BIS_fnc_initDisplay'); [ARR_2('infoDisplayChanged', [ARR_2(_this select 0, 'Stance')])] call FUNC(localEvent););
};
};
5 changes: 5 additions & 0 deletions addons/reload/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ if (!hasInterface) exitWith {};

_receiver addMagazine _magazine;
}] call EFUNC(common,addEventhandler);

// Hide ammo UI indicator
["InterfaceInitialized", {
[true, QEGVAR(ui,ammoCount), false] call EFUNC(ui,setElementVisibility);
}] call EFUNC(common,addEventhandler);
2 changes: 1 addition & 1 deletion addons/reload/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class CfgPatches {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_interaction"};
requiredAddons[] = {"ace_interaction", "ace_ui"};
author[] = {"commy2","KoffeinFlummi","esteldunedain"};
authorUrl = "https://github.com/commy2/";
VERSION_CONFIG;
Expand Down
2 changes: 1 addition & 1 deletion addons/reload/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
#define DEBUG_SETTINGS DEBUG_ENABLED_RELOAD
#endif

#include "\z\ace\addons\main\script_macros.hpp"
#include "\z\ace\addons\main\script_macros.hpp"
4 changes: 2 additions & 2 deletions addons/ui/ACE_Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ACE_Settings {
displayName = CSTRING(AmmoCount);
description = CSTRING(RequiresSoldierVehicleWeaponInfo);
typeName = "BOOL";
value = 0;
value = 1;
isClientSettable = 1;
};
class GVAR(magCount) {
Expand Down Expand Up @@ -122,7 +122,7 @@ class ACE_Settings {
};
class GVAR(weaponLowerInfoBackground) {
category = CSTRING(Category);
displayName = CSTRING(WeaponLowerInfoBackground); //todo
displayName = CSTRING(WeaponLowerInfoBackground);
description = CSTRING(RequiresSoldierVehicleWeaponInfo);
typeName = "BOOL";
value = 1;
Expand Down
2 changes: 1 addition & 1 deletion addons/ui/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CfgVehicles {
displayName = CSTRING(AmmoCount);
description = CSTRING(RequiresSoldierVehicleWeaponInfo);
typeName = "BOOL";
defaultValue = 0;
defaultValue = 1;
};
class magCount {
displayName = CSTRING(MagCount);
Expand Down
19 changes: 17 additions & 2 deletions addons/ui/XEH_clientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ 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));
{
[_x select 0, _x select 1, _x select 2, _force] call FUNC(setAdvancedElement);
[_x select 0, _x select 1, missionNamespace getVariable (_x select 2), _force] call FUNC(setAdvancedElement);
} forEach ELEMENTS_ADVANCED;

// 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
if (!GVAR(interfaceInitialized)) then {
["InterfaceInitialized", []] call EFUNC(common,localEvent);
GVAR(interfaceInitialized) = true;
};
}] call EFUNC(common,addEventHandler);

// On changing settings
Expand All @@ -30,8 +37,16 @@ if (!hasInterface) exitWith {};
{
_x params ["_idd", "_elements", "_elementName"];

// Get show/hide boolean from mission namespace
private _show = missionNamespace getVariable _elementName;

// Get show/hide boolean from a set element if set via API
if ([_idd, _elements, !(missionNamespace getVariable _elementName)] in GVAR(elementsSet)) then {
[LSTRING(Disabled), 2] call EFUNC(common,displayTextStructured);
};

if (_name == _elementName) then {
[_idd, _elements, _elementName] call FUNC(setAdvancedElement);
[_idd, _elements, _show] call FUNC(setAdvancedElement);
TRACE_2("Setting Changed",_name,_elementName);
};
} forEach ELEMENTS_ADVANCED;
Expand Down
1 change: 1 addition & 0 deletions addons/ui/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ ADDON = false;
#include "XEH_PREP.hpp"

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

ADDON = true;
14 changes: 7 additions & 7 deletions addons/ui/functions/fnc_setAdvancedElement.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Arguments:
* 0: Element IDD <NUMBER>
* 1: Element IDCs <ARRAY>
* 2: Show/Hide Element OR Element ACE Settings Variable <BOOL/STRING>
* 2: Show/Hide Element <BOOL>
* 3: Force change even when disallowed <BOOL> (default: false)
*
* Return Value:
Expand All @@ -20,16 +20,16 @@

params ["_idd", "_elements", "_show", ["_force", false, [true]] ];

if (_elementInfo in GVAR(elementsSet)) exitWith {};

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

// Get show/hide boolean from mission namespace if it's a string
if (typeName _show == "STRING") then {
_show = missionNamespace getVariable _show;
// Get show/hide boolean from a set element if set via API
// Inversion only needed if inverted, otherwise parameter can be used directly as it is the same
if ([_idd, _elements, !_show] in GVAR(elementsSet)) then {
_show = !_show;
};

_show = [1, 0] select _show;

// Disable/Enable elements
Expand Down
47 changes: 36 additions & 11 deletions addons/ui/functions/fnc_setElementVisibility.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,71 @@
*
* Arguments:
* 0: Set/Unset <BOOL> (default: true)
* 1: Element IDD <NUMBER> (default: 0)
* 2: Element IDCs <ARRAY> (default: [])
* 3: Show/Hide Element OR Element ACE Settings Variable <BOOL/STRING> (default: false)
* 1: Element Info OR Element Name <ARRAY/STRING> (default: "")
* 0: Element Info IDD <NUMBER> (default: 0)
* 1: Element Info IDCs <ARRAY> (default: [])
* 2: Show/Hide Element <BOOL> (default: false)
*
* Return Value:
* None
*
* Example:
* [true, 300, [188], false] call ace_ui_fnc_setElementVisibility
* [true, "ace_ui_ammoCount", false] call ace_ui_fnc_setElementVisibility
*
* Public: Yes
*/
#include "script_component.hpp"

params [
["_set", true, [true]],
["_idd", 0, [0]],
["_elements", [], [[]]],
["_show", false, [true, ""]]
["_element", "", ["", []]],
["_show", false, [true]]
];

// Get IDD and Elements from setting name
private _idd = 0;
private _elements = [];
if (_element isEqualType "") then {
private _elementInfo = ELEMENTS_ADVANCED select {_x select 2 == _element};
if (_elementInfo isEqualTo []) exitWith {
ACE_LOGWARNING_1("Element setting name does not exist (Element: %1)",_element);
};
_idd = (_elementInfo select 0) select 0;
_elements = (_elementInfo select 0) select 1;
} else {
_idd = _element select 0;
_elements = _element select 1;
};

private _return = false;

if (_set) then {
if ([_idd, _elements] in GVAR(elementsSet)) exitWith { TRACE_3("Element already set",_idd,_elements,GVAR(elementsSet)); };
// Exit if element has been set from another component, print warning if after interface initialization
if ([_idd, _elements] in GVAR(elementsSet)) exitWith {
if (GVAR(interfaceInitialized)) then {
ACE_LOGWARNING_3("Element already set (IDD: %1, Elements: %2, Elements Set: %3",_idd,_elements,GVAR(elementsSet));
};
};

TRACE_4("Setting element",_idd,_elements,_show,GVAR(elementsSet));
private _success = [_idd, _elements, _show] call FUNC(setAdvancedElement);

if (_success) then {
GVAR(elementsSet) pushBack [_idd, _elements];
GVAR(elementsSet) pushBack [_idd, _elements, _show];
_return = true;
};
} else {
if ([_idd, _elements] in GVAR(elementsSet)) then {
if ([_idd, _elements, _show] in GVAR(elementsSet) || {[_idd, _elements, !_show] in GVAR(elementsSet)}) then {
TRACE_4("Setting element",_idd,_elements,_show,GVAR(elementsSet));
[_idd, _elements, _show] call FUNC(setAdvancedElement);

private _index = GVAR(elementsSet) find [_idd, _elements];
private _index = GVAR(elementsSet) find [_idd, _elements, _show];
if (_index == -1) then {
_index = GVAR(elementsSet) find [_idd, _elements, !_show];
};
GVAR(elementsSet) deleteAt _index;

[_idd, _elements, _show] call FUNC(setAdvancedElement);
_return = true;
};
};
Expand Down
4 changes: 0 additions & 4 deletions addons/ui/functions/fnc_setElements.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ if (isArray (missionConfigFile >> "showHUD")) exitWith {};

params [ ["_force", false, [true]] ];

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

["ui", [
true,
GVAR(soldierVehicleWeaponInfo),
Expand Down
2 changes: 1 addition & 1 deletion addons/ui/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ RscUnitInfo = 300
+ 1203 (Firing Mode Background)
155 (Ammo Type)
184 (Ammo Count) - disabled in config by ace_reload
184 (Ammo Count) - disabled by default if ace_reload is loaded
185 (Magazine Count)
152 (Grenade/Flare Type)
151 (Grenade/Flare Count)
Expand Down
5 changes: 4 additions & 1 deletion addons/ui/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,8 @@
<English>Modifying User Interface is disabled.</English>
<Czech>Změna uživatelského rozhraní je zakázána.</Czech>
</Key>
<Key ID="STR_ACE_UI_Disabled">
<English>Cannot modify a forced User Interface element.</English>
</Key>
</Package>
</Project>
</Project>

0 comments on commit 5a2f1c0

Please sign in to comment.