Improve handling of unit tree

This commit is contained in:
SilentSpike 2015-07-17 02:30:00 +01:00
parent 6cb1813527
commit 27d85180f1
4 changed files with 38 additions and 64 deletions

View File

@ -174,7 +174,7 @@ class GVAR(interface) {
h = TOOL_H;
sizeEx = TOOL_H;
text = CSTRING(RefreshList);
action = QUOTE([] call FUNC(handleTree));
action = QUOTE([allUnits] call FUNC(updateUnits));
};
};
};

View File

@ -138,7 +138,7 @@ switch (toLower _mode) do {
(_display displayCtrl IDC_TOOL_VIEW) ctrlSetText (["FREE","FIRST","THIRD"] select GVAR(camMode));
// Keep unit tree up to date
[] call FUNC(handleTree);
[FUNC(handleTree), 10] call CBA_fnc_addPerFrameHandler;
// Hacky way to enable keybindings
//_display displayAddEventHandler ["KeyUp", {[_this,'keyup'] call CBA_events_fnc_keyHandler}];

View File

@ -1,6 +1,6 @@
/*
* Author: SilentSpike
* Tracks the units in the unit tree and updates it according to their status
* Tracks the the unit list and updates the unit tree according to its status
*
* Arguments:
* None <NIL>
@ -16,11 +16,8 @@
#include "script_component.hpp"
// Remove any existing PFH
if !(isNil QGVAR(treePFH)) then {
[GVAR(treePFH)] call CBA_fnc_removePerFrameHandler;
GVAR(treePFH) = nil;
};
// Kill PFH when display is closed
if (isNull (GETUVAR(GVAR(display),displayNull))) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; };
// Fetch tree
disableSerialization;
@ -33,9 +30,11 @@ _curSelData = _ctrl tvData (tvCurSel _ctrl);
// Clear the tree
tvClear _ctrl;
// Update the tree
// Update the tree from the unit list
_cachedGrps = [];
{
// Exclude any currently dead units
if ((alive _x) && !(_x getVariable [QGVAR(isSpectator), false])) then {
_grp = group _x;
_node = 0;
// If group already exists, find existing node
@ -62,34 +61,8 @@ _cachedGrps = [];
};
_ctrl tvSort [[_node],false];
};
} forEach GVAR(unitList);
// Sort group nodes by side
_ctrl tvSortByValue [[],false];
// Keep tree up to date
GVAR(treePFH) = [{
// Kill PFH when display is closed
if (isNull (GETUVAR(GVAR(display),displayNull))) exitWith {
[_this select 1] call CBA_fnc_removePerFrameHandler;
GVAR(treePFH) = nil;
};
disableSerialization;
_display = GETUVAR(GVAR(display),displayNull);
_ctrl = (_display displayCtrl IDC_UNIT) controlsGroupCtrl IDC_UNIT_TREE;
_nodes = (_ctrl tvCount []) - 1;
for "_n" from 0 to _nodes do {
_units = (_ctrl tvCount [_n]) - 1;
for "_i" from 0 to _units do {
_netID = _ctrl tvData [_n,_i];
_unit = objectFromNetId _netID;
if (isNull _unit || !alive _unit) then {
_ctrl tvDelete [_n,_i];
[[_unit],false] call FUNC(updateUnits);
};
};
};
}, 5] call CBA_fnc_addPerFrameHandler;

View File

@ -32,15 +32,14 @@ if (_permanent) then {
};
if (_append) then {
_newUnits = _newUnits - GVAR(unitList);
// Append only valid units to the list
{
if (
(_x isKindOf "CAManBase") &&
{(side _x) in [west,east,resistance,civilian]} &&
(alive _x) &&
{(_x isKindOf "CAManBase")} &&
{(side _x) in [west,east,resistance,civilian]} && // Side filter
{(isPlayer _x) || GVAR(allowAI)} && // AI restriction
{(simulationEnabled _x)} && //!isObjectHidden _unit} && // (currently dev branch only)
{(simulationEnabled _x) && !isObjectHidden _unit} &&
{!(_x getVariable [QGVAR(isSpectator), false])} // Who watches the watchmen?
) then {
GVAR(unitList) pushBack _x;
@ -53,3 +52,5 @@ if (_append) then {
// Apply whitelist and blacklist
GVAR(unitList) append GVAR(unitWhitelist);
GVAR(unitList) = GVAR(unitList) - GVAR(unitBlacklist);
GVAR(unitList) arrayIntersect GVAR(unitList);