ACE3/addons/dragging/functions/fnc_setDraggable.sqf

54 lines
1.9 KiB
Plaintext
Raw Normal View History

/*
* Author: commy2
* Enable the object to be dragged.
*
2016-06-18 09:50:41 +00:00
* Arguments:
2016-01-28 18:52:53 +00:00
* 0: Any object <OBJECT>
* 1: true to enable dragging, false to disable <BOOL>
* 2: Position offset for attachTo command (Array, optinal; default: [0,0,0])
* 3: Direction in degree to rotate the object after attachTo (Number, optional; default: 0)
*
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:
* [object, true, [0,0,0], 0] call ace_dragging_fnc_setDraggable;
*
2015-08-09 12:53:13 +00:00
* Public: Yes
*/
#include "script_component.hpp"
2015-05-13 04:01:59 +00:00
//IGNORE_PRIVATE_WARNING("_player", "_target");
2015-08-09 12:53:13 +00:00
params ["_object", "_enableDrag", "_position", "_direction"];
if (isNil "_position") then {
_position = _object getVariable [QGVAR(dragPosition), [0,0,0]];
};
if (isNil "_direction") then {
_direction = _object getVariable [QGVAR(dragDirection), 0];
};
// 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];
// 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,[]);
// do nothing if the class is already initialized
if (_type in _initializedClasses) exitWith {};
2015-03-16 14:41:55 +00:00
_initializedClasses pushBack _type;
GVAR(initializedClasses) = _initializedClasses;
2016-05-07 20:23:38 +00:00
private _icon = [QUOTE(PATHTOF(UI\icons\box_drag.paa)), QUOTE(PATHTOF(UI\icons\person_drag.paa))] select (_object isKindOf "Man");
private _dragAction = [QGVAR(drag), localize LSTRING(Drag), _icon, {[_player, _target] call FUNC(startDrag)}, {[_player, _target] call FUNC(canDrag)}] call EFUNC(interact_menu,createAction);
2016-01-28 18:52:53 +00:00
private _dropAction = [QGVAR(drop), localize LSTRING(Drop), "", {[_player, _target] call FUNC(dropObject)}, {[_player, _target] call FUNC(canDrop)}] call EFUNC(interact_menu,createAction);
[_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);