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 PlayerManager players = new();
public Settings settings; 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; public int Version { get; set; } = 0;
// The below exists just to make saving less cumbersome // 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; namespace HighRollerClassic.DataStructures;
public struct Settings public struct Settings()
{ {
/// <summary> /// <summary>
/// Contains data bout each multiplier, roll, etc. /// Contains data about each multiplier, roll, etc.
/// </summary> /// </summary>
public List<SettingsRolls> rolls; public readonly List<SettingsRolls> rolls = [];
/// <summary>
/// Contains messages such as announcements etc.
/// </summary>
public readonly List<Macro> macros = [];
/// <summary> /// <summary>
/// Maximum bet that will be allowed to set /// Maximum bet that will be allowed to set
/// </summary> /// </summary>
public uint maxBet; public uint? maxBet = 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; 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 // todo remove state as the window will only be opened by us calling it with parameters window id
private readonly Player? player; private readonly Player? player;
private readonly Plugin plugin; private readonly Plugin plugin;
private string name; private readonly string name;
public GambaWindow(Plugin plugin, MenuTargetDefault target) public GambaWindow(Plugin plugin, MenuTargetDefault target)
: base($"High Roller Classic###{target.TargetContentId}", : base($"High Roller Classic###{target.TargetContentId}",
@@ -45,9 +45,15 @@ public class GambaWindow : Window, IDisposable
} }
/* TODO check if all settings are set /* TODO check if all settings are set
bet/step
roll settings roll settings
message/macro 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 // todo if player is null, then allow user to set user by clicking on them manually
if (player == null) if (player == null)

View File

@@ -8,15 +8,14 @@ namespace HighRollerClassic.Windows;
public class SettingsWindow : Window, IDisposable public class SettingsWindow : Window, IDisposable
{ {
private readonly Configuration configuration;
private Settings settings;
private const int XOffset = 80; private const int XOffset = 80;
private const int Spacing = 5; private const int Spacing = 5;
private const int InputWidth = 105; private const int InputWidth = 105;
private const int InputMaxLen = 11; private const int InputMaxLen = 11;
private const uint MaxPossibleBet = 999_999_999; private const uint MaxPossibleBet = 999_999_999;
private readonly Configuration configuration;
private Settings settings;
// We give this window a constant ID using ###. // We give this window a constant ID using ###.
// This allows for labels to be dynamic, like "{FPS Counter}fps###XYZ counter window", // 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; SizeCondition = ImGuiCond.Always;
configuration = plugin.Configuration; configuration = plugin.Configuration;
settings = configuration.settings; settings = new Settings();
} }
public void Dispose() { } public void Dispose() { }
@@ -42,55 +41,72 @@ public class SettingsWindow : Window, IDisposable
// todo set up multiplier, roll, color, etc // todo set up multiplier, roll, color, etc
// todo add button for rolls // todo add button for rolls
ImGui.LabelText("###max_bet_label", "Max bet: "); if (ImGui.Button("Macro Settings")) { }
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 if (ImGui.Button("Add roll")) { }
var betBuf = settings.maxBet.ToString("N0"); // todo add check that there is at least one roll
if (ImGui.InputText("###max_bet_text", ref betBuf, InputMaxLen))
{ NewInput("max_bet_label", "Max bet", "max_bet_text", ref settings.maxBet);
var num = betBuf.Replace(",", string.Empty).Replace(".", string.Empty);
if (uint.TryParse(num, out var parsedValue)) settings.maxBet = parsedValue;
}
ImGui.Spacing(); ImGui.Spacing();
ImGui.LabelText("###step_label", "Step: "); NewInput("step_label", "Step", "step_input", ref settings.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;
}
ImGui.Spacing(); ImGui.Spacing();
// todo validation step? var inputValidation = ValidateInput();
var invalidInput = !ValidateInput();
ImGui.BeginDisabled(!inputValidation.valid);
ImGui.BeginDisabled(invalidInput);
if (ImGui.Button("Save")) if (ImGui.Button("Save"))
{ {
configuration.settings = settings; configuration.settings = settings;
configuration.Save(); configuration.Save();
} }
ImGui.EndDisabled(); 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> /// <summary>
/// Validates inputs for Max bet and Step /// Validates inputs for Max bet and Step
/// </summary> /// </summary>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
private bool ValidateInput() private (bool valid, string message) ValidateInput()
{ {
// TODO add explanation why input validation failed var valid = true;
if (settings.maxBet > MaxPossibleBet) return false; var message = string.Empty;
if (settings.step > configuration.settings.maxBet) return false;
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);
} }
} }