Allow updating via chat commands

This commit is contained in:
Jade Macho 2024-02-18 22:48:02 +01:00
parent 62470ea1f3
commit ad052e7ad3
Signed by: 0x0ade
GPG Key ID: E1960710FE4FBEEF
8 changed files with 138 additions and 33 deletions

View File

@ -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;
}
}

View File

@ -9,6 +9,7 @@ public class Configuration : IPluginConfiguration
{ {
public int Version { get; set; } = 0; public int Version { get; set; } = 0;
public bool IsEnabled = true;
public bool IsScale = true; public bool IsScale = true;
public float Scale = 1f; public float Scale = 1f;
public uint Width = 1024; public uint Width = 1024;

View File

@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Authors>0x0ade</Authors> <Authors>0x0ade</Authors>
<Company></Company> <Company></Company>
<Version>0.1.0.1</Version> <Version>0.1.0.2</Version>
<Description></Description> <Description></Description>
<Copyright></Copyright> <Copyright></Copyright>
<PackageProjectUrl></PackageProjectUrl> <PackageProjectUrl></PackageProjectUrl>
@ -61,8 +61,4 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Cmds\" />
</ItemGroup>
</Project> </Project>

View File

@ -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;
}
}

View File

@ -177,6 +177,8 @@ public sealed unsafe class Plugin : IDalamudPlugin
height = Service.Config.Height; height = Service.Config.Height;
} }
if (Service.Config.IsEnabled)
{
if (width != dev->Width || height != dev->Height) if (width != dev->Width || height != dev->Height)
{ {
Service.PluginLog.Info($"Changing resolution to {width} x {height}"); Service.PluginLog.Info($"Changing resolution to {width} x {height}");
@ -195,6 +197,12 @@ public sealed unsafe class Plugin : IDalamudPlugin
dev->NewHeight = height; dev->NewHeight = height;
dev->RequestResolutionChange = 1; dev->RequestResolutionChange = 1;
} }
}
else
{
width = dev->Width;
height = dev->Height;
}
CurrentWidth = width; CurrentWidth = width;
CurrentHeight = height; CurrentHeight = height;

View File

@ -21,7 +21,11 @@ public sealed class PluginUI : IDisposable
public bool SettingsVisible public bool SettingsVisible
{ {
get => _configWindow.IsOpen; get => _configWindow.IsOpen;
set => _configWindow.IsOpen = value; set
{
_configWindow.IsOpen = value;
_configWindow.UpdateFromConfig();
}
} }
public void Dispose() public void Dispose()

View File

@ -1,4 +1,5 @@
using CustomResolution.Hooks; using CustomResolution.Hooks;
using Dalamud.Game.Text;
using Dalamud.IoC; using Dalamud.IoC;
using Dalamud.Plugin; using Dalamud.Plugin;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
@ -33,4 +34,21 @@ public sealed class Service
[PluginService] [PluginService]
public static IPluginLog PluginLog { get; private set; } = null!; 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);
}
} }

View File

@ -10,6 +10,7 @@ public class ConfigWindow : Window, IDisposable
private int[] _displayCurrentWH = new int[2]; private int[] _displayCurrentWH = new int[2];
private int[] _displayCurrentWindowWH = new int[2]; private int[] _displayCurrentWindowWH = new int[2];
private bool _configIsEnabled;
private bool _configIsScale; private bool _configIsScale;
private float _configScale; private float _configScale;
private int[] _configWH = new int[2]; private int[] _configWH = new int[2];
@ -19,7 +20,7 @@ public class ConfigWindow : Window, IDisposable
ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar |
ImGuiWindowFlags.NoScrollWithMouse) ImGuiWindowFlags.NoScrollWithMouse)
{ {
Size = new Vector2(430, 160); Size = new Vector2(430, 184);
SizeCondition = ImGuiCond.Always; SizeCondition = ImGuiCond.Always;
UpdateFromConfig(); UpdateFromConfig();
@ -32,6 +33,7 @@ public class ConfigWindow : Window, IDisposable
{ {
var config = Service.Config; var config = Service.Config;
_configIsEnabled = config.IsEnabled;
_configIsScale = config.IsScale; _configIsScale = config.IsScale;
_configScale = config.Scale; _configScale = config.Scale;
_configWH[0] = (int) config.Width; _configWH[0] = (int) config.Width;
@ -42,6 +44,7 @@ public class ConfigWindow : Window, IDisposable
{ {
var config = Service.Config; var config = Service.Config;
config.IsEnabled = _configIsEnabled;
config.IsScale = _configIsScale; config.IsScale = _configIsScale;
config.Scale = _configScale; config.Scale = _configScale;
config.Width = (uint) _configWH[0]; config.Width = (uint) _configWH[0];
@ -65,6 +68,8 @@ public class ConfigWindow : Window, IDisposable
ImGui.InputInt2("Current render size", ref _displayCurrentWH[0]); ImGui.InputInt2("Current render size", ref _displayCurrentWH[0]);
ImGui.EndDisabled(); ImGui.EndDisabled();
ImGui.Checkbox("Enabled", ref _configIsEnabled);
ImGui.Checkbox("Use scale", ref _configIsScale); ImGui.Checkbox("Use scale", ref _configIsScale);
if (_configIsScale) if (_configIsScale)