1
0
Fork 0

(2.x) Add icons

master
Liza 2023-10-10 13:26:25 +02:00
parent 6564a49369
commit 59d6f50c18
Signed by: liza
GPG Key ID: 7199F8D727D55F67
5 changed files with 113 additions and 15 deletions

View File

@ -27,12 +27,14 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin
private readonly Configuration _configuration; private readonly Configuration _configuration;
private readonly GameCache _gameCache; private readonly GameCache _gameCache;
private readonly IconCache _iconCache;
private readonly VentureResolver _ventureResolver; private readonly VentureResolver _ventureResolver;
private readonly ConfigWindow _configWindow; private readonly ConfigWindow _configWindow;
private readonly AutoRetainerApi _autoRetainerApi; private readonly AutoRetainerApi _autoRetainerApi;
public AutoRetainerControlPlugin(DalamudPluginInterface pluginInterface, IDataManager dataManager, public AutoRetainerControlPlugin(DalamudPluginInterface pluginInterface, IDataManager dataManager,
IClientState clientState, IChatGui chatGui, ICommandManager commandManager, IPluginLog pluginLog) IClientState clientState, IChatGui chatGui, ICommandManager commandManager, ITextureProvider textureProvider,
IPluginLog pluginLog)
{ {
_pluginInterface = pluginInterface; _pluginInterface = pluginInterface;
_clientState = clientState; _clientState = clientState;
@ -43,9 +45,10 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin
_configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration { Version = 2 }; _configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration { Version = 2 };
_gameCache = new GameCache(dataManager); _gameCache = new GameCache(dataManager);
_iconCache = new IconCache(textureProvider);
_ventureResolver = new VentureResolver(_gameCache, _pluginLog); _ventureResolver = new VentureResolver(_gameCache, _pluginLog);
_configWindow = _configWindow =
new ConfigWindow(_pluginInterface, _configuration, _gameCache, _clientState, _commandManager, _pluginLog) new ConfigWindow(_pluginInterface, _configuration, _gameCache, _clientState, _commandManager, _iconCache, _pluginLog)
{ IsOpen = true }; { IsOpen = true };
_windowSystem.AddWindow(_configWindow); _windowSystem.AddWindow(_configWindow);
@ -184,6 +187,7 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin
_pluginInterface.UiBuilder.OpenConfigUi -= _configWindow.Toggle; _pluginInterface.UiBuilder.OpenConfigUi -= _configWindow.Toggle;
_pluginInterface.UiBuilder.Draw -= _windowSystem.Draw; _pluginInterface.UiBuilder.Draw -= _windowSystem.Draw;
_iconCache.Dispose();
_autoRetainerApi.Dispose(); _autoRetainerApi.Dispose();
ECommonsMain.Dispose(); ECommonsMain.Dispose();
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Dalamud.Configuration; using Dalamud.Configuration;
using Dalamud.Game.Text;
using Dalamud.Interface; using Dalamud.Interface;
namespace ARControl; namespace ARControl;
@ -20,6 +21,17 @@ internal sealed class Configuration : IPluginConfiguration
public required ListType Type { get; set; } = ListType.CollectOneTime; public required ListType Type { get; set; } = ListType.CollectOneTime;
public required ListPriority Priority { get; set; } = ListPriority.InOrder; public required ListPriority Priority { get; set; } = ListPriority.InOrder;
public List<QueuedItem> Items { get; set; } = new(); public List<QueuedItem> Items { get; set; } = new();
public string GetIcon()
{
return Type switch
{
ListType.CollectOneTime => SeIconChar.BoxedNumber1.ToIconString(),
ListType.KeepStocked when Priority == ListPriority.Balanced => SeIconChar.EurekaLevel.ToIconString(),
ListType.KeepStocked => SeIconChar.Circle.ToIconString(),
_ => string.Empty
};
}
} }
public enum ListType public enum ListType
@ -44,7 +56,6 @@ internal sealed class Configuration : IPluginConfiguration
{ {
public required Guid Id { get; set; } public required Guid Id { get; set; }
public required string Name { get; set; } public required string Name { get; set; }
public required FontAwesomeIcon Icon { get; set; }
public List<Guid> ItemListIds { get; set; } = new(); public List<Guid> ItemListIds { get; set; } = new();
} }

View File

@ -14,6 +14,7 @@ internal sealed class Venture
var taskDetails = dataManager.GetExcelSheet<RetainerTaskNormal>()!.GetRow(retainerTask.Task)!; var taskDetails = dataManager.GetExcelSheet<RetainerTaskNormal>()!.GetRow(retainerTask.Task)!;
var taskParameters = retainerTask.RetainerTaskParameter.Value!; var taskParameters = retainerTask.RetainerTaskParameter.Value!;
ItemId = taskDetails.Item.Row; ItemId = taskDetails.Item.Row;
IconId = taskDetails.Item.Value!.Icon;
Name = taskDetails.Item.Value!.Name.ToString(); Name = taskDetails.Item.Value!.Name.ToString();
Level = retainerTask.RetainerLevel; Level = retainerTask.RetainerLevel;
ItemLevelCombat = retainerTask.RequiredItemLevel; ItemLevelCombat = retainerTask.RequiredItemLevel;
@ -76,6 +77,7 @@ internal sealed class Venture
} }
public uint ItemId { get; } public uint ItemId { get; }
public ushort IconId { get; }
public string Name { get; } public string Name { get; }
public byte Level { get; } public byte Level { get; }
public ushort ItemLevelCombat { get; } public ushort ItemLevelCombat { get; }

53
ARControl/IconCache.cs Normal file
View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using Dalamud.Interface.Internal;
using Dalamud.Plugin.Services;
namespace ARControl;
internal sealed class IconCache : IDisposable
{
private readonly ITextureProvider _textureProvider;
private readonly Dictionary<uint, TextureContainer> _textureWraps = new();
public IconCache(ITextureProvider textureProvider)
{
_textureProvider = textureProvider;
}
public IDalamudTextureWrap? GetIcon(uint iconId)
{
if (_textureWraps.TryGetValue(iconId, out TextureContainer? container))
return container.Texture;
var iconTex = _textureProvider.GetIcon(iconId);
if (iconTex != null)
{
if (iconTex.ImGuiHandle != nint.Zero)
{
_textureWraps[iconId] = new TextureContainer { Texture = iconTex };
return iconTex;
}
iconTex.Dispose();
}
_textureWraps[iconId] = new TextureContainer { Texture = null };
return null;
}
public void Dispose()
{
foreach (TextureContainer container in _textureWraps.Values)
container.Dispose();
_textureWraps.Clear();
}
private sealed class TextureContainer : IDisposable
{
public required IDalamudTextureWrap? Texture { get; init; }
public void Dispose() => Texture?.Dispose();
}
}

View File

@ -7,6 +7,7 @@ using Dalamud.Game.Text;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Interface.Components; using Dalamud.Interface.Components;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Plugin; using Dalamud.Plugin;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
@ -18,6 +19,7 @@ namespace ARControl.Windows;
internal sealed class ConfigWindow : Window internal sealed class ConfigWindow : Window
{ {
// TODO This should also allow retainers under max level
private const byte MaxLevel = 90; private const byte MaxLevel = 90;
private static readonly Vector4 ColorGreen = ImGuiColors.HealerGreen; private static readonly Vector4 ColorGreen = ImGuiColors.HealerGreen;
@ -31,6 +33,7 @@ internal sealed class ConfigWindow : Window
private readonly GameCache _gameCache; private readonly GameCache _gameCache;
private readonly IClientState _clientState; private readonly IClientState _clientState;
private readonly ICommandManager _commandManager; private readonly ICommandManager _commandManager;
private readonly IconCache _iconCache;
private readonly IPluginLog _pluginLog; private readonly IPluginLog _pluginLog;
private readonly Dictionary<Guid, TemporaryConfig> _currentEditPopups = new(); private readonly Dictionary<Guid, TemporaryConfig> _currentEditPopups = new();
@ -51,6 +54,7 @@ internal sealed class ConfigWindow : Window
GameCache gameCache, GameCache gameCache,
IClientState clientState, IClientState clientState,
ICommandManager commandManager, ICommandManager commandManager,
IconCache iconCache,
IPluginLog pluginLog) IPluginLog pluginLog)
: base("ARC###ARControlConfig") : base("ARC###ARControlConfig")
{ {
@ -59,6 +63,7 @@ internal sealed class ConfigWindow : Window
_gameCache = gameCache; _gameCache = gameCache;
_clientState = clientState; _clientState = clientState;
_commandManager = commandManager; _commandManager = commandManager;
_iconCache = iconCache;
_pluginLog = pluginLog; _pluginLog = pluginLog;
SizeConstraints = new() SizeConstraints = new()
@ -80,7 +85,7 @@ internal sealed class ConfigWindow : Window
} }
} }
private unsafe void DrawVentureLists() private void DrawVentureLists()
{ {
if (ImGui.BeginTabItem("Venture Lists")) if (ImGui.BeginTabItem("Venture Lists"))
{ {
@ -102,7 +107,10 @@ internal sealed class ConfigWindow : Window
DrawVentureListEditorPopup(list, ref listToDelete); DrawVentureListEditorPopup(list, ref listToDelete);
ImGui.SameLine(); ImGui.SameLine();
if (ImGui.CollapsingHeader($"{list.Name} {(list.Type == Configuration.ListType.CollectOneTime ? SeIconChar.BoxedNumber1.ToIconChar() : SeIconChar.Circle.ToIconChar())}"))
string label = $"{list.Name} {list.GetIcon()}";
if (ImGui.CollapsingHeader(label))
{ {
ImGui.Indent(30); ImGui.Indent(30);
DrawVentureListItemSelection(list); DrawVentureListItemSelection(list);
@ -257,10 +265,10 @@ internal sealed class ConfigWindow : Window
private void DrawVentureListItemSelection(Configuration.ItemList list) private void DrawVentureListItemSelection(Configuration.ItemList list)
{ {
ImGuiEx.SetNextItemFullWidth(); ImGuiEx.SetNextItemFullWidth();
if (ImGui.BeginCombo($"##VentureSelection{list.Id}", "Add Item...")) if (ImGui.BeginCombo($"##VentureSelection{list.Id}", "Add Venture...", ImGuiComboFlags.HeightLarge))
{ {
ImGuiEx.SetNextItemFullWidth(); ImGuiEx.SetNextItemFullWidth();
ImGui.InputTextWithHint("", "Filter...", ref _searchString, 256); ImGui.InputTextWithHint("", "Filter...", ref _searchString, 256, ImGuiInputTextFlags.AutoSelectAll);
foreach (var ventures in _gameCache.Ventures foreach (var ventures in _gameCache.Ventures
.Where(x => x.Name.ToLower().Contains(_searchString.ToLower())) .Where(x => x.Name.ToLower().Contains(_searchString.ToLower()))
@ -270,6 +278,14 @@ internal sealed class ConfigWindow : Window
.GroupBy(x => x.ItemId)) .GroupBy(x => x.ItemId))
{ {
var venture = ventures.First(); var venture = ventures.First();
IDalamudTextureWrap? icon = _iconCache.GetIcon(venture.IconId);
if (icon != null)
{
ImGui.Image(icon.ImGuiHandle, new Vector2(23, 23));
ImGui.SameLine();
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + 3);
}
if (ImGui.Selectable( if (ImGui.Selectable(
$"{venture.Name} ({string.Join(" ", ventures.Select(x => x.CategoryName))})##SelectVenture{venture.RowId}")) $"{venture.Name} ({string.Join(" ", ventures.Select(x => x.CategoryName))})##SelectVenture{venture.RowId}"))
{ {
@ -278,7 +294,6 @@ internal sealed class ConfigWindow : Window
ItemId = venture.ItemId, ItemId = venture.ItemId,
RemainingQuantity = 0, RemainingQuantity = 0,
}); });
_searchString = string.Empty;
Save(); Save();
} }
} }
@ -286,7 +301,7 @@ internal sealed class ConfigWindow : Window
ImGui.EndCombo(); ImGui.EndCombo();
} }
ImGui.Separator(); ImGui.Spacing();
Configuration.QueuedItem? itemToRemove = null; Configuration.QueuedItem? itemToRemove = null;
Configuration.QueuedItem? itemToAdd = null; Configuration.QueuedItem? itemToAdd = null;
@ -299,6 +314,13 @@ internal sealed class ConfigWindow : Window
var ventures = _gameCache.Ventures.Where(x => x.ItemId == item.ItemId).ToList(); var ventures = _gameCache.Ventures.Where(x => x.ItemId == item.ItemId).ToList();
var venture = ventures.First(); var venture = ventures.First();
IDalamudTextureWrap? icon = _iconCache.GetIcon(venture.IconId);
if (icon != null)
{
ImGui.Image(icon.ImGuiHandle, new Vector2(23, 23));
ImGui.SameLine(0, 3);
}
ImGui.SetNextItemWidth(130); ImGui.SetNextItemWidth(130);
int quantity = item.RemainingQuantity; int quantity = item.RemainingQuantity;
if (ImGui.InputInt($"{venture.Name} ({string.Join(" ", ventures.Select(x => x.CategoryName))})", if (ImGui.InputInt($"{venture.Name} ({string.Join(" ", ventures.Select(x => x.CategoryName))})",
@ -349,6 +371,7 @@ internal sealed class ConfigWindow : Window
if (list.Items.Count > 0 && list.Type == Configuration.ListType.CollectOneTime) if (list.Items.Count > 0 && list.Type == Configuration.ListType.CollectOneTime)
{ {
ImGui.Spacing();
ImGui.BeginDisabled(list.Items.All(x => x.RemainingQuantity > 0)); ImGui.BeginDisabled(list.Items.All(x => x.RemainingQuantity > 0));
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Check, "Remove all finished items")) if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Check, "Remove all finished items"))
{ {
@ -356,8 +379,8 @@ internal sealed class ConfigWindow : Window
Save(); Save();
} }
ImGui.EndDisabled(); ImGui.EndDisabled();
ImGui.Spacing();
} }
ImGui.Spacing();
} }
private void DrawCharacters() private void DrawCharacters()
@ -479,8 +502,14 @@ internal sealed class ConfigWindow : Window
ImGui.BeginDisabled(retainer.Level < MaxLevel); ImGui.BeginDisabled(retainer.Level < MaxLevel);
bool managed = retainer.Managed && retainer.Level == MaxLevel; bool managed = retainer.Managed && retainer.Level == MaxLevel;
ImGui.Text(_gameCache.Jobs[retainer.Job]);
IDalamudTextureWrap? icon = _iconCache.GetIcon(62000 + retainer.Job);
if (icon != null)
{
ImGui.Image(icon.ImGuiHandle, new Vector2(23, 23));
ImGui.SameLine(); ImGui.SameLine();
}
if (ImGui.Checkbox($"{retainer.Name}###Retainer{retainer.Name}{retainer.DisplayOrder}", if (ImGui.Checkbox($"{retainer.Name}###Retainer{retainer.Name}{retainer.DisplayOrder}",
ref managed)) ref managed))
{ {
@ -643,7 +672,6 @@ internal sealed class ConfigWindow : Window
{ {
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
Name = _newGroup.Name, Name = _newGroup.Name,
Icon = FontAwesomeIcon.None,
ItemListIds = new(), ItemListIds = new(),
}); });
@ -868,8 +896,8 @@ internal sealed class ConfigWindow : Window
var list = itemLists[listIndex].List; var list = itemLists[listIndex].List;
ImGui.Indent(30); ImGui.Indent(30);
ImGui.Text(list.Type == Configuration.ListType.CollectOneTime ImGui.Text(list.Type == Configuration.ListType.CollectOneTime
? $"{SeIconChar.BoxedNumber1.ToIconString()} Items on this list will be collected once." ? $"{list.GetIcon()} Items on this list will be collected once."
: $"{SeIconChar.Circle.ToIconString()} Items on this list will be kept in stock on each character."); : $"{list.GetIcon()} Items on this list will be kept in stock on each character.");
ImGui.Spacing(); ImGui.Spacing();
foreach (var item in list.Items) foreach (var item in list.Items)
{ {