Package com.github.tommyettinger.textra
Class TypingLabel
java.lang.Object
com.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.ui.Widget
com.github.tommyettinger.textra.TextraLabel
com.github.tommyettinger.textra.TypingLabel
- All Implemented Interfaces:
com.badlogic.gdx.scenes.scene2d.utils.Layout
An extension of
Label that progressively shows the text as if it was being typed in real time, and allows the
use of tokens in the following format: {TOKEN=PARAMETER}.-
Field Summary
FieldsModifier and TypeFieldDescriptioncom.badlogic.gdx.utils.FloatArrayprotected com.badlogic.gdx.utils.Array<com.github.tommyettinger.textra.TokenEntry>protected LayoutFields inherited from class com.github.tommyettinger.textra.TextraLabel
align, font, layout, storedText, wrap -
Constructor Summary
ConstructorsConstructorDescriptionTypingLabel(String text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style)TypingLabel(String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin)TypingLabel(String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, String styleName)TypingLabel(String text, Font font)TypingLabel(String text, Font font, com.badlogic.gdx.graphics.Color color) -
Method Summary
Modifier and TypeMethodDescriptionvoidact(float delta)voidCancels calls toskipToTheEnd().voidRemoves all variables from this label.voiddraw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)If your font usesFont.DistanceFieldType.SDForFont.DistanceFieldType.MSDF, then this has to do some extra work to use the appropriate shader.com.badlogic.gdx.graphics.ColorReturns aColorinstance with the color to be used onCLEARCOLORtokens.Returns the default token being used in this label.longgetFromIntermediate(int index)longgetInLayout(Layout layout, int index)Similar toLayout.toString(), but returns the original text with all the tokens unchanged.floatfloatReturns theTypingListenerassociated with this label.Returns anObjectMapwith all the variable names and their respective replacement values.booleanhasEnded()Returns whether or not this label's char progression has ended.booleanisPaused()Returns whether or not this label is paused.booleanReturns whether or not this label is currently skipping its typing progression all the way to the end.voidlayout()voidParses all tokens of this label.voidpause()Pauses this label's character progression.booleanremove()voidrestart()Restarts this label with the original text and starts the char progression right away.voidRestarts this label with the given text and starts the char progression right away.protected voidRestores the original text with all tokens unchanged to this label.voidresume()Resumes this label's character progression.protected voidsaveOriginalText(CharSequence text)Copies the content ofgetOriginalText()to theStringBuildercontaining the original text with all tokens unchanged.voidsetDefaultToken(String defaultToken)Sets the default token being used in this label.voidsetInLayout(Layout layout, int index, long newGlyph)voidsetInLayouts(int index, long newGlyph)voidsetIntermediateText(CharSequence text, boolean modifyOriginalText, boolean restart)voidsetSize(float width, float height)voidModifies the text of this label.protected voidSets the text of this label.protected voidSets the text of this label.voidsetTypingListener(TypingListener listener)Sets theTypingListenerassociated with this label, ornullto remove the current one.voidsetVariable(String var, String value)Registers a variable and its respective replacement value to this label.voidsetVariables(com.badlogic.gdx.utils.ObjectMap<String,String> variableMap)Registers a set of variables and their respective replacement values to this label.voidsetVariables(Map<String,String> variableMap)Registers a set of variables and their respective replacement values to this label.voidSkips the char progression to the end, showing the entire label.voidskipToTheEnd(boolean ignoreEvents)Skips the char progression to the end, showing the entire label.voidskipToTheEnd(boolean ignoreEvents, boolean ignoreEffects)Skips the char progression to the end, showing the entire label.toString()Methods inherited from class com.github.tommyettinger.textra.TextraLabel
getAlignment, isWrap, setAlignment, setWrapMethods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validateMethods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clear, 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, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, scaleChanged, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setStage, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront
-
Field Details
-
tokenEntries
protected final com.badlogic.gdx.utils.Array<com.github.tommyettinger.textra.TokenEntry> tokenEntries -
workingLayout
-
offsets
public final com.badlogic.gdx.utils.FloatArray offsets
-
-
Constructor Details
-
TypingLabel
public TypingLabel() -
TypingLabel
-
TypingLabel
-
TypingLabel
-
TypingLabel
-
TypingLabel
-
-
Method Details
-
setText
Modifies the text of this label. If the char progression is already running, it's highly recommended to userestart(String)instead.- Overrides:
setTextin classTextraLabel- Parameters:
newText- a String that can contain Font markup
-
setText
Sets the text of this label.- Parameters:
modifyOriginalText- Flag determining if the original text should be modified as well. Iffalse, only the display text is changed while the original text is untouched. Iftrue, then this runsParser.preprocess(CharSequence)on the text, which should only generally be run once per original text.- See Also:
restart(String)
-
setText
Sets the text of this label.- Parameters:
modifyOriginalText- Flag determining if the original text should be modified as well. Iffalse, only the display text is changed while the original text is untouched.restart- Whether or not this label should restart. Defaults to true.- See Also:
restart(String)
-
getOriginalText
Similar toLayout.toString(), but returns the original text with all the tokens unchanged. -
saveOriginalText
Copies the content ofgetOriginalText()to theStringBuildercontaining the original text with all tokens unchanged. -
restoreOriginalText
protected void restoreOriginalText()Restores the original text with all tokens unchanged to this label. Make sure to callparseTokens()to parse the tokens again. -
getTypingListener
Returns theTypingListenerassociated with this label. May benull. -
setTypingListener
Sets theTypingListenerassociated with this label, ornullto remove the current one. -
getClearColor
public com.badlogic.gdx.graphics.Color getClearColor()Returns aColorinstance with the color to be used onCLEARCOLORtokens. Modify this instance to change the token color. Default value is specified byTypingConfig.- See Also:
TypingConfig.DEFAULT_CLEAR_COLOR
-
getDefaultToken
Returns the default token being used in this label. Defaults to empty string. -
setDefaultToken
Sets the default token being used in this label. This token will be used before the label's text, and after each {RESET} call. Useful if you want a certain token to be active at all times without having to type it all the time. -
parseTokens
public void parseTokens()Parses all tokens of this label. Use this after setting the text and any variables that should be replaced. -
skipToTheEnd
public void skipToTheEnd()Skips the char progression to the end, showing the entire label. Useful for when users don't want to wait for too long. Ignores all subsequent events by default. -
skipToTheEnd
public void skipToTheEnd(boolean ignoreEvents)Skips the char progression to the end, showing the entire label. Useful for when users don't want to wait for too long.- Parameters:
ignoreEvents- Iftrue, skipped events won't be reported to the listener.
-
skipToTheEnd
public void skipToTheEnd(boolean ignoreEvents, boolean ignoreEffects)Skips the char progression to the end, showing the entire label. Useful for when users don't want to wait for too long.- Parameters:
ignoreEvents- Iftrue, skipped events won't be reported to the listener.ignoreEffects- Iftrue, all text effects will be instantly cancelled.
-
cancelSkipping
public void cancelSkipping()Cancels calls toskipToTheEnd(). Useful if you need to restore the label's normal behavior at some event after skipping. -
isSkipping
public boolean isSkipping()Returns whether or not this label is currently skipping its typing progression all the way to the end. This is only true if skipToTheEnd is called. -
isPaused
public boolean isPaused()Returns whether or not this label is paused. -
pause
public void pause()Pauses this label's character progression. -
resume
public void resume()Resumes this label's character progression. -
hasEnded
public boolean hasEnded()Returns whether or not this label's char progression has ended. -
restart
public void restart()Restarts this label with the original text and starts the char progression right away. All tokens are automatically parsed. -
restart
Restarts this label with the given text and starts the char progression right away. All tokens are automatically parsed. -
getVariables
Returns anObjectMapwith all the variable names and their respective replacement values. -
setVariable
Registers a variable and its respective replacement value to this label. -
setVariables
Registers a set of variables and their respective replacement values to this label. -
setVariables
Registers a set of variables and their respective replacement values to this label. -
clearVariables
public void clearVariables()Removes all variables from this label. -
getPrefWidth
public float getPrefWidth()- Specified by:
getPrefWidthin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
getPrefWidthin classTextraLabel
-
getPrefHeight
public float getPrefHeight()- Specified by:
getPrefHeightin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
getPrefHeightin classTextraLabel
-
act
public void act(float delta)- Overrides:
actin classcom.badlogic.gdx.scenes.scene2d.Actor
-
remove
public boolean remove()- Overrides:
removein classcom.badlogic.gdx.scenes.scene2d.Actor
-
setSize
public void setSize(float width, float height)- Overrides:
setSizein classTextraLabel
-
layout
public void layout()- Specified by:
layoutin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
layoutin classTextraLabel
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)If your font usesFont.DistanceFieldType.SDForFont.DistanceFieldType.MSDF, then this has to do some extra work to use the appropriate shader. IfFont.enableShader(Batch)was called before rendering a group of TypingLabels, then they will try to share one Batch; otherwise this will change the shader to render SDF or MSDF, then change it back at the end of each draw() call.- Overrides:
drawin classTextraLabel- Parameters:
batch-parentAlpha-
-
toString
- Overrides:
toStringin classcom.badlogic.gdx.scenes.scene2d.Actor
-
setIntermediateText
-
getIntermediateText
-
getInLayout
-
getFromIntermediate
public long getFromIntermediate(int index) -
setInLayout
-
setInLayouts
public void setInLayouts(int index, long newGlyph)
-