Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodfeat authored Feb 12, 2025
2 parents acc06a8 + 8aeccca commit 22299e6
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 80 deletions.
6 changes: 4 additions & 2 deletions src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ private void ParseErrorCommonArg()

string[] buttons = GetButtonsText(module, description, "DlgBtn");

bool showDetails = _horizon.Device.UIHandler.DisplayErrorAppletDialog($"Error Code: {module}-{description:0000}", "\n" + message, buttons);
(uint Module, uint Description) errorCodeTuple = (module, uint.Parse(description.ToString("0000")));

bool showDetails = _horizon.Device.UIHandler.DisplayErrorAppletDialog($"Error Code: {module}-{description:0000}", "\n" + message, buttons, errorCodeTuple);
if (showDetails)
{
message = GetMessageText(module, description, "FlvMsg");
buttons = GetButtonsText(module, description, "FlvBtn");

_horizon.Device.UIHandler.DisplayErrorAppletDialog($"Details: {module}-{description:0000}", "\n" + message, buttons);
_horizon.Device.UIHandler.DisplayErrorAppletDialog($"Details: {module}-{description:0000}", "\n" + message, buttons, errorCodeTuple);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Ryujinx.HLE/UI/IHostUIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ public interface IHostUIHandler
/// <param name="value">The value associated to the <paramref name="kind"/>.</param>
void ExecuteProgram(Switch device, ProgramSpecifyKind kind, ulong value);

/// <summary>
/// Displays a Message Dialog box specific to Error Applet and blocks until it is closed.
/// </summary>
/// <returns>False when OK is pressed, True when another button (Details) is pressed.</returns>
bool DisplayErrorAppletDialog(string title, string message, string[] buttonsText);
// ReSharper disable once UnusedParameter.Global
bool DisplayErrorAppletDialog(string title, string message, string[] buttonsText, (uint Module, uint Description)? errorCode = null);

/// <summary>
/// Creates a handler to process keyboard inputs into text strings.
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx/Headless/Windows/WindowBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,15 @@ public void ExecuteProgram(Switch device, ProgramSpecifyKind kind, ulong value)
Exit();
}

public bool DisplayErrorAppletDialog(string title, string message, string[] buttonsText)
public bool DisplayErrorAppletDialog(string title, string message, string[] buttonsText, (uint Module, uint Description)? errorCode = null)
{
SDL_MessageBoxData data = new()
{
title = title,
message = message,
buttons = new SDL_MessageBoxButtonData[buttonsText.Length],
numbuttons = buttonsText.Length,
window = WindowHandle,
window = WindowHandle
};

for (int i = 0; i < buttonsText.Length; i++)
Expand Down
104 changes: 57 additions & 47 deletions src/Ryujinx/UI/Applet/AvaHostUIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,32 @@ public bool DisplayMessageDialog(string title, string message)
bool opened = false;

UserResult response = await ContentDialogHelper.ShowDeferredContentDialog(_parent,
title,
message,
string.Empty,
LocaleManager.Instance[LocaleKeys.DialogOpenSettingsWindowLabel],
string.Empty,
LocaleManager.Instance[LocaleKeys.SettingsButtonClose],
(int)Symbol.Important,
deferEvent,
async window =>
{
if (opened)
{
return;
}
title,
message,
string.Empty,
LocaleManager.Instance[LocaleKeys.DialogOpenSettingsWindowLabel],
string.Empty,
LocaleManager.Instance[LocaleKeys.SettingsButtonClose],
(int)Symbol.Important,
deferEvent,
async window =>
{
if (opened)
{
return;
}

opened = true;
opened = true;

_parent.SettingsWindow = new SettingsWindow(_parent.VirtualFileSystem, _parent.ContentManager);
_parent.SettingsWindow =
new SettingsWindow(_parent.VirtualFileSystem, _parent.ContentManager);

await _parent.SettingsWindow.ShowDialog(window);
await _parent.SettingsWindow.ShowDialog(window);

_parent.SettingsWindow = null;
_parent.SettingsWindow = null;

opened = false;
});
opened = false;
});

if (response == UserResult.Ok)
{
Expand All @@ -110,7 +111,9 @@ public bool DisplayMessageDialog(string title, string message)
}
catch (Exception ex)
{
await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogMessageDialogErrorExceptionMessage, ex));
await ContentDialogHelper.CreateErrorDialog(
LocaleManager.Instance.UpdateAndGetDynamicValue(
LocaleKeys.DialogMessageDialogErrorExceptionMessage, ex));

dialogCloseEvent.Set();
}
Expand All @@ -134,7 +137,9 @@ public bool DisplayInputDialog(SoftwareKeyboardUIArgs args, out string userText)
try
{
_parent.ViewModel.AppHost.NpadManager.BlockInputUpdates();
(UserResult result, string userInput) = await SwkbdAppletDialog.ShowInputDialog(LocaleManager.Instance[LocaleKeys.SoftwareKeyboard], args);
(UserResult result, string userInput) =
await SwkbdAppletDialog.ShowInputDialog(LocaleManager.Instance[LocaleKeys.SoftwareKeyboard],
args);

if (result == UserResult.Ok)
{
Expand All @@ -146,7 +151,9 @@ public bool DisplayInputDialog(SoftwareKeyboardUIArgs args, out string userText)
{
error = true;

await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogSoftwareKeyboardErrorExceptionMessage, ex));
await ContentDialogHelper.CreateErrorDialog(
LocaleManager.Instance.UpdateAndGetDynamicValue(
LocaleKeys.DialogSoftwareKeyboardErrorExceptionMessage, ex));
}
finally
{
Expand Down Expand Up @@ -177,7 +184,8 @@ public bool DisplayCabinetDialog(out string userText)
args.InitialText = "Ryujinx";
args.StringLengthMin = 1;
args.StringLengthMax = 25;
(UserResult result, string userInput) = await SwkbdAppletDialog.ShowInputDialog(LocaleManager.Instance[LocaleKeys.CabinetDialog], args);
(UserResult result, string userInput) =
await SwkbdAppletDialog.ShowInputDialog(LocaleManager.Instance[LocaleKeys.CabinetDialog], args);
if (result == UserResult.Ok)
{
inputText = userInput;
Expand All @@ -201,11 +209,13 @@ public void DisplayCabinetMessageDialog()
Dispatcher.UIThread.InvokeAsync(async () =>
{
dialogCloseEvent.Set();
await ContentDialogHelper.CreateInfoDialog(LocaleManager.Instance[LocaleKeys.CabinetScanDialog],
string.Empty,
LocaleManager.Instance[LocaleKeys.InputDialogOk],
string.Empty,
LocaleManager.Instance[LocaleKeys.CabinetTitle]);
await ContentDialogHelper.CreateInfoDialog(
LocaleManager.Instance[LocaleKeys.CabinetScanDialog],
string.Empty,
LocaleManager.Instance[LocaleKeys.InputDialogOk],
string.Empty,
LocaleManager.Instance[LocaleKeys.CabinetTitle]
);
});
dialogCloseEvent.WaitOne();
}
Expand All @@ -217,7 +227,8 @@ public void ExecuteProgram(Switch device, ProgramSpecifyKind kind, ulong value)
_parent.ViewModel.AppHost?.Stop();
}

public bool DisplayErrorAppletDialog(string title, string message, string[] buttons)
public bool DisplayErrorAppletDialog(string title, string message, string[] buttons,
(uint Module, uint Description)? errorCode = null)
{
ManualResetEvent dialogCloseEvent = new(false);

Expand All @@ -229,9 +240,7 @@ public bool DisplayErrorAppletDialog(string title, string message, string[] butt
{
ErrorAppletWindow msgDialog = new(_parent, buttons, message)
{
Title = title,
WindowStartupLocation = WindowStartupLocation.CenterScreen,
Width = 400
Title = title, WindowStartupLocation = WindowStartupLocation.CenterScreen, Width = 400
};

object response = await msgDialog.Run();
Expand All @@ -249,7 +258,9 @@ public bool DisplayErrorAppletDialog(string title, string message, string[] butt
{
dialogCloseEvent.Set();

await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogErrorAppletErrorExceptionMessage, ex));
await ContentDialogHelper.CreateErrorDialog(
LocaleManager.Instance.UpdateAndGetDynamicValue(
LocaleKeys.DialogErrorAppletErrorExceptionMessage, ex));
}
});

Expand All @@ -259,38 +270,36 @@ public bool DisplayErrorAppletDialog(string title, string message, string[] butt
}

public IDynamicTextInputHandler CreateDynamicTextInputHandler() => new AvaloniaDynamicTextInputHandler(_parent);

public UserProfile ShowPlayerSelectDialog()
{
UserId selected = UserId.Null;
byte[] defaultGuestImage = EmbeddedResources.Read("Ryujinx.HLE/HOS/Services/Account/Acc/GuestUserImage.jpg");
UserProfile guest = new(new UserId("00000000000000000000000000000080"), "Guest", defaultGuestImage);

ManualResetEvent dialogCloseEvent = new(false);

Dispatcher.UIThread.InvokeAsync(async () =>
{
ObservableCollection<BaseModel> profiles = [];
NavigationDialogHost nav = new();

_parent.AccountManager.GetAllUsers()
.OrderBy(x => x.Name)
.ForEach(profile => profiles.Add(new Models.UserProfile(profile, nav)));

profiles.Add(new Models.UserProfile(guest, nav));
UserSelectorDialogViewModel viewModel = new()
ProfileSelectorDialogViewModel viewModel = new()
{
Profiles = profiles,
SelectedUserId = _parent.AccountManager.LastOpenedUser.UserId
Profiles = profiles, SelectedUserId = _parent.AccountManager.LastOpenedUser.UserId
};
UserSelectorDialog content = new(viewModel);
(selected, _) = await UserSelectorDialog.ShowInputDialog(content);

(selected, _) = await ProfileSelectorDialog.ShowInputDialog(viewModel);

dialogCloseEvent.Set();
});

dialogCloseEvent.WaitOne();

UserProfile profile = _parent.AccountManager.LastOpenedUser;
if (selected == guest.UserId)
{
Expand All @@ -311,6 +320,7 @@ public UserProfile ShowPlayerSelectDialog()
}
}
}

return profile;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<UserControl
x:Class="Ryujinx.Ava.UI.Applet.UserSelectorDialog"
x:Class="Ryujinx.Ava.UI.Applet.ProfileSelectorDialog"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -12,9 +12,9 @@
d:DesignWidth="800"
mc:Ignorable="d"
Focusable="True"
x:DataType="viewModels:UserSelectorDialogViewModel">
x:DataType="viewModels:ProfileSelectorDialogViewModel">
<Design.DataContext>
<viewModels:UserSelectorDialogViewModel />
<viewModels:ProfileSelectorDialogViewModel />
</Design.DataContext>

<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

namespace Ryujinx.Ava.UI.Applet
{
public partial class UserSelectorDialog : UserControl, INotifyPropertyChanged
public partial class ProfileSelectorDialog : UserControl
{
public UserSelectorDialogViewModel ViewModel { get; set; }
public ProfileSelectorDialogViewModel ViewModel { get; set; }

public UserSelectorDialog(UserSelectorDialogViewModel viewModel)
public ProfileSelectorDialog(ProfileSelectorDialogViewModel viewModel)
{
DataContext = ViewModel = viewModel;

InitializeComponent();
ViewModel = viewModel;
DataContext = ViewModel;
}

private void Grid_PointerEntered(object sender, PointerEventArgs e)
Expand Down Expand Up @@ -54,7 +54,7 @@ private void ProfilesList_SelectionChanged(object sender, SelectionChangedEventA
if (ViewModel.Profiles[selectedIndex] is UserProfile userProfile)
{
ViewModel.SelectedUserId = userProfile.UserId;
Logger.Info?.Print(LogClass.UI, $"Selected user: {userProfile.UserId}");
Logger.Info?.Print(LogClass.UI, $"Selected: {userProfile.UserId}", "ProfileSelector");

ObservableCollection<BaseModel> newProfiles = [];

Expand All @@ -79,43 +79,40 @@ private void ProfilesList_SelectionChanged(object sender, SelectionChangedEventA
}
}

public static async Task<(UserId Id, bool Result)> ShowInputDialog(UserSelectorDialog content)
public static async Task<(UserId Id, bool Result)> ShowInputDialog(ProfileSelectorDialogViewModel viewModel)
{
ContentDialog contentDialog = new()
{
Title = LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle],
PrimaryButtonText = LocaleManager.Instance[LocaleKeys.Continue],
SecondaryButtonText = string.Empty,
CloseButtonText = LocaleManager.Instance[LocaleKeys.Cancel],
Content = content,
Content = new ProfileSelectorDialog(viewModel),
Padding = new Thickness(0)
};

UserId result = UserId.Null;
bool input = false;

contentDialog.Closed += Handler;

await ContentDialogHelper.ShowAsync(contentDialog);

return (result, input);

void Handler(ContentDialog sender, ContentDialogClosedEventArgs eventArgs)
{
if (eventArgs.Result == ContentDialogResult.Primary)
{
if (contentDialog.Content is UserSelectorDialog view)
{
result = view.ViewModel.SelectedUserId;
input = true;
}
result = viewModel.SelectedUserId;
input = true;
}
else
{
result = UserId.Null;
input = false;
}
}

contentDialog.Closed += Handler;

await ContentDialogHelper.ShowAsync(contentDialog);

return (result, input);
}
}
}
6 changes: 3 additions & 3 deletions src/Ryujinx/UI/ViewModels/AmiiboWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private async Task<AmiiboJson> GetMostRecentAmiiboListOrDefaultJson()
Logger.Error?.Print(LogClass.Application, $"Couldn't get valid amiibo data: {exception}");

// Neither local or remote files are valid JSON, close window.
ShowInfoDialog();
await ShowInfoDialog();
Close();
}
else if (!remoteIsValid)
Expand All @@ -273,7 +273,7 @@ private async Task<AmiiboJson> GetMostRecentAmiiboListOrDefaultJson()

// Only the local file is valid, the local one should be used
// but the user should be warned.
ShowInfoDialog();
await ShowInfoDialog();
}
}

Expand Down Expand Up @@ -525,7 +525,7 @@ private void ResetAmiiboPreview()
AmiiboImage = bitmap;
}

private static async void ShowInfoDialog()
private static async Task ShowInfoDialog()
{
await ContentDialogHelper.CreateInfoDialog(LocaleManager.Instance[LocaleKeys.DialogAmiiboApiTitle],
LocaleManager.Instance[LocaleKeys.DialogAmiiboApiConnectErrorMessage],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Ryujinx.Ava.UI.ViewModels
{
public partial class UserSelectorDialogViewModel : BaseModel
public partial class ProfileSelectorDialogViewModel : BaseModel
{

[ObservableProperty] private UserId _selectedUserId;
Expand Down
Loading

0 comments on commit 22299e6

Please sign in to comment.