Class InputService

java.lang.Object
com.csse3200.game.input.InputService
All Implemented Interfaces:
com.badlogic.gdx.input.GestureDetector.GestureListener, com.badlogic.gdx.InputProcessor

public class InputService extends Object implements com.badlogic.gdx.InputProcessor, com.badlogic.gdx.input.GestureDetector.GestureListener
Provides a global access point for handling user input and creating input handlers. All active input handlers should be registered here.

When an input is received, it is passed to registered input handlers in descending priority order and stops as soon as the input is handled.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
    InputService(InputFactory inputFactory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    fling(float velocityX, float velocityY, int button)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
     
    Get the input factory to create input handlers
    boolean
    keyDown(int keycode)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed.
    boolean
    keyTyped(char character)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
    boolean
    keyUp(int keycode)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
    boolean
    longPress(float x, float y)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
    boolean
    mouseMoved(int screenX, int screenY)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
    boolean
    pan(float x, float y, float deltaX, float deltaY)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
    boolean
    panStop(float x, float y, int pointer, int button)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
    boolean
    pinch(com.badlogic.gdx.math.Vector2 initialPointer1, com.badlogic.gdx.math.Vector2 initialPointer2, com.badlogic.gdx.math.Vector2 pointer1, com.badlogic.gdx.math.Vector2 pointer2)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
    void
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
    void
    register(InputComponent inputHandler)
    Register an input handler based on its priority and reorder inputHandlers.
    boolean
    scrolled(float amountX, float amountY)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
    boolean
    tap(float x, float y, int count, int button)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
    boolean
    touchDown(float x, float y, int pointer, int button)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
    boolean
    touchDown(int screenX, int screenY, int pointer, int button)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
    boolean
    touchDragged(int screenX, int screenY, int pointer)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
    boolean
    touchUp(int screenX, int screenY, int pointer, int button)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed
    void
    unregister(InputComponent inputHandler)
    Unregister an input handler
    boolean
    zoom(float initialDistance, float distance)
    Iterates over registered input handlers in descending priority and stops as soon as the input is processed

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • InputService

      public InputService()
    • InputService

      public InputService(InputFactory inputFactory)
  • Method Details

    • getInputFactory

      public InputFactory getInputFactory()
      Get the input factory to create input handlers
      Returns:
      input factory
    • getEngineerInput

      public EngineerInputComponent getEngineerInput()
    • register

      public void register(InputComponent inputHandler)
      Register an input handler based on its priority and reorder inputHandlers.
      Parameters:
      inputHandler - input handler
    • unregister

      public void unregister(InputComponent inputHandler)
      Unregister an input handler
      Parameters:
      inputHandler - input handler
    • keyDown

      public boolean keyDown(int keycode)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed.
      Specified by:
      keyDown in interface com.badlogic.gdx.InputProcessor
      Returns:
      whether the input was processed
      See Also:
      • InputProcessor.keyDown(int)
    • keyTyped

      public boolean keyTyped(char character)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      keyTyped in interface com.badlogic.gdx.InputProcessor
      Returns:
      whether the input was processed
      See Also:
      • InputProcessor.keyTyped(char)
    • keyUp

      public boolean keyUp(int keycode)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      keyUp in interface com.badlogic.gdx.InputProcessor
      Returns:
      whether the input was processed
      See Also:
      • InputProcessor.keyUp(int)
    • mouseMoved

      public boolean mouseMoved(int screenX, int screenY)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      mouseMoved in interface com.badlogic.gdx.InputProcessor
      Returns:
      whether the input was processed
      See Also:
      • InputProcessor.mouseMoved(int, int)
    • scrolled

      public boolean scrolled(float amountX, float amountY)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      scrolled in interface com.badlogic.gdx.InputProcessor
      Returns:
      whether the input was processed
      See Also:
      • InputProcessor.scrolled(float, float)
    • touchDown

      public boolean touchDown(int screenX, int screenY, int pointer, int button)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      touchDown in interface com.badlogic.gdx.InputProcessor
      Returns:
      whether the input was processed
      See Also:
      • InputProcessor.touchDown(int, int, int, int)
    • touchDragged

      public boolean touchDragged(int screenX, int screenY, int pointer)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      touchDragged in interface com.badlogic.gdx.InputProcessor
      Returns:
      whether the input was processed
      See Also:
      • InputProcessor.touchDragged(int, int, int)
    • touchUp

      public boolean touchUp(int screenX, int screenY, int pointer, int button)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      touchUp in interface com.badlogic.gdx.InputProcessor
      Returns:
      whether the input was processed
      See Also:
      • InputProcessor.touchUp(int, int, int, int)
    • fling

      public boolean fling(float velocityX, float velocityY, int button)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      fling in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      Returns:
      whether the input was processed
      See Also:
      • GestureDetector.GestureListener.fling(float, float, int)
    • longPress

      public boolean longPress(float x, float y)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      longPress in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      Returns:
      whether the input was processed
      See Also:
      • GestureDetector.GestureListener.longPress(float, float)
    • pan

      public boolean pan(float x, float y, float deltaX, float deltaY)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      pan in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      Returns:
      whether the input was processed
      See Also:
      • GestureDetector.GestureListener.pan(float, float, float, float)
    • panStop

      public boolean panStop(float x, float y, int pointer, int button)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      panStop in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      Returns:
      whether the input was processed
      See Also:
      • GestureDetector.GestureListener.panStop(float, float, int, int)
    • pinch

      public boolean pinch(com.badlogic.gdx.math.Vector2 initialPointer1, com.badlogic.gdx.math.Vector2 initialPointer2, com.badlogic.gdx.math.Vector2 pointer1, com.badlogic.gdx.math.Vector2 pointer2)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      pinch in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      Returns:
      whether the input was processed
      See Also:
      • GestureDetector.GestureListener.pinch(Vector2, Vector2, Vector2, Vector2)
    • pinchStop

      public void pinchStop()
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      pinchStop in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      See Also:
      • GestureDetector.GestureListener.pinchStop()
    • tap

      public boolean tap(float x, float y, int count, int button)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      tap in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      Returns:
      whether the input was processed
      See Also:
      • GestureDetector.GestureListener.tap(float, float, int, int)
    • touchDown

      public boolean touchDown(float x, float y, int pointer, int button)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      touchDown in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      Returns:
      whether the input was processed
      See Also:
      • GestureDetector.GestureListener.touchDown(float, float, int, int)
    • zoom

      public boolean zoom(float initialDistance, float distance)
      Iterates over registered input handlers in descending priority and stops as soon as the input is processed
      Specified by:
      zoom in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      Returns:
      whether the input was processed
      See Also:
      • GestureDetector.GestureListener.zoom(float, float)