2019-11-29 04:32:51 +00:00
|
|
|
using Gtk;
|
2021-01-08 08:14:13 +00:00
|
|
|
using Ryujinx.Common.Logging;
|
2022-05-15 11:30:15 +00:00
|
|
|
using Ryujinx.Ui.Common.Configuration;
|
2021-04-23 20:26:31 +00:00
|
|
|
using System.Collections.Generic;
|
2022-05-15 11:30:15 +00:00
|
|
|
using System.Reflection;
|
2019-11-29 04:32:51 +00:00
|
|
|
|
2021-01-08 08:14:13 +00:00
|
|
|
namespace Ryujinx.Ui.Widgets
|
2019-11-29 04:32:51 +00:00
|
|
|
{
|
2020-05-03 02:00:53 +00:00
|
|
|
internal class GtkDialog : MessageDialog
|
2019-11-29 04:32:51 +00:00
|
|
|
{
|
2020-09-29 20:05:25 +00:00
|
|
|
private static bool _isChoiceDialogOpen;
|
2020-03-29 12:47:37 +00:00
|
|
|
|
2020-09-29 20:05:25 +00:00
|
|
|
private GtkDialog(string title, string mainText, string secondaryText, MessageType messageType = MessageType.Other, ButtonsType buttonsType = ButtonsType.Ok)
|
|
|
|
: base(null, DialogFlags.Modal, messageType, buttonsType, null)
|
2019-11-29 04:32:51 +00:00
|
|
|
{
|
2021-01-08 08:14:13 +00:00
|
|
|
Title = title;
|
2022-05-15 11:30:15 +00:00
|
|
|
Icon = new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Logo_Ryujinx.png");
|
2021-01-08 08:14:13 +00:00
|
|
|
Text = mainText;
|
|
|
|
SecondaryText = secondaryText;
|
|
|
|
WindowPosition = WindowPosition.Center;
|
|
|
|
SecondaryUseMarkup = true;
|
|
|
|
|
|
|
|
Response += GtkDialog_Response;
|
|
|
|
|
|
|
|
SetSizeRequest(200, 20);
|
2020-05-03 02:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void GtkDialog_Response(object sender, ResponseArgs args)
|
|
|
|
{
|
|
|
|
Dispose();
|
2019-11-29 04:32:51 +00:00
|
|
|
}
|
2020-02-06 11:38:24 +00:00
|
|
|
|
2021-01-08 08:14:13 +00:00
|
|
|
internal static void CreateInfoDialog(string mainText, string secondaryText)
|
|
|
|
{
|
|
|
|
new GtkDialog("Ryujinx - Info", mainText, secondaryText, MessageType.Info).Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
internal static void CreateUpdaterInfoDialog(string mainText, string secondaryText)
|
2020-02-06 11:38:24 +00:00
|
|
|
{
|
2021-01-08 08:14:13 +00:00
|
|
|
new GtkDialog("Ryujinx - Updater", mainText, secondaryText, MessageType.Info).Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
internal static MessageDialog CreateWaitingDialog(string mainText, string secondaryText)
|
|
|
|
{
|
|
|
|
return new GtkDialog("Ryujinx - Waiting", mainText, secondaryText, MessageType.Info, ButtonsType.None);
|
2020-05-03 02:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal static void CreateWarningDialog(string mainText, string secondaryText)
|
|
|
|
{
|
|
|
|
new GtkDialog("Ryujinx - Warning", mainText, secondaryText, MessageType.Warning).Run();
|
2020-02-06 11:38:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal static void CreateErrorDialog(string errorMessage)
|
|
|
|
{
|
2021-01-08 08:14:13 +00:00
|
|
|
Logger.Error?.Print(LogClass.Application, errorMessage);
|
|
|
|
|
2020-05-03 02:00:53 +00:00
|
|
|
new GtkDialog("Ryujinx - Error", "Ryujinx has encountered an error", errorMessage, MessageType.Error).Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
internal static MessageDialog CreateConfirmationDialog(string mainText, string secondaryText = "")
|
|
|
|
{
|
|
|
|
return new GtkDialog("Ryujinx - Confirmation", mainText, secondaryText, MessageType.Question, ButtonsType.YesNo);
|
2020-02-06 11:38:24 +00:00
|
|
|
}
|
2020-03-29 12:47:37 +00:00
|
|
|
|
2020-09-29 20:05:25 +00:00
|
|
|
internal static bool CreateChoiceDialog(string title, string mainText, string secondaryText)
|
2020-03-29 12:47:37 +00:00
|
|
|
{
|
2020-09-29 20:05:25 +00:00
|
|
|
if (_isChoiceDialogOpen)
|
2021-01-08 08:14:13 +00:00
|
|
|
{
|
2020-03-29 12:47:37 +00:00
|
|
|
return false;
|
2021-01-08 08:14:13 +00:00
|
|
|
}
|
2020-09-29 20:05:25 +00:00
|
|
|
|
|
|
|
_isChoiceDialogOpen = true;
|
2021-01-08 08:14:13 +00:00
|
|
|
|
2020-09-29 20:05:25 +00:00
|
|
|
ResponseType response = (ResponseType)new GtkDialog(title, mainText, secondaryText, MessageType.Question, ButtonsType.YesNo).Run();
|
2021-01-08 08:14:13 +00:00
|
|
|
|
2020-09-29 20:05:25 +00:00
|
|
|
_isChoiceDialogOpen = false;
|
|
|
|
|
|
|
|
return response == ResponseType.Yes;
|
2020-03-29 12:47:37 +00:00
|
|
|
}
|
2020-10-09 23:22:25 +00:00
|
|
|
|
2021-04-23 20:26:31 +00:00
|
|
|
internal static ResponseType CreateCustomDialog(string title, string mainText, string secondaryText, Dictionary<int, string> buttons, MessageType messageType = MessageType.Other)
|
|
|
|
{
|
|
|
|
GtkDialog gtkDialog = new GtkDialog(title, mainText, secondaryText, messageType, ButtonsType.None);
|
|
|
|
|
|
|
|
foreach (var button in buttons)
|
|
|
|
{
|
|
|
|
gtkDialog.AddButton(button.Value, button.Key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ResponseType)gtkDialog.Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
internal static string CreateInputDialog(Window parent, string title, string mainText, uint inputMax)
|
|
|
|
{
|
|
|
|
GtkInputDialog gtkDialog = new GtkInputDialog(parent, title, mainText, inputMax);
|
|
|
|
ResponseType response = (ResponseType)gtkDialog.Run();
|
|
|
|
string responseText = gtkDialog.InputEntry.Text.TrimEnd();
|
|
|
|
|
|
|
|
gtkDialog.Dispose();
|
|
|
|
|
|
|
|
if (response == ResponseType.Ok)
|
|
|
|
{
|
|
|
|
return responseText;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2020-10-09 23:22:25 +00:00
|
|
|
internal static bool CreateExitDialog()
|
|
|
|
{
|
2021-03-18 22:44:39 +00:00
|
|
|
return CreateChoiceDialog("Ryujinx - Exit", "Are you sure you want to close Ryujinx?", "All unsaved data will be lost!");
|
2020-10-09 23:22:25 +00:00
|
|
|
}
|
2019-11-29 04:32:51 +00:00
|
|
|
}
|
2021-03-18 22:44:39 +00:00
|
|
|
}
|