aboutsummaryrefslogtreecommitdiff
path: root/Erable/Views/MessageBox.axaml.cs
diff options
context:
space:
mode:
authorAndrew Lee <alee14498@protonmail.com>2021-02-08 00:00:49 -0500
committerAndrew Lee <alee14498@protonmail.com>2021-02-08 00:00:49 -0500
commitf5a7e3ef7e25aa2545f541e171f2d5f6fe43ecc7 (patch)
tree6f5dbb64c68ff3bf8a2cd771366ac5ff466d183d /Erable/Views/MessageBox.axaml.cs
parentc7428fab1c38d29bcc50ee263678504e34d01318 (diff)
downloaderable-godot-f5a7e3ef7e25aa2545f541e171f2d5f6fe43ecc7.tar.gz
erable-godot-f5a7e3ef7e25aa2545f541e171f2d5f6fe43ecc7.tar.bz2
erable-godot-f5a7e3ef7e25aa2545f541e171f2d5f6fe43ecc7.zip
Erable playing audio in bg thread; Sirop backend initalized; Msgbox added
Diffstat (limited to 'Erable/Views/MessageBox.axaml.cs')
-rw-r--r--Erable/Views/MessageBox.axaml.cs74
1 files changed, 74 insertions, 0 deletions
diff --git a/Erable/Views/MessageBox.axaml.cs b/Erable/Views/MessageBox.axaml.cs
new file mode 100644
index 0000000..6d8b6d9
--- /dev/null
+++ b/Erable/Views/MessageBox.axaml.cs
@@ -0,0 +1,74 @@
+using System.Threading.Tasks;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace Erable.Views
+{
+ public class MessageBox : Window
+ {
+ public enum MessageBoxButtons
+ {
+ Ok,
+ OkCancel,
+ YesNo,
+ YesNoCancel
+ }
+
+ public enum MessageBoxResult
+ {
+ Ok,
+ Cancel,
+ Yes,
+ No
+ }
+
+
+ public MessageBox()
+ {
+ AvaloniaXamlLoader.Load(this);
+ }
+
+ public static Task<MessageBoxResult> Show(Window parent, string text, string title, MessageBoxButtons buttons)
+ {
+ var msgbox = new MessageBox()
+ {
+ Title = title
+ };
+ msgbox.FindControl<TextBlock>("Text").Text = text;
+ var buttonPanel = msgbox.FindControl<StackPanel>("Buttons");
+
+ var res = MessageBoxResult.Ok;
+
+ void AddButton(string caption, MessageBoxResult r, bool def = false)
+ {
+ var btn = new Button {Content = caption};
+ btn.Click += (_, __) => {
+ res = r;
+ msgbox.Close();
+ };
+ buttonPanel.Children.Add(btn);
+ if (def)
+ res = r;
+ }
+
+ if (buttons == MessageBoxButtons.Ok || buttons == MessageBoxButtons.OkCancel)
+ AddButton("OK", MessageBoxResult.Ok, true);
+ if (buttons == MessageBoxButtons.YesNo || buttons == MessageBoxButtons.YesNoCancel)
+ {
+ AddButton("Yes", MessageBoxResult.Yes);
+ AddButton("No", MessageBoxResult.No, true);
+ }
+
+ if (buttons == MessageBoxButtons.OkCancel || buttons == MessageBoxButtons.YesNoCancel)
+ AddButton("Cancel", MessageBoxResult.Cancel, true);
+
+
+ var tcs = new TaskCompletionSource<MessageBoxResult>();
+ msgbox.Closed += delegate { tcs.TrySetResult(res); };
+ if (parent != null)
+ msgbox.ShowDialog(parent);
+ else msgbox.Show();
+ return tcs.Task;
+ }
+ }
+} \ No newline at end of file