GtkHostUiHandler.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using Gtk;
  2. using Ryujinx.Common.Logging;
  3. using Ryujinx.HLE;
  4. using Ryujinx.HLE.HOS.Applets;
  5. using System;
  6. using System.Threading;
  7. namespace Ryujinx.Ui
  8. {
  9. internal class GtkHostUiHandler : IHostUiHandler
  10. {
  11. private readonly Window _parent;
  12. public GtkHostUiHandler(Window parent)
  13. {
  14. _parent = parent;
  15. }
  16. public bool DisplayMessageDialog(ControllerAppletUiArgs args)
  17. {
  18. string playerCount = args.PlayerCountMin == args.PlayerCountMax
  19. ? $"exactly {args.PlayerCountMin}"
  20. : $"{args.PlayerCountMin}-{args.PlayerCountMax}";
  21. string message =
  22. $"Application requests <b>{playerCount}</b> player(s) with:\n\n"
  23. + $"<tt><b>TYPES:</b> {args.SupportedStyles}</tt>\n\n"
  24. + $"<tt><b>PLAYERS:</b> {string.Join(", ", args.SupportedPlayers)}</tt>\n\n"
  25. + (args.IsDocked ? "Docked mode set. <tt>Handheld</tt> is also invalid.\n\n" : "")
  26. + "<i>Please reconfigure Input now and then press OK.</i>";
  27. return DisplayMessageDialog("Controller Applet", message);
  28. }
  29. public bool DisplayMessageDialog(string title, string message)
  30. {
  31. ManualResetEvent dialogCloseEvent = new ManualResetEvent(false);
  32. bool okPressed = false;
  33. Application.Invoke(delegate
  34. {
  35. MessageDialog msgDialog = null;
  36. try
  37. {
  38. msgDialog = new MessageDialog(_parent, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, null)
  39. {
  40. Title = title,
  41. Text = message,
  42. UseMarkup = true
  43. };
  44. msgDialog.SetDefaultSize(400, 0);
  45. msgDialog.Response += (object o, ResponseArgs args) =>
  46. {
  47. if (args.ResponseId == ResponseType.Ok) okPressed = true;
  48. dialogCloseEvent.Set();
  49. msgDialog?.Dispose();
  50. };
  51. msgDialog.Show();
  52. }
  53. catch (Exception e)
  54. {
  55. Logger.Error?.Print(LogClass.Application, $"Error displaying Message Dialog: {e}");
  56. dialogCloseEvent.Set();
  57. }
  58. });
  59. dialogCloseEvent.WaitOne();
  60. return okPressed;
  61. }
  62. public bool DisplayInputDialog(SoftwareKeyboardUiArgs args, out string userText)
  63. {
  64. ManualResetEvent dialogCloseEvent = new ManualResetEvent(false);
  65. bool okPressed = false;
  66. bool error = false;
  67. string inputText = args.InitialText ?? "";
  68. Application.Invoke(delegate
  69. {
  70. try
  71. {
  72. var swkbdDialog = new InputDialog(_parent)
  73. {
  74. Title = "Software Keyboard",
  75. Text = args.HeaderText,
  76. SecondaryText = args.SubtitleText
  77. };
  78. swkbdDialog.InputEntry.Text = inputText;
  79. swkbdDialog.InputEntry.PlaceholderText = args.GuideText;
  80. swkbdDialog.OkButton.Label = args.SubmitText;
  81. swkbdDialog.SetInputLengthValidation(args.StringLengthMin, args.StringLengthMax);
  82. if (swkbdDialog.Run() == (int)ResponseType.Ok)
  83. {
  84. inputText = swkbdDialog.InputEntry.Text;
  85. okPressed = true;
  86. }
  87. swkbdDialog.Dispose();
  88. }
  89. catch (Exception e)
  90. {
  91. error = true;
  92. Logger.Error?.Print(LogClass.Application, $"Error displaying Software Keyboard: {e}");
  93. }
  94. finally
  95. {
  96. dialogCloseEvent.Set();
  97. }
  98. });
  99. dialogCloseEvent.WaitOne();
  100. userText = error ? null : inputText;
  101. return error || okPressed;
  102. }
  103. }
  104. }