From d2538c6ff27ceb757fe0a1a93259fa5607e7006f Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Sun, 22 Nov 2015 20:03:10 +0000 Subject: [PATCH] Add spectator text chat Turns out custom radio channels are kind of a pain to work with. However this should work fine assuming the radioChannelAdd commands will work on client machines. --- addons/spectator/XEH_postInit.sqf | 6 ++++++ .../functions/fnc_handleInterface.sqf | 5 ++++- .../spectator/functions/fnc_setSpectator.sqf | 19 ++++++++++++++++++- .../functions/fnc_transitionCamera.sqf | 6 ------ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/addons/spectator/XEH_postInit.sqf b/addons/spectator/XEH_postInit.sqf index a9737868a0..e5a037641e 100644 --- a/addons/spectator/XEH_postInit.sqf +++ b/addons/spectator/XEH_postInit.sqf @@ -9,5 +9,11 @@ GVAR(availableVisions) = [[-2,-1,0,1], [-2,-1], [-2,0,1], [-2]] select GVAR(restrictVisions); }] call EFUNC(common,addEventHandler); +// Create a radio channel for any spectators to text chat in +if (isServer) then { + GVAR(channel) = radioChannelCreate [[0.729,0.149,0.098,1],"Spectator","Spectator (%UNIT_NAME)",[]]; + publicVariable QGVAR(channel); +}; + // Should prevent unending spectator on mission end addMissionEventHandler ["Ended",{ [false] call FUNC(setSpectator) }]; diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index 8f29b20296..b4e76b5e82 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -172,9 +172,12 @@ switch (toLower _mode) do { [QGVAR(zeus)] call FUNC(interrupt); ["zeus"] call FUNC(handleInterface); }; - if ((isServer || {serverCommandAvailable "#kick"}) && {_dik in (actionKeys "Chat" + actionKeys "PrevChannel" + actionKeys "NextChannel")}) exitWith { + if (_dik in (actionKeys "Chat")) exitWith { false }; + if (_dik in (actionKeys "PrevChannel" + actionKeys "NextChannel")) exitWith { + !(isServer || serverCommandAvailable "#kick") + }; // Handle held keys (prevent repeat calling) if (GVAR(heldKeys) param [_dik,false]) exitwith {}; diff --git a/addons/spectator/functions/fnc_setSpectator.sqf b/addons/spectator/functions/fnc_setSpectator.sqf index 065ca0079b..30aa03764f 100644 --- a/addons/spectator/functions/fnc_setSpectator.sqf +++ b/addons/spectator/functions/fnc_setSpectator.sqf @@ -63,9 +63,17 @@ if (_set) then { GVAR(unitCamera) camCommit 0; [] call FUNC(transitionCamera); - // Close map and clear radio + // Cache current channel to switch back to on exit + GVAR(channelCache) = currentChannel; + + // Channel index starts count after the 5 default channels + GVAR(channel) radioChannelAdd [player]; + setCurrentChannel (5 + GVAR(channel)); + + // Close map and clear the chat openMap [false,false]; clearRadio; + enableRadio false; // Disable BI damage effects BIS_fnc_feedback_allowPP = false; @@ -111,7 +119,16 @@ if (_set) then { camDestroy GVAR(unitCamera); camDestroy GVAR(targetCamera); + // Remove from spectator chat + GVAR(channel) radioChannelRemove [player]; + + // Restore cached channel and delete cache + setCurrentChannel GVAR(channelCache); + GVAR(channelCache) = nil; + + // Clear any residual spectator chat clearRadio; + enableRadio true; // Return to player view player switchCamera "internal"; diff --git a/addons/spectator/functions/fnc_transitionCamera.sqf b/addons/spectator/functions/fnc_transitionCamera.sqf index 0f6eb3ffc7..0d51ebc427 100644 --- a/addons/spectator/functions/fnc_transitionCamera.sqf +++ b/addons/spectator/functions/fnc_transitionCamera.sqf @@ -61,7 +61,6 @@ if (_newMode == 0) then { // Free }; GVAR(camAgent) switchCamera "internal"; - clearRadio; } else { _camera = GVAR(unitCamera); @@ -87,11 +86,6 @@ if (_newMode == 0) then { // Free _camera cameraEffect ["internal", "back"]; }; - // Clear radio if group changed - if (group _newUnit != group GVAR(camUnit)) then { - clearRadio; - }; - GVAR(camUnit) = _newUnit; };