Magazine Repack - Add inventory context menu action (#7631)

This commit is contained in:
mharis001 2020-04-08 21:52:54 -04:00 committed by GitHub
parent ee3a721429
commit a7260c6974
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 2 deletions

View File

@ -1,4 +1,3 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));
@ -10,3 +9,9 @@ class Extended_PreInit_EventHandlers {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};

View File

@ -1,4 +1,4 @@
PREP(canRepackMagazine);
PREP(getMagazineChildren);
PREP(magazineRepackFinish);
PREP(magazineRepackProgress);

View File

@ -0,0 +1,23 @@
#include "script_component.hpp"
// Inventory context menu action to repack magazines
[
"#Magazine",
["CONTAINER", "MAGAZINE"],
LSTRING(RepackMagazines),
[],
QPATHTOEF(common,UI\repack_ca.paa),
[
{true},
{
params ["_unit", "", "_magazine"];
[_unit, _magazine] call FUNC(canRepackMagazine)
}
],
{
params ["_unit", "", "_magazine"];
[_unit, _unit, _magazine] call FUNC(startRepackingMagazine);
}
] call CBA_fnc_addItemContextMenuOption;

View File

@ -0,0 +1,29 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Checks if the given unit can repack magazines of the given type.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Magazine <STRING>
*
* Return Value:
* Can Repack Magazine <BOOL>
*
* Example:
* [_unit, _magazine] call ace_magazinerepack_fnc_canRepackMagazine
*
* Public: No
*/
params ["_unit", "_magazine"];
private _maxAmmoCount = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count");
{
_x params ["_magazineType", "_ammoCount", "_isLoaded"];
_magazineType == _magazine // Magazine is of given type
&& {_ammoCount > 0 && {_ammoCount < _maxAmmoCount}} // Is a partial magazine
&& {!_isLoaded || {_unit canAdd _magazineType}} // In inventory or can be moved into it
} count magazinesAmmoFull _unit > 1