2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-03-14 12:51:23 +00:00
|
|
|
/*
|
2019-01-20 16:23:24 +00:00
|
|
|
* Author: commy2, PiZZADOX
|
2023-07-23 23:07:37 +00:00
|
|
|
* Enables the object to be dragged.
|
2015-03-14 12:51:23 +00:00
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Arguments:
|
2023-07-23 23:07:37 +00:00
|
|
|
* 0: Object <OBJECT>
|
|
|
|
* 1: True to enable dragging, false to disable <BOOL>
|
2021-07-23 14:11:57 +00:00
|
|
|
* 2: Position offset for attachTo command (optional; default: [0, 1.5, 0]) <ARRAY>
|
2023-07-23 23:07:37 +00:00
|
|
|
* 3: Direction in degrees to rotate the object after attachTo (optional; default: 0) <NUMBER>
|
|
|
|
* 4: Override weight limit <BOOL> (default: false)
|
2015-03-14 12:51:23 +00:00
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Return Value:
|
2015-08-09 12:53:13 +00:00
|
|
|
* None
|
|
|
|
*
|
2016-01-28 18:52:53 +00:00
|
|
|
* Example:
|
2023-07-23 23:07:37 +00:00
|
|
|
* [cursorTarget, true, [0, 0, 0], 0, false] call ace_dragging_fnc_setDraggable;
|
2016-01-28 18:52:53 +00:00
|
|
|
*
|
2015-08-09 12:53:13 +00:00
|
|
|
* Public: Yes
|
2015-03-14 12:51:23 +00:00
|
|
|
*/
|
|
|
|
|
2019-01-20 16:23:24 +00:00
|
|
|
params ["_object", "_enableDrag", "_position", "_direction", ["_ignoreWeightDrag", false, [false]]];
|
2015-03-14 12:51:23 +00:00
|
|
|
|
|
|
|
if (isNil "_position") then {
|
2021-07-23 14:11:57 +00:00
|
|
|
_position = _object getVariable [QGVAR(dragPosition), [0, 1.5, 0]];
|
2015-03-14 12:51:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (isNil "_direction") then {
|
|
|
|
_direction = _object getVariable [QGVAR(dragDirection), 0];
|
|
|
|
};
|
|
|
|
|
2023-07-23 23:07:37 +00:00
|
|
|
// Update variables
|
2015-03-16 13:31:16 +00:00
|
|
|
_object setVariable [QGVAR(canDrag), _enableDrag];
|
|
|
|
_object setVariable [QGVAR(dragPosition), _position];
|
|
|
|
_object setVariable [QGVAR(dragDirection), _direction];
|
2019-01-20 16:23:24 +00:00
|
|
|
_object setVariable [QGVAR(ignoreWeightDrag), _ignoreWeightDrag];
|
2015-03-14 12:51:23 +00:00
|
|
|
|
2023-07-23 23:07:37 +00:00
|
|
|
// Add action to class if it is not already present
|
2016-01-28 18:52:53 +00:00
|
|
|
private _type = typeOf _object;
|
|
|
|
private _initializedClasses = GETGVAR(initializedClasses,[]);
|
2015-03-14 12:51:23 +00:00
|
|
|
|
2023-07-23 23:07:37 +00:00
|
|
|
// Do nothing if the class is already initialized
|
2015-03-14 12:51:23 +00:00
|
|
|
if (_type in _initializedClasses) exitWith {};
|
|
|
|
|
2015-03-16 14:41:55 +00:00
|
|
|
_initializedClasses pushBack _type;
|
|
|
|
GVAR(initializedClasses) = _initializedClasses;
|
|
|
|
|
2023-07-22 03:30:40 +00:00
|
|
|
[_type, "ContainerClosed", {
|
|
|
|
params ["_object"];
|
|
|
|
private _owner = _object getVariable [QEGVAR(common,owner), objNull];
|
|
|
|
TRACE_2("ContainerClosed-drag",_object,_owner);
|
|
|
|
if (isNull _owner) exitWith {};
|
|
|
|
if (_object isNotEqualTo (_owner getVariable [QGVAR(draggedObject), objNull])) exitWith {};
|
|
|
|
[QGVAR(draggingContainerClosed), [_object, _owner], _owner] call CBA_fnc_targetEvent;
|
|
|
|
}, false] call CBA_fnc_addClassEventHandler;
|
|
|
|
|
2023-11-21 20:18:19 +00:00
|
|
|
private _icon = [QPATHTOF(UI\icons\box_drag.paa), QPATHTOF(UI\icons\person_drag.paa)] select (_object isKindOf "CAManBase");
|
2016-05-07 20:23:38 +00:00
|
|
|
|
2024-01-13 16:39:39 +00:00
|
|
|
private _dragAction = [
|
|
|
|
QGVAR(drag),
|
|
|
|
LLSTRING(Drag),
|
|
|
|
_icon,
|
|
|
|
{
|
|
|
|
[_player, _target] call FUNC(startDrag)
|
|
|
|
}, {
|
|
|
|
[_player, _target] call FUNC(canDrag)
|
|
|
|
}] call EFUNC(interact_menu,createAction);
|
|
|
|
|
|
|
|
private _dropAction = [
|
|
|
|
QGVAR(drop),
|
|
|
|
LLSTRING(Drop),
|
|
|
|
"",
|
|
|
|
{
|
|
|
|
[_player, _target] call FUNC(dropObject);
|
|
|
|
}, {
|
|
|
|
[_player, _target] call FUNC(canDrop)
|
|
|
|
}] call EFUNC(interact_menu,createAction);
|
2015-03-20 02:33:11 +00:00
|
|
|
|
|
|
|
[_type, 0, ["ACE_MainActions"], _dragAction] call EFUNC(interact_menu,addActionToClass);
|
2015-03-22 15:38:21 +00:00
|
|
|
[_type, 0, [], _dropAction] call EFUNC(interact_menu,addActionToClass);
|