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

Armory - loadout import #447

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
21 changes: 19 additions & 2 deletions addons/armory/Dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -395,10 +395,27 @@ 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);
};
class Import_Pic: GVAR(RscPicture) {
idc = IMPORTPIC;
x = X_PART(30.5);
y = Y_PART(4);
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(4);
w = W_PART(2);
h = H_PART(2);
tooltip = CSTRING(BtnImportTooltip);
};
};
};
Binary file added addons/armory/UI/btnImport.paa
Binary file not shown.
1 change: 1 addition & 0 deletions addons/armory/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ PREP(getBaseVariant);
PREP(getBoxContents);
PREP(getDataVanilla);
PREP(getDataChronos);
PREP(importLoadout);
PREP(init);
PREP(isCompatible);
PREP(openArmory);
Expand Down
3 changes: 2 additions & 1 deletion addons/armory/functions/fnc_dialogControl.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ if (_requestedMenu == "main") exitWith {
} forEach [
TITLE,
BACKPIC, BACKBTN,
EXPORTPIC, EXPORTBTN
EXPORTPIC, EXPORTBTN,
IMPORTPIC, IMPORTBTN
];

// Set Title
Expand Down
196 changes: 196 additions & 0 deletions addons/armory/functions/fnc_importLoadout.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
#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;
};
};
};
} else {
["Failed to get loadout, invalid input"] call CBA_fnc_notify;
};

// 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;
};
3 changes: 3 additions & 0 deletions addons/armory/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions addons/armory/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,8 @@
<Key ID="STR_TAC_Armory_ExportComplete">
<English>Loadout exported to clipboard!</English>
</Key>
<Key ID="STR_TAC_Armory_BtnImportTooltip">
<English>Import loadout from clipboard</English>
</Key>
</Package>
</Project>