UI: Add keybinds to useful things

This commit is contained in:
Evan Husted 2024-10-19 16:39:21 -05:00 committed by KeatonTheBot
parent 5ea895ed2e
commit e7e89efb3c
10 changed files with 87 additions and 45 deletions

View file

@ -30,7 +30,7 @@ namespace Ryujinx.Ava.UI.ViewModels
private readonly string _amiiboJsonPath;
private readonly byte[] _amiiboLogoBytes;
private readonly HttpClient _httpClient;
private readonly StyleableWindow _owner;
private readonly AmiiboWindow _owner;
private Bitmap _amiiboImage;
private List<AmiiboApi> _amiiboList;
@ -46,7 +46,7 @@ namespace Ryujinx.Ava.UI.ViewModels
private static readonly AmiiboJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions());
public AmiiboWindowViewModel(StyleableWindow owner, string lastScannedAmiiboId, string titleId)
public AmiiboWindowViewModel(AmiiboWindow owner, string lastScannedAmiiboId, string titleId)
{
_owner = owner;
@ -183,6 +183,22 @@ namespace Ryujinx.Ava.UI.ViewModels
}
}
public void Scan()
{
if (AmiiboSelectedIndex > -1)
{
_owner.ScannedAmiibo = AmiiboList[AmiiboSelectedIndex];
_owner.IsScanned = true;
_owner.Close();
}
}
public void Cancel()
{
_owner.IsScanned = false;
_owner.Close();
}
public void Dispose()
{
GC.SuppressFinalize(this);

View file

@ -156,6 +156,8 @@ namespace Ryujinx.Ava.UI.ViewModels
public IEnumerable<LdnGameData> LastLdnGameData;
public MainWindow Window { get; init; }
internal AppHost AppHost { get; set; }
public MainWindowViewModel()
@ -1782,7 +1784,7 @@ namespace Ryujinx.Ava.UI.ViewModels
public async Task ExitCurrentState()
{
if (WindowState == WindowState.FullScreen)
if (WindowState == MainWindow.FullScreenWindowState)
{
ToggleFullscreen();
}
@ -2097,6 +2099,28 @@ namespace Ryujinx.Ava.UI.ViewModels
}
}
public async Task OpenAmiiboWindow()
{
if (!IsAmiiboRequested)
return;
if (AppHost.Device.System.SearchingForAmiibo(out int deviceId))
{
string titleId = AppHost.Device.Processes.ActiveApplication.ProgramIdText.ToUpper();
AmiiboWindow window = new(ShowAll, LastScannedAmiiboId, titleId);
await window.ShowDialog(Window);
if (window.IsScanned)
{
ShowAll = window.ViewModel.ShowAllAmiibo;
LastScannedAmiiboId = window.ScannedAmiibo.GetId();
AppHost.Device.System.ScanAmiibo(deviceId, LastScannedAmiiboId, window.ViewModel.UseRandomUuid);
}
}
}
public void ToggleFullscreen()
{
@ -2107,7 +2131,7 @@ namespace Ryujinx.Ava.UI.ViewModels
LastFullscreenToggle = Environment.TickCount64;
if (WindowState == WindowState.FullScreen)
if (WindowState is not WindowState.Normal)
{
WindowState = WindowState.Normal;
@ -2118,7 +2142,7 @@ namespace Ryujinx.Ava.UI.ViewModels
}
else
{
WindowState = WindowState.FullScreen;
WindowState = MainWindow.FullScreenWindowState;
if (IsGameRunning)
{
@ -2126,7 +2150,7 @@ namespace Ryujinx.Ava.UI.ViewModels
}
}
IsFullScreen = WindowState == WindowState.FullScreen;
IsFullScreen = WindowState == MainWindow.FullScreenWindowState;
}
public static void SaveConfig()

View file

@ -170,6 +170,7 @@
AttachedToVisualTree="ScanAmiiboMenuItem_AttachedToVisualTree"
Click="OpenAmiiboWindow"
Header="{locale:Locale MenuBarActionsScanAmiibo}"
InputGesture="Ctrl + A"
IsEnabled="{Binding IsAmiiboRequested}" />
<MenuItem
Name="ScanAmiiboMenuItemFromBin"

View file

@ -61,14 +61,21 @@
</Grid.ColumnDefinitions>
<CheckBox Margin="10" Grid.Column="0" VerticalContentAlignment="Center" IsChecked="{Binding ShowAllAmiibo}"
Content="{locale:Locale AmiiboOptionsShowAllLabel}" />
<CheckBox Margin="10" VerticalContentAlignment="Center" Grid.Column="1" IsChecked="{Binding UseRandomUuid}"
<CheckBox HotKey="H"
Margin="10" VerticalContentAlignment="Center" Grid.Column="1"
IsChecked="{Binding UseRandomUuid}"
Content="{locale:Locale AmiiboOptionsUsRandomTagLabel}" />
<Button Grid.Column="3" IsEnabled="{Binding EnableScanning}" Width="80"
Content="{locale:Locale AmiiboScanButtonLabel}" Name="ScanButton"
<Button Grid.Column="3"
IsEnabled="{Binding EnableScanning}"
Width="80"
Name="ScanButton"
HotKey="Return"
Content="{locale:Locale AmiiboScanButtonLabel}"
Click="ScanButton_Click" />
<Button Grid.Column="4" Margin="10,0" Width="80" Content="{locale:Locale InputDialogCancel}"
<Button Grid.Column="4" Margin="10,0" Width="80"
Name="CancelButton"
HotKey="Escape"
Content="{locale:Locale InputDialogCancel}"
Click="CancelButton_Click" />
</Grid>
</Grid>

View file

@ -9,13 +9,11 @@ namespace Ryujinx.Ava.UI.Windows
{
public AmiiboWindow(bool showAll, string lastScannedAmiiboId, string titleId)
{
ViewModel = new AmiiboWindowViewModel(this, lastScannedAmiiboId, titleId)
DataContext = ViewModel = new AmiiboWindowViewModel(this, lastScannedAmiiboId, titleId)
{
ShowAllAmiibo = showAll,
};
DataContext = ViewModel;
InitializeComponent();
Title = $"Ryujinx {Program.Version} - " + LocaleManager.Instance[LocaleKeys.Amiibo];
@ -23,9 +21,7 @@ namespace Ryujinx.Ava.UI.Windows
public AmiiboWindow()
{
ViewModel = new AmiiboWindowViewModel(this, string.Empty, string.Empty);
DataContext = ViewModel;
DataContext = ViewModel = new AmiiboWindowViewModel(this, string.Empty, string.Empty);
InitializeComponent();
@ -37,24 +33,10 @@ namespace Ryujinx.Ava.UI.Windows
public bool IsScanned { get; set; }
public AmiiboApi ScannedAmiibo { get; set; }
public AmiiboWindowViewModel ViewModel { get; set; }
public AmiiboWindowViewModel ViewModel;
private void ScanButton_Click(object sender, RoutedEventArgs e)
{
if (ViewModel.AmiiboSelectedIndex > -1)
{
AmiiboApi amiibo = ViewModel.AmiiboList[ViewModel.AmiiboSelectedIndex];
ScannedAmiibo = amiibo;
IsScanned = true;
Close();
}
}
private void ScanButton_Click(object sender, RoutedEventArgs e) => ViewModel.Scan();
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
IsScanned = false;
Close();
}
private void CancelButton_Click(object sender, RoutedEventArgs e) => ViewModel.Cancel();
}
}

View file

@ -1,4 +1,4 @@
<window:StyleableWindow
<window:StyleableWindow
x:Class="Ryujinx.Ava.UI.Windows.CheatWindow"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@ -109,6 +109,7 @@
Name="SaveButton"
MinWidth="90"
Margin="5"
HotKey="Ctrl+S"
Command="{Binding Save}"
IsVisible="{Binding !NoCheatsFound}">
<TextBlock Text="{locale:Locale SettingsButtonSave}" />
@ -117,6 +118,7 @@
Name="CancelButton"
MinWidth="90"
Margin="5"
HotKey="Escape"
Command="{Binding Close}">
<TextBlock Text="{locale:Locale InputDialogCancel}" />
</Button>

View file

@ -39,6 +39,7 @@
<KeyBinding Gesture="Ctrl+Cmd+F" Command="{Binding ToggleFullscreen}" />
<KeyBinding Gesture="F9" Command="{Binding ToggleDockMode}" />
<KeyBinding Gesture="Escape" Command="{Binding ExitCurrentState}" />
<KeyBinding Gesture="Ctrl+A" Command="{Binding OpenAmiiboWindow}" />
<KeyBinding Gesture="Ctrl+B" Command="{Binding OpenBinFile}" />
</Window.KeyBindings>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

View file

@ -38,7 +38,7 @@ namespace Ryujinx.Ava.UI.Windows
public partial class MainWindow : StyleableWindow
{
internal static MainWindowViewModel MainWindowViewModel { get; private set; }
private bool _isLoading;
private bool _applicationsLoadedOnce;
@ -67,9 +67,20 @@ namespace Ryujinx.Ava.UI.Windows
public readonly double StatusBarHeight;
public readonly double MenuBarHeight;
// The special window decoration from AppWindow in FluentAvalonia is only present on Windows;
// and as such optimizing for the fact that the menu bar and the title bar are the same is only needed on Windows.
// Maximized is considered superior to FullScreen on Windows in this case because you get the benefits of being in full screen,
// while still being able to use the standard 3 window controls in the top right to minimize, make the window smaller, or close the app.
public static readonly WindowState FullScreenWindowState =
OperatingSystem.IsWindows() ? WindowState.Maximized : WindowState.FullScreen;
public MainWindow()
{
ViewModel = new MainWindowViewModel();
DataContext = ViewModel = new MainWindowViewModel
{
Window = this
};
MainWindowViewModel = ViewModel;
@ -220,7 +231,7 @@ namespace Ryujinx.Ava.UI.Windows
ViewModel.ShowContent = true;
ViewModel.IsLoadingIndeterminate = false;
if (startFullscreen && ViewModel.WindowState != WindowState.FullScreen)
if (startFullscreen && ViewModel.WindowState != MainWindow.FullScreenWindowState)
{
ViewModel.ToggleFullscreen();
}
@ -232,7 +243,7 @@ namespace Ryujinx.Ava.UI.Windows
ViewModel.ShowLoadProgress = true;
ViewModel.IsLoadingIndeterminate = true;
if (startFullscreen && ViewModel.WindowState != WindowState.FullScreen)
if (startFullscreen && ViewModel.WindowState != MainWindow.FullScreenWindowState)
{
ViewModel.ToggleFullscreen();
}

View file

@ -14,7 +14,7 @@ namespace Ryujinx.Ava.UI.Windows
{
public partial class ModManagerWindow : UserControl
{
public ModManagerViewModel ViewModel;
public readonly ModManagerViewModel ViewModel;
public ModManagerWindow()
{

View file

@ -10,14 +10,13 @@ namespace Ryujinx.Ava.UI.Windows
{
public partial class SettingsWindow : StyleableWindow
{
internal SettingsViewModel ViewModel { get; set; }
internal readonly SettingsViewModel ViewModel;
public SettingsWindow(VirtualFileSystem virtualFileSystem, ContentManager contentManager)
{
Title = $"Ryujinx {Program.Version} - {LocaleManager.Instance[LocaleKeys.Settings]}";
ViewModel = new SettingsViewModel(virtualFileSystem, contentManager);
DataContext = ViewModel;
DataContext = ViewModel = new SettingsViewModel(virtualFileSystem, contentManager);
ViewModel.CloseWindow += Close;
ViewModel.SaveSettingsEvent += SaveSettings;
@ -28,8 +27,7 @@ namespace Ryujinx.Ava.UI.Windows
public SettingsWindow()
{
ViewModel = new SettingsViewModel();
DataContext = ViewModel;
DataContext = ViewModel = new SettingsViewModel();
InitializeComponent();
Load();