2024-07-07 18:49:45 +00:00
|
|
|
using Dalamud.Interface.Utility;
|
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; }
|
2024-07-07 18:49:45 +00:00
|
|
|
#if DEBUG
|
|
|
|
internal bool Debug = true;
|
|
|
|
#else
|
|
|
|
internal bool Debug;
|
|
|
|
#endif
|
2022-09-03 02:59:45 +00:00
|
|
|
|
2024-06-12 18:16:53 +00:00
|
|
|
private List<(string, string)> Modals { get; } = [];
|
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() {
|
2024-07-07 18:49:45 +00:00
|
|
|
if (this.Debug) {
|
|
|
|
this.DrawDebug();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2024-07-07 18:49:45 +00:00
|
|
|
|
|
|
|
private void DrawDebug() {
|
|
|
|
foreach (var msg in this.Plugin.Messages.CurrentCloned.Values) {
|
|
|
|
if (!this.Plugin.GameGui.WorldToScreen(msg.Position, out var screen)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui.GetBackgroundDrawList().AddCircleFilled(screen, 6f * ImGuiHelpers.GlobalScale, 0xff0000ff);
|
|
|
|
|
|
|
|
var label = msg.Id.ToString("N");
|
|
|
|
var size = ImGui.CalcTextSize(label);
|
|
|
|
ImGui.GetBackgroundDrawList().AddRectFilled(
|
|
|
|
screen,
|
|
|
|
screen + size,
|
|
|
|
0xff000000
|
|
|
|
);
|
|
|
|
ImGui.GetForegroundDrawList().AddText(screen, 0xffffffff, label);
|
|
|
|
}
|
|
|
|
}
|
2022-09-03 02:59:45 +00:00
|
|
|
}
|