Add SelectTab event, update new clientstructs.

This commit is contained in:
Ottermandias 2023-06-07 18:29:05 +02:00
parent 78e772dad9
commit 5fcb07487e
10 changed files with 79 additions and 159 deletions

View file

@ -5,8 +5,6 @@ using Dalamud.Plugin;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using Penumbra.Api.Enums;
using Penumbra.Mods;
using Penumbra.Services;
using Penumbra.UI.Classes;
using Penumbra.UI.Tabs;
@ -24,12 +22,6 @@ public sealed class ConfigWindow : Window
private ConfigTabBar _configTabs = null!;
private string? _lastException;
public void SelectTab(TabType tab)
=> _configTabs.SelectTab = tab;
public void SelectMod(Mod mod)
=> _configTabs.Mods.SelectMod = mod;
public ConfigWindow(PerformanceTracker tracker, DalamudPluginInterface pi, Configuration config, ValidityChecker checker,
TutorialService tutorial)
: base(GetLabel(checker))
@ -41,14 +33,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);
_penumbra = penumbra;
_configTabs = configTabs;
_configTabs.SelectTab = _config.SelectedTab;
}
public override bool DrawConditions()

View file

@ -10,6 +10,7 @@ using OtterGui.Widgets;
using Penumbra.Api.Enums;
using Penumbra.Collections.Manager;
using Penumbra.Mods;
using Penumbra.Services;
using Penumbra.UI.Classes;
namespace Penumbra.UI.Tabs;
@ -19,18 +20,17 @@ public class ChangedItemsTab : ITab
private readonly CollectionManager _collectionManager;
private readonly ChangedItemDrawer _drawer;
private readonly CollectionSelectHeader _collectionHeader;
private ConfigTabBar? _tabBar = null;
private readonly CommunicatorService _communicator;
public ChangedItemsTab(CollectionManager collectionManager, CollectionSelectHeader collectionHeader, ChangedItemDrawer drawer)
public ChangedItemsTab(CollectionManager collectionManager, CollectionSelectHeader collectionHeader, ChangedItemDrawer drawer,
CommunicatorService communicator)
{
_collectionManager = collectionManager;
_collectionHeader = collectionHeader;
_drawer = drawer;
_communicator = communicator;
}
public void SetTabBar(ConfigTabBar tabBar)
=> _tabBar = tabBar;
public ReadOnlySpan<byte> Label
=> "Changed Items"u8;
@ -106,22 +106,18 @@ public class ChangedItemsTab : ITab
if (mods.Count <= 0)
return;
var first = mods[0];
var first = mods[0];
using var style = ImRaii.PushStyle(ImGuiStyleVar.SelectableTextAlign, new Vector2(0, 0.5f));
if (ImGui.Selectable(first.Name, false, ImGuiSelectableFlags.None, new Vector2(0, ImGui.GetFrameHeight()))
&& ImGui.GetIO().KeyCtrl
&& _tabBar != null
&& first is Mod mod)
{
_tabBar.SelectTab = TabType.Mods;
_tabBar.Mods.SelectMod = mod;
}
if (ImGui.Selectable(first.Name, false, ImGuiSelectableFlags.None, new Vector2(0, ImGui.GetFrameHeight()))
&& ImGui.GetIO().KeyCtrl
&& first is Mod mod)
_communicator.SelectTab.Invoke(TabType.Mods, mod);
if (ImGui.IsItemHovered())
{
using var _ = ImRaii.Tooltip();
ImGui.TextUnformatted("Hold Control and click to jump to mod.\n");
if (mods.Count > 1)
using var _ = ImRaii.Tooltip();
ImGui.TextUnformatted("Hold Control and click to jump to mod.\n");
if (mods.Count > 1)
ImGui.TextUnformatted("Other mods affecting this item:\n" + string.Join("\n", mods.Skip(1).Select(m => m.Name)));
}
}

View file

@ -2,11 +2,15 @@ using System;
using ImGuiNET;
using OtterGui.Widgets;
using Penumbra.Api.Enums;
using Penumbra.Mods;
using Penumbra.Services;
namespace Penumbra.UI.Tabs;
public class ConfigTabBar
public class ConfigTabBar : IDisposable
{
private readonly CommunicatorService _communicator;
public readonly SettingsTab Settings;
public readonly ModsTab Mods;
public readonly CollectionsTab Collections;
@ -22,9 +26,12 @@ public class ConfigTabBar
/// <summary> The tab to select on the next Draw call, if any. </summary>
public TabType SelectTab = TabType.None;
public ConfigTabBar(SettingsTab settings, ModsTab mods, CollectionsTab collections, ChangedItemsTab changedItems, EffectiveTab effective,
DebugTab debug, ResourceTab resource, ResourceWatcher watcher, OnScreenTab onScreenTab)
public ConfigTabBar(CommunicatorService communicator, SettingsTab settings, ModsTab mods, CollectionsTab collections,
ChangedItemsTab changedItems, EffectiveTab effective, DebugTab debug, ResourceTab resource, ResourceWatcher watcher,
OnScreenTab onScreenTab)
{
_communicator = communicator;
Settings = settings;
Mods = mods;
Collections = collections;
@ -46,9 +53,12 @@ public class ConfigTabBar
Resource,
Watcher,
};
ChangedItems.SetTabBar(this);
_communicator.SelectTab.Subscribe(OnSelectTab, Communication.SelectTab.Priority.ConfigTabBar);
}
public void Dispose()
=> _communicator.SelectTab.Unsubscribe(OnSelectTab);
public TabType Draw()
{
if (TabBar.Draw(string.Empty, ImGuiTabBarFlags.NoTooltip, ToLabel(SelectTab), out var currentLabel, () => { }, Tabs))
@ -87,4 +97,11 @@ public class ConfigTabBar
// @formatter:on
return TabType.None;
}
private void OnSelectTab(TabType tab, Mod? mod)
{
SelectTab = tab;
if (mod != null)
Mods.SelectMod = mod;
}
}

View file

@ -696,7 +696,7 @@ public class DebugTab : Window, ITab
if (imc != null)
UiHelpers.Text(imc);
var mdl = (RenderModel*)model->ModelArray[i];
var mdl = (RenderModel*)model->Models[i];
ImGui.TableNextColumn();
ImGui.TextUnformatted(mdl == null ? "NULL" : $"0x{(ulong)mdl:X}");
if (mdl == null || mdl->ResourceHandle == null || mdl->ResourceHandle->Category != ResourceCategory.Chara)