mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 09:58:21 +08:00
Add a more basic ConfirmDialog implementation
This commit is contained in:
parent
8a660b2bf5
commit
7dce9b04fa
45
osu.Game/Overlays/Dialog/ConfirmDialog.cs
Normal file
45
osu.Game/Overlays/Dialog/ConfirmDialog.cs
Normal 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
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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...";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user