Package net.risingworld.api.ui
Class UITextField
java.lang.Object
net.risingworld.api.ui.UIElement
net.risingworld.api.ui.UITextField
Represents a text field, i.e an element where the player can enter text.
-
Field Summary
Fields inherited from class net.risingworld.api.ui.UIElement
hoverStyle, style
-
Constructor Summary
ConstructorDescriptionCreates a new, empty text field.UITextField
(String initialText) Creates a new text field and sets an initial text. -
Method Summary
Modifier and TypeMethodDescriptionvoid
getCurrentText
(Player player, Callback<String> callback) Gets the current text of the textfield.char
int
Gets the max number of allowed characters in this text field.boolean
isMasked()
Gets whether or not masking is currently enabled, i.e if all characters should be replaced by a mask character automatically.boolean
boolean
Gets whether or not the text field is in read-only mode.void
setFontColor
(float r, float g, float b, float a) Sets a font color for the text field.void
setFontColor
(int rgba) Sets a font color for the label.void
setFontSize
(float size) Sets the font size for the text field.void
setMasked
(boolean set) If set to true, individual characters entered into the text field will be masked.void
setMaskedCharacter
(char c) If the text field is masked (seesetMasked(boolean)
), this determines the character that should replace the original characters.void
setMaxCharacters
(int length) Sets the max number of allowed characters in this text field.void
setMultiLine
(boolean set) Determines if the text field should support multi-line input, i.e if the player should be able to enter multiple lines of text.void
setReadOnly
(boolean set) If set to true, the player will no longer be able to change the text of the text field.void
Sets the text of the text field.Methods inherited from class net.risingworld.api.ui.UIElement
addChild, addStyleSheet, addToClassList, getChildCount, getChilds, getID, getParent, getPluginID, isClickable, onClick, removeAllChilds, removeChild, removeFromClassList, removeFromParent, removeStyleSheet, resetPivot, resetPosition, setBackgroundColor, setBackgroundColor, setBorder, setBorderColor, setBorderColor, setBorderEdgeRadius, setClickable, setOpacity, setPickable, setPivot, setPosition, setSize, setVisible, updateStyle
-
Constructor Details
-
UITextField
public UITextField()Creates a new, empty text field. -
UITextField
Creates a new text field and sets an initial text.- Parameters:
initialText
- the initial text you want to set for this text field.
-
-
Method Details
-
setText
Sets the text of the text field.- Parameters:
text
- the new text you want to set.
-
setMultiLine
public void setMultiLine(boolean set) Determines if the text field should support multi-line input, i.e if the player should be able to enter multiple lines of text. Disabled by default.- Parameters:
set
- true to enable multi-line, false to disable it (single-lined text field)
-
isMultiLine
public boolean isMultiLine() -
setReadOnly
public void setReadOnly(boolean set) If set to true, the player will no longer be able to change the text of the text field.- Parameters:
set
- true to set the text field to read-only, false to allow the player to enter text.
-
isReadOnly
public boolean isReadOnly()Gets whether or not the text field is in read-only mode.- Returns:
- true if the text field is read-only (i.e the player cannot modify it), false if not (default).
-
setMasked
public void setMasked(boolean set) If set to true, individual characters entered into the text field will be masked. Useful for password fields, for example. Disabled by default.- Parameters:
set
- true to replace all characters in the text field with a masked character (e.g '*'), false to disable this behaviour.- See Also:
-
isMasked
public boolean isMasked()Gets whether or not masking is currently enabled, i.e if all characters should be replaced by a mask character automatically.- Returns:
- true if masking is enabled, false if not.
-
setMaskedCharacter
public void setMaskedCharacter(char c) If the text field is masked (seesetMasked(boolean)
), this determines the character that should replace the original characters. By default the masked character is '*'- Parameters:
c
- the new mask character you want to set for the text field (only relevant if text field is masked).
-
getMaskedCharacter
public char getMaskedCharacter() -
setMaxCharacters
public void setMaxCharacters(int length) Sets the max number of allowed characters in this text field. Set to -1 for no limit (default).- Parameters:
length
- the max length of the text (number of characters) that could be entered into the text field.
-
getMaxCharacters
public int getMaxCharacters()Gets the max number of allowed characters in this text field.- Returns:
- the number of allowed characters, or -1 if there is no limit.
-
setFontSize
public void setFontSize(float size) Sets the font size for the text field. Please note that Unity currently only supports pixel values for text fields.
Note: This is just a helper method. Internally it only changes the style fontSize value!- Parameters:
size
- the font size in pixels.
-
setFontColor
public void setFontColor(float r, float g, float b, float a) Sets a font color for the text field.
Note: This is just a helper method. Internally it changes the style color property!- Parameters:
r
- the new red component for the font color (0-1).g
- the new green component for the font color (0-1).b
- the new blue component for the font color (0-1).a
- the new alpha component (opacity) for the font color (0-1).
-
setFontColor
public void setFontColor(int rgba) Sets a font color for the label.
Note: This is just a helper method. Internally it changes the style color property!- Parameters:
rgba
- an int RGBA value describing the new color (e.g 0xFF0000FF for fully opaque red etc).
-
getCurrentText
Gets the current text of the textfield. Since the text will be received from the client, you have to work with callbacks: The callback gets invoked once the server has queried the text field from the client.- Parameters:
player
- the player you want to get the text from.callback
- the callback which will be called once the text has been received from the client.- Example: Get text from textfield using lambda expression
-