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

@ -12,6 +12,8 @@
*/
#include "script_component.hpp"
BEGIN_COUNTER(fnc_render);
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];
@ -97,7 +99,11 @@ if (GVAR(keyDown)) then {
{
_action = _x;
_pos = (((positionCameraToWorld [0, 0, 0]) call EFUNC(common,positionToASL)) vectorAdd GVAR(selfMenuOffset)) call EFUNC(common,ASLToPosition);
_pos = if !(visibleMap) then {
(((positionCameraToWorld [0, 0, 0]) call EFUNC(common,positionToASL)) vectorAdd GVAR(selfMenuOffset)) call EFUNC(common,ASLToPosition)
} else {
[0.5, 0.5]
};
[_target, _action, _pos] call FUNC(renderBaseMenu);
} forEach _classActions;
};
@ -115,14 +121,11 @@ if(GVAR(keyDown) || GVAR(keyDownSelfAction)) then {
_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;
};
_sPos = _x select 1;
_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);
@ -131,15 +134,14 @@ if(GVAR(keyDown) || GVAR(keyDownSelfAction)) then {
_closest = GVAR(currentOptions) select _closestSelection;
_pos = _closest select 1;
_sPos = _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"];
GVAR(rotationAngle) = (GVAR(rotationAngle) + (270*_delta)) mod 360;
[_sPos] call FUNC(renderSelector);
_foundTarget = true;
GVAR(actionSelected) = true;
GVAR(selectedAction) = (_closest select 0) select 1;
@ -207,3 +209,5 @@ for "_i" from GVAR(iconCount) to (count GVAR(iconCtrls))-1 do {
};
GVAR(iconCtrls) resize GVAR(iconCount);
GVAR(iconCount) = 0;
END_COUNTER(fnc_render);