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

Zeus - Add ability to unload cargo #6226

Merged
merged 3 commits into from
Jun 1, 2018
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
68 changes: 63 additions & 5 deletions addons/zeus/functions/fnc_ui_attributeCargo.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Author: PabstMirror, mharis001
* Initalises the ace_cargo attribute of the zeus vehicle attributes display
* Initializes the ace_cargo attribute of the zeus vehicle attributes display.
* (the display shown on double click)
*
* Arguments:
Expand All @@ -19,18 +19,76 @@
params ["_control"];
TRACE_1("params",_control);

private _veh = GETMVAR(BIS_fnc_initCuratorAttributes_target,objNull);
TRACE_1("",_veh);
private _vehicle = GETMVAR(BIS_fnc_initCuratorAttributes_target,objNull);
TRACE_1("",_vehicle);

private _loaded = _veh getVariable [QEGVAR(cargo,loaded), []];
private _loaded = _vehicle getVariable [QEGVAR(cargo,loaded), []];
TRACE_1("",_loaded);

_control ctrlRemoveAllEventHandlers "setFocus";
_control ctrlRemoveAllEventHandlers "SetFocus";

// Init cargo list
private _listbox = _control controlsGroupCtrl 80086;

{
private _class = if (_x isEqualType "") then {_x} else {typeOf _x};
private _displayName = getText (configFile >> "CfgVehicles" >> _class >> "displayName");
_listbox lbAdd _displayName;
} forEach _loaded;

// Init unload button
private _button = _control controlsGroupCtrl 80087;

private _fnc_onButtonUnload = {
params ["_button"];

// Validate vehicle
private _vehicle = GETMVAR(BIS_fnc_initCuratorAttributes_target,objNull);
if (isNull _vehicle || {!alive _vehicle}) exitWith {
LOG("Vehicle deleted or killed, cannot unload");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a been a while, but is log a valid macro? I ask because it's an sqf command 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SilentSpike Don't remember
#define true false fun? ^^
The preprocessor doesn't know what SQF is. It just does it's job and hands the result off to others.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 Yeah I remembered, that's why I wasn't sure if we'd actually hijacked that command

Copy link
Contributor

@dedmen dedmen Apr 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh.. uh.. yeah we did :D
Preproc macros are case sensitive though.
And that's the devs fault if he feels like writing SQF commands in caps

};

// Handle selection
private _index = lbCurSel ((ctrlParent _button) displayCtrl 80086);
private _cargoArray = _vehicle getVariable [QEGVAR(cargo,loaded), []];
if ((_index < 0) || {_index >= (count _cargoArray)}) exitWith {
[LSTRING(SelectCargo)] call FUNC(showMessage);
};

// Unload selected cargo
private _item = _cargoArray select _index;
private _class = if (_item isEqualType "") then {_item} else {typeOf _item};
private _itemName = getText (configFile >> "CfgVehicles" >> _class >> "displayName");
if ([_item, _vehicle] call EFUNC(cargo,unloadItem)) then {
private _vehicleName = getText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "displayName");
private _message = [localize ELSTRING(cargo,UnloadedItem), "<br/>", " "] call CBA_fnc_replace;
[_message, _itemName, _vehicleName] call FUNC(showMessage);
} else {
private _message = [localize ELSTRING(cargo,UnloadingFailed), "<br/>", " "] call CBA_fnc_replace;
[_message, _itemName] call FUNC(showMessage);
};
};

_button ctrlAddEventHandler ["ButtonClick", _fnc_onButtonUnload];

// Add PFH to update cargo list
[{
params ["_args", "_pfhID"];
_args params ["_vehicle", "_listbox"];

// Display closed or vehicle deleted
if (isNull _listbox || {isNull _vehicle || {!alive _vehicle}}) exitWith {
[_pfhID] call CBA_fnc_removePerFrameHandler;
LOG("Display closed or vehicle deleted, PFH removed");
};

// Update cargo list
private _loaded = _vehicle getVariable [QEGVAR(cargo,loaded), []];

lbClear _listbox;
{
private _class = if (_x isEqualType "") then {_x} else {typeOf _x};
private _displayName = getText (configFile >> "CfgVehicles" >> _class >> "displayName");
_listbox lbAdd _displayName;
} forEach _loaded;
}, 0.25, [_vehicle, _listbox]] call CBA_fnc_addPerFrameHandler;
5 changes: 4 additions & 1 deletion addons/zeus/stringtable.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project name="ACE">
<Package name="Zeus">
<Key ID="STR_ACE_Zeus_DisplayName">
Expand Down Expand Up @@ -961,6 +961,9 @@
<Chinesesimp>货物:</Chinesesimp>
<Chinese>貨物:</Chinese>
</Key>
<Key ID="STR_ACE_Zeus_SelectCargo">
<English>Select cargo to unload</English>
</Key>
<Key ID="STR_ACE_Zeus_AttributeRadius">
<English>Task Radius</English>
<French>Rayon de la tâche</French>
Expand Down
13 changes: 11 additions & 2 deletions addons/zeus/ui/RscAttributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class RscActivePicture;
class RscMapControl;
class RscPicture;
class ctrlToolbox;
class RscButton;

class RscDisplayAttributes {
class Controls {
Expand Down Expand Up @@ -430,7 +431,7 @@ class GVAR(AttributeCargo): RscControlsGroupNoScrollbars {
x = 0;
y = 0;
w = W_PART(10);
h = H_PART(3);
h = H_PART(2);
colorBackground[] = {0,0,0,0.5};
};
class Background: RscText {
Expand All @@ -448,7 +449,15 @@ class GVAR(AttributeCargo): RscControlsGroupNoScrollbars {
w = W_PART(16);
h = H_PART(3);
};

class Unload: RscButton {
idc = 80087;
text = ECSTRING(cargo,unloadObject);
x = 0;
y = H_PART(2);
w = W_PART(10);
h = H_PART(1);
colorBackground[] = {0, 0, 0, 0.7};
};
};
};

Expand Down