From 53dc519336af9c59d6611886d794fa850d12bb2c Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Tue, 21 Jul 2015 21:21:46 +0100 Subject: [PATCH] Improved side handling in unit tree --- .../functions/fnc_handleInterface.sqf | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index e9bbd97f40..c45f50a3b1 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -266,7 +266,7 @@ switch (toLower _mode) do { }; case "onunitsupdate": { _args params ["_tree"]; - private ["_curSelData","_cachedGrps","_grp","_sNode","_gNode","_uNode"]; + private ["_curSelData","_cachedGrps","_cachedSides","_grp","_side","_sNode","_gNode","_uNode"]; // Cache current selection _curSelData = _tree tvData (tvCurSel _tree); @@ -274,20 +274,24 @@ switch (toLower _mode) do { // Clear the tree tvClear _tree; - // Add side nodes - { - _tree tvAdd [[], _x]; - _tree tvExpand [_forEachIndex]; - } forEach ["West","East","Resistance","Civilian","Unknown"]; - // Update the tree from the unit list _cachedGrps = []; + _cachedSides = []; { _grp = group _x; + _side = WFSideText side _grp; // Use correct side node - _sNode = [west,east,resistance,civilian] find (side _grp); - if (_sNode == -1) then { _sNode = 4 }; + if !(_side in _cachedSides) then { + // Add side node + _sNode = _tree tvAdd [[], _side]; + + _cachedSides pushBack _side; + _cachedSides pushBack _sNode; + } else { + // If side already processed, use existing node + _sNode = _cachedSides select ((_cachedSides find _side) + 1); + }; // Use correct group node if !(_grp in _cachedGrps) then { @@ -313,7 +317,14 @@ switch (toLower _mode) do { _tree tvExpand [_sNode,_gNode]; } forEach GVAR(unitList); - { _tree tvSort [[_x], false]; } forEach [0,1,2,3,4]; + { + if (typeName _x == "SCALAR") then { + _tree tvSort [[_x],false]; + _tree tvExpand [_x]; + }; + } forEach _cachedSides; + + _tree tvSort [[],false]; }; // Map events case "onmapdblclick": {