mirror of
https://github.com/JonasunderscoreJones/Microcraft.git
synced 2025-10-25 12:39:21 +02:00
fix: proper button :D
This commit is contained in:
parent
4689a6fb6b
commit
6462c9ee21
2 changed files with 55 additions and 26 deletions
|
|
@ -0,0 +1,52 @@
|
|||
package me.jonasjones.microcraft.gui.widget;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.components.ImageButton;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
// todo: change everythign to spruceUI one day :P
|
||||
public class ImageBackgroundButton extends ImageButton {
|
||||
private final ResourceLocation resourceLocation;
|
||||
private final int textureWidth;
|
||||
private final int textureHeight;
|
||||
|
||||
public ImageBackgroundButton(int x, int y, int width, int height, ResourceLocation resourceLocation,
|
||||
int textureWidth, int textureHeight, OnPress onPress) {
|
||||
super(x, y, width, height, 0, 0, 0, resourceLocation, textureWidth, textureHeight, onPress);
|
||||
this.resourceLocation = resourceLocation;
|
||||
this.textureWidth = textureWidth;
|
||||
this.textureHeight = textureHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float partialTick) {
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
Font font = minecraft.font;
|
||||
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderTexture(0, WIDGETS_LOCATION);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.enableDepthTest();
|
||||
|
||||
int i = this.getYImage(this.isHoveredOrFocused());
|
||||
|
||||
this.blit(poseStack, this.getX(), this.getY(), 0, 46 + i * 20, this.width / 2, this.height);
|
||||
this.blit(poseStack, this.getX() + this.width / 2, this.getY(), 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);
|
||||
|
||||
this.renderBg(poseStack, minecraft, mouseX, mouseY);
|
||||
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderTexture(0, this.resourceLocation);
|
||||
|
||||
RenderSystem.enableDepthTest();
|
||||
blit(poseStack, this.getX(), this.getY(), 0, (float) 0, this.width, this.height,
|
||||
this.textureWidth, this.textureHeight);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package me.jonasjones.microcraft.mixin;
|
|||
|
||||
import me.jonasjones.microcraft.gui.screens.BoardScreen;
|
||||
import me.jonasjones.microcraft.gui.screens.GuiHome;
|
||||
import me.jonasjones.microcraft.gui.widget.ImageBackgroundButton;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.ImageButton;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
|
|
@ -25,26 +26,6 @@ public class TitleScreenMixin extends Screen {
|
|||
super(component);
|
||||
}
|
||||
|
||||
// @Inject(at = @At("HEAD"), method = "init")
|
||||
// private void gameMenuScreenButton(CallbackInfo ci) {
|
||||
// final ResourceLocation ICON_TEXTURE = new ResourceLocation(MOD_ID, "gui/button_icon.png");
|
||||
//
|
||||
// int buttonX = this.width / 2 + 108;
|
||||
// int buttonY = 3 * this.height / 4 + 8;
|
||||
//
|
||||
// this.addRenderableWidget(new Button.Builder(Component.empty(), (b) -> {
|
||||
// this.minecraft.setScreen(new GuiHome(this));
|
||||
// }).bounds(buttonX, buttonY, 20, 20).build());
|
||||
//
|
||||
//// this.addRenderableWidget(new ImageButton(buttonX, buttonY,
|
||||
//// 20, 20,
|
||||
//// 0, 0, 0,
|
||||
//// ICON_TEXTURE,
|
||||
//// 20, 20,
|
||||
//// (buttonWidget) -> this.minecraft.setScreen(new GuiHome(this))
|
||||
//// ));
|
||||
// }
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "createNormalMenuOptions")
|
||||
private void titleScreenButton(int y, int spacingY, CallbackInfo ci) {
|
||||
|
||||
|
|
@ -53,11 +34,7 @@ public class TitleScreenMixin extends Screen {
|
|||
int buttonX = this.width / 2 + 104;
|
||||
int buttonY = y + spacingY * 2;
|
||||
|
||||
// this.addRenderableWidget(new Button.Builder(Component.literal(""), (button) -> {
|
||||
// this.minecraft.setScreen(new BoardScreen(this));
|
||||
// }).bounds(buttonX, buttonY, 20, 20).build());
|
||||
|
||||
this.addRenderableWidget(new ImageButton(buttonX, buttonY, 20, 20, 0, 0, 0, ICON_TEXTURE, 20, 20,
|
||||
(buttonWidget) -> this.minecraft.setScreen(new BoardScreen(this))));
|
||||
this.addRenderableWidget(new ImageBackgroundButton(buttonX, buttonY, 20, 20, ICON_TEXTURE, 20, 20,
|
||||
(buttonWidget) -> this.minecraft.setScreen(new BoardScreen(this))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue