diff --git a/addons/spectator/functions/fnc_ui_toggleUI.sqf b/addons/spectator/functions/fnc_ui_toggleUI.sqf index ff34798c690..91decbfa933 100644 --- a/addons/spectator/functions/fnc_ui_toggleUI.sqf +++ b/addons/spectator/functions/fnc_ui_toggleUI.sqf @@ -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 @@ -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; diff --git a/addons/spectator/script_component.hpp b/addons/spectator/script_component.hpp index c29c60bdefc..357b75690b5 100644 --- a/addons/spectator/script_component.hpp +++ b/addons/spectator/script_component.hpp @@ -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) diff --git a/addons/spectator/ui.hpp b/addons/spectator/ui.hpp index d81887db760..a1d8a745501 100644 --- a/addons/spectator/ui.hpp +++ b/addons/spectator/ui.hpp @@ -456,6 +456,8 @@ class GVAR(display) { }; }; }; - class compass: EGVAR(common,CompassControl) {}; + class compass: EGVAR(common,CompassControl) { + idc = IDC_COMPASS; + }; }; };