Further settings implementation and macros

This commit is contained in:
2025-12-28 01:09:44 +01:00
parent 81a4bb4bc4
commit f5a35344d0
6 changed files with 105 additions and 43 deletions

View File

@@ -9,6 +9,11 @@ public class Configuration : IPluginConfiguration
{
public PlayerManager players = new();
public Settings settings;
public bool SettingsInit => !settings.maxBet.HasValue && !settings.step.HasValue && settings.rolls.Count > 0 &&
settings.macros.Count > 0;
// TODO calculate the amount of macros having to be saved
public int Version { get; set; } = 0;
// The below exists just to make saving less cumbersome

View File

@@ -0,0 +1,21 @@
namespace HighRollerClassic.DataStructures;
public struct Macro
{
/// <summary>
/// which type of message we're storing here
/// </summary>
private MacroType type;
/// <summary>
/// only for messages that talk about rolls
/// </summary>
private uint? rollNum;
/// <summary>
/// message itself
/// </summary>
private string message;
/// <summary>
/// additional emotes that character will play out after/before outputting the message
/// </summary>
private string emotes;
}

View File

@@ -0,0 +1,9 @@
namespace HighRollerClassic.DataStructures;
public enum MacroType
{
Announce,
TargetBets,
WinsRoll,
LosesRoll
}

View File

@@ -2,20 +2,25 @@ using System.Collections.Generic;
namespace HighRollerClassic.DataStructures;
public struct Settings
public struct Settings()
{
/// <summary>
/// Contains data bout each multiplier, roll, etc.
/// Contains data about each multiplier, roll, etc.
/// </summary>
public List<SettingsRolls> rolls;
public readonly List<SettingsRolls> rolls = [];
/// <summary>
/// Contains messages such as announcements etc.
/// </summary>
public readonly List<Macro> macros = [];
/// <summary>
/// Maximum bet that will be allowed to set
/// </summary>
public uint maxBet;
public uint? maxBet = null;
/// <summary>
/// How much the bet will change when user adjusts their bet via +/- keys
/// </summary>
public uint step;
public uint? step = null;
}

View File

@@ -13,7 +13,7 @@ public class GambaWindow : Window, IDisposable
// 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 string name;
private readonly string name;
public GambaWindow(Plugin plugin, MenuTargetDefault target)
: base($"High Roller Classic###{target.TargetContentId}",
@@ -45,9 +45,15 @@ public class GambaWindow : Window, IDisposable
}
/* TODO check if all settings are set
bet/step
roll settings
message/macro settings
*/
if (!configuration.SettingsInit)
{
ImGui.Text("Please set up settings");
return;
}
// todo if player is null, then allow user to set user by clicking on them manually
if (player == null)

View File

@@ -8,15 +8,14 @@ namespace HighRollerClassic.Windows;
public class SettingsWindow : Window, IDisposable
{
private readonly Configuration configuration;
private Settings settings;
private const int XOffset = 80;
private const int Spacing = 5;
private const int InputWidth = 105;
private const int InputMaxLen = 11;
private const uint MaxPossibleBet = 999_999_999;
private readonly Configuration configuration;
private Settings settings;
// We give this window a constant ID using ###.
// This allows for labels to be dynamic, like "{FPS Counter}fps###XYZ counter window",
@@ -30,7 +29,7 @@ public class SettingsWindow : Window, IDisposable
SizeCondition = ImGuiCond.Always;
configuration = plugin.Configuration;
settings = configuration.settings;
settings = new Settings();
}
public void Dispose() { }
@@ -42,55 +41,72 @@ public class SettingsWindow : Window, IDisposable
// todo set up multiplier, roll, color, etc
// todo add button for rolls
ImGui.LabelText("###max_bet_label", "Max bet: ");
ImGui.SameLine(XOffset, Spacing);
ImGui.SetNextItemWidth(InputWidth);
// TODO maybe throw it in a function because we have 2 fields behaving the same except for variables and label
var betBuf = settings.maxBet.ToString("N0");
if (ImGui.InputText("###max_bet_text", ref betBuf, InputMaxLen))
{
var num = betBuf.Replace(",", string.Empty).Replace(".", string.Empty);
if (uint.TryParse(num, out var parsedValue)) settings.maxBet = parsedValue;
}
if (ImGui.Button("Macro Settings")) { }
if (ImGui.Button("Add roll")) { }
// todo add check that there is at least one roll
NewInput("max_bet_label", "Max bet", "max_bet_text", ref settings.maxBet);
ImGui.Spacing();
ImGui.LabelText("###step_label", "Step: ");
ImGui.SameLine(XOffset, Spacing);
ImGui.SetNextItemWidth(InputWidth);
var stepBuf = settings.step.ToString("N0");
if (ImGui.InputText("###step_input", ref stepBuf, InputMaxLen))
{
var num = stepBuf.Replace(",", string.Empty).Replace(".", string.Empty);
if (uint.TryParse(num, out var parsedValue)) settings.step = parsedValue;
}
NewInput("step_label", "Step", "step_input", ref settings.step);
ImGui.Spacing();
// todo validation step?
var invalidInput = !ValidateInput();
ImGui.BeginDisabled(invalidInput);
var inputValidation = ValidateInput();
ImGui.BeginDisabled(!inputValidation.valid);
if (ImGui.Button("Save"))
{
configuration.settings = settings;
configuration.Save();
}
ImGui.EndDisabled();
if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) ImGui.SetTooltip(inputValidation.message);
}
private static void NewInput(string labelId, string labelText, string inputId, ref uint? result)
{
ImGui.LabelText($"###{labelId}", $"{labelText}: ");
ImGui.SameLine(XOffset, Spacing);
ImGui.SetNextItemWidth(InputWidth);
var buf = result?.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;
}
}
/// <summary>
/// Validates inputs for Max bet and Step
/// Validates inputs for Max bet and Step
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private bool ValidateInput()
private (bool valid, string message) ValidateInput()
{
// TODO add explanation why input validation failed
if (settings.maxBet > MaxPossibleBet) return false;
if (settings.step > configuration.settings.maxBet) return false;
var valid = true;
var message = string.Empty;
return true;
if (settings.maxBet > MaxPossibleBet)
{
message += "Entered bet amount exceeds maximum possible bet";
valid = false;
}
if (settings.step > configuration.settings.maxBet)
{
if (!valid) message += "\n";
message += "Entered step change exceeds current maximum bet";
valid = false;
}
;
return (valid, message);
}
}