Class ExpressionTextField

java.lang.Object
org.cyclops.integrateddynamics.core.logicprogrammer.client.ExpressionTextField

public class ExpressionTextField extends Object
The text of an expression in the logic programmer.
  • Field Details

  • Constructor Details

    • ExpressionTextField

      public ExpressionTextField(net.minecraft.client.gui.Font font, int width)
      Parameters:
      font - The font.
      width - The width at which lines wrap.
  • Method Details

    • getValue

      public String getValue()
    • isDraft

      public boolean isDraft()
      Returns:
      If the text was typed, differs from the expression and is not applied yet.
    • isPrinted

      public boolean isPrinted()
      Returns:
      If the text is the text of the expression, so the tokens tell the node of each character.
    • markApplied

      public void markApplied(@Nullable Expression expression)
      Mark the text as applied, which is no draft anymore and keeps it as typed while it has focus.
      Parameters:
      expression - The expression it is applied as, or null if it is the current one.
    • showExpressionText

      public void showExpressionText()
      Show the text of the expression in place of applied text, unless the applied expression is not followed yet. The expression keeps the text it was typed as, so this only changes text that no longer reads as the expression, such as a reference whose type became known.
    • getMillisSinceEdit

      public long getMillisSinceEdit()
      Returns:
      The time since the text was last changed by typing.
    • getTokens

      public List<ExpressionPrinter.Token> getTokens()
      Returns:
      The tokens of the text of the expression, which tell the node of each character while it is shown.
    • getPrinted

      public String getPrinted()
      Returns:
      The text of the expression, as typed or printed, without a draft.
    • followDraft

      public int[] followDraft(int[] values, int typed)
      Parameters:
      values - A value for each character of the text of the expression, such as its color.
      typed - The value of the characters that were typed.
      Returns:
      A value for each character of the text, where the text before and after what was typed keeps its value.
    • followChanges

      public static int[] followChanges(String from, String to, int[] values, int changed)
      Parameters:
      from - A text.
      to - The text after a change.
      values - A value for each character of the first text.
      changed - The value of the characters that changed.
      Returns:
      A value for each character of the second text, which is the value of the same character in the first text for the characters before and after the change.
    • sync

      public void sync(Expression expression, @Nullable String text, Supplier<List<ExpressionPrinter.Token>> printer)
      Follow the given expression. A draft is kept, and is compared to the new expression from now on. Applied text is kept if this is the expression it was applied as, and is replaced by the text of the expression otherwise.
      Parameters:
      expression - The current expression.
      text - The text it was typed as, or null if it is printed.
      printer - Gives the text of the expression as tokens, only called when the expression or its text changed.
    • revert

      public void revert()
      Throw away the draft or the applied text, so the text is that of the expression.
    • reset

      public void reset()
      Forget everything, such as when another expression is opened.
    • isFocused

      public boolean isFocused()
    • setFocused

      public void setFocused(boolean focused)
    • isPressed

      public boolean isPressed()
    • setPressed

      public void setPressed(boolean pressed)
    • getCursor

      public int getCursor()
    • getCharAtCursor

      public int getCharAtCursor()
      Returns:
      The index of the character right after the cursor, or right before it at the end of a line.
    • mouseClicked

      public void mouseClicked(double x, double y)
      Place the cursor, or extend the selection while shift is held. A double click selects a word, and a triple click everything.
      Parameters:
      x - The x position, relative to the text.
      y - The y position, relative to the text.
    • mouseDragged

      public void mouseDragged(double x, double y)
      Select from the cursor to the given position.
      Parameters:
      x - The x position, relative to the text.
      y - The y position, relative to the text.
    • scroll

      public void scroll(double amount)
    • keyPressed

      public boolean keyPressed(net.minecraft.client.input.KeyEvent evt)
      Handle a key such as an arrow, backspace, or a shortcut to select, copy, cut or paste.
      Parameters:
      evt - The key.
      Returns:
      If it was handled.
    • charTyped

      public void charTyped(char character)
    • insert

      public void insert(String value)
    • replace

      public void replace(String value)
      Change the text as if it was typed, with the cursor after the part that changed.
      Parameters:
      value - The new text.
    • addParameter

      public void addParameter(ExpressionParser.Context context)
      Add a parameter to the text, as typing it would, with the cursor where the rest is typed if nothing follows the parameters yet.
      Parameters:
      context - What the parser needs to know about the world.
    • setParserContext

      public void setParserContext(Supplier<ExpressionParser.Context> parserContext)
      Parameters:
      parserContext - What the parser needs to know about the world, to find what can be completed.
    • closeCompletions

      public boolean closeCompletions()
      Returns:
      If a list was shown, which is closed now, such as by Escape.
    • keyPressedCompletion

      public boolean keyPressedCompletion(int keyCode)
      Handle a key for the shown list: Up and Down to choose an entry, and Tab or Enter to insert it.
      Parameters:
      keyCode - The key.
      Returns:
      If it was handled.
    • mouseClickedCompletion

      public boolean mouseClickedCompletion(double x, double y)
      Insert the clicked entry, if the list is shown there.
      Parameters:
      x - The x position, relative to the text.
      y - The y position, relative to the text.
      Returns:
      If the list was clicked.
    • mouseScrolledCompletion

      public boolean mouseScrolledCompletion(double x, double y, double amount)
      Move through the shown list, if the mouse is over it.
      Parameters:
      x - The x position, relative to the text.
      y - The y position, relative to the text.
      amount - The amount scrolled.
      Returns:
      If the list was scrolled.
    • isOverPopups

      public boolean isOverPopups(double mouseX, double mouseY)
      Parameters:
      mouseX - The x position on the screen.
      mouseY - The y position on the screen.
      Returns:
      If the shown list or signature is drawn there.
    • getSignature

      public static net.minecraft.network.chat.Component getSignature(IOperator operator, boolean method)
      Parameters:
      operator - An operator.
      method - If it is called as a method, so its first input is left out.
      Returns:
      Its inputs and output in the colors of their types, as in (Integer, String): Boolean.
    • getCallSignature

      public static net.minecraft.network.chat.Component getCallSignature(ExpressionParser.Call call)
      Parameters:
      call - A call that the cursor is in.
      Returns:
      Its signature in the colors of its types, with the input at the cursor underlined, as in Item.strength(Block): Double for a method, where the first input is before the point.
    • render

      public void render(net.minecraft.client.gui.GuiGraphicsExtractor guiGraphics, int x, int y, int width, int height, int[] colors, int[] backgrounds, int mark, int markEnd, int markColor)
      Parameters:
      guiGraphics - The graphics.
      x - The left of the text.
      y - The top of the text.
      width - The width of the text, including room for a scrollbar.
      height - The height of the text.
      colors - The color of each character.
      backgrounds - The background of each character, or 0 for none.
      mark - The first character to underline, such as where an error is, or -1.
      markEnd - The character after the last one to underline, which is at least the first one.
      markColor - The color of the underline.
    • renderErrorTooltip

      public void renderErrorTooltip(net.minecraft.client.gui.GuiGraphicsExtractor guiGraphics, int position, int end, net.minecraft.network.chat.Component message, int mouseX, int mouseY)
      Show the message of an error in a tooltip while the mouse is over its line, with an arrow at its position, as in Integrated Scripting's editor. Not while the list is shown, which is what is being typed in, and in place of the signature of the call at the cursor, which it would cover. Called after the text is drawn.
      Parameters:
      guiGraphics - The graphics.
      position - Where the error is.
      end - The character after the part with the error, which is at least the position.
      message - The message.
      mouseX - The x position of the mouse.
      mouseY - The y position of the mouse.
    • renderPartTooltip

      public void renderPartTooltip(net.minecraft.client.gui.GuiGraphicsExtractor guiGraphics, int start, int end, net.minecraft.network.chat.Component message, int mouseX, int mouseY)
      Show the message of an error of a part of the text in a tooltip while the mouse is over that part, with an arrow at the part on the row of the mouse, as for renderErrorTooltip(GuiGraphicsExtractor, int, int, Component, int, int).
      Parameters:
      guiGraphics - The graphics.
      start - The first character of the part.
      end - The character after the part.
      message - The message.
      mouseX - The x position of the mouse.
      mouseY - The y position of the mouse.
    • getCharAtMouse

      public int getCharAtMouse(int mouseX, int mouseY)
      Parameters:
      mouseX - The x position of the mouse.
      mouseY - The y position of the mouse.
      Returns:
      The index of the character under the mouse, or -1 if it is not over a character of the text.
    • renderPopups

      public void renderPopups(net.minecraft.client.gui.GuiGraphicsExtractor guiGraphics)
      Draw the list shown while typing, or the signature of the call at the cursor, if the text was drawn since. This is done after everything else, as slots and labels are drawn without depth, so they would cover them.
      Parameters:
      guiGraphics - The graphics, without translation.