From 37ffdab2ca51c7a3baa60f2c505050d77df273ca Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Tue, 21 Jul 2015 13:31:13 +0100 Subject: [PATCH] Add camera cycling function --- addons/spectator/ACE_Settings.hpp | 10 ++++ addons/spectator/XEH_postInit.sqf | 4 +- addons/spectator/XEH_preInit.sqf | 4 ++ .../spectator/functions/fnc_cycleCamera.sqf | 47 +++++++++++++++++++ .../functions/fnc_handleInterface.sqf | 10 ++-- .../functions/fnc_transitionCamera.sqf | 5 ++ addons/spectator/stringtable.xml | 40 ++++++++++++---- 7 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 addons/spectator/functions/fnc_cycleCamera.sqf diff --git a/addons/spectator/ACE_Settings.hpp b/addons/spectator/ACE_Settings.hpp index 48af019059..8fd6981f33 100644 --- a/addons/spectator/ACE_Settings.hpp +++ b/addons/spectator/ACE_Settings.hpp @@ -13,4 +13,14 @@ class ACE_Settings { value = 0; values[] = {CSTRING(sides_player), CSTRING(sides_friendly), CSTRING(sides_hostile), CSTRING(sides_all)}; }; + class GVAR(restrictModes) { + typeName = "SCALAR"; + value = 0; + values[] = {CSTRING(modes_all), CSTRING(modes_unit), CSTRING(modes_free), CSTRING(modes_internal), CSTRING(modes_external)}; + }; + class GVAR(restrictVisions) { + typeName = "SCALAR"; + value = 0; + values[] = {CSTRING(modes_all), CSTRING(visions_nv), CSTRING(visions_ti), "$STR_Special_None"}; + }; }; diff --git a/addons/spectator/XEH_postInit.sqf b/addons/spectator/XEH_postInit.sqf index e96bbf2c10..1adef9c16a 100644 --- a/addons/spectator/XEH_postInit.sqf +++ b/addons/spectator/XEH_postInit.sqf @@ -12,8 +12,10 @@ [FUNC(checkUnits), 2] call CBA_fnc_addPerFrameHandler; [FUNC(trackUnits), 20] call CBA_fnc_addPerFrameHandler; };*/ + GVAR(availableModes) = [[0,1,2], [1,2], [0], [1], [2]] select GVAR(restrictModes); + GVAR(availableVisions) = [[-2,-1,0,1], [-2,-1], [-2,0,1], [-2]] select GVAR(restrictVisions); - if GVAR(system) then { + if (GVAR(system)) then { // Add event handlers to correctly enter spectator upon death player addEventHandler ["Killed", FUNC(handleKilled)]; player addEventHandler ["Respawn", FUNC(handleRespawn)]; diff --git a/addons/spectator/XEH_preInit.sqf b/addons/spectator/XEH_preInit.sqf index 100c45dea9..8ed30c60a6 100644 --- a/addons/spectator/XEH_preInit.sqf +++ b/addons/spectator/XEH_preInit.sqf @@ -2,6 +2,7 @@ ADDON = false; +PREP(cycleCamera); PREP(handleCamera); PREP(handleCompass); PREP(handleInterface); @@ -18,6 +19,9 @@ PREP(toggleInterface); PREP(updateUnits); // Permanent variables +GVAR(availableModes) = [0,1,2]; +GVAR(availableVisions) = [-2,-1,0,1]; + GVAR(camMode) = 0; GVAR(camPan) = 0; GVAR(camPos) = [worldSize * 0.5,worldSize * 0.5,20]; diff --git a/addons/spectator/functions/fnc_cycleCamera.sqf b/addons/spectator/functions/fnc_cycleCamera.sqf new file mode 100644 index 0000000000..ef8b6c8196 --- /dev/null +++ b/addons/spectator/functions/fnc_cycleCamera.sqf @@ -0,0 +1,47 @@ +/* + * Author: SilentSpike + * Cycle through the spectator camera vision/view/units in steps + * + * Arguments: + * 0: Camera mode steps + * 1: Camera unit steps + * 2: Vision mode steps + * + * Return Value: + * None + * + * Example: + * [0, -1] call ace_spectator_fnc_cycleCamera + * + * Public: No + */ + +#include "script_component.hpp" + +params [["_stepMode",0], ["_stepUnit",0], ["_stepVision",0]]; +private ["_modes","_visions","_iMode","_iVision","_countModes","_countVisions","_newMode","_newVision","_newUnit"]; + +_modes = GVAR(availableModes); +_visions = GVAR(availableVisions); + +// Get current index +_iMode = abs(_modes find GVAR(camMode)); +_iVision = abs(_visions find GVAR(camVision)); + +_countModes = count _modes; +_countVisions = count _visions; + +// Step index by step number (lopp ends) +_iMode = (_iMode + _stepMode) % _countModes; +if (_iMode < 0) then { _iMode = _countModes + _iMode; }; + +_iVision = (_iVision + _stepVision) % _countVisions; +if (_iVision < 0) then { _iVision = _countVisions + _iVision; }; + +// Get value at new index +_newMode = _modes select _iMode; +_newVision = _visions select _iVision; + +_newUnit = GVAR(camUnit); + +[_newMode, _newUnit, _newVision] call FUNC(transitionCamera); diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index abe9cc8c47..3fff2a9bb5 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -189,7 +189,7 @@ switch (toLower _mode) do { GVAR(camBoom) set [1,true]; }; case 49: { // N - + [nil,nil,1] call FUNC(cycleCamera); }; case 50: { // M [_display,nil,nil,nil,true] call FUNC(toggleInterface); @@ -200,7 +200,7 @@ switch (toLower _mode) do { // Freecam attachment here, if in external then set cam pos and attach }; case 200: { // Up arrow - [[2,0,1] select GVAR(camMode)] call FUNC(transitionCamera); + [-1] call FUNC(cycleCamera); }; case 203: { // Left arrow @@ -209,7 +209,7 @@ switch (toLower _mode) do { }; case 208: { // Down arrow - [[1,2,0] select GVAR(camMode)] call FUNC(transitionCamera); + [1] call FUNC(cycleCamera); }; }; @@ -260,7 +260,9 @@ switch (toLower _mode) do { _newMode = [2,2,1] select GVAR(camMode); }; - [_newMode,_newUnit] call FUNC(transitionCamera); + if (_newMode in GVAR(availableModes)) then { + [_newMode,_newUnit] call FUNC(transitionCamera); + }; }; }; case "onunitsupdate": { diff --git a/addons/spectator/functions/fnc_transitionCamera.sqf b/addons/spectator/functions/fnc_transitionCamera.sqf index 0dcea4d6c0..db9ca12bd5 100644 --- a/addons/spectator/functions/fnc_transitionCamera.sqf +++ b/addons/spectator/functions/fnc_transitionCamera.sqf @@ -27,6 +27,11 @@ params [["_newMode",GVAR(camMode)], ["_newUnit",GVAR(camUnit)], ["_newVision",GVAR(camVision)]]; +if !(_newMode in GVAR(availableModes)) exitWith { + [1] call FUNC(cycleCamera); + [nil, _newUnit, _newVision] call FUNC(transitionCamera); +}; + // When no units available to spectate, exit to freecam if (GVAR(unitList) isEqualTo []) then { _newMode = 0; diff --git a/addons/spectator/stringtable.xml b/addons/spectator/stringtable.xml index f6840ae8df..b3df0501fe 100644 --- a/addons/spectator/stringtable.xml +++ b/addons/spectator/stringtable.xml @@ -43,16 +43,38 @@ All sides - - - End Mission - Zakończ misję - Konec mise + + Camera modes - - End mission when all players dead (default BIS behaviour)? - Zakończ misję kiedy wszyscy gracze będą martwi (domyślne zachowanie BIS)? - Ukončit misi když umřou všichni hráči (výchozí BIS chování)? + + Camera modes that can be used. + + + All + + + Free only + + + Internal only + + + External only + + + Internal and external + + + Vision modes + + + Vision modes that can be used. + + + Night vision + + + Thermal Imaging