2020-08-03 03:30:58 +02:00
|
|
|
using Gtk;
|
|
|
|
using Ryujinx.HLE;
|
|
|
|
using Ryujinx.HLE.HOS.Applets;
|
2020-09-21 05:45:30 +02:00
|
|
|
using Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy.Types;
|
2021-01-08 09:14:13 +01:00
|
|
|
using Ryujinx.Ui.Widgets;
|
2020-08-03 03:30:58 +02:00
|
|
|
using System;
|
|
|
|
using System.Threading;
|
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
namespace Ryujinx.Ui.Applet
|
2020-08-03 03:30:58 +02:00
|
|
|
{
|
|
|
|
internal class GtkHostUiHandler : IHostUiHandler
|
|
|
|
{
|
|
|
|
private readonly Window _parent;
|
|
|
|
|
|
|
|
public GtkHostUiHandler(Window parent)
|
|
|
|
{
|
|
|
|
_parent = parent;
|
|
|
|
}
|
|
|
|
|
2020-08-23 22:54:11 +02:00
|
|
|
public bool DisplayMessageDialog(ControllerAppletUiArgs args)
|
|
|
|
{
|
2021-01-08 09:14:13 +01:00
|
|
|
string playerCount = args.PlayerCountMin == args.PlayerCountMax ? $"exactly {args.PlayerCountMin}" : $"{args.PlayerCountMin}-{args.PlayerCountMax}";
|
2020-08-23 22:54:11 +02:00
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
string message = $"Application requests <b>{playerCount}</b> player(s) with:\n\n"
|
|
|
|
+ $"<tt><b>TYPES:</b> {args.SupportedStyles}</tt>\n\n"
|
|
|
|
+ $"<tt><b>PLAYERS:</b> {string.Join(", ", args.SupportedPlayers)}</tt>\n\n"
|
|
|
|
+ (args.IsDocked ? "Docked mode set. <tt>Handheld</tt> is also invalid.\n\n" : "")
|
|
|
|
+ "<i>Please reconfigure Input now and then press OK.</i>";
|
2020-08-23 22:54:11 +02:00
|
|
|
|
|
|
|
return DisplayMessageDialog("Controller Applet", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool DisplayMessageDialog(string title, string message)
|
|
|
|
{
|
|
|
|
ManualResetEvent dialogCloseEvent = new ManualResetEvent(false);
|
2021-01-08 09:14:13 +01:00
|
|
|
|
2020-08-23 22:54:11 +02:00
|
|
|
bool okPressed = false;
|
|
|
|
|
|
|
|
Application.Invoke(delegate
|
|
|
|
{
|
|
|
|
MessageDialog msgDialog = null;
|
2021-01-08 09:14:13 +01:00
|
|
|
|
2020-08-23 22:54:11 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
msgDialog = new MessageDialog(_parent, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, null)
|
|
|
|
{
|
2021-01-08 09:14:13 +01:00
|
|
|
Title = title,
|
|
|
|
Text = message,
|
2020-08-23 22:54:11 +02:00
|
|
|
UseMarkup = true
|
|
|
|
};
|
|
|
|
|
|
|
|
msgDialog.SetDefaultSize(400, 0);
|
|
|
|
|
|
|
|
msgDialog.Response += (object o, ResponseArgs args) =>
|
|
|
|
{
|
2021-01-08 09:14:13 +01:00
|
|
|
if (args.ResponseId == ResponseType.Ok)
|
|
|
|
{
|
|
|
|
okPressed = true;
|
|
|
|
}
|
|
|
|
|
2020-08-23 22:54:11 +02:00
|
|
|
dialogCloseEvent.Set();
|
|
|
|
msgDialog?.Dispose();
|
|
|
|
};
|
|
|
|
|
|
|
|
msgDialog.Show();
|
|
|
|
}
|
2021-01-08 09:14:13 +01:00
|
|
|
catch (Exception ex)
|
2020-08-23 22:54:11 +02:00
|
|
|
{
|
2021-01-08 09:14:13 +01:00
|
|
|
GtkDialog.CreateErrorDialog($"Error displaying Message Dialog: {ex}");
|
|
|
|
|
2020-08-23 22:54:11 +02:00
|
|
|
dialogCloseEvent.Set();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogCloseEvent.WaitOne();
|
|
|
|
|
|
|
|
return okPressed;
|
|
|
|
}
|
|
|
|
|
2020-08-03 03:30:58 +02:00
|
|
|
public bool DisplayInputDialog(SoftwareKeyboardUiArgs args, out string userText)
|
|
|
|
{
|
|
|
|
ManualResetEvent dialogCloseEvent = new ManualResetEvent(false);
|
2021-01-08 09:14:13 +01:00
|
|
|
|
|
|
|
bool okPressed = false;
|
|
|
|
bool error = false;
|
2020-08-03 03:30:58 +02:00
|
|
|
string inputText = args.InitialText ?? "";
|
|
|
|
|
|
|
|
Application.Invoke(delegate
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-01-08 09:14:13 +01:00
|
|
|
var swkbdDialog = new SwkbdAppletDialog(_parent)
|
2020-08-03 03:30:58 +02:00
|
|
|
{
|
2021-01-08 09:14:13 +01:00
|
|
|
Title = "Software Keyboard",
|
|
|
|
Text = args.HeaderText,
|
2020-08-03 03:30:58 +02:00
|
|
|
SecondaryText = args.SubtitleText
|
|
|
|
};
|
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
swkbdDialog.InputEntry.Text = inputText;
|
2020-08-03 03:30:58 +02:00
|
|
|
swkbdDialog.InputEntry.PlaceholderText = args.GuideText;
|
2021-01-08 09:14:13 +01:00
|
|
|
swkbdDialog.OkButton.Label = args.SubmitText;
|
2020-08-03 03:30:58 +02:00
|
|
|
|
|
|
|
swkbdDialog.SetInputLengthValidation(args.StringLengthMin, args.StringLengthMax);
|
|
|
|
|
|
|
|
if (swkbdDialog.Run() == (int)ResponseType.Ok)
|
|
|
|
{
|
|
|
|
inputText = swkbdDialog.InputEntry.Text;
|
|
|
|
okPressed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
swkbdDialog.Dispose();
|
|
|
|
}
|
2021-01-08 09:14:13 +01:00
|
|
|
catch (Exception ex)
|
2020-08-03 03:30:58 +02:00
|
|
|
{
|
|
|
|
error = true;
|
2021-01-08 09:14:13 +01:00
|
|
|
|
|
|
|
GtkDialog.CreateErrorDialog($"Error displaying Software Keyboard: {ex}");
|
2020-08-03 03:30:58 +02:00
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
dialogCloseEvent.Set();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogCloseEvent.WaitOne();
|
|
|
|
|
|
|
|
userText = error ? null : inputText;
|
|
|
|
|
|
|
|
return error || okPressed;
|
|
|
|
}
|
2020-09-21 05:45:30 +02:00
|
|
|
|
|
|
|
public void ExecuteProgram(HLE.Switch device, ProgramSpecifyKind kind, ulong value)
|
|
|
|
{
|
|
|
|
device.UserChannelPersistence.ExecuteProgram(kind, value);
|
2021-05-04 18:19:04 +02:00
|
|
|
((MainWindow)_parent).RendererWidget?.Exit();
|
2020-09-21 05:45:30 +02:00
|
|
|
}
|
2020-09-28 00:00:38 +02:00
|
|
|
|
|
|
|
public bool DisplayErrorAppletDialog(string title, string message, string[] buttons)
|
|
|
|
{
|
|
|
|
ManualResetEvent dialogCloseEvent = new ManualResetEvent(false);
|
2021-01-08 09:14:13 +01:00
|
|
|
|
2020-09-28 00:00:38 +02:00
|
|
|
bool showDetails = false;
|
|
|
|
|
|
|
|
Application.Invoke(delegate
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ErrorAppletDialog msgDialog = new ErrorAppletDialog(_parent, DialogFlags.DestroyWithParent, MessageType.Error, buttons)
|
|
|
|
{
|
|
|
|
Title = title,
|
|
|
|
Text = message,
|
|
|
|
UseMarkup = true,
|
|
|
|
WindowPosition = WindowPosition.CenterAlways
|
|
|
|
};
|
|
|
|
|
|
|
|
msgDialog.SetDefaultSize(400, 0);
|
|
|
|
|
|
|
|
msgDialog.Response += (object o, ResponseArgs args) =>
|
|
|
|
{
|
|
|
|
if (buttons != null)
|
|
|
|
{
|
|
|
|
if (buttons.Length > 1)
|
|
|
|
{
|
|
|
|
if (args.ResponseId != (ResponseType)(buttons.Length - 1))
|
|
|
|
{
|
|
|
|
showDetails = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dialogCloseEvent.Set();
|
|
|
|
msgDialog?.Dispose();
|
|
|
|
};
|
|
|
|
|
|
|
|
msgDialog.Show();
|
|
|
|
}
|
2021-01-08 09:14:13 +01:00
|
|
|
catch (Exception ex)
|
2020-09-28 00:00:38 +02:00
|
|
|
{
|
2021-01-08 09:14:13 +01:00
|
|
|
GtkDialog.CreateErrorDialog($"Error displaying ErrorApplet Dialog: {ex}");
|
2020-09-28 00:00:38 +02:00
|
|
|
|
|
|
|
dialogCloseEvent.Set();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogCloseEvent.WaitOne();
|
|
|
|
|
|
|
|
return showDetails;
|
|
|
|
}
|
2020-08-03 03:30:58 +02:00
|
|
|
}
|
2021-01-08 09:14:13 +01:00
|
|
|
}
|