From 30b8d5d5ac518a6bdf5d20981f6c10b74c8846e8 Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 1 Jul 2024 20:52:09 -0400 Subject: [PATCH] refactor: update for api 10 --- QuestMap/Node.cs | 10 +++--- QuestMap/Plugin.cs | 6 +--- QuestMap/PluginUi.cs | 71 ++++++++++++++++--------------------- QuestMap/QuestMap.csproj | 11 +++--- QuestMap/Quests.cs | 7 ++-- QuestMap/packages.lock.json | 20 ++++------- 6 files changed, 54 insertions(+), 71 deletions(-) mode change 100644 => 100755 QuestMap/packages.lock.json diff --git a/QuestMap/Node.cs b/QuestMap/Node.cs index a73f705..3d76060 100644 --- a/QuestMap/Node.cs +++ b/QuestMap/Node.cs @@ -8,7 +8,7 @@ namespace QuestMap { internal uint Id { get; } internal List> Parents { get; set; } internal T Value { get; set; } - internal List> Children { get; } = new(); + internal List> Children { get; } = []; internal Node(List> parents, uint id, T value) { this.Id = id; @@ -18,7 +18,7 @@ namespace QuestMap { private Node(uint id) { this.Id = id; - this.Parents = new List>(); + this.Parents = []; this.Value = default!; } @@ -58,7 +58,7 @@ namespace QuestMap { var consolidated = consolidator(parent.Value); parents.Push(consolidated == null ? parent - : new Node(new List>(), parent.Id, consolidated) { + : new Node([], parent.Id, consolidated) { Children = { this }, }); } @@ -70,7 +70,7 @@ namespace QuestMap { var consolidated = consolidator(parent.Value); parents.Push(consolidated == null ? parent - : new Node(new List>(), parent.Id, consolidated) { + : new Node([], parent.Id, consolidated) { Children = { next }, }); } @@ -110,7 +110,7 @@ namespace QuestMap { if (lookup.TryGetValue(item.Key, out var ourNode)) { ourNode.Value = item.Value; } else { - ourNode = new Node(new List>(), item.Key, item.Value); + ourNode = new Node([], item.Key, item.Value); lookup[item.Key] = ourNode; allNodes[item.Key] = ourNode; } diff --git a/QuestMap/Plugin.cs b/QuestMap/Plugin.cs index 9dd21bc..e89e305 100644 --- a/QuestMap/Plugin.cs +++ b/QuestMap/Plugin.cs @@ -2,7 +2,6 @@ using Dalamud.IoC; using Dalamud.Plugin; using Dalamud.Plugin.Services; -using XivCommon; namespace QuestMap { // ReSharper disable once ClassNeverInstantiated.Global @@ -10,7 +9,7 @@ namespace QuestMap { internal static string Name => "Quest Map"; [PluginService] - internal DalamudPluginInterface Interface { get; init; } = null!; + internal IDalamudPluginInterface Interface { get; init; } = null!; [PluginService] internal IClientState ClientState { get; init; } = null!; @@ -27,14 +26,12 @@ namespace QuestMap { [PluginService] internal ITextureProvider TextureProvider { get; init; } = null!; - internal XivCommonBase Common { get; } internal Configuration Config { get; } internal Quests Quests { get; } internal PluginUi Ui { get; } private Commands Commands { get; } public Plugin() { - this.Common = new XivCommonBase(this.Interface); this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration(); var graphChannel = Channel.CreateUnbounded(); @@ -47,7 +44,6 @@ namespace QuestMap { public void Dispose() { this.Commands.Dispose(); this.Ui.Dispose(); - this.Common.Dispose(); } internal void SaveConfig() { diff --git a/QuestMap/PluginUi.cs b/QuestMap/PluginUi.cs index 380ff8f..1bd6548 100644 --- a/QuestMap/PluginUi.cs +++ b/QuestMap/PluginUi.cs @@ -5,11 +5,14 @@ using System.Numerics; using System.Reflection; using System.Threading; using System.Threading.Channels; -using Dalamud; +using Dalamud.Game; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Interface; -using Dalamud.Interface.Internal; +using Dalamud.Interface.Textures; +using Dalamud.Interface.Textures.TextureWraps; +using FFXIVClientStructs.FFXIV.Client.Game; +using FFXIVClientStructs.FFXIV.Client.UI.Agent; using ImGuiNET; using Lumina.Data; using Lumina.Excel; @@ -40,9 +43,8 @@ namespace QuestMap { private Node? Centre { get; set; } private ChannelReader GraphChannel { get; } private CancellationTokenSource? CancellationTokenSource { get; set; } - private HashSet InfoWindows { get; } = new(); - private Dictionary Icons { get; } = new(); - private List<(Quest, bool, string)> FilteredQuests { get; } = new(); + private HashSet InfoWindows { get; } = []; + private List<(Quest, bool, string)> FilteredQuests { get; } = []; internal bool Show; @@ -67,17 +69,13 @@ namespace QuestMap { public void Dispose() { this.Plugin.Interface.UiBuilder.OpenConfigUi -= this.OpenConfig; this.Plugin.Interface.UiBuilder.Draw -= this.Draw; - - foreach (var icon in this.Icons.Values) { - icon.Dispose(); - } } private void OpenConfig() { this.Show = true; } - private void Refilter() { + private unsafe void Refilter() { this.FilteredQuests.Clear(); var filterLower = this._filter.ToLowerInvariant(); @@ -91,7 +89,7 @@ namespace QuestMap { return false; } - var completed = this.Plugin.Common.Functions.Journal.IsQuestCompleted(quest); + var completed = QuestManager.IsQuestComplete(quest.RowId); if (!this.Plugin.Config.ShowCompleted && completed) { return false; } @@ -191,7 +189,7 @@ namespace QuestMap { this.DrawMainWindow(); } - private void DrawMainWindow() { + private unsafe void DrawMainWindow() { if (!this.Show) { return; } @@ -289,13 +287,9 @@ namespace QuestMap { var (quest, indent, drawItem) = this.FilteredQuests[row]; void DrawSelectable(string name, Quest quest) { - var completed = this.Plugin.Common.Functions.Journal.IsQuestCompleted(quest); + var completed = QuestManager.IsQuestComplete(quest.RowId); if (completed) { - Vector4 disabled; - unsafe { - disabled = *ImGui.GetStyleColorVec4(ImGuiCol.TextDisabled); - } - + var disabled = *ImGui.GetStyleColorVec4(ImGuiCol.TextDisabled); ImGui.PushStyleColor(ImGuiCol.Text, disabled); } @@ -385,7 +379,7 @@ namespace QuestMap { return !open; } - var completed = this.Plugin.Common.Functions.Journal.IsQuestCompleted(quest); + var completed = QuestManager.IsQuestComplete(quest.RowId); ImGui.TextUnformatted($"Level: {quest.ClassJobLevel0}"); @@ -399,16 +393,7 @@ namespace QuestMap { } IDalamudTextureWrap? GetIcon(uint id) { - if (this.Icons.TryGetValue(id, out var wrap)) { - return wrap; - } - - wrap = this.Plugin.TextureProvider.GetIcon(id); - if (wrap != null) { - this.Icons[id] = wrap; - } - - return wrap; + return this.Plugin.TextureProvider.GetFromGameIcon(new GameIconLookup(id)).GetWrapOrDefault(); } var textWrap = ImGui.GetFontSize() * 20f; @@ -417,7 +402,7 @@ namespace QuestMap { var header = GetIcon(quest.Icon); if (header != null) { textWrap = header.Width; - ImGui.Image(header.ImGuiHandle, new Vector2(header.Width, header.Height)); + ImGui.Image(header.ImGuiHandle, new Vector2(header.Width / 2f, header.Height / 2f)); } } @@ -452,8 +437,8 @@ namespace QuestMap { var maxHeight = items .Select(entry => GetIcon(entry.icon)) - .Where(image => image != null) - .Max(image => image!.Height); + .Select(image => image?.Height ?? 0) + .Max(height => height / 2f); var originalY = ImGui.GetCursorPosY(); foreach (var (name, icon, qty) in items) { @@ -463,7 +448,7 @@ namespace QuestMap { ImGui.SetCursorPosY(originalY + (maxHeight - image.Height) / 2f); } - ImGui.Image(image.ImGuiHandle, new Vector2(image.Width, image.Height)); + ImGui.Image(image.ImGuiHandle, new Vector2(image.Width / 2f, image.Height / 2f)); Util.Tooltip(name.ToString()); } @@ -563,7 +548,7 @@ namespace QuestMap { if (icon > 0) { var image = GetIcon(icon); if (image != null) { - ImGui.Image(image.ImGuiHandle, new Vector2(image.Width, image.Height)); + ImGui.Image(image.ImGuiHandle, new Vector2(image.Width / 2f, image.Height / 2f)); Util.Tooltip(this.Convert(instance.Name).ToString()); } } else { @@ -583,7 +568,7 @@ namespace QuestMap { var image = GetIcon(tribe.Icon); if (image != null) { - ImGui.Image(image.ImGuiHandle, new Vector2(image.Width, image.Height)); + ImGui.Image(image.ImGuiHandle, new Vector2(image.Width / 2f, image.Height / 2f)); Util.Tooltip(this.Convert(tribe.Name).ToString()); } @@ -606,11 +591,11 @@ namespace QuestMap { // ReSharper disable once ConstantConditionalAccessQualifier .MakeGenericMethod(typeof(QuestData))? // ReSharper disable once ConstantConditionalAccessQualifier - .Invoke(this.Plugin.DataManager.Excel, new object?[] { + .Invoke(this.Plugin.DataManager.Excel, [ path, lang, null, - }) as ExcelSheet; + ]) as ExcelSheet; // default to english if reflection failed sheet ??= this.Plugin.DataManager.Excel.GetSheet(path); var firstData = sheet?.GetRow(0); @@ -657,7 +642,9 @@ namespace QuestMap { ImGui.SameLine(); if (Util.IconButton(FontAwesomeIcon.Book)) { - this.Plugin.Common.Functions.Journal.OpenQuest(quest); + unsafe { + AgentQuestJournal.Instance()->OpenForQuest(quest.RowId & 0xFFFF, 1); + } } Util.Tooltip("Open quest in Journal"); @@ -836,7 +823,7 @@ namespace QuestMap { }; var textColour = Colours.Text; - var completed = this.Plugin.Common.Functions.Journal.IsQuestCompleted(quest.RowId); + var completed = QuestManager.IsQuestComplete(quest.RowId); if (completed) { colour.W = .5f; textColour = (uint) ((0x80 << 24) | (textColour & 0xFFFFFF)); @@ -885,7 +872,9 @@ namespace QuestMap { } if (right) { - this.Plugin.Common.Functions.Journal.OpenQuest(id); + unsafe { + AgentQuestJournal.Instance()->OpenForQuest(id, 1); + } } break; @@ -901,7 +890,7 @@ namespace QuestMap { // ImGui.SetCursorPosY(ImGui.GetCursorPosY() + 5); } - private static readonly byte[] NewLinePayload = { 0x02, 0x10, 0x01, 0x03 }; + private static readonly byte[] NewLinePayload = [0x02, 0x10, 0x01, 0x03]; private SeString Convert(Lumina.Text.SeString lumina) { var se = (SeString) lumina; diff --git a/QuestMap/QuestMap.csproj b/QuestMap/QuestMap.csproj index 90d6ca4..5eada87 100755 --- a/QuestMap/QuestMap.csproj +++ b/QuestMap/QuestMap.csproj @@ -1,7 +1,7 @@ - net7-windows + net8-windows QuestMap 1.4.7 enable @@ -33,6 +33,10 @@ $(DalamudLibPath)\ImGui.NET.dll False + + $(DalamudLibPath)\FFXIVClientStructs.dll + False + $(DalamudLibPath)\Lumina.dll False @@ -45,9 +49,8 @@ - - - + + diff --git a/QuestMap/Quests.cs b/QuestMap/Quests.cs index 9925bf3..9516b65 100644 --- a/QuestMap/Quests.cs +++ b/QuestMap/Quests.cs @@ -62,7 +62,7 @@ namespace QuestMap { if (itemRewards.TryGetValue(quest.RowId, out var items)) { rewards = items; } else { - rewards = new List(); + rewards = []; itemRewards[quest.RowId] = rewards; } @@ -76,7 +76,7 @@ namespace QuestMap { if (itemRewards.TryGetValue(quest.RowId, out var items)) { rewards = items; } else { - rewards = new List(); + rewards = []; itemRewards[quest.RowId] = rewards; } @@ -254,6 +254,7 @@ namespace QuestMap { 70214 => "Gods Revel, Lands Tremble (6.3)", 70279 => "The Dark Throne (6.4)", 70286 => "Growing Light (6.5)", + 70495 => "Dawntrail (7.0)", _ => null, }; @@ -272,7 +273,7 @@ namespace QuestMap { private HashSet InstanceUnlocks(Quest quest, ICollection others) { if (quest.IsRepeatable) { - return new HashSet(); + return []; } var unlocks = new HashSet(); diff --git a/QuestMap/packages.lock.json b/QuestMap/packages.lock.json old mode 100644 new mode 100755 index 47af76d..64f3cfe --- a/QuestMap/packages.lock.json +++ b/QuestMap/packages.lock.json @@ -1,7 +1,7 @@ { "version": 1, "dependencies": { - "net7.0-windows7.0": { + "net8.0-windows7.0": { "AutomaticGraphLayout": { "type": "Direct", "requested": "[1.1.12, )", @@ -10,21 +10,15 @@ }, "DalamudPackager": { "type": "Direct", - "requested": "[2.1.12, )", - "resolved": "2.1.12", - "contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg==" + "requested": "[2.1.13, )", + "resolved": "2.1.13", + "contentHash": "rMN1omGe8536f4xLMvx9NwfvpAc9YFFfeXJ1t4P4PE6Gu8WCIoFliR1sh07hM+bfODmesk/dvMbji7vNI+B/pQ==" }, "System.Threading.Channels": { "type": "Direct", - "requested": "[7.0.0, )", - "resolved": "7.0.0", - "contentHash": "qmeeYNROMsONF6ndEZcIQ+VxR4Q/TX/7uIVLJqtwIWL7dDWeh0l1UIqgo4wYyjG//5lUNhwkLDSFl+pAWO6oiA==" - }, - "XivCommon": { - "type": "Direct", - "requested": "[9.0.0, )", - "resolved": "9.0.0", - "contentHash": "avaBp3FmSCi/PiQhntCeBDYOHejdyTWmFtz4pRBVQQ8vHkmRx+YTk1la9dkYBMlXxRXKckEdH1iI1Fu61JlE7w==" + "requested": "[8.0.0, )", + "resolved": "8.0.0", + "contentHash": "CMaFr7v+57RW7uZfZkPExsPB6ljwzhjACWW1gfU35Y56rk72B/Wu+sTqxVmGSk4SFUlPc3cjeKND0zktziyjBA==" } } }