diff --git a/Craftimizer/Plugin.cs b/Craftimizer/Plugin.cs index 6fefd28..cb31ff4 100644 --- a/Craftimizer/Plugin.cs +++ b/Craftimizer/Plugin.cs @@ -74,6 +74,12 @@ public sealed class Plugin : IDalamudPlugin SettingsWindow.BringToFront(); } + public void OpenSettingsTab(string selectedTabLabel) + { + OpenSettingsWindow(); + SettingsWindow.SelectTab(selectedTabLabel); + } + public void Dispose() { SimulatorWindow?.Dispose(); diff --git a/Craftimizer/Windows/Craft.cs b/Craftimizer/Windows/Craft.cs index 26c61c1..4345a99 100644 --- a/Craftimizer/Windows/Craft.cs +++ b/Craftimizer/Windows/Craft.cs @@ -61,7 +61,7 @@ public sealed unsafe partial class Craft : Window, IDisposable ImGui.SameLine(); if (ImGuiComponents.IconButton("synthSettingsButton", FontAwesomeIcon.Cog)) - Service.Plugin.OpenSettingsWindow(); + Service.Plugin.OpenSettingsTab(Settings.TabSynthHelper); } private void DrawActions() diff --git a/Craftimizer/Windows/Settings.cs b/Craftimizer/Windows/Settings.cs index ad3eef0..a643f08 100644 --- a/Craftimizer/Windows/Settings.cs +++ b/Craftimizer/Windows/Settings.cs @@ -14,6 +14,13 @@ public class Settings : Window private const int OptionWidth = 200; private static Vector2 OptionButtonSize => new(OptionWidth, ImGuiUtils.ButtonHeight); + public const string TabGeneral = "General"; + public const string TabSimulator = "Simulator"; + public const string TabSynthHelper = "Synthesis Helper"; + public const string TabAbout = "About"; + + private string? SelectedTab { get; set; } + public Settings() : base("Craftimizer Settings") { Service.WindowSystem.AddWindow(this); @@ -27,6 +34,23 @@ public class Settings : Window SizeCondition = ImGuiCond.Appearing; } + public void SelectTab(string label) + { + SelectedTab = label; + } + + private bool BeginTabItem(string label) + { + var isSelected = string.Equals(SelectedTab, label, StringComparison.Ordinal); + if (isSelected) + { + SelectedTab = null; + var open = true; + return ImGui.BeginTabItem(label, ref open, ImGuiTabItemFlags.SetSelected); + } + return ImGui.BeginTabItem(label); + } + private static void DrawOption(string label, string tooltip, bool val, Action setter, ref bool isDirty) { if (ImGui.Checkbox(label, ref val)) @@ -101,9 +125,9 @@ public class Settings : Window } } - private static void DrawTabGeneral() + private void DrawTabGeneral() { - if (!ImGui.BeginTabItem("General")) + if (!BeginTabItem("General")) return; ImGuiHelpers.ScaledDummy(5); @@ -352,9 +376,9 @@ public class Settings : Window configRef = config; } - private static void DrawTabSimulator() + private void DrawTabSimulator() { - if (!ImGui.BeginTabItem("Simulator")) + if (!BeginTabItem("Simulator")) return; ImGuiHelpers.ScaledDummy(5); @@ -397,9 +421,9 @@ public class Settings : Window ImGui.EndTabItem(); } - private static void DrawTabSynthHelper() + private void DrawTabSynthHelper() { - if (!ImGui.BeginTabItem("Synthesis Helper")) + if (!BeginTabItem("Synthesis Helper")) return; ImGuiHelpers.ScaledDummy(5); @@ -432,9 +456,9 @@ public class Settings : Window ImGui.EndTabItem(); } - private static void DrawTabAbout() + private void DrawTabAbout() { - if (!ImGui.BeginTabItem("About")) + if (!BeginTabItem("About")) return; ImGuiHelpers.ScaledDummy(5); diff --git a/Craftimizer/Windows/SimulatorDrawer.cs b/Craftimizer/Windows/SimulatorDrawer.cs index d4e2c76..c15a312 100644 --- a/Craftimizer/Windows/SimulatorDrawer.cs +++ b/Craftimizer/Windows/SimulatorDrawer.cs @@ -332,7 +332,7 @@ public sealed partial class Simulator : Window, IDisposable ImGui.PopFont(); ImGui.SameLine(0, totalWidth - ImGui.GetStyle().ItemSpacing.X - checkboxWidth - cogWidth); if (ImGuiComponents.IconButton("simSettingsButton", FontAwesomeIcon.Cog)) - Service.Plugin.OpenSettingsWindow(); + Service.Plugin.OpenSettingsTab(Settings.TabSimulator); //