public void DefaultTranslatedInputRepository_RetrieveMappingsForRawInputs_ReturnsExpectedMappings()
        {
            var mockPlayerPrefsRepoInterface = Substitute.For <IPlayerPrefsRepositoryInterface>();

            const EInputKey expectedInputKey = EInputKey.Interact;

            var expectedRawInputs = new List <RawInput>
            {
                new RawInput("Test", EInputType.Button),
                new RawInput("Test2", EInputType.Analog)
            };

            foreach (var expectedRawInput in expectedRawInputs)
            {
                mockPlayerPrefsRepoInterface.GetValueForKey(Arg.Any <string>())
                .Returns(expectedInputKey.ToString());
            }

            var defaultTranslatedInputRepo = new DefaultTranslatedInputRepository(mockPlayerPrefsRepoInterface);
            var actualMappings             = defaultTranslatedInputRepo.RetrieveMappingsForRawInputs(expectedRawInputs);

            foreach (var expectedRawInput in expectedRawInputs)
            {
                Assert.IsTrue(ObjectComparisonExtensions.EqualByPublicProperties(actualMappings[expectedRawInput], new TranslatedInput(expectedInputKey, expectedRawInput.InputType)));
            }
        }
Ejemplo n.º 2
0
 public EInputHandlerResult HandleAnalogInput(EInputKey inInputKey, float analogValue)
 {
     if (AnalogResponses.ContainsKey(inInputKey))
     {
         return(AnalogResponses[inInputKey](analogValue));
     }
     return(EInputHandlerResult.Unhandled);
 }
Ejemplo n.º 3
0
 public EInputHandlerResult HandleMouseInput(EInputKey inInputKey, Vector3 mousePosition)
 {
     if (MouseResponses.ContainsKey(inInputKey))
     {
         return(MouseResponses[inInputKey](mousePosition));
     }
     return(EInputHandlerResult.Unhandled);
 }
Ejemplo n.º 4
0
 public EInputHandlerResult HandleButtonInput(EInputKey inInputKey, bool pressed)
 {
     if (ButtonResponses.ContainsKey(inInputKey))
     {
         return(ButtonResponses[inInputKey](pressed));
     }
     return(EInputHandlerResult.Unhandled);
 }
Ejemplo n.º 5
0
 private void OnMouseInput(EInputKey inInputKey, Vector3 mousePosition)
 {
     for (var currentHandlerIndex = _registeredInputHandlers.Count - 1; currentHandlerIndex >= 0; currentHandlerIndex--)
     {
         if (_registeredInputHandlers[currentHandlerIndex].HandleMouseInput(inInputKey, mousePosition) == EInputHandlerResult.Handled)
         {
             return;
         }
     }
 }
Ejemplo n.º 6
0
 private void OnButtonInput(EInputKey inInputKey, bool pressed)
 {
     for (var currentHandlerIndex = _registeredInputHandlers.Count - 1; currentHandlerIndex >= 0; currentHandlerIndex--)
     {
         if (_registeredInputHandlers[currentHandlerIndex].HandleButtonInput(inInputKey, pressed) == EInputHandlerResult.Handled)
         {
             return;
         }
     }
 }
Ejemplo n.º 7
0
 private void OnAnalogInput(EInputKey inInputKey, float analogValue)
 {
     for (var currentHandlerIndex = _registeredInputHandlers.Count - 1; currentHandlerIndex >= 0; currentHandlerIndex--)
     {
         if (_registeredInputHandlers[currentHandlerIndex].HandleAnalogInput(inInputKey, analogValue) == EInputHandlerResult.Handled)
         {
             return;
         }
     }
 }
Ejemplo n.º 8
0
    internal void SetCloseData(string a_title, string a_text, EInputKey a_closeKey)
    {
        closeButton.gameObject.SetActive(true);
        cancelButton.gameObject.SetActive(false);
        validButton.gameObject.SetActive(false);

        titleLabel.text   = a_title;
        contentLabel.text = a_text;

        closeButton.inputKey = a_closeKey;
    }
Ejemplo n.º 9
0
 public InputUIInfo GetAssociatedInputUIInfo(EInputKey inputKey)
 {
     for (int i = 0; i < m_InputUIInfos.Length; i++)
     {
         if (m_InputUIInfos[i].m_Input == inputKey)
         {
             return(m_InputUIInfos[i]);
         }
     }
     return(null);
 }
Ejemplo n.º 10
0
        public void Button_BindingDoesNotHandle_Unhandled()
        {
            var             inputHandler     = new TestInputHandler();
            const EInputKey expectedInputKey = EInputKey.Interact;

            inputHandler.AddButtonResponse
            (
                expectedInputKey, pressed => EInputHandlerResult.Unhandled
            );

            Assert.AreEqual(inputHandler.HandleButtonInput(expectedInputKey, false), EInputHandlerResult.Unhandled);
            inputHandler.ClearResponses();
        }
Ejemplo n.º 11
0
        public void Analog_BindingHandles_Handled()
        {
            var             inputHandler     = new TestInputHandler();
            const EInputKey expectedInputKey = EInputKey.Interact;

            inputHandler.AddAnalogResponse
            (
                expectedInputKey, analogValue => EInputHandlerResult.Handled
            );

            Assert.AreEqual(inputHandler.HandleAnalogInput(expectedInputKey, 0.0f), EInputHandlerResult.Handled);
            inputHandler.ClearResponses();
        }
Ejemplo n.º 12
0
        public void Mouse_BindingDoesNotHandle_Unhandled()
        {
            var             inputHandler     = new TestInputHandler();
            const EInputKey expectedInputKey = EInputKey.Interact;

            inputHandler.AddMouseResponse
            (
                expectedInputKey, mousePosition => EInputHandlerResult.Unhandled
            );

            Assert.AreEqual(inputHandler.HandleMouseInput(expectedInputKey, new Vector3()), EInputHandlerResult.Unhandled);
            inputHandler.ClearResponses();
        }
Ejemplo n.º 13
0
        //Input zurückgeben
        public EInputKey[] GetInput()
        {
            //Create input array and count int
            EInputKey[] inputs = new EInputKey[20];
            int         count  = 0;

            //check every key and save in input array
            if (KeyJustPressed(currentKeyboardState, previousKeyboardState, Keys.Escape) || ButtonJustPressed(currentPadState, previousPadState, Buttons.Start))
            {
                inputs[count] = EInputKey.Escape; count++;
            }
            if (KeyIsPressed(currentKeyboardState, Keys.Up) || ButtonIsPressed(currentPadState, Buttons.DPadUp))
            {
                inputs[count] = EInputKey.Up; count++;
            }
            if (KeyIsPressed(currentKeyboardState, Keys.Down) || ButtonIsPressed(currentPadState, Buttons.DPadDown))
            {
                inputs[count] = EInputKey.Down; count++;
            }
            if (KeyIsPressed(currentKeyboardState, Keys.Left) || ButtonIsPressed(currentPadState, Buttons.DPadLeft))
            {
                inputs[count] = EInputKey.Left; count++;
            }
            if (KeyIsPressed(currentKeyboardState, Keys.Right) || ButtonIsPressed(currentPadState, Buttons.DPadRight))
            {
                inputs[count] = EInputKey.Right; count++;
            }
            if (KeyIsPressed(currentKeyboardState, Keys.Space) || ButtonIsPressed(currentPadState, Buttons.A))
            {
                inputs[count] = EInputKey.Jump; count++;
            }
            if (KeyIsPressed(currentKeyboardState, Keys.LeftAlt) || ButtonIsPressed(currentPadState, Buttons.X))
            {
                inputs[count] = EInputKey.Attack; count++;
            }
            if (KeyIsPressed(currentKeyboardState, Keys.E) || ButtonIsPressed(currentPadState, Buttons.Y))
            {
                inputs[count] = EInputKey.Use; count++;
            }

            //Create new array with correct lenght
            EInputKey[] finalInputs = new EInputKey[count];
            for (int i = 0; i < count; i++)
            {
                //Add all inputs
                finalInputs[i] = inputs[i];
            }

            //return final new array
            return(finalInputs);
        }
Ejemplo n.º 14
0
    private bool HasValidInput(List <GameInput> gameInputs, out EInputKey validInput)
    {
        validInput = EInputKey.Invalid;
        for (int i = 0; i < gameInputs.Count; i++)
        {
            if (PlayerGamePad.K_DEFAULT_INPUT_MAPPING.ContainsKey(gameInputs[i].GetInputKey()))
            {
                validInput = gameInputs[i].GetInputKey();
                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 15
0
    private IEnumerator ListenInput_Coroutine()
    {
        // Skip the first frame as we're just triggering A input to start listening
        yield return(null);

        bool validInputReceived = false;

        while (!validInputReceived)
        {
            List <GameInput> gamepadInputList = GamePadManager.GetPlayerGamepadInput((int)m_Player);
            if (HasValidInput(gamepadInputList, out EInputKey validInput))
            {
                m_CurrentInputKey = validInput;
                StopListeningInput();
                yield break;
            }
            yield return(null);
        }
    }
Ejemplo n.º 16
0
    private void UpdateInputSprite()
    {
        if (m_CurrentInputKey == EInputKey.Invalid)
        {
            m_CurrentInputKey = GamePadManager.GetPlayerGamepadInputMapping((int)m_Player, m_DefaultInputKey);
            if (m_CurrentInputKey == EInputKey.Invalid)
            {
                m_CurrentInputKey = m_DefaultInputKey;
            }
        }

        InputUIInfo associatedInputUIInfo = UIConfig.Instance.GetAssociatedInputUIInfo(m_CurrentInputKey);

        if (associatedInputUIInfo != null)
        {
            m_PS4ImageInput.sprite  = associatedInputUIInfo.m_PS4Sprite;
            m_XboxImageInput.sprite = associatedInputUIInfo.m_XboxSprite;
        }
    }
Ejemplo n.º 17
0
    public void StartListeningInput()
    {
        // Check if it's the correct player's trying to update input
        List <GameInput> gamepadInputList = GamePadManager.GetPlayerGamepadInput((int)m_Player);

        if (gamepadInputList.Exists(x => x.GetInputKey() == EInputKey.A))
        {
            m_IsListeningInput           = true;
            m_OldInputKey                = m_CurrentInputKey;
            m_CurrentEventSystem         = EventSystem.current;
            m_CurrentEventSystem.enabled = false;
            m_XboxImageInput.enabled     = false;
            m_PS4ImageInput.enabled      = false;
            m_PressAKeyText.enabled      = true;
            StartCoroutine(ListenInput_Coroutine());
        }
        else
        {
            m_ControlMenuComponent.DisplayWrongPlayerFeedback();
        }
    }
Ejemplo n.º 18
0
 public void TestActivateAnalogEvent(EInputKey inInputKey, float analogValue)
 {
     OnAnalogInputEvent(inInputKey, analogValue);
 }
Ejemplo n.º 19
0
 public static void SetPlayerGamepadInputMapping(int playerIndex, EInputKey key, EInputKey newValue)
 {
     m_PlayerGamePads[playerIndex].SetInputMapping(key, newValue);
 }
Ejemplo n.º 20
0
 public void ResetInputMapping()
 {
     m_CurrentInputKey = EInputKey.Invalid;
     UpdateInputSprite();
 }
Ejemplo n.º 21
0
    public static string ConvertInputKeyToString(EInputKey key)
    {
        string inputString = "";

        switch (key)
        {
        case EInputKey.Down:
            inputString = GameInputConstants.K_DOWN;
            break;

        case EInputKey.DownRight:
            inputString = GameInputConstants.K_DOWN_RIGHT;
            break;

        case EInputKey.Right:
            inputString = GameInputConstants.K_RIGHT;
            break;

        case EInputKey.UpRight:
            inputString = GameInputConstants.K_UP_RIGHT;
            break;

        case EInputKey.Up:
            inputString = GameInputConstants.K_UP;
            break;

        case EInputKey.UpLeft:
            inputString = GameInputConstants.K_UP_LEFT;
            break;

        case EInputKey.Left:
            inputString = GameInputConstants.K_LEFT;
            break;

        case EInputKey.DownLeft:
            inputString = GameInputConstants.K_DOWN_LEFT;
            break;

        case EInputKey.A:
            inputString = GameInputConstants.K_A;
            break;

        case EInputKey.B:
            inputString = GameInputConstants.K_B;
            break;

        case EInputKey.X:
            inputString = GameInputConstants.K_X;
            break;

        case EInputKey.Y:
            inputString = GameInputConstants.K_Y;
            break;

        case EInputKey.RB:
            inputString = GameInputConstants.K_RB;
            break;

        case EInputKey.LB:
            inputString = GameInputConstants.K_LB;
            break;

        case EInputKey.RT:
            inputString = GameInputConstants.K_RT;
            break;

        case EInputKey.LT:
            inputString = GameInputConstants.K_LT;
            break;

        case EInputKey.Invalid:
        default:
            inputString = "";
            break;
        }

        return(inputString);
    }
Ejemplo n.º 22
0
 public void AddMouseResponse(EInputKey inInputKey, OnMouseInputHandledDelegate func)
 {
     MouseResponses.Add(inInputKey, func);
 }
Ejemplo n.º 23
0
 public void AddAnalogResponse(EInputKey inInputKey, OnAnalogInputHandledDelegate func)
 {
     AnalogResponses.Add(inInputKey, func);
 }
Ejemplo n.º 24
0
 public void AddButtonResponse(EInputKey inInputKey, OnButtonInputHandledDelegate func)
 {
     ButtonResponses.Add(inInputKey, func);
 }
Ejemplo n.º 25
0
    public static EInputKey ConvertInputStringToKey(string str)
    {
        EInputKey inputKey = EInputKey.Invalid;

        switch (str)
        {
        case GameInputConstants.K_DOWN:
            inputKey = EInputKey.Down;
            break;

        case GameInputConstants.K_DOWN_RIGHT:
            inputKey = EInputKey.DownRight;
            break;

        case GameInputConstants.K_RIGHT:
            inputKey = EInputKey.Right;
            break;

        case GameInputConstants.K_UP_RIGHT:
            inputKey = EInputKey.UpRight;
            break;

        case GameInputConstants.K_UP:
            inputKey = EInputKey.Up;
            break;

        case GameInputConstants.K_UP_LEFT:
            inputKey = EInputKey.UpLeft;
            break;

        case GameInputConstants.K_LEFT:
            inputKey = EInputKey.Left;
            break;

        case GameInputConstants.K_DOWN_LEFT:
            inputKey = EInputKey.DownLeft;
            break;

        case GameInputConstants.K_A:
            inputKey = EInputKey.A;
            break;

        case GameInputConstants.K_B:
            inputKey = EInputKey.B;
            break;

        case GameInputConstants.K_X:
            inputKey = EInputKey.X;
            break;

        case GameInputConstants.K_Y:
            inputKey = EInputKey.Y;
            break;

        case GameInputConstants.K_RB:
            inputKey = EInputKey.RB;
            break;

        case GameInputConstants.K_LB:
            inputKey = EInputKey.LB;
            break;

        case GameInputConstants.K_RT:
            inputKey = EInputKey.RT;
            break;

        case GameInputConstants.K_LT:
            inputKey = EInputKey.LT;
            break;

        default:
            inputKey = EInputKey.Invalid;
            break;
        }

        return(inputKey);
    }
Ejemplo n.º 26
0
 public GameInput(GameInput input)
 {
     m_InputKey    = input.GetInputKey();
     m_InputString = input.GetInputString();
 }
Ejemplo n.º 27
0
 public GameInput(EInputKey key)
 {
     m_InputKey    = key;
     m_InputString = ConvertInputKeyToString(key);
 }
Ejemplo n.º 28
0
 public void TestActivateButtonEvent(EInputKey inInputKey, bool pressed)
 {
     OnButtonInputEvent(inInputKey, pressed);
 }
Ejemplo n.º 29
0
 public void TestActivateMouseEvent(EInputKey inInputKey, Vector3 mousePosition)
 {
     OnMouseInputEvent(inInputKey, mousePosition);
 }
Ejemplo n.º 30
0
 public GameInput(string str)
 {
     m_InputString = str;
     m_InputKey    = ConvertInputStringToKey(str);
 }