Settings improvements

This commit is contained in:
2025-12-28 21:17:21 +01:00
parent f5a35344d0
commit 08162ecccb
5 changed files with 56 additions and 43 deletions

View File

@@ -7,12 +7,8 @@ namespace HighRollerClassic;
[Serializable] [Serializable]
public class Configuration : IPluginConfiguration public class Configuration : IPluginConfiguration
{ {
public PlayerManager players = new(); public PlayerManager Players { get; set; }= new();
public Settings settings; public Settings Settings { get; set; } = new();
public bool SettingsInit => !settings.maxBet.HasValue && !settings.step.HasValue && settings.rolls.Count > 0 &&
settings.macros.Count > 0;
// TODO calculate the amount of macros having to be saved
public int Version { get; set; } = 0; public int Version { get; set; } = 0;

View File

@@ -1,6 +1,6 @@
namespace HighRollerClassic.DataStructures; namespace HighRollerClassic.DataStructures;
public struct Macro public struct MessageMacro
{ {
/// <summary> /// <summary>
/// which type of message we're storing here /// which type of message we're storing here

View File

@@ -12,7 +12,7 @@ public struct Settings()
/// <summary> /// <summary>
/// Contains messages such as announcements etc. /// Contains messages such as announcements etc.
/// </summary> /// </summary>
public readonly List<Macro> macros = []; public readonly List<MessageMacro> macros = [];
/// <summary> /// <summary>
/// Maximum bet that will be allowed to set /// Maximum bet that will be allowed to set

View File

@@ -15,8 +15,10 @@ public class GambaWindow : Window, IDisposable
private readonly Plugin plugin; private readonly Plugin plugin;
private readonly string name; private readonly string name;
private bool SettingsSet => configuration.Settings is { maxBet: not null, step: not null, rolls.Count: > 0, macros.Count: > 0 };
public GambaWindow(Plugin plugin, MenuTargetDefault target) public GambaWindow(Plugin plugin, MenuTargetDefault target)
: base($"High Roller Classic###{target.TargetContentId}", : base($"High Roller Classic - {target.TargetName}###HRC{target.TargetContentId}",
ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse) ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)
{ {
SizeConstraints = new WindowSizeConstraints SizeConstraints = new WindowSizeConstraints
@@ -28,7 +30,7 @@ public class GambaWindow : Window, IDisposable
this.plugin = plugin; this.plugin = plugin;
configuration = this.plugin.Configuration; configuration = this.plugin.Configuration;
player = configuration.players.GetOrCreatePlayer(target); player = configuration.Players.GetOrCreatePlayer(target);
name = target.TargetName; name = target.TargetName;
} }
@@ -36,25 +38,17 @@ public class GambaWindow : Window, IDisposable
public override void Draw() public override void Draw()
{ {
// TODO check if local player is null and if it is do not load anything
if (!plugin.PlayerIsLoaded()) if (!plugin.PlayerIsLoaded())
{ {
ImGui.Text("Player must be loaded in the world in order for the plugin to function"); ImGui.Text("Player must be loaded in the world in order for the plugin to function");
return; return;
} }
/* TODO check if all settings are set if (!SettingsSet)
bet/step
roll settings
message/macro settings
*/
if (!configuration.SettingsInit)
{ {
ImGui.Text("Please set up settings"); ImGui.Text("Please set up settings");
return; return;
} }
// todo if player is null, then allow user to set user by clicking on them manually
if (player == null) if (player == null)
{ {

View File

@@ -13,14 +13,11 @@ public class SettingsWindow : Window, IDisposable
private const int InputWidth = 105; private const int InputWidth = 105;
private const int InputMaxLen = 11; private const int InputMaxLen = 11;
private const uint MaxPossibleBet = 999_999_999; private const uint MaxAllowedGil = 999_999_999;
private readonly Configuration configuration; private readonly Configuration configuration;
private Settings settings; private Settings settings;
// We give this window a constant ID using ###. public SettingsWindow(Plugin plugin) : base("Settings###HRC Settings")
// This allows for labels to be dynamic, like "{FPS Counter}fps###XYZ counter window",
// and the window ID will always be "###XYZ counter window" for ImGui
public SettingsWindow(Plugin plugin) : base("Settings###HRC")
{ {
Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar | Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar |
ImGuiWindowFlags.NoScrollWithMouse; ImGuiWindowFlags.NoScrollWithMouse;
@@ -29,7 +26,8 @@ public class SettingsWindow : Window, IDisposable
SizeCondition = ImGuiCond.Always; SizeCondition = ImGuiCond.Always;
configuration = plugin.Configuration; configuration = plugin.Configuration;
settings = new Settings(); // this creates a copy, not a reference
settings = configuration.Settings;
} }
public void Dispose() { } public void Dispose() { }
@@ -41,27 +39,26 @@ public class SettingsWindow : Window, IDisposable
// todo set up multiplier, roll, color, etc // todo set up multiplier, roll, color, etc
// todo add button for rolls // todo add button for rolls
if (ImGui.Button("Macro Settings")) { }
if (ImGui.Button("Add roll")) { } if (ImGui.Button("Add roll")) { }
// todo add check that there is at least one roll
NewInput("max_bet_label", "Max bet", "max_bet_text", ref settings.maxBet);
var maxbetValid = NewInput("max_bet_label", "Max bet", "max_bet_text", ref settings.maxBet);
ImGui.Spacing(); ImGui.Spacing();
NewInput("step_label", "Step", "step_input", ref settings.step); var stepValid = NewInput("step_label", "Step", "step_input", ref settings.step);
ImGui.Spacing(); ImGui.Spacing();
var inputValidation = ValidateInput(); bool? valid = maxbetValid.HasValue && stepValid.HasValue ? maxbetValid.Value && stepValid.Value : null;
var inputValidation = ValidateInput(valid);
ImGui.BeginDisabled(!inputValidation.valid); ImGui.BeginDisabled(!inputValidation.valid);
if (ImGui.Button("Save")) if (ImGui.Button("Save"))
{ {
configuration.settings = settings; configuration.Settings = settings;
configuration.Save(); configuration.Save();
Plugin.Log.Debug($"Configuration data: \n\n " +
$"Max bet: {configuration.Settings.maxBet}\n" +
$"Step change: {configuration.Settings.step}");
} }
ImGui.EndDisabled(); ImGui.EndDisabled();
@@ -69,44 +66,70 @@ public class SettingsWindow : Window, IDisposable
if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) ImGui.SetTooltip(inputValidation.message); if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) ImGui.SetTooltip(inputValidation.message);
} }
private static void NewInput(string labelId, string labelText, string inputId, ref uint? result) private bool? NewInput(string labelId, string labelText, string inputId, ref uint? result)
{ {
var valid = false;
ImGui.LabelText($"###{labelId}", $"{labelText}: "); ImGui.LabelText($"###{labelId}", $"{labelText}: ");
ImGui.SameLine(XOffset, Spacing); ImGui.SameLine(XOffset, Spacing);
ImGui.SetNextItemWidth(InputWidth); ImGui.SetNextItemWidth(InputWidth);
var buf = result?.ToString("N0") ?? ""; var buf = result?.ToString("N0") ?? "";
if (ImGui.InputText($"###{inputId}", ref buf, InputMaxLen)) if (ImGui.InputText($"###{inputId}", ref buf, InputMaxLen))
{ {
var num = buf.Replace(",", string.Empty).Replace(".", string.Empty); var num = buf.Replace(",", string.Empty).Replace(".", string.Empty);
if (uint.TryParse(num, out var parsedValue)) result = parsedValue; if (uint.TryParse(num, out var parsedValue))
{
result = parsedValue;
valid = true;
}
else
{
valid = false;
}
} }
return valid;
} }
/// <summary> /// <summary>
/// Validates inputs for Max bet and Step /// Validates inputs for Max bet and Step
/// </summary> /// </summary>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
private (bool valid, string message) ValidateInput() private (bool valid, string message) ValidateInput(bool? validInputFormat)
{ {
var valid = true; var valid = true;
var message = string.Empty; var message = string.Empty;
if (settings.maxBet > MaxPossibleBet) if (validInputFormat.HasValue && !validInputFormat.Value)
{
message += "Input fields have invalid data";
valid = false;
}
if (settings.maxBet > MaxAllowedGil)
{ {
message += "Entered bet amount exceeds maximum possible bet"; message += "Entered bet amount exceeds maximum possible bet";
valid = false; valid = false;
} }
if (settings.step > configuration.settings.maxBet) if (settings.step > configuration.Settings.maxBet || settings.maxBet < configuration.Settings.maxBet)
{ {
if (!valid) message += "\n"; if (!valid) message += "\n";
message += "Entered step change exceeds current maximum bet"; message += "Step change must not exceed current maximum bet";
valid = false; valid = false;
// SetError("Step change must not exceed current maximum bet", message, valid);
} }
;
return (valid, message); return (valid, message);
} }
private void SetError(string errMsg, ref string message, ref bool valid)
{
if (!valid) message += "\n";
message += errMsg;
valid = false;
}
} }