From fb67cb99ef7fc7172bf2e041f0ee67d7ac5e7ad5 Mon Sep 17 00:00:00 2001 From: shibbo Date: Tue, 7 Nov 2023 01:31:21 -0500 Subject: [PATCH] Implement custom MessageBox with customizable options --- Fushigi/ui/widgets/CourseScene.cs | 2 +- Fushigi/util/MessageBox.cs | 79 +++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 Fushigi/util/MessageBox.cs diff --git a/Fushigi/ui/widgets/CourseScene.cs b/Fushigi/ui/widgets/CourseScene.cs index 5291816b..6eaf9869 100644 --- a/Fushigi/ui/widgets/CourseScene.cs +++ b/Fushigi/ui/widgets/CourseScene.cs @@ -81,7 +81,7 @@ public void DrawUI(GL gl) { CourseErrorList(); } - + ulong selectionVersionBefore = activeViewport.mEditContext.SelectionVersion; bool status = ImGui.Begin("Viewports"); diff --git a/Fushigi/util/MessageBox.cs b/Fushigi/util/MessageBox.cs new file mode 100644 index 00000000..294e0c8e --- /dev/null +++ b/Fushigi/util/MessageBox.cs @@ -0,0 +1,79 @@ +using ImGuiNET; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; + +namespace Fushigi.util +{ + public class MessageBox + { + public enum MessageBoxType + { + YesNo = 0, + Ok = 1 + } + + public enum MessageBoxResult + { + Waiting = -1, + Ok = 0, + No = 1, + Yes = 2, + Closed = 3 + } + + public MessageBox(MessageBoxType type) + { + mType = type; + } + + public MessageBoxResult Show(string header, string message) + { + MessageBoxResult res = MessageBoxResult.Waiting; + + bool needsClose = true; + bool status = ImGui.Begin(header, ref needsClose); + ImGui.Text(message); + + switch (mType) + { + case MessageBoxType.Ok: + if (ImGui.Button("OK")) + { + res = MessageBoxResult.Ok; + } + break; + case MessageBoxType.YesNo: + if (ImGui.Button("Yes")) + { + res = MessageBoxResult.Yes; + } + + ImGui.SameLine(); + + if (ImGui.Button("No")) + { + res = MessageBoxResult.No; + } + break; + } + + if (!needsClose) + { + res = MessageBoxResult.Closed; + } + + if (status) + { + ImGui.End(); + } + + return res; + } + + MessageBoxType mType; + } +}