java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WBar

public class WBar extends WWidget
A bar that displays int values from a PropertyDelegate.

Bars can be used for all kinds of bars including progress bars (and progress arrows) and energy bars.

  • Field Details

    • bg

      @Nullable protected final @Nullable Texture bg
      The background texture. If not null, it will be drawn behind the bar contents.
    • bar

      @Nullable protected final @Nullable Texture bar
      The bar texture. If not null, it will be drawn to represent the current field.
    • field

      protected final int field
      The ID of the displayed property in the properties.
    • max

      protected final int max
      The ID of the property representing the maximum value of the field.

      If max is 0, the maxValue constant will be used instead.

    • maxValue

      protected int maxValue
      The constant maximum value of the field.

      This constant will only be used if max is 0.

      See Also:
      withConstantMaximum(Identifier, Identifier, int, int, Direction)
    • properties

      protected PropertyDelegate properties
    • direction

      protected final WBar.Direction direction
    • tooltipLabel

      protected String tooltipLabel
    • tooltipTextComponent

      protected Text tooltipTextComponent
  • Constructor Details

  • Method Details

    • withTooltip

      public WBar withTooltip(String label)
      Adds a tooltip to the WBar. Formatting Guide: The tooltip label is passed into String.format and can receive two integers (%d) - the first is the current value of the bar's focused field, and the second is the bar's focused maximum.
      Parameters:
      label - Translation key of the string to render on the tooltip.
      Returns:
      WBar with tooltip enabled and set.
    • withTooltip

      public WBar withTooltip(Text label)
    • canResize

      public boolean canResize()
      Description copied from class: WWidget
      Checks whether this widget can be resized using WWidget.setSize(int, int).
      Overrides:
      canResize in class WWidget
      Returns:
      true if this widget can be resized, false otherwise
    • paint

      @Environment(CLIENT) public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY)
      Description copied from class: WWidget
      Paints this widget.
      Overrides:
      paint in class WWidget
      Parameters:
      matrices - the rendering matrix stack
      x - this widget's X coordinate on the screen
      y - this widget's Y coordinate on the screen
      mouseX - the X coordinate of the cursor
      mouseY - the X coordinate of the cursor
    • addTooltip

      @Environment(CLIENT) public void addTooltip(TooltipBuilder information)
      Description copied from class: WWidget
      Adds lines to this widget's tooltip. If the lines remain empty after this call, no tooltip will be drawn.
      Overrides:
      addTooltip in class WWidget
      Parameters:
      information - the builder to add tooltip lines to
    • validate

      public void validate(GuiDescription host)
      Description copied from class: WWidget
      Creates component peers, lays out children, and initializes animation data for this Widget and all its children. The host container must clear any heavyweight peers from its records before this method is called.
      Overrides:
      validate in class WWidget
      Parameters:
      host - the host GUI description
    • getProperties

      @Nullable public @Nullable PropertyDelegate getProperties()
      Gets the current properties of this bar.
      Returns:
      the current property delegate, or null if not initialized yet
    • setProperties

      public WBar setProperties(PropertyDelegate properties)
      Sets the current properties of this bar.

      This method is meant for situations when a GUI description is unavailable (such as HUDs). GuiDescription.getPropertyDelegate() should be preferred over this if available.

      Parameters:
      properties - the properties
      Returns:
      this bar
    • withConstantMaximum

      public static WBar withConstantMaximum(Identifier bg, Identifier bar, int field, int maxValue, WBar.Direction dir)
      Creates a WBar that has a constant maximum-value instead of getting the maximum from a field.
      Parameters:
      bg - the background image to use for the bar
      bar - the foreground image that represents the filled bar
      field - the field index for bar values
      maxValue - the constant maximum value for the bar
      dir - the direction the bar should grow towards
      Returns:
      a new WBar with a constant maximum value.