Add some more debugging fuckery for the import popup fuckery.

This commit is contained in:
Ottermandias 2023-05-03 16:56:38 +02:00
parent 6316458613
commit beb777e3cd
5 changed files with 110 additions and 20 deletions

View file

@ -49,6 +49,7 @@ public class Configuration : IPluginConfiguration, ISavable
public bool HideRedrawBar { get; set; } = false; public bool HideRedrawBar { get; set; } = false;
public int OptionGroupCollapsibleMin { get; set; } = 5; public int OptionGroupCollapsibleMin { get; set; } = 5;
public bool DebugSeparateWindow = false;
#if DEBUG #if DEBUG
public bool DebugMode { get; set; } = true; public bool DebugMode { get; set; } = true;
#else #else

View file

@ -23,6 +23,14 @@ public class ModImportManager : IDisposable
private TexToolsImporter? _import; private TexToolsImporter? _import;
internal IEnumerable<string[]> ModBatches
=> _modsToUnpack;
internal IEnumerable<DirectoryInfo> AddableMods
=> _modsToAdd;
public ModImportManager(ModManager modManager, Configuration config, ModEditor modEditor) public ModImportManager(ModManager modManager, Configuration config, ModEditor modEditor)
{ {
_modManager = modManager; _modManager = modManager;
@ -43,9 +51,9 @@ public class ModImportManager : IDisposable
Penumbra.ChatService.NotificationMessage($"Failed to import queued mod at {s}, the file does not exist.", "Warning", Penumbra.ChatService.NotificationMessage($"Failed to import queued mod at {s}, the file does not exist.", "Warning",
NotificationType.Warning); NotificationType.Warning);
return false; return false;
}).Select(s => new FileInfo(s)).ToArray(); }).Select(s => new FileInfo(s)).ToArray();
Penumbra.Log.Debug($"Unpacking mods: {string.Join("\n\t", files.Select(f => f.FullName))}.");
if (files.Length == 0) if (files.Length == 0)
return; return;
@ -62,10 +70,13 @@ public class ModImportManager : IDisposable
} }
public void AddUnpack(IEnumerable<string> paths) public void AddUnpack(IEnumerable<string> paths)
=> _modsToUnpack.Enqueue(paths.ToArray()); => AddUnpack(paths.ToArray());
public void AddUnpack(params string[] paths) public void AddUnpack(params string[] paths)
=> _modsToUnpack.Enqueue(paths); {
Penumbra.Log.Debug($"Adding mods to install: {string.Join("\n\t", paths)}");
_modsToUnpack.Enqueue(paths);
}
public void ClearImport() public void ClearImport()
{ {
@ -117,6 +128,7 @@ public class ModImportManager : IDisposable
} }
else if (dir != null) else if (dir != null)
{ {
Penumbra.Log.Debug($"Adding newly installed mod to queue: {dir.FullName}");
_modsToAdd.Enqueue(dir); _modsToAdd.Enqueue(dir);
} }
} }

View file

@ -11,10 +11,15 @@ namespace Penumbra.UI;
/// <summary> Draw the progress information for import. </summary> /// <summary> Draw the progress information for import. </summary>
public sealed class ImportPopup : Window public sealed class ImportPopup : Window
{ {
public const string WindowLabel = "Penumbra Import Status";
private readonly ModImportManager _modImportManager; private readonly ModImportManager _modImportManager;
public bool WasDrawn { get; private set; }
public bool PopupWasDrawn { get; private set; }
public ImportPopup(ModImportManager modImportManager) public ImportPopup(ModImportManager modImportManager)
: base("Penumbra Import Status", : base(WindowLabel,
ImGuiWindowFlags.NoCollapse ImGuiWindowFlags.NoCollapse
| ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoDecoration
| ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoBackground
@ -30,15 +35,16 @@ public sealed class ImportPopup : Window
}; };
} }
public override void PreDraw() public override void PreOpenCheck()
{ {
WasDrawn = false;
PopupWasDrawn = false;
_modImportManager.TryUnpacking(); _modImportManager.TryUnpacking();
ImGui.SetNextWindowCollapsed(false, ImGuiCond.Always);
IsOpen = true;
} }
public override void Draw() public override void Draw()
{ {
WasDrawn = true;
if (!_modImportManager.IsImporting(out var import)) if (!_modImportManager.IsImporting(out var import))
return; return;
@ -53,6 +59,7 @@ public sealed class ImportPopup : Window
ImGui.SetNextWindowPos(ImGui.GetMainViewport().GetCenter(), ImGuiCond.Always, Vector2.One / 2); ImGui.SetNextWindowPos(ImGui.GetMainViewport().GetCenter(), ImGuiCond.Always, Vector2.One / 2);
ImGui.SetNextWindowSize(size); ImGui.SetNextWindowSize(size);
using var popup = ImRaii.Popup(importPopup, ImGuiWindowFlags.Modal); using var popup = ImRaii.Popup(importPopup, ImGuiWindowFlags.Modal);
PopupWasDrawn = true;
using (var child = ImRaii.Child("##import", new Vector2(-1, size.Y - ImGui.GetFrameHeight() * 2))) using (var child = ImRaii.Child("##import", new Vector2(-1, size.Y - ImGui.GetFrameHeight() * 2)))
{ {
if (child) if (child)

View file

@ -2,6 +2,8 @@ using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using Dalamud.Interface;
using Dalamud.Interface.Windowing;
using FFXIVClientStructs.FFXIV.Client.Game.Character; using FFXIVClientStructs.FFXIV.Client.Game.Character;
using FFXIVClientStructs.FFXIV.Client.Game.Group; using FFXIVClientStructs.FFXIV.Client.Game.Group;
using FFXIVClientStructs.FFXIV.Client.Game.Object; using FFXIVClientStructs.FFXIV.Client.Game.Object;
@ -13,6 +15,7 @@ using Penumbra.Api;
using Penumbra.Collections.Manager; using Penumbra.Collections.Manager;
using Penumbra.GameData.Actors; using Penumbra.GameData.Actors;
using Penumbra.GameData.Files; using Penumbra.GameData.Files;
using Penumbra.Import.Structs;
using Penumbra.Interop.ResourceLoading; using Penumbra.Interop.ResourceLoading;
using Penumbra.Interop.PathResolving; using Penumbra.Interop.PathResolving;
using Penumbra.Interop.Structs; using Penumbra.Interop.Structs;
@ -28,7 +31,7 @@ using ResidentResourceManager = Penumbra.Interop.Services.ResidentResourceManage
namespace Penumbra.UI.Tabs; namespace Penumbra.UI.Tabs;
public class DebugTab : ITab public class DebugTab : Window, ITab
{ {
private readonly StartTracker _timer; private readonly StartTracker _timer;
private readonly PerformanceTracker _performance; private readonly PerformanceTracker _performance;
@ -50,14 +53,23 @@ public class DebugTab : ITab
private readonly SubfileHelper _subfileHelper; private readonly SubfileHelper _subfileHelper;
private readonly IdentifiedCollectionCache _identifiedCollectionCache; private readonly IdentifiedCollectionCache _identifiedCollectionCache;
private readonly CutsceneService _cutsceneService; private readonly CutsceneService _cutsceneService;
private readonly ModImportManager _modImporter;
private readonly ImportPopup _importPopup;
public DebugTab(StartTracker timer, PerformanceTracker performance, Configuration config, CollectionManager collectionManager, public DebugTab(StartTracker timer, PerformanceTracker performance, Configuration config, CollectionManager collectionManager,
ValidityChecker validityChecker, ModManager modManager, HttpApi httpApi, ActorService actorService, ValidityChecker validityChecker, ModManager modManager, HttpApi httpApi, ActorService actorService,
DalamudServices dalamud, StainService stains, CharacterUtility characterUtility, ResidentResourceManager residentResources, DalamudServices dalamud, StainService stains, CharacterUtility characterUtility, ResidentResourceManager residentResources,
ResourceManagerService resourceManager, PenumbraIpcProviders ipc, CollectionResolver collectionResolver, ResourceManagerService resourceManager, PenumbraIpcProviders ipc, CollectionResolver collectionResolver,
DrawObjectState drawObjectState, PathState pathState, SubfileHelper subfileHelper, IdentifiedCollectionCache identifiedCollectionCache, DrawObjectState drawObjectState, PathState pathState, SubfileHelper subfileHelper, IdentifiedCollectionCache identifiedCollectionCache,
CutsceneService cutsceneService) CutsceneService cutsceneService, ModImportManager modImporter, ImportPopup importPopup)
: base("Penumbra Debug Window", ImGuiWindowFlags.NoCollapse, false)
{ {
IsOpen = true;
SizeConstraints = new WindowSizeConstraints
{
MinimumSize = new Vector2(200, 200),
MaximumSize = new Vector2(2000, 2000),
};
_timer = timer; _timer = timer;
_performance = performance; _performance = performance;
_config = config; _config = config;
@ -78,13 +90,15 @@ public class DebugTab : ITab
_subfileHelper = subfileHelper; _subfileHelper = subfileHelper;
_identifiedCollectionCache = identifiedCollectionCache; _identifiedCollectionCache = identifiedCollectionCache;
_cutsceneService = cutsceneService; _cutsceneService = cutsceneService;
_modImporter = modImporter;
_importPopup = importPopup;
} }
public ReadOnlySpan<byte> Label public ReadOnlySpan<byte> Label
=> "Debug"u8; => "Debug"u8;
public bool IsVisible public bool IsVisible
=> _config.DebugMode; => _config.DebugMode && !_config.DebugSeparateWindow;
#if DEBUG #if DEBUG
private const string DebugVersionString = "(Debug)"; private const string DebugVersionString = "(Debug)";
@ -127,6 +141,14 @@ public class DebugTab : ITab
if (!ImGui.CollapsingHeader("General")) if (!ImGui.CollapsingHeader("General"))
return; return;
var separateWindow = _config.DebugSeparateWindow;
if (ImGui.Checkbox("Draw as Separate Window", ref separateWindow))
{
IsOpen = true;
_config.DebugSeparateWindow = separateWindow;
_config.Save();
}
using (var table = Table("##DebugGeneralTable", 2, ImGuiTableFlags.SizingFixedFit)) using (var table = Table("##DebugGeneralTable", 2, ImGuiTableFlags.SizingFixedFit))
{ {
if (table) if (table)
@ -178,6 +200,40 @@ public class DebugTab : ITab
} }
} }
} }
using (var tree = TreeNode("Mod Import"))
{
if (tree)
{
using var table = Table("##DebugModImport", 2, ImGuiTableFlags.SizingFixedFit);
if (table)
{
var importing = _modImporter.IsImporting(out var importer);
PrintValue("Is Importing", importing.ToString());
PrintValue("Importer State", (importer?.State ?? ImporterState.None).ToString());
PrintValue("Import Window Was Drawn", _importPopup.WasDrawn.ToString());
PrintValue("Import Popup Was Drawn", _importPopup.PopupWasDrawn.ToString());
ImGui.TableNextColumn();
ImGui.TextUnformatted("Import Batches");
ImGui.TableNextColumn();
foreach (var (batch, index) in _modImporter.ModBatches.WithIndex())
{
foreach (var mod in batch)
PrintValue(index.ToString(), mod);
}
ImGui.TableNextColumn();
ImGui.TextUnformatted("Addable Mods");
ImGui.TableNextColumn();
foreach (var mod in _modImporter.AddableMods)
{
ImGui.TableNextColumn();
ImGui.TableNextColumn();
ImGui.TextUnformatted(mod.Name);
}
}
}
}
} }
private void DrawPerformanceTab() private void DrawPerformanceTab()
@ -655,4 +711,16 @@ public class DebugTab : ITab
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.TextUnformatted(value); ImGui.TextUnformatted(value);
} }
public override void Draw()
=> DrawContent();
public override bool DrawConditions()
=> _config.DebugMode && _config.DebugSeparateWindow;
public override void OnClose()
{
_config.DebugSeparateWindow = false;
_config.Save();
}
} }

View file

@ -4,6 +4,7 @@ using Dalamud.Interface.Windowing;
using Dalamud.Plugin; using Dalamud.Plugin;
using Penumbra.UI; using Penumbra.UI;
using Penumbra.UI.AdvancedWindow; using Penumbra.UI.AdvancedWindow;
using Penumbra.UI.Tabs;
namespace Penumbra; namespace Penumbra;
@ -16,7 +17,7 @@ public class PenumbraWindowSystem : IDisposable
public readonly PenumbraChangelog Changelog; public readonly PenumbraChangelog Changelog;
public PenumbraWindowSystem(DalamudPluginInterface pi, Configuration config, PenumbraChangelog changelog, ConfigWindow window, public PenumbraWindowSystem(DalamudPluginInterface pi, Configuration config, PenumbraChangelog changelog, ConfigWindow window,
LaunchButton _, ModEditWindow editWindow, FileDialogService fileDialog, ImportPopup importPopup) LaunchButton _, ModEditWindow editWindow, FileDialogService fileDialog, ImportPopup importPopup, DebugTab debugTab)
{ {
_uiBuilder = pi.UiBuilder; _uiBuilder = pi.UiBuilder;
_fileDialog = fileDialog; _fileDialog = fileDialog;
@ -27,6 +28,7 @@ public class PenumbraWindowSystem : IDisposable
_windowSystem.AddWindow(window); _windowSystem.AddWindow(window);
_windowSystem.AddWindow(editWindow); _windowSystem.AddWindow(editWindow);
_windowSystem.AddWindow(importPopup); _windowSystem.AddWindow(importPopup);
_windowSystem.AddWindow(debugTab);
_uiBuilder.OpenConfigUi += Window.Toggle; _uiBuilder.OpenConfigUi += Window.Toggle;
_uiBuilder.Draw += _windowSystem.Draw; _uiBuilder.Draw += _windowSystem.Draw;
_uiBuilder.Draw += _fileDialog.Draw; _uiBuilder.Draw += _fileDialog.Draw;