more settings blackmagic

This commit is contained in:
2026-01-04 01:37:58 +01:00
parent 8c9c3b3d94
commit 6fffedaa9d
4 changed files with 49 additions and 55 deletions

View File

@@ -13,16 +13,17 @@ public class Settings(Configuration? configuration)
/// <summary>
/// Maximum bet that will be allowed to set
/// </summary>
public TrackedValue MaxBet { get; set; } = new(SettingValueType.MaxBet, null);
public TrackedValue MaxBet { get; set; } = new(SettingValueType.MaxBet, null, null);
/// <summary>
/// How much the bet will change when user adjusts their bet via +/- keys
/// </summary>
public uint? Step { get; set; }
public TrackedValue Step { get; set; } = new(SettingValueType.Step, configuration, null);
/// <summary>
/// Contains messages such as announcements etc.
/// </summary>
// TODO IMPLEMENT
public List<MessageMacro> 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;
}
}

View File

@@ -15,18 +15,18 @@ public class SettingsRoll(uint? multiplier, uint? roll, Vector4? colour)
/// <summary>
/// Roll multiplier
/// </summary>
public TrackedValue Multiplier { get; set; } = new(SettingValueType.Multiplier, multiplier);
public TrackedValue Multiplier { get; set; } = new(SettingValueType.Multiplier, null, multiplier);
/// <summary>
/// Roll itself
/// </summary>
public TrackedValue Roll { get; set; } = new(SettingValueType.Roll, roll);
public TrackedValue Roll { get; set; } = new(SettingValueType.Roll, null, roll);
/// <summary>
/// Colour that will be used to highlight roll in history
/// </summary>
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);
/// <summary>
/// Returns true if all properties in record are valid

View File

@@ -7,21 +7,27 @@ namespace HighRollerClassic.SettingsStructure;
/// Tracks value and its validity
/// </summary>
/// <param name="type">Type of the value</param>
/// <param name="configuration">only gets sent if type is Step, to check it against existing MaxBet</param>
/// <param name="value">Its value</param>
public class TrackedValue(SettingValueType type, uint? value)
public class TrackedValue(SettingValueType type, Configuration? configuration, uint? valueInit)
{
// TODO FIX!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
private uint? _value = valueInit;
/// <summary>
/// The main value
/// </summary>
public uint? Value
{
get;
get => _value;
set
{
IsValid = CheckValid(value);
field = value;
_value = value;
}
} = value;
}
public ref uint? ValueRef => ref _value;
/// <summary>
/// Tracks validity of the value
@@ -47,6 +53,22 @@ public class TrackedValue(SettingValueType type, uint? value)
private readonly Func<uint?, bool> rollValid = v => v is >= MinRoll and <= MaxRoll;
private readonly Func<uint?, bool> 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;
}
/// <summary>
/// Checks if the value is valid
/// </summary>
@@ -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
};
}
}

View File

@@ -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
/// <param name="colour">colours the rolls in main window, depending on their value</param>
/// <param name="id">tracks which roll we're setting so input fields don't have the same ids</param>
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
/// <param name="labelId">id of the label field</param>
/// <param name="labelText">text for the label input field</param>
/// <param name="inputId">id of the input field</param>
/// <param name="result">new value if parsing was successful</param>
/// <param name="original">the original value in configuration to compare it to</param>
/// <returns></returns>
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");
}
/// <summary>