Package squidpony.squidgrid.gui.gdx
Class VisualInput
java.lang.Object
com.badlogic.gdx.InputAdapter
squidpony.squidgrid.gui.gdx.SquidInput
squidpony.squidgrid.gui.gdx.VisualInput
- All Implemented Interfaces:
com.badlogic.gdx.InputProcessor
public class VisualInput extends SquidInput
Acts like SquidInput but displays available keys as visible buttons if the device has no physical keyboard.
Only relevant if you want keyboard input to always be available, so this doesn't implement the SquidInput
constructors that don't handle any keys (the buttons this shows will act like keys even on Android and iOS).
This doesn't currently work well when used with a SquidPanel or SquidLayers that pans a camera over an area that is larger than one screen (you only need to worry about this in "standard" SquidLib usage if you use the
Created by Tommy Ettinger on 4/15/2016.
This doesn't currently work well when used with a SquidPanel or SquidLayers that pans a camera over an area that is larger than one screen (you only need to worry about this in "standard" SquidLib usage if you use the
SquidPanel(int, int, TextCellFactory, squidpony.IColorCenter, float, float, char[][])
) or
SquidLayers(int, int, int, int, TextCellFactory, SquidColorCenter, SquidColorCenter, char[][])
constructors with a larger 2D char array than the given gridWidth and/or gridHeight). It works fine if the
area that can be seen on one screen is as big as it gets, such as in the normal text-based mode of games like
Rogue and Brogue. It can also work if you manually handle movement over a larger area without using libGDX
Viewport and Camera code to accomplish that, since this class needs to handle the Viewport to some extent.
Created by Tommy Ettinger on 4/15/2016.
-
Nested Class Summary
Nested classes/interfaces inherited from class squidpony.squidgrid.gui.gdx.SquidInput
SquidInput.KeyHandler
-
Field Summary
Fields Modifier and Type Field Description protected TreeMap<Character,String>
availableKeys
protected com.badlogic.gdx.utils.CharArray
clicks
com.badlogic.gdx.graphics.Color
color
boolean
eightWay
boolean
forceButtons
protected boolean
initialized
SquidPanel
left
protected SquidMouse
mouseLeft
protected SquidMouse
mouseRight
SquidPanel
right
protected ShrinkPartViewport
spv
com.badlogic.gdx.scenes.scene2d.Stage
stage
protected TextCellFactory
tcfLeft
protected TextCellFactory
tcfRight
Fields inherited from class squidpony.squidgrid.gui.gdx.SquidInput
BACKSPACE, CENTER_ARROW, DOWN_ARROW, DOWN_LEFT_ARROW, DOWN_RIGHT_ARROW, END, ENTER, ESCAPE, F1, F10, F11, F12, F2, F3, F4, F5, F6, F7, F8, F9, FORWARD_DELETE, GAMEPAD_A, GAMEPAD_B, GAMEPAD_C, GAMEPAD_L1, GAMEPAD_L2, GAMEPAD_LEFT_THUMB, GAMEPAD_R1, GAMEPAD_R2, GAMEPAD_RIGHT_THUMB, GAMEPAD_SELECT, GAMEPAD_START, GAMEPAD_X, GAMEPAD_Y, GAMEPAD_Z, heldCodes, HOME, ignoreInput, INSERT, keyAction, lastKeyTime, LEFT_ARROW, mapping, mouse, numpadDirections, PAGE_DOWN, PAGE_UP, queue, repeatGapMillis, RIGHT_ARROW, TAB, UP_ARROW, UP_LEFT_ARROW, UP_RIGHT_ARROW, VERTICAL_ARROW
-
Constructor Summary
Constructors Constructor Description VisualInput(SquidInput.KeyHandler keyHandler)
VisualInput(SquidInput.KeyHandler keyHandler, boolean ignoreInput)
VisualInput(SquidInput.KeyHandler keyHandler, SquidMouse mouse)
VisualInput(SquidInput.KeyHandler keyHandler, SquidMouse mouse, boolean ignoreInput)
-
Method Summary
Modifier and Type Method Description int
getSectionHeight()
int
getSectionWidth()
void
init(String... enabled)
Convenience method that does essentially the same thing as init(Map<Character, String>).void
init(Map<Character,String> available)
For each char and String in available, registers each keyboard key (as a char, such as 'A' or SquidInput.LEFT_ARROW) with a String that names the action that key is used to perform, and makes these Strings available as buttons on the right side of the screen if on a device with no hardware keyboard.void
init(TextCellFactory font, String... enabled)
Convenience method that does essentially the same thing as init(Map<Character, String>).void
init(TextCellFactory font, Map<Character,String> available)
For each char and String in available, registers each keyboard key (as a char, such as 'A' or SquidInput.LEFT_ARROW) with a String that names the action that key is used to perform, and makes these Strings available as buttons on the right side of the screen if on a device with no hardware keyboard.boolean
mouseMoved(int screenX, int screenY)
void
reinitialize(float cellWidth, float cellHeight, float gridWidth, float gridHeight, int offsetX, int offsetY, float screenWidth, float screenHeight)
ShrinkPartViewport
resizeInnerStage(com.badlogic.gdx.scenes.scene2d.Stage insides)
void
show()
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)
void
update(int width, int height, boolean centerCamera)
Methods inherited from class squidpony.squidgrid.gui.gdx.SquidInput
clearMapping, combineModifiers, drain, flush, fromCode, getIgnoreInput, getKeyHandler, getMouse, getRepeatGap, hasNext, isUsingNumpadDirections, keyDown, keyMappingFromString, keyMappingToString, keyTyped, keyUp, next, remap, remap, remap, scrolled, setIgnoreInput, setKeyHandler, setMouse, setRepeatGap, setUsingNumpadDirections, unmap, unmap
-
Field Details
-
Constructor Details
-
Method Details
-
init
Convenience method that does essentially the same thing as init(Map<Character, String>). This assumes that each String passed to this is an action, and the first letter of a String is the character that a keypress would generate to perform the action named by the String. For example, calling this withinit("fire", "Fortify")
would register "fire" under 'f' and "Fortify" under 'F', displaying the Strings instead of the characters if possible. The first char of each String should be unique in the arguments.
This also initializes the displayed buttons if there is no hardware keyboard available. This uses the color and eightWay fields to determine what color the buttons will be drawn with and if directions should be 8-way or 4-way, respectively. These fields should be set before calling init() if you don't want the defaults, which are white buttons and 8-way directions. The font with this overload of init is set to Inconsolata-LGC-Custom, which is normally available viaDefaultResources.getStretchableFont()
and requires the .fnt file and .png file listed in the documentation for that method. If you don't have those files, but have some other font (preferably some kind of distance field font, since this resizes the font significantly), you can useinit(TextCellFactory, String...)
orinit(TextCellFactory, Map)
to have this use your font.- Parameters:
enabled
- an array or vararg of Strings that name actions; the first char of each String should be unique
-
init
Convenience method that does essentially the same thing as init(Map<Character, String>). This assumes that each String passed to this is an action, and the first letter of a String is the character that a keypress would generate to perform the action named by the String. For example, calling this withinit("fire", "Fortify")
would register "fire" under 'f' and "Fortify" under 'F', displaying the Strings instead of the characters if possible. The first char of each String should be unique in the arguments.
This also initializes the displayed buttons if there is no hardware keyboard available. This uses the color and eightWay fields to determine what color the buttons will be drawn with and if directions should be 8-way or 4-way, respectively. These fields should be set before calling init() if you don't want the defaults, which are white buttons and 8-way directions.- Parameters:
font
- the TextCellFactory to use for the buttons, usually a distance field font from DefaultResourcesenabled
- an array or vararg of Strings that name actions; the first char of each String should be unique
-
init
For each char and String in available, registers each keyboard key (as a char, such as 'A' or SquidInput.LEFT_ARROW) with a String that names the action that key is used to perform, and makes these Strings available as buttons on the right side of the screen if on a device with no hardware keyboard. Arrows will be provided on the left side of the screen for directions.
This also initializes the displayed buttons if there is no hardware keyboard available. This uses the color and eightWay fields to determine what color the buttons will be drawn with and if directions should be 8-way or 4-way, respectively. These fields should be set before calling init() if you don't want the defaults, which are white buttons and 8-way directions. The font with this overload of init is set to Inconsolata-LGC-Custom, which is normally available viaDefaultResources.getStretchableFont()
and requires the .fnt file and .png file listed in the documentation for that method. If you don't have those files, but have some other font (preferably some kind of distance field font, since this resizes the font significantly), you can useinit(TextCellFactory, String...)
orinit(TextCellFactory, Map)
to have this use your font.- Parameters:
available
- a Map of Character keys representing keyboard keys and Strings for the actions they trigger
-
init
For each char and String in available, registers each keyboard key (as a char, such as 'A' or SquidInput.LEFT_ARROW) with a String that names the action that key is used to perform, and makes these Strings available as buttons on the right side of the screen if on a device with no hardware keyboard. Arrows will be provided on the left side of the screen for directions.
This uses the color and eightWay fields to determine what color the buttons will be drawn with and if directions should be 8-way or 4-way, respectively. These fields should be set before calling init() if you don't want the defaults, which are white buttons and 8-way directions.- Parameters:
font
- the TextCellFactory to use for the buttons, usually a distance field font from DefaultResourcesavailable
- a Map of Character keys representing keyboard keys and Strings for the actions they trigger
-
touchDown
- Specified by:
touchDown
in interfacecom.badlogic.gdx.InputProcessor
- Overrides:
touchDown
in classSquidInput
-
touchUp
- Specified by:
touchUp
in interfacecom.badlogic.gdx.InputProcessor
- Overrides:
touchUp
in classSquidInput
-
touchDragged
- Specified by:
touchDragged
in interfacecom.badlogic.gdx.InputProcessor
- Overrides:
touchDragged
in classSquidInput
-
mouseMoved
- Specified by:
mouseMoved
in interfacecom.badlogic.gdx.InputProcessor
- Overrides:
mouseMoved
in classSquidInput
-
reinitialize
public void reinitialize(float cellWidth, float cellHeight, float gridWidth, float gridHeight, int offsetX, int offsetY, float screenWidth, float screenHeight) -
resizeInnerStage
-
getSectionWidth
-
getSectionHeight
-
update
-
show
-