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
Modifier and TypeClassDescriptionstatic enum
The direction of aWBar
, representing where the bar will grown when its field increases. -
Field Summary
Modifier and TypeFieldDescriptionThe bar texture.The background texture.protected final WBar.Direction
The direction of this bar, representing where the bar will grow when the field increases.protected final int
The ID of the displayed property in theproperties
.protected final int
The ID of the property representing the maximum value of thefield
.protected int
The constant maximum value of thefield
.protected PropertyDelegate
The properties used for painting this bar.protected String
The translation key of the tooltip.protected Text
A tooltip text component. -
Constructor Summary
ConstructorDescriptionWBar
(Identifier bg, Identifier bar, int field, int maxField) WBar
(Identifier bg, Identifier bar, int field, int maxField, WBar.Direction dir) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addTooltip
(TooltipBuilder information) Adds lines to this widget's tooltip.boolean
Checks whether this widget can be resized usingWWidget.setSize(int, int)
.Gets the current properties of this bar.void
paint
(DrawContext context, int x, int y, int mouseX, int mouseY) Paints this widget.setProperties
(PropertyDelegate properties) Sets the current properties of this bar.void
validate
(GuiDescription host) Creates component peers and initializes animation data for this Widget and all its children.static WBar
withConstantMaximum
(Texture bg, Texture 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.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.withTooltip
(String label) Adds a tooltip to the WBar.withTooltip
(Text label) Adds a tooltipText
to the WBar.Methods inherited from class io.github.cottonmc.cotton.gui.widget.WWidget
addNarrations, addPainters, canFocus, canHover, getAbsoluteX, getAbsoluteY, getFocusModel, getHeight, getHost, getParent, getWidth, getX, getY, hit, hoveredProperty, isActivationKey, isFocused, isHovered, isNarratable, isWithinBounds, onCharTyped, onClick, onFocusGained, onFocusLost, onHidden, onKeyPressed, onKeyReleased, onMouseDown, onMouseDrag, onMouseMove, onMouseScroll, onMouseUp, onShown, releaseFocus, renderTooltip, requestFocus, setHost, setHovered, setLocation, setParent, setSize, shouldRenderInDarkMode, 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- See Also:
-
properties
-
direction
The direction of this bar, representing where the bar will grow when the field increases. -
tooltipLabel
The translation key of the tooltip.- See Also:
-
tooltipTextComponent
A tooltip text component. This can be used instead oftooltipLabel
, or together with it. In that case, this component will be drawn after the other label.
-
-
Constructor Details
-
WBar
-
WBar
-
WBar
-
WBar
-
-
Method Details
-
withTooltip
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
- the translation key of the string to render on the tooltip- Returns:
- this bar with tooltip enabled and set
-
withTooltip
Adds a tooltipText
to the WBar.- Parameters:
label
- the added tooltip label- Returns:
- this bar
-
canResize
public boolean canResize()Description copied from class:WWidget
Checks whether this widget can be resized usingWWidget.setSize(int, int)
. -
paint
Description copied from class:WWidget
Paints this widget. -
addTooltip
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 classWWidget
- Parameters:
information
- the builder to add tooltip lines to
-
validate
Description copied from class:WWidget
Creates component peers and initializes animation data for this Widget and all its children. The host screen handler must clear any heavyweight peers from its records before this method is called.This method must be called on the root panel of any screen once the widgets have been initialized.
-
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(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 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
-
withConstantMaximum
public static WBar withConstantMaximum(Texture bg, Texture 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
- Since:
- 4.1.0
-