66 lines
		
	
	
	
		
			2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
	
		
			2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package net.minecraft.client.gui.components;
 | |
| 
 | |
| import net.fabricmc.api.EnvType;
 | |
| import net.fabricmc.api.Environment;
 | |
| import net.minecraft.client.Minecraft;
 | |
| import net.minecraft.client.gui.Font;
 | |
| import net.minecraft.client.gui.GuiGraphics;
 | |
| import net.minecraft.client.gui.navigation.CommonInputs;
 | |
| import net.minecraft.client.renderer.RenderPipelines;
 | |
| import net.minecraft.network.chat.Component;
 | |
| import net.minecraft.resources.ResourceLocation;
 | |
| import net.minecraft.util.ARGB;
 | |
| 
 | |
| @Environment(EnvType.CLIENT)
 | |
| public abstract class AbstractButton extends AbstractWidget {
 | |
| 	protected static final int TEXT_MARGIN = 2;
 | |
| 	private static final WidgetSprites SPRITES = new WidgetSprites(
 | |
| 		ResourceLocation.withDefaultNamespace("widget/button"),
 | |
| 		ResourceLocation.withDefaultNamespace("widget/button_disabled"),
 | |
| 		ResourceLocation.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();
 | |
| 
 | |
| 	@Override
 | |
| 	protected void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
 | |
| 		Minecraft minecraft = Minecraft.getInstance();
 | |
| 		guiGraphics.blitSprite(
 | |
| 			RenderPipelines.GUI_TEXTURED,
 | |
| 			SPRITES.get(this.active, this.isHoveredOrFocused()),
 | |
| 			this.getX(),
 | |
| 			this.getY(),
 | |
| 			this.getWidth(),
 | |
| 			this.getHeight(),
 | |
| 			ARGB.white(this.alpha)
 | |
| 		);
 | |
| 		int i = ARGB.color(this.alpha, this.active ? -1 : -6250336);
 | |
| 		this.renderString(guiGraphics, minecraft.font, i);
 | |
| 	}
 | |
| 
 | |
| 	public void renderString(GuiGraphics guiGraphics, Font font, int color) {
 | |
| 		this.renderScrollingString(guiGraphics, font, 2, color);
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public void onClick(double mouseX, double mouseY) {
 | |
| 		this.onPress();
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
 | |
| 		if (!this.active || !this.visible) {
 | |
| 			return false;
 | |
| 		} else if (CommonInputs.selected(keyCode)) {
 | |
| 			this.playDownSound(Minecraft.getInstance().getSoundManager());
 | |
| 			this.onPress();
 | |
| 			return true;
 | |
| 		} else {
 | |
| 			return false;
 | |
| 		}
 | |
| 	}
 | |
| }
 |