Class UITextField

java.lang.Object
net.risingworld.api.ui.UIElement
net.risingworld.api.ui.UITextField
All Implemented Interfaces:
Serializable

public class UITextField extends UIElement
Represents a text field, i.e an element where the player can enter text.
See Also:
  • Constructor Details

    • UITextField

      public UITextField()
      Creates a new, empty text field.
    • UITextField

      public UITextField(String initialText)
      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

      public void setText(String text)
      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 (see setMasked(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

      public void getCurrentText(Player player, Callback<String> callback)
      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
      1textField.getCurrentText(player, (String txt) -> {
      2 System.out.println("Text: " + txt);
      3});