Cleanup SideButton a bit.

This commit is contained in:
raoulvdberge
2020-09-05 15:14:09 +02:00
parent 8c84e703c1
commit cbf6a22b2f
2 changed files with 14 additions and 8 deletions

View File

@@ -264,10 +264,10 @@ public abstract class BaseScreen<T extends Container> extends ContainerScreen<T>
} }
public void addSideButton(SideButton button) { public void addSideButton(SideButton button) {
button.x = guiLeft + -SideButton.WIDTH - 2; button.x = guiLeft - button.getWidth() - 2;
button.y = guiTop + sideButtonY; button.y = guiTop + sideButtonY;
sideButtonY += SideButton.HEIGHT + 2; sideButtonY += button.getHeight() + 2;
this.addButton(button); this.addButton(button);
} }

View File

@@ -10,14 +10,16 @@ import net.minecraft.util.text.StringTextComponent;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
public abstract class SideButton extends Button { public abstract class SideButton extends Button {
public static final int WIDTH = 18; private static final Button.IPressable NO_ACTION = btn -> {
public static final int HEIGHT = 18; };
private static final int WIDTH = 18;
private static final int HEIGHT = 18;
protected final BaseScreen<?> screen; protected final BaseScreen<?> screen;
public SideButton(BaseScreen<?> screen) { public SideButton(BaseScreen<?> screen) {
super(-1, -1, 18, 18, new StringTextComponent(""), btn -> { super(-1, -1, WIDTH, HEIGHT, StringTextComponent.EMPTY, NO_ACTION);
});
this.screen = screen; this.screen = screen;
} }
@@ -30,7 +32,7 @@ public abstract class SideButton extends Button {
isHovered = RenderUtils.inBounds(x, y, width, height, mouseX, mouseY); isHovered = RenderUtils.inBounds(x, y, width, height, mouseX, mouseY);
screen.bindTexture(RS.ID, "icons.png"); screen.bindTexture(RS.ID, "icons.png");
screen.blit(matrixStack, x, y, 238, isHovered ? 35 : 16, 18, 18); screen.blit(matrixStack, x, y, 238, isHovered ? 35 : 16, WIDTH, HEIGHT);
renderButtonIcon(matrixStack, x + 1, y + 1); renderButtonIcon(matrixStack, x + 1, y + 1);
@@ -38,11 +40,15 @@ public abstract class SideButton extends Button {
RenderSystem.enableBlend(); RenderSystem.enableBlend();
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
RenderSystem.color4f(1.0f, 1.0f, 1.0f, 0.5f); RenderSystem.color4f(1.0f, 1.0f, 1.0f, 0.5f);
screen.blit(matrixStack, x, y, 238, 54, 18, 18); screen.blit(matrixStack, x, y, 238, 54, WIDTH, HEIGHT);
RenderSystem.disableBlend(); RenderSystem.disableBlend();
} }
} }
public int getHeight() {
return height;
}
protected abstract void renderButtonIcon(MatrixStack matrixStack, int x, int y); protected abstract void renderButtonIcon(MatrixStack matrixStack, int x, int y);
public abstract String getTooltip(); public abstract String getTooltip();