GtkHostUiHandler.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using Gtk;
  2. using Ryujinx.Common.Logging;
  3. using Ryujinx.HLE;
  4. using Ryujinx.HLE.HOS.Applets;
  5. using Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy.Types;
  6. using System;
  7. using System.Threading;
  8. namespace Ryujinx.Ui
  9. {
  10. internal class GtkHostUiHandler : IHostUiHandler
  11. {
  12. private readonly Window _parent;
  13. public GtkHostUiHandler(Window parent)
  14. {
  15. _parent = parent;
  16. }
  17. public bool DisplayMessageDialog(ControllerAppletUiArgs args)
  18. {
  19. string playerCount = args.PlayerCountMin == args.PlayerCountMax
  20. ? $"exactly {args.PlayerCountMin}"
  21. : $"{args.PlayerCountMin}-{args.PlayerCountMax}";
  22. string message =
  23. $"Application requests <b>{playerCount}</b> player(s) with:\n\n"
  24. + $"<tt><b>TYPES:</b> {args.SupportedStyles}</tt>\n\n"
  25. + $"<tt><b>PLAYERS:</b> {string.Join(", ", args.SupportedPlayers)}</tt>\n\n"
  26. + (args.IsDocked ? "Docked mode set. <tt>Handheld</tt> is also invalid.\n\n" : "")
  27. + "<i>Please reconfigure Input now and then press OK.</i>";
  28. return DisplayMessageDialog("Controller Applet", message);
  29. }
  30. public bool DisplayMessageDialog(string title, string message)
  31. {
  32. ManualResetEvent dialogCloseEvent = new ManualResetEvent(false);
  33. bool okPressed = false;
  34. Application.Invoke(delegate
  35. {
  36. MessageDialog msgDialog = null;
  37. try
  38. {
  39. msgDialog = new MessageDialog(_parent, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, null)
  40. {
  41. Title = title,
  42. Text = message,
  43. UseMarkup = true
  44. };
  45. msgDialog.SetDefaultSize(400, 0);
  46. msgDialog.Response += (object o, ResponseArgs args) =>
  47. {
  48. if (args.ResponseId == ResponseType.Ok) okPressed = true;
  49. dialogCloseEvent.Set();
  50. msgDialog?.Dispose();
  51. };
  52. msgDialog.Show();
  53. }
  54. catch (Exception e)
  55. {
  56. Logger.Error?.Print(LogClass.Application, $"Error displaying Message Dialog: {e}");
  57. dialogCloseEvent.Set();
  58. }
  59. });
  60. dialogCloseEvent.WaitOne();
  61. return okPressed;
  62. }
  63. public bool DisplayInputDialog(SoftwareKeyboardUiArgs args, out string userText)
  64. {
  65. ManualResetEvent dialogCloseEvent = new ManualResetEvent(false);
  66. bool okPressed = false;
  67. bool error = false;
  68. string inputText = args.InitialText ?? "";
  69. Application.Invoke(delegate
  70. {
  71. try
  72. {
  73. var swkbdDialog = new InputDialog(_parent)
  74. {
  75. Title = "Software Keyboard",
  76. Text = args.HeaderText,
  77. SecondaryText = args.SubtitleText
  78. };
  79. swkbdDialog.InputEntry.Text = inputText;
  80. swkbdDialog.InputEntry.PlaceholderText = args.GuideText;
  81. swkbdDialog.OkButton.Label = args.SubmitText;
  82. swkbdDialog.SetInputLengthValidation(args.StringLengthMin, args.StringLengthMax);
  83. if (swkbdDialog.Run() == (int)ResponseType.Ok)
  84. {
  85. inputText = swkbdDialog.InputEntry.Text;
  86. okPressed = true;
  87. }
  88. swkbdDialog.Dispose();
  89. }
  90. catch (Exception e)
  91. {
  92. error = true;
  93. Logger.Error?.Print(LogClass.Application, $"Error displaying Software Keyboard: {e}");
  94. }
  95. finally
  96. {
  97. dialogCloseEvent.Set();
  98. }
  99. });
  100. dialogCloseEvent.WaitOne();
  101. userText = error ? null : inputText;
  102. return error || okPressed;
  103. }
  104. public void ExecuteProgram(HLE.Switch device, ProgramSpecifyKind kind, ulong value)
  105. {
  106. device.UserChannelPersistence.ExecuteProgram(kind, value);
  107. MainWindow.GlWidget?.Exit();
  108. }
  109. public bool DisplayErrorAppletDialog(string title, string message, string[] buttons)
  110. {
  111. ManualResetEvent dialogCloseEvent = new ManualResetEvent(false);
  112. bool showDetails = false;
  113. Application.Invoke(delegate
  114. {
  115. try
  116. {
  117. ErrorAppletDialog msgDialog = new ErrorAppletDialog(_parent, DialogFlags.DestroyWithParent, MessageType.Error, buttons)
  118. {
  119. Title = title,
  120. Text = message,
  121. UseMarkup = true,
  122. WindowPosition = WindowPosition.CenterAlways
  123. };
  124. msgDialog.SetDefaultSize(400, 0);
  125. msgDialog.Response += (object o, ResponseArgs args) =>
  126. {
  127. if (buttons != null)
  128. {
  129. if (buttons.Length > 1)
  130. {
  131. if (args.ResponseId != (ResponseType)(buttons.Length - 1))
  132. {
  133. showDetails = true;
  134. }
  135. }
  136. }
  137. dialogCloseEvent.Set();
  138. msgDialog?.Dispose();
  139. };
  140. msgDialog.Show();
  141. }
  142. catch (Exception e)
  143. {
  144. Logger.Error?.Print(LogClass.Application, $"Error displaying ErrorApplet Dialog: {e}");
  145. dialogCloseEvent.Set();
  146. }
  147. });
  148. dialogCloseEvent.WaitOne();
  149. return showDetails;
  150. }
  151. }
  152. }