mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
refactor: new code style in DalamudInterface.cs
This commit is contained in:
parent
83eebe3aac
commit
115fa54957
1 changed files with 86 additions and 41 deletions
|
|
@ -1,16 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using CheapLoc;
|
||||
using Dalamud.Game.ClientState;
|
||||
using Dalamud.Game.Command;
|
||||
using Dalamud.Game.Internal;
|
||||
using Dalamud.Plugin;
|
||||
using ImGuiNET;
|
||||
using Serilog;
|
||||
|
|
@ -18,19 +13,15 @@ using Serilog.Events;
|
|||
|
||||
namespace Dalamud.Interface
|
||||
{
|
||||
/// <summary>
|
||||
/// Class handling Dalamud core interface.
|
||||
/// </summary>
|
||||
internal class DalamudInterface
|
||||
{
|
||||
private readonly Dalamud dalamud;
|
||||
|
||||
private ulong frameCount = 0;
|
||||
|
||||
public DalamudInterface(Dalamud dalamud) {
|
||||
this.dalamud = dalamud;
|
||||
if (dalamud.Configuration.LogOpenAtStartup) {
|
||||
OpenLog();
|
||||
}
|
||||
}
|
||||
|
||||
private bool isImguiDrawDemoWindow = false;
|
||||
|
||||
#if DEBUG
|
||||
|
|
@ -39,12 +30,6 @@ namespace Dalamud.Interface
|
|||
private bool isImguiDrawDevMenu = false;
|
||||
#endif
|
||||
|
||||
public bool IsDevMenu
|
||||
{
|
||||
get => this.isImguiDrawDevMenu;
|
||||
set => this.isImguiDrawDevMenu = value;
|
||||
}
|
||||
|
||||
private bool isImguiDrawLogWindow = false;
|
||||
private bool isImguiDrawDataWindow = false;
|
||||
private bool isImguiDrawPluginWindow = false;
|
||||
|
|
@ -61,6 +46,29 @@ namespace Dalamud.Interface
|
|||
private DalamudPluginStatWindow pluginStatWindow;
|
||||
private DalamudChangelogWindow changelogWindow;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DalamudInterface"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dalamud">The Dalamud instance to register to.</param>
|
||||
public DalamudInterface(Dalamud dalamud)
|
||||
{
|
||||
this.dalamud = dalamud;
|
||||
if (dalamud.Configuration.LogOpenAtStartup)
|
||||
this.OpenLog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the Dalamud dev menu is drawing.
|
||||
/// </summary>
|
||||
public bool IsDevMenu
|
||||
{
|
||||
get => this.isImguiDrawDevMenu;
|
||||
set => this.isImguiDrawDevMenu = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw the Dalamud core interface via ImGui.
|
||||
/// </summary>
|
||||
public void Draw()
|
||||
{
|
||||
this.frameCount++;
|
||||
|
|
@ -96,18 +104,21 @@ namespace Dalamud.Interface
|
|||
{
|
||||
if (ImGui.BeginMenu("Dalamud"))
|
||||
{
|
||||
ImGui.MenuItem("Draw Dalamud dev menu", "", ref this.isImguiDrawDevMenu);
|
||||
ImGui.MenuItem("Draw Dalamud dev menu", string.Empty, ref this.isImguiDrawDevMenu);
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
if (ImGui.MenuItem("Open Log window"))
|
||||
{
|
||||
this.logWindow = new DalamudLogWindow(this.dalamud.CommandManager, this.dalamud.Configuration);
|
||||
this.isImguiDrawLogWindow = true;
|
||||
}
|
||||
|
||||
if (ImGui.BeginMenu("Set log level..."))
|
||||
{
|
||||
foreach (var logLevel in Enum.GetValues(typeof(LogEventLevel)).Cast<LogEventLevel>())
|
||||
{
|
||||
if (ImGui.MenuItem(logLevel + "##logLevelSwitch", "", this.dalamud.LogLevelSwitch.MinimumLevel == logLevel))
|
||||
if (ImGui.MenuItem(logLevel + "##logLevelSwitch", string.Empty, this.dalamud.LogLevelSwitch.MinimumLevel == logLevel))
|
||||
{
|
||||
this.dalamud.LogLevelSwitch.MinimumLevel = logLevel;
|
||||
}
|
||||
|
|
@ -115,52 +126,66 @@ namespace Dalamud.Interface
|
|||
|
||||
ImGui.EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui.MenuItem("Enable AntiDebug", null, this.dalamud.AntiDebug.IsEnabled))
|
||||
{
|
||||
this.dalamud.AntiDebug.Enable();
|
||||
}
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
if (ImGui.MenuItem("Open Data window"))
|
||||
{
|
||||
this.dataWindow = new DalamudDataWindow(this.dalamud);
|
||||
this.isImguiDrawDataWindow = true;
|
||||
}
|
||||
|
||||
if (ImGui.MenuItem("Open Credits window"))
|
||||
{
|
||||
OpenCredits();
|
||||
}
|
||||
if (ImGui.MenuItem("Open Settings window"))
|
||||
{
|
||||
OpenSettings();
|
||||
}
|
||||
if (ImGui.MenuItem("Open Changelog window"))
|
||||
{
|
||||
OpenChangelog();
|
||||
this.OpenCredits();
|
||||
}
|
||||
|
||||
if (this.dalamud.Fools != null) {
|
||||
ImGui.MenuItem("Draw Tippy", "", ref this.dalamud.Fools.IsEnabled);
|
||||
if (ImGui.MenuItem("Open Settings window"))
|
||||
{
|
||||
this.OpenSettings();
|
||||
}
|
||||
|
||||
ImGui.MenuItem("Draw ImGui demo", "", ref this.isImguiDrawDemoWindow);
|
||||
|
||||
if (ImGui.MenuItem("Open Changelog window"))
|
||||
{
|
||||
this.OpenChangelog();
|
||||
}
|
||||
|
||||
if (this.dalamud.Fools != null)
|
||||
{
|
||||
ImGui.MenuItem("Draw Tippy", string.Empty, ref this.dalamud.Fools.IsEnabled);
|
||||
}
|
||||
|
||||
ImGui.MenuItem("Draw ImGui demo", string.Empty, ref this.isImguiDrawDemoWindow);
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
if (ImGui.MenuItem("Unload Dalamud"))
|
||||
{
|
||||
this.dalamud.Unload();
|
||||
}
|
||||
|
||||
if (ImGui.MenuItem("Kill game"))
|
||||
{
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
|
||||
if (ImGui.MenuItem("Cause AccessViolation"))
|
||||
{
|
||||
var a = Marshal.ReadByte(IntPtr.Zero);
|
||||
}
|
||||
|
||||
ImGui.Separator();
|
||||
if (ImGui.MenuItem("Enable Dalamud testing", "", this.dalamud.Configuration.DoDalamudTest)) {
|
||||
if (ImGui.MenuItem("Enable Dalamud testing", string.Empty, this.dalamud.Configuration.DoDalamudTest))
|
||||
{
|
||||
this.dalamud.Configuration.DoDalamudTest = !this.dalamud.Configuration.DoDalamudTest;
|
||||
this.dalamud.Configuration.Save();
|
||||
}
|
||||
|
||||
ImGui.MenuItem(Util.AssemblyVersion, false);
|
||||
ImGui.MenuItem(this.dalamud.StartInfo.GameVersion, false);
|
||||
|
||||
|
|
@ -184,7 +209,9 @@ namespace Dalamud.Interface
|
|||
this.pluginWindow = new PluginInstallerWindow(this.dalamud, this.dalamud.StartInfo.GameVersion);
|
||||
this.isImguiDrawPluginWindow = true;
|
||||
}
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
if (ImGui.MenuItem("Open Plugin Stats"))
|
||||
{
|
||||
if (!this.isImguiDrawPluginStatWindow)
|
||||
|
|
@ -193,6 +220,7 @@ namespace Dalamud.Interface
|
|||
this.isImguiDrawPluginStatWindow = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui.MenuItem("Print plugin info"))
|
||||
{
|
||||
foreach (var plugin in this.dalamud.PluginManager.Plugins)
|
||||
|
|
@ -201,6 +229,7 @@ namespace Dalamud.Interface
|
|||
Log.Information($"{plugin.Plugin.Name}");
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui.MenuItem("Reload plugins"))
|
||||
{
|
||||
try
|
||||
|
|
@ -249,6 +278,7 @@ namespace Dalamud.Interface
|
|||
|
||||
ImGui.EndMenu();
|
||||
}
|
||||
|
||||
ImGui.EndMenu();
|
||||
}
|
||||
|
||||
|
|
@ -323,33 +353,48 @@ namespace Dalamud.Interface
|
|||
this.isImguiDrawChangelogWindow = this.changelogWindow != null && this.changelogWindow.Draw();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open the Plugin Installer window.
|
||||
/// </summary>
|
||||
internal void OpenPluginInstaller()
|
||||
{
|
||||
if (this.pluginWindow == null)
|
||||
{
|
||||
this.pluginWindow = new PluginInstallerWindow(this.dalamud, this.dalamud.StartInfo.GameVersion);
|
||||
}
|
||||
this.pluginWindow ??= new PluginInstallerWindow(this.dalamud, this.dalamud.StartInfo.GameVersion);
|
||||
this.isImguiDrawPluginWindow ^= true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open the changelog window.
|
||||
/// </summary>
|
||||
internal void OpenChangelog()
|
||||
{
|
||||
this.changelogWindow = new DalamudChangelogWindow(this.dalamud);
|
||||
this.isImguiDrawChangelogWindow = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open the settings window.
|
||||
/// </summary>
|
||||
internal void OpenSettings()
|
||||
{
|
||||
this.settingsWindow = new DalamudSettingsWindow(this.dalamud);
|
||||
this.isImguiDrawSettingsWindow ^= true;
|
||||
}
|
||||
|
||||
public void OpenLog() {
|
||||
/// <summary>
|
||||
/// Open the log window.
|
||||
/// </summary>
|
||||
internal void OpenLog()
|
||||
{
|
||||
this.logWindow = new DalamudLogWindow(this.dalamud.CommandManager, this.dalamud.Configuration);
|
||||
this.isImguiDrawLogWindow = true;
|
||||
}
|
||||
|
||||
public void OpenCredits() {
|
||||
/// <summary>
|
||||
/// Open the credits window.
|
||||
/// </summary>
|
||||
internal void OpenCredits()
|
||||
{
|
||||
var logoGraphic =
|
||||
this.dalamud.InterfaceManager.LoadImage(
|
||||
Path.Combine(this.dalamud.AssetDirectory.FullName, "UIRes", "logo.png"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue