experimental Settings changes
This commit is contained in:
16
HighRollerClassic/DataStructures/Misc.cs
Normal file
16
HighRollerClassic/DataStructures/Misc.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace HighRollerClassic.DataStructures;
|
||||
|
||||
public class Misc
|
||||
{
|
||||
/// <summary>
|
||||
/// Appends message if error par is true
|
||||
/// </summary>
|
||||
/// <param name="error">it will write the message if it's true</param>
|
||||
/// <param name="errorMessage">the message we wish to write</param>
|
||||
/// <param name="message">reference to the message</param>
|
||||
public static void AppendMessage(bool error, string errorMessage, ref string? message)
|
||||
{
|
||||
if (!error) return;
|
||||
message = message == null ? errorMessage : $"\n{errorMessage}";
|
||||
}
|
||||
}
|
||||
@@ -2,30 +2,66 @@ using System.Collections.Generic;
|
||||
|
||||
namespace HighRollerClassic.DataStructures;
|
||||
|
||||
public struct Settings()
|
||||
public class Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains data about each multiplier, roll, etc.
|
||||
/// </summary>
|
||||
public readonly List<SettingsRoll> rolls = new();
|
||||
|
||||
/// <summary>
|
||||
/// Contains messages such as announcements etc.
|
||||
/// </summary>
|
||||
public readonly List<MessageMacro> macros = new();
|
||||
|
||||
/// <summary>
|
||||
/// Maximum bet that will be allowed to set
|
||||
/// </summary>
|
||||
public uint? maxBet = null;
|
||||
|
||||
/// <summary>
|
||||
/// How much the bet will change when user adjusts their bet via +/- keys
|
||||
/// </summary>
|
||||
public uint? step = null;
|
||||
|
||||
/// <summary>
|
||||
/// Whether developer options should be visible in the settings
|
||||
/// </summary>
|
||||
public bool devOptions = false;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum bet that will be allowed to set
|
||||
/// </summary>
|
||||
public uint? MaxBet { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// How much the bet will change when user adjusts their bet via +/- keys
|
||||
/// </summary>
|
||||
public uint? Step { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Contains messages such as announcements etc.
|
||||
/// </summary>
|
||||
public List<MessageMacro> Macros { get; private set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Contains data about each multiplier, roll, etc.
|
||||
/// </summary>
|
||||
public List<SettingsRoll> Rolls { get; private set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Adds roll
|
||||
/// </summary>
|
||||
/// <param name="newRoll">The roll 'collection' we wish to add</param>
|
||||
/// <returns>returns error message if validations fails, null if it's successfully added</returns>
|
||||
public string? AddRoll(SettingsRoll newRoll)
|
||||
{
|
||||
var individualValidation = ValidateIndividual(newRoll);
|
||||
if (individualValidation != null) return individualValidation;
|
||||
|
||||
var fullValidation = ValidateRoll(newRoll);
|
||||
if (fullValidation != null) return fullValidation;
|
||||
|
||||
Rolls.Add(newRoll);
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates new roll
|
||||
/// </summary>
|
||||
/// <param name="newRoll">The roll we wish to add</param>
|
||||
/// <returns>Returns error message if validation fails, otherwise null string</returns>
|
||||
private string? ValidateRoll(SettingsRoll newRoll)
|
||||
{
|
||||
string? message = null;
|
||||
|
||||
var rollExists = Rolls.Exists(p => p.Roll == newRoll.Roll);
|
||||
Misc.AppendMessage(rollExists, "The roll already exists", ref message);
|
||||
var multiplierExists = Rolls.Exists(p => p.Multiplier == newRoll.Multiplier);
|
||||
Misc.AppendMessage(multiplierExists, "This multiplier already exists", ref message);
|
||||
var colourExists = Rolls.Exists(p => p.Colour == newRoll.Colour);
|
||||
Misc.AppendMessage(colourExists, "This colour already exists", ref message);
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,44 @@ using System.Numerics;
|
||||
|
||||
namespace HighRollerClassic.DataStructures;
|
||||
|
||||
public struct SettingsRoll
|
||||
/// <summary>
|
||||
/// Stores individual 'Roll' setting (multiplier, roll, colour)
|
||||
/// </summary>
|
||||
/// <param name="Multiplier">the amount gil will get multiplied if roll interval is reached</param>
|
||||
/// <param name="Roll">the amount that will manipulate multiplier, usually acquired by a player running /random</param>
|
||||
/// <param name="Colour">each roll can be colour coded for better visibility</param>
|
||||
public record SettingsRoll(uint? Multiplier, uint? Roll, Vector4? Colour)
|
||||
{
|
||||
private uint multiplier;
|
||||
private uint roll;
|
||||
private Vector4 color;
|
||||
private const uint MinRollInterval = 1;
|
||||
private const uint MaxRollInterval = 999;
|
||||
|
||||
/// <summary>
|
||||
/// Roll multiplier
|
||||
/// </summary>
|
||||
public uint? Multiplier { get; set; } = Multiplier;
|
||||
|
||||
/// <summary>
|
||||
/// Roll itself
|
||||
/// </summary>
|
||||
public uint? Roll
|
||||
{
|
||||
get;
|
||||
set
|
||||
{
|
||||
if (value is < MinRollInterval or > MaxRollInterval)
|
||||
{
|
||||
field = null;
|
||||
return;
|
||||
}
|
||||
|
||||
field = value;
|
||||
}
|
||||
} = Roll;
|
||||
|
||||
/// <summary>
|
||||
/// Colour that will be used to highlight roll in history
|
||||
/// </summary>
|
||||
public Vector4? Colour { get; set; } = Colour;
|
||||
|
||||
public bool ValidInput => Multiplier.HasValue && Roll.HasValue;
|
||||
}
|
||||
|
||||
@@ -9,13 +9,11 @@ namespace HighRollerClassic.Windows;
|
||||
public class GambaWindow : Window, IDisposable
|
||||
{
|
||||
private readonly Configuration configuration;
|
||||
private readonly string name;
|
||||
|
||||
// todo remove state as the window will only be opened by us calling it with parameters window id
|
||||
private readonly Player? player;
|
||||
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.TargetName}##HRC{target.TargetContentId}",
|
||||
@@ -34,6 +32,9 @@ public class GambaWindow : Window, IDisposable
|
||||
name = target.TargetName;
|
||||
}
|
||||
|
||||
private bool SettingsSet => configuration.Settings is
|
||||
{ MaxBet: not null, Step: not null, Rolls.Count: > 0, Macros.Count: > 0 };
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public override void Draw()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using Dalamud.Interface.Components;
|
||||
using Dalamud.Interface.Windowing;
|
||||
@@ -19,34 +18,27 @@ public class SettingsWindow : Window, IDisposable
|
||||
|
||||
private const uint MaxAllowedGil = 999_999_999;
|
||||
private readonly Configuration configuration;
|
||||
private readonly Vector4 red = new(1, 0, 0, 1f);
|
||||
|
||||
// colours
|
||||
private readonly Vector4 yellow = new(249 / 255f, 180 / 255f, 45 / 255f, 1);
|
||||
|
||||
private bool maxBetFormatValid = true;
|
||||
private SettingsRoll? newRoll;
|
||||
|
||||
private (uint min, uint max) rollInterval = (1, 999);
|
||||
private Settings settings;
|
||||
private bool stepFormatValid = true;
|
||||
|
||||
// colours
|
||||
private readonly Vector4 yellow = new(249/255f, 180/255f, 45/255f, 1);
|
||||
private readonly Vector4 red = new(1, 0, 0, 1f);
|
||||
|
||||
public SettingsWindow(Plugin plugin) : base("Settings##HRC Settings")
|
||||
public SettingsWindow(Plugin plugin) : base("Settings##HRC")
|
||||
{
|
||||
Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar |
|
||||
ImGuiWindowFlags.NoScrollWithMouse;
|
||||
Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse;
|
||||
|
||||
Size = new Vector2(500, 300);
|
||||
SizeCondition = ImGuiCond.Always;
|
||||
|
||||
configuration = plugin.Configuration;
|
||||
// this creates a copy, not a reference
|
||||
settings = configuration.Settings;
|
||||
settings = new Settings();
|
||||
}
|
||||
|
||||
// todo proper implementation it's just a placeholder
|
||||
private bool TempRoll => newRoll.HasValue;
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public override void PreDraw() { }
|
||||
@@ -73,7 +65,6 @@ public class SettingsWindow : Window, IDisposable
|
||||
radius - (textSize.Y * 0.5f)
|
||||
);
|
||||
|
||||
|
||||
drawList.AddText(textPos, textColor, text);
|
||||
|
||||
ImGui.Dummy(new Vector2(radius * 2f, radius * 2f));
|
||||
@@ -81,14 +72,14 @@ public class SettingsWindow : Window, IDisposable
|
||||
// todo set up multiplier, roll, color, etc
|
||||
// todo add button for rolls
|
||||
|
||||
if (ImGui.Button("Add roll") && TempRoll)
|
||||
{
|
||||
// TODO no new rolls must be there
|
||||
newRoll = new SettingsRoll();
|
||||
}
|
||||
|
||||
if (ImGui.CollapsingHeader("Rolls##settings"))
|
||||
{
|
||||
if (ImGui.Button("Add roll") && TempRoll)
|
||||
{
|
||||
// TODO no new rolls must be there
|
||||
newRoll = new SettingsRoll();
|
||||
}
|
||||
// todo here we put new rolls
|
||||
// foreach (var roll in settings.rolls)
|
||||
// {
|
||||
@@ -98,11 +89,11 @@ public class SettingsWindow : Window, IDisposable
|
||||
|
||||
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();
|
||||
|
||||
var stepValid = LabelTextInput("step_label", "Step", "step_input", ref settings.step);
|
||||
var stepValid = LabelTextInput("step_label", "Step", "step_input", ref settings.Step);
|
||||
if (stepValid.HasValue) stepFormatValid = stepValid.Value;
|
||||
ImGui.Spacing();
|
||||
|
||||
@@ -125,8 +116,8 @@ public class SettingsWindow : Window, IDisposable
|
||||
configuration.Settings = settings;
|
||||
configuration.Save();
|
||||
Plugin.Log.Debug($"Configuration data: \n\n " +
|
||||
$"Max bet: {configuration.Settings.maxBet}\n" +
|
||||
$"Step change: {configuration.Settings.step}");
|
||||
$"Max bet: {configuration.Settings.MaxBet}\n" +
|
||||
$"Step change: {configuration.Settings.Step}");
|
||||
}
|
||||
|
||||
ImGui.EndDisabled();
|
||||
@@ -141,12 +132,11 @@ public class SettingsWindow : Window, IDisposable
|
||||
/// Returns false if the roll is to be removed
|
||||
/// </summary>
|
||||
/// <param name="multiplier">gil multiplication in case of a roll</param>
|
||||
/// <param name="exact">if roll is checked on less/less or equal comparison</param>
|
||||
/// <param name="roll">how much user rolls</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>
|
||||
private bool? DisplayRollSetting(
|
||||
ref uint multiplier, ref bool exact, ref uint roll, ref Vector4 colour, ref uint id)
|
||||
private (bool? valid, bool change) DisplayRollSetting(
|
||||
ref uint multiplier, ref uint roll, ref Vector4 colour, ref uint id, ref)
|
||||
{
|
||||
ImGui.SetNextItemWidth(RollSettingInputWidth);
|
||||
ImGui.InputUInt($"##multiplier{id}", ref multiplier);
|
||||
@@ -173,7 +163,8 @@ public class SettingsWindow : Window, IDisposable
|
||||
// TODO verify input
|
||||
// we need to verify if data inputted is "good"
|
||||
|
||||
return ValidateRollSetting();
|
||||
var valid = ValidateRollSetting();
|
||||
var change =
|
||||
}
|
||||
|
||||
private bool ValidateRollSetting()
|
||||
@@ -184,6 +175,8 @@ public class SettingsWindow : Window, IDisposable
|
||||
|
||||
// roll must not already exist
|
||||
|
||||
// colour must not exist already
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -194,8 +187,10 @@ public class SettingsWindow : Window, IDisposable
|
||||
/// <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? LabelTextInput(string labelId, string labelText, string inputId, ref uint? result)
|
||||
private (bool? valid, bool change) LabelTextInput(
|
||||
string labelId, string labelText, string inputId, ref uint? result, ref uint? original)
|
||||
{
|
||||
bool? valid = null;
|
||||
|
||||
@@ -213,8 +208,7 @@ public class SettingsWindow : Window, IDisposable
|
||||
result = parsedValue;
|
||||
valid = true;
|
||||
}
|
||||
else
|
||||
valid = false;
|
||||
else valid = false;
|
||||
}
|
||||
|
||||
// todo alert that appears when field doesn't match the configuration
|
||||
@@ -222,12 +216,11 @@ public class SettingsWindow : Window, IDisposable
|
||||
ImGui.Text("*");
|
||||
|
||||
// todo place the alert if field validation fails
|
||||
|
||||
return valid;
|
||||
return (valid, result == original);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates inputs for Max bet and Step
|
||||
/// Validates input values for Max bet and Step
|
||||
/// </summary>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private (bool valid, string message) ValidateInput()
|
||||
@@ -237,10 +230,10 @@ public class SettingsWindow : Window, IDisposable
|
||||
|
||||
if (!maxBetFormatValid || !stepFormatValid) SetError("Input fields have invalid data", ref message, ref valid);
|
||||
|
||||
if (settings.maxBet > MaxAllowedGil)
|
||||
if (settings.MaxBet > MaxAllowedGil)
|
||||
SetError("Entered bet amount exceeds maximum possible bet", ref message, ref valid);
|
||||
|
||||
if (settings.step > configuration.Settings.maxBet || settings.maxBet < configuration.Settings.maxBet)
|
||||
if (settings.Step > configuration.Settings.MaxBet || settings.MaxBet < configuration.Settings.MaxBet)
|
||||
SetError("Step change must not exceed current maximum bet", ref message, ref valid);
|
||||
|
||||
return (valid, message);
|
||||
|
||||
Reference in New Issue
Block a user