alert icon implementation
This commit is contained in:
@@ -7,12 +7,12 @@ public struct Settings()
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains data about each multiplier, roll, etc.
|
/// Contains data about each multiplier, roll, etc.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly List<SettingsRoll> rolls = [];
|
public readonly List<SettingsRoll> rolls = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains messages such as announcements etc.
|
/// Contains messages such as announcements etc.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly List<MessageMacro> macros = [];
|
public readonly List<MessageMacro> macros = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Maximum bet that will be allowed to set
|
/// Maximum bet that will be allowed to set
|
||||||
@@ -23,4 +23,9 @@ public struct Settings()
|
|||||||
/// 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 = null;
|
public uint? step = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether developer options should be visible in the settings
|
||||||
|
/// </summary>
|
||||||
|
public bool devOptions = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using Dalamud.Bindings.ImGui;
|
using Dalamud.Bindings.ImGui;
|
||||||
using Dalamud.Interface.Components;
|
using Dalamud.Interface.Components;
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
@@ -15,20 +16,21 @@ public class SettingsWindow : Window, IDisposable
|
|||||||
private const int InputMaxLen = 11;
|
private const int InputMaxLen = 11;
|
||||||
|
|
||||||
private const uint RollSettingInputWidth = 50;
|
private const uint RollSettingInputWidth = 50;
|
||||||
|
|
||||||
private const uint MaxAllowedGil = 999_999_999;
|
private const uint MaxAllowedGil = 999_999_999;
|
||||||
private readonly Configuration configuration;
|
private readonly Configuration configuration;
|
||||||
private Settings settings;
|
|
||||||
|
|
||||||
private bool maxBetFormatValid = true;
|
private bool maxBetFormatValid = true;
|
||||||
private bool stepFormatValid = true;
|
|
||||||
|
|
||||||
// todo proper implementation it's just a placeholder
|
|
||||||
private bool TempRoll => newRoll.HasValue;
|
|
||||||
private SettingsRoll? newRoll;
|
private SettingsRoll? newRoll;
|
||||||
|
|
||||||
private (uint min, uint max) rollInterval = (1, 999);
|
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 Settings")
|
||||||
{
|
{
|
||||||
Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar |
|
Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar |
|
||||||
@@ -42,12 +44,40 @@ public class SettingsWindow : Window, IDisposable
|
|||||||
settings = configuration.Settings;
|
settings = configuration.Settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo proper implementation it's just a placeholder
|
||||||
|
private bool TempRoll => newRoll.HasValue;
|
||||||
|
|
||||||
public void Dispose() { }
|
public void Dispose() { }
|
||||||
|
|
||||||
public override void PreDraw() { }
|
public override void PreDraw() { }
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
|
// todo integrate for every field
|
||||||
|
var drawList = ImGui.GetWindowDrawList();
|
||||||
|
|
||||||
|
var center = ImGui.GetCursorScreenPos();
|
||||||
|
const uint radius = 10;
|
||||||
|
|
||||||
|
var circleColor = ImGui.GetColorU32(yellow);
|
||||||
|
var borderColor = ImGui.GetColorU32(red);
|
||||||
|
var textColor = ImGui.GetColorU32(red);
|
||||||
|
|
||||||
|
drawList.AddCircleFilled(center + new Vector2(radius, radius), radius, circleColor);
|
||||||
|
drawList.AddCircle(center + new Vector2(radius, radius), radius, borderColor, 0, 2.5f);
|
||||||
|
|
||||||
|
const string text = "!";
|
||||||
|
var textSize = ImGui.CalcTextSize(text);
|
||||||
|
var textPos = center + new Vector2(
|
||||||
|
radius - (textSize.X * 0.5f),
|
||||||
|
radius - (textSize.Y * 0.5f)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
drawList.AddText(textPos, textColor, text);
|
||||||
|
|
||||||
|
ImGui.Dummy(new Vector2(radius * 2f, radius * 2f));
|
||||||
|
|
||||||
// todo set up multiplier, roll, color, etc
|
// todo set up multiplier, roll, color, etc
|
||||||
// todo add button for rolls
|
// todo add button for rolls
|
||||||
|
|
||||||
@@ -56,25 +86,38 @@ public class SettingsWindow : Window, IDisposable
|
|||||||
// TODO no new rolls must be there
|
// TODO no new rolls must be there
|
||||||
newRoll = new SettingsRoll();
|
newRoll = new SettingsRoll();
|
||||||
}
|
}
|
||||||
if (ImGui.CollapsingHeader("Rolls###settings", ImGuiTreeNodeFlags.DefaultOpen))
|
|
||||||
|
if (ImGui.CollapsingHeader("Rolls##settings"))
|
||||||
{
|
{
|
||||||
// todo here we put new rolls
|
// todo here we put new rolls
|
||||||
foreach (var roll in settings.rolls)
|
// foreach (var roll in settings.rolls)
|
||||||
{
|
// {
|
||||||
// todo here we put existing rolls
|
// // todo here we put existing rolls
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxbetValid = NewInput("max_bet_label", "Max bet", "max_bet_text", ref settings.maxBet);
|
if (ImGui.CollapsingHeader("General##settings"))
|
||||||
if (maxbetValid.HasValue) maxBetFormatValid = maxbetValid.Value;
|
{
|
||||||
ImGui.Spacing();
|
var maxbetValid = LabelTextInput("max_bet_label", "Max bet", "max_bet_text", ref settings.maxBet);
|
||||||
|
if (maxbetValid.HasValue) maxBetFormatValid = maxbetValid.Value;
|
||||||
|
ImGui.Spacing();
|
||||||
|
|
||||||
var stepValid = NewInput("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;
|
if (stepValid.HasValue) stepFormatValid = stepValid.Value;
|
||||||
ImGui.Spacing();
|
ImGui.Spacing();
|
||||||
|
|
||||||
|
ImGui.Checkbox("Developer options", ref settings.devOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configuration.Settings.devOptions && ImGui.CollapsingHeader("Developer options"))
|
||||||
|
{
|
||||||
|
// todo add developer settings - like the ability to have every character have HRC open
|
||||||
|
}
|
||||||
|
|
||||||
var inputValidation = ValidateInput();
|
var inputValidation = ValidateInput();
|
||||||
|
|
||||||
|
ImGui.Spacing();
|
||||||
|
|
||||||
ImGui.BeginDisabled(!inputValidation.valid);
|
ImGui.BeginDisabled(!inputValidation.valid);
|
||||||
|
|
||||||
if (ImGui.Button("Save"))
|
if (ImGui.Button("Save"))
|
||||||
@@ -88,37 +131,39 @@ public class SettingsWindow : Window, IDisposable
|
|||||||
|
|
||||||
ImGui.EndDisabled();
|
ImGui.EndDisabled();
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
if (!inputValidation.valid && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) ImGui.SetTooltip(inputValidation.message);
|
if (!inputValidation.valid && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
|
||||||
|
ImGui.SetTooltip(inputValidation.message);
|
||||||
|
|
||||||
if (ImGui.Button("Reset")) settings = configuration.Settings;
|
if (ImGui.Button("Reset")) settings = configuration.Settings;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns false if the roll is to be removed
|
/// Returns false if the roll is to be removed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="multiplier">gil multiplication in case of a roll</param>
|
/// <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="exact">if roll is checked on less/less or equal comparison</param>
|
||||||
/// <param name="roll">how much user rolls</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="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>
|
/// <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? DisplayRollSetting(
|
||||||
|
ref uint multiplier, ref bool exact, ref uint roll, ref Vector4 colour, ref uint id)
|
||||||
{
|
{
|
||||||
ImGui.SetNextItemWidth(RollSettingInputWidth);
|
ImGui.SetNextItemWidth(RollSettingInputWidth);
|
||||||
ImGui.InputUInt($"##multiplier{id}", ref multiplier);
|
ImGui.InputUInt($"##multiplier{id}", ref multiplier);
|
||||||
|
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
|
|
||||||
ImGui.Text("x");
|
ImGui.Text("x");
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
|
|
||||||
ImGui.SetNextItemWidth(RollSettingInputWidth);
|
ImGui.SetNextItemWidth(RollSettingInputWidth);
|
||||||
ImGui.InputUInt($"##roll{id}", ref roll);
|
ImGui.InputUInt($"##roll{id}", ref roll);
|
||||||
|
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
var newColour = ImGuiComponents.ColorPickerWithPalette(
|
var newColour = ImGuiComponents.ColorPickerWithPalette(
|
||||||
(int)id, "placeholder", colour);
|
(int)id, "placeholder", colour);
|
||||||
|
|
||||||
|
ImGui.SameLine();
|
||||||
if (ImGui.Button("-"))
|
if (ImGui.Button("-"))
|
||||||
{
|
{
|
||||||
// signals to the colour to remove this roll setting
|
// signals to the colour to remove this roll setting
|
||||||
@@ -129,38 +174,37 @@ public class SettingsWindow : Window, IDisposable
|
|||||||
// we need to verify if data inputted is "good"
|
// we need to verify if data inputted is "good"
|
||||||
|
|
||||||
return ValidateRollSetting();
|
return ValidateRollSetting();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ValidateRollSetting()
|
private bool ValidateRollSetting()
|
||||||
{
|
{
|
||||||
// multiplier must not already exist
|
// multiplier must not already exist
|
||||||
|
|
||||||
// roll must be between 1 and 999
|
// roll must be between 1 and 999
|
||||||
|
|
||||||
// roll must not already exist
|
// roll must not already exist
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns true if valid, false if invalid or null if validity has no changed
|
/// Returns true if valid, false if invalid or null if validity has no changed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="labelId">id of the label field</param>
|
/// <param name="labelId">id of the label field</param>
|
||||||
/// <param name="labelText">text for the label input field</param>
|
/// <param name="labelText">text for the label input field</param>
|
||||||
/// <param name="inputId">id of the input field</param>
|
/// <param name="inputId">id of the input field</param>
|
||||||
/// <param name="result">new value if parsing was successful</param>
|
/// <param name="result">new value if parsing was successful</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static bool? NewInput(string labelId, string labelText, string inputId, ref uint? result)
|
private bool? LabelTextInput(string labelId, string labelText, string inputId, ref uint? result)
|
||||||
{
|
{
|
||||||
bool? valid = null;
|
bool? valid = null;
|
||||||
|
|
||||||
ImGui.LabelText($"###{labelId}", $"{labelText}: ");
|
ImGui.LabelText($"###{labelId}", $"{labelText}: ");
|
||||||
ImGui.SameLine(XOffset, Spacing);
|
ImGui.SameLine(XOffset, Spacing);
|
||||||
ImGui.SetNextItemWidth(InputWidth);
|
ImGui.SetNextItemWidth(InputWidth);
|
||||||
|
|
||||||
var buf = result?.ToString("N0") ?? "";
|
var buf = result?.ToString("N0") ?? "";
|
||||||
|
|
||||||
if (ImGui.InputText($"###{inputId}", ref buf, InputMaxLen))
|
if (ImGui.InputText($"###{inputId}", ref buf, InputMaxLen))
|
||||||
{
|
{
|
||||||
var num = buf.Replace(",", string.Empty).Replace(".", string.Empty);
|
var num = buf.Replace(",", string.Empty).Replace(".", string.Empty);
|
||||||
@@ -170,10 +214,14 @@ public class SettingsWindow : Window, IDisposable
|
|||||||
valid = true;
|
valid = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo alert that appears when field doesn't match the configuration
|
||||||
|
ImGui.SameLine();
|
||||||
|
ImGui.Text("*");
|
||||||
|
|
||||||
|
// todo place the alert if field validation fails
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
@@ -187,20 +235,13 @@ public class SettingsWindow : Window, IDisposable
|
|||||||
var valid = true;
|
var valid = true;
|
||||||
var message = string.Empty;
|
var message = string.Empty;
|
||||||
|
|
||||||
if (!maxBetFormatValid || !stepFormatValid)
|
if (!maxBetFormatValid || !stepFormatValid) SetError("Input fields have invalid data", ref message, ref valid);
|
||||||
{
|
|
||||||
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);
|
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);
|
SetError("Step change must not exceed current maximum bet", ref message, ref valid);
|
||||||
}
|
|
||||||
|
|
||||||
return (valid, message);
|
return (valid, message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user