From 5b92d953a84d6a2bc6eb46bb7147fc83aa301188 Mon Sep 17 00:00:00 2001 From: IncognitoWater Date: Fri, 5 Jul 2024 00:23:03 +0200 Subject: [PATCH] IcWa - Fixed nullable warnings, added height settings modified UI to be a little cleaner and added scale parameter to UI to avoid errors on little percentage UI --- Configuration.cs | 3 +++ EasyZoomRebornPlugin.cs | 10 ++++++++++ SettingsWindow.cs | 31 +++++++++++++++++++++++++++---- Utils.cs | 3 ++- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Configuration.cs b/Configuration.cs index 8c647d2..5631848 100644 --- a/Configuration.cs +++ b/Configuration.cs @@ -14,6 +14,7 @@ public class Configuration : IPluginConfiguration [JsonIgnore] public static readonly float ZoomMaxDefault = 20f; [JsonIgnore] public static readonly float AngleMinDefault = -1.483529806f; [JsonIgnore] public static readonly float AngleMaxDefault = 0.7853981853f; + [JsonIgnore] public static readonly float HeightCamPositionDefault = 0.0f; public int Version { get; set; } @@ -28,6 +29,8 @@ public class Configuration : IPluginConfiguration public float ZoomMin = ZoomMinDefault; public float ZoomMax = ZoomMaxDefault; + public float HeightCamPosition = HeightCamPositionDefault; + // Add any other properties or methods here. [JsonIgnore] private IDalamudPluginInterface _pluginInterface; diff --git a/EasyZoomRebornPlugin.cs b/EasyZoomRebornPlugin.cs index 6dd9217..347d3bf 100644 --- a/EasyZoomRebornPlugin.cs +++ b/EasyZoomRebornPlugin.cs @@ -72,6 +72,10 @@ ITextureProvider textureProvider Marshal.StructureToPtr(10000f, MaxFloat, true); PiFloat = Marshal.AllocHGlobal(4); Marshal.StructureToPtr((float)Math.PI, PiFloat, true); + MinFloatHeight = Marshal.AllocHGlobal(4); + Marshal.StructureToPtr(-3f, MinFloatHeight, true); + MaxFloatHeight = Marshal.AllocHGlobal(4); + Marshal.StructureToPtr(3f, MaxFloatHeight, true); Configuration = (Configuration)pluginInterface.GetPluginConfig() ?? new Configuration(); Configuration.Initialize(pluginInterface); @@ -151,10 +155,14 @@ private void ClientState_OnLogin() public static IntPtr AngleMin => (IntPtr)(&Cam->minVRotation); public static IntPtr AngleMax => (IntPtr)(&Cam->maxVRotation); + public static IntPtr HeightCamPosition => (IntPtr)(&Cam->lookAtHeightOffset); + public static IntPtr ZeroFloat; public static IntPtr PiFloat; public static IntPtr MaxFloat; + public static IntPtr MinFloatHeight; + public static IntPtr MaxFloatHeight; internal static void SetCamDistanceNoReset(bool on) { @@ -218,6 +226,8 @@ protected virtual void Dispose(bool disposing) Marshal.FreeHGlobal(ZeroFloat); Marshal.FreeHGlobal(MaxFloat); Marshal.FreeHGlobal(PiFloat); + Marshal.FreeHGlobal(MinFloatHeight); + Marshal.FreeHGlobal(MaxFloatHeight); _getZoomDeltaHook?.Dispose(); } diff --git a/SettingsWindow.cs b/SettingsWindow.cs index 41306e5..af66cf4 100644 --- a/SettingsWindow.cs +++ b/SettingsWindow.cs @@ -26,10 +26,21 @@ public override void Draw() { if (Utils.TryGetTextureWrap(imageUrl, out var texture)) { - ImGui.Image(texture.ImGuiHandle, new(texture.Width/4, texture.Height/4)); + // Calculate padding for ImGui image + Vector2 windowSize = ImGui.GetContentRegionAvail(); + Vector2 imageSize = new(texture.Width / 3 * _scale, texture.Height / 3 * _scale); + Vector2 padding = (windowSize - imageSize) * 0.5f; + ImGui.Dummy(new Vector2(0, padding.Y - 20.0f)); + ImGui.SameLine(padding.X); + ImGui.Image(texture.ImGuiHandle, imageSize); } - - if (ImGui.Button("Support on Ko-fi", new Vector2(104 * _scale, 24 * _scale))) + + // Center the ImGui button + Vector2 buttonSize = new Vector2(104 * _scale, 24 * _scale); + float buttonPosX = (ImGui.GetContentRegionAvail().X - buttonSize.X) * 0.5f; + ImGui.SetCursorPosX(buttonPosX); + + if (ImGui.Button("Support on Ko-fi", buttonSize)) { OpenUrl("https://ko-fi.com/incognitowater"); } @@ -115,6 +126,18 @@ public void DrawGeneralTab() EasyZoomRebornPlugin.Configuration.ZoomMax = Marshal.PtrToStructure(ZoomMax); EasyZoomRebornPlugin.Configuration.Save(); } + + if (ImGui.DragScalar("Camera Height", ImGuiDataType.Float, HeightCamPosition, 0.05f, MinFloatHeight, MaxFloatHeight, Marshal.PtrToStructure(HeightCamPosition).ToString(), ImGuiSliderFlags.Logarithmic)) + { + EasyZoomRebornPlugin.Configuration.HeightCamPosition = Marshal.PtrToStructure(HeightCamPosition); + EasyZoomRebornPlugin.Configuration.Save(); + } + if (ImGui.IsItemHovered() && ImGui.IsMouseDown(ImGuiMouseButton.Right)) + { + Marshal.StructureToPtr(HeightCamPositionDefault, HeightCamPosition, true); + EasyZoomRebornPlugin.Configuration.HeightCamPosition = Marshal.PtrToStructure(HeightCamPosition); + EasyZoomRebornPlugin.Configuration.Save(); + } ImGui.Spacing(); } @@ -154,7 +177,7 @@ public static void OpenUrl(string url) public SettingsWindow(string name) : base(name) { Flags = ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoScrollWithMouse; - Size = new Vector2(400, 250); + Size = new Vector2(400 * _scale, 300 *_scale); } } } \ No newline at end of file diff --git a/Utils.cs b/Utils.cs index 747339c..e30abfd 100644 --- a/Utils.cs +++ b/Utils.cs @@ -1,4 +1,5 @@ -using Dalamud.Interface.Textures.TextureWraps; +#nullable enable +using Dalamud.Interface.Textures.TextureWraps; using System; using System.Collections.Concurrent; using System.Collections.Generic;