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

Cargo load menu overhaul #4871

Merged
merged 9 commits into from
May 31, 2017
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: 1 addition & 2 deletions addons/cargo/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

PREP(addCargoItem);
PREP(canLoad);
PREP(addCargoVehiclesActions);
PREP(canLoadItemIn);
PREP(canUnloadItem);
PREP(findNearestVehicle);
PREP(getCargoSpaceLeft);
PREP(getSizeItem);
PREP(handleDestroyed);
Expand Down
44 changes: 44 additions & 0 deletions addons/cargo/functions/fnc_addCargoVehiclesActions.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Author: Dystopian
* Create actions for nearest vehicles with cargo.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Player <OBJECT>
*
* Return Value:
* Children actions <ARRAY>
*
* Example:
* [target, player] call ace_cargo_fnc_addCargoVehiclesActions
*
* Public: No
*/
#include "script_component.hpp"

private _statement = {
params ["_target", "_player", "_params"];
_params params ["_vehicle"];
[_player, _target, _vehicle] call FUNC(startLoadIn);
};

private _actions = [];

{
private _config = configFile >> "CfgVehicles" >> typeOf _x;
if (
1 == getNumber (_config >> QGVAR(hasCargo)) &&
{_x != _target}
) then {
private _name = getText (_config >> "displayName");
private _ownerName = [_x, true] call EFUNC(common,getName);
if ("" != _ownerName) then {
_name = format ["%1 (%2)", _name, _ownerName];
};
private _icon = (getText (_config >> "icon")) call BIS_fnc_textureVehicleIcon;
private _action = [format ["%1", _x], _name, _icon, _statement, {true}, {}, [_x]] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _target];
};
} forEach (nearestObjects [_player, CARGO_VEHICLE_CLASSES, MAX_LOAD_DISTANCE]);

_actions
36 changes: 0 additions & 36 deletions addons/cargo/functions/fnc_canLoad.sqf

This file was deleted.

41 changes: 0 additions & 41 deletions addons/cargo/functions/fnc_findNearestVehicle.sqf

This file was deleted.

9 changes: 6 additions & 3 deletions addons/cargo/functions/fnc_initObject.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ private _condition = {
{(_target getVariable [QGVAR(canLoad), getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(canLoad))]) == 1} &&
{locked _target < 2} &&
{alive _target} &&
{[_player, _target, []] call EFUNC(common,canInteractWith)}
{[_player, _target, []] call EFUNC(common,canInteractWith)} &&
{0 < {
1 == getNumber (configFile >> "CfgVehicles" >> typeOf _x >> QGVAR(hasCargo)) &&
{_x != _target}
} count (nearestObjects [_player, CARGO_VEHICLE_CLASSES, MAX_LOAD_DISTANCE])}
};
private _statement = {
params ["_target", "_player"];
[_player, _target] call FUNC(startLoadIn);
};
private _text = localize LSTRING(loadObject);
private _icon = QPATHTOF(UI\Icon_load.paa);

private _action = [QGVAR(load), _text, _icon, _statement, _condition] call EFUNC(interact_menu,createAction);
private _action = [QGVAR(load), _text, _icon, _statement, _condition, {call FUNC(addCargoVehiclesActions)}] call EFUNC(interact_menu,createAction);
[_type, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToClass);

12 changes: 6 additions & 6 deletions addons/cargo/functions/fnc_startLoadIn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Arguments:
* 0: Player <OBJECT>
* 1: Object <OBJECT>
* 2: Vehicle <OBJECT> (Optional)
*
* Return Value:
* Load ProgressBar Started <BOOL>
Expand All @@ -16,15 +17,14 @@
*/
#include "script_component.hpp"

params ["_player", "_object"];
TRACE_2("params",_player,_object);
params ["_player", "_object", ["_cargoVehicle", objNull]];
TRACE_3("params",_player,_object,_cargoVehicle);

private _vehicle = [_player, _object] call FUNC(findNearestVehicle);

if ((isNull _vehicle) || {_vehicle isKindOf "Cargo_Base_F"}) then {
private _vehicle = _cargoVehicle;
if (isNull _vehicle) then {
{
if ([_object, _x] call FUNC(canLoadItemIn)) exitWith {_vehicle = _x};
} forEach (nearestObjects [_player, ["Cargo_base_F", "Land_PaperBox_closed_F"], MAX_LOAD_DISTANCE]);
} forEach (nearestObjects [_player, CARGO_VEHICLE_CLASSES, MAX_LOAD_DISTANCE]);
};

if (isNull _vehicle) exitWith {
Expand Down
1 change: 1 addition & 0 deletions addons/cargo/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
#include "\z\ace\addons\main\script_macros.hpp"

#define MAX_LOAD_DISTANCE 10
#define CARGO_VEHICLE_CLASSES ["Car", "Air", "Tank", "Ship", "Cargo_base_F", "Land_PaperBox_closed_F"]