mirror of
https://git.743378673.xyz/MeloNX/MeloNX.git
synced 2025-05-14 08:45:18 +00:00
* So much boilerplate * Slow and steady * Restructure + Ack suggestions * Restructure + Ack suggestions * Restructure * Clean * Propogate those fields i forgot about * It builds * Progress * Almost there * Fix stupid mistake * Fix more stupid mistakes * Actually fix fuck ups * Start localising * r/therestofthefuckingowl * Localise ButtonKeyAssigner * Are you feeling it now mr krabs * We’re done at last * Crimes against code * Try me in the Hague * Please be quiet * Crimes are here to stay * Dispose stuff * Cleanup a couple things * Visual fixes and improvements One weird bug * Fix rebase errors * Fixes * Ack Suggestions Remaining ack suggestions Update src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs Co-authored-by: Ac_K <Acoustik666@gmail.com> Update src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs Co-authored-by: Ac_K <Acoustik666@gmail.com> * Formatting and error More Ava 11-ness Whoops * Code style fixes * Style fixes * Analyzer fix * Remove all ReflectionBindings * Remove ambigious object * Remove redundant property * Old man yells at formatter * r e a d o n l y * Fix profiles * Use new Sliders --------- Co-authored-by: Ac_K <Acoustik666@gmail.com>
103 lines
2.7 KiB
C#
103 lines
2.7 KiB
C#
using Avalonia.Controls.Primitives;
|
|
using Avalonia.Threading;
|
|
using Ryujinx.Input;
|
|
using Ryujinx.Input.Assigner;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Ryujinx.Ava.UI.Helpers
|
|
{
|
|
internal class ButtonKeyAssigner
|
|
{
|
|
internal class ButtonAssignedEventArgs : EventArgs
|
|
{
|
|
public ToggleButton Button { get; }
|
|
public ButtonValue? ButtonValue { get; }
|
|
|
|
public ButtonAssignedEventArgs(ToggleButton button, ButtonValue? buttonValue)
|
|
{
|
|
Button = button;
|
|
ButtonValue = buttonValue;
|
|
}
|
|
}
|
|
|
|
public ToggleButton ToggledButton { get; set; }
|
|
|
|
private bool _isWaitingForInput;
|
|
private bool _shouldUnbind;
|
|
public event EventHandler<ButtonAssignedEventArgs> ButtonAssigned;
|
|
|
|
public ButtonKeyAssigner(ToggleButton toggleButton)
|
|
{
|
|
ToggledButton = toggleButton;
|
|
}
|
|
|
|
public async void GetInputAndAssign(IButtonAssigner assigner, IKeyboard keyboard = null)
|
|
{
|
|
Dispatcher.UIThread.Post(() =>
|
|
{
|
|
ToggledButton.IsChecked = true;
|
|
});
|
|
|
|
if (_isWaitingForInput)
|
|
{
|
|
Dispatcher.UIThread.Post(() =>
|
|
{
|
|
Cancel();
|
|
});
|
|
|
|
return;
|
|
}
|
|
|
|
_isWaitingForInput = true;
|
|
|
|
assigner.Initialize();
|
|
|
|
await Task.Run(async () =>
|
|
{
|
|
while (true)
|
|
{
|
|
if (!_isWaitingForInput)
|
|
{
|
|
return;
|
|
}
|
|
|
|
await Task.Delay(10);
|
|
|
|
assigner.ReadInput();
|
|
|
|
if (assigner.HasAnyButtonPressed() || assigner.ShouldCancel() || (keyboard != null && keyboard.IsPressed(Key.Escape)))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
|
|
await Dispatcher.UIThread.InvokeAsync(() =>
|
|
{
|
|
ButtonValue? pressedButton = assigner.GetPressedButton();
|
|
|
|
if (_shouldUnbind)
|
|
{
|
|
pressedButton = null;
|
|
}
|
|
|
|
_shouldUnbind = false;
|
|
_isWaitingForInput = false;
|
|
|
|
ToggledButton.IsChecked = false;
|
|
|
|
ButtonAssigned?.Invoke(this, new ButtonAssignedEventArgs(ToggledButton, pressedButton));
|
|
|
|
});
|
|
}
|
|
|
|
public void Cancel(bool shouldUnbind = false)
|
|
{
|
|
_isWaitingForInput = false;
|
|
ToggledButton.IsChecked = false;
|
|
_shouldUnbind = shouldUnbind;
|
|
}
|
|
}
|
|
}
|