2025-11-24 22:52:51 +03:00

130 lines
4.2 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* org.jspecify.annotations.Nullable
*/
package net.minecraft.client.gui.components;
import java.util.function.Supplier;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractButton;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.input.InputWithModifiers;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import org.jspecify.annotations.Nullable;
public abstract class Button
extends AbstractButton {
public static final int SMALL_WIDTH = 120;
public static final int DEFAULT_WIDTH = 150;
public static final int BIG_WIDTH = 200;
public static final int DEFAULT_HEIGHT = 20;
public static final int DEFAULT_SPACING = 8;
protected static final CreateNarration DEFAULT_NARRATION = defaultNarrationSupplier -> (MutableComponent)defaultNarrationSupplier.get();
protected final OnPress onPress;
protected final CreateNarration createNarration;
public static Builder builder(Component message, OnPress onPress) {
return new Builder(message, onPress);
}
protected Button(int x, int y, int width, int height, Component message, OnPress onPress, CreateNarration createNarration) {
super(x, y, width, height, message);
this.onPress = onPress;
this.createNarration = createNarration;
}
@Override
public void onPress(InputWithModifiers input) {
this.onPress.onPress(this);
}
@Override
protected MutableComponent createNarrationMessage() {
return this.createNarration.createNarrationMessage(() -> super.createNarrationMessage());
}
@Override
public void updateWidgetNarration(NarrationElementOutput output) {
this.defaultButtonNarrationText(output);
}
public static class Builder {
private final Component message;
private final OnPress onPress;
private @Nullable Tooltip tooltip;
private int x;
private int y;
private int width = 150;
private int height = 20;
private CreateNarration createNarration = DEFAULT_NARRATION;
public Builder(Component message, OnPress onPress) {
this.message = message;
this.onPress = onPress;
}
public Builder pos(int x, int y) {
this.x = x;
this.y = y;
return this;
}
public Builder width(int width) {
this.width = width;
return this;
}
public Builder size(int width, int height) {
this.width = width;
this.height = height;
return this;
}
public Builder bounds(int x, int y, int width, int height) {
return this.pos(x, y).size(width, height);
}
public Builder tooltip(@Nullable Tooltip tooltip) {
this.tooltip = tooltip;
return this;
}
public Builder createNarration(CreateNarration createNarration) {
this.createNarration = createNarration;
return this;
}
public Button build() {
Plain button = new Plain(this.x, this.y, this.width, this.height, this.message, this.onPress, this.createNarration);
button.setTooltip(this.tooltip);
return button;
}
}
public static interface OnPress {
public void onPress(Button var1);
}
public static interface CreateNarration {
public MutableComponent createNarrationMessage(Supplier<MutableComponent> var1);
}
public static class Plain
extends Button {
protected Plain(int x, int y, int width, int height, Component message, OnPress onPress, CreateNarration createNarration) {
super(x, y, width, height, message, onPress, createNarration);
}
@Override
protected void renderContents(GuiGraphics graphics, int mouseX, int mouseY, float a) {
this.renderDefaultSprite(graphics);
this.renderDefaultLabel(graphics.textRendererForWidget(this, GuiGraphics.HoveredTextEffects.NONE));
}
}
}