From 4e1afdb5c99a3445c9ca0e3a2ca4fb1d821abb4e Mon Sep 17 00:00:00 2001 From: Dedmen Miller Date: Sun, 14 Jul 2024 16:06:29 +0200 Subject: [PATCH] Added ability to view inventory of players within 100m radius --- addons/main/XEH_PREP.hpp | 1 + .../functions/fnc_createPresetFromBox.sqf | 7 +- .../functions/fnc_createPresetFromPlayer.sqf | 48 +++++++++ addons/ui/XEH_PREP.hpp | 1 + addons/ui/functions/fnc_onLoadoutInfoOpen.sqf | 15 ++- .../functions/fnc_onSelChangedPlayerList.sqf | 99 +++++++++++++++++++ addons/ui/ui/IDs.hpp | 6 +- addons/ui/ui/LoadoutInfo.hpp | 21 ++++ 8 files changed, 187 insertions(+), 11 deletions(-) create mode 100644 addons/main/functions/fnc_createPresetFromPlayer.sqf create mode 100644 addons/ui/functions/fnc_onSelChangedPlayerList.sqf diff --git a/addons/main/XEH_PREP.hpp b/addons/main/XEH_PREP.hpp index 69882d3..5e0a0cb 100644 --- a/addons/main/XEH_PREP.hpp +++ b/addons/main/XEH_PREP.hpp @@ -1,4 +1,5 @@ PREP(createPresetFromBox); +PREP(createPresetFromPlayer); PREP(fillPresetIntoBox); diff --git a/addons/main/functions/fnc_createPresetFromBox.sqf b/addons/main/functions/fnc_createPresetFromBox.sqf index b9efcd8..d3b3fc9 100644 --- a/addons/main/functions/fnc_createPresetFromBox.sqf +++ b/addons/main/functions/fnc_createPresetFromBox.sqf @@ -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; @@ -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 \ No newline at end of file diff --git a/addons/main/functions/fnc_createPresetFromPlayer.sqf b/addons/main/functions/fnc_createPresetFromPlayer.sqf new file mode 100644 index 0000000..81163c1 --- /dev/null +++ b/addons/main/functions/fnc_createPresetFromPlayer.sqf @@ -0,0 +1,48 @@ +#include "script_component.hpp" +/* + * Author: dedmen + * Generates a preset from the contents of a players inventory + * + * Arguments: + * 0: Source Player + * 1: Preset Name + * 2: Preset Description + * + * Return Value: + * New Preset + * + * 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 \ No newline at end of file diff --git a/addons/ui/XEH_PREP.hpp b/addons/ui/XEH_PREP.hpp index b90fb6e..099c8c2 100644 --- a/addons/ui/XEH_PREP.hpp +++ b/addons/ui/XEH_PREP.hpp @@ -13,6 +13,7 @@ PREP(handleLoadoutsSearchbar); PREP(onLoadoutInfoOpen); PREP(generateLoadoutDescription); PREP(onSelChangedLoadouts); +PREP(onSelChangedPlayerList); PREP(openLogistikMenuOnBox); PREP(openPresetInfo); PREP(updateBoxFillState); diff --git a/addons/ui/functions/fnc_onLoadoutInfoOpen.sqf b/addons/ui/functions/fnc_onLoadoutInfoOpen.sqf index fda890a..a1fec74 100644 --- a/addons/ui/functions/fnc_onLoadoutInfoOpen.sqf +++ b/addons/ui/functions/fnc_onLoadoutInfoOpen.sqf @@ -1,5 +1,5 @@ #include "script_component.hpp" - +#include "..\ui\IDs.hpp" /* * Author: dedmen * onLoad EH for LoadoutInfo. @@ -20,4 +20,15 @@ _args params ["_display"]; [_display] call FUNC(fillLoadoutsList); -_display call FUNC(updateBoxFillState); \ No newline at end of file +_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}); + diff --git a/addons/ui/functions/fnc_onSelChangedPlayerList.sqf b/addons/ui/functions/fnc_onSelChangedPlayerList.sqf new file mode 100644 index 0000000..562af06 --- /dev/null +++ b/addons/ui/functions/fnc_onSelChangedPlayerList.sqf @@ -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 + * 1: Loadouts panel selection + * + * 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]; + + + + + diff --git a/addons/ui/ui/IDs.hpp b/addons/ui/ui/IDs.hpp index 40b318e..e6776bd 100644 --- a/addons/ui/ui/IDs.hpp +++ b/addons/ui/ui/IDs.hpp @@ -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 diff --git a/addons/ui/ui/LoadoutInfo.hpp b/addons/ui/ui/LoadoutInfo.hpp index 0e237fd..ddec168 100644 --- a/addons/ui/ui/LoadoutInfo.hpp +++ b/addons/ui/ui/LoadoutInfo.hpp @@ -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}; + }; };