forked from liza/ARDiscard
Add customization options to the preview discards window
This commit is contained in:
parent
a4fc9bc954
commit
b31b2e24dc
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<Version>3.2</Version>
|
||||
<Version>3.3</Version>
|
||||
<LangVersion>11.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
|
@ -14,6 +14,7 @@ using ECommons.Automation;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game;
|
||||
using FFXIVClientStructs.FFXIV.Client.UI;
|
||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||
using LLib;
|
||||
|
||||
namespace ARDiscard;
|
||||
|
||||
@ -32,6 +33,7 @@ public class AutoDiscardPlogon : IDalamudPlugin
|
||||
private readonly IGameGui _gameGui;
|
||||
private readonly ICommandManager _commandManager;
|
||||
private readonly InventoryUtils _inventoryUtils;
|
||||
private readonly IconCache _iconCache;
|
||||
private readonly AutoRetainerApi _autoRetainerApi;
|
||||
private readonly TaskManager _taskManager;
|
||||
private readonly ContextMenuIntegration _contextMenuIntegration;
|
||||
@ -40,7 +42,7 @@ public class AutoDiscardPlogon : IDalamudPlugin
|
||||
|
||||
public AutoDiscardPlogon(DalamudPluginInterface pluginInterface, ICommandManager commandManager, IChatGui chatGui,
|
||||
IDataManager dataManager, IClientState clientState, ICondition condition, IPluginLog pluginLog,
|
||||
IGameGui gameGui)
|
||||
IGameGui gameGui, ITextureProvider textureProvider)
|
||||
{
|
||||
ItemCache itemCache = new ItemCache(dataManager);
|
||||
|
||||
@ -64,11 +66,12 @@ public class AutoDiscardPlogon : IDalamudPlugin
|
||||
HelpMessage = "Show what will be discarded with your current configuration",
|
||||
});
|
||||
_inventoryUtils = new InventoryUtils(_configuration, itemCache, _pluginLog);
|
||||
_iconCache = new IconCache(textureProvider);
|
||||
|
||||
_pluginInterface.UiBuilder.Draw += _windowSystem.Draw;
|
||||
_pluginInterface.UiBuilder.OpenConfigUi += OpenConfigUi;
|
||||
|
||||
_discardWindow = new(_inventoryUtils, itemCache, clientState, condition);
|
||||
_discardWindow = new(_inventoryUtils, itemCache, _iconCache, clientState, condition, _configuration);
|
||||
_windowSystem.AddWindow(_discardWindow);
|
||||
|
||||
_configWindow = new(_pluginInterface, _configuration, itemCache, clientState, condition);
|
||||
@ -274,6 +277,7 @@ public class AutoDiscardPlogon : IDalamudPlugin
|
||||
_contextMenuIntegration.Dispose();
|
||||
_autoRetainerApi.Dispose();
|
||||
ECommonsMain.Dispose();
|
||||
_iconCache.Dispose();
|
||||
|
||||
_pluginInterface.UiBuilder.OpenConfigUi -= OpenConfigUi;
|
||||
_pluginInterface.UiBuilder.Draw -= _windowSystem.Draw;
|
||||
|
@ -13,6 +13,7 @@ internal sealed class Configuration : IPluginConfiguration
|
||||
|
||||
public ArmouryConfiguration Armoury { get; set; } = new();
|
||||
public ContextMenuConfiguration ContextMenu { get; set; } = new();
|
||||
public PreviewConfiguration Preview { get; set; } = new();
|
||||
public uint IgnoreItemCountWhenAbove { get; set; } = 50;
|
||||
|
||||
public sealed class CharacterInfo
|
||||
@ -35,4 +36,10 @@ internal sealed class Configuration : IPluginConfiguration
|
||||
public bool Enabled { get; set; } = false;
|
||||
public bool OnlyWhenConfigIsOpen { get; set; } = true;
|
||||
}
|
||||
|
||||
public sealed class PreviewConfiguration
|
||||
{
|
||||
public bool GroupByCategory { get; set; } = true;
|
||||
public bool ShowIcons { get; set; } = true;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ internal sealed class ItemCache
|
||||
{
|
||||
ItemId = item.RowId,
|
||||
Name = item.Name.ToString(),
|
||||
IconId = item.Icon,
|
||||
ILvl = item.LevelItem.Row,
|
||||
Rarity = item.Rarity,
|
||||
IsUnique = item.IsUnique,
|
||||
@ -26,6 +27,7 @@ internal sealed class ItemCache
|
||||
IsIndisposable = item.IsIndisposable,
|
||||
Level = item.LevelEquip,
|
||||
UiCategory = item.ItemUICategory.Row,
|
||||
UiCategoryName = item.ItemUICategory.Value!.Name.ToString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -46,10 +48,18 @@ internal sealed class ItemCache
|
||||
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 required uint ItemId { get; init; }
|
||||
public required string Name { get; init; }
|
||||
public required ushort IconId { get; init; }
|
||||
public required uint ILvl { get; init; }
|
||||
public required uint Level { get; init; }
|
||||
public required byte Rarity { get; init; }
|
||||
@ -62,5 +72,6 @@ internal sealed class ItemCache
|
||||
public required bool IsIndisposable { get; init; }
|
||||
|
||||
public required uint UiCategory { get; init; }
|
||||
public required string UiCategoryName { get; init; }
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Threading.Tasks;
|
||||
using ARDiscard.GameData;
|
||||
using Dalamud.Game.ClientState.Conditions;
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin.Services;
|
||||
using ECommons;
|
||||
@ -332,6 +330,22 @@ internal sealed class ConfigWindow : LImGui.LWindow
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ARDiscard.GameData;
|
||||
using Dalamud.Game.ClientState.Conditions;
|
||||
using Dalamud.Interface.Internal;
|
||||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Plugin.Services;
|
||||
using FFXIVClientStructs.FFXIV.Common.Math;
|
||||
using ImGuiNET;
|
||||
@ -16,22 +16,26 @@ internal sealed class DiscardWindow : LImGui.LWindow
|
||||
{
|
||||
private readonly InventoryUtils _inventoryUtils;
|
||||
private readonly ItemCache _itemCache;
|
||||
private readonly IconCache _iconCache;
|
||||
private readonly IClientState _clientState;
|
||||
private readonly ICondition _condition;
|
||||
private readonly Configuration _configuration;
|
||||
|
||||
private List<SelectableItem> _displayedItems = new();
|
||||
|
||||
public event EventHandler? OpenConfigurationClicked;
|
||||
public event EventHandler<ItemFilter>? DiscardAllClicked;
|
||||
|
||||
public DiscardWindow(InventoryUtils inventoryUtils, ItemCache itemCache,
|
||||
IClientState clientState, ICondition condition)
|
||||
public DiscardWindow(InventoryUtils inventoryUtils, ItemCache itemCache, IconCache iconCache,
|
||||
IClientState clientState, ICondition condition, Configuration configuration)
|
||||
: base("Discard Items###AutoDiscardDiscard")
|
||||
{
|
||||
_inventoryUtils = inventoryUtils;
|
||||
_itemCache = itemCache;
|
||||
_iconCache = iconCache;
|
||||
_clientState = clientState;
|
||||
_condition = condition;
|
||||
_configuration = configuration;
|
||||
|
||||
Size = new Vector2(600, 400);
|
||||
SizeCondition = ImGuiCond.FirstUseEver;
|
||||
@ -62,10 +66,22 @@ internal sealed class DiscardWindow : LImGui.LWindow
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var displayedItem in _displayedItems)
|
||||
if (_configuration.Preview.GroupByCategory)
|
||||
{
|
||||
if (ImGui.Selectable(displayedItem.ToString(), displayedItem.Selected))
|
||||
displayedItem.Selected = !displayedItem.Selected;
|
||||
foreach (var category in _displayedItems.OrderBy(x => x.UiCategory)
|
||||
.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();
|
||||
}
|
||||
|
||||
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 OnClose() => _displayedItems.Clear();
|
||||
@ -113,13 +146,21 @@ internal sealed class DiscardWindow : LImGui.LWindow
|
||||
}
|
||||
|
||||
_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
|
||||
{
|
||||
ItemId = x.Key,
|
||||
Name = _itemCache.GetItemName(x.Key),
|
||||
ItemId = x.Key.ItemId,
|
||||
Name = x.Key.ItemInfo!.Name,
|
||||
IconId = x.Key.ItemInfo!.IconId,
|
||||
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())
|
||||
.ToList();
|
||||
@ -129,8 +170,11 @@ internal sealed class DiscardWindow : LImGui.LWindow
|
||||
{
|
||||
public required uint ItemId { get; init; }
|
||||
public required string Name { get; init; }
|
||||
public required ushort IconId { 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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user