From 654978dd6450de6b40ea390863263d0776f1eab8 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Tue, 9 May 2023 20:04:23 +0200 Subject: [PATCH] Store last tab selected. --- Penumbra/Configuration.cs | 2 ++ Penumbra/UI/ConfigWindow.cs | 10 ++++++++-- Penumbra/UI/Tabs/ConfigTabBar.cs | 22 ++++++++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Penumbra/Configuration.cs b/Penumbra/Configuration.cs index f71e4d32..ba8ca1cc 100644 --- a/Penumbra/Configuration.cs +++ b/Penumbra/Configuration.cs @@ -9,6 +9,7 @@ using OtterGui; using OtterGui.Classes; using OtterGui.Filesystem; using OtterGui.Widgets; +using Penumbra.Api.Enums; using Penumbra.GameData.Enums; using Penumbra.Import.Structs; using Penumbra.Interop.Services; @@ -87,6 +88,7 @@ public class Configuration : IPluginConfiguration, ISavable public string QuickMoveFolder3 { get; set; } = string.Empty; public DoubleModifier DeleteModModifier { get; set; } = new(ModifierHotkey.Control, ModifierHotkey.Shift); public CollectionsTab.PanelMode CollectionPanel { get; set; } = CollectionsTab.PanelMode.SimpleAssignment; + public TabType SelectedTab { get; set; } = TabType.Settings; public bool PrintSuccessfulCommandsToChat { get; set; } = true; public bool FixMainWindow { get; set; } = false; diff --git a/Penumbra/UI/ConfigWindow.cs b/Penumbra/UI/ConfigWindow.cs index 0007f53a..8d22fe01 100644 --- a/Penumbra/UI/ConfigWindow.cs +++ b/Penumbra/UI/ConfigWindow.cs @@ -43,13 +43,14 @@ public sealed class ConfigWindow : Window RespectCloseHotkey = true; tutorial.UpdateTutorialStep(); - IsOpen = _config.DebugMode; + IsOpen = _config.DebugMode; } public void Setup(Penumbra penumbra, ConfigTabBar configTabs) { _penumbra = penumbra; _configTabs = configTabs; + SelectTab(_config.SelectedTab); } public override bool DrawConditions() @@ -108,7 +109,12 @@ public sealed class ConfigWindow : Window } else { - _configTabs.Draw(); + var type = _configTabs.Draw(); + if (type != _config.SelectedTab) + { + _config.SelectedTab = type; + _config.Save(); + } } _lastException = null; diff --git a/Penumbra/UI/Tabs/ConfigTabBar.cs b/Penumbra/UI/Tabs/ConfigTabBar.cs index f778daea..b221224d 100644 --- a/Penumbra/UI/Tabs/ConfigTabBar.cs +++ b/Penumbra/UI/Tabs/ConfigTabBar.cs @@ -48,10 +48,12 @@ public class ConfigTabBar }; } - public void Draw() + public TabType Draw() { - if (TabBar.Draw(string.Empty, ImGuiTabBarFlags.NoTooltip, ToLabel(SelectTab), out _, () => { }, Tabs)) + if (TabBar.Draw(string.Empty, ImGuiTabBarFlags.NoTooltip, ToLabel(SelectTab), out var currentLabel, () => { }, Tabs)) SelectTab = TabType.None; + + return FromLabel(currentLabel); } private ReadOnlySpan ToLabel(TabType type) @@ -68,4 +70,20 @@ public class ConfigTabBar TabType.ResourceManager => Resource.Label, _ => ReadOnlySpan.Empty, }; + + private TabType FromLabel(ReadOnlySpan label) + { + // @formatter:off + if (label == Mods.Label) return TabType.Mods; + if (label == Collections.Label) return TabType.Collections; + if (label == Settings.Label) return TabType.Settings; + if (label == ChangedItems.Label) return TabType.ChangedItems; + if (label == Effective.Label) return TabType.EffectiveChanges; + if (label == OnScreenTab.Label) return TabType.OnScreen; + if (label == Watcher.Label) return TabType.ResourceWatcher; + if (label == Debug.Label) return TabType.Debug; + if (label == Resource.Label) return TabType.ResourceManager; + // @formatter:on + return TabType.None; + } }