Class WBar
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WBar
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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @Nullable TextureThe bar texture.protected @Nullable TextureThe background texture.protected WBar.Directionprotected intThe ID of the displayed property in theproperties.protected intThe ID of the property representing the maximum value of thefield.protected intThe constant maximum value of thefield.protected net.minecraft.screen.PropertyDelegateprotected Stringprotected net.minecraft.text.Text -
Constructor Summary
ConstructorsConstructorDescriptionWBar(Texture bg, Texture bar, int field, int maxfield, WBar.Direction dir)WBar(net.minecraft.util.Identifier bg, net.minecraft.util.Identifier bar, int field, int maxfield)WBar(net.minecraft.util.Identifier bg, net.minecraft.util.Identifier bar, int field, int maxfield, WBar.Direction dir) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTooltip(TooltipBuilder information)Adds lines to this widget's tooltip.booleanChecks whether this widget can be resized usingWWidget.setSize(int, int).@Nullable net.minecraft.screen.PropertyDelegateGets the current properties of this bar.voidpaint(net.minecraft.client.util.math.MatrixStack matrices, int x, int y, int mouseX, int mouseY)Paints this widget.setProperties(net.minecraft.screen.PropertyDelegate properties)Sets the current properties of this bar.voidvalidate(GuiDescription host)Creates component peers, lays out children, and initializes animation data for this Widget and all its children.static WBarwithConstantMaximum(net.minecraft.util.Identifier bg, net.minecraft.util.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.withTooltip(String label)Adds a tooltip to the WBar.withTooltip(net.minecraft.text.Text label)Methods inherited from class io.github.cottonmc.cotton.gui.widget.WWidget
addPainters, canFocus, createPeers, cycleFocus, getAbsoluteX, getAbsoluteY, getHeight, getHost, getParent, getWidth, getX, getY, hit, isActivationKey, isFocused, isWithinBounds, onCharTyped, onClick, onFocusGained, onFocusLost, onHidden, onKeyPressed, onKeyReleased, onMouseDown, onMouseDrag, onMouseMove, onMouseScroll, onMouseUp, onShown, releaseFocus, renderTooltip, requestFocus, setHost, setLocation, setParent, setSize, tick
-
Field Details
-
bg
The background texture. If not null, it will be drawn behind the bar contents. -
bar
The bar texture. If not null, it will be drawn to represent the current field. -
field
protected final int fieldThe ID of the displayed property in theproperties. -
max
protected final int max -
maxValue
protected int maxValue -
properties
protected net.minecraft.screen.PropertyDelegate properties -
direction
-
tooltipLabel
-
tooltipTextComponent
protected net.minecraft.text.Text tooltipTextComponent
-
-
Constructor Details
-
WBar
-
WBar
-
WBar
public WBar(net.minecraft.util.Identifier bg, net.minecraft.util.Identifier bar, int field, int maxfield) -
WBar
public WBar(net.minecraft.util.Identifier bg, net.minecraft.util.Identifier bar, int field, int maxfield, WBar.Direction dir)
-
-
Method Details
-
withTooltip
Adds a tooltip to the WBar. Formatting Guide: The tooltip label is passed intoString.formatand 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
-
canResize
public boolean canResize()Description copied from class:WWidgetChecks whether this widget can be resized usingWWidget.setSize(int, int). -
paint
@Environment(CLIENT) public void paint(net.minecraft.client.util.math.MatrixStack matrices, int x, int y, int mouseX, int mouseY)Description copied from class:WWidgetPaints this widget. -
addTooltip
Description copied from class:WWidgetAdds lines to this widget's tooltip. If the lines remain empty after this call, no tooltip will be drawn.- Overrides:
addTooltipin classWWidget- Parameters:
information- the builder to add tooltip lines to
-
validate
Description copied from class:WWidgetCreates 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. -
getProperties
@Nullable public @Nullable net.minecraft.screen.PropertyDelegate getProperties()Gets the current properties of this bar.- Returns:
- the current property delegate, or null if not initialized yet
-
setProperties
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(net.minecraft.util.Identifier bg, net.minecraft.util.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 barbar- the foreground image that represents the filled barfield- the field index for bar valuesmaxValue- the constant maximum value for the bardir- the direction the bar should grow towards- Returns:
- a new WBar with a constant maximum value.
-