Example #1
0
 @Override
 public String getText() {
   try {
     return String.format(source.getText(), currentThemeName);
   } catch (IllegalFormatException e) {
     CraftGuideLog.log(e);
     return "Current theme: " + currentThemeName;
   }
 }
Example #2
0
    public ConfigEntry(TextSource text, GuiElement element, int pos) {
      super(0, pos, ConfigList.this.width(), 0);

      this.element = element;
      textDisplay =
          new MultilineText(
              BORDER_THICKNESS + element.width() + BORDER_THICKNESS, BORDER_THICKNESS, null);
      translatedText = text;
      translatedText.addListener(this);
      addElement(element);
      recalculateHeight();
    }
Example #3
0
    private void recalculateHeight() {
      int textLeft = BORDER_THICKNESS + element.width() + BORDER_THICKNESS;
      int textRight = ConfigEntry.this.width() - BORDER_THICKNESS;

      String[] lines = layoutText(translatedText.getText(), textRight - textLeft);
      textDisplay.setText(lines);

      int textHeight = lines.length * 10 + BORDER_THICKNESS * 2;
      int elementHeight = element.height() + BORDER_THICKNESS * 2;
      int height = Math.max(textHeight, elementHeight);

      setSize(width(), height);

      if (textHeight > elementHeight) {
        textDisplay.setPosition(textLeft, BORDER_THICKNESS);
        element.setPosition(BORDER_THICKNESS, (height - element.height()) / 2);
      } else {
        textDisplay.setPosition(textLeft, (height - lines.length * 10 + 1) / 2);
        element.setPosition(BORDER_THICKNESS, BORDER_THICKNESS);
      }
    }
Example #4
0
 public CurrentThemeTextSource() {
   source = new TranslatedTextSource("craftguide.gui.config.current_theme.format_string");
   source.addListener(this);
 }