aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx/UI/Views/Input/MotionInputView.axaml.cs
blob: 1b340752b1c5d3deeac35eb7d043a171f2fac96d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using Avalonia.Controls;
using FluentAvalonia.UI.Controls;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Models;
using Ryujinx.Ava.UI.ViewModels;
using Ryujinx.Common.Configuration.Hid.Controller;
using System.Threading.Tasks;

namespace Ryujinx.Ava.UI.Views.Input
{
    public partial class MotionInputView : UserControl
    {
        private readonly MotionInputViewModel _viewModel;

        public MotionInputView()
        {
            InitializeComponent();
        }

        public MotionInputView(ControllerInputViewModel viewModel)
        {
            var config = viewModel.Configuration as InputConfiguration<GamepadInputId, StickInputId>;

            _viewModel = new MotionInputViewModel
            {
                Slot = config.Slot,
                AltSlot = config.AltSlot,
                DsuServerHost = config.DsuServerHost,
                DsuServerPort = config.DsuServerPort,
                MirrorInput = config.MirrorInput,
                Sensitivity = config.Sensitivity,
                GyroDeadzone = config.GyroDeadzone,
                EnableCemuHookMotion = config.EnableCemuHookMotion,
            };

            InitializeComponent();
            DataContext = _viewModel;
        }

        public static async Task Show(ControllerInputViewModel viewModel)
        {
            MotionInputView content = new(viewModel);

            ContentDialog contentDialog = new()
            {
                Title = LocaleManager.Instance[LocaleKeys.ControllerMotionTitle],
                PrimaryButtonText = LocaleManager.Instance[LocaleKeys.ControllerSettingsSave],
                SecondaryButtonText = "",
                CloseButtonText = LocaleManager.Instance[LocaleKeys.ControllerSettingsClose],
                Content = content,
            };
            contentDialog.PrimaryButtonClick += (sender, args) =>
            {
                var config = viewModel.Configuration as InputConfiguration<GamepadInputId, StickInputId>;
                config.Slot = content._viewModel.Slot;
                config.Sensitivity = content._viewModel.Sensitivity;
                config.GyroDeadzone = content._viewModel.GyroDeadzone;
                config.AltSlot = content._viewModel.AltSlot;
                config.DsuServerHost = content._viewModel.DsuServerHost;
                config.DsuServerPort = content._viewModel.DsuServerPort;
                config.EnableCemuHookMotion = content._viewModel.EnableCemuHookMotion;
                config.MirrorInput = content._viewModel.MirrorInput;
            };

            await contentDialog.ShowAsync();
        }
    }
}