Complete overhaul of the ladder interaction routine

This commit is contained in:
ulteq 2015-06-12 23:54:51 +02:00
parent 9499592322
commit 8336f1d192
9 changed files with 168 additions and 95 deletions

View File

@ -64,7 +64,7 @@ class CfgVehicles {
selection = ""; selection = "";
displayName = "$STR_ACE_PICKUP_TACLADDER"; displayName = "$STR_ACE_PICKUP_TACLADDER";
distance = 4; distance = 4;
condition = "true"; condition = QUOTE((backpack ACE_player) == '');
statement = QUOTE([ARR_2(_target,_player)] call FUNC(pickupTL)); statement = QUOTE([ARR_2(_target,_player)] call FUNC(pickupTL));
showDisabled = 0; showDisabled = 0;
exceptions[] = {}; exceptions[] = {};

View File

@ -1,81 +1,14 @@
#include "script_component.hpp" #include "script_component.hpp"
GVAR(height) = false; GVAR(ladder) = objNull;
GVAR(rotate) = false; GVAR(currentStep) = 3;
GVAR(currentAngle) = 0;
GVAR(key_add) = { // Cancel tactical ladder deployment if the interact menu is opened
GVAR(handlerid_press) = (findDisplay 46) displayAddEventHandler ["KeyDown", QUOTE(_this call GVAR(keypressed))]; ["interactMenuOpened", {
GVAR(handlerid_release) = (findDisplay 46) displayAddEventHandler ["KeyUp", QUOTE(_this call GVAR(keyreleased))]; if (!isNull GVAR(ladder)) then {
}; GVAR(ladder) call FUNC(cancelTLdeploy);
GVAR(key_rem) = { };
(findDisplay 46) displayRemoveEventHandler ["KeyDown", GVAR(handlerid_press)]; }] call EFUNC(common,addEventHandler);
(findDisplay 46) displayRemoveEventHandler ["KeyUp", GVAR(handlerid_release)];
};
GVAR(keypressed) = { [{(_this select 0) call FUNC(handleScrollWheel);}] call EFUNC(Common,addScrollWheelEventHandler);
if (_this select 2) then {
GVAR(height) = true; // SHIFT for setting height
};
if (_this select 3) then {
GVAR(rotate) = true; // ALT for rotating
};
};
GVAR(keyreleased) = {
GVAR(height) = false;
GVAR(rotate) = false;
};
FUNC(ladderKey_add) = {
GVAR(ladder_handlerid_press) = (findDisplay 46) displayAddEventHandler ["KeyDown", QUOTE(_this call FUNC(ladder_interaction))];
};
FUNC(ladderKey_remove) = {
(findDisplay 46) displayRemoveEventHandler ["KeyDown", GVAR(ladder_handlerid_press)];
};
FUNC(ladder_interaction) = {
private "_fnc_collide";
#define __ANIMS ["extract_4","extract_5","extract_6","extract_7","extract_8","extract_9","extract_10","extract_11"]
// Ladder animations start from "extract_4" onwards, because from initial setting, the first three elements extract automatically
_ladder = GVAR(ladder);
_key = _this select 1;
_shift = _this select 2;
_fnc_collide = {
_pos1 = ATLtoASL(GVAR(ladder) modelToWorld (GVAR(ladder) selectionPosition "check2"));
_pos2 = [_pos1 select 0,_pos1 select 1,(_pos1 select 2)+0.4];
lineIntersects [_pos1, _pos2, GVAR(ladder)]
};
if (_key == 18 && {!_shift}) then { // UP
if (call _fnc_collide) exitWith {};
_currentStep = GVAR(currentStep);
_currentStep = _currentStep + 1;
if (_currentStep == 12) exitWith { GVAR(currentStep) = 11; };
if (_ladder animationPhase (format["extract_%1",_currentStep]) == 0) then {
_ladder animate [(format["extract_%1",_currentStep]),1];
GVAR(currentStep) = _currentStep;
};
};
if (_key == 18 && {_shift}) then {
_currentAngle = GVAR(currentAngle);
_currentAngle = _currentAngle + 2.5;
if (_currentAngle > 90) exitWith { GVAR(currentAngle = 90); };
_ladder animate ["rotate",_currentAngle];
GVAR(currentAngle) = _currentAngle;
};
if (_key == 16 && {!_shift}) then { // DOWN // TODO: actionKeyName "leanleft"
_currentStep = GVAR(currentStep);
if (_currentStep == 3) exitWith { GVAR(currentStep) = 3; };
if (_ladder animationPhase (format["extract_%1",_currentStep]) == 1) then {
_ladder animate [(format["extract_%1",_currentStep]),0];
GVAR(currentStep) = _currentStep - 1;
};
};
if (_key == 16 && {_shift}) then {
_currentAngle = GVAR(currentAngle);
_currentAngle = _currentAngle - 2.5;
if (_currentAngle <= 0) then { _currentAngle = 0; };
_ladder animate ["rotate",_currentAngle];
GVAR(currentAngle) = _currentAngle;
};
false
};

View File

@ -5,6 +5,7 @@ ADDON = false;
PREP(cancelTLdeploy); PREP(cancelTLdeploy);
PREP(confirmTLdeploy); PREP(confirmTLdeploy);
PREP(deployTL); PREP(deployTL);
PREP(handleScrollWheel);
PREP(pickupTL); PREP(pickupTL);
PREP(positionTL); PREP(positionTL);

View File

@ -1,16 +1,32 @@
// #define DEBUG_MODE_FULL /*
* Author: Rocko, Ruthberg
* Cancel tactical ladder deployment
*
* Arguments:
* 0: ladder <OBJECT>
*
* Return Value:
* None
*
* Example:
* [_ladder] call ace_tacticalladder_fnc_cancelTLdeploy;
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
#define __ANIMS ["extract_1","extract_2","extract_3","extract_4","extract_5","extract_6","extract_7","extract_8","extract_9","extract_10","extract_11"] #define __ANIMS ["extract_1","extract_2","extract_3","extract_4","extract_5","extract_6","extract_7","extract_8","extract_9","extract_10","extract_11"]
PARAMS_4(_target,_caller,_index,_ladder); PARAMS_1(_ladder);
_target removeAction _index;
detach _ladder; detach _ladder;
_ladder animate ["rotate", 0]; _ladder animate ["rotate", 0];
{ {
_ladder animate [_x, 0]; _ladder animate [_x, 0];
} forEach __ANIMS; } forEach __ANIMS;
_target removeAction (_target getVariable QGVAR(TLdeployAction)); call EFUNC(interaction,hideMouseHint);
call FUNC(ladderKey_remove); [ACE_player, "DefaultAction", ACE_player getVariable [QGVAR(Deploy), -1]] call EFUNC(Common,removeActionEventHandler);
[ACE_player, "zoomtemp", ACE_player getVariable [QGVAR(Cancel), -1]] call EFUNC(Common,removeActionEventHandler);
GVAR(ladder) = objNull;

View File

@ -1,14 +1,32 @@
/*
* Author: Rocko, Ruthberg
* Confirm tactical ladder deployment
*
* Arguments:
* 0: ladder <OBJECT>
*
* Return Value:
* Success?
*
* Example:
* [_ladder] call ace_tacticalladder_fnc_confirmTLdeploy;
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_4(_target,_caller,_index,_ladder); PARAMS_1(_ladder);
private ["_pos1", "_pos2"]; private ["_pos1", "_pos2"];
_pos1 = getPosASL GVAR(ladder); _pos1 = getPosASL GVAR(ladder);
_pos2 = (GVAR(ladder) modelToWorld (GVAR(ladder) selectionPosition "check2")) call EFUNC(common,positionToASL); _pos2 = (GVAR(ladder) modelToWorld (GVAR(ladder) selectionPosition "check2")) call EFUNC(common,positionToASL);
if (lineIntersects [_pos1, _pos2, GVAR(ladder)]) exitWith {}; if (lineIntersects [_pos1, _pos2, GVAR(ladder)]) exitWith { false };
call EFUNC(interaction,hideMouseHint);
[ACE_player, "DefaultAction", ACE_player getVariable [QGVAR(Deploy), -1]] call EFUNC(Common,removeActionEventHandler);
[ACE_player, "zoomtemp", ACE_player getVariable [QGVAR(Cancel), -1]] call EFUNC(Common,removeActionEventHandler);
_target removeAction _index;
detach _ladder; detach _ladder;
GVAR(ladder) = objNull;
_target removeAction (_target getVariable QGVAR(TLdropAction)); true
call FUNC(ladderKey_remove);

View File

@ -1,5 +1,22 @@
/*
* Author: Rocko, Ruthberg
* Deploy tactical ladder
*
* Arguments:
* Nothing
*
* Return Value:
* Nothing
*
* Example:
* call ace_tacticalladder_fnc_deployTL;
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
if ((backpack ACE_player) != "ACE_TacticalLadder_Pack") exitWith {};
private ["_pos", "_offset", "_ladder"]; private ["_pos", "_offset", "_ladder"];
removeBackpack ACE_player; removeBackpack ACE_player;

View File

@ -0,0 +1,48 @@
/*
* Author: Rocko, Ruthberg
* Handles lengthening and tilting of the ladder
*
* Arguments:
* Amount scrolled <NUMBER>
*
* Return Value:
* Handled <BOOL>
*
* Example:
* 1 call ace_tacticalladder_fnc_handleScrollWheel;
*
* Public: No
*/
#include "script_component.hpp"
PARAMS_1(_scroll);
if (isNull GVAR(ladder)) exitWith { false };
if (GETMVAR(ACE_Modifier,0) == 0) then {
private ["_currentStep"];
// Lengthening
if (_scroll > 0) then {
_currentStep = GVAR(currentStep);
if (_currentStep == 11) exitWith {};
_currentStep = _currentStep + 1;
if (GVAR(ladder) animationPhase (format["extract_%1", _currentStep]) == 0) then {
GVAR(ladder) animate [format["extract_%1", _currentStep], 1];
GVAR(currentStep) = _currentStep;
};
};
if (_scroll < 0) then {
_currentStep = GVAR(currentStep);
if (_currentStep == 3) exitWith {};
if (GVAR(ladder) animationPhase (format["extract_%1", _currentStep]) == 1) then {
GVAR(ladder) animate [format["extract_%1", _currentStep], 0];
GVAR(currentStep) = _currentStep - 1;
};
};
} else {
// Tilting
GVAR(currentAngle) = 0 max (GVAR(currentAngle) + _scroll) min 90;
GVAR(ladder) animate ["rotate", GVAR(currentAngle)];
};
true

View File

@ -1,8 +1,26 @@
/* ace_sys_sandbag (.pbo) | (c) 2009 by rocko */ /*
* Author: Rocko, Ruthberg
* Pick up tactical ladder
*
* Arguments:
* 0: ladder <OBJECT>
* 1: unit <OBJECT>
*
* Return Value:
* Success?
*
* Example:
* [_ladder, _unit] call ace_tacticalladder_fnc_pickupTL;
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
if ((backpack ACE_player) != "") exitWith { false };
PARAMS_2(_ladder,_unit); PARAMS_2(_ladder,_unit);
deleteVehicle _ladder; deleteVehicle _ladder;
_unit addBackpack "ACE_TacticalLadder_Pack"; _unit addBackpack "ACE_TacticalLadder_Pack";
true

View File

@ -1,3 +1,19 @@
/*
* Author: Rocko, Ruthberg
* Position tactical ladder
*
* Arguments:
* 0: sandbag <OBJECT>
* 1: unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [_ladder, _unit] call ace_tacticalladder_fnc_positionTL;
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
#define __ANIMS ["extract_1","extract_2","extract_3","extract_4","extract_5","extract_6","extract_7","extract_8","extract_9","extract_10","extract_11"] #define __ANIMS ["extract_1","extract_2","extract_3","extract_4","extract_5","extract_6","extract_7","extract_8","extract_9","extract_10","extract_11"]
@ -20,10 +36,16 @@ GVAR(ladder) = _ladder;
GVAR(currentStep) = 3; GVAR(currentStep) = 3;
GVAR(currentAngle) = 0; GVAR(currentAngle) = 0;
call FUNC(ladderKey_add); ["Confirm", "Cancel", "Adjust"] call EFUNC(interaction,showMouseHint);
_action_drop = _unit addAction [localize "STR_ACE_DROP_TACLADDER", { call FUNC(cancelTLdeploy); }, _ladder]; ACE_player setVariable [QGVAR(Deploy),
_action_deploy = _unit addAction [localize "STR_ACE_DEPLOY_TACLADDER", { call FUNC(confirmTLdeploy); }, _ladder]; [ACE_player, "DefaultAction",
{!isNull GVAR(ladder)},
{GVAR(ladder) call FUNC(confirmTLdeploy);}
] call EFUNC(common,AddActionEventHandler)];
_unit setVariable [QGVAR(TLdeployAction), _action_deploy]; ACE_player setVariable [QGVAR(Cancel),
_unit setVariable [QGVAR(TLdropAction), _action_drop]; [ACE_player, "zoomtemp",
{!isNull GVAR(ladder)},
{GVAR(ladder) call FUNC(cancelTLdeploy);}
] call EFUNC(common,AddActionEventHandler)];