mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Improve handling of unit tree
This commit is contained in:
parent
6cb1813527
commit
27d85180f1
@ -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));
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -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}];
|
||||
|
@ -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,63 +30,39 @@ _curSelData = _ctrl tvData (tvCurSel _ctrl);
|
||||
// Clear the tree
|
||||
tvClear _ctrl;
|
||||
|
||||
// Update the tree
|
||||
// Update the tree from the unit list
|
||||
_cachedGrps = [];
|
||||
{
|
||||
_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 [];
|
||||
// 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
|
||||
if !(_grp in _cachedGrps) then {
|
||||
_side = [west,east,resistance,civilian,sideLogic] find (side _grp);
|
||||
_node = _ctrl tvCount [];
|
||||
|
||||
_ctrl tvAdd [[], groupID _grp];
|
||||
_ctrl tvSetValue [[_node], _side];
|
||||
_ctrl tvAdd [[], groupID _grp];
|
||||
_ctrl tvSetValue [[_node], _side];
|
||||
|
||||
_cachedGrps pushBack _grp;
|
||||
} else {
|
||||
_node = _cachedGrps find _grp;
|
||||
_cachedGrps pushBack _grp;
|
||||
} else {
|
||||
_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);
|
||||
|
||||
// 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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user