65 lines
2.4 KiB
Java
65 lines
2.4 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*/
|
|
package net.minecraft.client.gui.components;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.gui.ActiveTextCollector;
|
|
import net.minecraft.client.gui.GuiGraphics;
|
|
import net.minecraft.client.gui.components.AbstractWidget;
|
|
import net.minecraft.client.gui.components.WidgetSprites;
|
|
import net.minecraft.client.input.InputWithModifiers;
|
|
import net.minecraft.client.input.KeyEvent;
|
|
import net.minecraft.client.input.MouseButtonEvent;
|
|
import net.minecraft.client.renderer.RenderPipelines;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.resources.Identifier;
|
|
import net.minecraft.util.ARGB;
|
|
|
|
public abstract class AbstractButton
|
|
extends AbstractWidget.WithInactiveMessage {
|
|
protected static final int TEXT_MARGIN = 2;
|
|
private static final WidgetSprites SPRITES = new WidgetSprites(Identifier.withDefaultNamespace("widget/button"), Identifier.withDefaultNamespace("widget/button_disabled"), Identifier.withDefaultNamespace("widget/button_highlighted"));
|
|
|
|
public AbstractButton(int x, int y, int width, int height, Component message) {
|
|
super(x, y, width, height, message);
|
|
}
|
|
|
|
public abstract void onPress(InputWithModifiers var1);
|
|
|
|
@Override
|
|
protected final void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float a) {
|
|
this.renderContents(graphics, mouseX, mouseY, a);
|
|
this.handleCursor(graphics);
|
|
}
|
|
|
|
protected abstract void renderContents(GuiGraphics var1, int var2, int var3, float var4);
|
|
|
|
protected void renderDefaultLabel(ActiveTextCollector output) {
|
|
this.renderScrollingStringOverContents(output, this.getMessage(), 2);
|
|
}
|
|
|
|
protected final void renderDefaultSprite(GuiGraphics graphics) {
|
|
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SPRITES.get(this.active, this.isHoveredOrFocused()), this.getX(), this.getY(), this.getWidth(), this.getHeight(), ARGB.white(this.alpha));
|
|
}
|
|
|
|
@Override
|
|
public void onClick(MouseButtonEvent event, boolean doubleClick) {
|
|
this.onPress(event);
|
|
}
|
|
|
|
@Override
|
|
public boolean keyPressed(KeyEvent event) {
|
|
if (!this.isActive()) {
|
|
return false;
|
|
}
|
|
if (event.isSelection()) {
|
|
this.playDownSound(Minecraft.getInstance().getSoundManager());
|
|
this.onPress(event);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|