diff --git a/src/main/java/li/cil/oc2/client/ClientSetup.java b/src/main/java/li/cil/oc2/client/ClientSetup.java index 80fe48b6..bf285239 100644 --- a/src/main/java/li/cil/oc2/client/ClientSetup.java +++ b/src/main/java/li/cil/oc2/client/ClientSetup.java @@ -1,7 +1,7 @@ package li.cil.oc2.client; import li.cil.oc2.api.bus.device.DeviceType; -import li.cil.oc2.client.gui.ComputerInventoryScreen; +import li.cil.oc2.client.gui.ComputerContainerScreen; import li.cil.oc2.client.gui.ComputerTerminalScreen; import li.cil.oc2.client.gui.RobotContainerScreen; import li.cil.oc2.client.gui.RobotTerminalScreen; @@ -40,7 +40,7 @@ public final class ClientSetup { CustomItemModelProperties.initialize(); CustomItemColors.initialize(); - ScreenManager.register(Containers.COMPUTER.get(), ComputerInventoryScreen::new); + ScreenManager.register(Containers.COMPUTER.get(), ComputerContainerScreen::new); ScreenManager.register(Containers.COMPUTER_TERMINAL.get(), ComputerTerminalScreen::new); ScreenManager.register(Containers.ROBOT.get(), RobotContainerScreen::new); ScreenManager.register(Containers.ROBOT_TERMINAL.get(), RobotTerminalScreen::new); diff --git a/src/main/java/li/cil/oc2/client/gui/AbstractTerminalWidget.java b/src/main/java/li/cil/oc2/client/gui/AbstractTerminalWidget.java index 90ad1afc..15c31dd4 100644 --- a/src/main/java/li/cil/oc2/client/gui/AbstractTerminalWidget.java +++ b/src/main/java/li/cil/oc2/client/gui/AbstractTerminalWidget.java @@ -2,9 +2,7 @@ package li.cil.oc2.client.gui; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; -import li.cil.oc2.api.API; import li.cil.oc2.client.gui.terminal.TerminalInput; -import li.cil.oc2.client.gui.widget.Sprite; import li.cil.oc2.client.gui.widget.ToggleImageButton; import li.cil.oc2.common.Constants; import li.cil.oc2.common.vm.Terminal; @@ -13,7 +11,6 @@ import net.minecraft.client.gui.AbstractGui; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.Widget; -import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextProperties; import net.minecraft.util.text.TextFormatting; @@ -29,29 +26,6 @@ import java.util.List; import static li.cil.oc2.common.util.TooltipUtils.withColor; public abstract class AbstractTerminalWidget extends AbstractGui { - public static final ResourceLocation BACKGROUND_LOCATION = new ResourceLocation(API.MOD_ID, "textures/gui/screen/terminal.png"); - public static final ResourceLocation TERMINAL_FOCUSED_LOCATION = new ResourceLocation(API.MOD_ID, "textures/gui/screen/terminal_focused.png"); - public static final int TEXTURE_SIZE = 512; - - private static final Sprite BACKGROUND = new Sprite(BACKGROUND_LOCATION, TEXTURE_SIZE, 336, 208, 0, 0); - - private static final Sprite CONTROLS_BACKGROUND = new Sprite(BACKGROUND_LOCATION, TEXTURE_SIZE, 19, 34, 50, 250); - - private static final Sprite POWER_BASE = new Sprite(BACKGROUND_LOCATION, TEXTURE_SIZE, 12, 12, 15, 255); - private static final Sprite POWER_PRESSED = new Sprite(BACKGROUND_LOCATION, TEXTURE_SIZE, 12, 12, 29, 255); - private static final Sprite POWER_ACTIVE = new Sprite(BACKGROUND_LOCATION, TEXTURE_SIZE, 12, 12, 1, 255); - - private static final Sprite CAPTURE_INPUT_BASE = new Sprite(BACKGROUND_LOCATION, TEXTURE_SIZE, 12, 12, 15, 241); - private static final Sprite CAPTURE_INPUT_PRESSED = new Sprite(BACKGROUND_LOCATION, TEXTURE_SIZE, 12, 12, 29, 241); - private static final Sprite CAPTURE_INPUT_ACTIVE = new Sprite(BACKGROUND_LOCATION, TEXTURE_SIZE, 12, 12, 1, 241); - - private static final Sprite ENERGY_BACKGROUND = new Sprite(BACKGROUND_LOCATION, TEXTURE_SIZE, 19, 34, 80, 250); - - private static final Sprite ENERGY_BASE = new Sprite(BACKGROUND_LOCATION, TEXTURE_SIZE, 12, 26, 110, 250); - private static final Sprite ENERGY_BAR = new Sprite(BACKGROUND_LOCATION, TEXTURE_SIZE, 12, 26, 125, 250); - - private static final Sprite TERMINAL_FOCUSED = new Sprite(TERMINAL_FOCUSED_LOCATION, TEXTURE_SIZE, 336, 208, 0, 0); - public static final int TERMINAL_WIDTH = Terminal.WIDTH * Terminal.CHAR_WIDTH / 2; public static final int TERMINAL_HEIGHT = Terminal.HEIGHT * Terminal.CHAR_HEIGHT / 2; @@ -63,7 +37,7 @@ public abstract class AbstractTerminalWidget extends AbstractGui { public static final int HEIGHT = TERMINAL_HEIGHT + MARGIN_SIZE * 2; private static final int CONTROLS_TOP = 8; - private static final int ENERGY_TOP = CONTROLS_TOP + CONTROLS_BACKGROUND.height + 4; + private static final int ENERGY_TOP = CONTROLS_TOP + Sprites.SIDEBAR_2.height + 4; private static boolean isInputCaptureEnabled; @@ -90,24 +64,23 @@ public abstract class AbstractTerminalWidget extends AbstractGui { } public void renderBackground(final MatrixStack matrixStack, final int mouseX, final int mouseY) { + RenderSystem.color4f(1f, 1f, 1f, 1f); + isMouseOverTerminal = isMouseOverTerminal(mouseX, mouseY); - RenderSystem.color4f(1f, 1f, 1f, 1f); - getClient().getTextureManager().bind(BACKGROUND_LOCATION); - - CONTROLS_BACKGROUND.draw(matrixStack, windowLeft - CONTROLS_BACKGROUND.width, windowTop + CONTROLS_TOP); + Sprites.SIDEBAR_2.draw(matrixStack, windowLeft - Sprites.SIDEBAR_2.width, windowTop + CONTROLS_TOP); if (maxEnergy > 0) { - final int x = windowLeft - ENERGY_BACKGROUND.width; + final int x = windowLeft - Sprites.SIDEBAR_2.width; final int y = windowTop + ENERGY_TOP; - ENERGY_BACKGROUND.draw(matrixStack, x, y); - ENERGY_BASE.draw(matrixStack, x + 4, y + 4); + Sprites.SIDEBAR_2.draw(matrixStack, x, y); + Sprites.ENERGY_BASE.draw(matrixStack, x + 4, y + 4); } - BACKGROUND.draw(matrixStack, windowLeft, windowTop); + Sprites.TERMINAL_SCREEN.draw(matrixStack, windowLeft, windowTop); if (shouldCaptureInput()) { - TERMINAL_FOCUSED.draw(matrixStack, windowLeft, windowTop); + Sprites.TERMINAL_FOCUSED.draw(matrixStack, windowLeft, windowTop); } } @@ -132,9 +105,9 @@ public abstract class AbstractTerminalWidget extends AbstractGui { } if (maxEnergy > 0) { - ENERGY_BAR.drawFillY(matrixStack, windowLeft - ENERGY_BACKGROUND.width + 4, windowTop + ENERGY_TOP + 4, currentEnergy / (float) maxEnergy); + Sprites.ENERGY_BAR.drawFillY(matrixStack, windowLeft - Sprites.SIDEBAR_2.width + 4, windowTop + ENERGY_TOP + 4, currentEnergy / (float) maxEnergy); - if (isMouseOver(mouseX, mouseY, -ENERGY_BACKGROUND.width + 4, ENERGY_TOP + 4, ENERGY_BAR.width, ENERGY_BAR.height)) { + if (isMouseOver(mouseX, mouseY, -Sprites.SIDEBAR_2.width + 4, ENERGY_TOP + 4, Sprites.ENERGY_BAR.width, Sprites.ENERGY_BAR.height)) { final List tooltip = Arrays.asList( new TranslationTextComponent(Constants.TOOLTIP_ENERGY, withColor(currentEnergy + "/" + maxEnergy, TextFormatting.GREEN)), new TranslationTextComponent(Constants.TOOLTIP_ENERGY_CONSUMPTION, withColor(String.valueOf(energyConsumption), TextFormatting.GREEN)) @@ -185,13 +158,13 @@ public abstract class AbstractTerminalWidget extends AbstractGui { getClient().keyboardHandler.setSendRepeatsToGui(true); addButton(new ToggleImageButton( - parent, windowLeft - CONTROLS_BACKGROUND.width + 4, windowTop + CONTROLS_TOP + 4, + parent, windowLeft - Sprites.SIDEBAR_2.width + 4, windowTop + CONTROLS_TOP + 4, 12, 12, new TranslationTextComponent(Constants.COMPUTER_SCREEN_POWER_CAPTION), new TranslationTextComponent(Constants.COMPUTER_SCREEN_POWER_DESCRIPTION), - POWER_BASE, - POWER_PRESSED, - POWER_ACTIVE + Sprites.POWER_BUTTON_BASE, + Sprites.POWER_BUTTON_PRESSED, + Sprites.POWER_BUTTON_ACTIVE ) { @Override public void onPress() { @@ -206,13 +179,13 @@ public abstract class AbstractTerminalWidget extends AbstractGui { }); addButton(new ToggleImageButton( - parent, windowLeft - CONTROLS_BACKGROUND.width + 4, windowTop + CONTROLS_TOP + 18, + parent, windowLeft - Sprites.SIDEBAR_2.width + 4, windowTop + CONTROLS_TOP + 18, 12, 12, new TranslationTextComponent(Constants.COMPUTER_SCREEN_CAPTURE_INPUT_CAPTION), new TranslationTextComponent(Constants.COMPUTER_SCREEN_CAPTURE_INPUT_DESCRIPTION), - CAPTURE_INPUT_BASE, - CAPTURE_INPUT_PRESSED, - CAPTURE_INPUT_ACTIVE + Sprites.INPUT_BUTTON_BASE, + Sprites.INPUT_BUTTON_PRESSED, + Sprites.INPUT_BUTTON_ACTIVE ) { @Override public void onPress() { diff --git a/src/main/java/li/cil/oc2/client/gui/BusInterfaceScreen.java b/src/main/java/li/cil/oc2/client/gui/BusInterfaceScreen.java index 38ba4193..fc7dbd5c 100644 --- a/src/main/java/li/cil/oc2/client/gui/BusInterfaceScreen.java +++ b/src/main/java/li/cil/oc2/client/gui/BusInterfaceScreen.java @@ -2,9 +2,7 @@ package li.cil.oc2.client.gui; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; -import li.cil.oc2.api.API; import li.cil.oc2.client.gui.widget.ImageButton; -import li.cil.oc2.client.gui.widget.Sprite; import li.cil.oc2.common.Constants; import li.cil.oc2.common.item.Items; import li.cil.oc2.common.network.Network; @@ -13,7 +11,6 @@ import li.cil.oc2.common.tileentity.BusCableTileEntity; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.text.TranslationTextComponent; import org.lwjgl.glfw.GLFW; @@ -21,14 +18,6 @@ import org.lwjgl.glfw.GLFW; import static li.cil.oc2.common.util.TranslationUtils.text; public final class BusInterfaceScreen extends Screen { - private static final ResourceLocation BACKGROUND_LOCATION = new ResourceLocation(API.MOD_ID, "textures/gui/screen/bus_interface.png"); - - private static final Sprite BACKGROUND = new Sprite(BACKGROUND_LOCATION, 256, 240, 30, 0, 0); - private static final Sprite CONFIRM_BASE = new Sprite(BACKGROUND_LOCATION, 256, 12, 12, 5, 35); - private static final Sprite CONFIRM_PRESSED = new Sprite(BACKGROUND_LOCATION, 256, 12, 12, 20, 35); - private static final Sprite CANCEL_BASE = new Sprite(BACKGROUND_LOCATION, 256, 12, 12, 5, 50); - private static final Sprite CANCEL_PRESSED = new Sprite(BACKGROUND_LOCATION, 256, 12, 12, 20, 50); - private static final int TEXT_LEFT = 9; private static final int TEXT_TOP = 11; private static final int CONFIRM_LEFT = 206; @@ -59,8 +48,8 @@ public final class BusInterfaceScreen extends Screen { getMinecraft().keyboardHandler.setSendRepeatsToGui(true); - left = (width - BACKGROUND.width) / 2; - top = (height - BACKGROUND.height) / 2; + left = (width - Sprites.BUS_INTERFACE_SCREEN.width) / 2; + top = (height - Sprites.BUS_INTERFACE_SCREEN.height) / 2; nameField = new TextFieldWidget(font, left + TEXT_LEFT, top + TEXT_TOP, 192, 12, text("{mod}.gui.bus_interface_name")); nameField.setCanLoseFocus(false); @@ -74,11 +63,11 @@ public final class BusInterfaceScreen extends Screen { addButton(new ImageButton( this, left + CONFIRM_LEFT, top + CONFIRM_TOP, - CONFIRM_BASE.width, CONFIRM_BASE.height, + Sprites.CONFIRM_BASE.width, Sprites.CONFIRM_BASE.height, new TranslationTextComponent(Constants.TOOLTIP_CONFIRM), null, - CONFIRM_BASE, - CONFIRM_PRESSED + Sprites.CONFIRM_BASE, + Sprites.CONFIRM_PRESSED ) { @Override public void onPress() { @@ -90,11 +79,11 @@ public final class BusInterfaceScreen extends Screen { addButton(new ImageButton( this, left + CANCEL_LEFT, top + CANCEL_TOP, - CANCEL_BASE.width, CANCEL_BASE.height, + Sprites.CANCEL_BASE.width, Sprites.CANCEL_BASE.height, new TranslationTextComponent(Constants.TOOLTIP_CANCEL), null, - CANCEL_BASE, - CANCEL_PRESSED + Sprites.CANCEL_BASE, + Sprites.CANCEL_PRESSED ) { @Override public void onPress() { @@ -137,7 +126,7 @@ public final class BusInterfaceScreen extends Screen { @Override public void render(final MatrixStack matrixStack, final int mouseX, final int mouseY, final float partialTicks) { renderBackground(matrixStack); - BACKGROUND.draw(matrixStack, left, top); + Sprites.BUS_INTERFACE_SCREEN.draw(matrixStack, left, top); super.render(matrixStack, mouseX, mouseY, partialTicks); diff --git a/src/main/java/li/cil/oc2/client/gui/ComputerInventoryScreen.java b/src/main/java/li/cil/oc2/client/gui/ComputerContainerScreen.java similarity index 68% rename from src/main/java/li/cil/oc2/client/gui/ComputerInventoryScreen.java rename to src/main/java/li/cil/oc2/client/gui/ComputerContainerScreen.java index 13ec1331..eb1aa670 100644 --- a/src/main/java/li/cil/oc2/client/gui/ComputerInventoryScreen.java +++ b/src/main/java/li/cil/oc2/client/gui/ComputerContainerScreen.java @@ -2,26 +2,18 @@ package li.cil.oc2.client.gui; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; -import li.cil.oc2.api.API; import li.cil.oc2.api.bus.device.DeviceTypes; import li.cil.oc2.client.gui.util.GuiUtils; import li.cil.oc2.common.container.ComputerInventoryContainer; import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; -import static java.util.Objects.requireNonNull; - -public final class ComputerInventoryScreen extends ContainerScreen { - private static final ResourceLocation BACKGROUND = new ResourceLocation(API.MOD_ID, "textures/gui/container/computer.png"); - - /////////////////////////////////////////////////////////////////// - - public ComputerInventoryScreen(final ComputerInventoryContainer container, final PlayerInventory inventory, final ITextComponent title) { +public final class ComputerContainerScreen extends ContainerScreen { + public ComputerContainerScreen(final ComputerInventoryContainer container, final PlayerInventory inventory, final ITextComponent title) { super(container, inventory, title); - imageWidth = 176; - imageHeight = 197; + imageWidth = Sprites.COMPUTER_CONTAINER.width; + imageHeight = Sprites.COMPUTER_CONTAINER.height; inventoryLabelY = imageHeight - 94; } @@ -31,9 +23,9 @@ public final class ComputerInventoryScreen extends ContainerScreen { - private static final ResourceLocation BACKGROUND = new ResourceLocation(API.MOD_ID, "textures/gui/container/robot.png"); - private static final ResourceLocation SELECTION = new ResourceLocation(API.MOD_ID, "textures/gui/overlay/robot_selection.png"); - private static final int SLOT_SIZE = 18; /////////////////////////////////////////////////////////////////// public static void renderSelection(final MatrixStack matrixStack, final int selectedSlot, final int x, final int y, final int columns) { RenderSystem.color4f(1f, 1f, 1f, 1f); - Minecraft.getInstance().getTextureManager().bind(SELECTION); final int slotX = (selectedSlot % columns) * SLOT_SIZE; final int slotY = (selectedSlot / columns) * SLOT_SIZE; - final float offset = SLOT_SIZE * (int) (15 * (System.currentTimeMillis() % 1000) / 1000f); - blit(matrixStack, x + slotX, y + slotY, 0, offset, SLOT_SIZE, SLOT_SIZE, SLOT_SIZE, 270); + final int offset = SLOT_SIZE * (int) (15 * (System.currentTimeMillis() % 1000) / 1000); + Sprites.SLOT_SELECTION.draw(matrixStack, x + slotX, y + slotY, 0, offset); } /////////////////////////////////////////////////////////////////// public RobotContainerScreen(final RobotContainer container, final PlayerInventory playerInventory, final ITextComponent title) { super(container, playerInventory, title); - imageWidth = 176; - imageHeight = 197; + imageWidth = Sprites.ROBOT_CONTAINER.width; + imageHeight = Sprites.ROBOT_CONTAINER.height; inventoryLabelY = imageHeight - 94; } @@ -47,9 +40,9 @@ public final class RobotContainerScreen extends ContainerScreen renderSelection(matrixStack); - GuiUtils.renderMissingDeviceInfoIcon(matrixStack, this, DeviceTypes.FLASH_MEMORY, GuiUtils.WARN_ICON); - GuiUtils.renderMissingDeviceInfoIcon(matrixStack, this, DeviceTypes.MEMORY, GuiUtils.WARN_ICON); - GuiUtils.renderMissingDeviceInfoIcon(matrixStack, this, DeviceTypes.HARD_DRIVE, GuiUtils.INFO_ICON); + GuiUtils.renderMissingDeviceInfoIcon(matrixStack, this, DeviceTypes.FLASH_MEMORY, Sprites.WARN_ICON); + GuiUtils.renderMissingDeviceInfoIcon(matrixStack, this, DeviceTypes.MEMORY, Sprites.WARN_ICON); + GuiUtils.renderMissingDeviceInfoIcon(matrixStack, this, DeviceTypes.HARD_DRIVE, Sprites.INFO_ICON); GuiUtils.renderMissingDeviceInfoTooltip(matrixStack, this, mouseX, mouseY, DeviceTypes.FLASH_MEMORY); GuiUtils.renderMissingDeviceInfoTooltip(matrixStack, this, mouseX, mouseY, DeviceTypes.MEMORY); @@ -63,8 +56,7 @@ public final class RobotContainerScreen extends ContainerScreen @Override protected void renderBg(final MatrixStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) { RenderSystem.color4f(1f, 1f, 1f, 1f); - getMinecraft().getTextureManager().bind(BACKGROUND); - blit(matrixStack, leftPos, topPos, 0, 0, imageWidth, imageHeight); + Sprites.ROBOT_CONTAINER.draw(matrixStack, leftPos, topPos); } /////////////////////////////////////////////////////////////////// diff --git a/src/main/java/li/cil/oc2/client/gui/RobotTerminalScreen.java b/src/main/java/li/cil/oc2/client/gui/RobotTerminalScreen.java index 4fa7ac18..fd65e264 100644 --- a/src/main/java/li/cil/oc2/client/gui/RobotTerminalScreen.java +++ b/src/main/java/li/cil/oc2/client/gui/RobotTerminalScreen.java @@ -1,7 +1,6 @@ package li.cil.oc2.client.gui; import com.mojang.blaze3d.matrix.MatrixStack; -import li.cil.oc2.client.gui.widget.Sprite; import li.cil.oc2.common.container.RobotTerminalContainer; import li.cil.oc2.common.network.Network; import li.cil.oc2.common.network.message.RobotPowerMessage; @@ -16,9 +15,7 @@ import net.minecraft.util.text.ITextComponent; import java.nio.ByteBuffer; public final class RobotTerminalScreen extends ContainerScreen { - private static final Sprite INVENTORY_BACKGROUND = new Sprite(AbstractTerminalWidget.BACKGROUND_LOCATION, AbstractTerminalWidget.TEXTURE_SIZE, 224, 26, 80, 300); - - private static final int SLOTS_X = (AbstractTerminalWidget.WIDTH - INVENTORY_BACKGROUND.width) / 2; + private static final int SLOTS_X = (AbstractTerminalWidget.WIDTH - Sprites.HOTBAR.width) / 2; private static final int SLOTS_Y = AbstractTerminalWidget.HEIGHT - 1; private final RobotTerminalWidget terminalWidget; @@ -34,7 +31,7 @@ public final class RobotTerminalScreen extends ContainerScreen WARNING_BY_DEVICE_TYPE = Util.make(() -> { final HashMap map = new HashMap<>(); @@ -40,20 +35,10 @@ public final class GuiUtils { /////////////////////////////////////////////////////////////////// - public static void renderMissingDeviceInfoIcon(final MatrixStack matrixStack, final ContainerScreen screen, final DeviceType type, final ResourceLocation icon) { - findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(screen.getMenu(), type).ifPresent(slot -> { - screen.getMinecraft().getTextureManager().bind(icon); - AbstractGui.blit(matrixStack, - screen.getGuiLeft() + slot.x - 1 + RELATIVE_ICON_POSITION, - screen.getGuiTop() + slot.y - 1 + RELATIVE_ICON_POSITION, - 200, - 0, - 0, - DEVICE_INFO_ICON_SIZE, - DEVICE_INFO_ICON_SIZE, - DEVICE_INFO_ICON_SIZE, - DEVICE_INFO_ICON_SIZE); - }); + public static void renderMissingDeviceInfoIcon(final MatrixStack matrixStack, final ContainerScreen screen, final DeviceType type, final Sprite icon) { + findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(screen.getMenu(), type).ifPresent(slot -> icon.draw(matrixStack, + screen.getGuiLeft() + slot.x - 1 + RELATIVE_ICON_POSITION, + screen.getGuiTop() + slot.y - 1 + RELATIVE_ICON_POSITION)); } public static void renderMissingDeviceInfoTooltip(final MatrixStack matrixStack, final ContainerScreen screen, final int mouseX, final int mouseY, final DeviceType type) { diff --git a/src/main/java/li/cil/oc2/client/gui/widget/Sprite.java b/src/main/java/li/cil/oc2/client/gui/widget/Sprite.java index cf174a45..e630154e 100644 --- a/src/main/java/li/cil/oc2/client/gui/widget/Sprite.java +++ b/src/main/java/li/cil/oc2/client/gui/widget/Sprite.java @@ -1,21 +1,26 @@ package li.cil.oc2.client.gui.widget; import com.mojang.blaze3d.matrix.MatrixStack; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.AbstractGui; -import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.MathHelper; -public final class Sprite extends AbstractGui { - public final ResourceLocation image; - public final int textureSize; +public final class Sprite { + public final Texture texture; public final int width, height; public final int u0, v0; /////////////////////////////////////////////////////////////////// - public Sprite(final ResourceLocation atlas, final int textureSize, final int width, final int height, final int u0, final int v0) { - this.image = atlas; - this.textureSize = textureSize; + public Sprite(final Texture texture) { + this.texture = texture; + this.width = texture.width; + this.height = texture.height; + this.u0 = 0; + this.v0 = 0; + } + + public Sprite(final Texture texture, final int width, final int height, final int u0, final int v0) { + this.texture = texture; this.width = width; this.height = height; this.u0 = u0; @@ -25,13 +30,20 @@ public final class Sprite extends AbstractGui { /////////////////////////////////////////////////////////////////// public void draw(final MatrixStack stack, final int x, final int y) { - Minecraft.getInstance().getTextureManager().bind(image); - blit(stack, x, y, u0, v0, width, height, textureSize, textureSize); + draw(stack, x, y, 0, 0); + } + + public void draw(final MatrixStack stack, final int x, final int y, final int uOffset, final int vOffset) { + blit(stack, x, y, u0 + uOffset, v0 + vOffset, width, height); } public void drawFillY(final MatrixStack stack, final int x, final int y, final float value) { - Minecraft.getInstance().getTextureManager().bind(image); - final int h = (int) (this.height * value); - blit(stack, x, y + (height - h), u0, v0 + (height - h), width, h, textureSize, textureSize); + final int h = (int) (this.height * MathHelper.clamp(value, 0, 1)); + blit(stack, x, y + (height - h), u0, v0 + (height - h), width, h); + } + + private void blit(final MatrixStack stack, final int x, final int y, final int u0, final int v0, final int width, final int height) { + texture.bind(); + AbstractGui.blit(stack, x, y, u0, v0, width, height, texture.width, texture.height); } } diff --git a/src/main/java/li/cil/oc2/client/gui/widget/Texture.java b/src/main/java/li/cil/oc2/client/gui/widget/Texture.java new file mode 100644 index 00000000..06b93195 --- /dev/null +++ b/src/main/java/li/cil/oc2/client/gui/widget/Texture.java @@ -0,0 +1,24 @@ +package li.cil.oc2.client.gui.widget; + +import li.cil.oc2.api.API; +import net.minecraft.client.Minecraft; +import net.minecraft.util.ResourceLocation; + +public final class Texture { + public final ResourceLocation location; + public final int width, height; + + public Texture(final String location, final int width, final int height) { + this(new ResourceLocation(API.MOD_ID, location), width, height); + } + + public Texture(final ResourceLocation location, final int width, final int height) { + this.location = location; + this.width = width; + this.height = height; + } + + public void bind() { + Minecraft.getInstance().getTextureManager().bind(location); + } +} diff --git a/src/main/resources/assets/oc2/textures/gui/container/computer.png b/src/main/resources/assets/oc2/textures/gui/container/computer.png deleted file mode 100644 index 73cba94a..00000000 Binary files a/src/main/resources/assets/oc2/textures/gui/container/computer.png and /dev/null differ diff --git a/src/main/resources/assets/oc2/textures/gui/container/robot.png b/src/main/resources/assets/oc2/textures/gui/container/robot.png deleted file mode 100644 index 168fdcbb..00000000 Binary files a/src/main/resources/assets/oc2/textures/gui/container/robot.png and /dev/null differ diff --git a/src/main/resources/assets/oc2/textures/gui/overlay/robot_selection.png b/src/main/resources/assets/oc2/textures/gui/overlay/slot_selection.png similarity index 100% rename from src/main/resources/assets/oc2/textures/gui/overlay/robot_selection.png rename to src/main/resources/assets/oc2/textures/gui/overlay/slot_selection.png diff --git a/src/main/resources/assets/oc2/textures/gui/overlay/terminal_focused.png b/src/main/resources/assets/oc2/textures/gui/overlay/terminal_focused.png new file mode 100644 index 00000000..7855b1e1 Binary files /dev/null and b/src/main/resources/assets/oc2/textures/gui/overlay/terminal_focused.png differ diff --git a/src/main/resources/assets/oc2/textures/gui/screen/bus_interface.png b/src/main/resources/assets/oc2/textures/gui/screen/bus_interface.png deleted file mode 100644 index b1c1e7b3..00000000 Binary files a/src/main/resources/assets/oc2/textures/gui/screen/bus_interface.png and /dev/null differ diff --git a/src/main/resources/assets/oc2/textures/gui/screen/terminal.png b/src/main/resources/assets/oc2/textures/gui/screen/terminal.png deleted file mode 100644 index 3e4e0137..00000000 Binary files a/src/main/resources/assets/oc2/textures/gui/screen/terminal.png and /dev/null differ diff --git a/src/main/resources/assets/oc2/textures/gui/screen/terminal_focused.png b/src/main/resources/assets/oc2/textures/gui/screen/terminal_focused.png deleted file mode 100644 index cffc6334..00000000 Binary files a/src/main/resources/assets/oc2/textures/gui/screen/terminal_focused.png and /dev/null differ diff --git a/src/main/resources/assets/oc2/textures/gui/widget/bus_interface_screen.png b/src/main/resources/assets/oc2/textures/gui/widget/bus_interface_screen.png new file mode 100644 index 00000000..0da9d463 Binary files /dev/null and b/src/main/resources/assets/oc2/textures/gui/widget/bus_interface_screen.png differ diff --git a/src/main/resources/assets/oc2/textures/gui/widget/cancel_button.png b/src/main/resources/assets/oc2/textures/gui/widget/cancel_button.png new file mode 100644 index 00000000..c3b4b000 Binary files /dev/null and b/src/main/resources/assets/oc2/textures/gui/widget/cancel_button.png differ diff --git a/src/main/resources/assets/oc2/textures/gui/widget/computer_container.png b/src/main/resources/assets/oc2/textures/gui/widget/computer_container.png new file mode 100644 index 00000000..08cd17c4 Binary files /dev/null and b/src/main/resources/assets/oc2/textures/gui/widget/computer_container.png differ diff --git a/src/main/resources/assets/oc2/textures/gui/widget/confirm_button.png b/src/main/resources/assets/oc2/textures/gui/widget/confirm_button.png new file mode 100644 index 00000000..95b0495f Binary files /dev/null and b/src/main/resources/assets/oc2/textures/gui/widget/confirm_button.png differ diff --git a/src/main/resources/assets/oc2/textures/gui/widget/energy.png b/src/main/resources/assets/oc2/textures/gui/widget/energy.png new file mode 100644 index 00000000..18bca82c Binary files /dev/null and b/src/main/resources/assets/oc2/textures/gui/widget/energy.png differ diff --git a/src/main/resources/assets/oc2/textures/gui/widget/hotbar.png b/src/main/resources/assets/oc2/textures/gui/widget/hotbar.png new file mode 100644 index 00000000..dea716e6 Binary files /dev/null and b/src/main/resources/assets/oc2/textures/gui/widget/hotbar.png differ diff --git a/src/main/resources/assets/oc2/textures/gui/widget/input_button.png b/src/main/resources/assets/oc2/textures/gui/widget/input_button.png new file mode 100644 index 00000000..edece6dd Binary files /dev/null and b/src/main/resources/assets/oc2/textures/gui/widget/input_button.png differ diff --git a/src/main/resources/assets/oc2/textures/gui/widget/intentory_button.png b/src/main/resources/assets/oc2/textures/gui/widget/intentory_button.png new file mode 100644 index 00000000..dc71c43d Binary files /dev/null and b/src/main/resources/assets/oc2/textures/gui/widget/intentory_button.png differ diff --git a/src/main/resources/assets/oc2/textures/gui/widget/power_button.png b/src/main/resources/assets/oc2/textures/gui/widget/power_button.png new file mode 100644 index 00000000..7c13683a Binary files /dev/null and b/src/main/resources/assets/oc2/textures/gui/widget/power_button.png differ diff --git a/src/main/resources/assets/oc2/textures/gui/widget/robot_container.png b/src/main/resources/assets/oc2/textures/gui/widget/robot_container.png new file mode 100644 index 00000000..e7e7db16 Binary files /dev/null and b/src/main/resources/assets/oc2/textures/gui/widget/robot_container.png differ diff --git a/src/main/resources/assets/oc2/textures/gui/widget/sidebar_2.png b/src/main/resources/assets/oc2/textures/gui/widget/sidebar_2.png new file mode 100644 index 00000000..66f2b25d Binary files /dev/null and b/src/main/resources/assets/oc2/textures/gui/widget/sidebar_2.png differ diff --git a/src/main/resources/assets/oc2/textures/gui/widget/sidebar_3.png b/src/main/resources/assets/oc2/textures/gui/widget/sidebar_3.png new file mode 100644 index 00000000..8706af67 Binary files /dev/null and b/src/main/resources/assets/oc2/textures/gui/widget/sidebar_3.png differ diff --git a/src/main/resources/assets/oc2/textures/gui/widget/terminal_screen.png b/src/main/resources/assets/oc2/textures/gui/widget/terminal_screen.png new file mode 100644 index 00000000..e670318a Binary files /dev/null and b/src/main/resources/assets/oc2/textures/gui/widget/terminal_screen.png differ