Making progress in SettingsWindow.cs implementation

This commit is contained in:
2026-01-04 16:14:15 +01:00
parent 6fffedaa9d
commit f2545cab05
6 changed files with 59 additions and 115 deletions

View File

@@ -8,7 +8,7 @@ namespace HighRollerClassic;
public class Configuration : IPluginConfiguration
{
public PlayerManager Players { get; set; } = new();
public SettingsStructure.Settings Settings { get; set; } = new(null);
public SettingsStructure.Settings? Settings { get; set; } // is nullable if settings are not yet created
public int Version { get; set; } = 0;

View File

@@ -7,39 +7,16 @@ public class RollsCollection
/// <summary>
/// Contains data about each multiplier, roll, etc.
/// </summary>
public List<SettingsRoll> Rolls { get; set; } = new();
public int Size => Rolls.Count;
/// <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 bool AddRoll(SettingsRoll newRoll)
{
if (!ValidateRoll(newRoll)) return false;
Rolls.Add(newRoll);
return true;
// todo add that specific roll message
}
public void RemoveRoll(SettingsRoll roll)
{
Rolls.Remove(roll);
// todo remove that specific roll macromessage
}
public List<SettingsRoll> Rolls { get; private set; } = new();
/// <summary>
/// Validates given roll
/// </summary>
/// <param name="newRoll">The roll we wish to validate</param>
/// <returns>Returns </returns>
private bool ValidateRoll(SettingsRoll newRoll)
/// <returns>Returns message TODO</returns>
private string? ValidateRoll(SettingsRoll newRoll)
{
var inputValid = newRoll.IsValid;
if (!newRoll.IsValid) return "Invalid roll configuration input";
// existing values must not exist anywhere else
var mpExists = Rolls.Exists(p => p != newRoll && p.Roll.Value == newRoll.Roll.Value);
@@ -50,22 +27,22 @@ public class RollsCollection
colourExists = Rolls.Exists(p => p != newRoll && p.Colour.Value == newRoll.Colour.Value);
}
var fullNotExists = !mpExists && !rollExists && !colourExists;
return inputValid && fullNotExists;
var hasDuplicate = mpExists && rollExists && colourExists;
return hasDuplicate ? "The roll configuration is not unique!" : null;
}
/// <summary>
/// Does quick iteration to see if rolls are valid
/// </summary>
/// <returns>true if all rolls are valid</returns>
public bool ValidateAll()
/// <returns>string if there is an error</returns>
public (bool valid, string? message) ValidateAll()
{
foreach (var roll in Rolls)
{
if (!roll.IsValid) return false;
var val = ValidateRoll(roll);
if (ValidateRoll(roll) != null) return (false, val);
}
return true;
return (true, null);
}
}

View File

@@ -26,11 +26,9 @@ public class Settings(Configuration? configuration)
// 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
public readonly RollsCollection RollsCollection = new();
public readonly RollsCollection Rolls = new();
// todo might get fucky wucky if maxbet is not yet defined
public bool IsValid => MaxBet.IsValid && Step.IsValid && RollsCollection.ValidateAll();
public bool Set => IsValid && RollsCollection.Size > 0 && Macros.Count > 0;
public bool IsValid => MaxBet.IsValid && Step.IsValid && Rolls.ValidateAll().valid;
public bool Set => IsValid && Rolls.Rolls.Count > 0 && Macros.Count > 0;
}

View File

@@ -11,23 +11,20 @@ namespace HighRollerClassic.SettingsStructure;
/// <param name="value">Its value</param>
public class TrackedValue(SettingValueType type, Configuration? configuration, uint? valueInit)
{
// TODO FIX!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
private uint? _value = valueInit;
/// <summary>
/// The main value
/// </summary>
public uint? Value
{
get => _value;
get;
set
{
if (value == field) return;
IsValid = CheckValid(value);
_value = value;
field = value;
}
}
public ref uint? ValueRef => ref _value;
} = valueInit;
/// <summary>
/// Tracks validity of the value
@@ -63,7 +60,7 @@ public class TrackedValue(SettingValueType type, Configuration? configuration, u
// 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
/* TODO if any of setting is considered INVALID
DO NOT USER USE THE APPLICATION
*/
return true;

View File

@@ -11,7 +11,6 @@ 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;

View File

@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface;
using Dalamud.Interface.Components;
using Dalamud.Interface.Windowing;
using HighRollerClassic.DataStructures;
@@ -22,12 +24,7 @@ public class SettingsWindow : Window, IDisposable
private readonly Vector4 red = new(1, 0, 0, 1f);
private readonly Vector4 yellow = new(249 / 255f, 180 / 255f, 45 / 255f, 1);
private SettingsStructure.Settings settings;
/// <summary>
/// Tracks new roll
/// </summary>
private SettingsRoll? newRoll;
private Settings settings;
public SettingsWindow(Plugin plugin) : base("Settings##HRC")
{
@@ -37,7 +34,10 @@ public class SettingsWindow : Window, IDisposable
SizeCondition = ImGuiCond.Always;
configuration = plugin.Configuration;
settings = new SettingsStructure.Settings(configuration);
// todo settings from config can be null
// todo if null create new, if not copy existing
settings = new Settings(configuration);
}
public void Dispose() { }
@@ -47,37 +47,30 @@ public class SettingsWindow : Window, IDisposable
public override void Draw()
{
// todo set up multiplier, roll, color, etc
// todo add button for rolls
if (ImGui.CollapsingHeader("Rolls##settings"))
{
ImGui.BeginDisabled(newRoll != null);
if (ImGui.Button("Add roll") && newRoll == null)
if (ImGui.Button("Add roll"))
{
newRoll = new SettingsRoll(null, null, null);
// todo display shit
// todo make it display actual error
ImGui.SameLine();
if (!newRoll.IsValid) ImGui.Text("ERROR");
settings.Rolls.Rolls.Add(new SettingsRoll(null, null, null));
}
ImGui.EndDisabled();
// todo display new roll
foreach (var roll in settings.RollsCollection.Rolls)
for (uint i = 0; i < settings.Rolls.Rolls.Count; i++)
{
// todo here we put existing rolls
DisplayRollSetting(i, settings.Rolls.Rolls[(int)i]);
}
// todo reorder by multiplier/roll
}
if (ImGui.CollapsingHeader("General##settings"))
{
var maxbetValid = LabelTextInput("max_bet_label", "Max bet", "max_bet_text", ref settings.MaxBet);
LabelTextInput("max_bet_label", "Max bet", "max_bet_text", settings.MaxBet);
ImGui.Spacing();
var stepValid = LabelTextInput("step_label", "Step", "step_input", ref settings.Step.ValueRef);
LabelTextInput("step_label", "Step", "step_input", settings.Step);
ImGui.Spacing();
ImGui.Checkbox("Developer options", ref settings.devOptions);
@@ -88,11 +81,9 @@ public class SettingsWindow : Window, IDisposable
// todo add developer settings - like the ability to have every character have HRC open
}
var inputValidation = ValidateInput();
ImGui.Spacing();
ImGui.BeginDisabled(!inputValidation.valid);
var validation = settings.Rolls.ValidateAll();
ImGui.BeginDisabled(validation != null);
if (ImGui.Button("Save"))
{
@@ -105,8 +96,8 @@ public class SettingsWindow : Window, IDisposable
ImGui.EndDisabled();
ImGui.SameLine();
if (!inputValidation.valid && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
ImGui.SetTooltip(inputValidation.message);
if (validation != null && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
ImGui.SetTooltip(validation);
if (ImGui.Button("Reset")) settings = configuration.Settings;
}
@@ -145,11 +136,20 @@ public class SettingsWindow : Window, IDisposable
/// <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? valid, bool change) DisplayRollSetting(
ref uint multiplier, ref uint roll, ref Vector4 colour, ref uint id, ref TrackedValue original)
private void DisplayRollSetting(uint id, SettingsRoll rollConfig)
{
uint multiplier = rollConfig.Multiplier.Value ?? 0;
ImGui.SetNextItemWidth(RollInputWidth);
ImGui.InputUInt($"##multiplier{id}", ref multiplier);
if (ImGui.InputUInt($"##multiplier{id}", ref multiplier))
{
// todo edge case if we change but don't get good value
/* possible solutions
1. do int
2. do string textbox
3. make a fucky check if the new value = old value and in that case don't send it in
*/
rollConfig.Multiplier.Value = multiplier;
}
ImGui.SameLine();
@@ -160,21 +160,22 @@ public class SettingsWindow : Window, IDisposable
ImGui.InputUInt($"##roll{id}", ref roll);
ImGui.SameLine();
var colourVal = rollConfig.Colour.Value.HasValue
? ColorHelpers.RgbaUintToVector4(rollConfig.Colour.Value.Value)
: new Vector4(0, 0, 0, 1);
var newColour = ImGuiComponents.ColorPickerWithPalette(
(int)id, "placeholder", colour);
(int)id, "placeholder", colourVal);
// TODO if colour is black (0,0,0) set it to null
ImGui.SameLine();
if (ImGui.Button("-"))
{
// signals to the colour to remove this roll setting
return null;
settings.Rolls.Rolls.Remove(rollConfig);
}
// TODO verify input
// we need to verify if data inputted is "good"
var valid = ValidateRollSetting();
var change =
}
@@ -186,7 +187,7 @@ public class SettingsWindow : Window, IDisposable
/// <param name="inputId">id of the input field</param>
/// <param name="original">the original value in configuration to compare it to</param>
private void LabelTextInput(
string labelId, string labelText, string inputId, ref TrackedValue original)
string labelId, string labelText, string inputId, TrackedValue original)
{
ImGui.LabelText($"###{labelId}", $"{labelText}: ");
ImGui.SameLine(XOffset, Spacing);
@@ -204,36 +205,8 @@ public class SettingsWindow : Window, IDisposable
}
if (original.IsValid) return;
// todo test
ImGui.SameLine();
// todo alert that appears when field doesn't match the configuration
ImGui.Text("ERROR");
}
/// <summary>
/// Validates input values for Max bet and Step
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private (bool valid, string message) ValidateInput()
{
var valid = true;
var message = string.Empty;
if (!maxBetFormatValid || !stepFormatValid) SetError("Input fields have invalid data", ref message, ref valid);
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)
SetError("Step change must not exceed current maximum bet", ref message, ref valid);
return (valid, message);
}
private static void SetError(string errMsg, ref string message, ref bool valid)
{
if (!valid) message += "\n";
message += errMsg;
valid = false;
}
}