diff --git a/HighRollerClassic/Configuration.cs b/HighRollerClassic/Configuration.cs index 00fc282..9e2f712 100644 --- a/HighRollerClassic/Configuration.cs +++ b/HighRollerClassic/Configuration.cs @@ -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; diff --git a/HighRollerClassic/DataStructures/Macro.cs b/HighRollerClassic/DataStructures/MessageMacro.cs similarity index 95% rename from HighRollerClassic/DataStructures/Macro.cs rename to HighRollerClassic/DataStructures/MessageMacro.cs index 89ca7b6..faff4c6 100644 --- a/HighRollerClassic/DataStructures/Macro.cs +++ b/HighRollerClassic/DataStructures/MessageMacro.cs @@ -1,6 +1,6 @@ namespace HighRollerClassic.DataStructures; -public struct Macro +public struct MessageMacro { /// /// which type of message we're storing here diff --git a/HighRollerClassic/DataStructures/Settings.cs b/HighRollerClassic/DataStructures/Settings.cs index 2f0120d..1517f3c 100644 --- a/HighRollerClassic/DataStructures/Settings.cs +++ b/HighRollerClassic/DataStructures/Settings.cs @@ -12,7 +12,7 @@ public struct Settings() /// /// Contains messages such as announcements etc. /// - public readonly List macros = []; + public readonly List macros = []; /// /// Maximum bet that will be allowed to set diff --git a/HighRollerClassic/Windows/GambaWindow.cs b/HighRollerClassic/Windows/GambaWindow.cs index c6aea6f..a2d0452 100644 --- a/HighRollerClassic/Windows/GambaWindow.cs +++ b/HighRollerClassic/Windows/GambaWindow.cs @@ -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) { diff --git a/HighRollerClassic/Windows/SettingsWindow.cs b/HighRollerClassic/Windows/SettingsWindow.cs index f5a8678..4c3ed90 100644 --- a/HighRollerClassic/Windows/SettingsWindow.cs +++ b/HighRollerClassic/Windows/SettingsWindow.cs @@ -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; } /// /// Validates inputs for Max bet and Step /// /// - 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; + } }