Skip to content

Commit

Permalink
Spectator - Hide all UI elements when toggling UI (#10465)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnb432 authored and LinkIsGrim committed Nov 2, 2024
1 parent 6b361cd commit 8994b6b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 10 deletions.
83 changes: 74 additions & 9 deletions addons/spectator/functions/fnc_ui_toggleUI.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "..\script_component.hpp"
/*
* Author: Nelson Duarte, AACO, kymckay
* Function used to toggle the whole user interface
* Function used to toggle the whole user interface.
* When toggled on it restores the UI to the state it was in when it was toggled off.
*
* Arguments:
* None
Expand All @@ -15,19 +16,83 @@
* Public: No
*/

private _visible = !GVAR(uiVisible);
private _visible = GVAR(uiVisible);

{
private _fade = 1;
if (_visible) then {
_fade = getNumber (configFile >> QGVAR(display) >> "Controls" >> ctrlClassName _x >> "fade");
private _fade = if (_visible) then {
1
} else {
getNumber (configFile >> QGVAR(display) >> "Controls" >> ctrlClassName _x >> "fade")
};

_x ctrlSetFade _fade;
_x ctrlCommit 0.25;
} forEach [CTRL_LIST, CTRL_TABS, CTRL_CAM_TYPES, CTRL_WIDGET];
} forEach [CTRL_LIST, CTRL_TABS, CTRL_CAM_TYPES, CTRL_WIDGET, CTRL_COMPASS];

showChat !_visible;
playSound (["HintExpand","HintCollapse"] select _visible);
if (_visible) then {
// If UI is to be toggled off, save what is currently visible
GVAR(toggleUiOpenDisplays) = [GVAR(uiHelpVisible), GVAR(uiMapVisible), GVAR(drawUnits), GVAR(drawProjectiles)];

GVAR(uiVisible) = _visible;
// Turn help off
if (GVAR(uiHelpVisible)) then {
{
_x ctrlSetFade 1;
_x ctrlCommit 0.25;
} forEach [CTRL_HELP_BACK, CTRL_HELP];

GVAR(uiHelpVisible) = !GVAR(uiHelpVisible);
};

// Turn off map
if (GVAR(uiMapVisible)) then {
[] call FUNC(ui_toggleMap);
};

// Turn unit markers off
if (GVAR(drawUnits)) then {
GVAR(drawUnits) = !GVAR(drawUnits);
};

// Turn projectile markers off
if (GVAR(drawProjectiles)) then {
GVAR(drawProjectiles) = !GVAR(drawProjectiles);
};
} else {
// If UI is to be toggled on
(missionNamespace getVariable [QGVAR(toggleUiOpenDisplays), []]) params [
["_helpWasVisible", false],
["_mapWasVisible", false],
["_unitsWereVisible", false],
["_projectilesWereVisible", false]
];

// Turn help on if previously enabled and help is now disabled
if (_helpWasVisible && !GVAR(uiHelpVisible)) then {
{
_x ctrlSetFade (getNumber (configFile >> QGVAR(display) >> "Controls" >> ctrlClassName _x >> "fade"));
_x ctrlCommit 0.25;
} forEach [CTRL_HELP_BACK, CTRL_HELP];

GVAR(uiHelpVisible) = !GVAR(uiHelpVisible);
};

// Turn map on if previously enabled and map is now disabled
if (_mapWasVisible && !GVAR(uiMapVisible)) then {
[] call FUNC(ui_toggleMap);
};

// Turn unit markers on if previously enabled and unit markers are now disabled
if (_unitsWereVisible && !GVAR(drawUnits)) then {
GVAR(drawUnits) = !GVAR(drawUnits);
};

// Turn projectile markers on if previously enabled and projectile markers are now disabled
if (_projectilesWereVisible && !GVAR(drawProjectiles)) then {
GVAR(drawProjectiles) = !GVAR(drawProjectiles);
};
};

showChat _visible;
playSound (["HintExpand", "HintCollapse"] select !_visible);

GVAR(uiVisible) = !_visible;
2 changes: 2 additions & 0 deletions addons/spectator/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,5 @@
#define CTRL_WIDGET_WEAPON (SPEC_DISPLAY displayCtrl IDC_WIDGET_WEAPON)
#define IDC_WIDGET_THROWABLE 60042
#define CTRL_WIDGET_THROWABLE (SPEC_DISPLAY displayCtrl IDC_WIDGET_THROWABLE)
#define IDC_COMPASS 60043
#define CTRL_COMPASS (SPEC_DISPLAY displayCtrl IDC_COMPASS)
4 changes: 3 additions & 1 deletion addons/spectator/ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ class GVAR(display) {
};
};
};
class compass: EGVAR(common,CompassControl) {};
class compass: EGVAR(common,CompassControl) {
idc = IDC_COMPASS;
};
};
};

0 comments on commit 8994b6b

Please sign in to comment.