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 int OptionGroupCollapsibleMin { get; set; } = 5;
public bool DebugSeparateWindow = false;
#if DEBUG
public bool DebugMode { get; set; } = true;
#else

View file

@ -23,6 +23,14 @@ public class ModImportManager : IDisposable
private TexToolsImporter? _import;
internal IEnumerable<string[]> ModBatches
=> _modsToUnpack;
internal IEnumerable<DirectoryInfo> AddableMods
=> _modsToAdd;
public ModImportManager(ModManager modManager, Configuration config, ModEditor modEditor)
{
_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",
NotificationType.Warning);
return false;
}).Select(s => new FileInfo(s)).ToArray();
Penumbra.Log.Debug($"Unpacking mods: {string.Join("\n\t", files.Select(f => f.FullName))}.");
if (files.Length == 0)
return;
@ -62,10 +70,13 @@ public class ModImportManager : IDisposable
}
public void AddUnpack(IEnumerable<string> paths)
=> _modsToUnpack.Enqueue(paths.ToArray());
=> AddUnpack(paths.ToArray());
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()
{
@ -117,6 +128,7 @@ public class ModImportManager : IDisposable
}
else if (dir != null)
{
Penumbra.Log.Debug($"Adding newly installed mod to queue: {dir.FullName}");
_modsToAdd.Enqueue(dir);
}
}

View file

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

View file

@ -2,6 +2,8 @@ using System;
using System.IO;
using System.Linq;
using System.Numerics;
using Dalamud.Interface;
using Dalamud.Interface.Windowing;
using FFXIVClientStructs.FFXIV.Client.Game.Character;
using FFXIVClientStructs.FFXIV.Client.Game.Group;
using FFXIVClientStructs.FFXIV.Client.Game.Object;
@ -13,6 +15,7 @@ using Penumbra.Api;
using Penumbra.Collections.Manager;
using Penumbra.GameData.Actors;
using Penumbra.GameData.Files;
using Penumbra.Import.Structs;
using Penumbra.Interop.ResourceLoading;
using Penumbra.Interop.PathResolving;
using Penumbra.Interop.Structs;
@ -28,7 +31,7 @@ using ResidentResourceManager = Penumbra.Interop.Services.ResidentResourceManage
namespace Penumbra.UI.Tabs;
public class DebugTab : ITab
public class DebugTab : Window, ITab
{
private readonly StartTracker _timer;
private readonly PerformanceTracker _performance;
@ -50,14 +53,23 @@ public class DebugTab : ITab
private readonly SubfileHelper _subfileHelper;
private readonly IdentifiedCollectionCache _identifiedCollectionCache;
private readonly CutsceneService _cutsceneService;
private readonly ModImportManager _modImporter;
private readonly ImportPopup _importPopup;
public DebugTab(StartTracker timer, PerformanceTracker performance, Configuration config, CollectionManager collectionManager,
ValidityChecker validityChecker, ModManager modManager, HttpApi httpApi, ActorService actorService,
DalamudServices dalamud, StainService stains, CharacterUtility characterUtility, ResidentResourceManager residentResources,
ResourceManagerService resourceManager, PenumbraIpcProviders ipc, CollectionResolver collectionResolver,
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;
_performance = performance;
_config = config;
@ -78,13 +90,15 @@ public class DebugTab : ITab
_subfileHelper = subfileHelper;
_identifiedCollectionCache = identifiedCollectionCache;
_cutsceneService = cutsceneService;
_modImporter = modImporter;
_importPopup = importPopup;
}
public ReadOnlySpan<byte> Label
=> "Debug"u8;
public bool IsVisible
=> _config.DebugMode;
=> _config.DebugMode && !_config.DebugSeparateWindow;
#if DEBUG
private const string DebugVersionString = "(Debug)";
@ -127,6 +141,14 @@ public class DebugTab : ITab
if (!ImGui.CollapsingHeader("General"))
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))
{
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()
@ -655,4 +711,16 @@ public class DebugTab : ITab
ImGui.TableNextColumn();
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 Penumbra.UI;
using Penumbra.UI.AdvancedWindow;
using Penumbra.UI.Tabs;
namespace Penumbra;
@ -16,7 +17,7 @@ public class PenumbraWindowSystem : IDisposable
public readonly PenumbraChangelog Changelog;
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;
_fileDialog = fileDialog;
@ -27,6 +28,7 @@ public class PenumbraWindowSystem : IDisposable
_windowSystem.AddWindow(window);
_windowSystem.AddWindow(editWindow);
_windowSystem.AddWindow(importPopup);
_windowSystem.AddWindow(debugTab);
_uiBuilder.OpenConfigUi += Window.Toggle;
_uiBuilder.Draw += _windowSystem.Draw;
_uiBuilder.Draw += _fileDialog.Draw;