From e4b3dd291486cb6e0ad7ec21717c06d13e063ac1 Mon Sep 17 00:00:00 2001 From: avail Date: Fri, 5 Jul 2024 21:18:47 +0200 Subject: [PATCH 1/2] net8 & update for api 10 --- WhereIsMyMouse/Configuration.cs | 14 ++------- WhereIsMyMouse/Plugin.cs | 44 +++++++++++++++------------- WhereIsMyMouse/PluginUI.cs | 21 ++++++------- WhereIsMyMouse/WhereIsMyMouse.csproj | 4 +-- WhereIsMyMouse/packages.lock.json | 8 ++--- 5 files changed, 41 insertions(+), 50 deletions(-) diff --git a/WhereIsMyMouse/Configuration.cs b/WhereIsMyMouse/Configuration.cs index a02ac43..f180c32 100644 --- a/WhereIsMyMouse/Configuration.cs +++ b/WhereIsMyMouse/Configuration.cs @@ -1,6 +1,7 @@ using Dalamud.Configuration; using Dalamud.Plugin; using System; +using System.Diagnostics; using System.Numerics; namespace WhereIsMyMouse @@ -26,19 +27,10 @@ public class Configuration : IPluginConfiguration public Vector4 Color = new Vector4(1, 0, 0, 1); - // the below exist just to make saving less cumbersome - - [NonSerialized] - private DalamudPluginInterface? pluginInterface; - - public void Initialize(DalamudPluginInterface pluginInterface) - { - this.pluginInterface = pluginInterface; - } - public void Save() { - this.pluginInterface!.SavePluginConfig(this); + Trace.WriteLine("saving settings"); + Plugin.PluginInterface!.SavePluginConfig(this); } } } diff --git a/WhereIsMyMouse/Plugin.cs b/WhereIsMyMouse/Plugin.cs index 8399ab3..39fba06 100644 --- a/WhereIsMyMouse/Plugin.cs +++ b/WhereIsMyMouse/Plugin.cs @@ -4,6 +4,7 @@ using System.IO; using System.Reflection; using Dalamud.Plugin.Services; +using static FFXIVClientStructs.FFXIV.Client.UI.UIModule.Delegates; namespace WhereIsMyMouse { @@ -13,40 +14,37 @@ public sealed class Plugin : IDalamudPlugin private const string commandName = "/wmm"; - private DalamudPluginInterface PluginInterface { get; init; } - private ICommandManager CommandManager { get; init; } + [PluginService] internal static IDalamudPluginInterface PluginInterface { get; private set; } = null!; + [PluginService] internal static ICommandManager CommandManager { get; private set; } = null!; private Configuration Configuration { get; init; } private PluginUI PluginUi { get; init; } - private ICondition Condition { get; init; } + [PluginService] internal static ICondition Condition { get; private set; } = null!; - public Plugin( - [RequiredVersion("1.0")] DalamudPluginInterface pluginInterface, - [RequiredVersion("1.0")] ICommandManager commandManager, - [RequiredVersion("1.0")] ICondition condition) + public Plugin() { - this.PluginInterface = pluginInterface; - this.CommandManager = commandManager; - this.Condition = condition; - - this.Configuration = this.PluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); - this.Configuration.Initialize(this.PluginInterface); + this.Configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); - this.PluginUi = new PluginUI(this.Configuration, this.PluginInterface, this.Condition); + this.PluginUi = new PluginUI(this.Configuration); - this.CommandManager.AddHandler(commandName, new CommandInfo(OnCommand) + CommandManager.AddHandler(commandName, new CommandInfo(OnCommand) { HelpMessage = "Open Where's my mouse setting menu" }); - - this.PluginInterface.UiBuilder.Draw += DrawUI; + + + PluginInterface.UiBuilder.OpenConfigUi += ToggleUI; + PluginInterface.UiBuilder.Draw += Draw; } public void Dispose() { // Save config PluginInterface.SavePluginConfig(this.Configuration); - this.PluginInterface.UiBuilder.Draw -= DrawUI; - this.CommandManager.RemoveHandler(commandName); + + PluginInterface.UiBuilder.OpenConfigUi -= ToggleUI; + PluginInterface.UiBuilder.Draw -= Draw; + + CommandManager.RemoveHandler(commandName); this.PluginUi.Dispose(); } @@ -56,10 +54,14 @@ private void OnCommand(string command, string args) this.PluginUi.Visible = true; } - private void DrawUI() + private void Draw() { this.PluginUi.Draw(); } - + + private void ToggleUI() + { + this.PluginUi.ToggleUI(); + } } } diff --git a/WhereIsMyMouse/PluginUI.cs b/WhereIsMyMouse/PluginUI.cs index c95bc9d..07eba4a 100644 --- a/WhereIsMyMouse/PluginUI.cs +++ b/WhereIsMyMouse/PluginUI.cs @@ -11,9 +11,7 @@ using Dalamud.Plugin; using Dalamud.Plugin.Services; using FFXIVClientStructs.FFXIV.Client.Game.UI; -using FFXIVClientStructs.Interop.Attributes; using Lumina; -using Character = Dalamud.Game.ClientState.Objects.Types.Character; using StructsCharacter = FFXIVClientStructs.FFXIV.Client.Game.Character.Character; namespace WhereIsMyMouse @@ -23,8 +21,6 @@ namespace WhereIsMyMouse class PluginUI : IDisposable { private Configuration configuration; - - private DalamudPluginInterface wmmInterface; // this extra bool exists for ImGui, since you can't ref a property private bool visible = false; @@ -44,8 +40,6 @@ class PluginUI : IDisposable private float cycleSpeed = 0.10f; private Vector4 color = new Vector4(1, 0, 0, 1); - - private ICondition condition { get; init; } public bool Visible { @@ -53,11 +47,9 @@ public bool Visible set { this.visible = value; } } - public PluginUI(Configuration configuration, DalamudPluginInterface wmmInterface, ICondition condition) + public PluginUI(Configuration configuration) { this.configuration = configuration; - this.wmmInterface = wmmInterface; - this.condition = condition; this.thickness = this.configuration.Thickness; this.color = this.configuration.Color; this.size = this.configuration.Size; @@ -74,8 +66,13 @@ public void Dispose() public void Draw() { - DrawMainWindow(); CursorAura(); + DrawMainWindow(); + } + + public void ToggleUI() + { + Visible = !Visible; } public void CursorAura() @@ -85,7 +82,7 @@ public void CursorAura() return; } - if (EnableInCombatOnly && !this.condition[ConditionFlag.InCombat]) + if (EnableInCombatOnly && !Plugin.Condition[ConditionFlag.InCombat]) { return; } @@ -127,7 +124,7 @@ public void SaveSettings() this.configuration.ForegroundCursor = this.ForegroundCursor; this.configuration.EnableInCombatOnly = this.EnableInCombatOnly; this.configuration.Rainbow = this.Rainbow; - wmmInterface.SavePluginConfig(this.configuration); + Plugin.PluginInterface.SavePluginConfig(this.configuration); } diff --git a/WhereIsMyMouse/WhereIsMyMouse.csproj b/WhereIsMyMouse/WhereIsMyMouse.csproj index 83d1bca..0bbc6e0 100644 --- a/WhereIsMyMouse/WhereIsMyMouse.csproj +++ b/WhereIsMyMouse/WhereIsMyMouse.csproj @@ -11,7 +11,7 @@ - net7.0-windows + net8.0-windows x64 enable latest @@ -26,7 +26,7 @@ - + $(DalamudLibPath)FFXIVClientStructs.dll false diff --git a/WhereIsMyMouse/packages.lock.json b/WhereIsMyMouse/packages.lock.json index 6cf1c73..19fcea9 100644 --- a/WhereIsMyMouse/packages.lock.json +++ b/WhereIsMyMouse/packages.lock.json @@ -1,12 +1,12 @@ { "version": 1, "dependencies": { - "net7.0-windows7.0": { + "net8.0-windows7.0": { "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==" } } } From 15f011cf6e72954af8cba213eecce51301a54563 Mon Sep 17 00:00:00 2001 From: avail Date: Fri, 5 Jul 2024 21:21:21 +0200 Subject: [PATCH 2/2] remove unused function --- WhereIsMyMouse/Configuration.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/WhereIsMyMouse/Configuration.cs b/WhereIsMyMouse/Configuration.cs index f180c32..e3266fb 100644 --- a/WhereIsMyMouse/Configuration.cs +++ b/WhereIsMyMouse/Configuration.cs @@ -26,11 +26,5 @@ public class Configuration : IPluginConfiguration public float CycleSpeed = 0.10f; public Vector4 Color = new Vector4(1, 0, 0, 1); - - public void Save() - { - Trace.WriteLine("saving settings"); - Plugin.PluginInterface!.SavePluginConfig(this); - } } }