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 bool IsEnabled = true;
public bool IsScale = true;
public float Scale = 1f;
public uint Width = 1024;

View File

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

View File

@ -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()

View File

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

View File

@ -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)