ACE3/addons/interact_menu/functions/fnc_renderMenu.sqf

120 lines
3.3 KiB
Plaintext
Raw Normal View History

2015-02-21 20:11:03 +00:00
/*
2015-03-24 04:18:00 +00:00
* Author: NouberNou and esteldunedain
* Render an interaction menu and it's children recursively
2015-02-21 20:11:03 +00:00
*
* Argument:
* 0: Parent path <ARRAY>
2015-02-21 20:11:03 +00:00
* 1: Action data <ARRAY>
* 2: 2D position <ARRAY>
2015-02-21 20:11:03 +00:00
* 3: Angle range available for rendering <ARRAY>
*
* Return value:
* None
2015-02-21 20:11:03 +00:00
*
* Public: No
*/
2015-01-18 18:38:27 +00:00
#include "script_component.hpp"
private ["_menuInSelectedPath", "_path", "_menuDepth", "_currentRenderDepth", "_x", "_offset", "_newPos", "_forEachIndex"];
2015-01-18 18:38:27 +00:00
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];
// Check if the menu is on the selected path
_menuInSelectedPath = true;
{
if (_forEachIndex >= (count GVAR(menuDepthPath))) exitWith {
_menuInSelectedPath = false;
};
if !(_x isEqualTo (GVAR(menuDepthPath) select _forEachIndex)) exitWith {
_menuInSelectedPath = false;
2015-02-19 13:49:36 +00:00
};
} forEach _path;
2015-01-18 18:38:27 +00:00
//END_COUNTER(constructing_paths);
//BEGIN_COUNTER(constructing_colors);
// Render icon
// ARGB Color (First Hex Pair is transparancy)
_color = "#FFFFFFFF";
if(!_menuInSelectedPath) then {
2015-03-01 23:14:27 +00:00
if (_menuDepth > 0) then {
_color = format ["#%1FFFFFF", [255 * ((((count _path) - 1)/_menuDepth) max 0.25)] call EFUNC(common,toHex)];
2015-03-01 23:14:27 +00:00
} else {
_color = format ["#%1FFFFFF", [255 * 0.75] call EFUNC(common,toHex)];
};
};
//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, _sPos, _path];
//END_COUNTER(currentOptions);
// Exit without rendering children if it isn't
if !(_menuInSelectedPath) exitWith {true};
//BEGIN_COUNTER(children);
2015-03-23 17:01:38 +00:00
private ["_numChildren","_angleSpan","_angle","_angleInterval","_scale","_offset"];
_numChildren = count _activeChildren;
_angleSpan = _maxAngleSpan min (55 * ((_numChildren) - 1));
if (_angleSpan >= 305) then {
_angleSpan = 360;
2015-01-18 18:38:27 +00:00
};
_angleInterval = 55;
if (_angleSpan < 360) then {
2015-03-23 17:01:38 +00:00
if (_numChildren > 1) then {
_angleInterval = _angleSpan / (_numChildren - 1);
};
} else {
_angleInterval = _angleSpan / (_numChildren);
};
2015-03-23 17:01:38 +00:00
if (_numChildren == 1) then {
_angleInterval = 55;
};
// Scale menu based on the amount of children
_scale = 0.17;
// Animate menu scale
if (_menuInSelectedPath && (_menuDepth == count _path)) then {
_scale = _scale * (0.3 + 0.7 * (((diag_tickTime - GVAR(expandedTime)) * 8) min 1));
};
2015-03-23 17:01:38 +00:00
_target = _actionObject;
_player = ACE_player;
//END_COUNTER(children);
_angle = _centerAngle - _angleSpan / 2;
{
//BEGIN_COUNTER(children);
2015-03-23 17:01:38 +00:00
private ["_offset","_newPos"];
_newPos = [(_sPos select 0) + _scale * 1.10,
(_sPos select 1) + _scale * 0.30 * 4/3 * (_foreachindex - _numChildren/2 + 0.5)];
//drawLine3D [_pos, _newPos, [1,0,0,0.8]];
//END_COUNTER(children);
[_path, _x, _newPos, [_angle, 150]] call FUNC(renderMenu);
2015-03-23 17:01:38 +00:00
_angle = _angle + _angleInterval;
} forEach _activeChildren;
true