mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-23 17:09:17 +01:00
feat: use new UiBuilder class for plugins, DalamudPluginInterface is now IDisposable
This commit is contained in:
parent
72a4e6278d
commit
24450cf830
3 changed files with 45 additions and 13 deletions
|
|
@ -32,7 +32,7 @@ namespace Dalamud.Interface
|
||||||
private RawDX11Scene scene;
|
private RawDX11Scene scene;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This event gets called when ImGUI is ready to draw your UI.
|
/// This event gets called by a plugin UiBuilder when read
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event RawDX11Scene.BuildUIDelegate OnDraw;
|
public event RawDX11Scene.BuildUIDelegate OnDraw;
|
||||||
|
|
||||||
|
|
@ -109,14 +109,7 @@ namespace Dalamud.Interface
|
||||||
// Doing this here because it's somewhat application-specific behavior
|
// Doing this here because it's somewhat application-specific behavior
|
||||||
ImGui.GetIO().MouseDrawCursor = ImGui.GetIO().WantCaptureMouse;
|
ImGui.GetIO().MouseDrawCursor = ImGui.GetIO().WantCaptureMouse;
|
||||||
|
|
||||||
// invoke all our external ui handlers, giving each a custom id to prevent name collisions
|
OnDraw?.Invoke();
|
||||||
// because ImGui control names are globally shared
|
|
||||||
foreach (var del in this.OnDraw?.GetInvocationList())
|
|
||||||
{
|
|
||||||
//ImGui.PushID(someId);
|
|
||||||
del.DynamicInvoke();
|
|
||||||
//ImGui.PopID();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
35
Dalamud/Interface/UiBuilder.cs
Normal file
35
Dalamud/Interface/UiBuilder.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ImGuiNET;
|
||||||
|
using ImGuiScene;
|
||||||
|
|
||||||
|
namespace Dalamud.Interface
|
||||||
|
{
|
||||||
|
public class UiBuilder : IDisposable {
|
||||||
|
private readonly string namespaceName;
|
||||||
|
|
||||||
|
public event RawDX11Scene.BuildUIDelegate OnBuildUi;
|
||||||
|
|
||||||
|
private InterfaceManager interfaceManager;
|
||||||
|
|
||||||
|
public UiBuilder(InterfaceManager interfaceManager, string namespaceName) {
|
||||||
|
this.namespaceName = namespaceName;
|
||||||
|
|
||||||
|
this.interfaceManager = interfaceManager;
|
||||||
|
this.interfaceManager.OnDraw += OnDraw;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
this.interfaceManager.OnDraw -= OnDraw;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDraw() {
|
||||||
|
ImGui.PushID(this.namespaceName);
|
||||||
|
OnBuildUi?.Invoke();
|
||||||
|
ImGui.PopID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,7 +18,7 @@ namespace Dalamud.Plugin
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This class acts as an interface to various objects needed to interact with Dalamud and the game.
|
/// This class acts as an interface to various objects needed to interact with Dalamud and the game.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DalamudPluginInterface {
|
public class DalamudPluginInterface : IDisposable {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The CommandManager object that allows you to add and remove custom chat commands.
|
/// The CommandManager object that allows you to add and remove custom chat commands.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -35,9 +35,9 @@ namespace Dalamud.Plugin
|
||||||
public readonly Framework Framework;
|
public readonly Framework Framework;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A <see cref="InterfaceManager">InterfaceManager</see> instance which allows you to draw UI into the game via ImGui draw calls.
|
/// A <see cref="UiBuilder">UiBuilder</see> instance which allows you to draw UI into the game via ImGui draw calls.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly InterfaceManager Interface;
|
public readonly UiBuilder UiBuilder;
|
||||||
|
|
||||||
/// A <see cref="SigScanner">SigScanner</see> instance targeting the main module of the FFXIV process.
|
/// A <see cref="SigScanner">SigScanner</see> instance targeting the main module of the FFXIV process.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -54,13 +54,17 @@ namespace Dalamud.Plugin
|
||||||
this.CommandManager = dalamud.CommandManager;
|
this.CommandManager = dalamud.CommandManager;
|
||||||
this.Framework = dalamud.Framework;
|
this.Framework = dalamud.Framework;
|
||||||
this.ClientState = dalamud.ClientState;
|
this.ClientState = dalamud.ClientState;
|
||||||
this.Interface = dalamud.InterfaceManager;
|
this.UiBuilder = new UiBuilder(dalamud.InterfaceManager, pluginName);
|
||||||
this.TargetModuleScanner = new SigScanner(dalamud.TargetModule);
|
this.TargetModuleScanner = new SigScanner(dalamud.TargetModule);
|
||||||
|
|
||||||
this.dalamud = dalamud;
|
this.dalamud = dalamud;
|
||||||
this.pluginName = pluginName;
|
this.pluginName = pluginName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
this.UiBuilder.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Save a plugin configuration(inheriting IPluginConfiguration).
|
/// Save a plugin configuration(inheriting IPluginConfiguration).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue