예제 #1
0
 private bool SetTypeXbox(ButtonAlias button)
 {
     button.Pressed = PressType.XboxController;
     //_pressedButtons.Add(button.GetAssociation());
     _buttonLocks.Add(button.GetAssociation(), button);
     return(true);
 }
예제 #2
0
 private bool buttonNotHeldEnough(ButtonAlias button)
 {
     if (button.GetHoldable() > 0 && _holdTimes.ContainsKey(button.GetAssociation()) && _holdTimes[button.GetAssociation()].CompareTo(SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds) > 0 && !_repeatHoldTimes.ContainsKey(button.GetAssociation()))
     {
         return(false);
     }
     return(true);
 }
예제 #3
0
 private bool isHoldable(ButtonAlias button)
 {
     if (button.GetHoldable() == 0)
     {
         return(true);
     }
     return(false);
 }
예제 #4
0
 private bool buttonNotHeldLongEnough(ButtonAlias button)
 {
     if (!_repeatHoldTimes.ContainsKey(button.GetAssociation()) && button.GetHoldableRepeat() >= 0)
     {
         _repeatHoldTimes.Add(button.GetAssociation(), SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds + button.GetHoldableRepeat());
         return(false);
     }
     return(true);
 }
예제 #5
0
 private bool isHoldableButNotHeldEnough(ButtonAlias button)
 {
     if (button.GetHoldable() > 0 && !_holdTimes.ContainsKey(button.GetAssociation()))
     {
         _holdTimes.Add(button.GetAssociation(), SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds + button.GetHoldable());
         return(false);
     }
     return(true);
 }
예제 #6
0
 private bool checkCommandButtonUp(ButtonAlias button)
 {
     if (_gamePadState.IsButtonUp(button.GetButton()) && _buttonLocks.ContainsValue(button))
     {
         RemoveLocksAndHolds(button);
         return(false);
     }
     return(true);
 }
예제 #7
0
 private bool setupNewKeyAssociation(ButtonAlias button)
 {
     if (_keyState.IsKeyDown(button.GetKey()) && !_buttonLocks.ContainsKey(button.GetAssociation()))
     {
         button.Pressed = PressType.Key;
         _buttonLocks.Add(button.GetAssociation(), button);
         return(true);
     }
     return(false);
 }
예제 #8
0
 private bool buttonHeldEnoughRepeat(ButtonAlias button)
 {
     if (_repeatHoldTimes.ContainsKey(button.GetAssociation()) && _repeatHoldTimes[button.GetAssociation()].CompareTo(SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds) < 0)
     {
         _repeatHoldTimes.Remove(button.GetAssociation());
         _advances++;
         return(true);
     }
     return(false);
 }
예제 #9
0
 private bool allowOneButtonPress(ButtonAlias button)
 {
     if (_holdTimes.ContainsKey(button.GetAssociation()) && _holdTimes[button.GetAssociation()].CompareTo(SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds) < 0 && !_repeatHoldTimes.ContainsKey(button.GetAssociation()) && button.GetHoldableRepeat() >= 0)
     {
         // Remove, re-add, rinse, repeat!
         _repeatHoldTimes.Add(button.GetAssociation(), SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds + button.GetHoldableRepeat());
         return(false);
     }
     return(true);
 }
예제 #10
0
 private void RemoveLocksAndHolds(ButtonAlias button)
 {
     if (_holdTimes.ContainsKey(button.GetAssociation()) && button.GetHoldable() > 0 && _holdTimes[button.GetAssociation()].CompareTo(SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds) < 0 && !_repeatHoldTimes.ContainsKey(button.GetAssociation()))
     {
         _holdTimes.Remove(button.GetAssociation());
         _buttonLocks.Remove(button.GetAssociation());
     }
     else if (_repeatHoldTimes.ContainsKey(button.GetAssociation()) && _repeatHoldTimes[button.GetAssociation()].CompareTo(SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds) < 0)
     {
         _repeatHoldTimes.Remove(button.GetAssociation());
         _buttonLocks.Remove(button.GetAssociation());
     }
     else if (!_holdTimes.ContainsKey(button.GetAssociation()))
     {
         _buttonLocks.Remove(button.GetAssociation());
     }
 }
예제 #11
0
 private bool checkCommandKeyUp(ButtonAlias button)
 {
     if (_keyState.IsKeyUp(button.GetKey()) && _buttonLocks.ContainsValue(button))
     {
         if (_holdTimes.ContainsKey(button.GetAssociation()) && button.GetHoldable() > 0 && _holdTimes[button.GetAssociation()].CompareTo(SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds) < 0 && !_repeatHoldTimes.ContainsKey(button.GetAssociation()))
         {
             _holdTimes.Remove(button.GetAssociation());
             _buttonLocks.Remove(button.GetAssociation());
         }
         else if (_repeatHoldTimes.ContainsKey(button.GetAssociation()) && _repeatHoldTimes[button.GetAssociation()].CompareTo(SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds) < 0)
         {
             _repeatHoldTimes.Remove(button.GetAssociation());
         }
         else if (!_holdTimes.ContainsKey(button.GetAssociation()))
         {
             _buttonLocks.Remove(button.GetAssociation());
         }
         return(false);
     }
     return(true);
 }
예제 #12
0
        public void TestAddingToSuperButtonArray()
        {
            var handler = new InputHandler();
            //var keystate = new KeyboardState();
            var aliasAButton = new ButtonAlias(Buttons.A, -1, -1, "TestAlias");
            var aliasAKey = new ButtonAlias(Keys.Up, -1, -1, "TestAlias");
            var dictionary = new Dictionary<ButtonAction, List<ButtonAlias>>();
            var listOfAliases = new List<ButtonAlias> { aliasAButton, aliasAKey };
            dictionary.Add(ButtonAction.MenuUp, listOfAliases);

            var buttonsetter = typeof(InputHandler).GetField("_superButton", BindingFlags.Static | BindingFlags.NonPublic);
            buttonsetter.SetValue(handler, dictionary);

            var keystate = typeof(InputHandler).GetField("_keyState", BindingFlags.NonPublic | BindingFlags.Instance);
            var keystatev = keystate.GetValue(handler);

            var test = typeof(KeyboardState).GetField("currentState1", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
            test.SetValue(keystatev, UInt32.Parse("64"));

            keystate.SetValue(handler, keystatev);
            Assert.IsTrue(handler.IsButtonPressed(ButtonAction.MenuUp));
        }
예제 #13
0
        private bool checkButtonDynamics(ButtonAlias button)
        {
            if (button.IsHoldable())
            {
                if (isHoldable(button))
                {
                    return(true);
                }

                if (!isHoldableButNotHeldEnough(button))
                {
                    return(false);
                }

                if (!buttonNotHeldEnough(button))
                {
                    return(false);
                }

                if (!allowOneButtonPress(button))
                {
                    return(false);
                }

                if (buttonHeldEnoughRepeat(button))
                {
                    return(true);
                }

                if (!buttonNotHeldLongEnough(button))
                {
                    return(false);
                }
            }
            return(false);
        }
예제 #14
0
 private bool isHoldableButNotHeldEnough(ButtonAlias button)
 {
     if (button.GetHoldable() > 0 && !_holdTimes.ContainsKey(button.GetAssociation()))
     {
         _holdTimes.Add(button.GetAssociation(), SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds + button.GetHoldable());
         return false;
     }
     return true;
 }
예제 #15
0
 private void RemoveLocksAndHolds(ButtonAlias button)
 {
     if (_holdTimes.ContainsKey(button.GetAssociation()) && button.GetHoldable() > 0 && _holdTimes[button.GetAssociation()].CompareTo(SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds) < 0 && !_repeatHoldTimes.ContainsKey(button.GetAssociation()))
     {
         _holdTimes.Remove(button.GetAssociation());
         _buttonLocks.Remove(button.GetAssociation());
     }
     else if (_repeatHoldTimes.ContainsKey(button.GetAssociation()) && _repeatHoldTimes[button.GetAssociation()].CompareTo(SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds) < 0)
     {
         _repeatHoldTimes.Remove(button.GetAssociation());
         _buttonLocks.Remove(button.GetAssociation());
     }
     else if (!_holdTimes.ContainsKey(button.GetAssociation()))
     {
         _buttonLocks.Remove(button.GetAssociation());
     }
 }
예제 #16
0
 private bool checkCommandKeyUp(ButtonAlias button)
 {
     if (_keyState.IsKeyUp(button.GetKey()) && _buttonLocks.ContainsValue(button))
     {
         if (_holdTimes.ContainsKey(button.GetAssociation()) && button.GetHoldable() > 0 && _holdTimes[button.GetAssociation()].CompareTo(SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds) < 0 && !_repeatHoldTimes.ContainsKey(button.GetAssociation()))
         {
             _holdTimes.Remove(button.GetAssociation());
             _buttonLocks.Remove(button.GetAssociation());
         }
         else if (_repeatHoldTimes.ContainsKey(button.GetAssociation()) && _repeatHoldTimes[button.GetAssociation()].CompareTo(SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds) < 0)
         {
             _repeatHoldTimes.Remove(button.GetAssociation());
         }
         else if (!_holdTimes.ContainsKey(button.GetAssociation()))
         {
             _buttonLocks.Remove(button.GetAssociation());
         }
         return false;
     }
     return true;
 }
예제 #17
0
 private bool isHoldable(ButtonAlias button)
 {
     if (button.GetHoldable() == 0)
     {
         return true;
     }
     return false;
 }
예제 #18
0
        private bool checkButtonDynamics(ButtonAlias button)
        {
            if (button.IsHoldable())
            {
                if (isHoldable(button)) return true;

                if (!isHoldableButNotHeldEnough(button)) return false;

                if (!buttonNotHeldEnough(button)) return false;

                if (!allowOneButtonPress(button)) return false;

                if (buttonHeldEnoughRepeat(button)) return true;

                if (!buttonNotHeldLongEnough(button)) return false;
            }
            return false;
        }
예제 #19
0
 private bool checkCommandButtonUp(ButtonAlias button)
 {
     if (_gamePadState.IsButtonUp(button.GetButton()) && _buttonLocks.ContainsValue(button))
     {
         RemoveLocksAndHolds(button);
         return false;
     }
     return true;
 }
예제 #20
0
 private bool buttonNotHeldLongEnough(ButtonAlias button)
 {
     if (!_repeatHoldTimes.ContainsKey(button.GetAssociation()) && button.GetHoldableRepeat() >= 0)
     {
         _repeatHoldTimes.Add(button.GetAssociation(), SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds + button.GetHoldableRepeat());
         return false;
     }
     return true;
 }
예제 #21
0
 private bool buttonNotHeldEnough(ButtonAlias button)
 {
     if (button.GetHoldable() > 0 && _holdTimes.ContainsKey(button.GetAssociation()) && _holdTimes[button.GetAssociation()].CompareTo(SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds) > 0 && !_repeatHoldTimes.ContainsKey(button.GetAssociation()))
     {
         return false;
     }
     return true;
 }
예제 #22
0
 private bool buttonHeldEnoughRepeat(ButtonAlias button)
 {
     if (_repeatHoldTimes.ContainsKey(button.GetAssociation()) && _repeatHoldTimes[button.GetAssociation()].CompareTo(SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds) < 0)
     {
         _repeatHoldTimes.Remove(button.GetAssociation());
         _advances++;
         return true;
     }
     return false;
 }
예제 #23
0
 private bool allowOneButtonPress(ButtonAlias button)
 {
     if (_holdTimes.ContainsKey(button.GetAssociation()) && _holdTimes[button.GetAssociation()].CompareTo(SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds) < 0 && !_repeatHoldTimes.ContainsKey(button.GetAssociation()) && button.GetHoldableRepeat() >= 0)
     {
         // Remove, re-add, rinse, repeat!
         _repeatHoldTimes.Add(button.GetAssociation(), SystemMain.CurrentGameTime.TotalRealTime.TotalSeconds + button.GetHoldableRepeat());
         return false;
     }
     return true;
 }
예제 #24
0
 private bool SetTypeXbox(ButtonAlias button)
 {
     button.Pressed = PressType.XboxController;
     //_pressedButtons.Add(button.GetAssociation());
     _buttonLocks.Add(button.GetAssociation(), button);
     return true;
 }
예제 #25
0
 private bool setupNewKeyAssociation(ButtonAlias button)
 {
     if (_keyState.IsKeyDown(button.GetKey()) && !_buttonLocks.ContainsKey(button.GetAssociation()))
     {
         button.Pressed = PressType.Key;
         _buttonLocks.Add(button.GetAssociation(), button);
         return true;
     }
     return false;
 }
예제 #26
0
 public void TestAliasCreationForKey()
 {
     var alias = new ButtonAlias(Keys.A, -1, -1, "TestAlias");
     Assert.IsNotNull(alias);
 }