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 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.
  • Field Details

  • Constructor Details

  • Method Details

    • init

      public void init​(String... enabled)
      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 with init("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 via DefaultResources.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 use init(TextCellFactory, String...) or init(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

      public void init​(TextCellFactory font, String... enabled)
      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 with init("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 DefaultResources
      enabled - an array or vararg of Strings that name actions; the first char of each String should be unique
    • init

      public 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. 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 via DefaultResources.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 use init(TextCellFactory, String...) or init(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

      public 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. 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 DefaultResources
      available - a Map of Character keys representing keyboard keys and Strings for the actions they trigger
    • touchDown

      public boolean touchDown​(int screenX, int screenY, int pointer, int button)
      Specified by:
      touchDown in interface com.badlogic.gdx.InputProcessor
      Overrides:
      touchDown in class SquidInput
    • touchUp

      public boolean touchUp​(int screenX, int screenY, int pointer, int button)
      Specified by:
      touchUp in interface com.badlogic.gdx.InputProcessor
      Overrides:
      touchUp in class SquidInput
    • touchDragged

      public boolean touchDragged​(int screenX, int screenY, int pointer)
      Specified by:
      touchDragged in interface com.badlogic.gdx.InputProcessor
      Overrides:
      touchDragged in class SquidInput
    • mouseMoved

      public boolean mouseMoved​(int screenX, int screenY)
      Specified by:
      mouseMoved in interface com.badlogic.gdx.InputProcessor
      Overrides:
      mouseMoved in class SquidInput
    • reinitialize

      public void reinitialize​(float cellWidth, float cellHeight, float gridWidth, float gridHeight, int offsetX, int offsetY, float screenWidth, float screenHeight)
    • resizeInnerStage

      public ShrinkPartViewport resizeInnerStage​(com.badlogic.gdx.scenes.scene2d.Stage insides)
    • getSectionWidth

      public int getSectionWidth()
    • getSectionHeight

      public int getSectionHeight()
    • update

      public void update​(int width, int height, boolean centerCamera)
    • show

      public void show()