2015-02-21 20:11:03 +00:00
|
|
|
/*
|
|
|
|
* Author: NouberNou and CAA-Picard
|
|
|
|
* Render all available nearby interactions
|
|
|
|
*
|
|
|
|
* Argument:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2015-01-18 18:38:27 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
private ["_cursorPos1", "_cursorPos2", "_cursorVec", "_p1", "_p2", "_p", "_v", "_cp", "_forEachIndex", "_renderTargets", "_x", "_cursorScreenPos", "_closestDistance", "_closestSelection", "_pos", "_sPos", "_disSq", "_closest", "_cTime", "_delta", "_foundTarget", "_misMatch", "_hoverPath", "_i"];
|
|
|
|
_foundTarget = false;
|
|
|
|
_cursorPos1 = positionCameraToWorld [0, 0, 0];
|
|
|
|
_cursorPos2 = positionCameraToWorld [0, 0, 2];
|
2015-02-27 04:55:16 +00:00
|
|
|
|
2015-02-28 20:48:46 +00:00
|
|
|
GVAR(selfMenuScale) = (((worldToScreen (positionCameraToWorld [1,0,2])) select 0) -
|
|
|
|
((worldToScreen (positionCameraToWorld [0,0,2])) select 0)) / 0.6;
|
|
|
|
//systemChat format ["selfMenuScale: %1", GVAR(selfMenuScale)];
|
2015-01-18 18:38:27 +00:00
|
|
|
GVAR(currentOptions) = [];
|
2015-02-27 04:55:16 +00:00
|
|
|
|
2015-03-03 02:29:57 +00:00
|
|
|
private ["_actionsVarName","_classActions","_objectActions","_target","_player","_action","_actionData","_active"];
|
2015-02-28 20:48:46 +00:00
|
|
|
_player = ACE_player;
|
2015-02-27 04:55:16 +00:00
|
|
|
if (GVAR(keyDown)) then {
|
|
|
|
|
|
|
|
// Render all nearby interaction menus
|
2015-02-28 20:48:46 +00:00
|
|
|
#define MAXINTERACTOBJECTS 3
|
|
|
|
private ["_numInteractObjects","_numInteractions"];
|
|
|
|
_numInteractObjects = 0;
|
|
|
|
|
2015-02-27 04:55:16 +00:00
|
|
|
_nearestObjects = nearestObjects [(getPos ACE_player), ["All"], 15];
|
|
|
|
{
|
|
|
|
_target = _x;
|
|
|
|
|
2015-02-28 20:48:46 +00:00
|
|
|
_numInteractions = 0;
|
|
|
|
// Prevent interacting with yourself or your own vehicle
|
|
|
|
if (_target != ACE_player && {_target != vehicle ACE_player}) then {
|
|
|
|
|
|
|
|
// Iterate through object actions, find base level actions and render them if appropiate
|
|
|
|
_actionsVarName = format [QGVAR(Act_%1), typeOf _target];
|
|
|
|
GVAR(objectActions) = _target getVariable [QGVAR(actions), []];
|
|
|
|
{
|
2015-03-03 02:29:57 +00:00
|
|
|
_action = _x;
|
2015-02-28 20:48:46 +00:00
|
|
|
// Only render them directly if they are base level actions
|
2015-03-03 02:29:57 +00:00
|
|
|
if (count ((_action select 0) select 7) == 1) then {
|
2015-02-28 20:48:46 +00:00
|
|
|
// Try to render the menu
|
2015-03-03 02:29:57 +00:00
|
|
|
if ([_target, _action] call FUNC(renderBaseMenu)) then {
|
2015-02-28 20:48:46 +00:00
|
|
|
_numInteractions = _numInteractions + 1;
|
|
|
|
};
|
2015-02-27 04:55:16 +00:00
|
|
|
};
|
2015-02-28 20:48:46 +00:00
|
|
|
} forEach GVAR(objectActions);
|
|
|
|
|
|
|
|
// Iterate through base level class actions and render them if appropiate
|
|
|
|
_classActions = missionNamespace getVariable [_actionsVarName, []];
|
|
|
|
{
|
2015-03-03 02:29:57 +00:00
|
|
|
_action = _x;
|
2015-02-28 20:48:46 +00:00
|
|
|
// Try to render the menu
|
2015-03-03 02:29:57 +00:00
|
|
|
if ([_target, _action] call FUNC(renderBaseMenu)) then {
|
2015-02-28 20:48:46 +00:00
|
|
|
_numInteractions = _numInteractions + 1;
|
|
|
|
};
|
|
|
|
} forEach _classActions;
|
2015-02-27 04:55:16 +00:00
|
|
|
|
2015-02-28 20:48:46 +00:00
|
|
|
// Limit the amount of objects the player can interact with
|
|
|
|
if (_numInteractions > 0) then {
|
|
|
|
_numInteractObjects = _numInteractObjects + 1;
|
2015-02-19 13:49:36 +00:00
|
|
|
};
|
2015-02-28 20:48:46 +00:00
|
|
|
};
|
|
|
|
if (_numInteractObjects >= MAXINTERACTOBJECTS) exitWith {};
|
2015-02-27 04:55:16 +00:00
|
|
|
|
|
|
|
} forEach _nearestObjects;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (GVAR(keyDownSelfAction)) then {
|
|
|
|
|
2015-02-19 13:49:36 +00:00
|
|
|
// Render only the self action menu
|
2015-02-27 04:55:16 +00:00
|
|
|
_target = vehicle ACE_player;
|
|
|
|
|
|
|
|
// Iterate through object actions, find base level actions and render them if appropiate
|
|
|
|
_actionsVarName = format [QGVAR(SelfAct_%1), typeOf _target];
|
|
|
|
GVAR(objectActions) = _target getVariable [QGVAR(selfActions), []];
|
2015-02-28 20:48:46 +00:00
|
|
|
/*
|
2015-02-27 04:55:16 +00:00
|
|
|
{
|
2015-03-03 02:29:57 +00:00
|
|
|
_action = _x;
|
2015-02-27 04:55:16 +00:00
|
|
|
// Only render them directly if they are base level actions
|
2015-03-03 02:29:57 +00:00
|
|
|
if (count (_action select 7) == 1) then {
|
|
|
|
[_target, _action, 0, [180, 360]] call FUNC(renderMenu);
|
2015-02-27 04:55:16 +00:00
|
|
|
};
|
|
|
|
} forEach GVAR(objectActions);
|
2015-02-28 20:48:46 +00:00
|
|
|
*/
|
2015-02-27 04:55:16 +00:00
|
|
|
|
|
|
|
// Iterate through base level class actions and render them if appropiate
|
|
|
|
_actionsVarName = format [QGVAR(SelfAct_%1), typeOf _target];
|
|
|
|
_classActions = missionNamespace getVariable [_actionsVarName, []];
|
|
|
|
{
|
2015-03-03 02:29:57 +00:00
|
|
|
_action = _x;
|
2015-02-27 04:55:16 +00:00
|
|
|
|
2015-03-03 04:37:17 +00:00
|
|
|
_pos = (((positionCameraToWorld [0, 0, 0]) call EFUNC(common,positionToASL)) vectorAdd GVAR(selfMenuOffset)) call EFUNC(common,ASLToPosition);
|
2015-03-03 02:29:57 +00:00
|
|
|
[_target, _action, _pos] call FUNC(renderBaseMenu);
|
2015-02-27 04:55:16 +00:00
|
|
|
} forEach _classActions;
|
|
|
|
};
|
2015-01-18 18:38:27 +00:00
|
|
|
};
|
|
|
|
|
2015-02-27 04:55:16 +00:00
|
|
|
|
2015-02-18 21:58:06 +00:00
|
|
|
if(GVAR(keyDown) || GVAR(keyDownSelfAction)) then {
|
2015-02-28 20:48:46 +00:00
|
|
|
// Draw the red selector only when there's no cursor
|
|
|
|
if !(uiNamespace getVariable [QGVAR(cursorMenuOpened),false]) then {
|
|
|
|
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selected_ca.paa", [1,0,0,1], _cursorPos2, 1, 1, 0, "", 0.5, 0.025, "TahomaB"];
|
|
|
|
};
|
|
|
|
|
|
|
|
_cursorScreenPos = [worldToScreen _cursorPos2, GVAR(cursorPos)] select (uiNamespace getVariable [QGVAR(cursorMenuOpened),false]);
|
2015-02-18 21:58:06 +00:00
|
|
|
|
2015-02-19 13:49:36 +00:00
|
|
|
_closestDistance = 1000000;
|
|
|
|
_closestSelection = -1;
|
|
|
|
{
|
|
|
|
_pos = _x select 1;
|
|
|
|
_sPos = worldToScreen _pos;
|
|
|
|
if(count _sPos > 0) then {
|
|
|
|
_disSq = (((_cursorScreenPos select 0) - (_sPos select 0))^2 + ((_cursorScreenPos select 1) - (_sPos select 1))^2);
|
|
|
|
if(_disSq < 0.0125 && _disSq < _closestDistance) then {
|
|
|
|
_closestDistance = _disSq;
|
|
|
|
_closestSelection = _forEachIndex;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} forEach GVAR(currentOptions);
|
2015-02-18 21:58:06 +00:00
|
|
|
|
|
|
|
|
2015-02-27 04:55:16 +00:00
|
|
|
if(_closestSelection == -1) exitWith {};
|
2015-02-18 21:58:06 +00:00
|
|
|
|
2015-02-27 04:55:16 +00:00
|
|
|
_closest = GVAR(currentOptions) select _closestSelection;
|
2015-02-18 21:58:06 +00:00
|
|
|
|
2015-02-27 04:55:16 +00:00
|
|
|
_pos = _closest select 1;
|
|
|
|
_cTime = diag_tickTime;
|
|
|
|
_delta = _cTime - GVAR(lastTime);
|
|
|
|
GVAR(lastTime) = _cTime;
|
|
|
|
GVAR(rotationAngle) = GVAR(rotationAngle) + (180*_delta);
|
|
|
|
if(GVAR(rotationAngle) > 360) then {
|
|
|
|
GVAR(rotationAngle) = GVAR(rotationAngle) - 360;
|
|
|
|
};
|
|
|
|
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,0,.75], _pos, 0.6*SafeZoneW, 0.6*SafeZoneW, GVAR(rotationAngle), "", 0.5, 0.025, "TahomaB"];
|
|
|
|
_foundTarget = true;
|
|
|
|
GVAR(actionSelected) = true;
|
|
|
|
GVAR(selectedTarget) = (_closest select 0) select 0;
|
2015-03-11 03:21:05 +00:00
|
|
|
GVAR(selectedAction) = (_closest select 0) select 1;
|
|
|
|
GVAR(selectedStatement) = ((GVAR(selectedAction)) select 0) select 3;
|
|
|
|
|
2015-02-27 04:55:16 +00:00
|
|
|
_misMatch = false;
|
|
|
|
_hoverPath = (_closest select 2);
|
2015-03-03 02:29:57 +00:00
|
|
|
|
2015-02-27 04:55:16 +00:00
|
|
|
if((count GVAR(lastPath)) != (count _hoverPath)) then {
|
|
|
|
_misMatch = true;
|
|
|
|
} else {
|
|
|
|
{
|
|
|
|
if(_x != (_hoverPath select _forEachIndex)) exitWith {
|
|
|
|
_misMatch = true;
|
2015-02-19 13:49:36 +00:00
|
|
|
};
|
2015-02-27 04:55:16 +00:00
|
|
|
} forEach GVAR(lastPath);
|
|
|
|
};
|
|
|
|
|
|
|
|
if(_misMatch) then {
|
|
|
|
GVAR(lastPath) = _hoverPath;
|
|
|
|
GVAR(startHoverTime) = diag_tickTime;
|
|
|
|
GVAR(expanded) = false;
|
|
|
|
} else {
|
|
|
|
if(!GVAR(expanded) && diag_tickTime-GVAR(startHoverTime) > 0.25) then {
|
|
|
|
GVAR(expanded) = true;
|
|
|
|
GVAR(menuDepthPath) = +GVAR(lastPath);
|
2015-03-11 02:45:46 +00:00
|
|
|
|
2015-03-11 03:39:23 +00:00
|
|
|
// Execute the current action if it's run on hover
|
|
|
|
private "_runOnHover";
|
|
|
|
_runOnHover = ((GVAR(selectedAction) select 0) select 6) select 3;
|
|
|
|
if (_runOnHover) then {
|
2015-03-11 02:45:46 +00:00
|
|
|
this = GVAR(selectedTarget);
|
|
|
|
_player = ACE_Player;
|
|
|
|
_target = GVAR(selectedTarget);
|
|
|
|
[GVAR(selectedTarget), ACE_player] call GVAR(selectedStatement);
|
|
|
|
};
|
2015-02-19 13:49:36 +00:00
|
|
|
};
|
|
|
|
};
|
2015-01-18 18:38:27 +00:00
|
|
|
};
|
2015-02-27 04:55:16 +00:00
|
|
|
|
2015-01-18 18:38:27 +00:00
|
|
|
if(!_foundTarget && GVAR(actionSelected)) then {
|
2015-02-19 13:49:36 +00:00
|
|
|
GVAR(actionSelected) = false;
|
|
|
|
GVAR(expanded) = false;
|
|
|
|
GVAR(lastPath) = [];
|
2015-01-18 18:38:27 +00:00
|
|
|
};
|
|
|
|
for "_i" from GVAR(iconCount) to (count GVAR(iconCtrls))-1 do {
|
2015-02-19 13:49:36 +00:00
|
|
|
ctrlDelete (GVAR(iconCtrls) select _i);
|
2015-01-18 18:38:27 +00:00
|
|
|
};
|
|
|
|
GVAR(iconCtrls) resize GVAR(iconCount);
|
|
|
|
GVAR(iconCount) = 0;
|