Skip to content

Commit

Permalink
Merge pull request #744 from CBATeam/cba_miscItems
Browse files Browse the repository at this point in the history
Add CBA_miscItems to virtual arsenal
  • Loading branch information
Killswitch00 committed Sep 12, 2017
2 parents f7fc5e7 + a441348 commit 1fa4f28
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
10 changes: 10 additions & 0 deletions addons/common/CfgWeapons.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CfgWeapons {
class ItemCore;
class InventoryItem_Base_F;
class CBA_MiscItem_ItemInfo: InventoryItem_Base_F {
type = 302; // "bipod"
};
class CBA_MiscItem: ItemCore { // type = 131072;
class ItemInfo: CBA_MiscItem_ItemInfo {};
};
};
2 changes: 2 additions & 0 deletions addons/common/XEH_preClientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ if (hasInterface) then {
GVAR(actionListUpdated) = false; // Set true to force recreation of actions.
GVAR(nextActionIndex) = 0; // Next index that will be given out.
GVAR(actionListPFEH) = false;

call COMPILE_FILE(init_addMiscItemsToArsenal); // Add CBA_MiscItems to VirtualArsenal
};
1 change: 1 addition & 0 deletions addons/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ class CfgPatches {

#include "CfgVehicles.hpp"
#include "CfgLocationTypes.hpp"
#include "CfgWeapons.hpp"
88 changes: 88 additions & 0 deletions addons/common/init_addMiscItemsToArsenal.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Description:
Adds items that inherit from CBA_MiscItem to the arsenal under "Miscellaneous Items" for uniform/vest/backpack.
Much of this code is directly from BIS's fn_arsenal.sqf -> "ListAdd"
Author:
PabstMirror (mostly just modified BIS code)
*/
// #define DEBUG_SYNCHRONOUS
// #define DEBUG_MODE_FULL

#include "script_component.hpp"
#include "\a3\ui_f\hpp\defineResinclDesign.inc"
// IDC_RSCDISPLAYARSENAL_LIST 960
// IDC_RSCDISPLAYARSENAL_TAB_CARGOMISC 24


[missionNamespace, "arsenalOpened", {
// If this code takes too long to finish, we could randomly get kicked out of missionNamespace
// For safety, spawn and then directCall to prevent problems because we are called from fn_arsenal via `with missionNamespace do {`
_this spawn {
[{
params ["_display"];
TRACE_1("arsenalOpened",_display);

// We only need to directly add the items to the display list once per mission as we also modify the data array
if (missionNamespace getVariable [QGVAR(arsenalDataModified), false]) exitWith {
TRACE_1("Already set", bis_fnc_arsenal_data select 24);
};


// Get properly scoped items that inherit from CBA_MiscItem
private _cbaMiscItems = [];
{
private _class = _x;
private _scope = if (isnumber (_class >> "scopeArsenal")) then {getnumber (_class >> "scopeArsenal")} else {getnumber (_class >> "scope")};
TRACE_2("",_class,_scope);
if (_scope == 2 && {gettext (_class >> "model") != ""}) then {
_cbaMiscItems pushBack (configName _class);
};
} forEach (configProperties [configFile >> "CfgWeapons", "(isClass _x) && {(configName _x) isKindOf ['CBA_MiscItem', configFile >> 'CfgWeapons']}"]);
TRACE_2("Items to add",count _cbaMiscItems,_cbaMiscItems);


// BIS code to determine which items should be shown in the list (all items will still be added to the data array)
private _fullVersion = missionNamespace getVariable ["BIS_fnc_arsenal_fullArsenal",false];
private _center = (missionNamespace getVariable ["BIS_fnc_arsenal_center",player]);
private _cargo = (missionNamespace getVariable ["BIS_fnc_arsenal_cargo",objNull]);

private _virtualItemCargo =
(missionNamespace call bis_fnc_getVirtualItemCargo) +
(_cargo call bis_fnc_getVirtualItemCargo) +
items _center +
assigneditems _center +
primaryweaponitems _center +
secondaryweaponitems _center +
handgunitems _center +
[uniform _center,vest _center,headgear _center,goggles _center];

private _ctrlList = _display displayctrl (IDC_RSCDISPLAYARSENAL_LIST + IDC_RSCDISPLAYARSENAL_TAB_CARGOMISC);
private _virtualCargo = _virtualItemCargo;
private _virtualAll = _fullVersion || {"%ALL" in _virtualCargo};
private _columns = count lnbGetColumnsPosition _ctrlList;
TRACE_2("",_virtualAll,_virtualCargo);
{
// Add item to display list if allowed
if (_virtualAll || {_x in _virtualCargo}) then {
private _xCfg = configfile >> "cfgweapons" >> _x;
private _lbAdd = _ctrlList lnbaddrow ["",gettext (_xCfg >> "displayName"),str 0];
_ctrlList lnbsetdata [[_lbAdd,0],_x];
_ctrlList lnbsetpicture [[_lbAdd,0],gettext (_xCfg >> "picture")];
_ctrlList lnbsetvalue [[_lbAdd,0],getnumber (_xCfg >> "itemInfo" >> "mass")];
_ctrlList lbsettooltip [_lbAdd * _columns,format ["%1\n%2",gettext (_xCfg >> "displayName"),_x]];
};

// Add item to main list (will be used on next arsenalOpened automaticly)
(bis_fnc_arsenal_data select IDC_RSCDISPLAYARSENAL_TAB_CARGOMISC) pushBack _x;
} forEach _cbaMiscItems;

// Sort the list:
_ctrlList lnbSort [1,false];

missionNamespace setVariable [QGVAR(arsenalDataModified), true];
TRACE_1("finished",GVAR(arsenalDataModified));

}, _this] call CBA_fnc_directCall;
};
}] call bis_fnc_addScriptedEventHandler;

0 comments on commit 1fa4f28

Please sign in to comment.