Allow updating via chat commands
This commit is contained in:
parent
62470ea1f3
commit
ad052e7ad3
86
CustomResolution/Cmds/OpenSettingsCmd.cs
Normal file
86
CustomResolution/Cmds/OpenSettingsCmd.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
@ -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>
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -177,23 +177,31 @@ public sealed unsafe class Plugin : IDalamudPlugin
|
|||||||
height = Service.Config.Height;
|
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 != dev->Width || height != dev->Height)
|
||||||
|
|
||||||
if (width < 256)
|
|
||||||
{
|
{
|
||||||
width = 256;
|
Service.PluginLog.Info($"Changing resolution to {width} x {height}");
|
||||||
}
|
|
||||||
|
|
||||||
if (height < 256)
|
if (width < 256)
|
||||||
{
|
{
|
||||||
height = 256;
|
width = 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev->NewWidth = width;
|
if (height < 256)
|
||||||
dev->NewHeight = height;
|
{
|
||||||
dev->RequestResolutionChange = 1;
|
height = 256;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev->NewWidth = width;
|
||||||
|
dev->NewHeight = height;
|
||||||
|
dev->RequestResolutionChange = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
width = dev->Width;
|
||||||
|
height = dev->Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentWidth = width;
|
CurrentWidth = width;
|
||||||
|
@ -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()
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user