From a3b913ad8b2a0167f0a84117262debad16e5a9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Badano?= Date: Thu, 19 Mar 2015 15:04:48 -0300 Subject: [PATCH] Interact menu usability improvements: - Submenu scale as a function of the number of children - Added menu expansion animation to better communicate where the options come from - Unused action point are faded as soon as the user hovers a certain action point --- addons/interact_menu/XEH_preInit.sqf | 1 + addons/interact_menu/functions/fnc_render.sqf | 1 + .../functions/fnc_renderMenu.sqf | 34 ++++++++++++++----- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/addons/interact_menu/XEH_preInit.sqf b/addons/interact_menu/XEH_preInit.sqf index 9d50eb0a1c..2687cf781c 100644 --- a/addons/interact_menu/XEH_preInit.sqf +++ b/addons/interact_menu/XEH_preInit.sqf @@ -41,6 +41,7 @@ GVAR(lastPath) = []; GVAR(expanded) = false; GVAR(startHoverTime) = diag_tickTime; +GVAR(expandedTime) = diag_tickTime; GVAR(iconCtrls) = []; GVAR(iconCount) = 0; diff --git a/addons/interact_menu/functions/fnc_render.sqf b/addons/interact_menu/functions/fnc_render.sqf index bb902e849b..361b7031cc 100644 --- a/addons/interact_menu/functions/fnc_render.sqf +++ b/addons/interact_menu/functions/fnc_render.sqf @@ -166,6 +166,7 @@ if(GVAR(keyDown) || GVAR(keyDownSelfAction)) then { } else { if(!GVAR(expanded) && diag_tickTime-GVAR(startHoverTime) > 0.25) then { GVAR(expanded) = true; + GVAR(expandedTime) = diag_tickTime; GVAR(menuDepthPath) = +GVAR(lastPath); // Execute the current action if it's run on hover diff --git a/addons/interact_menu/functions/fnc_renderMenu.sqf b/addons/interact_menu/functions/fnc_renderMenu.sqf index 459287424c..c5615ce66a 100644 --- a/addons/interact_menu/functions/fnc_renderMenu.sqf +++ b/addons/interact_menu/functions/fnc_renderMenu.sqf @@ -21,7 +21,7 @@ EXPLODE_4_PVT(_this,_parentPath,_action,_pos,_angles); EXPLODE_3_PVT(_action,_actionData,_activeChildren,_actionObject); EXPLODE_2_PVT(_angles,_centerAngle,_maxAngleSpan); -_menuDepth = (count GVAR(menuDepthPath)) - 1; +_menuDepth = (count GVAR(menuDepthPath)); // Store path to action _localPath = _actionData select 7; @@ -44,7 +44,7 @@ _menuInSelectedPath = true; _color = "#FFFFFFFF"; if(!_menuInSelectedPath) then { //_menuDepth > 0 && if (_menuDepth > 0) then { - _color = format ["#%1FFFFFF", [255 * ((((count _path) - 2)/_menuDepth) max 0.25)] call EFUNC(common,toHex)]; + _color = format ["#%1FFFFFF", [255 * ((((count _path) - 1)/_menuDepth) max 0.25)] call EFUNC(common,toHex)]; } else { _color = format ["#%1FFFFFF", [255 * 0.75] call EFUNC(common,toHex)]; }; @@ -57,24 +57,42 @@ GVAR(currentOptions) pushBack [_this, _pos, _path]; // Exit without rendering children if it isn't if !(_menuInSelectedPath) exitWith {true}; -private ["_angleSpan","_angle"]; +private ["_angleSpan","_angle","_angleInterval","_scale"]; _angleSpan = _maxAngleSpan min (55 * ((count _activeChildren) - 1)); if (_angleSpan >= 305) then { _angleSpan = 360; }; +_angleInterval = 55; +if (_angleSpan < 360) then { + if (count _activeChildren > 1) then { + _angleInterval = _angleSpan / (count _activeChildren - 1); + }; +} else { + _angleSpan / (count _activeChildren); +}; +if (count _activeChildren == 1) then { + _angleInterval = 60; +}; + +// Scale menu based on distance +_scale = (0.15 max (0.15 * ((positionCameraToWorld [0, 0, 0]) distance _pos))) / GVAR(selfMenuScale); +// Scale menu based on the amount of children +_scale = _scale * (((0.8 * (0.46 / sin (0.5 * _angleInterval))) min 1.4) max 0.5); +// Animate menu scale +if (_menuInSelectedPath && (_menuDepth == count _path)) then { + _scale = _scale * (0.3 + 0.7 * (((diag_tickTime - GVAR(expandedTime)) * 8) min 1)); +}; _angle = _centerAngle - _angleSpan / 2; { _target = _actionObject; _player = ACE_player; - _mod = (0.15 max (0.15 * ((positionCameraToWorld [0, 0, 0]) distance _pos))) / GVAR(selfMenuScale); - - _offset = ((GVAR(refSystem) select 1) vectorMultiply (-_mod * cos _angle)) vectorAdd - ((GVAR(refSystem) select 2) vectorMultiply (-_mod * sin _angle)); + _offset = ((GVAR(refSystem) select 1) vectorMultiply (-_scale * cos _angle)) vectorAdd + ((GVAR(refSystem) select 2) vectorMultiply (-_scale * sin _angle)); _newPos = ((_pos call EFUNC(common,positionToASL)) vectorAdd _offset) call EFUNC(common,ASLToPosition); - //drawLine3D [_pos, _newPos, [1,0,0,0.5]]; + //drawLine3D [_pos, _newPos, [1,0,0,0.8]]; [_path, _x, _newPos, [_angle, 140]] call FUNC(renderMenu);