forked from acemod/ACE3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfnc_ui_spectator.sqf
More file actions
265 lines (205 loc) · 7.73 KB
/
fnc_ui_spectator.sqf
File metadata and controls
265 lines (205 loc) · 7.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include "..\script_component.hpp"
/*
* 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
*/
#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 = missionNamespace getVariable ["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 = _display getVariable [QGVAR(spectateSides), []];
private _selectedSide = (ctrlIDC _ctrl) - 92540;
// Add or remove from spectatable sides and update color and scale
if (_selectedSide in _sides) then {
_display setVariable [QGVAR(spectateSides), _sides - [_selectedSide]];
_color set [3, 0.5];
} else {
_display setVariable [QGVAR(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 {
_display setVariable [QGVAR(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 = _display getVariable [QGVAR(cameraModes), []];
private _selectedMode = (ctrlIDC _ctrl) - 92550;
// Add or remove from camera modes and update color and scale
if (_selectedMode in _modes) then {
_display setVariable [QGVAR(cameraModes), _modes - [_selectedMode]];
} else {
_display setVariable [QGVAR(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);
_display setVariable [QGVAR(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 = _display getVariable [QGVAR(visionModes), []];
private _selectedVision = (ctrlIDC _ctrl) - 92560;
// Add or remove from vision modes
if (_state) then {
_display setVariable [QGVAR(visionModes), _visions + [_selectedVision]];
} else {
_display setVariable [QGVAR(visionModes), _visions - [_selectedVision]];
};
// Handle all checked/unchecked
private _allCheckboxes = VISION_IDCs apply {cbChecked (_display displayCtrl _x)};
if (_allCheckboxes isEqualTo [_state, _state, _state, _state]) 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);
_display setVariable [QGVAR(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
_state = _state == 1;
// 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;
_display setVariable [QGVAR(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 = missionNamespace getVariable ["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 = missionNamespace getVariable ["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 = (_display getVariable [QGVAR(spectateSides), []]) apply {_x call BIS_fnc_sideType};
private _modes = _display getVariable [QGVAR(cameraModes), []];
private _visions = _display getVariable [QGVAR(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];