diff --git a/CustomResolution/Cmds/OpenSettingsCmd.cs b/CustomResolution/Cmds/OpenSettingsCmd.cs new file mode 100644 index 0000000..0b27634 --- /dev/null +++ b/CustomResolution/Cmds/OpenSettingsCmd.cs @@ -0,0 +1,86 @@ +using static FFXIVClientStructs.FFXIV.Client.UI.AddonRelicNoteBook; +using System.Collections; +using System.Globalization; +using System; + +namespace CustomResolution.Cmds; + +public sealed class OpenSettingsCmd : Cmd +{ + public override string Name => "cres"; + + public override string HelpMessage => $"Open / adjust the CustomResolution settings.\n" + + $"\tExamples:\n" + + $"\tTo open the settings:\n\t\t{FullName}\n" + + $"\tTo enable / disable it:\n\t\t{FullName} on\n\t\t{FullName} off\n\t\t{FullName} toggle\n" + + $"\tTo set the scale:\n\t\t{FullName} 1.5\n" + + $"\tTo set the resolution:\n\t\t{FullName} 1920 1080"; + + public override void Run(string arguments) + { + if (string.IsNullOrEmpty(arguments)) + { + ToggleOpen(); + + return; + } + + int indexOfSplit = arguments.IndexOf(' '); + + if (indexOfSplit != -1) + { + if (!uint.TryParse(arguments.AsSpan(0, indexOfSplit), CultureInfo.InvariantCulture, out var width) || + !uint.TryParse(arguments.AsSpan(indexOfSplit + 1), CultureInfo.InvariantCulture, out var height)) + { + Service.PrintChat("Invalid parameters."); + return; + } + + Service.Config.IsScale = false; + Service.Config.Width = width; + Service.Config.Height = height; + Service.Config.Save(); + + Service.PrintChat("Updated custom resolution."); + return; + } + + switch (arguments.ToLowerInvariant()) + { + case "on": + Service.Config.IsEnabled = true; + Service.Config.Save(); + Service.PrintChat("Enabled custom resolution."); + return; + + case "off": + Service.Config.IsEnabled = false; + Service.Config.Save(); + Service.PrintChat("Disabled custom resolution."); + return; + + case "toggle": + Service.Config.IsEnabled = !Service.Config.IsEnabled; + Service.Config.Save(); + Service.PrintChat($"{(Service.Config.IsEnabled ? "Enabled" : "Disabled")} custom resolution."); + return; + } + + if (!float.TryParse(arguments, out float value)) + { + Service.PrintChat("Invalid parameters."); + return; + } + + Service.Config.IsScale = true; + Service.Config.Scale = value; + Service.Config.Save(); + + Service.PrintChat("Updated custom resolution scale."); + } + + private void ToggleOpen() + { + Service.PluginUI.SettingsVisible = !Service.PluginUI.SettingsVisible; + } +} diff --git a/CustomResolution/Configuration.cs b/CustomResolution/Configuration.cs index 1c44be4..39f7eb3 100644 --- a/CustomResolution/Configuration.cs +++ b/CustomResolution/Configuration.cs @@ -9,6 +9,7 @@ public class Configuration : IPluginConfiguration { public int Version { get; set; } = 0; + public bool IsEnabled = true; public bool IsScale = true; public float Scale = 1f; public uint Width = 1024; diff --git a/CustomResolution/CustomResolution.csproj b/CustomResolution/CustomResolution.csproj index a8dce7d..8de017d 100644 --- a/CustomResolution/CustomResolution.csproj +++ b/CustomResolution/CustomResolution.csproj @@ -3,7 +3,7 @@ 0x0ade - 0.1.0.1 + 0.1.0.2 @@ -61,8 +61,4 @@ - - - - diff --git a/CustomResolution/OpenSettingsCmd.cs b/CustomResolution/OpenSettingsCmd.cs deleted file mode 100644 index a5212ba..0000000 --- a/CustomResolution/OpenSettingsCmd.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace CustomResolution; - -public sealed class OpenSettingsCmd : Cmd -{ - public override string Name => "cres"; - - public override string HelpMessage => "Open the CustomResolution Settings"; - - public override void Run(string arguments) - { - Service.PluginUI.SettingsVisible = !Service.PluginUI.SettingsVisible; - } -} diff --git a/CustomResolution/Plugin.cs b/CustomResolution/Plugin.cs index 4ff395d..9fc36a9 100644 --- a/CustomResolution/Plugin.cs +++ b/CustomResolution/Plugin.cs @@ -177,23 +177,31 @@ public sealed unsafe class Plugin : IDalamudPlugin height = Service.Config.Height; } - if (width != dev->Width || height != dev->Height) + if (Service.Config.IsEnabled) { - Service.PluginLog.Info($"Changing resolution to {width} x {height}"); - - if (width < 256) + if (width != dev->Width || height != dev->Height) { - width = 256; - } + Service.PluginLog.Info($"Changing resolution to {width} x {height}"); - if (height < 256) - { - height = 256; - } + if (width < 256) + { + width = 256; + } - dev->NewWidth = width; - dev->NewHeight = height; - dev->RequestResolutionChange = 1; + if (height < 256) + { + height = 256; + } + + dev->NewWidth = width; + dev->NewHeight = height; + dev->RequestResolutionChange = 1; + } + } + else + { + width = dev->Width; + height = dev->Height; } CurrentWidth = width; diff --git a/CustomResolution/PluginUI.cs b/CustomResolution/PluginUI.cs index c00a3cd..727c5fe 100644 --- a/CustomResolution/PluginUI.cs +++ b/CustomResolution/PluginUI.cs @@ -21,7 +21,11 @@ public sealed class PluginUI : IDisposable public bool SettingsVisible { get => _configWindow.IsOpen; - set => _configWindow.IsOpen = value; + set + { + _configWindow.IsOpen = value; + _configWindow.UpdateFromConfig(); + } } public void Dispose() diff --git a/CustomResolution/Service.cs b/CustomResolution/Service.cs index e676e86..cbcdfce 100644 --- a/CustomResolution/Service.cs +++ b/CustomResolution/Service.cs @@ -1,4 +1,5 @@ using CustomResolution.Hooks; +using Dalamud.Game.Text; using Dalamud.IoC; using Dalamud.Plugin; using Dalamud.Plugin.Services; @@ -33,4 +34,21 @@ public sealed class Service [PluginService] public static IPluginLog PluginLog { get; private set; } = null!; + + [PluginService] + public static IChatGui ChatGui { get; private set; } = null!; + + public static void PrintChat(string msg) + { + ChatGui.Print(new XivChatEntry + { + Message = msg, + Type = PluginInterface.GeneralChatType + }); + } + + public static void PrintChatErr(string msg) + { + ChatGui.PrintError(msg); + } } diff --git a/CustomResolution/Windows/ConfigWindow.cs b/CustomResolution/Windows/ConfigWindow.cs index 3cbb194..9e4b64d 100644 --- a/CustomResolution/Windows/ConfigWindow.cs +++ b/CustomResolution/Windows/ConfigWindow.cs @@ -10,6 +10,7 @@ public class ConfigWindow : Window, IDisposable private int[] _displayCurrentWH = new int[2]; private int[] _displayCurrentWindowWH = new int[2]; + private bool _configIsEnabled; private bool _configIsScale; private float _configScale; private int[] _configWH = new int[2]; @@ -19,7 +20,7 @@ public class ConfigWindow : Window, IDisposable ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse) { - Size = new Vector2(430, 160); + Size = new Vector2(430, 184); SizeCondition = ImGuiCond.Always; UpdateFromConfig(); @@ -32,6 +33,7 @@ public class ConfigWindow : Window, IDisposable { var config = Service.Config; + _configIsEnabled = config.IsEnabled; _configIsScale = config.IsScale; _configScale = config.Scale; _configWH[0] = (int) config.Width; @@ -42,6 +44,7 @@ public class ConfigWindow : Window, IDisposable { var config = Service.Config; + config.IsEnabled = _configIsEnabled; config.IsScale = _configIsScale; config.Scale = _configScale; config.Width = (uint) _configWH[0]; @@ -65,6 +68,8 @@ public class ConfigWindow : Window, IDisposable ImGui.InputInt2("Current render size", ref _displayCurrentWH[0]); ImGui.EndDisabled(); + ImGui.Checkbox("Enabled", ref _configIsEnabled); + ImGui.Checkbox("Use scale", ref _configIsScale); if (_configIsScale)