From 2da0eee1e278da6653829e331de7f5321c340fc2 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 16 Mar 2015 20:09:54 +0100 Subject: [PATCH] add drop dragged object action --- addons/dragging/XEH_preInit.sqf | 1 + addons/dragging/functions/fnc_canDrop.sqf | 1 + addons/dragging/functions/fnc_dragObject.sqf | 34 ++++++++++++------- addons/dragging/functions/fnc_dropObject.sqf | 5 ++- .../dragging/functions/fnc_setDraggable.sqf | 9 ++--- 5 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 addons/dragging/functions/fnc_canDrop.sqf diff --git a/addons/dragging/XEH_preInit.sqf b/addons/dragging/XEH_preInit.sqf index 88bd1d3d22..4ed8925e48 100644 --- a/addons/dragging/XEH_preInit.sqf +++ b/addons/dragging/XEH_preInit.sqf @@ -3,6 +3,7 @@ ADDON = false; PREP(canDrag); +PREP(canDrop); PREP(dragObject); PREP(dragObjectPFH); PREP(dropObject); diff --git a/addons/dragging/functions/fnc_canDrop.sqf b/addons/dragging/functions/fnc_canDrop.sqf new file mode 100644 index 0000000000..f32a5804e2 --- /dev/null +++ b/addons/dragging/functions/fnc_canDrop.sqf @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/addons/dragging/functions/fnc_dragObject.sqf b/addons/dragging/functions/fnc_dragObject.sqf index 9120c049b1..75a3c0cb2a 100644 --- a/addons/dragging/functions/fnc_dragObject.sqf +++ b/addons/dragging/functions/fnc_dragObject.sqf @@ -33,19 +33,29 @@ _position = _position vectorAdd [0, 0, _offset]; _target attachTo [_unit, _position]; _target setDir _direction; -// add scrollwheel action to release object -/* - _actionID = _unit getVariable ["AGM_Drag_ReleaseActionID", -1]; - - if (_actionID != -1) then { - _unit removeAction _actionID; - }; - _actionID = _unit addAction [format ["%1", localize "STR_AGM_Drag_EndDrag"], "player call AGM_Drag_fnc_releaseObject;", nil, 20, false, true, "","player call AGM_Drag_fnc_isDraggingObject"]; - - _unit setVariable ["AGM_Drag_ReleaseActionID", _actionID]; -*/ - _unit setVariable [QGVAR(isDragging), true, true]; +_unit setVariable [QGVAR(draggedObject), _target, true]; + +// add scrollwheel action to release object +private "_actionID"; +_actionID = _unit getVariable [QGVAR(ReleaseActionID), -1]; + +if (_actionID != -1) then { + _unit removeAction _actionID; +}; + +_actionID = _unit addAction [ + format ["%1", "STR_AGM_Drag_EndDrag"], + QUOTE([ARR_2(_this select 0, (_this select 0) getVariable [ARR_2(QUOTE(QGVAR(draggedObject)),objNull)])] call FUNC(dropObject)), + nil, + 20, + false, + true, + "", + QUOTE(!isNull (_this getVariable [ARR_2(QUOTE(QGVAR(draggedObject)),objNull)])) +]; + +_unit setVariable [QGVAR(ReleaseActionID), _actionID]; // check everything [FUNC(dragObjectPFH), 0, [_unit, _target]] call CBA_fnc_addPerFrameHandler; diff --git a/addons/dragging/functions/fnc_dropObject.sqf b/addons/dragging/functions/fnc_dropObject.sqf index 77c928513d..35952af48e 100644 --- a/addons/dragging/functions/fnc_dropObject.sqf +++ b/addons/dragging/functions/fnc_dropObject.sqf @@ -18,9 +18,7 @@ _unit = _this select 0; _target = _this select 1; // remove scroll wheel action -/* -_this removeAction (_this getVariable ["AGM_Drag_ReleaseActionID", -1]); -*/ +_unit removeAction (_unit getVariable [QGVAR(ReleaseActionID), -1]); // play release animation _unit playAction "released"; @@ -29,6 +27,7 @@ _unit playAction "released"; detach _target; _unit setVariable [QGVAR(isDragging), false, true]; +_unit setVariable [QGVAR(draggedObject), objNull, true]; // make object accesable for other units [objNull, _target, true] call EFUNC(common,claim); diff --git a/addons/dragging/functions/fnc_setDraggable.sqf b/addons/dragging/functions/fnc_setDraggable.sqf index e63f453d29..38e9438ca0 100644 --- a/addons/dragging/functions/fnc_setDraggable.sqf +++ b/addons/dragging/functions/fnc_setDraggable.sqf @@ -48,10 +48,5 @@ if (_type in _initializedClasses) exitWith {}; _initializedClasses pushBack _type; GVAR(initializedClasses) = _initializedClasses; -private ["_name", "_icon", "_selection", "_statement", "_condition"]; - -_name = "drag"; -_icon = ""; -_selection = ""; - -[_type, 0, ["ACE_MainActions", _name], _name, _icon, _selection, {[_player, _target] call FUNC(startDrag)}, {[_player, _target] call FUNC(canDrag)}, 2] call EFUNC(interact_menu,addClassAction); +[_type, 0, ["ACE_MainActions", QGVAR(drag)], "drg", "", "", {[_player, _target] call FUNC(startDrag)}, {[_player, _target] call FUNC(canDrag)}, 2] call EFUNC(interact_menu,addClassAction); +[_type, 0, ["ACE_MainActions", QGVAR(drop)], "drp", "", "", {[_player, _target] call FUNC(dropObject)}, {[_player, _target] call FUNC(canDrop)}, 2] call EFUNC(interact_menu,addClassAction);