From 3b15014099dc47140d0b9c8e925bab0c7a588c8a Mon Sep 17 00:00:00 2001 From: Jo David Date: Mon, 20 Apr 2020 17:45:59 +0200 Subject: [PATCH] Dragging - Add possiblity to rotate a carried object (#7640) * Add possiblity to rotate a carried object * simplify the code by using cba_events_control instead of a custom set variable * le ACE and don't save frames --- addons/dragging/CfgEventHandlers.hpp | 6 --- addons/dragging/XEH_missionDisplayLoad.sqf | 5 --- addons/dragging/XEH_postInit.sqf | 5 ++- addons/dragging/functions/fnc_carryObject.sqf | 2 +- .../functions/fnc_dropObject_carry.sqf | 3 ++ .../functions/fnc_handleScrollWheel.sqf | 44 ++++++++++++------- addons/dragging/stringtable.xml | 18 ++------ .../functions/fnc_showMouseHint.sqf | 2 +- 8 files changed, 40 insertions(+), 45 deletions(-) delete mode 100644 addons/dragging/XEH_missionDisplayLoad.sqf diff --git a/addons/dragging/CfgEventHandlers.hpp b/addons/dragging/CfgEventHandlers.hpp index e72425a68e..233c4bf79d 100644 --- a/addons/dragging/CfgEventHandlers.hpp +++ b/addons/dragging/CfgEventHandlers.hpp @@ -53,9 +53,3 @@ class Extended_Killed_EventHandlers { }; }; }; - -class Extended_DisplayLoad_EventHandlers { - class RscDisplayMission { - ADDON = QUOTE(_this call COMPILE_FILE(XEH_missionDisplayLoad)); - }; -}; diff --git a/addons/dragging/XEH_missionDisplayLoad.sqf b/addons/dragging/XEH_missionDisplayLoad.sqf deleted file mode 100644 index 289d2f067a..0000000000 --- a/addons/dragging/XEH_missionDisplayLoad.sqf +++ /dev/null @@ -1,5 +0,0 @@ -#include "script_component.hpp" - -params ["_display"]; - -_display displayAddEventHandler ["MouseZChanged", {(_this select 1) call FUNC(handleScrollWheel)}]; diff --git a/addons/dragging/XEH_postInit.sqf b/addons/dragging/XEH_postInit.sqf index f2cb60c646..f652162225 100644 --- a/addons/dragging/XEH_postInit.sqf +++ b/addons/dragging/XEH_postInit.sqf @@ -27,13 +27,16 @@ if (isNil "ACE_maxWeightCarry") then { // handle waking up dragged unit and falling unconscious while dragging ["ace_unconscious", {_this call FUNC(handleUnconscious)}] call CBA_fnc_addEventHandler; +// display event handler +["MouseZChanged", {_this select 1 call FUNC(handleScrollWheel)}] call CBA_fnc_addDisplayHandler; + //@todo Captivity? //Add Keybind: ["ACE3 Common", QGVAR(drag), (localize LSTRING(DragKeybind)), { if (!alive ACE_player) exitWith {false}; if !([ACE_player, objNull, ["isNotDragging", "isNotCarrying"]] call EFUNC(common,canInteractWith)) exitWith {false}; - + // If we are drag/carrying something right now then just drop it: if (ACE_player getVariable [QGVAR(isDragging), false]) exitWith { [ACE_player, ACE_player getVariable [QGVAR(draggedObject), objNull]] call FUNC(dropObject); diff --git a/addons/dragging/functions/fnc_carryObject.sqf b/addons/dragging/functions/fnc_carryObject.sqf index f7976079b3..e3f8c2b61e 100644 --- a/addons/dragging/functions/fnc_carryObject.sqf +++ b/addons/dragging/functions/fnc_carryObject.sqf @@ -63,7 +63,7 @@ _unit setVariable [QGVAR(ReleaseActionID), [ if (_target isKindOf "CAManBase") then { [localize LSTRING(Drop), "", ""] call EFUNC(interaction,showMouseHint); } else { - [localize LSTRING(Drop), "", localize LSTRING(LowerRaise)] call EFUNC(interaction,showMouseHint); + [localize LSTRING(Drop), "", localize LSTRING(RaiseLowerRotate)] call EFUNC(interaction,showMouseHint); }; // check everything diff --git a/addons/dragging/functions/fnc_dropObject_carry.sqf b/addons/dragging/functions/fnc_dropObject_carry.sqf index b6507898ca..5235b7e66d 100644 --- a/addons/dragging/functions/fnc_dropObject_carry.sqf +++ b/addons/dragging/functions/fnc_dropObject_carry.sqf @@ -83,3 +83,6 @@ private _mass = _target getVariable [QGVAR(originalMass), 0]; if (_mass != 0) then { [QEGVAR(common,setMass), [_target, _mass], _target] call CBA_fnc_targetEvent; }; + +// reset temp direction +_target setVariable [QGVAR(carryDirection_temp), nil]; diff --git a/addons/dragging/functions/fnc_handleScrollWheel.sqf b/addons/dragging/functions/fnc_handleScrollWheel.sqf index 9c444add21..04c2542b2f 100644 --- a/addons/dragging/functions/fnc_handleScrollWheel.sqf +++ b/addons/dragging/functions/fnc_handleScrollWheel.sqf @@ -22,30 +22,42 @@ private _unit = ACE_player; // EH is always assigned. Exit and don't overwrite input if not carrying if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith {false}; -// move carried item 15 cm per scroll interval -_scrollAmount = _scrollAmount * 0.15; - private _carriedItem = _unit getVariable [QGVAR(carriedObject), objNull]; //disabled for persons if (_carriedItem isKindOf "CAManBase") exitWith {false}; -private _position = getPosASL _carriedItem; -private _maxHeight = (_unit modelToWorldVisualWorld [0, 0, 0]) select 2; +if !(cba_events_control) then { + // raise/lower -_position set [2, ((_position select 2) + _scrollAmount min (_maxHeight + 1.5)) max _maxHeight]; + // move carried item 15 cm per scroll interval + _scrollAmount = _scrollAmount * 0.15; -// move up/down object and reattach at current position -detach _carriedItem; + private _position = getPosASL _carriedItem; + private _maxHeight = (_unit modelToWorldVisualWorld [0, 0, 0]) select 2; -// Uses this method of selecting position because setPosATL did not have immediate effect -private _positionChange = _position vectorDiff (getPosASL _carriedItem); -private _selectionPosition = _unit worldToModel (ASLtoAGL getPosWorld _carriedItem); -_selectionPosition = _selectionPosition vectorAdd _positionChange; -_carriedItem attachTo [_unit, _selectionPosition]; + _position set [2, ((_position select 2) + _scrollAmount min (_maxHeight + 1.5)) max _maxHeight]; -//reset the carry direction -private _direction = _carriedItem getVariable [QGVAR(carryDirection), 0]; -[QEGVAR(common,setDir), [_carriedItem, _direction], _carriedItem] call CBA_fnc_targetEvent; + // move up/down object and reattach at current position + detach _carriedItem; + + // Uses this method of selecting position because setPosATL did not have immediate effect + private _positionChange = _position vectorDiff (getPosASL _carriedItem); + private _selectionPosition = _unit worldToModel (ASLtoAGL getPosWorld _carriedItem); + _selectionPosition = _selectionPosition vectorAdd _positionChange; + _carriedItem attachTo [_unit, _selectionPosition]; + + //reset the carry direction + private _direction = _carriedItem getVariable [QGVAR(carryDirection_temp), _carriedItem getVariable [QGVAR(carryDirection), 0]]; + [QEGVAR(common,setDir), [_carriedItem, _direction], _carriedItem] call CBA_fnc_targetEvent; +} else { + // rotate + + private _direction = _carriedItem getVariable [QGVAR(carryDirection_temp), _carriedItem getVariable [QGVAR(carryDirection), 0]]; + _scrollAmount = _scrollAmount * 10; + _direction = _direction + _scrollAmount; + [QEGVAR(common,setDir), [_carriedItem, _direction], _carriedItem] call CBA_fnc_targetEvent; + _carriedItem setVariable [QGVAR(carryDirection_temp), _direction]; +}; true diff --git a/addons/dragging/stringtable.xml b/addons/dragging/stringtable.xml index ca9a9d45e5..41f9ac3469 100644 --- a/addons/dragging/stringtable.xml +++ b/addons/dragging/stringtable.xml @@ -86,21 +86,9 @@ 背起 Taşı - - Raise/Lower - Heben/Senken - Wyżej/Niżej - Levantar/Abaixar - Поднять/Опустить - Zvýšit/Snížit - Alza/Abbassa - Subir/Bajar - Lever/Baisser - 上げる/下げる - 높이기/낮추기 - 提高/下降 - 提高/下降 - Yukarı/Aşağı + + Raise/Lower | (Ctrl + Scroll) Rotate + Heben/Senken | (Strg + Scrollen) Drehen diff --git a/addons/interaction/functions/fnc_showMouseHint.sqf b/addons/interaction/functions/fnc_showMouseHint.sqf index b56d053eaa..2c43937a0e 100644 --- a/addons/interaction/functions/fnc_showMouseHint.sqf +++ b/addons/interaction/functions/fnc_showMouseHint.sqf @@ -8,7 +8,7 @@ * 0: Left click text * 1: Right click text * 2: Scroll text (default: "") - * 2: Extra icon/text pairs (default: []) + * 3: Extra icon/text pairs (default: []) * * Return Value: * None