Remove ambigious object

This commit is contained in:
Isaac Marovitz 2023-09-19 10:50:01 -04:00 committed by Isaac Marovitz
parent c7f52388c9
commit a0a74d3d10
7 changed files with 111 additions and 69 deletions

View file

@ -1,14 +1,8 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Data;
using Avalonia.LogicalTree;
using Avalonia.Threading;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Input;
using Ryujinx.Input.Assigner;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace Ryujinx.Ava.UI.Helpers
@ -19,13 +13,13 @@ namespace Ryujinx.Ava.UI.Helpers
{
public ToggleButton Button { get; }
public bool IsAssigned { get; }
public object Key { get; }
public ButtonValue? ButtonValue { get; }
public ButtonAssignedEventArgs(ToggleButton button, bool isAssigned, object key)
public ButtonAssignedEventArgs(ToggleButton button, bool isAssigned, ButtonValue? buttonValue)
{
Button = button;
IsAssigned = isAssigned;
Key = key;
ButtonValue = buttonValue;
}
}
@ -83,7 +77,7 @@ namespace Ryujinx.Ava.UI.Helpers
await Dispatcher.UIThread.InvokeAsync(() =>
{
object pressedButton = assigner.GetPressedButton();
ButtonValue? pressedButton = assigner.GetPressedButton();
if (_shouldUnbind)
{
@ -95,7 +89,7 @@ namespace Ryujinx.Ava.UI.Helpers
ToggledButton.IsChecked = false;
ButtonAssigned?.Invoke(this, new ButtonAssignedEventArgs(ToggledButton, pressedButton != null, pressedButton));
ButtonAssigned?.Invoke(this, new ButtonAssignedEventArgs(ToggledButton, pressedButton.HasValue, pressedButton));
});
}

View file

@ -9,7 +9,6 @@ using Ryujinx.Ava.UI.ViewModels.Input;
using Ryujinx.Common.Configuration.Hid.Controller;
using Ryujinx.Input;
using Ryujinx.Input.Assigner;
using StickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId;
namespace Ryujinx.Ava.UI.Views.Input
{
@ -69,75 +68,76 @@ namespace Ryujinx.Ava.UI.Views.Input
if (e.IsAssigned)
{
var viewModel = (DataContext as ControllerInputViewModel);
var buttonValue = e.ButtonValue.Value;
viewModel.parentModel.IsModified = true;
switch (button.Name)
{
case "ButtonZl":
viewModel.Config.ButtonZl = (GamepadInputId)e.Key;
viewModel.Config.ButtonZl = buttonValue.AsGamepadButtonInputId();
break;
case "ButtonL":
viewModel.Config.ButtonL = (GamepadInputId)e.Key;
viewModel.Config.ButtonL = buttonValue.AsGamepadButtonInputId();
break;
case "ButtonMinus":
viewModel.Config.ButtonMinus = (GamepadInputId)e.Key;
viewModel.Config.ButtonMinus = buttonValue.AsGamepadButtonInputId();
break;
case "LeftStickButton":
viewModel.Config.LeftStickButton = (GamepadInputId)e.Key;
viewModel.Config.LeftStickButton = buttonValue.AsGamepadButtonInputId();
break;
case "LeftJoystick":
viewModel.Config.LeftJoystick = (StickInputId)e.Key;
viewModel.Config.LeftJoystick = buttonValue.AsGamepadStickId();
break;
case "DpadUp":
viewModel.Config.DpadUp = (GamepadInputId)e.Key;
viewModel.Config.DpadUp = buttonValue.AsGamepadButtonInputId();
break;
case "DpadDown":
viewModel.Config.DpadDown = (GamepadInputId)e.Key;
viewModel.Config.DpadDown = buttonValue.AsGamepadButtonInputId();
break;
case "DpadLeft":
viewModel.Config.DpadLeft = (GamepadInputId)e.Key;
viewModel.Config.DpadLeft = buttonValue.AsGamepadButtonInputId();
break;
case "DpadRight":
viewModel.Config.DpadRight = (GamepadInputId)e.Key;
viewModel.Config.DpadRight = buttonValue.AsGamepadButtonInputId();
break;
case "LeftButtonSr":
viewModel.Config.LeftButtonSr = (GamepadInputId)e.Key;
viewModel.Config.LeftButtonSr = buttonValue.AsGamepadButtonInputId();
break;
case "LeftButtonSl":
viewModel.Config.LeftButtonSl = (GamepadInputId)e.Key;
viewModel.Config.LeftButtonSl = buttonValue.AsGamepadButtonInputId();
break;
case "RightButtonSr":
viewModel.Config.RightButtonSr = (GamepadInputId)e.Key;
viewModel.Config.RightButtonSr = buttonValue.AsGamepadButtonInputId();
break;
case "RightButtonSl":
viewModel.Config.RightButtonSl = (GamepadInputId)e.Key;
viewModel.Config.RightButtonSl = buttonValue.AsGamepadButtonInputId();
break;
case "ButtonZr":
viewModel.Config.ButtonZr = (GamepadInputId)e.Key;
viewModel.Config.ButtonZr = buttonValue.AsGamepadButtonInputId();
break;
case "ButtonR":
viewModel.Config.ButtonR = (GamepadInputId)e.Key;
viewModel.Config.ButtonR = buttonValue.AsGamepadButtonInputId();
break;
case "ButtonPlus":
viewModel.Config.ButtonPlus = (GamepadInputId)e.Key;
viewModel.Config.ButtonPlus = buttonValue.AsGamepadButtonInputId();
break;
case "ButtonA":
viewModel.Config.ButtonA = (GamepadInputId)e.Key;
viewModel.Config.ButtonA = buttonValue.AsGamepadButtonInputId();
break;
case "ButtonB":
viewModel.Config.ButtonB = (GamepadInputId)e.Key;
viewModel.Config.ButtonB = buttonValue.AsGamepadButtonInputId();
break;
case "ButtonX":
viewModel.Config.ButtonX = (GamepadInputId)e.Key;
viewModel.Config.ButtonX = buttonValue.AsGamepadButtonInputId();
break;
case "ButtonY":
viewModel.Config.ButtonY = (GamepadInputId)e.Key;
viewModel.Config.ButtonY = buttonValue.AsGamepadButtonInputId();
break;
case "RightStickButton":
viewModel.Config.RightStickButton = (GamepadInputId)e.Key;
viewModel.Config.RightStickButton = buttonValue.AsGamepadButtonInputId();
break;
case "RightJoystick":
viewModel.Config.RightJoystick = (StickInputId)e.Key;
viewModel.Config.RightJoystick = buttonValue.AsGamepadStickId();
break;
}
}

View file

@ -8,7 +8,6 @@ using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.ViewModels.Input;
using Ryujinx.Input;
using Ryujinx.Input.Assigner;
using Key = Ryujinx.Common.Configuration.Hid.Key;
namespace Ryujinx.Ava.UI.Views.Input
{
@ -68,93 +67,94 @@ namespace Ryujinx.Ava.UI.Views.Input
if (e.IsAssigned)
{
var viewModel = (DataContext as KeyboardInputViewModel);
var buttonValue = e.ButtonValue.Value;
viewModel.parentModel.IsModified = true;
switch (button.Name)
{
case "ButtonZl":
viewModel.Config.ButtonZl = (Key)e.Key;
viewModel.Config.ButtonZl = buttonValue.AsKey();
break;
case "ButtonL":
viewModel.Config.ButtonL = (Key)e.Key;
viewModel.Config.ButtonL = buttonValue.AsKey();
break;
case "ButtonMinus":
viewModel.Config.ButtonMinus = (Key)e.Key;
viewModel.Config.ButtonMinus = buttonValue.AsKey();
break;
case "LeftStickButton":
viewModel.Config.LeftStickButton = (Key)e.Key;
viewModel.Config.LeftStickButton = buttonValue.AsKey();
break;
case "LeftStickUp":
viewModel.Config.LeftStickUp = (Key)e.Key;
viewModel.Config.LeftStickUp = buttonValue.AsKey();
break;
case "LeftStickDown":
viewModel.Config.LeftStickDown = (Key)e.Key;
viewModel.Config.LeftStickDown = buttonValue.AsKey();
break;
case "LeftStickRight":
viewModel.Config.LeftStickRight = (Key)e.Key;
viewModel.Config.LeftStickRight = buttonValue.AsKey();
break;
case "LeftStickLeft":
viewModel.Config.LeftStickLeft = (Key)e.Key;
viewModel.Config.LeftStickLeft = buttonValue.AsKey();
break;
case "DpadUp":
viewModel.Config.DpadUp = (Key)e.Key;
viewModel.Config.DpadUp = buttonValue.AsKey();
break;
case "DpadDown":
viewModel.Config.DpadDown = (Key)e.Key;
viewModel.Config.DpadDown = buttonValue.AsKey();
break;
case "DpadLeft":
viewModel.Config.DpadLeft = (Key)e.Key;
viewModel.Config.DpadLeft = buttonValue.AsKey();
break;
case "DpadRight":
viewModel.Config.DpadRight = (Key)e.Key;
viewModel.Config.DpadRight = buttonValue.AsKey();
break;
case "LeftButtonSr":
viewModel.Config.LeftButtonSr = (Key)e.Key;
viewModel.Config.LeftButtonSr = buttonValue.AsKey();
break;
case "LeftButtonSl":
viewModel.Config.LeftButtonSl = (Key)e.Key;
viewModel.Config.LeftButtonSl = buttonValue.AsKey();
break;
case "RightButtonSr":
viewModel.Config.RightButtonSr = (Key)e.Key;
viewModel.Config.RightButtonSr = buttonValue.AsKey();
break;
case "RightButtonSl":
viewModel.Config.RightButtonSl = (Key)e.Key;
viewModel.Config.RightButtonSl = buttonValue.AsKey();
break;
case "ButtonZr":
viewModel.Config.ButtonZr = (Key)e.Key;
viewModel.Config.ButtonZr = buttonValue.AsKey();
break;
case "ButtonR":
viewModel.Config.ButtonR = (Key)e.Key;
viewModel.Config.ButtonR = buttonValue.AsKey();
break;
case "ButtonPlus":
viewModel.Config.ButtonPlus = (Key)e.Key;
viewModel.Config.ButtonPlus = buttonValue.AsKey();
break;
case "ButtonA":
viewModel.Config.ButtonA = (Key)e.Key;
viewModel.Config.ButtonA = buttonValue.AsKey();
break;
case "ButtonB":
viewModel.Config.ButtonB = (Key)e.Key;
viewModel.Config.ButtonB = buttonValue.AsKey();
break;
case "ButtonX":
viewModel.Config.ButtonX = (Key)e.Key;
viewModel.Config.ButtonX = buttonValue.AsKey();
break;
case "ButtonY":
viewModel.Config.ButtonY = (Key)e.Key;
viewModel.Config.ButtonY = buttonValue.AsKey();
break;
case "RightStickButton":
viewModel.Config.RightStickButton = (Key)e.Key;
viewModel.Config.RightStickButton = buttonValue.AsKey();
break;
case "RightStickUp":
viewModel.Config.RightStickUp = (Key)e.Key;
viewModel.Config.RightStickUp = buttonValue.AsKey();
break;
case "RightStickDown":
viewModel.Config.RightStickDown = (Key)e.Key;
viewModel.Config.RightStickDown = buttonValue.AsKey();
break;
case "RightStickRight":
viewModel.Config.RightStickRight = (Key)e.Key;
viewModel.Config.RightStickRight = buttonValue.AsKey();
break;
case "RightStickLeft":
viewModel.Config.RightStickLeft = (Key)e.Key;
viewModel.Config.RightStickLeft = buttonValue.AsKey();
break;
}
}

View file

@ -59,13 +59,13 @@ namespace Ryujinx.Input.Assigner
return _gamepad == null || !_gamepad.IsConnected;
}
public object GetPressedButton()
public ButtonValue? GetPressedButton()
{
IEnumerable<GamepadButtonInputId> pressedButtons = _detector.GetPressedButtons();
if (pressedButtons.Any())
{
return !_forStick ? pressedButtons.First() : ((StickInputId)pressedButtons.First());
return !_forStick ? new(pressedButtons.First()) : new(((StickInputId)pressedButtons.First()));
}
return null;

View file

@ -31,6 +31,6 @@ namespace Ryujinx.Input.Assigner
/// Get the pressed button that was read in <see cref="ReadInput"/> by the button assigner.
/// </summary>
/// <returns>The pressed button that was read</returns>
object GetPressedButton();
ButtonValue? GetPressedButton();
}
}

View file

@ -31,15 +31,15 @@ namespace Ryujinx.Input.Assigner
return _keyboardState.IsPressed(Key.Escape);
}
public object GetPressedButton()
public ButtonValue? GetPressedButton()
{
object keyPressed = null;
ButtonValue? keyPressed = null;
for (Key key = Key.Unknown; key < Key.Count; key++)
{
if (_keyboardState.IsPressed(key))
{
keyPressed = key;
keyPressed = new(key);
break;
}
}

View file

@ -0,0 +1,48 @@
using System.Diagnostics;
namespace Ryujinx.Input
{
public enum ButtonValueType { Key, GamepadButtonInputId, StickId }
public struct ButtonValue
{
public ButtonValueType Type;
public uint RawValue;
public ButtonValue(Key key)
{
Type = ButtonValueType.Key;
RawValue = (uint)key;
}
public ButtonValue(GamepadButtonInputId gamepad)
{
Type = ButtonValueType.GamepadButtonInputId;
RawValue = (uint)gamepad;
}
public ButtonValue(StickInputId stick)
{
Type = ButtonValueType.StickId;
RawValue = (uint)stick;
}
public Common.Configuration.Hid.Key AsKey()
{
Debug.Assert(Type == ButtonValueType.Key);
return (Common.Configuration.Hid.Key)RawValue;
}
public Common.Configuration.Hid.Controller.GamepadInputId AsGamepadButtonInputId()
{
Debug.Assert(Type == ButtonValueType.GamepadButtonInputId);
return (Common.Configuration.Hid.Controller.GamepadInputId)RawValue;
}
public Common.Configuration.Hid.Controller.StickInputId AsGamepadStickId()
{
Debug.Assert(Type == ButtonValueType.StickId);
return (Common.Configuration.Hid.Controller.StickInputId)RawValue;
}
}
}