From 3c2e53c4f76f6ef24ced41956f0396d8ec7aa416 Mon Sep 17 00:00:00 2001 From: JoramD0 Date: Mon, 8 Jun 2020 08:17:50 +0200 Subject: [PATCH 1/3] Inital commit --- addons/armory/Dialog.hpp | 17 ++ addons/armory/XEH_PREP.hpp | 1 + addons/armory/functions/fnc_dialogControl.sqf | 3 +- addons/armory/functions/fnc_importLoadout.sqf | 194 ++++++++++++++++++ addons/armory/script_component.hpp | 3 + addons/armory/stringtable.xml | 3 + 6 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 addons/armory/functions/fnc_importLoadout.sqf diff --git a/addons/armory/Dialog.hpp b/addons/armory/Dialog.hpp index bd5484c3..65d4f7a7 100644 --- a/addons/armory/Dialog.hpp +++ b/addons/armory/Dialog.hpp @@ -400,5 +400,22 @@ class GVAR(Display) { h = H_PART(2); tooltip = CSTRING(BtnExportTooltip); }; + class Import_Pic: GVAR(RscPicture) { + idc = IMPORTPIC; + x = X_PART(30.5); + y = Y_PART(6); + w = W_PART(2); + h = H_PART(2); + text = QPATHTOF(UI\btnImport.paa); + }; + class Import_Btn: GVAR(RscButton) { + idc = IMPORTBTN; + onMouseButtonClick = QUOTE(call FUNC(importLoadout)); + x = X_PART(30.5); + y = Y_PART(6); + w = W_PART(2); + h = H_PART(2); + tooltip = CSTRING(BtnImportTooltip); + }; }; }; diff --git a/addons/armory/XEH_PREP.hpp b/addons/armory/XEH_PREP.hpp index e8abb8af..091b658b 100644 --- a/addons/armory/XEH_PREP.hpp +++ b/addons/armory/XEH_PREP.hpp @@ -15,6 +15,7 @@ PREP(getBaseVariant); PREP(getBoxContents); PREP(getDataVanilla); PREP(getDataChronos); +PREP(importLoadout); PREP(init); PREP(isCompatible); PREP(openArmory); diff --git a/addons/armory/functions/fnc_dialogControl.sqf b/addons/armory/functions/fnc_dialogControl.sqf index 5f6128de..94bfbf09 100644 --- a/addons/armory/functions/fnc_dialogControl.sqf +++ b/addons/armory/functions/fnc_dialogControl.sqf @@ -30,7 +30,8 @@ if (_requestedMenu == "main") exitWith { } forEach [ TITLE, BACKPIC, BACKBTN, - EXPORTPIC, EXPORTBTN + EXPORTPIC, EXPORTBTN, + IMPORTPIC, IMPORTBTN ]; // Set Title diff --git a/addons/armory/functions/fnc_importLoadout.sqf b/addons/armory/functions/fnc_importLoadout.sqf new file mode 100644 index 00000000..a3944c76 --- /dev/null +++ b/addons/armory/functions/fnc_importLoadout.sqf @@ -0,0 +1,194 @@ +#include "..\script_component.hpp" +/* + * Author: JoramD + * Import loadout from clipboard and put those items into a box. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * [] call tac_armory_fnc_importLoadout + * + * Public: No + */ + +private _data = call (compile copyFromClipboard); +private _object = ACE_player getVariable [QGVAR(object), objNull]; + +if (count _data == 10) then { + GVAR(loadoutItems) = []; + for "_index" from 0 to 9 do { + switch (_index) do { + case 0: { + private _rifleElement = _data select _index; + if (count _rifleElement > 0) then { + { + _x params ["_element"]; + + if (typeName _element == "ARRAY") then { + GVAR(loadoutItems) pushBack (_element select 0); + } else { + GVAR(loadoutItems) pushBack _element; + }; + } forEach _rifleElement; + }; + }; + case 1: { + private _launcherElement = _data select _index; + if (count _launcherelement > 0) then { + { + _x params ["_element"]; + + if (typeName _element == "ARRAY") then { + GVAR(loadoutItems) pushBack (_element select 0); + } else { + GVAR(loadoutItems) pushBack _element; + }; + } forEach _launcherelement; + }; + }; + case 2: { + private _pistolElement = _data select _index; + if (count _pistolElement > 0) then { + { + _x params ["_element"]; + + if (typeName _element == "ARRAY") then { + GVAR(loadoutItems) pushBack (_element select 0); + } else { + GVAR(loadoutItems) pushBack _element; + }; + } forEach _pistolElement; + }; + }; + case 3: { + private _uniformElement = _data select _index; + if (count _uniformElement > 0) then { + GVAR(loadoutItems) pushBack (_uniformElement select 0); + private _uniformItemElement = _uniformElement select 1; + { + _x params ["_classname", "_amount"]; + + for _classname from 1 to _amount do { + GVAR(loadoutItems) pushBack _classname; + }; + } forEach _uniformItemElement; + }; + }; + case 4: { + private _vestElement = _data select _index; + if (count _vestElement > 0) then { + GVAR(loadoutItems) pushBack (_vestElement select 0); + private _uniformItemElement = _vestElement select 1; + { + _x params ["_classname", "_amount"]; + + for _classname from 1 to _amount do { + GVAR(loadoutItems) pushBack _classname; + }; + } forEach _uniformItemElement; + }; + }; + case 5: { + private _backpackElement = _data select _index; + if (count _backpackElement > 0) then { + GVAR(loadoutItems) pushBack (_backpackElement select 0); + private _uniformItemElement = _backpackElement select 1; + { + _x params ["_classname", "_amount"]; + + for _classname from 1 to _amount do { + GVAR(loadoutItems) pushBack _classname; + }; + } forEach _uniformItemElement; + }; + }; + case 6: { + GVAR(loadoutItems) pushBack (_data select _index); + }; + case 7: { + GVAR(loadoutItems) pushBack (_data select _index); + }; + case 8: { + private _binocularElement = _data select _index; + if (count _binocularElement > 0) then { + { + _x params ["_element"]; + + if (typeName _element == "ARRAY") then { + GVAR(loadoutItems) pushBack (_element select 0); + } else { + GVAR(loadoutItems) pushBack _element; + }; + } forEach _binocularElement; + }; + }; + case 9: { + private _utilityItemElement = _data select _index; + { + _x params ["_classname"]; + + GVAR(loadoutItems) pushBack _classname; + } forEach _utilityItemElement; + }; + }; + }; +}; + +// Final array of items in the unitLoadout provided (["item","item"]) +GVAR(loadoutItems) = [GVAR(loadoutItems), {_this in [""]}] call CBA_fnc_reject; + +// Sort loadoutItems (["item",amount],["item",amount]) +private _sortedLoadoutItems = []; +{ + _x params ["_item"]; + + private _itemCount = {_item isEqualTo _x} count GVAR(loadoutItems); + _sortedLoadoutItems pushBackUnique [_item, _itemCount]; +} forEach GVAR(loadoutItems); + +diag_log _sortedLoadoutItems; + +// All items currently in locker ([["classname","category","description","amount","?"],["classname","category","description","amount","?"]]) +private _lockerItems = ["all"] call tac_armory_fnc_getDataChronos; + +// Make array to be searched through +private _lockerSearchItems = _lockerItems apply {_x select 0}; + +// Check if items are in locker +private _itemsToExport = []; +private _allItemsAvailable = true; +{ + _x params ["_item", "_amount"]; + + _lockerSearchItems = _lockerSearchItems apply {configName (_x call CBA_fnc_getItemConfig)}; + + if (_item in _lockerSearchItems) then { + // item is in locker! + private _foundItemIndex = _lockerSearchItems find _item; + private _lockerItemAmount = parseNumber ((_lockerItems select _foundItemIndex) select 3); + + if (_lockerItemAmount >= _amount) then { + _itemsToExport pushBack [_item, _amount]; + } else { + format ["Failed to get loadout, not enough of: %1", _item] call CBA_fnc_notify; + _allItemsAvailable = false; + }; + } else { + // item not in locker + format ["Failed to get loadout, missing: %1", _item] call CBA_fnc_notify; + _allItemsAvailable = false; + }; +} forEach _sortedLoadoutItems; + +if (_allItemsAvailable isEqualTo true) then { + { + _x params ["_item", "_amount"]; + + [player, "remove", _object, _item, _item, _amount] call tac_apollo_fnc_lockerAction; + } forEach _itemsToExport; + ["Successfully put loadout in box!"] call CBA_fnc_notify; +}; diff --git a/addons/armory/script_component.hpp b/addons/armory/script_component.hpp index efc77daa..76f50d01 100644 --- a/addons/armory/script_component.hpp +++ b/addons/armory/script_component.hpp @@ -75,6 +75,9 @@ #define EXPORTPIC 3330014 #define EXPORTBTN EXPORTPIC + 1 +// Import +#define IMPORTPIC 3330016 +#define IMPORTBTN IMPORTPIC + 1 // MACROS #define CTRL(var) ((findDisplay DISPLAYID) displayCtrl var) diff --git a/addons/armory/stringtable.xml b/addons/armory/stringtable.xml index 53e11e6b..2e71c2f8 100644 --- a/addons/armory/stringtable.xml +++ b/addons/armory/stringtable.xml @@ -142,5 +142,8 @@ Loadout exported to clipboard! + + Import loadout from clipboard + From 446cb9de91129ad8fbda0779dc1a4702c0980aac Mon Sep 17 00:00:00 2001 From: JoramD0 Date: Mon, 8 Jun 2020 09:15:33 +0200 Subject: [PATCH 2/3] Fixed tabs --- addons/armory/functions/fnc_importLoadout.sqf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/armory/functions/fnc_importLoadout.sqf b/addons/armory/functions/fnc_importLoadout.sqf index a3944c76..6012e680 100644 --- a/addons/armory/functions/fnc_importLoadout.sqf +++ b/addons/armory/functions/fnc_importLoadout.sqf @@ -185,10 +185,10 @@ private _allItemsAvailable = true; } forEach _sortedLoadoutItems; if (_allItemsAvailable isEqualTo true) then { - { - _x params ["_item", "_amount"]; + { + _x params ["_item", "_amount"]; - [player, "remove", _object, _item, _item, _amount] call tac_apollo_fnc_lockerAction; - } forEach _itemsToExport; + [player, "remove", _object, _item, _item, _amount] call tac_apollo_fnc_lockerAction; + } forEach _itemsToExport; ["Successfully put loadout in box!"] call CBA_fnc_notify; }; From af596ce1a235f42b48284239059a04542768c6bf Mon Sep 17 00:00:00 2001 From: JoramD0 Date: Fri, 12 Jun 2020 03:04:50 +0200 Subject: [PATCH 3/3] Added import button and aligned it with export button --- addons/armory/Dialog.hpp | 8 ++++---- addons/armory/UI/btnImport.paa | Bin 0 -> 5625 bytes addons/armory/functions/fnc_importLoadout.sqf | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 addons/armory/UI/btnImport.paa diff --git a/addons/armory/Dialog.hpp b/addons/armory/Dialog.hpp index 65d4f7a7..2803beb5 100644 --- a/addons/armory/Dialog.hpp +++ b/addons/armory/Dialog.hpp @@ -386,7 +386,7 @@ class GVAR(Display) { class Export_Pic: GVAR(RscPicture) { idc = EXPORTPIC; x = X_PART(30.5); - y = Y_PART(3); + y = Y_PART(2); w = W_PART(2); h = H_PART(2); text = QPATHTOF(UI\btnExport.paa); @@ -395,7 +395,7 @@ class GVAR(Display) { idc = EXPORTBTN; onMouseButtonClick = QUOTE(call FUNC(exportLoadout)); x = X_PART(30.5); - y = Y_PART(3); + y = Y_PART(2); w = W_PART(2); h = H_PART(2); tooltip = CSTRING(BtnExportTooltip); @@ -403,7 +403,7 @@ class GVAR(Display) { class Import_Pic: GVAR(RscPicture) { idc = IMPORTPIC; x = X_PART(30.5); - y = Y_PART(6); + y = Y_PART(4); w = W_PART(2); h = H_PART(2); text = QPATHTOF(UI\btnImport.paa); @@ -412,7 +412,7 @@ class GVAR(Display) { idc = IMPORTBTN; onMouseButtonClick = QUOTE(call FUNC(importLoadout)); x = X_PART(30.5); - y = Y_PART(6); + y = Y_PART(4); w = W_PART(2); h = H_PART(2); tooltip = CSTRING(BtnImportTooltip); diff --git a/addons/armory/UI/btnImport.paa b/addons/armory/UI/btnImport.paa new file mode 100644 index 0000000000000000000000000000000000000000..51bd014cf1352e697cdd698388945fb0591fc28c GIT binary patch literal 5625 zcmeHLQB0dv6uuCMV61E6nq|SJ=;|VgW+{U%I9N*>i%n)E*k1@Uaiy8r0<}*w;Q>p= zT%B3yATuE*2A3F#J{YFv&Ifriwk*L)d@yz0q)I0kmH{ouU^Lfr{`UMW%?Om#x(6=( zp&$3&^PTV9^PhYFzf?3eHQFsrZ#0%L#*9Ye5gE5NzKU2tL)_GO+={peF2t`}t*@Ek zdoNsGHDmpI8T&}X*e$qnYi4F<3@oG?64H14yNh?@u`wS4b%4!%G42X;SB(%dmSW5{ zsJ9hEzWhJ9ZyNp4hKQeh&R71P`-i(Kxbp$pH$yu+wu+{8fx6EPUqTZWWW1~|6trld% z?0Gsg>IxGk|8|N`o#u|C+$toGcHw?-4s4Vj{^W5dM-fNJ{ zdb8c$eHClwuwKScHn+rI;rJ;djc;G(s_<|k`IuN5$aXR{H4&y-e&OzerG0s zJBP;zzt6NXhW-HGIHcpZ>1~k>L2$q*mBGV^Vdo+|yEu{vd6W8g!mpYbcSnsKiao=^ zs5a#J1)`IBj9CEkjK`Ro1t8DB^NXP0*Ry^7U-&z}hb5r+S7mLp;Ln-!M!k*rt6spz zAQi*-OVUMY|I1IEJi)KONd5Pg;T^$9&rLZWwh{j~`~B{j)V61D18u9x_~Lx|kdY%k zbknB|rR=3wKYx!YTjkSM{c3y_Si}y-!AI^mAcu*Wn;Rwp!|tBMl9Y}2{Q>=>TKRMU z^NSiLjU5NzgX5c_878>n(C^>;Am28vcIo&8tP!k~`h1|S1#jb(YpU?IEfTdD$LjA@v!8yIu|}gg<_-SYX6=+^V{zF3p6!Xri(N8?Zm6dv T7|#~