Skip to content

Commit

Permalink
Merge pull request #488 from mystchonky/redstone16x
Browse files Browse the repository at this point in the history
Clean up GUI widgets
  • Loading branch information
justliliandev committed Dec 2, 2023
2 parents cd71ab6 + b08661f commit 096741b
Show file tree
Hide file tree
Showing 30 changed files with 116 additions and 61 deletions.
9 changes: 7 additions & 2 deletions src/api/java/com/enderio/api/misc/ColorControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public enum ColorControl implements IIcon {
RED(0xFFB3312C, 0xFFD63A34);

private static final ResourceLocation TEXTURE = new ResourceLocation("enderio", "textures/gui/icons/color_control.png");
private static final Vector2i SIZE = new Vector2i(12, 12);
private static final Vector2i SIZE = new Vector2i(16, 16);
private final Vector2i pos;
private final int color;
private final int colorActive;

ColorControl(int color, int colorActive) {
pos = new Vector2i(12 * ordinal(), 0);
pos = new Vector2i(16 * ordinal(), 0);
this.color = color;
this.colorActive = colorActive;
}
Expand Down Expand Up @@ -62,4 +62,9 @@ public Vector2i getIconSize() {
public Vector2i getTexturePosition() {
return pos;
}

@Override
public Vector2i getTextureSize() {
return new Vector2i(256, 16);
}
}
9 changes: 7 additions & 2 deletions src/api/java/com/enderio/api/misc/RedstoneControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum RedstoneControl implements IIcon {
NEVER_ACTIVE(bool -> false, ApiLang.REDSTONE_NEVER_ACTIVE);

private static final ResourceLocation TEXTURE = new ResourceLocation("enderio", "textures/gui/icons/redstone_control.png");
private static final Vector2i SIZE = new Vector2i(12, 12);
private static final Vector2i SIZE = new Vector2i(16, 16);

private final UnaryOperator<Boolean> isActive;

Expand All @@ -21,7 +21,7 @@ public enum RedstoneControl implements IIcon {

RedstoneControl(UnaryOperator<Boolean> isActive, Component tooltip) {
this.isActive = isActive;
pos = new Vector2i(12*ordinal(), 0);
pos = new Vector2i(16*ordinal(), 0);
this.tooltip = tooltip;
}

Expand All @@ -44,6 +44,11 @@ public Vector2i getTexturePosition() {
return pos;
}

@Override
public Vector2i getTextureSize() {
return new Vector2i(64, 16);
}

@Override
public Component getTooltip() {
return tooltip;
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ default void renderSimpleArea(GuiGraphics guiGraphics, Vector2i pos, Vector2i po
}

default void renderIconBackground(GuiGraphics guiGraphics, Vector2i pos, IIcon icon) {
renderSimpleArea(guiGraphics, pos, pos.add(icon.getRenderSize()).expand(2));
renderSimpleArea(guiGraphics, pos, pos.add(icon.getRenderSize()));
}

default void renderTooltipAfterEverything(GuiGraphics guiGraphics, List<Component> pText, int pMouseX, int pMouseY) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.enderio.core.client.gui.widgets;

import com.enderio.api.misc.Vector2i;
import com.enderio.core.client.gui.screen.EIOScreen;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;

// Wrapper for ImageButton to draw background.
// Can be removed after GUI redesign if no longer required.
public class EIOImageButton extends ImageButton {

private final EIOScreen<?> addedOn;

public EIOImageButton(EIOScreen<?> addedOn, int x, int y, int width, int height, int xTexStart, int yTexStart, ResourceLocation resourceLocation,
OnPress onPress) {
super(x, y, width, height, xTexStart, yTexStart, resourceLocation, onPress);
this.addedOn = addedOn;
}

public EIOImageButton(EIOScreen<?> addedOn, int x, int y, int width, int height, int xTexStart, int yTexStart, int yDiffTex,
ResourceLocation resourceLocation, OnPress onPress) {
super(x, y, width, height, xTexStart, yTexStart, yDiffTex, resourceLocation, onPress);
this.addedOn = addedOn;
}

public EIOImageButton(EIOScreen<?> addedOn, int x, int y, int width, int height, int xTexStart, int yTexStart, int yDiffTex,
ResourceLocation resourceLocation, int textureWidth, int textureHeight, OnPress onPress) {
super(x, y, width, height, xTexStart, yTexStart, yDiffTex, resourceLocation, textureWidth, textureHeight, onPress);
this.addedOn = addedOn;
}

public EIOImageButton(EIOScreen<?> addedOn, int x, int y, int width, int height, int xTexStart, int yTexStart, int yDiffTex,
ResourceLocation resourceLocation, int textureWidth, int textureHeight, OnPress onPress, Component message) {
super(x, y, width, height, xTexStart, yTexStart, yDiffTex, resourceLocation, textureWidth, textureHeight, onPress, message);
this.addedOn = addedOn;
}

@Override
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
addedOn.renderSimpleArea(guiGraphics, new Vector2i(getX(), getY()), new Vector2i(getX() + getWidth(), getY() + getHeight()));
super.renderWidget(guiGraphics, mouseX, mouseY, partialTick);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void renderWidget(GuiGraphics guiGraphics, int pMouseX, int pMouseY, floa

T icon = getter.get();
addedOn.renderIconBackground(guiGraphics, new Vector2i(getX(), getY()), icon);
IEnderScreen.renderIcon(guiGraphics, new Vector2i(getX(), getY()).expand(1), icon);
IEnderScreen.renderIcon(guiGraphics, new Vector2i(getX(), getY()), icon);

if (isHoveredOrFocused() && tooltipDisplayCache != getter.get()) {
// Cache the last value of the tooltip so we don't append strings over and over.
Expand Down Expand Up @@ -264,10 +264,10 @@ public void renderWidget(GuiGraphics guiGraphics, int pMouseX, int pMouseY, floa
if (getter.get() != value) {
selection.renderIconBackground(guiGraphics, new Vector2i(getX(), getY()), value);
} else {
guiGraphics.fill(getX(), getY(), getX() + width, getY() + height, 0xFF0020FF);
guiGraphics.fill(getX() + 1, getY() + 1, getX() + width - 1, getY() + height - 1, 0xFF8B8B8B);
guiGraphics.fill(getX(), getY(),getX() + width - 2,getY() + height - 2, 0xFF0020FF);
guiGraphics.fill(getX() +1, getY()+1, getX() + width - 3, getY() + height - 3, 0xFF8B8B8B);
}
IEnderScreen.renderIcon(guiGraphics, new Vector2i(getX(), getY()).expand(1), value);
IEnderScreen.renderIcon(guiGraphics, new Vector2i(getX(), getY()), value);

if (isMouseOver(pMouseX, pMouseY)) {
Component tooltip = value.getTooltip();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ protected void init() {
addRenderableOnly(new ProgressWidget.BottomUp(this, () -> menu.getBlockEntity().getCraftingProgress(), getGuiLeft() + 104, getGuiTop() + 36, 14, 14, 176, 0));
addRenderableOnly(new CapacitorEnergyWidget(this, getMenu().getBlockEntity()::getEnergyStorage, menu.getBlockEntity()::isCapacitorInstalled, 16 + leftPos, 14 + topPos, 9, 42));

addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 8 - 12, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE));

addRenderableWidget(new ActiveWidget(this, menu.getBlockEntity()::getMachineStates, leftPos + imageWidth - 6 - 16, topPos + 16*4));

addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 8 - 12, topPos + 16 * 3, () -> menu.getBlockEntity().getMode(), mode -> menu.getBlockEntity().setMode(mode), MachineLang.ALLOY_SMELTER_MODE));
addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6 + 18 * 2, () -> menu.getBlockEntity().getMode(), mode -> menu.getBlockEntity().setMode(mode), MachineLang.ALLOY_SMELTER_MODE));

addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font));
addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 24, 16, 16, menu, this::addRenderableWidget, font));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ protected void init() {
super.init();
addRenderableOnly(new EnergyWidget(this, getMenu().getBlockEntity()::getEnergyStorage, 8 + leftPos, 9 + topPos, 9, 68));

addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 8 - 12, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE));

addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font));
addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 24, 16, 16, menu, this::addRenderableWidget, font));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ protected void init() {
super.init();
addRenderableOnly(new CapacitorEnergyWidget(this, getMenu().getBlockEntity()::getEnergyStorage, getMenu().getBlockEntity()::isCapacitorInstalled, 10 + leftPos, 14 + topPos, 9, 42));

addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 5 - 16, topPos + 5, () -> menu.getBlockEntity().getRedstoneControl(),
addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE));

addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font));
addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 24, 16, 16, menu, this::addRenderableWidget, font));
addRenderableWidget(new ActiveWidget(this, menu.getBlockEntity()::getMachineStates, leftPos + imageWidth - 6 - 16, topPos + 16*4));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,30 @@ protected void init() {

addRenderableOnly(new CapacitorEnergyWidget(this, getMenu().getBlockEntity()::getEnergyStorage, getMenu().getBlockEntity()::isCapacitorInstalled, 16 + leftPos, 14 + topPos, 9, 42));

addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 4 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE));

addRenderableOnly(new FluidStackWidget(this, getMenu().getBlockEntity()::getFluidTank, 80 + leftPos, 21 + topPos, 16, 47));

addRenderableWidget(new ToggleImageButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 2*16, 16, 16, 0, 0, 16, 0, RANGE_BUTTON_TEXTURE,
addRenderableWidget(new ToggleImageButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 2*16 + 2, 16, 16, 0, 0, 16, 0, RANGE_BUTTON_TEXTURE,
() -> menu.getBlockEntity().isRangeVisible(), state -> menu.getBlockEntity().setIsRangeVisible(state),
() -> menu.getBlockEntity().isRangeVisible() ? EIOLang.HIDE_RANGE : EIOLang.SHOW_RANGE));
addRenderableWidget(new ImageButton(leftPos + imageWidth - 2*16, topPos + 16*2, 8, 8, 8, 0, 16, BUTTONS, (b) -> menu.getBlockEntity().increaseRange()));
addRenderableWidget(new ImageButton(leftPos + imageWidth - 2*16, topPos + 16*2 + 8, 8, 8, 8, 8, 16, BUTTONS, (b) -> menu.getBlockEntity().decreaseRange()));
addRenderableWidget(new ImageButton(leftPos + imageWidth - 2*16, topPos + 2 + 16*2, 8, 8, 8, 0, 16, BUTTONS, (b) -> menu.getBlockEntity().increaseRange()));
addRenderableWidget(new ImageButton(leftPos + imageWidth - 2*16, topPos + 2 + 16*2 + 8, 8, 8, 8, 8, 16, BUTTONS, (b) -> menu.getBlockEntity().decreaseRange()));

addRenderableWidget(new ActiveWidget(this, menu.getBlockEntity()::getMachineStates, leftPos + imageWidth - 6 - 16, topPos + 16*4));
}

@Override
protected void renderLabels(GuiGraphics guiGraphics, int pMouseX, int pMouseY) {
super.renderLabels(guiGraphics, pMouseX, pMouseY);
guiGraphics.drawString(font, EIOLang.RANGE, imageWidth - 8 - font.width(EIOLang.RANGE), 16 + 6, 4210752, false);
guiGraphics.drawString(font, EIOLang.RANGE, imageWidth - 6 - font.width(EIOLang.RANGE), 16 + 8, 4210752, false);
}

@Override
public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) {
super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks);
guiGraphics.drawString(font, getMenu().getBlockEntity().getRange() + "", leftPos + imageWidth - 8 - 16 - font.width(getMenu().getBlockEntity().getRange() + "") - 10, topPos + 16*2 + 4, 0, false);
guiGraphics.drawString(font, getMenu().getBlockEntity().getRange() + "", leftPos + imageWidth - 8 - 16 - font.width(getMenu().getBlockEntity().getRange() + "") - 10, topPos + 16*2 + 6, 0, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public FluidTankScreen(FluidTankMenu pMenu, Inventory pPlayerInventory, Componen
protected void init() {
super.init();
addRenderableOnly(new FluidStackWidget(this, getMenu().getBlockEntity()::getFluidTank, 80 + leftPos, 21 + topPos, 16, 47));
addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 8 - 12, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE));
addRenderableWidget(new ActiveWidget(this, menu.getBlockEntity()::getMachineStates, leftPos + imageWidth - 6 - 16, topPos + 16*4));
addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font));
addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 24, 16, 16, menu, this::addRenderableWidget, font));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ protected void init() {
super.init();
addRenderableOnly(new CapacitorEnergyWidget(this, getMenu().getBlockEntity()::getEnergyStorage, getMenu().getBlockEntity()::isCapacitorInstalled, 15 + leftPos, 9 + topPos, 9, 47));

addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 8 - 12, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE));

addRenderableWidget(new ActiveWidget(this, menu.getBlockEntity()::getMachineStates, leftPos + imageWidth - 6 - 16, topPos + 16*4));

addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font));
addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 24, 16, 16, menu, this::addRenderableWidget, font));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public class PaintingMachineScreen extends MachineScreen<PaintingMachineMenu> {
private static final ResourceLocation PAINTING_MACHINE_BG = EnderIO.loc("textures/gui/painting_machine.png");

public PaintingMachineScreen(PaintingMachineMenu pMenu, Inventory pPlayerInventory, Component pTitle) {
super(pMenu, pPlayerInventory, pTitle, true);
super(pMenu, pPlayerInventory, pTitle);
this.inventoryLabelY = this.imageHeight - 106;
}

@Override
protected void init() {
super.init();
addRenderableOnly(addRenderableOnly(new CapacitorEnergyWidget(this, getMenu().getBlockEntity()::getEnergyStorage, getMenu().getBlockEntity()::isCapacitorInstalled, 16 + leftPos, 14 + topPos, 9, 42)));
addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 8 - 14, topPos + 52, () -> menu.getBlockEntity().getRedstoneControl(),
addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE));
addRenderableWidget(new ActiveWidget(this, menu.getBlockEntity()::getMachineStates, leftPos + imageWidth - 6 - 16, topPos + 16*4));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ protected void init() {

addRenderableOnly(new CapacitorEnergyWidget(this, getMenu().getBlockEntity()::getEnergyStorage, getMenu().getBlockEntity()::isCapacitorInstalled, 16 + leftPos, 14 + topPos, 9, 42));

addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 8 - 12, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE));

addRenderableWidget(new ToggleImageButton<>(this, leftPos + imageWidth - 8 - 13, topPos + 20, 16, 16, 0, 0, 16, 0, RANGE_BUTTON_TEXTURE,
addRenderableWidget(new ToggleImageButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 24, 16, 16, 0, 0, 16, 0, RANGE_BUTTON_TEXTURE,
() -> menu.getBlockEntity().isRangeVisible(), state -> menu.getBlockEntity().setIsRangeVisible(state),
() -> menu.getBlockEntity().isRangeVisible() ? EIOLang.HIDE_RANGE : EIOLang.SHOW_RANGE));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ protected void init() {

addRenderableOnly(new GrindingBallWidget(142 + leftPos, 23 + topPos));

addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 8 - 12, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE));

addRenderableWidget(new ActiveWidget(this, menu.getBlockEntity()::getMachineStates, leftPos + imageWidth - 6 - 16, topPos + 16*4));

addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font));
addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 24, 16, 16, menu, this::addRenderableWidget, font));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ protected void init() {

addRenderableOnly(new CapacitorEnergyWidget(this, getMenu().getBlockEntity()::getEnergyStorage, getMenu().getBlockEntity()::isCapacitorInstalled, 16 + leftPos, 14 + topPos, 9, 42));

addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 8 - 12, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE));

addRenderableWidget(new ActiveWidget(this, menu.getBlockEntity()::getMachineStates, leftPos + imageWidth - 6 - 16, topPos + 16*4));

addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font));
addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 24, 16, 16, menu, this::addRenderableWidget, font));
}

@Override
Expand Down

0 comments on commit 096741b

Please sign in to comment.