diff --git a/addons/dragging/CfgEventHandlers.hpp b/addons/dragging/CfgEventHandlers.hpp index f0a9f14d91..463ae20ddc 100644 --- a/addons/dragging/CfgEventHandlers.hpp +++ b/addons/dragging/CfgEventHandlers.hpp @@ -4,3 +4,17 @@ class Extended_PreInit_EventHandlers { init = QUOTE(call COMPILE_FILE(XEH_preInit)); }; }; + +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; + +class Extended_Init_EventHandlers { + class ThingX { + class ADDON { + init = QUOTE(if (local (_this select 0)) then {_this call DFUNC(initObject)};); + }; + }; +}; diff --git a/addons/dragging/CfgVehicles.hpp b/addons/dragging/CfgVehicles.hpp new file mode 100644 index 0000000000..e20cc9f6e9 --- /dev/null +++ b/addons/dragging/CfgVehicles.hpp @@ -0,0 +1,43 @@ + +class CfgVehicles { + class ThingX; + class ReammoBox_F: ThingX { + GVAR(canDrag) = 0; + GVAR(dragPosition[]) = {0,1,1}; + GVAR(dragDirection) = 0; + }; + + class Slingload_base_F: ReammoBox_F { + GVAR(canDrag) = 0; + }; + + class EAST_Box_Base: ReammoBox_F { + GVAR(canDrag) = 1; + }; + class IND_Box_Base: ReammoBox_F { + GVAR(canDrag) = 1; + }; + /*class FIA_Box_Base_F: ReammoBox_F { + GVAR(canDrag) = 1; + };*/ + class NATO_Box_Base: ReammoBox_F { + GVAR(canDrag) = 1; + }; + + // Remove Larger crate dragging support. + // Would be better to allow some sort of joint push/drag functionality + // Requiring 2 units to access the larger crates and attaching them together (a crappy method of doing it) + // in order to move the bigger ones. Currently simply remove support. + // I believe these crates are currently broken (hitbox doesn't work or something) in 1.22 (2014-07-04) + class Box_East_AmmoVeh_F: EAST_Box_Base { + GVAR(canDrag) = 0; + }; + + class Box_NATO_AmmoVeh_F: NATO_Box_Base { + GVAR(canDrag) = 0; + }; + + class Box_IND_AmmoVeh_F: IND_Box_Base { + GVAR(canDrag) = 0; + }; +}; diff --git a/addons/dragging/XEH_postInit.sqf b/addons/dragging/XEH_postInit.sqf new file mode 100644 index 0000000000..18dff50699 --- /dev/null +++ b/addons/dragging/XEH_postInit.sqf @@ -0,0 +1,11 @@ +// by PabstMirror + +#include "script_component.hpp" + +GVAR(currentHeightChange) = 0; + +[{_this call DFUNC(handleScrollWheel)}] call FUNC(common,addScrollWheelEventHandler); + +if (isNil QGVAR(maxWeight)) then { + GVAR(maxWeight) = 800; +}; diff --git a/addons/dragging/XEH_preInit.sqf b/addons/dragging/XEH_preInit.sqf index 69abb46fa9..3825d1b429 100644 --- a/addons/dragging/XEH_preInit.sqf +++ b/addons/dragging/XEH_preInit.sqf @@ -2,6 +2,7 @@ ADDON = false; -PREP(empty); +PREP(initObject); +PREP(setDraggable); ADDON = true; diff --git a/addons/dragging/config.cpp b/addons/dragging/config.cpp index ce4613ae39..35f9f6d492 100644 --- a/addons/dragging/config.cpp +++ b/addons/dragging/config.cpp @@ -13,3 +13,4 @@ class CfgPatches { }; #include "CfgEventHandlers.hpp" +#include "CfgVehicles.hpp" diff --git a/addons/dragging/functions/fnc_empty.sqf b/addons/dragging/functions/fnc_empty.sqf deleted file mode 100644 index c60a82b2d8..0000000000 --- a/addons/dragging/functions/fnc_empty.sqf +++ /dev/null @@ -1,3 +0,0 @@ -#include "script_component.hpp" - -diag_log text format["This is here as an example!!!"]; diff --git a/addons/dragging/functions/fnc_initObject.sqf b/addons/dragging/functions/fnc_initObject.sqf new file mode 100644 index 0000000000..3d1f51ad21 --- /dev/null +++ b/addons/dragging/functions/fnc_initObject.sqf @@ -0,0 +1,25 @@ +/* + * Author: commy2 + * + * Initialize variables for dragable objects. Called from init EH. + * + * Argument: + * 0: Any object (Object) + * + * Return value: + * NONE. + */ +#include "script_component.hpp" + +private "_object"; + +_object = _this select 0; + +if (getNumber (configFile >> "CfgVehicles" >> typeOf _object >> QGVAR(canDrag)) == 1) then { + private ["_position", "_direction"]; + + _position = getArray (configFile >> "CfgVehicles" >> typeOf _object >> QGVAR(dragPosition)); + _direction = getNumber (configFile >> "CfgVehicles" >> typeOf _object >> QGVAR(dragDirection)); + + [_object, true, _position, _direction] call FUNC(setDraggable); +}; diff --git a/addons/dragging/functions/fnc_setDraggable.sqf b/addons/dragging/functions/fnc_setDraggable.sqf new file mode 100644 index 0000000000..6c068540a6 --- /dev/null +++ b/addons/dragging/functions/fnc_setDraggable.sqf @@ -0,0 +1,55 @@ +/* + * Author: commy2 + * + * Enable the object to be dragged. + * + * Argument: + * 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) + * + * Return value: + * NONE. + */ +#include "script_component.hpp" + +private ["_object", "_enableDrag", "_position", "_direction"]; + +_this resize 4; + +_object = _this select 0; +_enableDrag = _this select 1; +_position = _this select 2; +_direction = _this select 3; + +if (isNil "_position") then { + _position = _object getVariable [QGVAR(dragPosition), [0,0,0]]; +}; + +if (isNil "_direction") then { + _direction = _object getVariable [QGVAR(dragDirection), 0]; +}; + +// update variables +_object setVariable [QGVAR(canDrag), _enableDrag, true]; +_object setVariable [QGVAR(dragPosition), _position, true]; +_object setVariable [QGVAR(dragDirection), _direction, true]; + +// add action to class if it is not already present +private ["_type", "_initializedClasses"]; + +_initializedClasses = GETMVAR(GVAR(initializedClasses),[]); + +// do nothing if the class is already initialized +if (_type in _initializedClasses) exitWith {}; + +private ["_name", "_icon", "_selection", "_statement", "_condition"]; + +_name = "drag"; +_icon = ""; +_selection = ""; +_statement = {hint str _target}; +_condition = {true}; + +[_type, 0, [_name], _name, _icon, _selection, _statement, _condition, 2] call EFUNC(interact_menu,addClassAction);