Store last tab selected.

This commit is contained in:
Ottermandias 2023-05-09 20:04:23 +02:00
parent f01b2f8754
commit 654978dd64
3 changed files with 30 additions and 4 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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<byte> ToLabel(TabType type)
@ -68,4 +70,20 @@ public class ConfigTabBar
TabType.ResourceManager => Resource.Label,
_ => ReadOnlySpan<byte>.Empty,
};
private TabType FromLabel(ReadOnlySpan<byte> 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;
}
}