From 188f0033fa3d0070e442a587acb9a1694ed75b95 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Wed, 4 Oct 2023 12:27:31 +0200 Subject: [PATCH] API 9 --- ARControl/ARControl.csproj | 13 +---- ARControl/ARControl.json | 2 +- ARControl/AutoRetainerControlPlugin.Sync.cs | 3 +- ARControl/AutoRetainerControlPlugin.cs | 54 ++++++++++----------- ARControl/Configuration.cs | 3 +- ARControl/GameData/GameCache.cs | 4 +- ARControl/GameData/ItemToGather.cs | 4 +- ARControl/GameData/Venture.cs | 4 +- ARControl/GameData/VentureResolver.cs | 15 +++--- ARControl/Windows/ConfigWindow.cs | 37 +++++++++----- ARControl/packages.lock.json | 12 ++--- 11 files changed, 75 insertions(+), 76 deletions(-) diff --git a/ARControl/ARControl.csproj b/ARControl/ARControl.csproj index 50b6ec1..e952dcd 100644 --- a/ARControl/ARControl.csproj +++ b/ARControl/ARControl.csproj @@ -16,7 +16,7 @@ $(appdata)\XIVLauncher\addon\Hooks\dev\ - $(appdata)\XIVLauncher\installedPlugins\AutoRetainer\4.1.2.5\ + $(appdata)\XIVLauncher\installedPlugins\AutoRetainer\4.2.0.2\ @@ -24,8 +24,7 @@ - - + @@ -37,10 +36,6 @@ $(DalamudLibPath)ImGui.NET.dll false - - $(DalamudLibPath)ImGuiScene.dll - false - $(DalamudLibPath)Lumina.dll false @@ -57,10 +52,6 @@ $(DalamudLibPath)FFXIVClientStructs.dll false - - $(DalamudLibPath)FFXIVClientStructs.dll - false - $(AutoRetainerLibPath)AutoRetainerAPI.dll diff --git a/ARControl/ARControl.json b/ARControl/ARControl.json index 27b4902..3318fb2 100644 --- a/ARControl/ARControl.json +++ b/ARControl/ARControl.json @@ -1,7 +1,7 @@ { "Name": "ARC", "Author": "Liza Carvelli", - "Punchline": "Better AutoRetainer Venture Distribution", + "Punchline": "Better AutoRetainer Venture Planner", "Description": "", "RepoUrl": "https://git.carvel.li/liza/ARControl" } diff --git a/ARControl/AutoRetainerControlPlugin.Sync.cs b/ARControl/AutoRetainerControlPlugin.Sync.cs index 28acc2e..45a5fa4 100644 --- a/ARControl/AutoRetainerControlPlugin.Sync.cs +++ b/ARControl/AutoRetainerControlPlugin.Sync.cs @@ -1,5 +1,4 @@ using System.Linq; -using Dalamud.Logging; namespace ARControl; @@ -12,7 +11,7 @@ partial class AutoRetainerControlPlugin // FIXME This should have a way to get blacklisted character ids foreach (ulong registeredCharacterId in _autoRetainerApi.GetRegisteredCharacters()) { - PluginLog.Information($"ch → {registeredCharacterId:X}"); + _pluginLog.Verbose($"Sync for character {registeredCharacterId:X}"); var offlineCharacterData = _autoRetainerApi.GetOfflineCharacterData(registeredCharacterId); if (offlineCharacterData.ExcludeRetainer) continue; diff --git a/ARControl/AutoRetainerControlPlugin.cs b/ARControl/AutoRetainerControlPlugin.cs index f2b4372..e425186 100644 --- a/ARControl/AutoRetainerControlPlugin.cs +++ b/ARControl/AutoRetainerControlPlugin.cs @@ -4,15 +4,12 @@ using System.Linq; using ARControl.GameData; using ARControl.Windows; using AutoRetainerAPI; -using Dalamud.Data; -using Dalamud.Game.ClientState; using Dalamud.Game.Command; -using Dalamud.Game.Gui; using Dalamud.Interface; using Dalamud.Interface.Components; using Dalamud.Interface.Windowing; -using Dalamud.Logging; using Dalamud.Plugin; +using Dalamud.Plugin.Services; using ECommons; using ImGuiNET; @@ -24,9 +21,10 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin private readonly WindowSystem _windowSystem = new(nameof(AutoRetainerControlPlugin)); private readonly DalamudPluginInterface _pluginInterface; - private readonly ClientState _clientState; - private readonly ChatGui _chatGui; - private readonly CommandManager _commandManager; + private readonly IClientState _clientState; + private readonly IChatGui _chatGui; + private readonly ICommandManager _commandManager; + private readonly IPluginLog _pluginLog; private readonly Configuration _configuration; private readonly GameCache _gameCache; @@ -34,19 +32,20 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin private readonly ConfigWindow _configWindow; private readonly AutoRetainerApi _autoRetainerApi; - public AutoRetainerControlPlugin(DalamudPluginInterface pluginInterface, DataManager dataManager, - ClientState clientState, ChatGui chatGui, CommandManager commandManager) + public AutoRetainerControlPlugin(DalamudPluginInterface pluginInterface, IDataManager dataManager, + IClientState clientState, IChatGui chatGui, ICommandManager commandManager, IPluginLog pluginLog) { _pluginInterface = pluginInterface; _clientState = clientState; _chatGui = chatGui; _commandManager = commandManager; + _pluginLog = pluginLog; _configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration(); _gameCache = new GameCache(dataManager); - _ventureResolver = new VentureResolver(_gameCache); - _configWindow = new ConfigWindow(_pluginInterface, _configuration, _gameCache, _clientState, _commandManager); + _ventureResolver = new VentureResolver(_gameCache, _pluginLog); + _configWindow = new ConfigWindow(_pluginInterface, _configuration, _gameCache, _clientState, _commandManager, _pluginLog); _windowSystem.AddWindow(_configWindow); ECommonsMain.Init(_pluginInterface, this); @@ -57,54 +56,55 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin _autoRetainerApi.OnSendRetainerToVenture += SendRetainerToVenture; _autoRetainerApi.OnRetainerPostVentureTaskDraw += RetainerTaskButtonDraw; _clientState.TerritoryChanged += TerritoryChanged; - _commandManager.AddHandler("/arc", new CommandInfo(ProcessCommand)); + _commandManager.AddHandler("/arc", new CommandInfo(ProcessCommand) + { + HelpMessage = "Manage retainers" + }); if (_autoRetainerApi.Ready) Sync(); } - public string Name => "ARC"; - private void SendRetainerToVenture(string retainerName) { var ch = _configuration.Characters.SingleOrDefault(x => x.LocalContentId == _clientState.LocalContentId); if (ch == null) { - PluginLog.Information("No character information found"); + _pluginLog.Information("No character information found"); } else if (!ch.Managed) { - PluginLog.Information("Character is not managed"); + _pluginLog.Information("Character is not managed"); } else { var retainer = ch.Retainers.SingleOrDefault(x => x.Name == retainerName); if (retainer == null) { - PluginLog.Information("No retainer information found"); + _pluginLog.Information("No retainer information found"); } else if (!retainer.Managed) { - PluginLog.Information("Retainer is not managed"); + _pluginLog.Information("Retainer is not managed"); } else { - PluginLog.Information("Checking tasks..."); + _pluginLog.Information("Checking tasks..."); Sync(); foreach (var queuedItem in _configuration.QueuedItems.Where(x => x.RemainingQuantity > 0)) { - PluginLog.Information($"Checking venture info for itemId {queuedItem.ItemId}"); + _pluginLog.Information($"Checking venture info for itemId {queuedItem.ItemId}"); var (venture, reward) = _ventureResolver.ResolveVenture(ch, retainer, queuedItem); if (reward == null) { - PluginLog.Information("Retainer can't complete venture"); + _pluginLog.Information("Retainer can't complete venture"); } else { _chatGui.Print( - $"ARC → Overriding venture to collect {reward.Quantity}x {venture!.Name}."); - PluginLog.Information( + $"[ARC] Sending retainer {retainerName} to collect {reward.Quantity}x {venture!.Name}."); + _pluginLog.Information( $"Setting AR to use venture {venture.RowId}, which should retrieve {reward.Quantity}x {venture.Name}"); _autoRetainerApi.SetVenture(venture.RowId); @@ -119,15 +119,15 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin // fallback: managed but no venture found if (retainer.LastVenture != 395) { - _chatGui.Print("ARC → No tasks left, using QC"); - PluginLog.Information($"No tasks left (previous venture = {retainer.LastVenture}), using QC"); + _chatGui.Print($"[ARC] No tasks left for retainer {retainerName}, sending to Quick Venture."); + _pluginLog.Information($"No tasks left (previous venture = {retainer.LastVenture}), using QC"); _autoRetainerApi.SetVenture(395); retainer.LastVenture = 395; _pluginInterface.SavePluginConfig(_configuration); } else - PluginLog.Information("Not changing venture plan, already 395"); + _pluginLog.Information("Not changing venture plan, already 395"); } } } @@ -148,7 +148,7 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin ImGuiComponents.IconButton(FontAwesomeIcon.Book); } - private void TerritoryChanged(object? sender, ushort e) => Sync(); + private void TerritoryChanged(ushort e) => Sync(); private void ProcessCommand(string command, string arguments) { diff --git a/ARControl/Configuration.cs b/ARControl/Configuration.cs index 77f1797..06eae06 100644 --- a/ARControl/Configuration.cs +++ b/ARControl/Configuration.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Dalamud.Configuration; namespace ARControl; diff --git a/ARControl/GameData/GameCache.cs b/ARControl/GameData/GameCache.cs index f375782..1753dc8 100644 --- a/ARControl/GameData/GameCache.cs +++ b/ARControl/GameData/GameCache.cs @@ -1,13 +1,13 @@ using System.Collections.Generic; using System.Linq; -using Dalamud.Data; +using Dalamud.Plugin.Services; using Lumina.Excel.GeneratedSheets; namespace ARControl.GameData; internal sealed class GameCache { - public GameCache(DataManager dataManager) + public GameCache(IDataManager dataManager) { Jobs = dataManager.GetExcelSheet()!.ToDictionary(x => x.RowId, x => x.Abbreviation.ToString()); Ventures = dataManager.GetExcelSheet()! diff --git a/ARControl/GameData/ItemToGather.cs b/ARControl/GameData/ItemToGather.cs index 1297e27..2cb69cd 100644 --- a/ARControl/GameData/ItemToGather.cs +++ b/ARControl/GameData/ItemToGather.cs @@ -1,11 +1,11 @@ -using Dalamud.Data; +using Dalamud.Plugin.Services; using Lumina.Excel.GeneratedSheets; namespace ARControl.GameData; internal sealed class ItemToGather { - public ItemToGather(DataManager dataManager, GatheringItem item) + public ItemToGather(IDataManager dataManager, GatheringItem item) { GatheredItemId = item.RowId; ItemId = item.Item; diff --git a/ARControl/GameData/Venture.cs b/ARControl/GameData/Venture.cs index 7258f22..433ef57 100644 --- a/ARControl/GameData/Venture.cs +++ b/ARControl/GameData/Venture.cs @@ -1,12 +1,12 @@ using System.Collections.Generic; -using Dalamud.Data; +using Dalamud.Plugin.Services; using Lumina.Excel.GeneratedSheets; namespace ARControl.GameData; internal sealed class Venture { - public Venture(DataManager dataManager, RetainerTask retainerTask) + public Venture(IDataManager dataManager, RetainerTask retainerTask) { RowId = retainerTask.RowId; Category = retainerTask.ClassJobCategory.Value!; diff --git a/ARControl/GameData/VentureResolver.cs b/ARControl/GameData/VentureResolver.cs index f98550d..b7fa025 100644 --- a/ARControl/GameData/VentureResolver.cs +++ b/ARControl/GameData/VentureResolver.cs @@ -1,16 +1,17 @@ -using System; -using System.Linq; -using Dalamud.Logging; +using System.Linq; +using Dalamud.Plugin.Services; namespace ARControl.GameData; internal sealed class VentureResolver { private readonly GameCache _gameCache; + private readonly IPluginLog _pluginLog; - public VentureResolver(GameCache gameCache) + public VentureResolver(GameCache gameCache, IPluginLog pluginLog) { _gameCache = gameCache; + _pluginLog = pluginLog; } public (Venture?, VentureReward?) ResolveVenture(Configuration.CharacterConfiguration character, @@ -21,18 +22,18 @@ internal sealed class VentureResolver .FirstOrDefault(x => x.ItemId == queuedItem.ItemId && x.MatchesJob(retainer.Job)); if (venture == null) { - PluginLog.Information($"No applicable venture found for itemId {queuedItem.ItemId}"); + _pluginLog.Information($"No applicable venture found for itemId {queuedItem.ItemId}"); return (null, null); } var itemToGather = _gameCache.ItemsToGather.FirstOrDefault(x => x.ItemId == queuedItem.ItemId); if (itemToGather != null && !character.GatheredItems.Contains(itemToGather.GatheredItemId)) { - PluginLog.Information($"Character hasn't gathered {venture.Name} yet"); + _pluginLog.Information($"Character hasn't gathered {venture.Name} yet"); return (null, null); } - PluginLog.Information( + _pluginLog.Information( $"Found venture {venture.Name}, row = {venture.RowId}, checking if it is suitable"); VentureReward? reward = null; if (venture.CategoryName is "MIN" or "BTN") diff --git a/ARControl/Windows/ConfigWindow.cs b/ARControl/Windows/ConfigWindow.cs index a3e08cb..c1cb8be 100644 --- a/ARControl/Windows/ConfigWindow.cs +++ b/ARControl/Windows/ConfigWindow.cs @@ -2,15 +2,12 @@ using System.Linq; using System.Numerics; using ARControl.GameData; -using Dalamud.Game.ClientState; -using Dalamud.Game.Command; using Dalamud.Interface; using Dalamud.Interface.Colors; using Dalamud.Interface.Components; -using Dalamud.Interface.Style; using Dalamud.Interface.Windowing; -using Dalamud.Logging; using Dalamud.Plugin; +using Dalamud.Plugin.Services; using ECommons.ImGuiMethods; using ImGuiNET; @@ -27,8 +24,9 @@ internal sealed class ConfigWindow : Window private readonly DalamudPluginInterface _pluginInterface; private readonly Configuration _configuration; private readonly GameCache _gameCache; - private readonly ClientState _clientState; - private readonly CommandManager _commandManager; + private readonly IClientState _clientState; + private readonly ICommandManager _commandManager; + private readonly IPluginLog _pluginLog; private string _searchString = string.Empty; private Configuration.QueuedItem? _dragDropSource; @@ -40,8 +38,9 @@ internal sealed class ConfigWindow : Window DalamudPluginInterface pluginInterface, Configuration configuration, GameCache gameCache, - ClientState clientState, - CommandManager commandManager) + IClientState clientState, + ICommandManager commandManager, + IPluginLog pluginLog) : base("ARC###ARControlConfig") { _pluginInterface = pluginInterface; @@ -49,6 +48,7 @@ internal sealed class ConfigWindow : Window _gameCache = gameCache; _clientState = clientState; _commandManager = commandManager; + _pluginLog = pluginLog; } public override void Draw() @@ -66,7 +66,7 @@ internal sealed class ConfigWindow : Window { if (ImGui.BeginTabItem("Venture Queue")) { - if (ImGui.BeginCombo("Venture...##VentureSelection", "")) + if (ImGui.BeginCombo("Add Item...##VentureSelection", "")) { ImGuiEx.SetNextItemFullWidth(); ImGui.InputTextWithHint("", "Filter...", ref _searchString, 256); @@ -95,7 +95,6 @@ internal sealed class ConfigWindow : Window ImGui.EndCombo(); } - ImGui.Checkbox("Enable Drag&Drop", ref _enableDragDrop); ImGui.Separator(); ImGui.Indent(30); @@ -167,13 +166,29 @@ internal sealed class ConfigWindow : Window if (itemToAdd != null) { - PluginLog.Information($"Updating {itemToAdd.ItemId} → {indexToAdd}"); + _pluginLog.Information($"Updating {itemToAdd.ItemId} → {indexToAdd}"); _configuration.QueuedItems.Remove(itemToAdd); _configuration.QueuedItems.Insert(indexToAdd, itemToAdd); Save(); } ImGui.Unindent(30); + + if (_configuration.QueuedItems.Count > 0) + ImGui.Separator(); + + if (ImGuiComponents.IconButtonWithText(_enableDragDrop ? FontAwesomeIcon.Times : FontAwesomeIcon.Sort, _enableDragDrop ? "Disable Drag&Drop" : "Enable Drag&Drop")) + { + _enableDragDrop = !_enableDragDrop; + } + + ImGui.SameLine(); + if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Check, "Remove all finished items")) + { + if (_configuration.QueuedItems.RemoveAll(q => q.RemainingQuantity == 0) > 0) + Save(); + } + ImGui.EndTabItem(); } } diff --git a/ARControl/packages.lock.json b/ARControl/packages.lock.json index 6bf9223..6cf1c73 100644 --- a/ARControl/packages.lock.json +++ b/ARControl/packages.lock.json @@ -2,17 +2,11 @@ "version": 1, "dependencies": { "net7.0-windows7.0": { - "Dalamud.ContextMenu": { - "type": "Direct", - "requested": "[1.2.3, )", - "resolved": "1.2.3", - "contentHash": "ydemplF7DNcA/LLeongDVzWUD/JV0Fw3EwA2+P0jYq3Le2ZYSt4U8qyJq4FyoChqt0lFG8BxYCAzfeWp4Jmnqw==" - }, "DalamudPackager": { "type": "Direct", - "requested": "[2.1.11, )", - "resolved": "2.1.11", - "contentHash": "9qlAWoRRTiL/geAvuwR/g6Bcbrd/bJJgVnB/RurBiyKs6srsP0bvpoo8IK+Eg8EA6jWeM6/YJWs66w4FIAzqPw==" + "requested": "[2.1.12, )", + "resolved": "2.1.12", + "contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg==" } } }