2022-05-15 13:30:15 +02:00
|
|
|
using Avalonia.Controls;
|
|
|
|
using Avalonia.Threading;
|
2022-07-05 20:06:31 +02:00
|
|
|
using FluentAvalonia.UI.Controls;
|
2022-05-15 13:30:15 +02:00
|
|
|
using Ryujinx.Ava.Common.Locale;
|
2022-12-29 15:24:05 +01:00
|
|
|
using Ryujinx.Ava.UI.Controls;
|
|
|
|
using Ryujinx.Ava.UI.Helpers;
|
|
|
|
using Ryujinx.Ava.UI.Windows;
|
2022-05-15 13:30:15 +02:00
|
|
|
using Ryujinx.HLE;
|
|
|
|
using Ryujinx.HLE.HOS.Applets;
|
|
|
|
using Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy.Types;
|
|
|
|
using Ryujinx.HLE.Ui;
|
|
|
|
using System;
|
|
|
|
using System.Threading;
|
|
|
|
|
2022-12-29 15:24:05 +01:00
|
|
|
namespace Ryujinx.Ava.UI.Applet
|
2022-05-15 13:30:15 +02:00
|
|
|
{
|
|
|
|
internal class AvaHostUiHandler : IHostUiHandler
|
|
|
|
{
|
|
|
|
private readonly MainWindow _parent;
|
|
|
|
|
|
|
|
public IHostUiTheme HostUiTheme { get; }
|
|
|
|
|
|
|
|
public AvaHostUiHandler(MainWindow parent)
|
|
|
|
{
|
|
|
|
_parent = parent;
|
|
|
|
|
|
|
|
HostUiTheme = new AvaloniaHostUiTheme(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool DisplayMessageDialog(ControllerAppletUiArgs args)
|
|
|
|
{
|
|
|
|
string playerCount = args.PlayerCountMin == args.PlayerCountMax
|
|
|
|
? args.PlayerCountMin.ToString()
|
|
|
|
: $"{args.PlayerCountMin}-{args.PlayerCountMax}";
|
|
|
|
|
2023-01-03 19:45:08 +01:00
|
|
|
LocaleKeys key = args.PlayerCountMin == args.PlayerCountMax ? LocaleKeys.DialogControllerAppletMessage : LocaleKeys.DialogControllerAppletMessagePlayerRange;
|
2022-05-15 13:30:15 +02:00
|
|
|
|
|
|
|
string message = string.Format(LocaleManager.Instance[key],
|
|
|
|
playerCount,
|
|
|
|
args.SupportedStyles,
|
|
|
|
string.Join(", ", args.SupportedPlayers),
|
2023-01-03 19:45:08 +01:00
|
|
|
args.IsDocked ? LocaleManager.Instance[LocaleKeys.DialogControllerAppletDockModeSet] : "");
|
2022-05-15 13:30:15 +02:00
|
|
|
|
2023-01-03 19:45:08 +01:00
|
|
|
return DisplayMessageDialog(LocaleManager.Instance[LocaleKeys.DialogControllerAppletTitle], message);
|
2022-05-15 13:30:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool DisplayMessageDialog(string title, string message)
|
|
|
|
{
|
2022-07-05 20:06:31 +02:00
|
|
|
ManualResetEvent dialogCloseEvent = new(false);
|
|
|
|
|
|
|
|
bool okPressed = false;
|
|
|
|
|
|
|
|
Dispatcher.UIThread.InvokeAsync(async () =>
|
2022-05-15 13:30:15 +02:00
|
|
|
{
|
2022-07-05 20:06:31 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ManualResetEvent deferEvent = new(false);
|
|
|
|
|
|
|
|
bool opened = false;
|
|
|
|
|
2022-11-24 09:31:00 +01:00
|
|
|
UserResult response = await ContentDialogHelper.ShowDeferredContentDialog(_parent,
|
|
|
|
title,
|
|
|
|
message,
|
|
|
|
"",
|
2023-01-03 19:45:08 +01:00
|
|
|
LocaleManager.Instance[LocaleKeys.DialogOpenSettingsWindowLabel],
|
2022-11-24 09:31:00 +01:00
|
|
|
"",
|
2023-01-03 19:45:08 +01:00
|
|
|
LocaleManager.Instance[LocaleKeys.SettingsButtonClose],
|
2022-11-24 09:31:00 +01:00
|
|
|
(int)Symbol.Important,
|
2022-07-05 20:06:31 +02:00
|
|
|
deferEvent,
|
|
|
|
async (window) =>
|
|
|
|
{
|
|
|
|
if (opened)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
opened = true;
|
|
|
|
|
|
|
|
_parent.SettingsWindow = new SettingsWindow(_parent.VirtualFileSystem, _parent.ContentManager);
|
|
|
|
|
|
|
|
await _parent.SettingsWindow.ShowDialog(window);
|
|
|
|
|
|
|
|
opened = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (response == UserResult.Ok)
|
|
|
|
{
|
|
|
|
okPressed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialogCloseEvent.Set();
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2023-01-03 19:45:08 +01:00
|
|
|
await ContentDialogHelper.CreateErrorDialog(string.Format(LocaleManager.Instance[LocaleKeys.DialogMessageDialogErrorExceptionMessage], ex));
|
2022-07-05 20:06:31 +02:00
|
|
|
|
|
|
|
dialogCloseEvent.Set();
|
|
|
|
}
|
2022-05-15 13:30:15 +02:00
|
|
|
});
|
|
|
|
|
2022-07-05 20:06:31 +02:00
|
|
|
dialogCloseEvent.WaitOne();
|
|
|
|
|
|
|
|
return okPressed;
|
2022-05-15 13:30:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool DisplayInputDialog(SoftwareKeyboardUiArgs args, out string userText)
|
|
|
|
{
|
|
|
|
ManualResetEvent dialogCloseEvent = new(false);
|
|
|
|
|
|
|
|
bool okPressed = false;
|
|
|
|
bool error = false;
|
|
|
|
string inputText = args.InitialText ?? "";
|
|
|
|
|
|
|
|
Dispatcher.UIThread.Post(async () =>
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-01-03 19:45:08 +01:00
|
|
|
var response = await SwkbdAppletDialog.ShowInputDialog(_parent, LocaleManager.Instance[LocaleKeys.SoftwareKeyboard], args);
|
2022-05-15 13:30:15 +02:00
|
|
|
|
|
|
|
if (response.Result == UserResult.Ok)
|
|
|
|
{
|
|
|
|
inputText = response.Input;
|
|
|
|
okPressed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
error = true;
|
2023-01-03 19:45:08 +01:00
|
|
|
await ContentDialogHelper.CreateErrorDialog(string.Format(LocaleManager.Instance[LocaleKeys.DialogSoftwareKeyboardErrorExceptionMessage], ex));
|
2022-05-15 13:30:15 +02:00
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
dialogCloseEvent.Set();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogCloseEvent.WaitOne();
|
|
|
|
|
|
|
|
userText = error ? null : inputText;
|
|
|
|
|
|
|
|
return error || okPressed;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ExecuteProgram(Switch device, ProgramSpecifyKind kind, ulong value)
|
|
|
|
{
|
|
|
|
device.Configuration.UserChannelPersistence.ExecuteProgram(kind, value);
|
2023-01-08 18:46:25 +01:00
|
|
|
if (_parent.ViewModel.AppHost != null)
|
2022-05-15 13:30:15 +02:00
|
|
|
{
|
2023-01-08 18:46:25 +01:00
|
|
|
_parent.ViewModel.AppHost.Stop();
|
2022-05-15 13:30:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool DisplayErrorAppletDialog(string title, string message, string[] buttons)
|
|
|
|
{
|
|
|
|
ManualResetEvent dialogCloseEvent = new(false);
|
|
|
|
|
|
|
|
bool showDetails = false;
|
|
|
|
|
|
|
|
Dispatcher.UIThread.Post(async () =>
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ErrorAppletWindow msgDialog = new(_parent, buttons, message)
|
|
|
|
{
|
|
|
|
Title = title,
|
|
|
|
WindowStartupLocation = WindowStartupLocation.CenterScreen,
|
|
|
|
Width = 400
|
|
|
|
};
|
|
|
|
|
|
|
|
object response = await msgDialog.Run();
|
|
|
|
|
2022-11-24 09:31:00 +01:00
|
|
|
if (response != null && buttons != null && buttons.Length > 1 && (int)response != buttons.Length - 1)
|
2022-05-15 13:30:15 +02:00
|
|
|
{
|
|
|
|
showDetails = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialogCloseEvent.Set();
|
|
|
|
|
|
|
|
msgDialog.Close();
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
dialogCloseEvent.Set();
|
2023-01-03 19:45:08 +01:00
|
|
|
await ContentDialogHelper.CreateErrorDialog(string.Format(LocaleManager.Instance[LocaleKeys.DialogErrorAppletErrorExceptionMessage], ex));
|
2022-05-15 13:30:15 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogCloseEvent.WaitOne();
|
|
|
|
|
|
|
|
return showDetails;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IDynamicTextInputHandler CreateDynamicTextInputHandler()
|
|
|
|
{
|
|
|
|
return new AvaloniaDynamicTextInputHandler(_parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|