diff --git a/WhereIsMyMouse/ConfigWindow.cs b/WhereIsMyMouse/ConfigWindow.cs new file mode 100644 index 0000000..992d0f7 --- /dev/null +++ b/WhereIsMyMouse/ConfigWindow.cs @@ -0,0 +1,86 @@ +using System; +using System.Numerics; +using Dalamud.Bindings.ImGui; +using Dalamud.Interface.Windowing; + +namespace WhereIsMyMouse; + +internal class ConfigWindow : Window, IDisposable +{ + private readonly Configuration _configuration; + + private bool _cursorOn; + private bool _foregroundCursor; + private bool _enableInCombatOnly; + private bool _rainbow; + private float _size; + private float _thickness; + private float _cycleSpeed; + private Vector4 _color; + + public ConfigWindow(Plugin plugin) : base("Where'sMyMouse Configuration###wheresmymouseconfig") + { + Flags = ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse; + + Size = new Vector2(375, 600); + SizeConstraints = new WindowSizeConstraints + { + MinimumSize = new Vector2(375, 600), + MaximumSize = new Vector2(float.MaxValue, float.MaxValue) + }; + SizeCondition = ImGuiCond.Appearing; + + _configuration = plugin.Configuration; + + _thickness = _configuration.Thickness; + _color = _configuration.Color; + _size = _configuration.Size; + _cycleSpeed = _configuration.CycleSpeed; + _cursorOn = _configuration.CursorOn; + _foregroundCursor = _configuration.ForegroundCursor; + _enableInCombatOnly = _configuration.EnableInCombatOnly; + _rainbow = _configuration.Rainbow; + } + + public void Dispose() { } + + public override void PreDraw() { } + + public override void Draw() + { + ImGui.Text("Cursor Aura : "); + ImGui.SameLine(); + ImGui.Checkbox("###CursorAura", ref _cursorOn); + ImGui.Text("Circle drawn in foreground : "); + ImGui.SameLine(); + ImGui.Checkbox("###ForegroundCursor", ref _foregroundCursor); + ImGui.Text("Circle Size : "); + ImGui.SameLine(); + ImGui.SliderFloat("###sizeslide", ref _size, 0f, 100f); + ImGui.Text("Thickness : "); + ImGui.SameLine(); + ImGui.SliderFloat("###thickslide", ref _thickness, 0f, 50f); + ImGui.ColorPicker4("###ColorPicker", ref _color); + ImGui.Text("Enable only in combat : "); + ImGui.SameLine(); + ImGui.Checkbox("###CombatOnlyEnable", ref _enableInCombatOnly); + ImGui.Text("Rainbow : "); + ImGui.SameLine(); + ImGui.Checkbox("###Rainbow", ref _rainbow); + ImGui.Text("Rainbow Cycle Speed : "); + ImGui.SliderFloat("###cyclespeedslide", ref _cycleSpeed, 0.01f, 1f); + // ReSharper disable once InvertIf + if (ImGui.Button("Save Settings")) + { + _configuration.Color = _color; + _configuration.Size = _size; + _configuration.Thickness = _thickness; + _configuration.CycleSpeed = _cycleSpeed; + _configuration.CursorOn = _cursorOn; + _configuration.ForegroundCursor = _foregroundCursor; + _configuration.EnableInCombatOnly = _enableInCombatOnly; + _configuration.Rainbow = _rainbow; + _configuration.Save(); + } + } +} \ No newline at end of file diff --git a/WhereIsMyMouse/Configuration.cs b/WhereIsMyMouse/Configuration.cs index e3266fb..3f37a35 100644 --- a/WhereIsMyMouse/Configuration.cs +++ b/WhereIsMyMouse/Configuration.cs @@ -1,30 +1,25 @@ using Dalamud.Configuration; -using Dalamud.Plugin; using System; -using System.Diagnostics; using System.Numerics; -namespace WhereIsMyMouse +namespace WhereIsMyMouse; + +[Serializable] +public class Configuration : IPluginConfiguration { - [Serializable] - public class Configuration : IPluginConfiguration + public int Version { get; set; } = 0; + + public bool CursorOn { get; set; } + public bool ForegroundCursor { get; set; } + public bool EnableInCombatOnly { get; set; } + public bool Rainbow { get; set; } + public float Size { get; set; } = 15; + public float Thickness { get; set; } = 2; + public float CycleSpeed { get; set; } = 0.10f; + public Vector4 Color { get; set; } = new(1, 0, 0, 1); + + public void Save() { - public int Version { get; set; } = 0; - - public bool CursorOn = false; - - public bool ForegroundCursor = false; - - public bool EnableInCombatOnly = false; - - public bool Rainbow = false; - - public float Size = 15; - - public float Thickness = 2; - - public float CycleSpeed = 0.10f; - - public Vector4 Color = new Vector4(1, 0, 0, 1); + Plugin.PluginInterface.SavePluginConfig(this); } -} +} \ No newline at end of file diff --git a/WhereIsMyMouse/MouseWindow.cs b/WhereIsMyMouse/MouseWindow.cs new file mode 100644 index 0000000..3bf5a07 --- /dev/null +++ b/WhereIsMyMouse/MouseWindow.cs @@ -0,0 +1,61 @@ +using System; +using System.Numerics; +using Dalamud.Bindings.ImGui; +using Dalamud.Game.ClientState.Conditions; +using Dalamud.Interface.Utility; +using Dalamud.Interface.Windowing; + +namespace WhereIsMyMouse; + +internal class MouseWindow : Window, IDisposable +{ + private readonly Plugin _plugin; + + public MouseWindow(Plugin plugin) : base("Mouse Window###CursorWindow", ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.NoFocusOnAppearing) + { + Size = new Vector2(300, 300); + + _plugin = plugin; + } + + public void Dispose() { } + + public override void Draw() + { + if (!_plugin.Configuration.CursorOn) + { + return; + } + + if (_plugin.Configuration.EnableInCombatOnly && !Plugin.Condition[ConditionFlag.InCombat]) + { + return; + } + + var color = _plugin.Configuration.Color; + if (_plugin.Configuration.Rainbow) + { + float h = 0, s = 0, v = 0; + float outr = 0, outg = 0, outb = 0; + ImGui.ColorConvertRGBtoHSV(color.X, color.Y, color.Z, ref h, ref s, ref v); + if (h >= 1) + { + h = 0; + } + h += _plugin.Configuration.CycleSpeed * ImGui.GetIO().DeltaTime; + ImGui.ColorConvertHSVtoRGB(h, s, v, ref outr, ref outg, ref outb); + color.X = outr; + color.Y = outg; + color.Z = outb; + _plugin.Configuration.Color = color; + } + + var cursorPos = ImGui.GetMousePos(); + ImGuiHelpers.ForceNextWindowMainViewport(); + ImGui.SetWindowPos(cursorPos - new Vector2(150,150)); + + var draw = _plugin.Configuration.ForegroundCursor ? ImGui.GetForegroundDrawList() : ImGui.GetWindowDrawList(); + + draw.AddCircle(cursorPos, _plugin.Configuration.Size, ImGui.ColorConvertFloat4ToU32(color), 0, _plugin.Configuration.Thickness); + } +} \ No newline at end of file diff --git a/WhereIsMyMouse/Plugin.cs b/WhereIsMyMouse/Plugin.cs index 39fba06..850e357 100644 --- a/WhereIsMyMouse/Plugin.cs +++ b/WhereIsMyMouse/Plugin.cs @@ -1,67 +1,73 @@ using Dalamud.Game.Command; using Dalamud.IoC; using Dalamud.Plugin; -using System.IO; -using System.Reflection; using Dalamud.Plugin.Services; -using static FFXIVClientStructs.FFXIV.Client.UI.UIModule.Delegates; +using Dalamud.Interface.Windowing; -namespace WhereIsMyMouse +namespace WhereIsMyMouse; + +public sealed class Plugin : IDalamudPlugin { - public sealed class Plugin : IDalamudPlugin - { - public string Name => "Where's my mouse"; + [PluginService] internal static IDalamudPluginInterface PluginInterface { get; private set; } = null!; + [PluginService] internal static ICommandManager CommandManager { get; private set; } = null!; + [PluginService] internal static ICondition Condition { get; private set; } = null!; - private const string commandName = "/wmm"; + private const string CommandName = "/wmm"; - [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; } - [PluginService] internal static ICondition Condition { get; private set; } = null!; + public Configuration Configuration { get; init; } - public Plugin() - { - this.Configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); + private readonly WindowSystem _windowSystem = new("WheresMyMouse"); + private ConfigWindow ConfigWindow { get; init; } + private MouseWindow MouseWindow { get; init; } + + public Plugin() + { + Configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); - this.PluginUi = new PluginUI(this.Configuration); + MouseWindow = new MouseWindow(this); - CommandManager.AddHandler(commandName, new CommandInfo(OnCommand) - { - HelpMessage = "Open Where's my mouse setting menu" - }); + ConfigWindow = new ConfigWindow(this); + CommandManager.AddHandler(CommandName, new CommandInfo(OnCommand) + { + HelpMessage = "Open Where's my mouse setting menu" + }); + _windowSystem.AddWindow(ConfigWindow); - PluginInterface.UiBuilder.OpenConfigUi += ToggleUI; - PluginInterface.UiBuilder.Draw += Draw; - } + PluginInterface.UiBuilder.OpenConfigUi += ToggleConfigUi; + PluginInterface.UiBuilder.OpenMainUi += ToggleConfigUi; + PluginInterface.UiBuilder.Draw += _windowSystem.Draw; + PluginInterface.UiBuilder.Draw += Draw; + } - public void Dispose() - { - // Save config - PluginInterface.SavePluginConfig(this.Configuration); + public void Dispose() + { + // Save config + PluginInterface.SavePluginConfig(Configuration); - PluginInterface.UiBuilder.OpenConfigUi -= ToggleUI; - PluginInterface.UiBuilder.Draw -= Draw; + PluginInterface.UiBuilder.OpenConfigUi -= ToggleConfigUi; + PluginInterface.UiBuilder.OpenMainUi -= ToggleConfigUi; + PluginInterface.UiBuilder.Draw -= _windowSystem.Draw; + PluginInterface.UiBuilder.Draw -= Draw; - CommandManager.RemoveHandler(commandName); - this.PluginUi.Dispose(); - } + _windowSystem.RemoveAllWindows(); - private void OnCommand(string command, string args) - { - // in response to the slash command, just display our main ui - this.PluginUi.Visible = true; - } + ConfigWindow.Dispose(); + MouseWindow.Dispose(); - private void Draw() - { - this.PluginUi.Draw(); - } + CommandManager.RemoveHandler(CommandName); + } - private void ToggleUI() - { - this.PluginUi.ToggleUI(); - } + private void OnCommand(string command, string args) + { + // in response to the slash command, just display our main ui + ConfigWindow.Toggle(); } -} + + private void Draw() + { + MouseWindow.Draw(); + } + + private void ToggleConfigUi() => ConfigWindow.Toggle(); +} \ No newline at end of file diff --git a/WhereIsMyMouse/PluginUI.cs b/WhereIsMyMouse/PluginUI.cs deleted file mode 100644 index 0779e83..0000000 --- a/WhereIsMyMouse/PluginUI.cs +++ /dev/null @@ -1,173 +0,0 @@ -using Dalamud.Bindings.ImGui; -using System; -using System.Drawing; -using System.Numerics; -using Dalamud.Game.ClientState.Conditions; -using Dalamud.Game.ClientState.Objects.SubKinds; -using Dalamud.Logging; -using Dalamud.Interface; -using Dalamud.Interface.Utility; -using Dalamud.IoC; -using Dalamud.Plugin; -using Dalamud.Plugin.Services; -using FFXIVClientStructs.FFXIV.Client.Game.UI; -using Lumina; -using StructsCharacter = FFXIVClientStructs.FFXIV.Client.Game.Character.Character; - -namespace WhereIsMyMouse -{ - // It is good to have this be disposable in general, in case you ever need it - // to do any cleanup - class PluginUI : IDisposable - { - private Configuration configuration; - - // this extra bool exists for ImGui, since you can't ref a property - private bool visible = false; - - private bool CursorOn = false; - - private bool ForegroundCursor = false; - - private bool EnableInCombatOnly = false; - - private bool Rainbow = false; - - private float size = 15; - - private float thickness = 2; - - private float cycleSpeed = 0.10f; - - private Vector4 color = new Vector4(1, 0, 0, 1); - - public bool Visible - { - get { return this.visible; } - set { this.visible = value; } - } - - public PluginUI(Configuration configuration) - { - this.configuration = configuration; - this.thickness = this.configuration.Thickness; - this.color = this.configuration.Color; - this.size = this.configuration.Size; - this.cycleSpeed = this.configuration.CycleSpeed; - this.CursorOn = this.configuration.CursorOn; - this.ForegroundCursor = this.configuration.ForegroundCursor; - this.EnableInCombatOnly = this.configuration.EnableInCombatOnly; - this.Rainbow = this.configuration.Rainbow; - } - - public void Dispose() - { - } - - public void Draw() - { - CursorAura(); - DrawMainWindow(); - } - - public void ToggleUI() - { - Visible = !Visible; - } - - public void CursorAura() - { - if (!CursorOn) - { - return; - } - - if (EnableInCombatOnly && !Plugin.Condition[ConditionFlag.InCombat]) - { - return; - } - - if (Rainbow) - { - float h = 0, s = 0, v = 0; - float outr = 0, outg = 0, outb = 0; - ImGui.ColorConvertRGBtoHSV(color.X, color.Y, color.Z, ref h, ref s, ref v); - if (h >= 1) - { - h = 0; - } - h += cycleSpeed * ImGui.GetIO().DeltaTime; - ImGui.ColorConvertHSVtoRGB(h, s, v, ref outr, ref outg, ref outb); - color.X = outr; - color.Y = outg; - color.Z = outb; - } - - Vector2 cursorPos = ImGui.GetMousePos(); - ImGui.SetNextWindowSize(new Vector2(300, 300)); - ImGuiHelpers.ForceNextWindowMainViewport(); - ImGui.Begin("CursorWindow", ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.NoFocusOnAppearing); - ImGui.SetWindowPos(cursorPos - new Vector2(150,150)); - - ImDrawListPtr draw; - draw = this.ForegroundCursor ? ImGui.GetForegroundDrawList() : ImGui.GetWindowDrawList(); - - draw.AddCircle(cursorPos, size, ImGui.ColorConvertFloat4ToU32(this.color), 0, this.thickness); - ImGui.End(); - } - - public void SaveSettings() - { - this.configuration.Color = this.color; - this.configuration.Size = this.size; - this.configuration.Thickness = this.thickness; - this.configuration.CycleSpeed = this.cycleSpeed; - this.configuration.CursorOn = this.CursorOn; - this.configuration.ForegroundCursor = this.ForegroundCursor; - this.configuration.EnableInCombatOnly = this.EnableInCombatOnly; - this.configuration.Rainbow = this.Rainbow; - Plugin.PluginInterface.SavePluginConfig(this.configuration); - } - - - public void DrawMainWindow() - { - if (!Visible) - { - return; - } - ImGui.SetNextWindowSize(new Vector2(375, 600), ImGuiCond.Appearing); - ImGui.SetNextWindowSizeConstraints(new Vector2(375, 330), new Vector2(float.MaxValue, float.MaxValue)); - if (ImGui.Begin("Cursor Settings", ref this.visible, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)) - { - ImGui.Text("Cursor Aura : "); - ImGui.SameLine(); - ImGui.Checkbox("###CursorAura", ref this.CursorOn); - ImGui.Text("Circle drawn in foreground : "); - ImGui.SameLine(); - ImGui.Checkbox("###ForegroundCursor", ref this.ForegroundCursor); - ImGui.Text("Circle Size : "); - ImGui.SameLine(); - ImGui.SliderFloat("###sizeslide", ref this.size, 0f, 100f); - ImGui.Text("Thickness : "); - ImGui.SameLine(); - ImGui.SliderFloat("###thickslide", ref this.thickness, 0f, 50f); - ImGui.ColorPicker4("###ColorPicker", ref this.color); - ImGui.Text("Enable only in combat : "); - ImGui.SameLine(); - ImGui.Checkbox("###CombatOnlyEnable", ref this.EnableInCombatOnly); - ImGui.Text("Rainbow : "); - ImGui.SameLine(); - ImGui.Checkbox("###Rainbow", ref this.Rainbow); - ImGui.Text("Rainbow Cycle Speed : "); - ImGui.SliderFloat("###cyclespeedslide", ref this.cycleSpeed, 0.01f, 1f); - if (ImGui.Button("Save Settings")) - { - SaveSettings(); - } - } - ImGui.End(); - } - - } -} diff --git a/WhereIsMyMouse/WhereIsMyMouse.csproj b/WhereIsMyMouse/WhereIsMyMouse.csproj index f218c05..36d7b46 100644 --- a/WhereIsMyMouse/WhereIsMyMouse.csproj +++ b/WhereIsMyMouse/WhereIsMyMouse.csproj @@ -1,12 +1,11 @@  - + Marethyu - - 0.0.1.4 + 0.0.1.5 Never lose track of your mouse again - https://github.com/Pythyu/WhereIsMyMouse WhereIsMyMouse + false diff --git a/WhereIsMyMouse/packages.lock.json b/WhereIsMyMouse/packages.lock.json index a790ca8..9b0ddac 100644 --- a/WhereIsMyMouse/packages.lock.json +++ b/WhereIsMyMouse/packages.lock.json @@ -4,9 +4,9 @@ "net9.0-windows7.0": { "DalamudPackager": { "type": "Direct", - "requested": "[13.0.0, )", - "resolved": "13.0.0", - "contentHash": "Mb3cUDSK/vDPQ8gQIeuCw03EMYrej1B4J44a1AvIJ9C759p9XeqdU9Hg4WgOmlnlPe0G7ILTD32PKSUpkQNa8w==" + "requested": "[13.1.0, )", + "resolved": "13.1.0", + "contentHash": "XdoNhJGyFby5M/sdcRhnc5xTop9PHy+H50PTWpzLhJugjB19EDBiHD/AsiDF66RETM+0qKUdJBZrNuebn7qswQ==" }, "DotNet.ReproducibleBuilds": { "type": "Direct",