Package net.minecraft.client.gui.widget
Class AbstractButtonWidget
java.lang.Object
net.minecraft.client.gui.DrawableHelper
net.minecraft.client.gui.widget.AbstractButtonWidget
- Direct Known Subclasses:
AbstractPressableButtonWidget
,AnimatedResultButton
,GameModeSelectionScreen.ButtonWidget
,RecipeAlternativesWidget.AlternativeButtonWidget
,SliderWidget
,TextFieldWidget
,ToggleButtonWidget
@Environment(CLIENT) public abstract class AbstractButtonWidget extends DrawableHelper implements Drawable, Element
-
Field Summary
Fields Modifier and Type Field Description boolean
active
protected float
alpha
private boolean
focused
protected int
height
protected boolean
hovered
private Text
message
protected long
nextNarration
boolean
visible
private boolean
wasHovered
static Identifier
WIDGETS_LOCATION
protected int
width
int
x
int
y
Fields inherited from class net.minecraft.client.gui.DrawableHelper
GUI_ICONS_TEXTURE, OPTIONS_BACKGROUND_TEXTURE, STATS_ICON_TEXTURE
-
Constructor Summary
Constructors Constructor Description AbstractButtonWidget(int x, int y, int width, int height, Text message)
-
Method Summary
Modifier and Type Method Description boolean
changeFocus(boolean lookForwards)
Changes the focusing element by cycling to the next/previous element.protected boolean
clicked(double mouseX, double mouseY)
int
getHeight()
Text
getMessage()
protected MutableText
getNarrationMessage()
int
getWidth()
protected int
getYImage(boolean hovered)
boolean
isFocused()
boolean
isHovered()
boolean
isMouseOver(double mouseX, double mouseY)
Checks if the mouse position is within the bound of the element.protected boolean
isValidClickButton(int button)
boolean
mouseClicked(double mouseX, double mouseY, int button)
Callback for when a mouse button down event has been captured.boolean
mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY)
Callback for when a mouse button drag event has been captured.boolean
mouseReleased(double mouseX, double mouseY, int button)
Callback for when a mouse button release event has been captured.protected void
narrate()
void
onClick(double mouseX, double mouseY)
protected void
onDrag(double mouseX, double mouseY, double deltaX, double deltaY)
protected void
onFocusedChanged(boolean bool)
void
onRelease(double mouseX, double mouseY)
void
playDownSound(SoundManager soundManager)
void
queueNarration(int delay)
void
render(MatrixStack matrices, int mouseX, int mouseY, float delta)
protected void
renderBg(MatrixStack matrices, MinecraftClient client, int mouseX, int mouseY)
void
renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta)
void
renderToolTip(MatrixStack matrices, int mouseX, int mouseY)
void
setAlpha(float value)
protected void
setFocused(boolean focused)
void
setMessage(Text text)
void
setWidth(int value)
Methods inherited from class net.minecraft.client.gui.DrawableHelper
drawCenteredString, drawCenteredText, drawHorizontalLine, drawSprite, drawStringWithShadow, drawTexture, drawTexture, drawTexture, drawTexture, drawTextWithShadow, drawVerticalLine, fill, fillGradient, fillGradient, getZOffset, method_29343, setZOffset
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.minecraft.client.gui.Element
charTyped, keyPressed, keyReleased, mouseMoved, mouseScrolled
-
Field Details
-
WIDGETS_LOCATION
-
width
protected int width -
height
protected int height -
x
public int x -
y
public int y -
message
-
wasHovered
private boolean wasHovered -
hovered
protected boolean hovered -
active
public boolean active -
visible
public boolean visible -
alpha
protected float alpha -
nextNarration
protected long nextNarration -
focused
private boolean focused
-
-
Constructor Details
-
AbstractButtonWidget
-
-
Method Details
-
getHeight
public int getHeight() -
getYImage
protected int getYImage(boolean hovered) -
render
-
narrate
protected void narrate() -
getNarrationMessage
-
renderButton
-
renderBg
-
onClick
public void onClick(double mouseX, double mouseY) -
onRelease
public void onRelease(double mouseX, double mouseY) -
onDrag
protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) -
mouseClicked
public boolean mouseClicked(double mouseX, double mouseY, int button)Callback for when a mouse button down event has been captured. The button number is identified by the constants inGLFW
class.- Specified by:
mouseClicked
in interfaceElement
- Parameters:
mouseX
- the X coordinate of the mousemouseY
- the Y coordinate of the mousebutton
- the mouse button number- Returns:
true
to indicate that the event handling is successful/valid- See Also:
Mouse.onMouseButton(long, int, int, int)
,GLFW.GLFW_MOUSE_BUTTON_1
-
mouseReleased
public boolean mouseReleased(double mouseX, double mouseY, int button)Callback for when a mouse button release event has been captured. The button number is identified by the constants inGLFW
class.- Specified by:
mouseReleased
in interfaceElement
- Parameters:
mouseX
- the X coordinate of the mousemouseY
- the Y coordinate of the mousebutton
- the mouse button number- Returns:
true
to indicate that the event handling is successful/valid- See Also:
Mouse.onMouseButton(long, int, int, int)
,GLFW.GLFW_MOUSE_BUTTON_1
-
isValidClickButton
protected boolean isValidClickButton(int button) -
mouseDragged
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY)Callback for when a mouse button drag event has been captured. The button number is identified by the constants inGLFW
class.- Specified by:
mouseDragged
in interfaceElement
- Parameters:
mouseX
- the current X coordinate of the mousemouseY
- the current Y coordinate of the mousebutton
- the mouse button numberdeltaX
- the difference of the current X with the previous X coordinatedeltaY
- the difference of the current Y with the previous Y coordinate- Returns:
true
to indicate that the event handling is successful/valid- See Also:
Mouse.onCursorPos(long, double, double)
,GLFW.GLFW_MOUSE_BUTTON_1
-
clicked
protected boolean clicked(double mouseX, double mouseY) -
isHovered
public boolean isHovered() -
changeFocus
public boolean changeFocus(boolean lookForwards)Changes the focusing element by cycling to the next/previous element. This action is done typically when the user has pressed the 'Tab' or 'Ctrl+Tab' key.- Specified by:
changeFocus
in interfaceElement
- Parameters:
lookForwards
-true
to cycle forwards, otherwise cycle backwards- Returns:
true
to indicate that the event handling is successful/valid
-
onFocusedChanged
protected void onFocusedChanged(boolean bool) -
isMouseOver
public boolean isMouseOver(double mouseX, double mouseY)Checks if the mouse position is within the bound of the element.- Specified by:
isMouseOver
in interfaceElement
- Parameters:
mouseX
- the X coordinate of the mousemouseY
- the Y coordinate of the mouse- Returns:
true
if the mouse is within the bound of the element, otherwisefalse
-
renderToolTip
-
playDownSound
-
getWidth
public int getWidth() -
setWidth
public void setWidth(int value) -
setAlpha
public void setAlpha(float value) -
setMessage
-
queueNarration
public void queueNarration(int delay) -
getMessage
-
isFocused
public boolean isFocused() -
setFocused
protected void setFocused(boolean focused)
-