Package com.csse3200.game.input
Class InputComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.input.InputComponent
- All Implemented Interfaces:
com.badlogic.gdx.input.GestureDetector.GestureListener
,com.badlogic.gdx.InputProcessor
- Direct Known Subclasses:
ArrowKeysPlayerInputComponent
,BaseTerminalInputComponent
,InputDecorator
,KeyboardPlayerInputComponent
,ShopInteractComponent
,TouchPlayerInputComponent
public abstract class InputComponent
extends Component
implements com.badlogic.gdx.InputProcessor, com.badlogic.gdx.input.GestureDetector.GestureListener
An InputComponent that supports keyboard and touch input and touch gestures. By default an
InputComponent does not handle any input events.
Subclasses of InputComponent should override relevant methods to handle input. Ensure the priority is set in the subclass' constructor.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
The priority that the input handler is visited in by InputService. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Sets priority to the default value;protected
InputComponent
(int priority) Sets input handler priority to a given value. -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Called when the entity is created and registered.void
dispose()
Called when the component is disposed.boolean
fling
(float velocityX, float velocityY, int button) int
protected boolean
Returns True as this component is pausable.boolean
keyDown
(int keycode) Handles key down events from the game engine.protected abstract boolean
keyPressed
(int keycode) An abstract method to be implemented by subclasses for specific key down events.protected abstract boolean
keyReleased
(int keycode) An abstract method to be implemented by subclasses for specific key down events.boolean
keyTyped
(char character) boolean
keyUp
(int keycode) Handles the key up events from the game engine.boolean
longPress
(float x, float y) boolean
mouseMoved
(int screenX, int screenY) boolean
pan
(float x, float y, float deltaX, float deltaY) boolean
panStop
(float x, float y, int pointer, int button) 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) void
boolean
Wrapper for pinch stop that can be overridden.boolean
scrolled
(float amountX, float amountY) void
setPriority
(int priority) boolean
tap
(float x, float y, int count, int button) boolean
touchDown
(float x, float y, int pointer, int button) boolean
touchDown
(int screenX, int screenY, int pointer, int button) boolean
touchDragged
(int screenX, int screenY, int pointer) boolean
touchUp
(int screenX, int screenY, int pointer, int button) boolean
zoom
(float initialDistance, float distance) Methods inherited from class com.csse3200.game.components.Component
earlyUpdate, getEntity, getPrio, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Field Details
-
priority
protected int priorityThe priority that the input handler is visited in by InputService.
-
-
Constructor Details
-
InputComponent
protected InputComponent()Sets priority to the default value; -
InputComponent
protected InputComponent(int priority) Sets input handler priority to a given value.- Parameters:
priority
- input handler's priority
-
-
Method Details
-
create
public void create()Description copied from class:Component
Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished. -
setPriority
public void setPriority(int priority) -
getPriority
public int getPriority() -
dispose
public void dispose()Description copied from class:Component
Called when the component is disposed. Dispose of any internal resources here. -
isPauseable
protected boolean isPauseable()Returns True as this component is pausable.- Returns:
- True if the component is not pauseable, False if it is
-
keyDown
public boolean keyDown(int keycode) Handles key down events from the game engine. This is final to ensure the logic is inherited by all children while delegating specific key handling to thekeyPressed(int)
method.- Specified by:
keyDown
in interfacecom.badlogic.gdx.InputProcessor
- Parameters:
keycode
- one of the constants inInput.Keys
- Returns:
- true if the even was handled, false otherwise
-
keyPressed
protected abstract boolean keyPressed(int keycode) An abstract method to be implemented by subclasses for specific key down events. This method is called by thekeyDown(int)
method.- Parameters:
keycode
- The key code of the key that was pressed.- Returns:
- true if the even was handled, false otherwise
-
keyTyped
public boolean keyTyped(char character) - Specified by:
keyTyped
in interfacecom.badlogic.gdx.InputProcessor
- See Also:
-
keyUp
public boolean keyUp(int keycode) Handles the key up events from the game engine. This is final to ensure that the logic is inherited by all the children while delegating specific key handling to thekeyReleased(int)
method.- Specified by:
keyUp
in interfacecom.badlogic.gdx.InputProcessor
- Parameters:
keycode
- one of the constants inInput.Keys
- Returns:
- true if the even was handled, false otherwise
-
keyReleased
protected abstract boolean keyReleased(int keycode) An abstract method to be implemented by subclasses for specific key down events. This method is called by thekeyUp(int)
method.- Parameters:
keycode
- The key code of the key that was pressed.- Returns:
- True if the even was handled, false otherwise
-
mouseMoved
public boolean mouseMoved(int screenX, int screenY) - Specified by:
mouseMoved
in interfacecom.badlogic.gdx.InputProcessor
- See Also:
-
scrolled
public boolean scrolled(float amountX, float amountY) - Specified by:
scrolled
in interfacecom.badlogic.gdx.InputProcessor
- See Also:
-
touchDown
public boolean touchDown(int screenX, int screenY, int pointer, int button) - Specified by:
touchDown
in interfacecom.badlogic.gdx.InputProcessor
- See Also:
-
touchDragged
public boolean touchDragged(int screenX, int screenY, int pointer) - Specified by:
touchDragged
in interfacecom.badlogic.gdx.InputProcessor
- See Also:
-
touchUp
public boolean touchUp(int screenX, int screenY, int pointer, int button) - Specified by:
touchUp
in interfacecom.badlogic.gdx.InputProcessor
- See Also:
-
fling
public boolean fling(float velocityX, float velocityY, int button) - Specified by:
fling
in interfacecom.badlogic.gdx.input.GestureDetector.GestureListener
- See Also:
-
longPress
public boolean longPress(float x, float y) - Specified by:
longPress
in interfacecom.badlogic.gdx.input.GestureDetector.GestureListener
- See Also:
-
pan
public boolean pan(float x, float y, float deltaX, float deltaY) - Specified by:
pan
in interfacecom.badlogic.gdx.input.GestureDetector.GestureListener
- See Also:
-
panStop
public boolean panStop(float x, float y, int pointer, int button) - Specified by:
panStop
in interfacecom.badlogic.gdx.input.GestureDetector.GestureListener
- See Also:
-
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) - Specified by:
pinch
in interfacecom.badlogic.gdx.input.GestureDetector.GestureListener
- See Also:
-
pinchStop
public void pinchStop()- Specified by:
pinchStop
in interfacecom.badlogic.gdx.input.GestureDetector.GestureListener
- See Also:
-
pinchStopHandled
public boolean pinchStopHandled()Wrapper for pinch stop that can be overridden. This was created because the pinchStop() doesn't have a return value.- Returns:
- whether the input was processed
-
tap
public boolean tap(float x, float y, int count, int button) - Specified by:
tap
in interfacecom.badlogic.gdx.input.GestureDetector.GestureListener
- See Also:
-
touchDown
public boolean touchDown(float x, float y, int pointer, int button) - Specified by:
touchDown
in interfacecom.badlogic.gdx.input.GestureDetector.GestureListener
- See Also:
-
zoom
public boolean zoom(float initialDistance, float distance) - Specified by:
zoom
in interfacecom.badlogic.gdx.input.GestureDetector.GestureListener
- See Also:
-