Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zeus - Add spectator module #6202

Merged
merged 10 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions addons/zeus/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ class CfgVehicles {
displayName = CSTRING(ModuleSimulation_DisplayName);
function = QFUNC(moduleSimulation);
};
class GVAR(moduleSpectator): GVAR(moduleBase) {
curatorCanAttach = 1;
category = QGVAR(Utility);
displayName = ECSTRING(spectator,Module_DisplayName);
curatorInfoType = QGVAR(RscSpectator);
};
class GVAR(moduleSuicideBomber): GVAR(moduleBase) {
curatorCanAttach = 1;
category = QGVAR(AI);
Expand Down
2 changes: 2 additions & 0 deletions addons/zeus/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ PREP(moduleSetMedicalFacility);
PREP(moduleSetRepairFacility);
PREP(moduleSetRepairVehicle);
PREP(moduleSimulation);
PREP(moduleSpectator);
PREP(moduleSuicideBomber);
PREP(moduleSuppressiveFire);
PREP(moduleSuppressiveFireLocal);
Expand All @@ -51,6 +52,7 @@ PREP(ui_groupSide);
PREP(ui_patrolArea);
PREP(ui_searchArea);
PREP(ui_setEngineer);
PREP(ui_spectator);
PREP(ui_suicideBomber);
PREP(ui_teleportPlayers);
PREP(ui_toggleFlashlight);
Expand Down
2 changes: 2 additions & 0 deletions addons/zeus/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ QGVAR(GlobalSkillAI) addPublicVariableEventHandler FUNC(moduleGlobalSetSkill);
_unit enableGunLights _mode;
}] call CBA_fnc_addEventHandler;

[QGVAR(moduleSpectator), LINKFUNC(moduleSpectator)] call CBA_fnc_addEventHandler;

// Editable object commands must be ran on server, this events are used in the respective module
if (isServer) then {
[QGVAR(equipFries), EFUNC(fastroping,equipFRIES)] call CBA_fnc_addEventHandler;
Expand Down
6 changes: 6 additions & 0 deletions addons/zeus/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ class CfgPatches {
QGVAR(RemoveFullAceArsenal)
};
};
class GVAR(spectator): ADDON {
units[] = {
QGVAR(moduleSpectator)
};
};
};

class ACE_Curator {
Expand All @@ -97,6 +102,7 @@ class ACE_Curator {
GVAR(fastroping) = "ace_fastroping";
GVAR(pylons) = "ace_pylons";
GVAR(arsenal) = "ace_arsenal";
GVAR(spectator) = "ace_spectator";
};

#include "CfgFactionClasses.hpp"
Expand Down
39 changes: 39 additions & 0 deletions addons/zeus/functions/fnc_moduleSpectator.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Author: mharis001
* Zeus module function to make the local player an ACE Spectator.
*
* Arguments:
* 0: Force interface <BOOL>
* 1: Hide player <BOOL>
* 2: Sides available to spectate <ARRAY>
* 3: Camera modes available <ARRAY>
* 4: Vision modes available <ARRAY>
*
* Return Value:
* None
*
* Example:
* [true, true, [west], [0, 1, 2], [-2, -1, 0, 1]] call ace_zeus_fnc_moduleSpectator
*
* Public: No
*/
#include "script_component.hpp"

params ["_force", "_hide", "_sides", "_modes", "_visions"];
TRACE_1("params",_this);

// Update sides available to spectate
[_sides, [west, east, independent, civilian] - _sides] call EFUNC(spectator,updateSides);

// Update available camera modes
[_modes, [0, 1, 2] - _modes] call EFUNC(spectator,updateCameraModes);

// Update available vision modes
[_visions, [-2, -1, 0, 1, 2, 3, 4, 5, 6, 7] - _visions] call EFUNC(spectator,updateVisionModes);

// Make unit spectator (close Zeus camera if open)
if !(isNull curatorCamera) then {
(findDisplay 312) closeDisplay 2;
};

[true, _force, _hide] call EFUNC(spectator,setSpectator);
265 changes: 265 additions & 0 deletions addons/zeus/functions/fnc_ui_spectator.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
/*
* Author: mharis001
* Initializes the "Spectator" Zeus module display.
*
* Arguments:
* 0: spectator controls group <CONTROL>
*
* Return Value:
* None
*
* Example:
* [CONTROL] call ace_zeus_fnc_ui_spectator
*
* Public: No
*/
#include "script_component.hpp"

#define SIDE_IDCs [92540, 92541, 92542, 92543]
#define CAMERA_IDCs [92550, 92551, 92552]
#define VISION_IDCs [92558, 92559, 92560, 92561]

params ["_control"];

private _display = ctrlParent _control;
private _ctrlButtonOK = _display displayCtrl 1; // IDC_OK
private _logic = GETMVAR(BIS_fnc_initCuratorAttributes_target,objNull);
TRACE_1("Logic Object",_logic);

_control ctrlRemoveAllEventHandlers "SetFocus";

// Validate module target
private _unit = attachedTo _logic;
TRACE_1("Unit",_unit);

scopeName "Main";
private _fnc_errorAndClose = {
params ["_msg"];
_display closeDisplay 0;
deleteVehicle _logic;
[_msg] call FUNC(showMessage);
breakOut "Main";
};

switch (false) do {
case (["ace_spectator"] call EFUNC(common,isModLoaded)): {
[LSTRING(RequiresAddon)] call _fnc_errorAndClose;
};
case !(isNull _unit): {
[LSTRING(NothingSelected)] call _fnc_errorAndClose;
};
case (_unit isKindOf "CAManBase"): {
[LSTRING(OnlyInfantry)] call _fnc_errorAndClose;
};
case (alive _unit): {
[LSTRING(OnlyAlive)] call _fnc_errorAndClose;
};
case ([_unit, true] call EFUNC(common,isPlayer)): {
[LSTRING(OnlyPlayers)] call _fnc_errorAndClose;
};
};

// Specific onLoad stuff
private _side = side _unit;

// Spectate sides
private _fnc_onSideSelection = {
params ["_ctrl"];

private _display = ctrlParent _ctrl;
if (isNull _display) exitWith {};

private _color = _ctrl getVariable "color";
private _scale = 1;

private _sides = GETVAR(_display,spectateSides,[]);
private _selectedSide = (ctrlIDC _ctrl) - 92540;

// Add or remove from spectatable sides and update color and scale
if (_selectedSide in _sides) then {
SETVAR(_display,spectateSides,_sides - [_selectedSide]);
_color set [3, 0.5];
} else {
SETVAR(_display,spectateSides,_sides + [_selectedSide]);
_color set [3, 1];
_scale = 1.2;
};

_ctrl ctrlSetTextColor _color;
[_ctrl, _scale, 0.1] call BIS_fnc_ctrlSetScale;
};

// Use the unit's side as default
private _activeSide = [east, west, independent, civilian] find _side;

// Handle sides other than default four (sideEnemy)
if (_activeSide != -1) then {
SETVAR(_display,spectateSides,[_activeSide]);
};

{
private _ctrl = _display displayCtrl _x;
private _side = _x - 92540;
private _color = [_side] call BIS_fnc_sideColor;
_ctrl setVariable ["color", _color];
_ctrl ctrlSetActiveColor _color;
_color set [3, 0.5];

if (_side == _activeSide) then {
[_ctrl, 1.2, 0] call BIS_fnc_ctrlSetScale;
_color set [3, 1];
};

_ctrl ctrlSetTextColor _color;

_ctrl ctrlAddEventHandler ["ButtonClick", _fnc_onSideSelection];
} forEach SIDE_IDCs;

// Camera modes
private _fnc_onModesSelection = {
params ["_ctrl"];

private _display = ctrlParent _ctrl;
if (isNull _display) exitWith {};

private _color = [1, 1, 1, 0.5];
private _scale = 1;

private _modes = GETVAR(_display,cameraModes,[]);
private _selectedMode = (ctrlIDC _ctrl) - 92550;

// Add or remove from camera modes and update color and scale
if (_selectedMode in _modes) then {
SETVAR(_display,cameraModes,_modes - [_selectedMode]);
} else {
SETVAR(_display,cameraModes,_modes + [_selectedMode]);
_color set [3, 1];
_scale = 1.2;
};

_ctrl ctrlSetTextColor _color;
[_ctrl, _scale, 0.1] call BIS_fnc_ctrlSetScale;
};

// Use setting as default since global variable will change
private _availableModes = [[0,1,2], [1,2], [0], [1], [2]] select EGVAR(spectator,restrictModes);
SETVAR(_display,cameraModes,_availableModes);

{
private _ctrl = _display displayCtrl _x;
private _color = [1, 1, 1, 0.5];

if ((_x - 92550) in _availableModes) then {
[_ctrl, 1.2, 0] call BIS_fnc_ctrlSetScale;
_color set [3, 1];
};

_ctrl ctrlSetTextColor _color;

_ctrl ctrlAddEventHandler ["ButtonClick", _fnc_onModesSelection];
} forEach CAMERA_IDCs;

// Vision Modes
private _fnc_onVisionSelection = {
params ["_ctrl", "_state"];

private _display = ctrlParent _ctrl;
if (isNull _display) exitwith {};

// Convert to boolean since EH returns state as 0 or 1
private _state = [false, true] select _state;

private _visions = GETVAR(_display,visionModes,[]);
private _selectedVision = (ctrlIDC _ctrl) - 92560;

// Add or remove from vision modes
if (_state) then {
SETVAR(_display,visionModes,_visions + [_selectedVision]);
} else {
SETVAR(_display,visionModes,_visions - [_selectedVision]);
};

// Handle all checked/unchecked
private _allCheckboxes = VISION_IDCs apply {cbChecked (_display displayCtrl _x)};

if (({_x isEqualTo _state} count _allCheckboxes) isEqualTo 4) then {
(_display displayCtrl 92557) cbSetChecked _state;
};
};

// Use setting as default since global variable will change
private _availableVisions = [[-2,-1,0,1], [-2,-1], [-2,0,1], [-2]] select EGVAR(spectator,restrictVisions);
SETVAR(_display,visionModes,_availableVisions);

{
private _ctrl = _display displayCtrl _x;

if ((_x - 92560) in _availableVisions) then {
_ctrl cbSetChecked true;
};

_ctrl ctrlAddEventHandler ["CheckedChanged", _fnc_onVisionSelection];
} forEach VISION_IDCs;

// Init all visions checkbox
private _fnc_onVisionsAll = {
params ["_ctrl", "_state"];

private _display = ctrlParent _ctrl;
if (isNull _display) exitWith {};

// Convert to boolean since EH returns state as 0 or 1
private _state = [false, true] select _state;

// Set state of all checkboxes
{
(_display displayCtrl _x) cbSetChecked _state;
} forEach VISION_IDCs;

// Store new visions mode setting
private _setting = [[], [-2, -1, 0, 1]] select _state;
SETVAR(_display,visionModes,_setting);
};

private _allCheckbox = _display displayCtrl 92557;

// Set to checked by default if setting is all vision modes
if (_availableVisions isEqualTo [-2, -1, 0, 1]) then {
_allCheckbox cbSetChecked true;
};

_allCheckbox ctrlAddEventHandler ["CheckedChanged", _fnc_onVisionsAll];

// Confirm and Cancel
private _fnc_onUnload = {
private _logic = GETMVAR(BIS_fnc_initCuratorAttributes_target,objNull);
if (isNull _logic) exitWith {};

deleteVehicle _logic;
};

private _fnc_onConfirm = {
params [["_ctrlButtonOK", controlNull, [controlNull]]];

private _display = ctrlParent _ctrlButtonOK;
if (isNull _display) exitWith {};

private _logic = GETMVAR(BIS_fnc_initCuratorAttributes_target,objNull);
if (isNull _logic) exitWith {};

private _unit = attachedTo _logic;
if (isNull _unit) exitWith {};

private _force = lbCurSel (_display displayCtrl 92531) > 0;
private _hide = lbCurSel (_display displayCtrl 92532) > 0;
private _sides = GETVAR(_display,spectateSides,[]) apply {[_x] call BIS_fnc_sideType};
private _modes = GETVAR(_display,cameraModes,[]);
private _visions = GETVAR(_display,visionModes,[]);

[QGVAR(moduleSpectator), [_force, _hide, _sides, _modes, _visions], _unit] call CBA_fnc_targetEvent;

deleteVehicle _logic;
};

_display displayAddEventHandler ["Unload", _fnc_onUnload];
_ctrlButtonOK ctrlAddEventHandler ["ButtonClick", _fnc_onConfirm];
Loading