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]
public class Configuration : IPluginConfiguration
{
public PlayerManager players = new();
public Settings settings;
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 PlayerManager Players { get; set; }= new();
public Settings Settings { get; set; } = new();
public int Version { get; set; } = 0;

View File

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

View File

@@ -12,7 +12,7 @@ public struct Settings()
/// <summary>
/// Contains messages such as announcements etc.
/// </summary>
public readonly List<Macro> macros = [];
public readonly List<MessageMacro> macros = [];
/// <summary>
/// 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 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)
: base($"High Roller Classic###{target.TargetContentId}",
: base($"High Roller Classic - {target.TargetName}###HRC{target.TargetContentId}",
ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)
{
SizeConstraints = new WindowSizeConstraints
@@ -28,7 +30,7 @@ public class GambaWindow : Window, IDisposable
this.plugin = plugin;
configuration = this.plugin.Configuration;
player = configuration.players.GetOrCreatePlayer(target);
player = configuration.Players.GetOrCreatePlayer(target);
name = target.TargetName;
}
@@ -36,25 +38,17 @@ public class GambaWindow : Window, IDisposable
public override void Draw()
{
// TODO check if local player is null and if it is do not load anything
if (!plugin.PlayerIsLoaded())
{
ImGui.Text("Player must be loaded in the world in order for the plugin to function");
return;
}
/* TODO check if all settings are set
bet/step
roll settings
message/macro settings
*/
if (!configuration.SettingsInit)
if (!SettingsSet)
{
ImGui.Text("Please set up settings");
return;
}
// todo if player is null, then allow user to set user by clicking on them manually
if (player == null)
{

View File

@@ -13,14 +13,11 @@ public class SettingsWindow : Window, IDisposable
private const int InputWidth = 105;
private const int InputMaxLen = 11;
private const uint MaxPossibleBet = 999_999_999;
private const uint MaxAllowedGil = 999_999_999;
private readonly Configuration configuration;
private Settings settings;
// We give this window a constant ID using ###.
// 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")
public SettingsWindow(Plugin plugin) : base("Settings###HRC Settings")
{
Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar |
ImGuiWindowFlags.NoScrollWithMouse;
@@ -29,7 +26,8 @@ public class SettingsWindow : Window, IDisposable
SizeCondition = ImGuiCond.Always;
configuration = plugin.Configuration;
settings = new Settings();
// this creates a copy, not a reference
settings = configuration.Settings;
}
public void Dispose() { }
@@ -41,27 +39,26 @@ public class SettingsWindow : Window, IDisposable
// todo set up multiplier, roll, color, etc
// todo add button for rolls
if (ImGui.Button("Macro Settings")) { }
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();
NewInput("step_label", "Step", "step_input", ref settings.step);
var stepValid = NewInput("step_label", "Step", "step_input", ref settings.step);
ImGui.Spacing();
var inputValidation = ValidateInput();
bool? valid = maxbetValid.HasValue && stepValid.HasValue ? maxbetValid.Value && stepValid.Value : null;
var inputValidation = ValidateInput(valid);
ImGui.BeginDisabled(!inputValidation.valid);
if (ImGui.Button("Save"))
{
configuration.settings = settings;
configuration.Settings = settings;
configuration.Save();
Plugin.Log.Debug($"Configuration data: \n\n " +
$"Max bet: {configuration.Settings.maxBet}\n" +
$"Step change: {configuration.Settings.step}");
}
ImGui.EndDisabled();
@@ -69,44 +66,70 @@ public class SettingsWindow : Window, IDisposable
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.SameLine(XOffset, Spacing);
ImGui.SetNextItemWidth(InputWidth);
var buf = result?.ToString("N0") ?? "";
if (ImGui.InputText($"###{inputId}", ref buf, InputMaxLen))
{
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>
/// Validates inputs for Max bet and Step
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private (bool valid, string message) ValidateInput()
private (bool valid, string message) ValidateInput(bool? validInputFormat)
{
var valid = true;
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";
valid = false;
}
if (settings.step > configuration.settings.maxBet)
if (settings.step > configuration.Settings.maxBet || settings.maxBet < configuration.Settings.maxBet)
{
if (!valid) message += "\n";
message += "Entered step change exceeds current maximum bet";
message += "Step change must not exceed current maximum bet";
valid = false;
}
;
// SetError("Step change must not exceed current maximum bet", message, valid);
}
return (valid, message);
}
private void SetError(string errMsg, ref string message, ref bool valid)
{
if (!valid) message += "\n";
message += errMsg;
valid = false;
}
}