コード例 #1
0
ファイル: ControllerWindow.cs プロジェクト: valx76/Ryujinx
        private void ProfileLoad_Activated(object sender, EventArgs args)
        {
            ((ToggleButton)sender).SetStateFlags(0, true);

            if (_inputDevice.ActiveId == "disabled" || _profile.ActiveId == null)
            {
                return;
            }

            InputConfig config = null;
            int         pos    = _profile.Active;

            if (_profile.ActiveId == "default")
            {
                if (_inputDevice.ActiveId.StartsWith("keyboard"))
                {
                    config = new KeyboardConfig
                    {
                        Index          = 0,
                        ControllerType = ControllerType.JoyconPair,
                        LeftJoycon     = new NpadKeyboardLeft
                        {
                            StickUp     = Key.W,
                            StickDown   = Key.S,
                            StickLeft   = Key.A,
                            StickRight  = Key.D,
                            StickButton = Key.F,
                            DPadUp      = Key.Up,
                            DPadDown    = Key.Down,
                            DPadLeft    = Key.Left,
                            DPadRight   = Key.Right,
                            ButtonMinus = Key.Minus,
                            ButtonL     = Key.E,
                            ButtonZl    = Key.Q,
                            ButtonSl    = Key.Unbound,
                            ButtonSr    = Key.Unbound
                        },
                        RightJoycon = new NpadKeyboardRight
                        {
                            StickUp     = Key.I,
                            StickDown   = Key.K,
                            StickLeft   = Key.J,
                            StickRight  = Key.L,
                            StickButton = Key.H,
                            ButtonA     = Key.Z,
                            ButtonB     = Key.X,
                            ButtonX     = Key.C,
                            ButtonY     = Key.V,
                            ButtonPlus  = Key.Plus,
                            ButtonR     = Key.U,
                            ButtonZr    = Key.O,
                            ButtonSl    = Key.Unbound,
                            ButtonSr    = Key.Unbound
                        }
                    };
                }
                else if (_inputDevice.ActiveId.StartsWith("controller"))
                {
                    config = new ControllerConfig
                    {
                        Index            = 0,
                        ControllerType   = ControllerType.ProController,
                        DeadzoneLeft     = 0.1f,
                        DeadzoneRight    = 0.1f,
                        TriggerThreshold = 0.5f,
                        LeftJoycon       = new NpadControllerLeft
                        {
                            StickX       = ControllerInputId.Axis0,
                            StickY       = ControllerInputId.Axis1,
                            StickButton  = ControllerInputId.Button8,
                            DPadUp       = ControllerInputId.Hat0Up,
                            DPadDown     = ControllerInputId.Hat0Down,
                            DPadLeft     = ControllerInputId.Hat0Left,
                            DPadRight    = ControllerInputId.Hat0Right,
                            ButtonMinus  = ControllerInputId.Button6,
                            ButtonL      = ControllerInputId.Button4,
                            ButtonZl     = ControllerInputId.Axis2,
                            ButtonSl     = ControllerInputId.Unbound,
                            ButtonSr     = ControllerInputId.Unbound,
                            InvertStickX = false,
                            InvertStickY = false
                        },
                        RightJoycon = new NpadControllerRight
                        {
                            StickX       = ControllerInputId.Axis3,
                            StickY       = ControllerInputId.Axis4,
                            StickButton  = ControllerInputId.Button9,
                            ButtonA      = ControllerInputId.Button1,
                            ButtonB      = ControllerInputId.Button0,
                            ButtonX      = ControllerInputId.Button3,
                            ButtonY      = ControllerInputId.Button2,
                            ButtonPlus   = ControllerInputId.Button7,
                            ButtonR      = ControllerInputId.Button5,
                            ButtonZr     = ControllerInputId.Axis5,
                            ButtonSl     = ControllerInputId.Unbound,
                            ButtonSr     = ControllerInputId.Unbound,
                            InvertStickX = false,
                            InvertStickY = false
                        }
                    };
                }
            }
            else
            {
                string path = System.IO.Path.Combine(GetProfileBasePath(), _profile.ActiveId);

                if (!File.Exists(path))
                {
                    if (pos >= 0)
                    {
                        _profile.Remove(pos);
                    }

                    return;
                }

                try
                {
                    using (Stream stream = File.OpenRead(path))
                    {
                        config = JsonHelper.Deserialize <ControllerConfig>(stream);
                    }
                }
                catch (JsonException)
                {
                    try
                    {
                        using (Stream stream = File.OpenRead(path))
                        {
                            config = JsonHelper.Deserialize <KeyboardConfig>(stream);
                        }
                    }
                    catch { }
                }
            }

            SetValues(config);
        }