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; h = TOOL_H;
sizeEx = TOOL_H; sizeEx = TOOL_H;
text = CSTRING(RefreshList); 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)); (_display displayCtrl IDC_TOOL_VIEW) ctrlSetText (["FREE","FIRST","THIRD"] select GVAR(camMode));
// Keep unit tree up to date // Keep unit tree up to date
[] call FUNC(handleTree); [FUNC(handleTree), 10] call CBA_fnc_addPerFrameHandler;
// Hacky way to enable keybindings // Hacky way to enable keybindings
//_display displayAddEventHandler ["KeyUp", {[_this,'keyup'] call CBA_events_fnc_keyHandler}]; //_display displayAddEventHandler ["KeyUp", {[_this,'keyup'] call CBA_events_fnc_keyHandler}];

View File

@ -1,6 +1,6 @@
/* /*
* Author: SilentSpike * 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: * Arguments:
* None <NIL> * None <NIL>
@ -16,11 +16,8 @@
#include "script_component.hpp" #include "script_component.hpp"
// Remove any existing PFH // Kill PFH when display is closed
if !(isNil QGVAR(treePFH)) then { if (isNull (GETUVAR(GVAR(display),displayNull))) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; };
[GVAR(treePFH)] call CBA_fnc_removePerFrameHandler;
GVAR(treePFH) = nil;
};
// Fetch tree // Fetch tree
disableSerialization; disableSerialization;
@ -33,63 +30,39 @@ _curSelData = _ctrl tvData (tvCurSel _ctrl);
// Clear the tree // Clear the tree
tvClear _ctrl; tvClear _ctrl;
// Update the tree // Update the tree from the unit list
_cachedGrps = []; _cachedGrps = [];
{ {
_grp = group _x; // Exclude any currently dead units
_node = 0; if ((alive _x) && !(_x getVariable [QGVAR(isSpectator), false])) then {
// If group already exists, find existing node _grp = group _x;
if !(_grp in _cachedGrps) then { _node = 0;
_side = [west,east,resistance,civilian,sideLogic] find (side _grp); // If group already exists, find existing node
_node = _ctrl tvCount []; if !(_grp in _cachedGrps) then {
_side = [west,east,resistance,civilian,sideLogic] find (side _grp);
_node = _ctrl tvCount [];
_ctrl tvAdd [[], groupID _grp]; _ctrl tvAdd [[], groupID _grp];
_ctrl tvSetValue [[_node], _side]; _ctrl tvSetValue [[_node], _side];
_cachedGrps pushBack _grp; _cachedGrps pushBack _grp;
} else { } else {
_node = _cachedGrps find _grp; _node = _cachedGrps find _grp;
};
_index = _ctrl tvCount [_node];
_ctrl tvAdd [[_node], name _x];
_ctrl tvSetData [[_node,_index], netID _x];
// Preserve the previous selection
if (_curSelData == (_ctrl tvData [_node,_index])) then {
_ctrl tvSetCurSel [_node,_index];
};
_ctrl tvSort [[_node],false];
}; };
_index = _ctrl tvCount [_node];
_ctrl tvAdd [[_node], name _x];
_ctrl tvSetData [[_node,_index], netID _x];
// Preserve the previous selection
if (_curSelData == (_ctrl tvData [_node,_index])) then {
_ctrl tvSetCurSel [_node,_index];
};
_ctrl tvSort [[_node],false];
} forEach GVAR(unitList); } forEach GVAR(unitList);
// Sort group nodes by side // Sort group nodes by side
_ctrl tvSortByValue [[],false]; _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 { if (_append) then {
_newUnits = _newUnits - GVAR(unitList);
// Append only valid units to the list // Append only valid units to the list
{ {
if ( if (
(_x isKindOf "CAManBase") && (alive _x) &&
{(side _x) in [west,east,resistance,civilian]} && {(_x isKindOf "CAManBase")} &&
{(side _x) in [west,east,resistance,civilian]} && // Side filter
{(isPlayer _x) || GVAR(allowAI)} && // AI restriction {(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? {!(_x getVariable [QGVAR(isSpectator), false])} // Who watches the watchmen?
) then { ) then {
GVAR(unitList) pushBack _x; GVAR(unitList) pushBack _x;
@ -53,3 +52,5 @@ if (_append) then {
// Apply whitelist and blacklist // Apply whitelist and blacklist
GVAR(unitList) append GVAR(unitWhitelist); GVAR(unitList) append GVAR(unitWhitelist);
GVAR(unitList) = GVAR(unitList) - GVAR(unitBlacklist); GVAR(unitList) = GVAR(unitList) - GVAR(unitBlacklist);
GVAR(unitList) arrayIntersect GVAR(unitList);