Files
StarterNG/StarterNG/Views/MessageBox.cs
maj00r 37dd038b96 Explain the missing-simulator prompt and name its buttons
It now says where the starter looks for the simulator and why it matters,
that starting from the wrong folder is the usual cause, and answers with
"Point to the simulator" and "Not now" instead of Yes and No.
2026-10-04 18:59:14 +02:00

71 lines
2.2 KiB
C#

using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Layout;
using Avalonia.Media;
namespace StarterNG.Views;
public enum MessageBoxButtons
{
YesNo,
Ok
}
public static class MessageBox
{
/// <param name="yesText">A label that says what the answer does, in place of "Yes".</param>
/// <param name="noText">Likewise in place of "No".</param>
public static async Task<bool> Show(Window owner, string message, string title, MessageBoxButtons buttons,
string? yesText = null, string? noText = null)
{
var win = new Window
{
Title = title,
Width = 420,
SizeToContent = SizeToContent.Height,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
CanResize = false
};
bool yes = false;
var yesBtn = new Button { Content = App.Loc["Yes"], MinWidth = 80, Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Hand) };
yesBtn.Classes.Add("Accent");
yesBtn.Click += (_, _) => { yes = true; win.Close(); };
var noBtn = new Button { Content = App.Loc["No"], MinWidth = 80, Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Hand) };
noBtn.Classes.Add("Flat");
noBtn.Click += (_, _) => win.Close();
if (yesText is not null)
yesBtn.Content = yesText;
if (noText is not null)
noBtn.Content = noText;
if (buttons == MessageBoxButtons.Ok)
{
yesBtn.Content = App.Loc["Ok"];
noBtn.IsVisible = false;
}
win.Content = new StackPanel
{
Margin = new Avalonia.Thickness(16),
Spacing = 16,
Children =
{
new TextBlock { Text = message, TextWrapping = TextWrapping.Wrap },
new StackPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Right,
Spacing = 8,
Children = { yesBtn, noBtn }
}
}
};
await win.ShowDialog(owner);
return yes;
}
}