diff --git a/addons/tacticalladder/CfgVehicles.hpp b/addons/tacticalladder/CfgVehicles.hpp index 570838d4ae..334be7928b 100644 --- a/addons/tacticalladder/CfgVehicles.hpp +++ b/addons/tacticalladder/CfgVehicles.hpp @@ -64,7 +64,7 @@ class CfgVehicles { selection = ""; displayName = "$STR_ACE_PICKUP_TACLADDER"; distance = 4; - condition = "true"; + condition = QUOTE((backpack ACE_player) == ''); statement = QUOTE([ARR_2(_target,_player)] call FUNC(pickupTL)); showDisabled = 0; exceptions[] = {}; diff --git a/addons/tacticalladder/XEH_postInit.sqf b/addons/tacticalladder/XEH_postInit.sqf index f994fc6038..0dca81fd64 100644 --- a/addons/tacticalladder/XEH_postInit.sqf +++ b/addons/tacticalladder/XEH_postInit.sqf @@ -1,81 +1,14 @@ #include "script_component.hpp" -GVAR(height) = false; -GVAR(rotate) = false; +GVAR(ladder) = objNull; +GVAR(currentStep) = 3; +GVAR(currentAngle) = 0; -GVAR(key_add) = { - GVAR(handlerid_press) = (findDisplay 46) displayAddEventHandler ["KeyDown", QUOTE(_this call GVAR(keypressed))]; - GVAR(handlerid_release) = (findDisplay 46) displayAddEventHandler ["KeyUp", QUOTE(_this call GVAR(keyreleased))]; -}; -GVAR(key_rem) = { - (findDisplay 46) displayRemoveEventHandler ["KeyDown", GVAR(handlerid_press)]; - (findDisplay 46) displayRemoveEventHandler ["KeyUp", GVAR(handlerid_release)]; -}; +// Cancel tactical ladder deployment if the interact menu is opened +["interactMenuOpened", { + if (!isNull GVAR(ladder)) then { + GVAR(ladder) call FUNC(cancelTLdeploy); + }; +}] call EFUNC(common,addEventHandler); -GVAR(keypressed) = { - 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 -}; +[{(_this select 0) call FUNC(handleScrollWheel);}] call EFUNC(Common,addScrollWheelEventHandler); diff --git a/addons/tacticalladder/XEH_preInit.sqf b/addons/tacticalladder/XEH_preInit.sqf index bcc8df2ffc..e434974c9a 100644 --- a/addons/tacticalladder/XEH_preInit.sqf +++ b/addons/tacticalladder/XEH_preInit.sqf @@ -5,6 +5,7 @@ ADDON = false; PREP(cancelTLdeploy); PREP(confirmTLdeploy); PREP(deployTL); +PREP(handleScrollWheel); PREP(pickupTL); PREP(positionTL); diff --git a/addons/tacticalladder/functions/fnc_cancelTLdeploy.sqf b/addons/tacticalladder/functions/fnc_cancelTLdeploy.sqf index bf7f850e0e..63a97d97e9 100644 --- a/addons/tacticalladder/functions/fnc_cancelTLdeploy.sqf +++ b/addons/tacticalladder/functions/fnc_cancelTLdeploy.sqf @@ -1,16 +1,32 @@ -// #define DEBUG_MODE_FULL +/* + * Author: Rocko, Ruthberg + * Cancel tactical ladder deployment + * + * Arguments: + * 0: ladder + * + * Return Value: + * None + * + * Example: + * [_ladder] call ace_tacticalladder_fnc_cancelTLdeploy; + * + * Public: No + */ #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"] -PARAMS_4(_target,_caller,_index,_ladder); +PARAMS_1(_ladder); -_target removeAction _index; detach _ladder; _ladder animate ["rotate", 0]; { _ladder animate [_x, 0]; } forEach __ANIMS; -_target removeAction (_target getVariable QGVAR(TLdeployAction)); -call FUNC(ladderKey_remove); +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); + +GVAR(ladder) = objNull; diff --git a/addons/tacticalladder/functions/fnc_confirmTLdeploy.sqf b/addons/tacticalladder/functions/fnc_confirmTLdeploy.sqf index 8fd370dfc7..93263c6aa0 100644 --- a/addons/tacticalladder/functions/fnc_confirmTLdeploy.sqf +++ b/addons/tacticalladder/functions/fnc_confirmTLdeploy.sqf @@ -1,14 +1,32 @@ +/* + * Author: Rocko, Ruthberg + * Confirm tactical ladder deployment + * + * Arguments: + * 0: ladder + * + * Return Value: + * Success? + * + * Example: + * [_ladder] call ace_tacticalladder_fnc_confirmTLdeploy; + * + * Public: No + */ #include "script_component.hpp" -PARAMS_4(_target,_caller,_index,_ladder); +PARAMS_1(_ladder); private ["_pos1", "_pos2"]; _pos1 = getPosASL GVAR(ladder); _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; +GVAR(ladder) = objNull; -_target removeAction (_target getVariable QGVAR(TLdropAction)); -call FUNC(ladderKey_remove); +true diff --git a/addons/tacticalladder/functions/fnc_deployTL.sqf b/addons/tacticalladder/functions/fnc_deployTL.sqf index ca84113801..7ad135ca90 100644 --- a/addons/tacticalladder/functions/fnc_deployTL.sqf +++ b/addons/tacticalladder/functions/fnc_deployTL.sqf @@ -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" +if ((backpack ACE_player) != "ACE_TacticalLadder_Pack") exitWith {}; + private ["_pos", "_offset", "_ladder"]; removeBackpack ACE_player; diff --git a/addons/tacticalladder/functions/fnc_handleScrollWheel.sqf b/addons/tacticalladder/functions/fnc_handleScrollWheel.sqf new file mode 100644 index 0000000000..d08cb6e208 --- /dev/null +++ b/addons/tacticalladder/functions/fnc_handleScrollWheel.sqf @@ -0,0 +1,48 @@ +/* + * Author: Rocko, Ruthberg + * Handles lengthening and tilting of the ladder + * + * Arguments: + * Amount scrolled + * + * Return Value: + * Handled + * + * 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 \ No newline at end of file diff --git a/addons/tacticalladder/functions/fnc_pickupTL.sqf b/addons/tacticalladder/functions/fnc_pickupTL.sqf index a09134d18e..c603f1feca 100644 --- a/addons/tacticalladder/functions/fnc_pickupTL.sqf +++ b/addons/tacticalladder/functions/fnc_pickupTL.sqf @@ -1,8 +1,26 @@ -/* ace_sys_sandbag (.pbo) | (c) 2009 by rocko */ - +/* + * Author: Rocko, Ruthberg + * Pick up tactical ladder + * + * Arguments: + * 0: ladder + * 1: unit + * + * Return Value: + * Success? + * + * Example: + * [_ladder, _unit] call ace_tacticalladder_fnc_pickupTL; + * + * Public: No + */ #include "script_component.hpp" +if ((backpack ACE_player) != "") exitWith { false }; + PARAMS_2(_ladder,_unit); deleteVehicle _ladder; _unit addBackpack "ACE_TacticalLadder_Pack"; + +true diff --git a/addons/tacticalladder/functions/fnc_positionTL.sqf b/addons/tacticalladder/functions/fnc_positionTL.sqf index 999d7dc7ac..022b02da0f 100644 --- a/addons/tacticalladder/functions/fnc_positionTL.sqf +++ b/addons/tacticalladder/functions/fnc_positionTL.sqf @@ -1,3 +1,19 @@ +/* + * Author: Rocko, Ruthberg + * Position tactical ladder + * + * Arguments: + * 0: sandbag + * 1: unit + * + * Return Value: + * None + * + * Example: + * [_ladder, _unit] call ace_tacticalladder_fnc_positionTL; + * + * Public: No + */ #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"] @@ -20,10 +36,16 @@ GVAR(ladder) = _ladder; GVAR(currentStep) = 3; 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]; -_action_deploy = _unit addAction [localize "STR_ACE_DEPLOY_TACLADDER", { call FUNC(confirmTLdeploy); }, _ladder]; +ACE_player setVariable [QGVAR(Deploy), + [ACE_player, "DefaultAction", + {!isNull GVAR(ladder)}, + {GVAR(ladder) call FUNC(confirmTLdeploy);} +] call EFUNC(common,AddActionEventHandler)]; -_unit setVariable [QGVAR(TLdeployAction), _action_deploy]; -_unit setVariable [QGVAR(TLdropAction), _action_drop]; +ACE_player setVariable [QGVAR(Cancel), + [ACE_player, "zoomtemp", + {!isNull GVAR(ladder)}, + {GVAR(ladder) call FUNC(cancelTLdeploy);} +] call EFUNC(common,AddActionEventHandler)];