From 20f05d99068320a76b5e8cf53447e71b336e4888 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Thu, 16 Jul 2015 18:31:49 +0100 Subject: [PATCH] Improve unit switching UX --- addons/spectator/UI/interface.hpp | 5 ++- .../functions/fnc_handleInterface.sqf | 32 +++++++------------ addons/spectator/functions/fnc_handleTree.sqf | 8 +++++ 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/addons/spectator/UI/interface.hpp b/addons/spectator/UI/interface.hpp index a53d001e99..83ae94e343 100644 --- a/addons/spectator/UI/interface.hpp +++ b/addons/spectator/UI/interface.hpp @@ -146,9 +146,9 @@ class GVAR(overlay) { class unitTree: RscTree { idc = IDC_TREE; x = safeZoneX; - y = safezoneY + TOOL_H; + y = safezoneY + TOOL_H * 2; w = TOOL_W * 2; - h = safeZoneH - TOOL_H; + h = safeZoneH - TOOL_H * 4; borderSize = 1; colorBorder[] = {1,1,1,1}; colorBackground[] = {0.1,0.1,0.1,0.8}; @@ -161,7 +161,6 @@ class GVAR(overlay) { multiselectEnabled = 0; maxHistoryDelay = 1; onTreeDblClick = QUOTE([ARR_2('onTreeDblClick',_this)] call FUNC(handleInterface)); - onTreeSelChanged = QUOTE([ARR_2('onTreeSelChanged',_this)] call FUNC(handleInterface)); }; class spectatorMap: RscMapControl { idc = IDC_MAP; diff --git a/addons/spectator/functions/fnc_handleInterface.sqf b/addons/spectator/functions/fnc_handleInterface.sqf index b99fe856ec..61e642b96d 100644 --- a/addons/spectator/functions/fnc_handleInterface.sqf +++ b/addons/spectator/functions/fnc_handleInterface.sqf @@ -278,30 +278,20 @@ switch (toLower _mode) do { }; // Tree events case "ontreedblclick": { - if (GVAR(camMode) != 0) then { - private ["_sel","_netID"]; - _sel = _args select 1; + // Update camera view when listbox unit is double clicked on + private ["_sel","_netID"]; + _sel = _args select 1; - // Ensure a unit was selected - if (count _sel == 2) then { - _netID = (_args select 0) tvData _sel; - GVAR(camUnit) = objectFromNetId _netID; - }; - } else { - GVAR(camMode) = 1; - }; - call FUNC(updateView); - }; - case "ontreeselchanged": { - if (GVAR(camMode) == 0) then { - private ["_sel","_netID"]; - _sel = _args select 1; + // Ensure a unit was selected + if (count _sel == 2) then { + _netID = (_args select 0) tvData _sel; + GVAR(camUnit) = objectFromNetId _netID; - // Ensure a unit was selected - if (count _sel == 2) then { - _netID = (_args select 0) tvData _sel; - GVAR(camUnit) = objectFromNetId _netID; + // Only update camera mode when in free cam + if (GVAR(camMode) == 0) then { + GVAR(camMode) = 1; }; + call FUNC(updateView); }; }; }; diff --git a/addons/spectator/functions/fnc_handleTree.sqf b/addons/spectator/functions/fnc_handleTree.sqf index 593b1a5cb1..fce039a7a2 100644 --- a/addons/spectator/functions/fnc_handleTree.sqf +++ b/addons/spectator/functions/fnc_handleTree.sqf @@ -27,6 +27,9 @@ disableSerialization; _display = GETUVAR(GVAR(display),displayNull); _ctrl = _display displayCtrl IDC_TREE; +// Cache current selection +_curSelData = _ctrl tvData (tvCurSel _ctrl); + // Clear the tree _ctrl tvDelete []; @@ -53,6 +56,11 @@ _cachedGrps = []; _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);