Package squidpony.squidgrid.gui.gdx
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.
-
Field Summary
Fields Modifier and Type Field Description protected int
messageIndex
protected ArrayList<IColoredString<com.badlogic.gdx.graphics.Color>>
messages
Fields inherited from class squidpony.squidgrid.gui.gdx.SparseLayers
animationCount, backgrounds, defaultBackground, defaultForeground, defaultPackedBackground, defaultPackedForeground, font, glyphs, gridHeight, gridWidth, layers, mapping, scc
-
Constructor Summary
Constructors Constructor Description SquidMessageBox(int gridWidth, int gridHeight)
Creates a bare-bones panel with all default values for text rendering.SquidMessageBox(int gridWidth, int gridHeight, int cellWidth, int cellHeight)
Creates a panel with the given grid and cell size.SquidMessageBox(int gridWidth, int gridHeight, TextCellFactory factory)
Builds a panel with the given grid size and all other parameters determined by the factory.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. -
Method Summary
Modifier and Type Method Description void
appendMessage(String message)
The primary way of using this class.void
appendMessage(IColoredString<com.badlogic.gdx.graphics.Color> message)
A common way of using this class.void
appendWrappingMessage(String message)
Appends a new line to the message listing and scrolls to the bottom.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.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)
Draws the SparseLayers and all glyphs it tracks.void
nudgeDown()
Used internally to scroll down by one line, but can also be triggered by your code.void
nudgeUp()
Used internally to scroll up by one line, but can also be triggered by your code.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.Methods inherited from class squidpony.squidgrid.gui.gdx.SparseLayers
addLayer, addLayer, blend, bump, bump, burst, burst, burst, burst, calculateConsistentLightAmount, calculateConsistentLightModifier, calculateConsistentLightModifier, cellHeight, cellWidth, clear, clear, clear, clear, fillArea, fillArea, fillBackground, fillBackground, findLayer, getBackgrounds, getColorCenter, getDefaultBackgroundColor, getDefaultForegroundColor, getFont, getGridHeight, getGridWidth, getLayer, getLayerCount, getScc, glyph, glyph, glyphFromGrid, glyphFromGrid, gridHeight, gridWidth, gridX, gridY, hasActiveAnimations, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, putBorders, putBordersCaptioned, putChars, putChars, putChars, putWithConsistentLight, putWithConsistentLight, putWithConsistentLight, putWithConsistentLight, putWithConsistentLight, putWithConsistentLight, putWithConsistentLight, putWithConsistentLight, putWithConsistentLight, putWithLight, putWithLight, putWithLight, putWithLight, putWithLight, putWithLight, putWithLight, putWithLight, putWithLight, putWithLight, putWithLight, putWithLight, putWithReverseConsistentLight, putWithReverseConsistentLight, putWithReverseConsistentLight, putWithReverseConsistentLight, putWithReverseConsistentLight, putWithReverseLight, putWithReverseLight, recallToGrid, recallToGrid, recolor, recolor, recolor, recolor, recolor, recolor, recolor, recolor, removeGlyph, setBackgrounds, setColorCenter, setDefaultBackground, setDefaultForeground, setFont, setLayer, setScc, setTextSize, slide, slide, summon, summon, summon, summon, tint, tint, tint, tint, tint, tint, tint, tint, wiggle, wiggle, worldX, worldY
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebug, drawDebugBounds, fire, firstAscendant, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasKeyboardFocus, hasParent, hasScrollFocus, hit, isAscendantOf, isDescendantOf, isTouchable, isTouchFocusListener, isTouchFocusTarget, isVisible, localToActorCoordinates, localToAscendantCoordinates, localToParentCoordinates, localToScreenCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, screenToLocalCoordinates, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setStage, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, sizeChanged, stageToLocalCoordinates, toBack, toFront, toString
-
Field Details
-
Constructor Details
-
SquidMessageBox
Creates a bare-bones panel with all default values for text rendering.- Parameters:
gridWidth
- the number of cells horizontallygridHeight
- the number of cells vertically, must be at least 3
-
SquidMessageBox
Creates a panel with the given grid and cell size. Uses a default square font.- Parameters:
gridWidth
- the number of cells horizontallygridHeight
- the number of cells verticallycellWidth
- the number of horizontal pixels in each cellcellHeight
- the number of vertical pixels in each cell
-
SquidMessageBox
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 horizontallygridHeight
- the number of cells verticallyfactory
- 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 horizontallygridHeight
- the number of cells verticallyfactory
- the factory to use for cell renderingcenter
- ignored.
-
-
Method Details
-
appendMessage
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
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
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
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
Used internally to scroll up by one line, but can also be triggered by your code. -
nudgeDown
Used internally to scroll down by one line, but can also be triggered by your code. -
draw
Description copied from class:SparseLayers
Draws the SparseLayers and all glyphs it tracks.Batch.begin()
must have already been called on the batch, andBatch.end()
should be called after this returns and before the rendering code finishes for the frame.
This will set the shader ofbatch
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 classSparseLayers
- Parameters:
batch
- a Batch such as aFilterBatch
that must be between a begin() and end() call; usually done by StageparentAlpha
- currently ignored
-
setBounds
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 classcom.badlogic.gdx.scenes.scene2d.Actor
- Parameters:
x
- x position in pixels or other units that libGDX is set to usey
- y position in pixels or other units that libGDX is set to usewidth
- the width in pixels (usually) of the message box; changes on resizeheight
- the height in pixels (usually) of the message box; changes on resize
-