Formatting and error

More Ava 11-ness

Whoops
This commit is contained in:
Isaac Marovitz 2023-08-12 11:52:46 +01:00 committed by Isaac Marovitz
parent 5e8eedae37
commit 02b355eebf
12 changed files with 260 additions and 258 deletions

View file

@ -1,7 +1,7 @@
using Avalonia; using Avalonia;
using Avalonia.Data;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;
using Avalonia.Data;
using Avalonia.LogicalTree; using Avalonia.LogicalTree;
using Avalonia.Threading; using Avalonia.Threading;
using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Common.Locale;
@ -19,7 +19,7 @@ namespace Ryujinx.Ava.UI.Helpers
{ {
public ToggleButton Button { get; } public ToggleButton Button { get; }
public bool IsAssigned { get; } public bool IsAssigned { get; }
public object Key { get; } public object Key { get; }
public ButtonAssignedEventArgs(ToggleButton button, bool isAssigned, object key) public ButtonAssignedEventArgs(ToggleButton button, bool isAssigned, object key)
{ {
@ -107,4 +107,4 @@ namespace Ryujinx.Ava.UI.Helpers
_shouldUnbind = shouldUnbind; _shouldUnbind = shouldUnbind;
} }
} }
} }

View file

@ -565,7 +565,7 @@ namespace Ryujinx.Ava.UI.Models.Input
} }
else else
{ {
config.Motion = new MotionConfigController config.Motion = new MotionConfigController
{ {
EnableMotion = EnableMotion, EnableMotion = EnableMotion,
MotionBackend = MotionInputBackendType.GamepadDriver, MotionBackend = MotionInputBackendType.GamepadDriver,
@ -577,4 +577,4 @@ namespace Ryujinx.Ava.UI.Models.Input
return config; return config;
} }
} }
} }

View file

@ -419,4 +419,4 @@ namespace Ryujinx.Ava.UI.Models.Input
return config; return config;
} }
} }
} }

View file

@ -81,4 +81,4 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
Image = parentModel.Image; Image = parentModel.Image;
} }
} }
} }

View file

@ -889,4 +889,4 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
AvaloniaKeyboardDriver.Dispose(); AvaloniaKeyboardDriver.Dispose();
} }
} }
} }

View file

@ -70,4 +70,4 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
Image = parentModel.Image; Image = parentModel.Image;
} }
} }
} }

View file

@ -25,8 +25,7 @@ namespace Ryujinx.Ava.UI.Views.Input
{ {
if (visual is ToggleButton button && !(visual is CheckBox)) if (visual is ToggleButton button && !(visual is CheckBox))
{ {
button.Checked += Button_Checked; button.IsCheckedChanged += Button_IsCheckedChanged;
button.Unchecked += Button_Unchecked;
} }
} }
} }
@ -41,129 +40,131 @@ namespace Ryujinx.Ava.UI.Views.Input
} }
} }
private void Button_Checked(object sender, RoutedEventArgs e) private void Button_IsCheckedChanged(object sender, RoutedEventArgs e)
{ {
if (sender is ToggleButton button) if (sender is ToggleButton button)
{ {
if (_currentAssigner != null && button == _currentAssigner.ToggledButton) if ((bool)button.IsChecked)
{ {
return; if (_currentAssigner != null && button == _currentAssigner.ToggledButton)
}
bool isStick = button.Tag != null && button.Tag.ToString() == "stick";
if (_currentAssigner == null && (bool)button.IsChecked)
{
_currentAssigner = new ButtonKeyAssigner(button);
FocusManager.Instance.Focus(this, NavigationMethod.Pointer);
PointerPressed += MouseClick;
IKeyboard keyboard = (IKeyboard)(DataContext as ControllerInputViewModel).parentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations.
IButtonAssigner assigner = CreateButtonAssigner(isStick);
_currentAssigner.ButtonAssigned += (sender, e) =>
{ {
if (e.IsAssigned) return;
}
bool isStick = button.Tag != null && button.Tag.ToString() == "stick";
if (_currentAssigner == null && (bool)button.IsChecked)
{
_currentAssigner = new ButtonKeyAssigner(button);
this.Focus(NavigationMethod.Pointer);
PointerPressed += MouseClick;
IKeyboard keyboard = (IKeyboard)(DataContext as ControllerInputViewModel).parentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations.
IButtonAssigner assigner = CreateButtonAssigner(isStick);
_currentAssigner.ButtonAssigned += (sender, e) =>
{ {
var viewModel = (DataContext as ControllerInputViewModel); if (e.IsAssigned)
viewModel.parentModel.IsModified = true;
switch (button.Name)
{ {
case "ButtonZl": var viewModel = (DataContext as ControllerInputViewModel);
viewModel.Config.ButtonZl = (GamepadInputId)e.Key; viewModel.parentModel.IsModified = true;
break;
case "ButtonL":
viewModel.Config.ButtonL = (GamepadInputId)e.Key;
break;
case "ButtonMinus":
viewModel.Config.ButtonMinus = (GamepadInputId)e.Key;
break;
case "LeftStickButton":
viewModel.Config.LeftStickButton = (GamepadInputId)e.Key;
break;
case "LeftJoystick":
viewModel.Config.LeftJoystick = (StickInputId)e.Key;
break;
case "DpadUp":
viewModel.Config.DpadUp = (GamepadInputId)e.Key;
break;
case "DpadDown":
viewModel.Config.DpadDown = (GamepadInputId)e.Key;
break;
case "DpadLeft":
viewModel.Config.DpadLeft = (GamepadInputId)e.Key;
break;
case "DpadRight":
viewModel.Config.DpadRight = (GamepadInputId)e.Key;
break;
case "LeftButtonSr":
viewModel.Config.LeftButtonSr = (GamepadInputId)e.Key;
break;
case "LeftButtonSl":
viewModel.Config.LeftButtonSl = (GamepadInputId)e.Key;
break;
case "RightButtonSr":
viewModel.Config.RightButtonSr = (GamepadInputId)e.Key;
break;
case "RightButtonSl":
viewModel.Config.RightButtonSl = (GamepadInputId)e.Key;
break;
case "ButtonZr":
viewModel.Config.ButtonZr = (GamepadInputId)e.Key;
break;
case "ButtonR":
viewModel.Config.ButtonR = (GamepadInputId)e.Key;
break;
case "ButtonPlus":
viewModel.Config.ButtonPlus = (GamepadInputId)e.Key;
break;
case "ButtonA":
viewModel.Config.ButtonA = (GamepadInputId)e.Key;
break;
case "ButtonB":
viewModel.Config.ButtonB = (GamepadInputId)e.Key;
break;
case "ButtonX":
viewModel.Config.ButtonX = (GamepadInputId)e.Key;
break;
case "ButtonY":
viewModel.Config.ButtonY = (GamepadInputId)e.Key;
break;
case "RightStickButton":
viewModel.Config.RightStickButton = (GamepadInputId)e.Key;
break;
case "RightJoystick":
viewModel.Config.RightJoystick = (StickInputId)e.Key;
break;
}
}
};
_currentAssigner.GetInputAndAssign(assigner, keyboard); switch (button.Name)
{
case "ButtonZl":
viewModel.Config.ButtonZl = (GamepadInputId)e.Key;
break;
case "ButtonL":
viewModel.Config.ButtonL = (GamepadInputId)e.Key;
break;
case "ButtonMinus":
viewModel.Config.ButtonMinus = (GamepadInputId)e.Key;
break;
case "LeftStickButton":
viewModel.Config.LeftStickButton = (GamepadInputId)e.Key;
break;
case "LeftJoystick":
viewModel.Config.LeftJoystick = (StickInputId)e.Key;
break;
case "DpadUp":
viewModel.Config.DpadUp = (GamepadInputId)e.Key;
break;
case "DpadDown":
viewModel.Config.DpadDown = (GamepadInputId)e.Key;
break;
case "DpadLeft":
viewModel.Config.DpadLeft = (GamepadInputId)e.Key;
break;
case "DpadRight":
viewModel.Config.DpadRight = (GamepadInputId)e.Key;
break;
case "LeftButtonSr":
viewModel.Config.LeftButtonSr = (GamepadInputId)e.Key;
break;
case "LeftButtonSl":
viewModel.Config.LeftButtonSl = (GamepadInputId)e.Key;
break;
case "RightButtonSr":
viewModel.Config.RightButtonSr = (GamepadInputId)e.Key;
break;
case "RightButtonSl":
viewModel.Config.RightButtonSl = (GamepadInputId)e.Key;
break;
case "ButtonZr":
viewModel.Config.ButtonZr = (GamepadInputId)e.Key;
break;
case "ButtonR":
viewModel.Config.ButtonR = (GamepadInputId)e.Key;
break;
case "ButtonPlus":
viewModel.Config.ButtonPlus = (GamepadInputId)e.Key;
break;
case "ButtonA":
viewModel.Config.ButtonA = (GamepadInputId)e.Key;
break;
case "ButtonB":
viewModel.Config.ButtonB = (GamepadInputId)e.Key;
break;
case "ButtonX":
viewModel.Config.ButtonX = (GamepadInputId)e.Key;
break;
case "ButtonY":
viewModel.Config.ButtonY = (GamepadInputId)e.Key;
break;
case "RightStickButton":
viewModel.Config.RightStickButton = (GamepadInputId)e.Key;
break;
case "RightJoystick":
viewModel.Config.RightJoystick = (StickInputId)e.Key;
break;
}
}
};
_currentAssigner.GetInputAndAssign(assigner, keyboard);
}
else
{
if (_currentAssigner != null)
{
ToggleButton oldButton = _currentAssigner.ToggledButton;
_currentAssigner.Cancel();
_currentAssigner = null;
button.IsChecked = false;
}
}
} }
else else
{ {
if (_currentAssigner != null) _currentAssigner?.Cancel();
{ _currentAssigner = null;
ToggleButton oldButton = _currentAssigner.ToggledButton;
_currentAssigner.Cancel();
_currentAssigner = null;
button.IsChecked = false;
}
} }
} }
} }
private void Button_Unchecked(object sender, RoutedEventArgs e)
{
_currentAssigner?.Cancel();
_currentAssigner = null;
}
private void MouseClick(object sender, PointerPressedEventArgs e) private void MouseClick(object sender, PointerPressedEventArgs e)
{ {
bool shouldUnbind = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed; bool shouldUnbind = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed;
@ -189,4 +190,4 @@ namespace Ryujinx.Ava.UI.Views.Input
_currentAssigner = null; _currentAssigner = null;
} }
} }
} }

View file

@ -63,7 +63,7 @@
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Center" VerticalAlignment="Center"
SelectionChanged="PlayerIndexBox_OnSelectionChanged" SelectionChanged="PlayerIndexBox_OnSelectionChanged"
Items="{Binding PlayerIndexes}" ItemsSource="{Binding PlayerIndexes}"
SelectedIndex="{Binding PlayerId}"> SelectedIndex="{Binding PlayerId}">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate> <DataTemplate>
@ -91,14 +91,14 @@
HorizontalAlignment="Left" HorizontalAlignment="Left"
VerticalAlignment="Center" VerticalAlignment="Center"
Text="{locale:Locale ControllerSettingsProfile}" /> Text="{locale:Locale ControllerSettingsProfile}" />
<ui:ComboBox <ui:FAComboBox
Grid.Column="1" Grid.Column="1"
IsEditable="True" IsEditable="True"
Name="ProfileBox" Name="ProfileBox"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Center" VerticalAlignment="Center"
SelectedIndex="0" SelectedIndex="0"
Items="{Binding ProfilesList}" ItemsSource="{Binding ProfilesList}"
Text="{Binding ProfileName}" /> Text="{Binding ProfileName}" />
<Button <Button
Grid.Column="2" Grid.Column="2"
@ -167,7 +167,7 @@
Name="DeviceBox" Name="DeviceBox"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Center" VerticalAlignment="Center"
Items="{Binding DeviceList}" ItemsSource="{Binding DeviceList}"
SelectedIndex="{Binding Device}" /> SelectedIndex="{Binding Device}" />
<Button <Button
Grid.Column="2" Grid.Column="2"
@ -200,7 +200,7 @@
<ComboBox <ComboBox
Grid.Column="1" Grid.Column="1"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
Items="{ReflectionBinding Controllers}" ItemsSource="{ReflectionBinding Controllers}"
SelectedIndex="{ReflectionBinding Controller}"> SelectedIndex="{ReflectionBinding Controller}">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate DataType="models:ControllerModel"> <DataTemplate DataType="models:ControllerModel">
@ -222,4 +222,4 @@
</ContentControl.DataTemplates> </ContentControl.DataTemplates>
</ContentControl> </ContentControl>
</StackPanel> </StackPanel>
</UserControl> </UserControl>

View file

@ -58,4 +58,4 @@ namespace Ryujinx.Ava.UI.Views.Input
ViewModel.Dispose(); ViewModel.Dispose();
} }
} }
} }

View file

@ -24,8 +24,7 @@ namespace Ryujinx.Ava.UI.Views.Input
{ {
if (visual is ToggleButton button && !(visual is CheckBox)) if (visual is ToggleButton button && !(visual is CheckBox))
{ {
button.Checked += Button_Checked; button.IsCheckedChanged += Button_IsCheckedChanged;
button.Unchecked += Button_Unchecked;
} }
} }
} }
@ -40,147 +39,149 @@ namespace Ryujinx.Ava.UI.Views.Input
} }
} }
private void Button_Checked(object sender, RoutedEventArgs e) private void Button_IsCheckedChanged(object sender, RoutedEventArgs e)
{ {
if (sender is ToggleButton button) if (sender is ToggleButton button)
{ {
if (_currentAssigner != null && button == _currentAssigner.ToggledButton) if ((bool)button.IsChecked)
{ {
return; if (_currentAssigner != null && button == _currentAssigner.ToggledButton)
}
bool isStick = button.Tag != null && button.Tag.ToString() == "stick";
if (_currentAssigner == null && (bool)button.IsChecked)
{
_currentAssigner = new ButtonKeyAssigner(button);
FocusManager.Instance.Focus(this, NavigationMethod.Pointer);
PointerPressed += MouseClick;
IKeyboard keyboard = (IKeyboard)(DataContext as KeyboardInputViewModel).parentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations.
IButtonAssigner assigner = CreateButtonAssigner(isStick);
_currentAssigner.ButtonAssigned += (sender, e) =>
{ {
if (e.IsAssigned) return;
}
bool isStick = button.Tag != null && button.Tag.ToString() == "stick";
if (_currentAssigner == null && (bool)button.IsChecked)
{
_currentAssigner = new ButtonKeyAssigner(button);
this.Focus(NavigationMethod.Pointer);
PointerPressed += MouseClick;
IKeyboard keyboard = (IKeyboard)(DataContext as KeyboardInputViewModel).parentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations.
IButtonAssigner assigner = CreateButtonAssigner(isStick);
_currentAssigner.ButtonAssigned += (sender, e) =>
{ {
var viewModel = (DataContext as KeyboardInputViewModel); if (e.IsAssigned)
viewModel.parentModel.IsModified = true;
switch (button.Name)
{ {
case "ButtonZl": var viewModel = (DataContext as KeyboardInputViewModel);
viewModel.Config.ButtonZl = (Key)e.Key; viewModel.parentModel.IsModified = true;
break;
case "ButtonL":
viewModel.Config.ButtonL = (Key)e.Key;
break;
case "ButtonMinus":
viewModel.Config.ButtonMinus = (Key)e.Key;
break;
case "LeftStickButton":
viewModel.Config.LeftStickButton = (Key)e.Key;
break;
case "LeftStickUp":
viewModel.Config.LeftStickUp = (Key)e.Key;
break;
case "LeftStickDown":
viewModel.Config.LeftStickDown = (Key)e.Key;
break;
case "LeftStickRight":
viewModel.Config.LeftStickRight = (Key)e.Key;
break;
case "LeftStickLeft":
viewModel.Config.LeftStickLeft = (Key)e.Key;
break;
case "DpadUp":
viewModel.Config.DpadUp = (Key)e.Key;
break;
case "DpadDown":
viewModel.Config.DpadDown = (Key)e.Key;
break;
case "DpadLeft":
viewModel.Config.DpadLeft = (Key)e.Key;
break;
case "DpadRight":
viewModel.Config.DpadRight = (Key)e.Key;
break;
case "LeftButtonSr":
viewModel.Config.LeftButtonSr = (Key)e.Key;
break;
case "LeftButtonSl":
viewModel.Config.LeftButtonSl = (Key)e.Key;
break;
case "RightButtonSr":
viewModel.Config.RightButtonSr = (Key)e.Key;
break;
case "RightButtonSl":
viewModel.Config.RightButtonSl = (Key)e.Key;
break;
case "ButtonZr":
viewModel.Config.ButtonZr = (Key)e.Key;
break;
case "ButtonR":
viewModel.Config.ButtonR = (Key)e.Key;
break;
case "ButtonPlus":
viewModel.Config.ButtonPlus = (Key)e.Key;
break;
case "ButtonA":
viewModel.Config.ButtonA = (Key)e.Key;
break;
case "ButtonB":
viewModel.Config.ButtonB = (Key)e.Key;
break;
case "ButtonX":
viewModel.Config.ButtonX = (Key)e.Key;
break;
case "ButtonY":
viewModel.Config.ButtonY = (Key)e.Key;
break;
case "RightStickButton":
viewModel.Config.RightStickButton = (Key)e.Key;
break;
case "RightStickUp":
viewModel.Config.RightStickUp = (Key)e.Key;
break;
case "RightStickDown":
viewModel.Config.RightStickDown = (Key)e.Key;
break;
case "RightStickRight":
viewModel.Config.RightStickRight = (Key)e.Key;
break;
case "RightStickLeft":
viewModel.Config.RightStickLeft = (Key)e.Key;
break;
}
}
};
_currentAssigner.GetInputAndAssign(assigner, keyboard); switch (button.Name)
{
case "ButtonZl":
viewModel.Config.ButtonZl = (Key)e.Key;
break;
case "ButtonL":
viewModel.Config.ButtonL = (Key)e.Key;
break;
case "ButtonMinus":
viewModel.Config.ButtonMinus = (Key)e.Key;
break;
case "LeftStickButton":
viewModel.Config.LeftStickButton = (Key)e.Key;
break;
case "LeftStickUp":
viewModel.Config.LeftStickUp = (Key)e.Key;
break;
case "LeftStickDown":
viewModel.Config.LeftStickDown = (Key)e.Key;
break;
case "LeftStickRight":
viewModel.Config.LeftStickRight = (Key)e.Key;
break;
case "LeftStickLeft":
viewModel.Config.LeftStickLeft = (Key)e.Key;
break;
case "DpadUp":
viewModel.Config.DpadUp = (Key)e.Key;
break;
case "DpadDown":
viewModel.Config.DpadDown = (Key)e.Key;
break;
case "DpadLeft":
viewModel.Config.DpadLeft = (Key)e.Key;
break;
case "DpadRight":
viewModel.Config.DpadRight = (Key)e.Key;
break;
case "LeftButtonSr":
viewModel.Config.LeftButtonSr = (Key)e.Key;
break;
case "LeftButtonSl":
viewModel.Config.LeftButtonSl = (Key)e.Key;
break;
case "RightButtonSr":
viewModel.Config.RightButtonSr = (Key)e.Key;
break;
case "RightButtonSl":
viewModel.Config.RightButtonSl = (Key)e.Key;
break;
case "ButtonZr":
viewModel.Config.ButtonZr = (Key)e.Key;
break;
case "ButtonR":
viewModel.Config.ButtonR = (Key)e.Key;
break;
case "ButtonPlus":
viewModel.Config.ButtonPlus = (Key)e.Key;
break;
case "ButtonA":
viewModel.Config.ButtonA = (Key)e.Key;
break;
case "ButtonB":
viewModel.Config.ButtonB = (Key)e.Key;
break;
case "ButtonX":
viewModel.Config.ButtonX = (Key)e.Key;
break;
case "ButtonY":
viewModel.Config.ButtonY = (Key)e.Key;
break;
case "RightStickButton":
viewModel.Config.RightStickButton = (Key)e.Key;
break;
case "RightStickUp":
viewModel.Config.RightStickUp = (Key)e.Key;
break;
case "RightStickDown":
viewModel.Config.RightStickDown = (Key)e.Key;
break;
case "RightStickRight":
viewModel.Config.RightStickRight = (Key)e.Key;
break;
case "RightStickLeft":
viewModel.Config.RightStickLeft = (Key)e.Key;
break;
}
}
};
_currentAssigner.GetInputAndAssign(assigner, keyboard);
}
else
{
if (_currentAssigner != null)
{
ToggleButton oldButton = _currentAssigner.ToggledButton;
_currentAssigner.Cancel();
_currentAssigner = null;
button.IsChecked = false;
}
}
} }
else else
{ {
if (_currentAssigner != null) _currentAssigner?.Cancel();
{ _currentAssigner = null;
ToggleButton oldButton = _currentAssigner.ToggledButton;
_currentAssigner.Cancel();
_currentAssigner = null;
button.IsChecked = false;
}
} }
} }
} }
private void Button_Unchecked(object sender, RoutedEventArgs e)
{
_currentAssigner?.Cancel();
_currentAssigner = null;
}
private void MouseClick(object sender, PointerPressedEventArgs e) private void MouseClick(object sender, PointerPressedEventArgs e)
{ {
bool shouldUnbind = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed; bool shouldUnbind = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed;
@ -206,4 +207,4 @@ namespace Ryujinx.Ava.UI.Views.Input
_currentAssigner = null; _currentAssigner = null;
} }
} }
} }

View file

@ -194,4 +194,4 @@ namespace Ryujinx.Input.Assigner
} }
} }
} }
} }

View file

@ -1227,4 +1227,4 @@ namespace Ryujinx.UI.Windows
Dispose(); Dispose();
} }
} }
} }