Class SquidMessageBox

java.lang.Object
com.badlogic.gdx.scenes.scene2d.Actor
squidpony.squidgrid.gui.gdx.SparseLayers
squidpony.squidgrid.gui.gdx.SquidMessageBox
All Implemented Interfaces:
IPackedColorPanel

public class SquidMessageBox
extends SparseLayers
A specialized SquidPanel that is meant for displaying messages in a scrolling pane. You primarily use this class by calling appendMessage() or appendWrappingMessage(), but the full SquidPanel API is available as well, though it isn't the best idea to use that set of methods with this class in many cases. Messages can be Strings or IColoredStrings. Height must be at least 3 cells, because clicking/tapping the top or bottom borders (which are part of the grid's height, which leaves 1 row in the middle for a message) will scroll up or down. Created by Tommy Ettinger on 12/10/2015.
See Also:
An alternative, which is also designed to write messages (not in a scrolling pane though), but which is backed up by instead of (hence better supports tight variable-width fonts)
  • Field Details

  • Constructor Details

    • SquidMessageBox

      public SquidMessageBox​(int gridWidth, int gridHeight)
      Creates a bare-bones panel with all default values for text rendering.
      Parameters:
      gridWidth - the number of cells horizontally
      gridHeight - the number of cells vertically, must be at least 3
    • SquidMessageBox

      public SquidMessageBox​(int gridWidth, int gridHeight, int cellWidth, int cellHeight)
      Creates a panel with the given grid and cell size. Uses a default square font.
      Parameters:
      gridWidth - the number of cells horizontally
      gridHeight - the number of cells vertically
      cellWidth - the number of horizontal pixels in each cell
      cellHeight - the number of vertical pixels in each cell
    • SquidMessageBox

      public SquidMessageBox​(int gridWidth, int gridHeight, TextCellFactory factory)
      Builds a panel with the given grid size and all other parameters determined by the factory. Even if sprite images are being used, a TextCellFactory is still needed to perform sizing and other utility functions.

      If the TextCellFactory has not yet been initialized, then it will be sized at 12x12 px per cell. If it is null then a default one will be created and initialized.

      Parameters:
      gridWidth - the number of cells horizontally
      gridHeight - the number of cells vertically
      factory - the factory to use for cell rendering
    • SquidMessageBox

      public SquidMessageBox​(int gridWidth, int gridHeight, TextCellFactory factory, IColorCenter<com.badlogic.gdx.graphics.Color> center)
      Builds a panel with the given grid size and all other parameters determined by the factory. Even if sprite images are being used, a TextCellFactory is still needed to perform sizing and other utility functions.

      If the TextCellFactory has not yet been initialized, then it will be sized at 12x12 px per cell. If it is null then a default one will be created and initialized.

      Parameters:
      gridWidth - the number of cells horizontally
      gridHeight - the number of cells vertically
      factory - the factory to use for cell rendering
      center - ignored.
  • Method Details

    • appendMessage

      public void appendMessage​(String message)
      The primary way of using this class. Appends a new line to the message listing and scrolls to the bottom.
      Parameters:
      message - a String that should be no longer than gridWidth - 2; will be truncated otherwise.
    • appendWrappingMessage

      public void appendWrappingMessage​(String message)
      Appends a new line to the message listing and scrolls to the bottom. If the message cannot fit on one line, it will be word-wrapped and one or more messages will be appended after it.
      Parameters:
      message - a String; this method has no specific length restrictions
    • appendMessage

      public void appendMessage​(IColoredString<com.badlogic.gdx.graphics.Color> message)
      A common way of using this class. Appends a new line as an IColoredString to the message listing and scrolls to the bottom.
      Parameters:
      message - an IColoredString that should be no longer than gridWidth - 2; will be truncated otherwise.
    • appendWrappingMessage

      public void appendWrappingMessage​(IColoredString<com.badlogic.gdx.graphics.Color> message)
      Appends a new line as an IColoredString to the message listing and scrolls to the bottom. If the message cannot fit on one line, it will be word-wrapped and one or more messages will be appended after it.
      Parameters:
      message - an IColoredString with type parameter Color; this method has no specific length restrictions
    • nudgeUp

      public void nudgeUp()
      Used internally to scroll up by one line, but can also be triggered by your code.
    • nudgeDown

      public void nudgeDown()
      Used internally to scroll down by one line, but can also be triggered by your code.
    • draw

      public void draw​(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)
      Description copied from class: SparseLayers
      Draws the SparseLayers and all glyphs it tracks. Batch.begin() must have already been called on the batch, and Batch.end() should be called after this returns and before the rendering code finishes for the frame.
      This will set the shader of batch if using a distance field or MSDF font and the shader is currently not configured for such a font; it does not reset the shader to the default so that multiple Actors can all use the same shader and so specific extra glyphs or other items can be rendered after calling draw(). If you need to draw both a distance field font and full-color art, you should set the shader on the Batch to null when you want to draw full-color art, and end the Batch between drawing this object and the other art.
      Overrides:
      draw in class SparseLayers
      Parameters:
      batch - a Batch such as a FilterBatch that must be between a begin() and end() call; usually done by Stage
      parentAlpha - currently ignored
    • setBounds

      public void setBounds​(float x, float y, float width, float height)
      Set the x, y position of the lower left corner, plus set the width and height. ACTUALLY NEEDED to make the borders clickable. It can't know the boundaries of the clickable area until it knows its own position and bounds.
      Overrides:
      setBounds in class com.badlogic.gdx.scenes.scene2d.Actor
      Parameters:
      x - x position in pixels or other units that libGDX is set to use
      y - y position in pixels or other units that libGDX is set to use
      width - the width in pixels (usually) of the message box; changes on resize
      height - the height in pixels (usually) of the message box; changes on resize