diff --git a/addons/spectator/XEH_postInit.sqf b/addons/spectator/XEH_postInit.sqf index e5a037641e..4b1f653223 100644 --- a/addons/spectator/XEH_postInit.sqf +++ b/addons/spectator/XEH_postInit.sqf @@ -16,4 +16,4 @@ if (isServer) then { }; // Should prevent unending spectator on mission end -addMissionEventHandler ["Ended",{ [false] call FUNC(setSpectator) }]; +addMissionEventHandler ["Ended",{ [QGVAR(EndMission)] call FUNC(interrupt) }]; diff --git a/addons/spectator/XEH_preInit.sqf b/addons/spectator/XEH_preInit.sqf index 13f2ba1708..4b30edbadf 100644 --- a/addons/spectator/XEH_preInit.sqf +++ b/addons/spectator/XEH_preInit.sqf @@ -25,6 +25,9 @@ PREP(updateSpectatableSides); PREP(updateUnits); PREP(updateVisionModes); +// Reset the stored display +SETUVAR(GVAR(interface),displayNull); + // Permanent variables GVAR(availableModes) = [0,1,2]; GVAR(availableSides) = [west,east,resistance,civilian]; diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index 1ff8eaf301..a8a607d537 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -22,6 +22,7 @@ params ["_mode",["_args",[]]]; switch (toLower _mode) do { case "onload": { _args params ["_display"]; + SETUVAR(GVAR(interface),_display); // Always show interface and hide map upon opening [_display,nil,nil,!GVAR(showInterface),GVAR(showMap)] call FUNC(toggleInterface); @@ -454,13 +455,13 @@ switch (toLower _mode) do { // PFH to re-open display when menu closes [{ - if !(isNull (findDisplay 49)) exitWith {}; + if !(isNull (_this select 0)) exitWith {}; // If still a spectator then re-enter the interface [QGVAR(escape),false] call FUNC(interrupt); [_this select 1] call CBA_fnc_removePerFrameHandler; - },0] call CBA_fnc_addPerFrameHandler; + },0,_dlg] call CBA_fnc_addPerFrameHandler; }; case "zeus": { openCuratorInterface; diff --git a/addons/spectator/functions/fnc_interrupt.sqf b/addons/spectator/functions/fnc_interrupt.sqf index 72bb3eaa32..0826949b30 100644 --- a/addons/spectator/functions/fnc_interrupt.sqf +++ b/addons/spectator/functions/fnc_interrupt.sqf @@ -29,16 +29,16 @@ if (_interrupt) then { }; if (GVAR(interrupts) isEqualTo []) then { - if (isNull (findDisplay 12249)) then { - createDialog QGVAR(interface); + if (isNull (GETUVAR(GVAR(interface),displayNull))) then { + (findDisplay 46) createDisplay QGVAR(interface); [] call FUNC(transitionCamera); }; } else { - if !(isNull (findDisplay 12249)) then { + if !(isNull (GETUVAR(GVAR(interface),displayNull))) then { while {dialog} do { closeDialog 0; }; - (findDisplay 12249) closeDisplay 0; + (GETUVAR(GVAR(interface),displayNull)) closeDisplay 0; }; }; diff --git a/addons/spectator/functions/fnc_setSpectator.sqf b/addons/spectator/functions/fnc_setSpectator.sqf index b1160be2ea..ce9428cea4 100644 --- a/addons/spectator/functions/fnc_setSpectator.sqf +++ b/addons/spectator/functions/fnc_setSpectator.sqf @@ -24,7 +24,7 @@ params [["_set",true,[true]], ["_force",true,[true]]]; // Only clients can be spectators -if (!hasInterface) exitWith {}; +if !(hasInterface) exitWith {}; // Exit if no change if (_set isEqualTo GVAR(isSet)) exitWith {}; @@ -84,12 +84,13 @@ if (_set) then { }; [{ + disableSerialization; // Create the display - (findDisplay 46) createDisplay QGVAR(interface); + _display = (findDisplay 46) createDisplay QGVAR(interface); // If not forced, make esc end spectator if (_this) then { - (findDisplay 12249) displayAddEventHandler ["KeyDown", { + _display displayAddEventHandler ["KeyDown", { if (_this select 1 == 1) then { [false] call ace_spectator_fnc_setSpectator; true @@ -111,7 +112,7 @@ if (_set) then { }; // Kill the display - (findDisplay 12249) closeDisplay 0; + (GETUVAR(GVAR(interface),displayNull)) closeDisplay 0; // Terminate camera GVAR(freeCamera) cameraEffect ["terminate", "back"]; @@ -147,7 +148,6 @@ if (_set) then { //Kill these PFEH handlers now because the PFEH can run before the `onunload` event is handled GVAR(camHandler) = nil; GVAR(compHandler) = nil; - GVAR(iconHandler) = nil; GVAR(toolHandler) = nil; // Cleanup display variables