ACE3/addons/arsenal/functions/fnc_removeVirtualItems.sqf
Grim 339cfa8024
Arsenal - Add support for modifying Virtual Items while opened (#9542)
* add support for mod. virt. items while opened

* updateUniqueItems

* execNextFrame

* add notification and TRACE

* remove debug

* Update addons/arsenal/functions/fnc_addVirtualItems.sqf

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

* Update addons/arsenal/functions/fnc_refresh.sqf

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

* move to removeBox

* update english to plural, others are fine

* missing include

* directCall in refresh

---------

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
2023-10-23 13:31:21 -04:00

109 lines
4.3 KiB
Plaintext

#include "..\script_component.hpp"
#include "..\defines.hpp"
/*
* Author: Alganthe, johnb43
* Remove virtual items to the provided target.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Items <ARRAY of STRINGS> <BOOL>
* 2: Remove globally <BOOL> (default: false)
*
* Return Value:
* None
*
* Example:
* [_box, ["item1", "item2", "itemN"]] call ace_arsenal_fnc_removeVirtualItems
* [_box, true, false] call ace_arsenal_fnc_removeVirtualItems
*
* Public: Yes
*/
params [["_object", objNull, [objNull]], ["_items", [], [true, [""]]], ["_global", false, [false]]];
if (isNull _object || {_items isEqualTo []}) exitWith {};
if (_items isEqualType true) then {
if (_items) then {
[_object, _global] call FUNC(removeBox);
};
} else {
private _cargo = _object getVariable QGVAR(virtualItems);
if (isNil "_cargo") exitWith {
[_object, _global] call FUNC(removeBox);
};
// Make sure all items are in string form, then convert to config case (non-existent items return "")
_items = (_items select {_x isEqualType ""}) apply {_x call EFUNC(common,getConfigName)};
// Remove any invalid/non-existing items
_items = _items - [""];
private _configItemsFlat = uiNamespace getVariable QGVAR(configItemsFlat);
// Convert all items to their baseWeapon
_items = _items apply {if (_x in _configItemsFlat) then {_x} else {_x call FUNC(baseWeapon)}};
// Remove items from lists
{
switch (true) do {
// Weapons
case (_x in ((_cargo get IDX_VIRT_WEAPONS) get IDX_VIRT_PRIMARY_WEAPONS)): {
((_cargo get IDX_VIRT_WEAPONS) get IDX_VIRT_PRIMARY_WEAPONS) deleteAt _x;
};
case (_x in ((_cargo get IDX_VIRT_WEAPONS) get IDX_VIRT_HANDGUN_WEAPONS)): {
((_cargo get IDX_VIRT_WEAPONS) get IDX_VIRT_HANDGUN_WEAPONS) deleteAt _x;
};
case (_x in ((_cargo get IDX_VIRT_WEAPONS) get IDX_VIRT_SECONDARY_WEAPONS)): {
((_cargo get IDX_VIRT_WEAPONS) get IDX_VIRT_SECONDARY_WEAPONS) deleteAt _x;
};
// Weapon attachments
case (_x in ((_cargo get IDX_VIRT_ATTACHMENTS) get IDX_VIRT_OPTICS_ATTACHMENTS)): {
((_cargo get IDX_VIRT_ATTACHMENTS) get IDX_VIRT_OPTICS_ATTACHMENTS) deleteAt _x;
};
case (_x in ((_cargo get IDX_VIRT_ATTACHMENTS) get IDX_VIRT_FLASHLIGHT_ATTACHMENTS)): {
((_cargo get IDX_VIRT_ATTACHMENTS) get IDX_VIRT_FLASHLIGHT_ATTACHMENTS) deleteAt _x;
};
case (_x in ((_cargo get IDX_VIRT_ATTACHMENTS) get IDX_VIRT_MUZZLE_ATTACHMENTS)): {
((_cargo get IDX_VIRT_ATTACHMENTS) get IDX_VIRT_MUZZLE_ATTACHMENTS) deleteAt _x;
};
case (_x in ((_cargo get IDX_VIRT_ATTACHMENTS) get IDX_VIRT_BIPOD_ATTACHMENTS)): {
((_cargo get IDX_VIRT_ATTACHMENTS) get IDX_VIRT_BIPOD_ATTACHMENTS) deleteAt _x;
};
// Other
default {
for "_index" from IDX_VIRT_ITEMS_ALL to IDX_VIRT_MISC_ITEMS do {
if (_x in (_cargo get _index)) exitWith {
(_cargo get _index) deleteAt _x;
};
};
};
};
} forEach _items;
private _empty = [
[IDX_VIRT_WEAPONS, createHashMapFromArray [[IDX_VIRT_PRIMARY_WEAPONS, createHashMap], [IDX_VIRT_SECONDARY_WEAPONS, createHashMap], [IDX_VIRT_HANDGUN_WEAPONS, createHashMap]]],
[IDX_VIRT_ATTACHMENTS, createHashMapFromArray [[IDX_VIRT_OPTICS_ATTACHMENTS, createHashMap], [IDX_VIRT_FLASHLIGHT_ATTACHMENTS, createHashMap], [IDX_VIRT_MUZZLE_ATTACHMENTS, createHashMap], [IDX_VIRT_BIPOD_ATTACHMENTS, createHashMap]]]
];
_empty = createHashMapFromArray _empty;
for "_index" from IDX_VIRT_ITEMS_ALL to IDX_VIRT_MISC_ITEMS do {
_empty set [_index, createHashMap];
};
// If nothing is left, remove arsenal from object
if (_cargo isEqualTo _empty) then {
[_object, _global] call FUNC(removeBox);
} else {
_object setVariable [QGVAR(virtualItems), _cargo, _global];
// If the arsenal is already open, refresh arsenal display
if (!isNil QGVAR(currentBox) && {GVAR(currentBox) isEqualTo _object}) then {
[true, true] call FUNC(refresh);
};
};
};