diff --git a/addons/dragging/XEH_PREP.hpp b/addons/dragging/XEH_PREP.hpp index c359a35678..37b9722e8e 100644 --- a/addons/dragging/XEH_PREP.hpp +++ b/addons/dragging/XEH_PREP.hpp @@ -19,6 +19,10 @@ PREP(handleUnconscious); PREP(initObject); PREP(initPerson); PREP(isObjectOnObject); +PREP(pauseCarry); +PREP(pauseDrag); +PREP(resumeCarry); +PREP(resumeDrag); PREP(setCarryable); PREP(setDraggable); PREP(startCarry); diff --git a/addons/dragging/XEH_postInit.sqf b/addons/dragging/XEH_postInit.sqf index accdd50e4e..32b7d72faa 100644 --- a/addons/dragging/XEH_postInit.sqf +++ b/addons/dragging/XEH_postInit.sqf @@ -81,4 +81,27 @@ if (isNil QGVAR(maxWeightCarryRun)) then { }; }] call CBA_fnc_addEventHandler; +// When changing cameras, drop carried and dragged objects +["featureCamera", { + params ["_unit", "_camera"]; + + // Unit can either drag or carry, functions themselves handle which ones are executed + switch (_camera) do { + // Default camera + case "": { + _unit call FUNC(resumeDrag); + _unit call FUNC(resumeCarry); + }; + // Arsenals make the unit change animations, which makes the unit drop dragged/carried objects regardless + case "arsenal"; + case "ace_arsenal": { + _unit call FUNC(handleKilled); + }; + default { + _unit call FUNC(pauseDrag); + _unit call FUNC(pauseCarry); + }; + }; +}] call CBA_fnc_addPlayerEventHandler; + #include "initKeybinds.sqf" diff --git a/addons/dragging/functions/fnc_carryObjectPFH.sqf b/addons/dragging/functions/fnc_carryObjectPFH.sqf index 6f1d099440..932e30cf71 100644 --- a/addons/dragging/functions/fnc_carryObjectPFH.sqf +++ b/addons/dragging/functions/fnc_carryObjectPFH.sqf @@ -53,6 +53,11 @@ if !(alive _target && {_unit distance _target <= 10} && {_unit getHitPointDamage _idPFH call CBA_fnc_removePerFrameHandler; }; +private _previousHint = _unit getVariable [QGVAR(hint), []]; + +// If paused, don't show mouse button hints +if (_previousHint isEqualType "") exitWith {}; + // Mouse hint private _hintLMB = LLSTRING(Drop); getCursorObjectParams params ["_cursorObject", "", "_distance"]; @@ -81,7 +86,7 @@ if (_target isKindOf "CAManBase") then { private _hint = [_hintLMB, "", _hintMMB]; -if (_hint isNotEqualTo (_unit getVariable [QGVAR(hint), []])) then { +if (_hint isNotEqualTo _previousHint) then { _unit setVariable [QGVAR(hint), _hint]; _hint call EFUNC(interaction,showMouseHint); }; diff --git a/addons/dragging/functions/fnc_dropObject.sqf b/addons/dragging/functions/fnc_dropObject.sqf index c67815fb13..59a3cf9eeb 100644 --- a/addons/dragging/functions/fnc_dropObject.sqf +++ b/addons/dragging/functions/fnc_dropObject.sqf @@ -20,7 +20,10 @@ params ["_unit", "_target"]; TRACE_2("params",_unit,_target); // Remove drop action -[GVAR(releaseActionID), "keydown"] call CBA_fnc_removeKeyHandler; +if (!isNil QGVAR(releaseActionID)) then { + [GVAR(releaseActionID), "keydown"] call CBA_fnc_removeKeyHandler; + GVAR(releaseActionID) = nil; +}; // Stop blocking if !(GVAR(dragAndFire)) then { diff --git a/addons/dragging/functions/fnc_dropObject_carry.sqf b/addons/dragging/functions/fnc_dropObject_carry.sqf index 9a826bc680..b6033ed2b5 100644 --- a/addons/dragging/functions/fnc_dropObject_carry.sqf +++ b/addons/dragging/functions/fnc_dropObject_carry.sqf @@ -22,6 +22,7 @@ TRACE_1("params",_this); // Remove drop action [_unit, "DefaultAction", _unit getVariable [QGVAR(releaseActionID), -1]] call EFUNC(common,removeActionEventHandler); +_unit setVariable [QGVAR(releaseActionID), nil]; private _inBuilding = _unit call FUNC(isObjectOnObject); diff --git a/addons/dragging/functions/fnc_pauseCarry.sqf b/addons/dragging/functions/fnc_pauseCarry.sqf new file mode 100644 index 0000000000..bfe27420f6 --- /dev/null +++ b/addons/dragging/functions/fnc_pauseCarry.sqf @@ -0,0 +1,34 @@ +#include "..\script_component.hpp" +/* + * Author: johnb43 + * Removes user input affecting dragging. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Example: + * player call ace_dragging_fnc_pauseCarry; + * + * Public: No + */ + +params ["_unit"]; + +// If not carrying, don't do anything +if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith {}; + +private _actionID = _unit getVariable QGVAR(releaseActionID); + +// If action has already been removed, don't remove it again +if (isNil "_actionID") exitWith {}; + +// Remove drop action +[_unit, "DefaultAction", _actionID] call EFUNC(common,removeActionEventHandler); +_unit setVariable [QGVAR(releaseActionID), nil]; + +// Hide mouse hint +_unit setVariable [QGVAR(hint), "paused"]; +call EFUNC(interaction,hideMouseHint); diff --git a/addons/dragging/functions/fnc_pauseDrag.sqf b/addons/dragging/functions/fnc_pauseDrag.sqf new file mode 100644 index 0000000000..a06153bf44 --- /dev/null +++ b/addons/dragging/functions/fnc_pauseDrag.sqf @@ -0,0 +1,31 @@ +#include "..\script_component.hpp" +/* + * Author: johnb43 + * Removes user input affecting dragging. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Example: + * player call ace_dragging_fnc_pauseDrag; + * + * Public: No + */ + +params ["_unit"]; + +// If not dragging, don't do anything +if !(_unit getVariable [QGVAR(isDragging), false]) exitWith {}; + +// If action has already been removed, don't remove it again +if (isNil QGVAR(releaseActionID)) exitWith {}; + +// Remove drop action +[GVAR(releaseActionID), "keydown"] call CBA_fnc_removeKeyHandler; +GVAR(releaseActionID) = nil; + +// Hide mouse hint +call EFUNC(interaction,hideMouseHint); diff --git a/addons/dragging/functions/fnc_resumeCarry.sqf b/addons/dragging/functions/fnc_resumeCarry.sqf new file mode 100644 index 0000000000..233d60e298 --- /dev/null +++ b/addons/dragging/functions/fnc_resumeCarry.sqf @@ -0,0 +1,34 @@ +#include "..\script_component.hpp" +/* + * Author: johnb43 + * Adds user input affecting carrying back. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Example: + * player call ace_dragging_fnc_resumeCarry; + * + * Public: No + */ + +params ["_unit"]; + +// If not dragging, don't do anything +if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith {}; + +// If action is already present, don't add it again +if (!isNil {_unit getVariable QGVAR(releaseActionID)}) exitWith {}; + +// Remove drop action +_unit setVariable [QGVAR(releaseActionID), [ + _unit, "DefaultAction", + {!isNull ((_this select 0) getVariable [QGVAR(carriedObject), objNull])}, + {[_this select 0, (_this select 0) getVariable [QGVAR(carriedObject), objNull], true] call FUNC(dropObject_carry)} +] call EFUNC(common,addActionEventHandler)]; + +// Show mouse hint (done in FUNC(carryObjectPFH)) +_unit setVariable [QGVAR(hint), nil]; diff --git a/addons/dragging/functions/fnc_resumeDrag.sqf b/addons/dragging/functions/fnc_resumeDrag.sqf new file mode 100644 index 0000000000..d0fea988fb --- /dev/null +++ b/addons/dragging/functions/fnc_resumeDrag.sqf @@ -0,0 +1,32 @@ +#include "..\script_component.hpp" +/* + * Author: johnb43 + * Adds user input affecting dragging back. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Example: + * player call ace_dragging_fnc_resumeDrag; + * + * Public: No + */ + +params ["_unit"]; + +// If not dragging, don't do anything +if !(_unit getVariable [QGVAR(isDragging), false]) exitWith {}; + +// If action is already present, don't add it again +if (!isNil QGVAR(releaseActionID)) exitWith {}; + +// Add drop action +GVAR(releaseActionID) = [0xF1, [false, false, false], { + [GVAR(unit), GVAR(unit) getVariable [QGVAR(draggedObject), objNull]] call FUNC(dropObject); +}, "keydown", "", false, 0] call CBA_fnc_addKeyHandler; + +// Show mouse hint +["", LLSTRING(Drop)] call EFUNC(interaction,showMouseHint);