ACE3/addons/magazinerepack/functions/fnc_openSelectMagazineUI.sqf
PabstMirror 3f6ffa6ac2 Mag Repack - Keep Progress prototype
Ideas from AGM and CSE
Keeps Progress While Repacking if interrupted
Added sounds from CSE
2015-02-08 13:48:53 -06:00

48 lines
1.8 KiB
Plaintext

// by commy2, esteldunedain
#include "script_component.hpp"
private ["_unit", "_magazines", "_ammos", "_repackTime", "_magazine", "_ammo", "_count", "_index", "_i", "_j", "_ammoToTransfer", "_ammoAvailable", "_ammoNeeded"];
PARAMS_1(_unit);
_unitMagazines = [];
_unitMagCounts = [];
// get all mags and ammo count
{
_xClassname = _x select 0;
_xCount = _x select 1;
_fullMagazineCount = getNumber (configfile >> "CfgMagazines" >> _xClassname >> "count");
if ((_xCount != _fullMagazineCount) && {_xCount > 1}) then {//for every partial magazine
_index = _unitMagazines find _xClassname;
if (_index == -1) then {
_unitMagazines pushBack _xClassname;
_unitMagCounts pushBack [_xCount];
} else {
(_unitMagCounts select _index) pushBack _xCount;
};
};
} forEach magazinesAmmoFull _unit;
_actions = [localize "STR_ACE_MagazineRepack_SelectMagazineMenu", localize "STR_ACE_MagazineRepack_SelectMagazine"] call EFUNC(interaction,prepareSelectMenu);
systemChat format ["%1 - %2", _unitMagazines, _unitMagCounts];
{
if ((count (_unitMagCounts select _forEachIndex)) >= 2) then {// Ignore invalid magazines types (need 2+ partial mags to do anything)
_displayName = getText (configFile >> "CfgMagazines" >> _x >> "displayName");
_picture = getText (configFile >> "CfgMagazines" >> _x >> "picture");
_actions = [_actions, _displayName, _picture, _x] call EFUNC(interaction,addSelectableItem);
};
} forEach _unitMagazines;
[
_actions,
{ [ACE_player, _this] call FUNC(startRepackingMagazine); },
{
call EFUNC(interaction,hideMenu);
if !(profileNamespace getVariable [QGVAR(AutoCloseMenu), false]) then {"Default" call EFUNC(interaction,openMenuSelf)};
}
] call EFUNC(interaction,openSelectMenu);