diff --git a/HighRollerClassic/SettingsStructure/Settings.cs b/HighRollerClassic/SettingsStructure/Settings.cs index d59ed1e..1788a6d 100644 --- a/HighRollerClassic/SettingsStructure/Settings.cs +++ b/HighRollerClassic/SettingsStructure/Settings.cs @@ -13,16 +13,17 @@ public class Settings(Configuration? configuration) /// /// Maximum bet that will be allowed to set /// - public TrackedValue MaxBet { get; set; } = new(SettingValueType.MaxBet, null); + public TrackedValue MaxBet { get; set; } = new(SettingValueType.MaxBet, null, null); /// /// How much the bet will change when user adjusts their bet via +/- keys /// - public uint? Step { get; set; } + public TrackedValue Step { get; set; } = new(SettingValueType.Step, configuration, null); /// /// Contains messages such as announcements etc. /// + // TODO IMPLEMENT public List Macros { get; private set; } = new(); // todo we'll make this a new class because we have 3 roll methods already 'polluting' this class @@ -30,26 +31,6 @@ public class Settings(Configuration? configuration) public readonly RollsCollection RollsCollection = new(); // todo might get fucky wucky if maxbet is not yet defined - public bool IsValid => MaxBet.IsValid && StepValid() && RollsCollection.ValidateAll(); + public bool IsValid => MaxBet.IsValid && Step.IsValid && RollsCollection.ValidateAll(); public bool Set => IsValid && RollsCollection.Size > 0 && Macros.Count > 0; - - private bool StepValid() - { - uint maxBet; - - if (configuration is { Settings.MaxBet.IsValid: true }) - { - maxBet = configuration.Settings.MaxBet.Value!.Value; //IsValid guarantees validity - } - else if (MaxBet.IsValid) - { - maxBet = MaxBet.Value!.Value; // IsValid - } - else - { - maxBet = 0; - } - - return Step <= maxBet; - } } diff --git a/HighRollerClassic/SettingsStructure/SettingsRoll.cs b/HighRollerClassic/SettingsStructure/SettingsRoll.cs index c84a56e..c99f81f 100644 --- a/HighRollerClassic/SettingsStructure/SettingsRoll.cs +++ b/HighRollerClassic/SettingsStructure/SettingsRoll.cs @@ -15,18 +15,18 @@ public class SettingsRoll(uint? multiplier, uint? roll, Vector4? colour) /// /// Roll multiplier /// - public TrackedValue Multiplier { get; set; } = new(SettingValueType.Multiplier, multiplier); + public TrackedValue Multiplier { get; set; } = new(SettingValueType.Multiplier, null, multiplier); /// /// Roll itself /// - public TrackedValue Roll { get; set; } = new(SettingValueType.Roll, roll); + public TrackedValue Roll { get; set; } = new(SettingValueType.Roll, null, roll); /// /// Colour that will be used to highlight roll in history /// public TrackedValue Colour { get; set; } = - new(SettingValueType.Colour, colour.HasValue ? ColorHelpers.RgbaVector4ToUint(colour.Value) : null); + new(SettingValueType.Colour, null, colour.HasValue ? ColorHelpers.RgbaVector4ToUint(colour.Value) : null); /// /// Returns true if all properties in record are valid diff --git a/HighRollerClassic/SettingsStructure/TrackedValue.cs b/HighRollerClassic/SettingsStructure/TrackedValue.cs index 56c36cd..d6d3fe4 100644 --- a/HighRollerClassic/SettingsStructure/TrackedValue.cs +++ b/HighRollerClassic/SettingsStructure/TrackedValue.cs @@ -7,21 +7,27 @@ namespace HighRollerClassic.SettingsStructure; /// Tracks value and its validity /// /// Type of the value +/// only gets sent if type is Step, to check it against existing MaxBet /// Its value -public class TrackedValue(SettingValueType type, uint? value) +public class TrackedValue(SettingValueType type, Configuration? configuration, uint? valueInit) { + // TODO FIX!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + private uint? _value = valueInit; + /// /// The main value /// public uint? Value { - get; + get => _value; set { IsValid = CheckValid(value); - field = value; + _value = value; } - } = value; + } + + public ref uint? ValueRef => ref _value; /// /// Tracks validity of the value @@ -47,6 +53,22 @@ public class TrackedValue(SettingValueType type, uint? value) private readonly Func rollValid = v => v is >= MinRoll and <= MaxRoll; private readonly Func maxBetValid = v => v is <= MaxGil; + private bool StepValid(uint? value) + { + if (configuration is { Settings.MaxBet.IsValid: true }) + { + var maxBet = configuration.Settings.MaxBet.Value!.Value; + return value <= maxBet; + } + + // if max bet is not set allow the user to set whichever they want + // it will get invalidated as soon as maxbet is set anyway + /* TODO if any of setting is considered INVALID + DO NOT USER USE THE APPLICATION + */ + return true; + } + /// /// Checks if the value is valid /// @@ -59,8 +81,8 @@ public class TrackedValue(SettingValueType type, uint? value) SettingValueType.Roll => rollValid(value), SettingValueType.Colour => true, SettingValueType.MaxBet => maxBetValid(value), - // step will get checked upstream to prevent passing configuration to every tracked value - _ => false, + SettingValueType.Step => StepValid(value), + _ => false }; } } diff --git a/HighRollerClassic/Windows/SettingsWindow.cs b/HighRollerClassic/Windows/SettingsWindow.cs index 5040347..0de3bb0 100644 --- a/HighRollerClassic/Windows/SettingsWindow.cs +++ b/HighRollerClassic/Windows/SettingsWindow.cs @@ -46,7 +46,6 @@ public class SettingsWindow : Window, IDisposable public override void Draw() { - // todo set up multiplier, roll, color, etc // todo add button for rolls @@ -57,15 +56,16 @@ public class SettingsWindow : Window, IDisposable { newRoll = new SettingsRoll(null, null, null); // todo display shit - + // todo make it display actual error ImGui.SameLine(); if (!newRoll.IsValid) ImGui.Text("ERROR"); } + ImGui.EndDisabled(); - + // todo display new roll - + foreach (var roll in settings.RollsCollection.Rolls) { // todo here we put existing rolls @@ -75,11 +75,9 @@ public class SettingsWindow : Window, IDisposable if (ImGui.CollapsingHeader("General##settings")) { var maxbetValid = LabelTextInput("max_bet_label", "Max bet", "max_bet_text", ref settings.MaxBet); - if (maxbetValid.HasValue) maxBetFormatValid = maxbetValid.Value; ImGui.Spacing(); - var stepValid = LabelTextInput("step_label", "Step", "step_input", ref settings.Step); - if (stepValid.HasValue) stepFormatValid = stepValid.Value; + var stepValid = LabelTextInput("step_label", "Step", "step_input", ref settings.Step.ValueRef); ImGui.Spacing(); ImGui.Checkbox("Developer options", ref settings.devOptions); @@ -148,7 +146,7 @@ public class SettingsWindow : Window, IDisposable /// colours the rolls in main window, depending on their value /// tracks which roll we're setting so input fields don't have the same ids private (bool? valid, bool change) DisplayRollSetting( - ref uint multiplier, ref uint roll, ref Vector4 colour, ref uint id, ref) + ref uint multiplier, ref uint roll, ref Vector4 colour, ref uint id, ref TrackedValue original) { ImGui.SetNextItemWidth(RollInputWidth); ImGui.InputUInt($"##multiplier{id}", ref multiplier); @@ -186,37 +184,30 @@ public class SettingsWindow : Window, IDisposable /// id of the label field /// text for the label input field /// id of the input field - /// new value if parsing was successful /// the original value in configuration to compare it to - /// - private (bool? valid, bool change) LabelTextInput( - string labelId, string labelText, string inputId, ref uint? result, ref uint? original) + private void LabelTextInput( + string labelId, string labelText, string inputId, ref TrackedValue original) { - bool? valid = null; - ImGui.LabelText($"###{labelId}", $"{labelText}: "); ImGui.SameLine(XOffset, Spacing); ImGui.SetNextItemWidth(InputWidth); - var buf = result?.ToString("N0") ?? ""; + var buf = original.Value?.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; - valid = true; + original.Value = parsedValue; } - else valid = false; } - // todo alert that appears when field doesn't match the configuration + if (original.IsValid) return; + // todo test ImGui.SameLine(); - ImGui.Text("*"); - - // todo place the alert if field validation fails - return (valid, result == original); + // todo alert that appears when field doesn't match the configuration + ImGui.Text("ERROR"); } ///