Settings implementation

This commit is contained in:
2025-12-27 00:39:22 +01:00
parent 5eb4b92513
commit b6813c6f76
10 changed files with 151 additions and 82 deletions

View File

@@ -1,16 +1,16 @@
using Dalamud.Configuration; using System;
using System; using Dalamud.Configuration;
using HighRollerClassic.DataStructures;
namespace HighRollerClassic; namespace HighRollerClassic;
[Serializable] [Serializable]
public class Configuration : IPluginConfiguration public class Configuration : IPluginConfiguration
{ {
public PlayerManager players = new();
public Settings settings;
public int Version { get; set; } = 0; public int Version { get; set; } = 0;
public bool IsConfigWindowMovable { get; set; } = true;
public bool SomePropertyToBeSavedAndWithADefault { get; set; } = true;
// The below exists just to make saving less cumbersome // The below exists just to make saving less cumbersome
public void Save() public void Save()
{ {

View File

@@ -0,0 +1,8 @@
namespace HighRollerClassic.DataStructures;
public struct Roll
{
private uint value;
private uint multiplier;
private uint sum;
}

View File

@@ -0,0 +1,21 @@
using System.Collections.Generic;
namespace HighRollerClassic.DataStructures;
public struct Settings
{
/// <summary>
/// Contains data about each multiplier, roll, etc.
/// </summary>
private List<SettingsRolls> rolls;
/// <summary>
/// Maximum bet that will be allowed to set
/// </summary>
private uint max_bet;
/// <summary>
/// How much the bet will change when user adjusts their bet via +/- keys
/// </summary>
private uint step;
}

View File

@@ -0,0 +1,11 @@
using System.Numerics;
namespace HighRollerClassic.DataStructures;
public struct SettingsRolls
{
private uint multiplier;
private uint roll;
private bool exact;
private Vector4 color;
}

View File

@@ -1,17 +1,14 @@
using Dalamud.Game.Gui.ContextMenu; using Dalamud.Game.Gui.ContextMenu;
using HighRollerClassic.DataStructures;
namespace HighRollerClassic; namespace HighRollerClassic;
public class Player public class Player(MenuTargetDefault target)
{ {
private int balance; private Roll rolls = new();
private ulong content_id; public int Bank { get; private set; } = 0;
private string name; public string Name { get; private set; } = target.TargetName;
// todo maybe remove it and tie it to dalamud's api to get accurate character name once per session
public Player(MenuTargetDefault target) public ulong ContentId { get; private set; } = target.TargetContentId;
{
content_id = target.TargetContentId;
name = target.TargetName;
// get balance from DB
}
} }

View File

@@ -0,0 +1,20 @@
using System.Collections.Generic;
using System.Linq;
using Dalamud.Game.Gui.ContextMenu;
namespace HighRollerClassic;
public class PlayerManager
{
private List<Player> Players { get; set; } = [];
public Player GetPlayer(MenuTargetDefault target)
{
foreach (var player in Players)
if (player.ContentId == target.TargetContentId)
return player;
Players.Add(new Player(target));
return Players.Last();
}
}

View File

@@ -21,10 +21,10 @@ public sealed class Plugin : IDalamudPlugin
{ {
Configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); Configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
ConfigWindow = new ConfigWindow(this); SettingsWindow = new SettingsWindow(this);
MainWindow = new MainWindow(this, state); MainWindow = new MainWindow(this, state);
WindowSystem.AddWindow(ConfigWindow); WindowSystem.AddWindow(SettingsWindow);
WindowSystem.AddWindow(MainWindow); WindowSystem.AddWindow(MainWindow);
CommandManager.AddHandler(CommandName, new CommandInfo(OnCommand) CommandManager.AddHandler(CommandName, new CommandInfo(OnCommand)
@@ -76,7 +76,7 @@ public sealed class Plugin : IDalamudPlugin
internal static IContextMenu ContextMenu { get; private set; } = null!; internal static IContextMenu ContextMenu { get; private set; } = null!;
public Configuration Configuration { get; init; } public Configuration Configuration { get; init; }
private ConfigWindow ConfigWindow { get; init; } private SettingsWindow SettingsWindow { get; init; }
private MainWindow MainWindow { get; init; } private MainWindow MainWindow { get; init; }
public void Dispose() public void Dispose()
@@ -88,7 +88,7 @@ public sealed class Plugin : IDalamudPlugin
WindowSystem.RemoveAllWindows(); WindowSystem.RemoveAllWindows();
ConfigWindow.Dispose(); SettingsWindow.Dispose();
MainWindow.Dispose(); MainWindow.Dispose();
CommandManager.RemoveHandler(CommandName); CommandManager.RemoveHandler(CommandName);
@@ -100,12 +100,11 @@ public sealed class Plugin : IDalamudPlugin
{ {
// In response to the slash command, toggle the display status of our main ui // In response to the slash command, toggle the display status of our main ui
MainWindow.Toggle(); MainWindow.Toggle();
MainWindow.Draw();
} }
public void ToggleConfigUi() public void ToggleConfigUi()
{ {
ConfigWindow.Toggle(); SettingsWindow.Toggle();
} }
public void ToggleMainUi() public void ToggleMainUi()
@@ -113,6 +112,11 @@ public sealed class Plugin : IDalamudPlugin
MainWindow.Toggle(); MainWindow.Toggle();
} }
public bool PlayerIsLoaded()
{
return PlayerState.IsLoaded;
}
private void OnContextMenuOpened(IMenuOpenedArgs args) private void OnContextMenuOpened(IMenuOpenedArgs args)
{ {
if (args.MenuType == ContextMenuType.Inventory) return; if (args.MenuType == ContextMenuType.Inventory) return;

View File

@@ -1,55 +0,0 @@
using System;
using System.Numerics;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Windowing;
namespace HighRollerClassic.Windows;
public class ConfigWindow : Window, IDisposable
{
private readonly Configuration configuration;
// We give this window a constant ID using ###.
// This allows for labels to be dynamic, like "{FPS Counter}fps###XYZ counter window",
// and the window ID will always be "###XYZ counter window" for ImGui
public ConfigWindow(Plugin plugin) : base("A Wonderful Configuration Window###With a constant ID")
{
Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar |
ImGuiWindowFlags.NoScrollWithMouse;
Size = new Vector2(232, 90);
SizeCondition = ImGuiCond.Always;
configuration = plugin.Configuration;
}
public void Dispose() { }
public override void PreDraw()
{
// Flags must be added or removed before Draw() is being called, or they won't apply
if (configuration.IsConfigWindowMovable)
Flags &= ~ImGuiWindowFlags.NoMove;
else
Flags |= ImGuiWindowFlags.NoMove;
}
public override void Draw()
{
// Can't ref a property, so use a local copy
var configValue = configuration.SomePropertyToBeSavedAndWithADefault;
if (ImGui.Checkbox("Random Config Bool", ref configValue))
{
configuration.SomePropertyToBeSavedAndWithADefault = configValue;
// Can save immediately on change if you don't want to provide a "Save and Close" button
configuration.Save();
}
var movable = configuration.IsConfigWindowMovable;
if (ImGui.Checkbox("Movable Config Window", ref movable))
{
configuration.IsConfigWindowMovable = movable;
configuration.Save();
}
}
}

View File

@@ -7,12 +7,10 @@ namespace HighRollerClassic.Windows;
public class MainWindow : Window, IDisposable public class MainWindow : Window, IDisposable
{ {
private readonly Configuration configuration;
private readonly Plugin plugin; private readonly Plugin plugin;
private readonly PluginState state; private readonly PluginState state;
// We give this window a hidden ID using ##.
// The user will see "My Amazing Window" as window title,
// but for ImGui the ID is "My Amazing Window##With a hidden ID"
public MainWindow(Plugin plugin, PluginState state) public MainWindow(Plugin plugin, PluginState state)
: base($"High Roller Classic###{state.Target?.TargetName ?? "null"}", : base($"High Roller Classic###{state.Target?.TargetName ?? "null"}",
ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse) ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)
@@ -24,6 +22,7 @@ public class MainWindow : Window, IDisposable
}; };
this.plugin = plugin; this.plugin = plugin;
configuration = this.plugin.Configuration;
this.state = state; this.state = state;
} }
@@ -32,10 +31,32 @@ public class MainWindow : Window, IDisposable
public override void Draw() public override void Draw()
{ {
// TODO check if local player is null and if it is do not load anything // TODO check if local player is null and if it is do not load anything
// TODO check if all settings are set
if (!plugin.PlayerIsLoaded())
{
ImGui.Text("Player must be loaded in the world in order for the plugin to function");
return;
}
/* TODO check if all settings are set
roll settings
message/macro settings
*/
// TODO create player project and clear the existing shared state // TODO create player project and clear the existing shared state
if (state.Target != null) if (state.Target == null)
ImGui.Text($"Current selected target is {state.Target?.TargetName}"); {
ImGui.Text(
"No target selected, please open HRC by right clicking the player and choosing the 'High Roller Classic' option");
return;
}
var player = configuration.players.GetPlayer(state.Target);
state.Target = null;
ImGui.Text($"Player: {player}");
ImGui.Spacing();
ImGui.Text($"Bank balance: {player.Bank} gil");
} }
} }

View File

@@ -0,0 +1,42 @@
using System;
using System.Numerics;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Windowing;
using HighRollerClassic.DataStructures;
namespace HighRollerClassic.Windows;
public class SettingsWindow : Window, IDisposable
{
private readonly Configuration configuration;
// We give this window a constant ID using ###.
// This allows for labels to be dynamic, like "{FPS Counter}fps###XYZ counter window",
// and the window ID will always be "###XYZ counter window" for ImGui
public SettingsWindow(Plugin plugin) : base("Settings###HRC")
{
Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar |
ImGuiWindowFlags.NoScrollWithMouse;
Size = new Vector2(232, 90);
SizeCondition = ImGuiCond.Always;
configuration = plugin.Configuration;
}
public void Dispose() { }
public override void PreDraw() { }
public override void Draw()
{
Settings settings;
// todo set up multiplier, roll, color, etc
// todo add button for rolls
// todo setup max bet, change
// todo save button which will copy our settings to configuration and invoke .Save() to save configuration to disk
}
}