Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dragging - Add parameters for FUNC(setDraggable) & FUNC(setCarryable) to apply globally #10266

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions addons/dragging/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ if (isNil QGVAR(maxWeightCarryRun)) then {
[QGVAR(startCarry), LINKFUNC(startCarryLocal)] call CBA_fnc_addEventHandler;
[QGVAR(startDrag), LINKFUNC(startDragLocal)] call CBA_fnc_addEventHandler;

[QGVAR(setCarryable), LINKFUNC(setCarryable)] call CBA_fnc_addEventHandler;
[QGVAR(setDraggable), LINKFUNC(setDraggable)] call CBA_fnc_addEventHandler;

[QGVAR(carryingContainerClosed), {
params ["_container", "_owner"];
TRACE_2("carryingContainerClosed EH",_container,_owner);
Expand Down
17 changes: 16 additions & 1 deletion addons/dragging/functions/fnc_setCarryable.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* 2: Position offset for attachTo command <ARRAY> (default: [0, 1, 1])
* 3: Direction in degrees to rotate the object after attachTo <NUMBER> (default: 0)
* 4: Override weight limit <BOOL> (default: false)
* 5: Apply globally <BOOL> (default: false)
*
* Return Value:
* None
Expand All @@ -24,7 +25,8 @@ params [
["_enableCarry", false, [false]],
"_position",
"_direction",
["_ignoreWeightCarry", false, [false]]
["_ignoreWeightCarry", false, [false]],
["_global", false, [false]]
];

if (isNull _object) exitWith {};
Expand All @@ -37,6 +39,19 @@ if (!isNil "_direction" && {!(_direction isEqualType 0)}) exitWith {
ERROR_2("setCarryable: Bad direction parameter [%1] for [%2], should be a number or nil",_direction,_object);
};

// Handle global here
if (_global) exitWith {
private _jipID = format [QGVAR(carrying_%1), hashValue _object];
[QGVAR(setCarryable), [_object, _enableCarry, _position, _direction, _ignoreWeightCarry], _jipID] call CBA_fnc_globalEventJIP;

// Remove from JIP queue if object is deleted
if !(_object getVariable [QGVAR(setCarryableRemoveJip), false]) then {
[_jipID, _object] call CBA_fnc_removeGlobalEventJIP;

_object setVariable [QGVAR(setCarryableRemoveJip), true, true];
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved
};
};

if (isNil "_position") then {
_position = _object getVariable [QGVAR(carryPosition), [0, 1, 1]];
};
Expand Down
17 changes: 16 additions & 1 deletion addons/dragging/functions/fnc_setDraggable.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* 2: Position offset for attachTo command <ARRAY> (default: [0, 1.5, 0])
* 3: Direction in degrees to rotate the object after attachTo <NUMBER> (default: 0)
* 4: Override weight limit <BOOL> (default: false)
* 5: Apply globally <BOOL> (default: false)
*
* Return Value:
* None
Expand All @@ -24,7 +25,8 @@ params [
["_enableDrag", false, [false]],
"_position",
"_direction",
["_ignoreWeightDrag", false, [false]]
["_ignoreWeightDrag", false, [false]],
["_global", false, [false]]
];

if (isNull _object) exitWith {};
Expand All @@ -37,6 +39,19 @@ if (!isNil "_direction" && {!(_direction isEqualType 0)}) exitWith {
ERROR_2("setDraggable: Bad direction parameter [%1] for [%2], should be a number or nil",_direction,_object);
};

// Handle global here
if (_global) exitWith {
private _jipID = format [QGVAR(dragging_%1), hashValue _object];
[QGVAR(setDraggable), [_object, _enableDrag, _position, _direction, _ignoreWeightDrag], _jipID] call CBA_fnc_globalEventJIP;

// Remove from JIP queue if object is deleted
if !(_object getVariable [QGVAR(setDraggableRemoveJip), false]) then {
[_jipID, _object] call CBA_fnc_removeGlobalEventJIP;

_object setVariable [QGVAR(setDraggableRemoveJip), true, true];
};
};

if (isNil "_position") then {
_position = _object getVariable [QGVAR(dragPosition), [0, 1.5, 0]];
};
Expand Down
12 changes: 6 additions & 6 deletions addons/interaction/dev/initReplaceTerrainCursorObject.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ DFUNC(replaceTerrainModelsAdd) = {
) then {
// wait while server replaces object, then init dragging on all clients
[{
if (typeOf cursorObject == "") exitwith {};
[cursorObject, {
if !hasInterface exitWith {};
[_this, true] call EFUNC(dragging,setDraggable);
[_this, true] call EFUNC(dragging,setCarryable);
}] remoteExec ["call", 0];
private _object = cursorObject;

if (isNull _object) exitwith {};

[_object, true, nil, nil, nil, true] call EFUNC(dragging,setCarryable);
[_object, true, nil, nil, nil, true] call EFUNC(dragging,setDraggable);
}, [], 1] call CBA_fnc_waitAndExecute;
};
true
Expand Down
4 changes: 3 additions & 1 deletion docs/wiki/framework/dragging-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ You will **not** be able to carry / drag objects that are too heavy, the mass is
| 2 | Position to offset the object from player | Array | Optional (default: `[0, 1.5, 0]`) |
| 3 | Direction in degree to rotate the object | Number | Optional (default: `0`) |
| 4 | Ignore weight limitation for dragging | Boolean | Optional (default: `false`) |
| 5 | Apply changes globally | Boolean | Optional (default: `false`) |
| **R** | None | None | Return value |

#### 2.1.1 Example 1
Expand All @@ -63,7 +64,7 @@ You will **not** be able to carry / drag objects that are too heavy, the mass is
|----| --------- | ----------- |
| 0 | `foo` | My object |
| 1 | `true` | Dragging is enabled |
| 2 | `[0,2,0]` | 0 meters sideways, 2 meters forward, 0 |meters upwards
| 2 | `[0,2,0]` | 0 meters sideways, 2 meters forward, 0 meters upwards |
| 3 | `45` | Rotated by 45° |

#### 2.1.2 Example 2
Expand All @@ -89,6 +90,7 @@ You will **not** be able to carry / drag objects that are too heavy, the mass is
| 2 | Position to offset the object from player | Array | Optional (default: `[0, 1, 1]`) |
| 3 | Direction in degree to rotate the object | Number | Optional (default: `0`) |
| 4 | Ignore weight limitation for carrying | Boolean | Optional (default: `false`) |
| 5 | Apply changes globally | Boolean | Optional (default: `false`) |
| **R** | None | None | Return value |

#### 2.2.1 Example
Expand Down