Add a more basic ConfirmDialog implementation

This commit is contained in:
Dean Herbert 2021-03-03 14:50:45 +09:00
parent 8a660b2bf5
commit 7dce9b04fa
2 changed files with 50 additions and 21 deletions

View File

@ -0,0 +1,45 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Graphics.Sprites;
namespace osu.Game.Overlays.Dialog
{
/// <summary>
/// A dialog which confirms a user action.
/// </summary>
public class ConfirmDialog : PopupDialog
{
protected PopupDialogOkButton ButtonConfirm;
protected PopupDialogCancelButton ButtonCancel;
/// <summary>
/// Construct a new dialog.
/// </summary>
/// <param name="description">The description of the action to be displayed to the user.</param>
/// <param name="onConfirm">An action to perform on confirmation.</param>
/// <param name="onCancel">An optional action to perform on cancel.</param>
public ConfirmDialog(string description, Action onConfirm, Action onCancel = null)
{
HeaderText = $"Are you sure you want to {description}?";
BodyText = "Last chance to back out.";
Icon = FontAwesome.Solid.ExclamationTriangle;
Buttons = new PopupDialogButton[]
{
ButtonConfirm = new PopupDialogOkButton
{
Text = @"Yes",
Action = onConfirm
},
ButtonCancel = new PopupDialogCancelButton
{
Text = @"Cancel",
Action = onCancel
},
};
}
}
}

View File

@ -2,33 +2,17 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
namespace osu.Game.Screens.Menu
{
public class ConfirmExitDialog : PopupDialog
public class ConfirmExitDialog : ConfirmDialog
{
public ConfirmExitDialog(Action confirm, Action cancel)
public ConfirmExitDialog(Action confirm, Action onCancel = null)
: base("exit osu!", confirm, onCancel)
{
HeaderText = "Are you sure you want to exit?";
BodyText = "Last chance to back out.";
Icon = FontAwesome.Solid.ExclamationTriangle;
Buttons = new PopupDialogButton[]
{
new PopupDialogOkButton
{
Text = @"Goodbye",
Action = confirm
},
new PopupDialogCancelButton
{
Text = @"Just a little more",
Action = cancel
},
};
ButtonConfirm.Text = "Let me out!";
ButtonCancel.Text = "Just a little more...";
}
}
}