misc: Tweak NullReferenceException fixes

This commit is contained in:
KeatonTheBot
2025-10-31 01:04:00 -05:00
parent e3ee28605d
commit a6c0eabf49
23 changed files with 143 additions and 128 deletions
@@ -9,6 +9,7 @@ using Ryujinx.Ava.UI.ViewModels.Input;
using Ryujinx.Common.Configuration.Hid.Controller;
using Ryujinx.Input;
using Ryujinx.Input.Assigner;
using System;
using StickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId;
namespace Ryujinx.Ava.UI.Views.Input
@@ -68,14 +69,12 @@ namespace Ryujinx.Ava.UI.Views.Input
if (_changeSlider != -1.0f && _changeSlider != (float)check.Value)
{
if (DataContext is ControllerInputViewModel viewModel)
{
viewModel.ParentModel.IsModified = true;
}
var viewModel = (DataContext as ControllerInputViewModel);
if (viewModel != null)
{
viewModel.ParentModel.IsModified = true;
}
_changeSlider = (float)check.Value;
_changeSlider = (float)check.Value;
}
}
}
@@ -119,7 +118,10 @@ namespace Ryujinx.Ava.UI.Views.Input
PointerPressed += MouseClick;
var viewModel = (DataContext as ControllerInputViewModel);
if (DataContext is not ControllerInputViewModel viewModel)
{
return;
}
IKeyboard keyboard = (IKeyboard)viewModel.ParentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations.
IButtonAssigner assigner = CreateButtonAssigner(isStick);
@@ -234,13 +236,14 @@ namespace Ryujinx.Ava.UI.Views.Input
private IButtonAssigner CreateButtonAssigner(bool forStick)
{
IButtonAssigner assigner;
if (DataContext is not ControllerInputViewModel controllerInputViewModel)
{
return null;
}
var controllerInputViewModel = DataContext as ControllerInputViewModel;
assigner = new GamepadButtonAssigner(
controllerInputViewModel?.ParentModel.SelectedGamepad,
(controllerInputViewModel.ParentModel.Config as StandardControllerInputConfig).TriggerThreshold,
IButtonAssigner assigner = new GamepadButtonAssigner(
controllerInputViewModel.ParentModel.SelectedGamepad,
((StandardControllerInputConfig)controllerInputViewModel.ParentModel.Config).TriggerThreshold,
forStick);
return assigner;
@@ -36,7 +36,7 @@ namespace Ryujinx.Ava.UI.Views.Settings
{
base.OnPointerReleased(e);
if (!_currentAssigner?.ToggledButton?.IsPointerOver ?? false)
if (!_currentAssigner?.ToggledButton.IsPointerOver ?? false)
{
_currentAssigner.Cancel();
}
@@ -63,25 +63,27 @@ namespace Ryujinx.Ava.UI.Views.User
private async void Import_OnClick(object sender, RoutedEventArgs e)
{
var window = this.GetVisualRoot() as Window;
var result = await window?.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
if (this.GetVisualRoot() is Window window)
{
AllowMultiple = false,
FileTypeFilter = new List<FilePickerFileType>
var result = await window.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
new(LocaleManager.Instance[LocaleKeys.AllSupportedFormats])
AllowMultiple = false,
FileTypeFilter = new List<FilePickerFileType>
{
Patterns = ["*.jpg", "*.jpeg", "*.png", "*.bmp"],
AppleUniformTypeIdentifiers = ["public.jpeg", "public.png", "com.microsoft.bmp"],
MimeTypes = ["image/jpeg", "image/png", "image/bmp"],
new(LocaleManager.Instance[LocaleKeys.AllSupportedFormats])
{
Patterns = ["*.jpg", "*.jpeg", "*.png", "*.bmp"],
AppleUniformTypeIdentifiers = ["public.jpeg", "public.png", "com.microsoft.bmp"],
MimeTypes = ["image/jpeg", "image/png", "image/bmp"],
},
},
},
});
});
if (result.Count > 0)
{
_profile.Image = ProcessProfileImage(File.ReadAllBytes(result[0].Path.LocalPath));
_parent.GoBack();
if (result.Count > 0)
{
_profile.Image = ProcessProfileImage(File.ReadAllBytes(result[0].Path.LocalPath));
_parent.GoBack();
}
}
}
@@ -42,7 +42,10 @@ namespace Ryujinx.Ava.UI.Views.User
if (arg.NavigationMode == NavigationMode.Back)
{
((ContentDialog)_parent.Parent).Title = LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle];
if (_parent.Parent != null)
{
((ContentDialog)_parent.Parent).Title = LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle];
}
}
DataContext = ViewModel;