diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index 724832a77..b8724d694 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -27,6 +27,8 @@ class CfgFunctions { PATHTO_FNC(getMagazineIndex); PATHTO_FNC(currentMagazineIndex); PATHTO_FNC(setCallsign); + PATHTO_FNC(getActiveFeatureCamera); + PATHTO_FNC(registerFeatureCamera); }; class Soldiers { diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 714379e19..d927fc36a 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -23,6 +23,24 @@ GVAR(delayless_loop) = QUOTE(PATHTOF(delayless_loop.fsm)); // Initialize Components GVAR(groups) = [grpNull, grpNull, grpNull, grpNull, grpNull]; +GVAR(featureCamerasCode) = [ + {!isNull curatorCamera}, // Curator + {!isNull (missionNamespace getVariable ["BIS_EGSpectatorCamera_camera", objNull])}, // BIS Nexus Spectator + {!isNull (uiNamespace getVariable ["BIS_fnc_arsenal_cam", objNull])}, // Arsenal camera + {!isNull (missionNamespace getVariable ["BIS_fnc_establishingShot_fakeUAV", objNull])}, // Establishing shot camera + {!isNull (missionNamespace getVariable ["BIS_fnc_camera_cam", objNull])}, // Splendid camera + {!isNull (uiNamespace getVariable ["BIS_fnc_animViewer_cam", objNull])}, // Animation viewer camera + {!isNull (missionNamespace getVariable ["BIS_DEBUG_CAM", objNull])} // Classic camera +]; +GVAR(featureCamerasNames) = [ + "curator", // Curator + "nexus", // BIS Nexus Spectator + "arsenal", // Arsenal camera + "establishing", // Establishing shot camera + "splendid", // Splendid camera + "animViewer", // Animation viewer camera + "classic" // Classic camera +]; call COMPILE_FILE(init_gauss); call COMPILE_FILE(init_perFrameHandler); diff --git a/addons/common/fnc_getActiveFeatureCamera.sqf b/addons/common/fnc_getActiveFeatureCamera.sqf new file mode 100644 index 000000000..965b22801 --- /dev/null +++ b/addons/common/fnc_getActiveFeatureCamera.sqf @@ -0,0 +1,35 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_getActiveFeatureCamera + +Description: + Returns active feature camera. + + Checks for the following feature cameras: + - Curator + - Arsenal camera (BIS_fnc_arsenal) + - Nexus Spectator (BIS_fnc_EGSpectator) + - Establishing shot (BIS_fnc_establishingShot) + - Splendid camera (BIS_fnc_camera) + - Animation viewer (BIS_fnc_animViewer) + - Classic camera (BIS_fnc_cameraOld) + + And cameras registered via CBA_fnc_registerFeatureCamera. + +Parameters: + None + +Returns: + Active feature camera ("" if none) + +Examples: + (begin example) + _result = [] call CBA_fnc_getActiveFeatureCamera + (end) + +Author: + Sniperwolf572, Jonpas +---------------------------------------------------------------------------- */ +SCRIPT(getActiveFeatureCamera); + +GVAR(featureCamerasNames) param [GVAR(featureCamerasCode) findIf {call _x}, ""] diff --git a/addons/common/fnc_registerFeatureCamera.sqf b/addons/common/fnc_registerFeatureCamera.sqf new file mode 100644 index 000000000..06746579c --- /dev/null +++ b/addons/common/fnc_registerFeatureCamera.sqf @@ -0,0 +1,43 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_registerFeatureCamera + +Description: + Registers a feature camera for use with CBA_fnc_getActiveFeatureCamera. + +Parameters: + _name - Name (unique/tagged) + _callback - Activity check (should return true if active, false otherwise) + +Returns: + Successfully registered + +Examples: + (begin example) + _result = [ + "ace_spectator", + {!isNull (missionNamespace getVariable ["ace_spectator_isSet", objNull])} + ] call CBA_fnc_registerFeatureCamera + (end) + +Author: + Sniperwolf572, Jonpas +---------------------------------------------------------------------------- */ +SCRIPT(registerFeatureCamera); + +params [["_name", "", [""]], ["_callback", false, [{}]]]; + +if (_name isEqualTo "") exitWith { + TRACE_1("Name empty",_name); + false +}; + +if (_callback isEqualTo false) exitWith { + TRACE_1("Callback not code",_name); + false +}; + +if ((GVAR(featureCamerasNames) pushBackUnique _name) == -1) exitWith {false}; +GVAR(featureCamerasCode) pushBack _callback; + +true diff --git a/addons/events/fnc_addPlayerEventHandler.sqf b/addons/events/fnc_addPlayerEventHandler.sqf index 7543c9fa0..c3e22fbae 100644 --- a/addons/events/fnc_addPlayerEventHandler.sqf +++ b/addons/events/fnc_addPlayerEventHandler.sqf @@ -6,20 +6,21 @@ Description: Adds a player event handler. Possible events: - "unit" - player controlled unit changed - "weapon" - currently selected weapon change - "loadout" - players loadout changed - "vehicle" - players current vehicle changed - "turret" - position in vehicle changed - "visionMode" - player changed to normal/night/thermal view - "cameraView" - camera mode changed ("Internal", "External", "Gunner" etc.) - "visibleMap" - opened or closed map - "group" - player group changes - "leader" - leader of player changes + "unit" - player controlled unit changed + "weapon" - currently selected weapon change + "loadout" - players loadout changed + "vehicle" - players current vehicle changed + "turret" - position in vehicle changed + "visionMode" - player changed to normal/night/thermal view + "cameraView" - camera mode changed ("Internal", "External", "Gunner" etc.) + "featureCamera" - camera changed (Curator, Arsenal, Spectator etc.) + "visibleMap" - opened or closed map + "group" - player group changes + "leader" - leader of player changes Parameters: - _type - Event handler type. - _function - Function to add to event. + _type - Event handler type. + _function - Function to add to event. _applyRetroactively - Call function immediately if player is defined already (optional, default: false) Returns: @@ -84,6 +85,12 @@ private _id = switch (_type) do { }; [QGVAR(cameraViewEvent), _function] call CBA_fnc_addEventHandler // return id }; + case "featurecamera": { + if (_applyRetroactively && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + [GVAR(oldUnit), call CBA_fnc_getActiveFeatureCamera] call _function; + }; + [QGVAR(featureCameraEvent), _function] call CBA_fnc_addEventHandler // return id + }; case "visiblemap": { if (_applyRetroactively && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { [GVAR(oldUnit), visibleMap] call _function; @@ -120,6 +127,7 @@ if (_id != -1) then { GVAR(oldTurret) = []; GVAR(oldVisionMode) = -1; GVAR(oldCameraView) = ""; + GVAR(oldFeatureCamera) = ""; GVAR(oldVisibleMap) = false; GVAR(playerEHInfo) pushBack addMissionEventHandler ["EachFrame", {call FUNC(playerEH_EachFrame)}]; @@ -214,6 +222,15 @@ if (_id != -1) then { }; } call CBA_fnc_directCall; }; + + GVAR(playerEHInfo) pushBack ([{ + private _data = call CBA_fnc_getActiveFeatureCamera; + if !(_data isEqualTo GVAR(oldFeatureCamera)) then { + GVAR(oldFeatureCamera) = _data; + [QGVAR(featureCameraEvent), [call CBA_fnc_currentUnit, _data]] call CBA_fnc_localEvent; + }; + }, 0.5] call CBA_fnc_addPerFrameHandler); + }; GVAR(playerEHInfo) pushBack [_type, _id]; diff --git a/addons/events/fnc_removePlayerEventHandler.sqf b/addons/events/fnc_removePlayerEventHandler.sqf index 35e98f96a..a24e18502 100644 --- a/addons/events/fnc_removePlayerEventHandler.sqf +++ b/addons/events/fnc_removePlayerEventHandler.sqf @@ -48,6 +48,9 @@ switch (_type) do { case "cameraview": { [QGVAR(cameraViewEvent), _id] call CBA_fnc_removeEventHandler; }; + case "featurecamera": { + [QGVAR(featureCameraEvent), _id] call CBA_fnc_removeEventHandler; + }; case "visiblemap": { [QGVAR(visibleMapEvent), _id] call CBA_fnc_removeEventHandler; }; @@ -63,12 +66,13 @@ switch (_type) do { if (!isNil QGVAR(playerEHInfo)) then { GVAR(playerEHInfo) deleteAt (GVAR(playerEHInfo) find [_type, _id]); - // First two entries are mission eventhandler ids. Rest are framework - // specific ids in array form. If all playerChanged eventhandlers were - // removed, then also clean up the mission eventhandlers. - if (count GVAR(playerEHInfo) == 2) then { + // First two entries are Mission EH IDs, third is PFH ID. Rest are framework + // specific IDs in array form. If all playerChanged eventhandlers were + // removed, then also clean up the Mission EHs and PFHs. + if (count GVAR(playerEHInfo) == 3) then { removeMissionEventHandler ["EachFrame", GVAR(playerEHInfo) select 0]; removeMissionEventHandler ["Map", GVAR(playerEHInfo) select 1]; + [GVAR(playerEHInfo) select 2] call CBA_fnc_removePerFrameHandler; GVAR(playerEHInfo) = nil; }; };