ACE3/addons/spectator/functions/fnc_handleUnits.sqf

79 lines
1.9 KiB
Plaintext
Raw Normal View History

2015-07-16 10:15:33 +00:00
/*
* Author: SilentSpike
* Maintains the spectatable unit list and updates the unit tree accordingly
2015-07-18 17:46:46 +00:00
* Also updates current camera unit when status changes
2015-07-16 10:15:33 +00:00
*
* Arguments:
* 0: Parameters <ANY>
* 1: PFH handle <NUMBER>
2015-07-16 10:15:33 +00:00
*
* Return Value:
* None <NIL>
*
* Example:
2015-07-18 15:20:19 +00:00
* [ace_spectator_fnc_handleUnits, 10] call CBA_fnc_addPerFrameHandler;
2015-07-16 10:15:33 +00:00
*
* Public: No
*/
#include "script_component.hpp"
params ["_display"];
2015-07-17 01:30:00 +00:00
// Kill PFH when display is closed
if (isNull _display) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; };
2015-07-16 10:15:33 +00:00
2015-07-18 15:50:11 +00:00
// Remove all dead and null units from the list
[] call FUNC(updateUnits);
2015-07-18 15:50:11 +00:00
2015-07-18 17:25:59 +00:00
// Camera shouldn't stay on unit that isn't in the list
if !(GVAR(camUnit) in GVAR(unitList)) then {
[0,objNull] call FUNC(updateCamera);
};
private ["_ctrl","_curSelData","_cachedGrps","_grp","_node","_side","_index"];
2015-07-18 17:46:46 +00:00
2015-07-16 10:15:33 +00:00
// Fetch tree
2015-07-17 00:44:49 +00:00
_ctrl = (_display displayCtrl IDC_UNIT) controlsGroupCtrl IDC_UNIT_TREE;
2015-07-16 10:15:33 +00:00
2015-07-16 17:31:49 +00:00
// Cache current selection
_curSelData = _ctrl tvData (tvCurSel _ctrl);
2015-07-16 10:15:33 +00:00
// Clear the tree
2015-07-16 22:58:58 +00:00
tvClear _ctrl;
2015-07-16 10:15:33 +00:00
2015-07-17 01:30:00 +00:00
// Update the tree from the unit list
2015-07-16 10:15:33 +00:00
_cachedGrps = [];
{
2015-07-18 15:50:11 +00:00
_grp = group _x;
_node = 0;
// If group already exists, find existing node
if !(_grp in _cachedGrps) then {
_side = [west,east,resistance,civilian,sideLogic] find (side _grp);
_node = _ctrl tvCount [];
2015-07-17 01:30:00 +00:00
2015-07-18 15:50:11 +00:00
_ctrl tvAdd [[], groupID _grp];
_ctrl tvSetValue [[_node], _side];
2015-07-16 10:15:33 +00:00
2015-07-18 15:50:11 +00:00
_cachedGrps pushBack _grp;
} else {
_node = _cachedGrps find _grp;
};
2015-07-16 10:15:33 +00:00
2015-07-18 15:50:11 +00:00
_index = _ctrl tvCount [_node];
2015-07-16 10:15:33 +00:00
2015-07-18 15:50:11 +00:00
_ctrl tvAdd [[_node], name _x];
_ctrl tvSetData [[_node,_index], netID _x];
2015-07-16 10:15:33 +00:00
2015-07-18 15:50:11 +00:00
// Preserve the previous selection
if (_curSelData == (_ctrl tvData [_node,_index])) then {
_ctrl tvSetCurSel [_node,_index];
2015-07-16 17:31:49 +00:00
};
2015-07-18 15:50:11 +00:00
_ctrl tvSort [[_node],false];
_ctrl tvExpand [_node];
2015-07-16 10:15:33 +00:00
} forEach GVAR(unitList);
// Sort group nodes by side
_ctrl tvSortByValue [[],false];