From 9514ea3d2464930c34ab1ac1f89d18650c7910d9 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 5 Apr 2018 14:54:16 -0400 Subject: [PATCH 1/2] Add ability to unload cargo --- .../zeus/functions/fnc_ui_attributeCargo.sqf | 67 +++++++++++++++++-- addons/zeus/stringtable.xml | 3 + addons/zeus/ui/RscAttributes.hpp | 13 +++- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/addons/zeus/functions/fnc_ui_attributeCargo.sqf b/addons/zeus/functions/fnc_ui_attributeCargo.sqf index aa4ed000900..d5fb547af0f 100644 --- a/addons/zeus/functions/fnc_ui_attributeCargo.sqf +++ b/addons/zeus/functions/fnc_ui_attributeCargo.sqf @@ -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: @@ -19,14 +19,15 @@ 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; { @@ -34,3 +35,59 @@ private _listbox = _control controlsGroupCtrl 80086; 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"); + }; + + // Handle selection + private _index = lbCurSel ((ctrlParent _button) displayCtrl 80086); + if (_index == -1) exitWith { + [LSTRING(SelectCargo)] call FUNC(showMessage); + }; + + // Unload selected cargo + private _item = (_vehicle getVariable [QEGVAR(cargo,loaded), []]) 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), "
", " "] call CBA_fnc_replace; + [_message, _itemName, _vehicleName] call FUNC(showMessage); + } else { + private _message = [localize ELSTRING(cargo,UnloadingFailed), "
", " "] 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; diff --git a/addons/zeus/stringtable.xml b/addons/zeus/stringtable.xml index 38696f4038a..dba67f0b16d 100644 --- a/addons/zeus/stringtable.xml +++ b/addons/zeus/stringtable.xml @@ -963,6 +963,9 @@ 货物: 貨物: + + Select cargo to unload + Task Position Position de la tâche diff --git a/addons/zeus/ui/RscAttributes.hpp b/addons/zeus/ui/RscAttributes.hpp index 87ce44e54af..e5a3ce6dbb9 100644 --- a/addons/zeus/ui/RscAttributes.hpp +++ b/addons/zeus/ui/RscAttributes.hpp @@ -10,6 +10,7 @@ class RscActivePicture; class RscMapControl; class RscPicture; class ctrlToolbox; +class RscButton; class RscDisplayAttributes { class Controls { @@ -458,7 +459,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 { @@ -476,7 +477,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}; + }; }; }; From dfd2800ffada0f790e4847825350caba964f59cd Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 31 May 2018 21:16:24 -0500 Subject: [PATCH 2/2] Handle array index being out of bounds --- addons/zeus/functions/fnc_ui_attributeCargo.sqf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/zeus/functions/fnc_ui_attributeCargo.sqf b/addons/zeus/functions/fnc_ui_attributeCargo.sqf index d5fb547af0f..e973e0df763 100644 --- a/addons/zeus/functions/fnc_ui_attributeCargo.sqf +++ b/addons/zeus/functions/fnc_ui_attributeCargo.sqf @@ -50,12 +50,13 @@ private _fnc_onButtonUnload = { // Handle selection private _index = lbCurSel ((ctrlParent _button) displayCtrl 80086); - if (_index == -1) exitWith { + private _cargoArray = _vehicle getVariable [QEGVAR(cargo,loaded), []]; + if ((_index < 0) || {_index >= (count _cargoArray)}) exitWith { [LSTRING(SelectCargo)] call FUNC(showMessage); }; // Unload selected cargo - private _item = (_vehicle getVariable [QEGVAR(cargo,loaded), []]) select _index; + 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 {