Add settings window

This commit is contained in:
Asriel Camora
2023-06-29 13:11:18 -07:00
parent d982a9b8c5
commit 5205497946
6 changed files with 113 additions and 9 deletions
+1
View File
@@ -148,6 +148,7 @@ csharp_indent_labels = flush_left
dotnet_diagnostic.MA0049.severity = silent dotnet_diagnostic.MA0049.severity = silent
dotnet_diagnostic.MA0007.severity = silent dotnet_diagnostic.MA0007.severity = silent
dotnet_diagnostic.MA0048.severity = silent dotnet_diagnostic.MA0048.severity = silent
dotnet_diagnostic.MA0051.severity = silent
dotnet_diagnostic.MA0006.severity = suggestion dotnet_diagnostic.MA0006.severity = suggestion
dotnet_diagnostic.MA0016.severity = suggestion dotnet_diagnostic.MA0016.severity = suggestion
dotnet_diagnostic.MA0008.severity = suggestion dotnet_diagnostic.MA0008.severity = suggestion
+8 -2
View File
@@ -37,7 +37,7 @@ public sealed class Plugin : IDalamudPlugin
}); });
Service.PluginInterface.UiBuilder.Draw += WindowSystem.Draw; Service.PluginInterface.UiBuilder.Draw += WindowSystem.Draw;
Service.PluginInterface.UiBuilder.OpenConfigUi += () => SettingsWindow.IsOpen = true; Service.PluginInterface.UiBuilder.OpenConfigUi += OpenSettingsWindow;
} }
public void OpenSimulatorWindow(Item item, bool isExpert, SimulationInput input, ClassJob classJob, Macro? macro) public void OpenSimulatorWindow(Item item, bool isExpert, SimulationInput input, ClassJob classJob, Macro? macro)
@@ -50,6 +50,12 @@ public sealed class Plugin : IDalamudPlugin
SimulatorWindow = new(item, isExpert, input, classJob, macro); SimulatorWindow = new(item, isExpert, input, classJob, macro);
} }
public void OpenSettingsWindow()
{
SettingsWindow.IsOpen = true;
SettingsWindow.BringToFront();
}
public void Dispose() public void Dispose()
{ {
Service.CommandManager.RemoveHandler("/craft"); Service.CommandManager.RemoveHandler("/craft");
@@ -61,6 +67,6 @@ public sealed class Plugin : IDalamudPlugin
if (command != "/craft") if (command != "/craft")
return; return;
SettingsWindow.IsOpen = true; OpenSettingsWindow();
} }
} }
+1 -2
View File
@@ -135,7 +135,7 @@ public unsafe class CraftingLog : Window
Random = new(); Random = new();
} }
public CraftingLog() : base("RecipeNoteHelper", WindowFlags, true) public CraftingLog() : base("Craftimizer RecipeNoteHelper", WindowFlags, true)
{ {
Service.WindowSystem.AddWindow(this); Service.WindowSystem.AddWindow(this);
@@ -286,7 +286,6 @@ public unsafe class CraftingLog : Window
private void DrawMacros() private void DrawMacros()
{ {
var padding = ImGui.GetStyle().FramePadding; var padding = ImGui.GetStyle().FramePadding;
var itemPadding = ImGui.GetStyle().ItemInnerSpacing;
var fontSize = ImGui.GetFontSize(); var fontSize = ImGui.GetFontSize();
var height = fontSize + (padding.Y * 2); var height = fontSize + (padding.Y * 2);
+99 -3
View File
@@ -9,6 +9,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Numerics; using System.Numerics;
using System.Diagnostics;
namespace Craftimizer.Plugin.Windows; namespace Craftimizer.Plugin.Windows;
@@ -16,7 +17,7 @@ public class SettingsWindow : Window
{ {
private static Configuration Config => Service.Configuration; private static Configuration Config => Service.Configuration;
public SettingsWindow() : base("Craftimizer") public SettingsWindow() : base("Craftimizer Settings")
{ {
Service.WindowSystem.AddWindow(this); Service.WindowSystem.AddWindow(this);
@@ -30,8 +31,103 @@ public class SettingsWindow : Window
public override void Draw() public override void Draw()
{ {
var val = Config.OverrideUncraftability; bool val;
if (ImGui.Checkbox("Override Uncraftability Warning", ref val)) float valF;
int valI;
ImGuiUtils.BeginGroupPanel("General");
var isDirty = false;
val = Config.OverrideUncraftability;
if (ImGui.Checkbox("Override uncraftability warning", ref val))
{
Config.OverrideUncraftability = val; Config.OverrideUncraftability = val;
isDirty = true;
}
val = Config.HideUnlearnedActions;
if (ImGui.Checkbox("Show only learned actions", ref val))
{
Config.HideUnlearnedActions = val;
isDirty = true;
}
val = Config.ConditionRandomness;
if (ImGui.Checkbox("Condition randomness", ref val))
{
Config.ConditionRandomness = val;
isDirty = true;
}
ImGuiUtils.EndGroupPanel();
ImGuiUtils.BeginGroupPanel("Solver");
ImGui.TextWrapped("Credit to altosock's Craftingway for the original algorithm");
if (ImGui.Button("Open Craftingway"))
Process.Start(new ProcessStartInfo { FileName = "https://craftingway.app", UseShellExecute = true });
ImGuiHelpers.ScaledDummy(10);
var config = Config.SolverConfig;
var isSolverDirty = false;
valI = config.Iterations;
ImGui.SetNextItemWidth(200);
if (ImGui.InputInt("Iterations", ref valI))
{
config = config with { Iterations = valI };
isSolverDirty = true;
}
valF = config.ScoreStorageThreshold;
ImGui.SetNextItemWidth(200);
if (ImGui.InputFloat("Score Storage Threshold", ref valF))
{
config = config with { ScoreStorageThreshold = valF };
isSolverDirty = true;
}
valF = config.MaxScoreWeightingConstant;
ImGui.SetNextItemWidth(200);
if (ImGui.InputFloat("Score Weighting Constant", ref valF))
{
config = config with { MaxScoreWeightingConstant = valF };
isSolverDirty = true;
}
valF = config.ExplorationConstant;
ImGui.SetNextItemWidth(200);
if (ImGui.InputFloat("Exploration Constant", ref valF))
{
config = config with { ExplorationConstant = valF };
isSolverDirty = true;
}
valI = config.MaxStepCount;
ImGui.SetNextItemWidth(200);
if (ImGui.InputInt("Max Step Count", ref valI))
{
config = config with { MaxStepCount = valI };
isSolverDirty = true;
}
if (ImGui.Button("Reset to defaults"))
{
config = new();
isSolverDirty = true;
}
if (isSolverDirty)
{
Config.SolverConfig = config;
isDirty = true;
}
ImGuiUtils.EndGroupPanel();
if (isDirty)
Config.Save();
} }
} }
+2 -1
View File
@@ -1,6 +1,7 @@
using Craftimizer.Simulator; using Craftimizer.Simulator;
using Craftimizer.Simulator.Actions; using Craftimizer.Simulator.Actions;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Utility;
using ImGuiNET; using ImGuiNET;
using Lumina.Excel.GeneratedSheets; using Lumina.Excel.GeneratedSheets;
using System; using System;
@@ -29,7 +30,7 @@ public sealed partial class SimulatorWindow : Window, IDisposable
// Simulator is set by ResetSimulator() // Simulator is set by ResetSimulator()
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public SimulatorWindow(Item item, bool isExpert, SimulationInput input, ClassJob classJob, Macro? macro) : base("Simulator", WindowFlags) public SimulatorWindow(Item item, bool isExpert, SimulationInput input, ClassJob classJob, Macro? macro) : base("Craftimizer Simulator", WindowFlags)
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{ {
Service.WindowSystem.AddWindow(this); Service.WindowSystem.AddWindow(this);
+2 -1
View File
@@ -328,7 +328,8 @@ public sealed partial class SimulatorWindow : Window, IDisposable
var cogWidth = ImGui.CalcTextSize(FontAwesomeIcon.Cog.ToIconString()).X; var cogWidth = ImGui.CalcTextSize(FontAwesomeIcon.Cog.ToIconString()).X;
ImGui.PopFont(); ImGui.PopFont();
ImGui.SameLine(0, totalWidth - ImGui.GetStyle().ItemSpacing.X - checkboxWidth - cogWidth); ImGui.SameLine(0, totalWidth - ImGui.GetStyle().ItemSpacing.X - checkboxWidth - cogWidth);
ImGuiComponents.IconButton("simSettingsButton", FontAwesomeIcon.Cog); if (ImGuiComponents.IconButton("simSettingsButton", FontAwesomeIcon.Cog))
Service.Plugin.OpenSettingsWindow();
// //