OrangeGuidanceTomestone/client/PluginUi.cs

84 lines
2.2 KiB
C#
Raw Permalink Normal View History

2022-09-05 08:21:45 +00:00
using ImGuiNET;
2022-09-04 05:03:59 +00:00
using OrangeGuidanceTomestone.Ui;
2022-09-03 02:59:45 +00:00
namespace OrangeGuidanceTomestone;
public class PluginUi : IDisposable {
private Plugin Plugin { get; }
2022-09-04 05:03:59 +00:00
internal MainWindow MainWindow { get; }
internal Viewer Viewer { get; }
internal ViewerButton ViewerButton { get; }
2022-09-03 02:59:45 +00:00
2022-09-05 08:21:45 +00:00
private List<(string, string)> Modals { get; } = new();
2022-09-05 08:35:28 +00:00
private Queue<string> ToShow { get; } = new();
2022-09-05 08:21:45 +00:00
2022-09-03 02:59:45 +00:00
internal PluginUi(Plugin plugin) {
this.Plugin = plugin;
2022-09-04 05:03:59 +00:00
this.MainWindow = new MainWindow(this.Plugin);
this.Viewer = new Viewer(this.Plugin);
this.ViewerButton = new ViewerButton(this.Plugin);
2022-09-03 02:59:45 +00:00
this.Plugin.Interface.UiBuilder.Draw += this.Draw;
2022-09-13 19:56:06 +00:00
this.Plugin.Interface.UiBuilder.OpenConfigUi += this.OpenConfig;
2022-09-03 02:59:45 +00:00
}
public void Dispose() {
2022-09-13 19:56:06 +00:00
this.Plugin.Interface.UiBuilder.OpenConfigUi -= this.OpenConfig;
2022-09-03 02:59:45 +00:00
this.Plugin.Interface.UiBuilder.Draw -= this.Draw;
}
2022-09-13 19:56:06 +00:00
private void OpenConfig() {
this.MainWindow.Visible = true;
}
2022-09-03 02:59:45 +00:00
private void Draw() {
2022-09-04 05:03:59 +00:00
this.MainWindow.Draw();
this.ViewerButton.Draw();
this.Viewer.Draw();
2022-09-05 08:21:45 +00:00
this.DrawModals();
}
private void DrawModals() {
2022-09-05 08:35:28 +00:00
while (this.ToShow.TryDequeue(out var toShow)) {
2023-09-29 00:53:50 +00:00
ImGui.OpenPopup($"{Plugin.Name}##{toShow}");
2022-09-05 08:35:28 +00:00
}
2022-09-05 08:21:45 +00:00
var toRemove = -1;
for (var i = 0; i < this.Modals.Count; i++) {
var (id, text) = this.Modals[i];
2023-09-29 00:53:50 +00:00
if (!ImGui.BeginPopupModal($"{Plugin.Name}##{id}")) {
2022-09-05 08:21:45 +00:00
continue;
}
2022-09-05 08:40:28 +00:00
ImGui.PushID(id);
2022-09-05 08:21:45 +00:00
ImGui.TextUnformatted(text);
ImGui.Separator();
ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X);
if (ImGui.Button("Close")) {
ImGui.CloseCurrentPopup();
toRemove = i;
}
2022-09-05 08:40:28 +00:00
ImGui.PopID();
2022-09-05 08:21:45 +00:00
ImGui.EndPopup();
}
if (toRemove > -1) {
this.Modals.RemoveAt(toRemove);
}
}
2022-09-05 08:35:28 +00:00
internal void ShowModal(string text) {
this.ShowModal(Guid.NewGuid().ToString(), text);
2022-09-05 08:21:45 +00:00
}
2022-09-05 08:35:28 +00:00
internal void ShowModal(string id, string text) {
2022-09-05 08:21:45 +00:00
this.Modals.Add((id, text));
2022-09-05 08:35:28 +00:00
this.ToShow.Enqueue(id);
2022-09-04 02:52:18 +00:00
}
2022-09-03 02:59:45 +00:00
}