ACE3/addons/interact_menu/functions/fnc_renderBaseMenu.sqf

107 lines
3.3 KiB
Plaintext
Raw Normal View History

#include "..\script_component.hpp"
/*
2015-03-24 04:18:00 +00:00
* Author: NouberNou and esteldunedain
* Render the interaction menu for a base action
*
2016-06-18 09:50:41 +00:00
* Arguments:
* 0: Object <OBJECT>
* 1: Action node <ARRAY>
* 2: 3D position or 2D position <ARRAY> (Optional)
*
2016-06-18 09:50:41 +00:00
* Return Value:
* Was the menu rendered <BOOL>
*
* Example:
* [bob, [node], [0, 0, 0]] call ACE_interact_menu_fnc_renderBaseMenu
*
* Public: No
*/
BEGIN_COUNTER(fnc_renderBaseMenu)
params ["_object", "_baseActionNode"];
_baseActionNode params ["_actionData"];
2016-01-08 04:43:37 +00:00
_actionData params ["_actionName", "", "", "", "", "", "", "_positionCode", "_distance", "_params"];
// Obtain a 3D position for the action
2016-01-08 04:43:37 +00:00
private _pos = if((count _this) > 2) then {
_this select 2
} else {
// Setup scope variables for position code
2016-01-08 04:43:37 +00:00
private _target = _object;
// Get action position
2016-01-08 04:43:37 +00:00
_object modelToWorldVisual (call _positionCode)
};
// For non-self actions, exit if the action is too far away or ocluded
2016-01-08 04:43:37 +00:00
private _distanceToBasePoint = 0; //This will be 0 for self/zeus/in-vehicle (used later to check sub action distance)
if ((GVAR(openedMenuType) == 0) && {isNull (ACE_controlledUAV select 0)} && {vehicle ACE_player == ACE_player} && {isNull curatorCamera} &&
{
2016-01-08 04:43:37 +00:00
private _headPos = ACE_player modelToWorldVisual (ACE_player selectionPosition "pilot");
_distanceToBasePoint = _headPos distance _pos;
2016-01-08 04:43:37 +00:00
if (_distanceToBasePoint > _distance) exitWith {true};
if ((_distanceToBasePoint > 1.2) && {!(_params select 4)}) exitWith {
// If distance to action is greater than 1.2 m and check isn't disabled in params, check LOS
2016-01-08 04:43:37 +00:00
lineIntersects [AGLtoASL _headPos, AGLtoASL _pos, _object, ACE_player]
};
false
}) exitWith {false};
// Exit if the action is behind you
2016-01-08 04:43:37 +00:00
private _sPos = if (count _pos != 2) then {
worldToScreen _pos
} else {
_pos
};
2016-01-08 04:43:37 +00:00
if (_sPos isEqualTo []) exitWith {false};
// Exit if the action is off screen
2016-01-08 04:43:37 +00:00
if ((_sPos select 0) < safeZoneXAbs || {(_sPos select 0) > safeZoneXAbs + safeZoneWAbs}) exitWith {false};
if ((_sPos select 1) < safeZoneY || {(_sPos select 1) > safeZoneY + safeZoneH}) exitWith {false};
BEGIN_COUNTER(fnc_collectActiveActionTree);
// Collect active tree
2016-01-08 04:43:37 +00:00
private _uid = format [QGVAR(ATCache_%1), _actionName];
private _activeActionTree = [
[_object, _baseActionNode, [], _distanceToBasePoint],
DFUNC(collectActiveActionTree),
2016-07-14 18:06:45 +00:00
_object, _uid, 1.0, "ace_interactMenuClosed"
] call EFUNC(common,cachedCall);
END_COUNTER(fnc_collectActiveActionTree);
2016-01-08 04:43:37 +00:00
#ifdef DEBUG_MODE_EXTRA
2015-03-21 01:44:36 +00:00
diag_log "Printing: _activeActionTree";
2016-01-08 04:43:37 +00:00
[0, _activeActionTree] call {
params ["_level", "_node"];
_node params ["_actionData", "_children", "_object"];
2015-03-21 01:44:36 +00:00
diag_log text format ["Level %1 -> %2 on %3", _level, _actionData select 0, _object];
};
2016-01-08 04:43:37 +00:00
#endif
// Check if there's something left for rendering
2016-01-08 04:43:37 +00:00
if (_activeActionTree isEqualTo []) exitWith {false};
BEGIN_COUNTER(fnc_renderMenus);
2015-05-02 17:54:57 +00:00
if (count _pos > 2) then {
_sPos pushBack (((AGLtoASL _pos) vectorDiff GVAR(cameraPosASL)) vectorDotProduct GVAR(cameraDir));
2015-05-02 17:54:57 +00:00
} else {
_sPos pushBack 0;
};
// Add action point for oclusion and rendering
GVAR(collectedActionPoints) pushBack [_sPos select 2, _sPos, _activeActionTree];
END_COUNTER(fnc_renderMenus);
END_COUNTER(fnc_renderBaseMenu);
true