Skip to content

Commit

Permalink
Magazine Repack - Add inventory context menu action (#7631)
Browse files Browse the repository at this point in the history
  • Loading branch information
mharis001 authored Apr 9, 2020
1 parent ee3a721 commit a7260c6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
7 changes: 6 additions & 1 deletion addons/magazinerepack/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));
Expand All @@ -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));
};
};
2 changes: 1 addition & 1 deletion addons/magazinerepack/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

PREP(canRepackMagazine);
PREP(getMagazineChildren);
PREP(magazineRepackFinish);
PREP(magazineRepackProgress);
Expand Down
23 changes: 23 additions & 0 deletions addons/magazinerepack/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -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;
29 changes: 29 additions & 0 deletions addons/magazinerepack/functions/fnc_canRepackMagazine.sqf
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a7260c6

Please sign in to comment.