feat: add way to open ui

This commit is contained in:
Anna 2024-02-17 20:38:51 -05:00
parent d0d717a56d
commit 33068f3ce8
Signed by: anna
GPG Key ID: D0943384CD9F87D1
2 changed files with 17 additions and 1 deletions

View File

@ -24,6 +24,10 @@ internal class Command : IDisposable {
private void OnCommand(string command, string arguments) {
if (arguments == "config") {
this.Plugin.Ui.Visible ^= true;
}
using var bitmap = Photographer.Capture();
if (bitmap == null) {
return;

View File

@ -12,17 +12,25 @@ internal class PluginUi : IDisposable {
private Plugin Plugin { get; }
private FileDialogManager FileDialogManager { get; }
internal bool Visible;
internal PluginUi(Plugin plugin) {
this.Plugin = plugin;
this.FileDialogManager = new FileDialogManager();
this.Plugin.Interface.UiBuilder.Draw += this.Draw;
this.Plugin.Interface.UiBuilder.OpenConfigUi += this.OpenConfigUi;
}
public void Dispose() {
this.Plugin.Interface.UiBuilder.OpenConfigUi -= this.OpenConfigUi;
this.Plugin.Interface.UiBuilder.Draw -= this.Draw;
}
private void OpenConfigUi() {
this.Visible = true;
}
private void Draw() {
try {
this.FileDialogManager.Draw();
@ -30,10 +38,14 @@ internal class PluginUi : IDisposable {
Plugin.Log.Error(e, "Error in FileDialogManager.Draw");
}
if (!this.Visible) {
return;
}
using var end = new OnDispose(ImGui.End);
ImGui.SetNextWindowSize(new Vector2(350, 500), ImGuiCond.FirstUseEver);
if (!ImGui.Begin(Plugin.Name)) {
if (!ImGui.Begin(Plugin.Name, ref this.Visible)) {
return;
}