Add customization options to the preview discards window

This commit is contained in:
Liza 2023-11-13 22:31:35 +01:00
parent a4fc9bc954
commit b31b2e24dc
Signed by: liza
GPG Key ID: 7199F8D727D55F67
6 changed files with 96 additions and 16 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework> <TargetFramework>net7.0-windows</TargetFramework>
<Version>3.2</Version> <Version>3.3</Version>
<LangVersion>11.0</LangVersion> <LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

View File

@ -14,6 +14,7 @@ using ECommons.Automation;
using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Component.GUI; using FFXIVClientStructs.FFXIV.Component.GUI;
using LLib;
namespace ARDiscard; namespace ARDiscard;
@ -32,6 +33,7 @@ public class AutoDiscardPlogon : IDalamudPlugin
private readonly IGameGui _gameGui; private readonly IGameGui _gameGui;
private readonly ICommandManager _commandManager; private readonly ICommandManager _commandManager;
private readonly InventoryUtils _inventoryUtils; private readonly InventoryUtils _inventoryUtils;
private readonly IconCache _iconCache;
private readonly AutoRetainerApi _autoRetainerApi; private readonly AutoRetainerApi _autoRetainerApi;
private readonly TaskManager _taskManager; private readonly TaskManager _taskManager;
private readonly ContextMenuIntegration _contextMenuIntegration; private readonly ContextMenuIntegration _contextMenuIntegration;
@ -40,7 +42,7 @@ public class AutoDiscardPlogon : IDalamudPlugin
public AutoDiscardPlogon(DalamudPluginInterface pluginInterface, ICommandManager commandManager, IChatGui chatGui, public AutoDiscardPlogon(DalamudPluginInterface pluginInterface, ICommandManager commandManager, IChatGui chatGui,
IDataManager dataManager, IClientState clientState, ICondition condition, IPluginLog pluginLog, IDataManager dataManager, IClientState clientState, ICondition condition, IPluginLog pluginLog,
IGameGui gameGui) IGameGui gameGui, ITextureProvider textureProvider)
{ {
ItemCache itemCache = new ItemCache(dataManager); ItemCache itemCache = new ItemCache(dataManager);
@ -64,11 +66,12 @@ public class AutoDiscardPlogon : IDalamudPlugin
HelpMessage = "Show what will be discarded with your current configuration", HelpMessage = "Show what will be discarded with your current configuration",
}); });
_inventoryUtils = new InventoryUtils(_configuration, itemCache, _pluginLog); _inventoryUtils = new InventoryUtils(_configuration, itemCache, _pluginLog);
_iconCache = new IconCache(textureProvider);
_pluginInterface.UiBuilder.Draw += _windowSystem.Draw; _pluginInterface.UiBuilder.Draw += _windowSystem.Draw;
_pluginInterface.UiBuilder.OpenConfigUi += OpenConfigUi; _pluginInterface.UiBuilder.OpenConfigUi += OpenConfigUi;
_discardWindow = new(_inventoryUtils, itemCache, clientState, condition); _discardWindow = new(_inventoryUtils, itemCache, _iconCache, clientState, condition, _configuration);
_windowSystem.AddWindow(_discardWindow); _windowSystem.AddWindow(_discardWindow);
_configWindow = new(_pluginInterface, _configuration, itemCache, clientState, condition); _configWindow = new(_pluginInterface, _configuration, itemCache, clientState, condition);
@ -274,6 +277,7 @@ public class AutoDiscardPlogon : IDalamudPlugin
_contextMenuIntegration.Dispose(); _contextMenuIntegration.Dispose();
_autoRetainerApi.Dispose(); _autoRetainerApi.Dispose();
ECommonsMain.Dispose(); ECommonsMain.Dispose();
_iconCache.Dispose();
_pluginInterface.UiBuilder.OpenConfigUi -= OpenConfigUi; _pluginInterface.UiBuilder.OpenConfigUi -= OpenConfigUi;
_pluginInterface.UiBuilder.Draw -= _windowSystem.Draw; _pluginInterface.UiBuilder.Draw -= _windowSystem.Draw;

View File

@ -13,6 +13,7 @@ internal sealed class Configuration : IPluginConfiguration
public ArmouryConfiguration Armoury { get; set; } = new(); public ArmouryConfiguration Armoury { get; set; } = new();
public ContextMenuConfiguration ContextMenu { get; set; } = new(); public ContextMenuConfiguration ContextMenu { get; set; } = new();
public PreviewConfiguration Preview { get; set; } = new();
public uint IgnoreItemCountWhenAbove { get; set; } = 50; public uint IgnoreItemCountWhenAbove { get; set; } = 50;
public sealed class CharacterInfo public sealed class CharacterInfo
@ -35,4 +36,10 @@ internal sealed class Configuration : IPluginConfiguration
public bool Enabled { get; set; } = false; public bool Enabled { get; set; } = false;
public bool OnlyWhenConfigIsOpen { get; set; } = true; public bool OnlyWhenConfigIsOpen { get; set; } = true;
} }
public sealed class PreviewConfiguration
{
public bool GroupByCategory { get; set; } = true;
public bool ShowIcons { get; set; } = true;
}
} }

View File

@ -19,6 +19,7 @@ internal sealed class ItemCache
{ {
ItemId = item.RowId, ItemId = item.RowId,
Name = item.Name.ToString(), Name = item.Name.ToString(),
IconId = item.Icon,
ILvl = item.LevelItem.Row, ILvl = item.LevelItem.Row,
Rarity = item.Rarity, Rarity = item.Rarity,
IsUnique = item.IsUnique, IsUnique = item.IsUnique,
@ -26,6 +27,7 @@ internal sealed class ItemCache
IsIndisposable = item.IsIndisposable, IsIndisposable = item.IsIndisposable,
Level = item.LevelEquip, Level = item.LevelEquip,
UiCategory = item.ItemUICategory.Row, UiCategory = item.ItemUICategory.Row,
UiCategoryName = item.ItemUICategory.Value!.Name.ToString(),
}; };
} }
} }
@ -46,10 +48,18 @@ internal sealed class ItemCache
return string.Empty; return string.Empty;
} }
public ushort GetItemIconId(uint itemId)
{
if (_items.TryGetValue(itemId, out var item))
return item.IconId;
return ushort.MinValue;
}
public sealed class CachedItemInfo public sealed class CachedItemInfo
{ {
public required uint ItemId { get; init; } public required uint ItemId { get; init; }
public required string Name { get; init; } public required string Name { get; init; }
public required ushort IconId { get; init; }
public required uint ILvl { get; init; } public required uint ILvl { get; init; }
public required uint Level { get; init; } public required uint Level { get; init; }
public required byte Rarity { get; init; } public required byte Rarity { get; init; }
@ -62,5 +72,6 @@ internal sealed class ItemCache
public required bool IsIndisposable { get; init; } public required bool IsIndisposable { get; init; }
public required uint UiCategory { get; init; } public required uint UiCategory { get; init; }
public required string UiCategoryName { get; init; }
} }
} }

View File

@ -2,12 +2,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Threading.Tasks;
using ARDiscard.GameData; using ARDiscard.GameData;
using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Conditions;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Interface.Utility; using Dalamud.Interface.Utility;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin; using Dalamud.Plugin;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using ECommons; using ECommons;
@ -332,6 +330,22 @@ internal sealed class ConfigWindow : LImGui.LWindow
Save(); Save();
} }
ImGui.Separator();
bool groupPreviewByCategory = _configuration.Preview.GroupByCategory;
if (ImGui.Checkbox("Group items in 'Preview' by category", ref groupPreviewByCategory))
{
_configuration.Preview.GroupByCategory = groupPreviewByCategory;
Save();
}
bool showIconsInPreview = _configuration.Preview.ShowIcons;
if (ImGui.Checkbox("Show icons in 'Preview'", ref showIconsInPreview))
{
_configuration.Preview.ShowIcons = showIconsInPreview;
Save();
}
ImGui.EndTabItem(); ImGui.EndTabItem();
} }
} }

View File

@ -3,8 +3,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using ARDiscard.GameData; using ARDiscard.GameData;
using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Conditions;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Utility; using Dalamud.Interface.Utility;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Common.Math; using FFXIVClientStructs.FFXIV.Common.Math;
using ImGuiNET; using ImGuiNET;
@ -16,22 +16,26 @@ internal sealed class DiscardWindow : LImGui.LWindow
{ {
private readonly InventoryUtils _inventoryUtils; private readonly InventoryUtils _inventoryUtils;
private readonly ItemCache _itemCache; private readonly ItemCache _itemCache;
private readonly IconCache _iconCache;
private readonly IClientState _clientState; private readonly IClientState _clientState;
private readonly ICondition _condition; private readonly ICondition _condition;
private readonly Configuration _configuration;
private List<SelectableItem> _displayedItems = new(); private List<SelectableItem> _displayedItems = new();
public event EventHandler? OpenConfigurationClicked; public event EventHandler? OpenConfigurationClicked;
public event EventHandler<ItemFilter>? DiscardAllClicked; public event EventHandler<ItemFilter>? DiscardAllClicked;
public DiscardWindow(InventoryUtils inventoryUtils, ItemCache itemCache, public DiscardWindow(InventoryUtils inventoryUtils, ItemCache itemCache, IconCache iconCache,
IClientState clientState, ICondition condition) IClientState clientState, ICondition condition, Configuration configuration)
: base("Discard Items###AutoDiscardDiscard") : base("Discard Items###AutoDiscardDiscard")
{ {
_inventoryUtils = inventoryUtils; _inventoryUtils = inventoryUtils;
_itemCache = itemCache; _itemCache = itemCache;
_iconCache = iconCache;
_clientState = clientState; _clientState = clientState;
_condition = condition; _condition = condition;
_configuration = configuration;
Size = new Vector2(600, 400); Size = new Vector2(600, 400);
SizeCondition = ImGuiCond.FirstUseEver; SizeCondition = ImGuiCond.FirstUseEver;
@ -62,10 +66,22 @@ internal sealed class DiscardWindow : LImGui.LWindow
} }
else else
{ {
foreach (var displayedItem in _displayedItems) if (_configuration.Preview.GroupByCategory)
{ {
if (ImGui.Selectable(displayedItem.ToString(), displayedItem.Selected)) foreach (var category in _displayedItems.OrderBy(x => x.UiCategory)
displayedItem.Selected = !displayedItem.Selected; .GroupBy(x => new { x.UiCategory, x.UiCategoryName }))
{
ImGui.Text($"{category.Key.UiCategoryName}");
ImGui.Indent();
foreach (var displayedItem in category)
DrawItem(displayedItem);
ImGui.Unindent();
}
}
else
{
foreach (var displayedItem in _displayedItems)
DrawItem(displayedItem);
} }
} }
} }
@ -95,6 +111,23 @@ internal sealed class DiscardWindow : LImGui.LWindow
ImGui.EndDisabled(); ImGui.EndDisabled();
} }
private void DrawItem(SelectableItem displayedItem)
{
if (_configuration.Preview.ShowIcons)
{
IDalamudTextureWrap? icon = _iconCache.GetIcon(displayedItem.IconId);
if (icon != null)
{
ImGui.Image(icon.ImGuiHandle, new Vector2(23, 23));
ImGui.SameLine();
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + 3);
}
}
if (ImGui.Selectable(displayedItem.ToString(), displayedItem.Selected))
displayedItem.Selected = !displayedItem.Selected;
}
public override void OnOpen() => RefreshInventory(false); public override void OnOpen() => RefreshInventory(false);
public override void OnClose() => _displayedItems.Clear(); public override void OnClose() => _displayedItems.Clear();
@ -113,13 +146,21 @@ internal sealed class DiscardWindow : LImGui.LWindow
} }
_displayedItems = _inventoryUtils.GetAllItemsToDiscard() _displayedItems = _inventoryUtils.GetAllItemsToDiscard()
.GroupBy(x => x.InventoryItem->ItemID) .GroupBy(x => new
{
ItemId = x.InventoryItem->ItemID,
ItemInfo = _itemCache.GetItem(x.InventoryItem->ItemID),
})
.Where(x => x.Key.ItemInfo != null)
.Select(x => new SelectableItem .Select(x => new SelectableItem
{ {
ItemId = x.Key, ItemId = x.Key.ItemId,
Name = _itemCache.GetItemName(x.Key), Name = x.Key.ItemInfo!.Name,
IconId = x.Key.ItemInfo!.IconId,
Quantity = x.Sum(y => y.InventoryItem->Quantity), Quantity = x.Sum(y => y.InventoryItem->Quantity),
Selected = !notSelected.Contains(x.Key), UiCategory = x.Key.ItemInfo!.UiCategory,
UiCategoryName = x.Key.ItemInfo!.UiCategoryName,
Selected = !notSelected.Contains(x.Key.ItemId),
}) })
.OrderBy(x => x.Name.ToLower()) .OrderBy(x => x.Name.ToLower())
.ToList(); .ToList();
@ -129,8 +170,11 @@ internal sealed class DiscardWindow : LImGui.LWindow
{ {
public required uint ItemId { get; init; } public required uint ItemId { get; init; }
public required string Name { get; init; } public required string Name { get; init; }
public required ushort IconId { get; init; }
public required long Quantity { get; init; } public required long Quantity { get; init; }
public bool Selected { get; set; } = true; public required uint UiCategory { get; init; }
public required string UiCategoryName { get; init; }
public required bool Selected { get; set; }
public override string ToString() public override string ToString()
{ {