Skip to content

Commit

Permalink
Added ability to view inventory of players within 100m radius
Browse files Browse the repository at this point in the history
  • Loading branch information
dedmen committed Jul 14, 2024
1 parent 8926aab commit 4e1afdb
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 11 deletions.
1 change: 1 addition & 0 deletions addons/main/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


PREP(createPresetFromBox);
PREP(createPresetFromPlayer);
PREP(fillPresetIntoBox);
7 changes: 2 additions & 5 deletions addons/main/functions/fnc_createPresetFromBox.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private _newPreset = [_presetName, _presetDescription, _presetContents];
private _weapons = [];

{
_presetContents pushBack _X;
_presetContents pushBack _x;
} forEach weaponsItemsCargo _target; // [weapon, muzzle, flashlight, optics, primaryMag, secondaryMag, bipod]

private _magazineCargo = getMagazineCargo _target;
Expand All @@ -50,12 +50,9 @@ private _backpackCargo = everyContainer _target;
} forEach (_itemCargo select 0);



{
_x params ["_type", "_object"];
_presetContents pushBack [_type, [_object, "", ""] call wolf_logistics_main_fnc_createPresetFromBox, 1]; // [name, contentPreset, dummy]
} forEach _backpackCargo;

private _backpackCargo = everyBackpack _target;

_newPreset
_newPreset
48 changes: 48 additions & 0 deletions addons/main/functions/fnc_createPresetFromPlayer.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "script_component.hpp"
/*
* Author: dedmen
* Generates a preset from the contents of a players inventory
*
* Arguments:
* 0: Source Player <OBJECT>
* 1: Preset Name <STRING>
* 2: Preset Description <STRING>
*
* Return Value:
* New Preset <ARRAY>
*
* Example:
* [_target, "new Preset", "This is a preset"] call wolf_logistics_main_fnc_createPresetFromPlayer
*
* Public: Yes
*/

params ["_target", "_presetName", "_presetDescription"];

private _presetContents = [];
private _newPreset = [_presetName, _presetDescription, _presetContents];

// Player only has containers and weapons and assigned items

{
_presetContents pushBack _x;
} forEach weaponsItems _target; // [weapon, muzzle, flashlight, optics, primaryMag, secondaryMag, bipod]

{
_presetContents pushBack [_x, 1];
} forEach assignedItems [_target, true, false];

// This is basically all of the rest of the inventory

private _backpackCargo = [
[uniform _target, uniformContainer _target],
[vest _target, vestContainer _target],
[backpack _target, backpackContainer _target]
] select {(_x select 0) != ""};

{
_x params ["_type", "_object"];
_presetContents pushBack [_type, [_object, "", ""] call wolf_logistics_main_fnc_createPresetFromBox, 1]; // [name, contentPreset, dummy]
} forEach _backpackCargo;

_newPreset
1 change: 1 addition & 0 deletions addons/ui/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ PREP(handleLoadoutsSearchbar);
PREP(onLoadoutInfoOpen);
PREP(generateLoadoutDescription);
PREP(onSelChangedLoadouts);
PREP(onSelChangedPlayerList);
PREP(openLogistikMenuOnBox);
PREP(openPresetInfo);
PREP(updateBoxFillState);
Expand Down
15 changes: 13 additions & 2 deletions addons/ui/functions/fnc_onLoadoutInfoOpen.sqf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "script_component.hpp"

#include "..\ui\IDs.hpp"
/*
* Author: dedmen
* onLoad EH for LoadoutInfo.
Expand All @@ -20,4 +20,15 @@ _args params ["_display"];


[_display] call FUNC(fillLoadoutsList);
_display call FUNC(updateBoxFillState);
_display call FUNC(updateBoxFillState);

private _playerListCtrl = _display displayCtrl IDC_playerList;
lbClear _playerListCtrl;

// Can select any player within 100m and display their inventory contents

{
private _index = _playerListCtrl lbAdd name _x;
_playerListCtrl lbSetData [_index, hashValue _x];
} forEach (allPlayers select {_x distance player < 100});

99 changes: 99 additions & 0 deletions addons/ui/functions/fnc_onSelChangedPlayerList.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include "script_component.hpp"
#include "..\ui\IDs.hpp"
/*
* Author: Alganthe, Dedmen
* Handles selection changes on loadouts panel.
*
* Arguments:
* 0: Loadouts panel control <CONTROL>
* 1: Loadouts panel selection <SCALAR>
*
* Return Value:
* None
*
* Public: No
*/

params ["_display", "_control", "_curSel"];

private _saveButtonCtrl = _display displayCtrl IDC_buttonSave;
private _packIntoBoxButtonCtrl = _display displayCtrl IDC_buttonPackIntoBox;
private _clearBoxButtonCtrl = _display displayCtrl IDC_buttonClearBox;
private _exportBoxButtonCtrl = _display displayCtrl IDC_buttonShareBox;
private _exportPresetButtonCtrl = _display displayCtrl IDC_buttonSharePreset;
private _renameButtonCtrl = _display displayCtrl IDC_buttonRename;
private _deleteButtonCtrl = _display displayCtrl IDC_buttonDelete;
private _loadoutInfoCtrl = _display displayCtrl IDC_loadoutInfo;
private _textEditBoxCtrl = _display displayCtrl IDC_textLoadoutName;


private _contentPanelCtrl = _display displayCtrl IDC_playerList;
private _playerHash = _contentPanelCtrl lbData _curSel;

private _player = (allPlayers select {hashValue _x == _playerHash}) param [0, objNull];

if (isNull _player) exitWith {};

private _loadout = [_player, name _player, format ["Player inventory view %1", name _player]] call wolf_logistics_main_fnc_createPresetFromPlayer;

private _loadoutDescription = [_loadout] call wolf_logistics_ui_fnc_generateLoadoutDescription;

tvClear _loadoutInfoCtrl;
private _addTreeItem = {
params ["_item", "_parentPath"];

if (_item isEqualType []) then {
private _nodeItem = _loadoutInfoCtrl tvAdd [_parentPath, _item select 1];
private _nodePath = _parentPath + [_nodeItem];
_loadoutInfoCtrl tvSetPicture [_nodePath, getText ((_item select 0) >> "picture")];
_loadoutInfoCtrl tvSetTooltip [_nodePath, configName (_item select 0)]; // Classname tooltip

if (count _item > 2) then { // item with sub content
{
[_x, _nodePath] call _addTreeItem;
} forEach (_item select 2);
}
} else {
_loadoutInfoCtrl tvAdd [_parentPath, _item];
}
};

{
[_x, []] call _addTreeItem;
} forEach _loadoutDescription;

//#TODO extra features, click item in tree and delete it out of existing lodaout

tvExpandAll _loadoutInfoCtrl;

_textEditBoxCtrl ctrlSetText (_control lnbText [_curSel, 1]);

// We enable them all, then we disable what we can't have

{
_x ctrlEnable true;
_x ctrlCommit 0;
} foreach [
// First row
_saveButtonCtrl, _renameButtonCtrl, _deleteButtonCtrl, // Preset edit buttons
_clearBoxButtonCtrl, _packIntoBoxButtonCtrl, _exportBoxButtonCtrl,
// Second row
_exportPresetButtonCtrl
];

// No box
{
_x ctrlEnable false;
_x ctrlCommit 0;
} foreach [_saveButtonCtrl, _clearBoxButtonCtrl, _packIntoBoxButtonCtrl, _exportBoxButtonCtrl];

// No preset
{
_x ctrlEnable false;
_x ctrlCommit 0;
} foreach [_renameButtonCtrl, _deleteButtonCtrl, _packIntoBoxButtonCtrl, _exportPresetButtonCtrl];





6 changes: 2 additions & 4 deletions addons/ui/ui/IDs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
#define IDC_buttonClearBox 307
#define IDC_buttonRename 308
#define IDC_loadoutsSearchbar 309
#define IDC_loadoutInfo 310
#define IDC_boxFillState 311
#define IDC_textImportData 312
#define IDC_buttonShareBox 312
#define IDC_buttonSharePreset 313

#define IDC_loadoutInfo 310


#define IDC_playerList 314
21 changes: 21 additions & 0 deletions addons/ui/ui/LoadoutInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,27 @@ class GVAR(loadoutInfo) {
};


class playerListTitle: ctrlStaticTitle {
idc = -1;
style = ST_CENTER;
text = "Spieler in 100m radius:";
x = QUOTE(safezoneX + (5 * GRID_W));
y = QUOTE(safezoneY + (10 * GRID_H) + safezoneH - (34 * GRID_H) );
w = QUOTE(200 * GRID_W);
h = QUOTE(5 * GRID_H);
sizeEx = QUOTE(5 * GRID_H);
};
class playerList: RscCombo {
idc = IDC_playerList;
onLBSelChanged = QUOTE([ARR_3(ctrlParent (_this select 0), _this select 0, _this select 1)] call FUNC(onSelChangedPlayerList));
x = QUOTE(safezoneX + (5 * GRID_W));
y = QUOTE(safezoneY + (15 * GRID_H) + safezoneH - (34 * GRID_H) );
w = QUOTE(200 * GRID_W);
h = QUOTE(4 * GRID_H);
wholeHeight = QUOTE(10 * GRID_H);
sizeEx = QUOTE(5 * GRID_H);
colorBackground[]={0,0,0,0.8};
};

};

Expand Down

0 comments on commit 4e1afdb

Please sign in to comment.