more settings blackmagic
This commit is contained in:
@@ -13,16 +13,17 @@ public class Settings(Configuration? configuration)
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Maximum bet that will be allowed to set
|
/// Maximum bet that will be allowed to set
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TrackedValue MaxBet { get; set; } = new(SettingValueType.MaxBet, null);
|
public TrackedValue MaxBet { get; set; } = new(SettingValueType.MaxBet, null, null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How much the bet will change when user adjusts their bet via +/- keys
|
/// How much the bet will change when user adjusts their bet via +/- keys
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public uint? Step { get; set; }
|
public TrackedValue Step { get; set; } = new(SettingValueType.Step, configuration, null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains messages such as announcements etc.
|
/// Contains messages such as announcements etc.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
// TODO IMPLEMENT
|
||||||
public List<MessageMacro> Macros { get; private set; } = new();
|
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
|
// 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();
|
public readonly RollsCollection RollsCollection = new();
|
||||||
|
|
||||||
// todo might get fucky wucky if maxbet is not yet defined
|
// 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;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,18 +15,18 @@ public class SettingsRoll(uint? multiplier, uint? roll, Vector4? colour)
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Roll multiplier
|
/// Roll multiplier
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TrackedValue Multiplier { get; set; } = new(SettingValueType.Multiplier, multiplier);
|
public TrackedValue Multiplier { get; set; } = new(SettingValueType.Multiplier, null, multiplier);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Roll itself
|
/// Roll itself
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TrackedValue Roll { get; set; } = new(SettingValueType.Roll, roll);
|
public TrackedValue Roll { get; set; } = new(SettingValueType.Roll, null, roll);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Colour that will be used to highlight roll in history
|
/// Colour that will be used to highlight roll in history
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TrackedValue Colour { get; set; } =
|
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>
|
/// <summary>
|
||||||
/// Returns true if all properties in record are valid
|
/// Returns true if all properties in record are valid
|
||||||
|
|||||||
@@ -7,21 +7,27 @@ namespace HighRollerClassic.SettingsStructure;
|
|||||||
/// Tracks value and its validity
|
/// Tracks value and its validity
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type">Type of the value</param>
|
/// <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>
|
/// <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>
|
/// <summary>
|
||||||
/// The main value
|
/// The main value
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public uint? Value
|
public uint? Value
|
||||||
{
|
{
|
||||||
get;
|
get => _value;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
IsValid = CheckValid(value);
|
IsValid = CheckValid(value);
|
||||||
field = value;
|
_value = value;
|
||||||
}
|
}
|
||||||
} = value;
|
}
|
||||||
|
|
||||||
|
public ref uint? ValueRef => ref _value;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tracks validity of the value
|
/// 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> rollValid = v => v is >= MinRoll and <= MaxRoll;
|
||||||
private readonly Func<uint?, bool> maxBetValid = v => v is <= MaxGil;
|
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>
|
/// <summary>
|
||||||
/// Checks if the value is valid
|
/// Checks if the value is valid
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -59,8 +81,8 @@ public class TrackedValue(SettingValueType type, uint? value)
|
|||||||
SettingValueType.Roll => rollValid(value),
|
SettingValueType.Roll => rollValid(value),
|
||||||
SettingValueType.Colour => true,
|
SettingValueType.Colour => true,
|
||||||
SettingValueType.MaxBet => maxBetValid(value),
|
SettingValueType.MaxBet => maxBetValid(value),
|
||||||
// step will get checked upstream to prevent passing configuration to every tracked value
|
SettingValueType.Step => StepValid(value),
|
||||||
_ => false,
|
_ => false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ public class SettingsWindow : Window, IDisposable
|
|||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
|
|
||||||
// todo set up multiplier, roll, color, etc
|
// todo set up multiplier, roll, color, etc
|
||||||
// todo add button for rolls
|
// todo add button for rolls
|
||||||
|
|
||||||
@@ -57,15 +56,16 @@ public class SettingsWindow : Window, IDisposable
|
|||||||
{
|
{
|
||||||
newRoll = new SettingsRoll(null, null, null);
|
newRoll = new SettingsRoll(null, null, null);
|
||||||
// todo display shit
|
// todo display shit
|
||||||
|
|
||||||
// todo make it display actual error
|
// todo make it display actual error
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
if (!newRoll.IsValid) ImGui.Text("ERROR");
|
if (!newRoll.IsValid) ImGui.Text("ERROR");
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.EndDisabled();
|
ImGui.EndDisabled();
|
||||||
|
|
||||||
// todo display new roll
|
// todo display new roll
|
||||||
|
|
||||||
foreach (var roll in settings.RollsCollection.Rolls)
|
foreach (var roll in settings.RollsCollection.Rolls)
|
||||||
{
|
{
|
||||||
// todo here we put existing rolls
|
// todo here we put existing rolls
|
||||||
@@ -75,11 +75,9 @@ public class SettingsWindow : Window, IDisposable
|
|||||||
if (ImGui.CollapsingHeader("General##settings"))
|
if (ImGui.CollapsingHeader("General##settings"))
|
||||||
{
|
{
|
||||||
var maxbetValid = LabelTextInput("max_bet_label", "Max bet", "max_bet_text", ref settings.MaxBet);
|
var maxbetValid = LabelTextInput("max_bet_label", "Max bet", "max_bet_text", ref settings.MaxBet);
|
||||||
if (maxbetValid.HasValue) maxBetFormatValid = maxbetValid.Value;
|
|
||||||
ImGui.Spacing();
|
ImGui.Spacing();
|
||||||
|
|
||||||
var stepValid = LabelTextInput("step_label", "Step", "step_input", ref settings.Step);
|
var stepValid = LabelTextInput("step_label", "Step", "step_input", ref settings.Step.ValueRef);
|
||||||
if (stepValid.HasValue) stepFormatValid = stepValid.Value;
|
|
||||||
ImGui.Spacing();
|
ImGui.Spacing();
|
||||||
|
|
||||||
ImGui.Checkbox("Developer options", ref settings.devOptions);
|
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="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>
|
/// <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(
|
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.SetNextItemWidth(RollInputWidth);
|
||||||
ImGui.InputUInt($"##multiplier{id}", ref multiplier);
|
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="labelId">id of the label field</param>
|
||||||
/// <param name="labelText">text for the label input field</param>
|
/// <param name="labelText">text for the label input field</param>
|
||||||
/// <param name="inputId">id of the 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>
|
/// <param name="original">the original value in configuration to compare it to</param>
|
||||||
/// <returns></returns>
|
private void LabelTextInput(
|
||||||
private (bool? valid, bool change) LabelTextInput(
|
string labelId, string labelText, string inputId, ref TrackedValue original)
|
||||||
string labelId, string labelText, string inputId, ref uint? result, ref uint? original)
|
|
||||||
{
|
{
|
||||||
bool? valid = null;
|
|
||||||
|
|
||||||
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 = original.Value?.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))
|
if (uint.TryParse(num, out var parsedValue))
|
||||||
{
|
{
|
||||||
result = parsedValue;
|
original.Value = parsedValue;
|
||||||
valid = true;
|
|
||||||
}
|
}
|
||||||
else valid = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo alert that appears when field doesn't match the configuration
|
if (original.IsValid) return;
|
||||||
|
// todo test
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
ImGui.Text("*");
|
// todo alert that appears when field doesn't match the configuration
|
||||||
|
ImGui.Text("ERROR");
|
||||||
// todo place the alert if field validation fails
|
|
||||||
return (valid, result == original);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user