Beispiel #1
0
        /// <summary>
        /// Set inputs in specified <see cref="Joypad"/> to specified player
        /// </summary>
        /// <param name="player">Player (one based) whom inputs must be set</param>
        /// <param name="joypad"><see cref="Joypad"/> with inputs</param>
        /// <exception cref="IndexOutOfRangeException">Raised when you specify a player less than 1 or greater than maximum allows (see SystemInfo class to get this information)</exception>
        /// <remarks>Still have some strange behaviour with multiple inputs; so this feature is still in beta</remarks>
        public static void SetInput(int player, Joypad joypad)
        {
            if (!1.RangeTo(RunningSystem.MaxControllers).Contains(player))
            {
                throw new IndexOutOfRangeException($"{RunningSystem.DisplayName} does not support {player} controller(s)");
            }

            if (joypad.Inputs == 0)
            {
                Global.InputManager.AutofireStickyXorAdapter.ClearStickies();
            }
            else
            {
                foreach (var button in JoypadButtonsArray.Where(button => joypad.Inputs.HasFlag(button)))
                {
                    Global.InputManager.AutofireStickyXorAdapter.SetSticky(
                        RunningSystem == SystemInfo.GB
                                                        ? $"{JoypadConverter.ConvertBack(button, RunningSystem)}"
                                                        : $"P{player} {JoypadConverter.ConvertBack(button, RunningSystem)}",
                        isSticky: true
                        );
                }
            }

#if false // Using this breaks joypad usage (even in UI); have to figure out why
            if ((RunningSystem.AvailableButtons & JoypadButton.AnalogStick) == JoypadButton.AnalogStick)
            {
                for (var i = 1; i <= RunningSystem.MaxControllers; i++)
                {
                    Global.InputManager.AutofireStickyXorAdapter.SetAxis($"P{i} X Axis", _allJoyPads[i - 1].AnalogX);
                    Global.InputManager.AutofireStickyXorAdapter.SetAxis($"P{i} Y Axis", _allJoyPads[i - 1].AnalogY);
                }
            }
#endif
        }
        private void ExecCommand(Command cmd)
        {
            if (this.checkBoxSaveState.Checked)
            {
                ClientApi.SaveState(SaveStateName);
            }

            for (int i = 0; i < cmd.ButtonPresses.Length; i++)
            {
                for (int f = 0; f < cmd.ButtonPresses[i].Frames; f++)
                {
                    this.AddButtons(cmd.ButtonPresses[i].Buttons);
                    ClientApi.DoFrameAdvance();
                }
            }

            Joypad controller = ClientApi.GetInput(1);

            controller.ClearInputs();
            ClientApi.SetInput(1, controller);
        }
        private void button3_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 600; i++)
            {
                if (i % 60 == 0)
                {
                    Joypad j1 = ClientApi.GetInput(1);
                    j1.AddInput(JoypadButton.A);
                    ClientApi.SetInput(1, j1);

                    ClientApi.DoFrameAdvance();

                    j1.RemoveInput(JoypadButton.A);
                    ClientApi.SetInput(1, j1);
                    ClientApi.DoFrameAdvance();
                }
                ClientApi.DoFrameAdvance();
            }
            Joypad j = ClientApi.GetInput(1);

            j.ClearInputs();
            ClientApi.SetInput(1, j);
        }
        void AddButtons(SnesButtons buttons)
        {
            Joypad controller = ClientApi.GetInput(1);

            controller.ClearInputs();
            ClientApi.SetInput(1, controller);

            // D Pad
            if (buttons.HasFlag(SnesButtons.Left))
            {
                controller.AddInput(JoypadButton.Left);
            }
            if (buttons.HasFlag(SnesButtons.Right))
            {
                controller.AddInput(JoypadButton.Right);
            }
            if (buttons.HasFlag(SnesButtons.Down))
            {
                controller.AddInput(JoypadButton.Down);
            }
            if (buttons.HasFlag(SnesButtons.Up))
            {
                controller.AddInput(JoypadButton.Up);
            }

            // Toward/Away
            if (buttons.HasFlag(SnesButtons.Toward))
            {
                controller.AddInput(this.radioButtonLeft.Checked ? JoypadButton.Left : JoypadButton.Right);
            }
            if (buttons.HasFlag(SnesButtons.Away))
            {
                controller.AddInput(this.radioButtonLeft.Checked ? JoypadButton.Right : JoypadButton.Left);
            }

            // Face Buttons
            if (buttons.HasFlag(SnesButtons.A))
            {
                controller.AddInput(JoypadButton.A);
            }
            if (buttons.HasFlag(SnesButtons.B))
            {
                controller.AddInput(JoypadButton.B);
            }
            if (buttons.HasFlag(SnesButtons.X))
            {
                controller.AddInput(JoypadButton.X);
            }
            if (buttons.HasFlag(SnesButtons.Y))
            {
                controller.AddInput(JoypadButton.Y);
            }

            // S/s
            if (buttons.HasFlag(SnesButtons.Select))
            {
                controller.AddInput(JoypadButton.Select);
            }
            if (buttons.HasFlag(SnesButtons.Start))
            {
                controller.AddInput(JoypadButton.Start);
            }

            // Shoulder buttons
            if (buttons.HasFlag(SnesButtons.L))
            {
                controller.AddInput(JoypadButton.L);
            }
            if (buttons.HasFlag(SnesButtons.R))
            {
                controller.AddInput(JoypadButton.R);
            }

            if (this.checkBoxStrafe.Checked)
            {
                controller.AddInput(JoypadButton.R);
            }

            ClientApi.SetInput(1, controller);
        }