feat: port Dalamud windows to WindowSystem

This commit is contained in:
goat 2021-04-05 23:22:41 +02:00
parent 65fb949c61
commit c21e7efab7
10 changed files with 252 additions and 247 deletions

View file

@ -3,9 +3,11 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using CheapLoc;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using ImGuiNET;
using Serilog;
@ -16,7 +18,7 @@ namespace Dalamud.Interface
/// <summary>
/// Class handling Dalamud core interface.
/// </summary>
internal class DalamudInterface
internal class DalamudInterface : IDisposable
{
private readonly Dalamud dalamud;
@ -30,21 +32,15 @@ namespace Dalamud.Interface
private bool isImguiDrawDevMenu = false;
#endif
private bool isImguiDrawLogWindow = false;
private bool isImguiDrawDataWindow = false;
private bool isImguiDrawPluginWindow = false;
private bool isImguiDrawCreditsWindow = false;
private bool isImguiDrawSettingsWindow = false;
private bool isImguiDrawPluginStatWindow = false;
private bool isImguiDrawChangelogWindow = false;
private readonly DalamudLogWindow logWindow;
private readonly DalamudDataWindow dataWindow;
private readonly DalamudCreditsWindow creditsWindow;
private readonly DalamudSettingsWindow settingsWindow;
private readonly PluginInstallerWindow pluginWindow;
private readonly DalamudPluginStatWindow pluginStatWindow;
private readonly DalamudChangelogWindow changelogWindow;
private DalamudLogWindow logWindow;
private DalamudDataWindow dataWindow;
private DalamudCreditsWindow creditsWindow;
private DalamudSettingsWindow settingsWindow;
private PluginInstallerWindow pluginWindow;
private DalamudPluginStatWindow pluginStatWindow;
private DalamudChangelogWindow changelogWindow;
private readonly WindowSystem windowSystem = new WindowSystem("DalamudCore");
/// <summary>
/// Initializes a new instance of the <see cref="DalamudInterface"/> class.
@ -53,6 +49,51 @@ namespace Dalamud.Interface
public DalamudInterface(Dalamud dalamud)
{
this.dalamud = dalamud;
this.logWindow = new DalamudLogWindow(this.dalamud.CommandManager, this.dalamud.Configuration)
{
IsOpen = false,
};
this.windowSystem.AddWindow(this.logWindow);
this.dataWindow = new DalamudDataWindow(this.dalamud)
{
IsOpen = false,
};
this.windowSystem.AddWindow(this.dataWindow);
this.creditsWindow = new DalamudCreditsWindow(this.dalamud)
{
IsOpen = false,
};
this.windowSystem.AddWindow(this.creditsWindow);
this.settingsWindow = new DalamudSettingsWindow(this.dalamud)
{
IsOpen = false,
};
this.windowSystem.AddWindow(this.settingsWindow);
this.pluginWindow = new PluginInstallerWindow(this.dalamud, this.dalamud.StartInfo.GameVersion)
{
IsOpen = false,
};
this.windowSystem.AddWindow(this.pluginWindow);
this.pluginStatWindow = new DalamudPluginStatWindow(this.dalamud.PluginManager)
{
IsOpen = false,
};
this.windowSystem.AddWindow(this.pluginStatWindow);
this.changelogWindow = new DalamudChangelogWindow(this.dalamud)
{
IsOpen = false,
};
this.windowSystem.AddWindow(this.changelogWindow);
Log.Information("[DUI] Windows added");
if (dalamud.Configuration.LogOpenAtStartup)
this.OpenLog();
}
@ -111,8 +152,7 @@ namespace Dalamud.Interface
if (ImGui.MenuItem("Open Log window"))
{
this.logWindow = new DalamudLogWindow(this.dalamud.CommandManager, this.dalamud.Configuration);
this.isImguiDrawLogWindow = true;
this.OpenLog();
}
if (ImGui.BeginMenu("Set log level..."))
@ -137,8 +177,7 @@ namespace Dalamud.Interface
if (ImGui.MenuItem("Open Data window"))
{
this.dataWindow = new DalamudDataWindow(this.dalamud);
this.isImguiDrawDataWindow = true;
this.OpenData();
}
if (ImGui.MenuItem("Open Credits window"))
@ -202,19 +241,14 @@ namespace Dalamud.Interface
{
if (ImGui.MenuItem("Open Plugin installer"))
{
this.pluginWindow = new PluginInstallerWindow(this.dalamud, this.dalamud.StartInfo.GameVersion);
this.isImguiDrawPluginWindow = true;
this.OpenPluginInstaller();
}
ImGui.Separator();
if (ImGui.MenuItem("Open Plugin Stats"))
{
if (!this.isImguiDrawPluginStatWindow)
{
this.pluginStatWindow = new DalamudPluginStatWindow(this.dalamud.PluginManager);
this.isImguiDrawPluginStatWindow = true;
}
OpenPluginStats();
}
if (ImGui.MenuItem("Print plugin info"))
@ -291,63 +325,10 @@ namespace Dalamud.Interface
if (this.dalamud.Framework.Gui.GameUiHidden)
return;
if (this.isImguiDrawLogWindow)
{
this.isImguiDrawLogWindow = this.logWindow != null && this.logWindow.Draw();
if (this.isImguiDrawLogWindow == false)
{
this.logWindow?.Dispose();
this.logWindow = null;
}
}
if (this.isImguiDrawDataWindow)
{
this.isImguiDrawDataWindow = this.dataWindow != null && this.dataWindow.Draw();
}
if (this.isImguiDrawPluginWindow)
{
this.isImguiDrawPluginWindow = this.pluginWindow != null && this.pluginWindow.Draw();
if (!this.isImguiDrawPluginWindow)
this.pluginWindow = null;
}
if (this.isImguiDrawCreditsWindow)
{
this.isImguiDrawCreditsWindow = this.creditsWindow != null && this.creditsWindow.Draw();
if (this.isImguiDrawCreditsWindow == false)
{
this.creditsWindow?.Dispose();
this.creditsWindow = null;
}
}
if (this.isImguiDrawSettingsWindow)
{
this.isImguiDrawSettingsWindow = this.settingsWindow != null && this.settingsWindow.Draw();
}
this.windowSystem.Draw();
if (this.isImguiDrawDemoWindow)
ImGui.ShowDemoWindow();
if (this.isImguiDrawPluginStatWindow)
{
this.isImguiDrawPluginStatWindow = this.pluginStatWindow != null && this.pluginStatWindow.Draw();
if (!this.isImguiDrawPluginStatWindow)
{
this.pluginStatWindow?.Dispose();
this.pluginStatWindow = null;
}
}
if (this.isImguiDrawChangelogWindow)
{
this.isImguiDrawChangelogWindow = this.changelogWindow != null && this.changelogWindow.Draw();
}
}
/// <summary>
@ -355,8 +336,7 @@ namespace Dalamud.Interface
/// </summary>
internal void OpenPluginInstaller()
{
this.pluginWindow ??= new PluginInstallerWindow(this.dalamud, this.dalamud.StartInfo.GameVersion);
this.isImguiDrawPluginWindow ^= true;
this.pluginWindow.IsOpen ^= true;
}
/// <summary>
@ -364,8 +344,7 @@ namespace Dalamud.Interface
/// </summary>
internal void OpenChangelog()
{
this.changelogWindow = new DalamudChangelogWindow(this.dalamud);
this.isImguiDrawChangelogWindow = true;
this.changelogWindow.IsOpen ^= true;
}
/// <summary>
@ -373,8 +352,7 @@ namespace Dalamud.Interface
/// </summary>
internal void OpenSettings()
{
this.settingsWindow = new DalamudSettingsWindow(this.dalamud);
this.isImguiDrawSettingsWindow ^= true;
this.settingsWindow.IsOpen ^= true;
}
/// <summary>
@ -382,8 +360,15 @@ namespace Dalamud.Interface
/// </summary>
internal void OpenLog()
{
this.logWindow = new DalamudLogWindow(this.dalamud.CommandManager, this.dalamud.Configuration);
this.isImguiDrawLogWindow = true;
this.logWindow.IsOpen ^= true;
}
/// <summary>
/// Open the data window.
/// </summary>
internal void OpenData()
{
this.dataWindow.IsOpen ^= true;
}
/// <summary>
@ -391,11 +376,24 @@ namespace Dalamud.Interface
/// </summary>
internal void OpenCredits()
{
var logoGraphic =
this.dalamud.InterfaceManager.LoadImage(
Path.Combine(this.dalamud.AssetDirectory.FullName, "UIRes", "logo.png"));
this.creditsWindow = new DalamudCreditsWindow(this.dalamud, logoGraphic, this.dalamud.Framework);
this.isImguiDrawCreditsWindow = true;
this.creditsWindow.IsOpen ^= true;
}
/// <summary>
/// Open the stats window.
/// </summary>
internal void OpenPluginStats()
{
this.pluginStatWindow.IsOpen ^= true;
}
public void Dispose()
{
this.windowSystem.RemoveAllWindows();
this.dalamud?.Dispose();
this.logWindow?.Dispose();
this.creditsWindow?.Dispose();
}
}
}