Example #1
0
        private bool CheckDownButton(int deviceNumber, InputButton button)
        {
            if (this.devices == null)
            {
                return(false);
            }

            List <InputTrigger> triggers = this.devices.GetTriggers(deviceNumber, button);

            if (triggers == null || this.settingsShown)
            {
                return(false);
            }

            foreach (InputTrigger trigger in triggers)
            {
                if (trigger is KeyboardInputTrigger)
                {
                    if (this.keyboardInputEnabled)
                    {
                        if (JohnnyInputPlugin.IsKeyboardButtonDown(((KeyboardInputTrigger)trigger).Key))
                        {
                            return(true);
                        }
                    }
                }
                else if (trigger is JoystickTrigger)
                {
                    var joyTrigger = (JoystickTrigger)trigger;
                    if (this.joyChecker.CheckTrigger(joyTrigger))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #2
0
        private void JoystickWatchTimer_Tick(object sender, EventArgs e)
        {
            JoystickTrigger newTrigger      = this.joyWatcher.WatchForTrigger();
            bool            newTriggerFound = (newTrigger != null && !newTrigger.Equals(lastResult));

            lastResult = newTrigger;

            List <InputButton> glowButtons = null;

            if (this.isEditingButton)
            {
                if (newTriggerFound)
                {
                    this.DoStopEditButton(newTrigger);
                }
            }
            else
            {
                // If we're not editing, we can show fun glowy effects!
                this.joyChecker.UpdateValueCache();
                glowButtons = new List <InputButton>();

                InputBindingDevice currentDevice = null;
                if (this.deviceNumber >= 0 && this.devices.Count > this.deviceNumber)
                {
                    currentDevice = this.devices[this.deviceNumber];
                }

                if (currentDevice != null)
                {
                    var buttons = Enum.GetValues(typeof(InputButton));
                    foreach (var buttonEnum in buttons)
                    {
                        var button = (InputButton)buttonEnum;
                        List <InputTrigger> triggers = this.devices.GetTriggers(deviceNumber, button);
                        foreach (var trigger in triggers)
                        {
                            bool triggerHit = false;

                            if (trigger is KeyboardInputTrigger)
                            {
                                triggerHit = JohnnyInputPlugin.IsKeyboardButtonDown(((KeyboardInputTrigger)trigger).Key);
                            }
                            else if (trigger is JoystickTrigger)
                            {
                                triggerHit = this.joyChecker.CheckTrigger((JoystickTrigger)trigger);
                            }

                            if (triggerHit)
                            {
                                glowButtons.Add(button);
                                break;
                            }
                        }
                    }
                }

                if (glowButtons.Count == 0)
                {
                    glowButtons = null;
                }
            }
            this.controllerPreview.SetGlowingButtons(glowButtons);
        }