ACE3/addons/magazinerepack/functions/fnc_openSelectMagazineUI.sqf

60 lines
2.0 KiB
Plaintext
Raw Normal View History

2015-02-08 22:36:58 +00:00
/*
* Author: PabstMirror (based on repack from commy2, esteldunedain, Ruthberg)
* Opens the selectMenu UI to chose which magazine to repack.
* Only shows classnames that have 2+ partial magazines
*
* Arguments:
* 0: Unit (player) <OBJECT>
*
* Return Value:
* Nothing
*
* Example:
* [_player] call ace_magazinerepack_fnc_openSelectMagazineUI
*
* Public: No
*/
2015-01-16 14:37:32 +00:00
#include "script_component.hpp"
2015-02-08 22:36:58 +00:00
private ["_unitMagazines", "_unitMagCounts", "_xFullMagazineCount", "_index", "_actions", "_displayName", "_picture"];
2015-01-16 14:37:32 +00:00
PARAMS_1(_unit);
2015-01-16 14:37:32 +00:00
_unitMagazines = [];
_unitMagCounts = [];
// get all mags and ammo count
{
2015-02-08 22:36:58 +00:00
EXPLODE_2_PVT(_x,_xClassname,_xCount);
_xFullMagazineCount = getNumber (configfile >> "CfgMagazines" >> _xClassname >> "count");
2015-02-08 22:36:58 +00:00
if ((_xCount != _xFullMagazineCount) && {_xCount > 0}) 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;
2015-01-16 14:37:32 +00:00
_actions = [localize "STR_ACE_MagazineRepack_SelectMagazineMenu", localize "STR_ACE_MagazineRepack_SelectMagazine"] call EFUNC(interaction,prepareSelectMenu);
{
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;
2015-01-16 14:37:32 +00:00
[
_actions,
2015-02-08 22:36:58 +00:00
{ [_this] call FUNC(startRepackingMagazine); },
{
call EFUNC(interaction,hideMenu);
if !(profileNamespace getVariable [QGVAR(AutoCloseMenu), false]) then {"Default" call EFUNC(interaction,openMenuSelf)};
}
2015-01-16 14:37:32 +00:00
] call EFUNC(interaction,openSelectMenu);