Make interac_menu work in real 2D:

- Children positions are calculated directly on screen space
- Saves a lot of worldToScreen, ATLtoASL, etc calls
- Selector is now a control instead of a 3D icon
This commit is contained in:
Nicolás Badano
2015-03-23 18:08:31 -03:00
parent 20362e8dc9
commit eb557bf777
36 changed files with 113 additions and 53 deletions

View File

@ -5,7 +5,7 @@
* Argument:
* 0: Parent path <ARRAY>
* 1: Action data <ARRAY>
* 2: 3D position <ARRAY>
* 2: 2D position <ARRAY>
* 3: Angle range available for rendering <ARRAY>
*
* Return value:
@ -17,12 +17,14 @@
private ["_menuInSelectedPath", "_path", "_menuDepth", "_currentRenderDepth", "_x", "_offset", "_newPos", "_forEachIndex"];
EXPLODE_4_PVT(_this,_parentPath,_action,_pos,_angles);
EXPLODE_4_PVT(_this,_parentPath,_action,_sPos,_angles);
EXPLODE_3_PVT(_action,_actionData,_activeChildren,_actionObject);
EXPLODE_2_PVT(_angles,_centerAngle,_maxAngleSpan);
_menuDepth = (count GVAR(menuDepthPath));
//BEGIN_COUNTER(constructing_paths);
// Store path to action
_path = +_parentPath;
_path pushBack [_actionData select 0,_actionObject];
@ -38,24 +40,39 @@ _menuInSelectedPath = true;
};
} forEach _path;
//END_COUNTER(constructing_paths);
//BEGIN_COUNTER(constructing_colors);
// Render icon
// ARGB Color (First Hex Pair is transparancy)
_color = "#FFFFFFFF";
if(!_menuInSelectedPath) then { //_menuDepth > 0 &&
if(!_menuInSelectedPath) then {
if (_menuDepth > 0) then {
_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)];
};
};
[_actionData select 1, _color, _pos, 1, 1, 0, _actionData select 2, 0.5, 0.025, "TahomaB"] call FUNC(renderIcon);
//END_COUNTER(constructing_colors);
//BEGIN_COUNTER(fnc_renderIcons);
[_actionData select 1, _color, _sPos, 1, 1, 0, _actionData select 2, 0.5, 0.025, "TahomaB"] call FUNC(renderIcon);
//END_COUNTER(fnc_renderIcons);
//BEGIN_COUNTER(currentOptions);
// Add the action to current options
GVAR(currentOptions) pushBack [_this, _pos, _path];
GVAR(currentOptions) pushBack [_this, _sPos, _path];
//END_COUNTER(currentOptions);
// Exit without rendering children if it isn't
if !(_menuInSelectedPath) exitWith {true};
//BEGIN_COUNTER(children);
private ["_numChildren","_angleSpan","_angle","_angleInterval","_scale","_offset"];
_numChildren = count _activeChildren;
_angleSpan = _maxAngleSpan min (55 * ((_numChildren) - 1));
@ -75,6 +92,7 @@ if (_numChildren == 1) then {
};
// Scale menu based on the amount of children
GVAR(menuScale) = 0.15;
_scale = GVAR(menuScale) * (((0.8 * (0.46 / sin (0.5 * _angleInterval))) min 1.4) max 0.5);
// Animate menu scale
if (_menuInSelectedPath && (_menuDepth == count _path)) then {
@ -83,16 +101,17 @@ if (_menuInSelectedPath && (_menuDepth == count _path)) then {
_target = _actionObject;
_player = ACE_player;
//END_COUNTER(children);
_angle = _centerAngle - _angleSpan / 2;
{
//BEGIN_COUNTER(children);
private ["_offset","_newPos"];
_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);
_newPos = [(_sPos select 0) -_scale * cos _angle,
(_sPos select 1) +_scale * (sin _angle) * 4/3];
//drawLine3D [_pos, _newPos, [1,0,0,0.8]];
//END_COUNTER(children);
[_path, _x, _newPos, [_angle, 140]] call FUNC(renderMenu);
_angle = _angle + _angleInterval;