Centralized UI sprite and texture definitions.
@@ -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);
|
||||
|
||||
@@ -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<? extends ITextProperties> 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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<ComputerInventoryContainer> {
|
||||
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<ComputerInventoryContainer> {
|
||||
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<ComputerInven
|
||||
|
||||
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||
|
||||
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);
|
||||
@@ -47,7 +39,6 @@ public final class ComputerInventoryScreen extends ContainerScreen<ComputerInven
|
||||
@Override
|
||||
protected void renderBg(final MatrixStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) {
|
||||
RenderSystem.color4f(1f, 1f, 1f, 1f);
|
||||
requireNonNull(minecraft).getTextureManager().bind(BACKGROUND);
|
||||
blit(matrixStack, leftPos, topPos, 0, 0, imageWidth, imageHeight);
|
||||
Sprites.COMPUTER_CONTAINER.draw(matrixStack, leftPos, topPos);
|
||||
}
|
||||
}
|
||||
@@ -2,40 +2,33 @@ 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.RobotContainer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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;
|
||||
|
||||
public final class RobotContainerScreen extends ContainerScreen<RobotContainer> {
|
||||
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<RobotContainer>
|
||||
|
||||
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<RobotContainer>
|
||||
@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);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -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<RobotTerminalContainer> {
|
||||
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<RobotTerminalCont
|
||||
|
||||
@Override
|
||||
protected void renderBg(final MatrixStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) {
|
||||
INVENTORY_BACKGROUND.draw(matrixStack, leftPos + SLOTS_X, topPos + SLOTS_Y);
|
||||
Sprites.HOTBAR.draw(matrixStack, leftPos + SLOTS_X, topPos + SLOTS_Y);
|
||||
terminalWidget.renderBackground(matrixStack, mouseX, mouseY);
|
||||
}
|
||||
|
||||
|
||||
41
src/main/java/li/cil/oc2/client/gui/Sprites.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package li.cil.oc2.client.gui;
|
||||
|
||||
import li.cil.oc2.client.gui.widget.Sprite;
|
||||
|
||||
import static li.cil.oc2.client.gui.Textures.*;
|
||||
|
||||
public final class Sprites {
|
||||
public static final Sprite COMPUTER_CONTAINER = new Sprite(COMPUTER_CONTAINER_TEXTURE);
|
||||
public static final Sprite ROBOT_CONTAINER = new Sprite(ROBOT_CONTAINER_TEXTURE);
|
||||
public static final Sprite TERMINAL_SCREEN = new Sprite(TERMINAL_SCREEN_TEXTURE);
|
||||
public static final Sprite BUS_INTERFACE_SCREEN = new Sprite(BUS_INTERFACE_SCREEN_TEXTURE);
|
||||
|
||||
public static final Sprite TERMINAL_FOCUSED = new Sprite(TERMINAL_FOCUSED_TEXTURE);
|
||||
public static final Sprite SLOT_SELECTION = new Sprite(SLOT_SELECTION_TEXTURE, 18, 18, 0, 0);
|
||||
public static final Sprite INFO_ICON = new Sprite(INFO_ICON_TEXTURE);
|
||||
public static final Sprite WARN_ICON = new Sprite(WARN_ICON_TEXTURE);
|
||||
|
||||
public static final Sprite HOTBAR = new Sprite(HOTBAR_TEXTURE);
|
||||
public static final Sprite SIDEBAR_2 = new Sprite(SIDEBAR_2_TEXTURE);
|
||||
public static final Sprite SIDEBAR_3 = new Sprite(SIDEBAR_3_TEXTURE);
|
||||
|
||||
public static final Sprite ENERGY_BASE = new Sprite(ENERGY_TEXTURE, 12, 26, 0, 0);
|
||||
public static final Sprite ENERGY_BAR = new Sprite(ENERGY_TEXTURE, 12, 26, 12, 0);
|
||||
|
||||
public static final Sprite INPUT_BUTTON_ACTIVE = new Sprite(INPUT_BUTTON_TEXTURE, 12, 12, 1, 1);
|
||||
public static final Sprite INPUT_BUTTON_BASE = new Sprite(INPUT_BUTTON_TEXTURE, 12, 12, 15, 1);
|
||||
public static final Sprite INPUT_BUTTON_PRESSED = new Sprite(INPUT_BUTTON_TEXTURE, 12, 12, 29, 1);
|
||||
|
||||
public static final Sprite POWER_BUTTON_ACTIVE = new Sprite(POWER_BUTTON_TEXTURE, 12, 12, 1, 1);
|
||||
public static final Sprite POWER_BUTTON_BASE = new Sprite(POWER_BUTTON_TEXTURE, 12, 12, 15, 1);
|
||||
public static final Sprite POWER_BUTTON_PRESSED = new Sprite(POWER_BUTTON_TEXTURE, 12, 12, 29, 1);
|
||||
|
||||
public static final Sprite INVENTORY_BUTTON_ACTIVE = new Sprite(INVENTORY_BUTTON_TEXTURE, 12, 12, 1, 1);
|
||||
public static final Sprite INVENTORY_BUTTON_BASE = new Sprite(INVENTORY_BUTTON_TEXTURE, 12, 12, 15, 1);
|
||||
public static final Sprite INVENTORY_BUTTON_PRESSED = new Sprite(INVENTORY_BUTTON_TEXTURE, 12, 12, 29, 1);
|
||||
|
||||
public static final Sprite CONFIRM_PRESSED = new Sprite(CONFIRM_BUTTON_TEXTURE, 12, 12, 14, 1);
|
||||
public static final Sprite CONFIRM_BASE = new Sprite(CONFIRM_BUTTON_TEXTURE, 12, 12, 1, 1);
|
||||
public static final Sprite CANCEL_PRESSED = new Sprite(CANCEL_BUTTON_TEXTURE, 12, 12, 14, 1);
|
||||
public static final Sprite CANCEL_BASE = new Sprite(CANCEL_BUTTON_TEXTURE, 12, 12, 1, 1);
|
||||
}
|
||||
26
src/main/java/li/cil/oc2/client/gui/Textures.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package li.cil.oc2.client.gui;
|
||||
|
||||
import li.cil.oc2.client.gui.widget.Texture;
|
||||
|
||||
public final class Textures {
|
||||
public static final Texture COMPUTER_CONTAINER_TEXTURE = new Texture("textures/gui/widget/computer_container.png", 176, 197);
|
||||
public static final Texture ROBOT_CONTAINER_TEXTURE = new Texture("textures/gui/widget/robot_container.png", 176, 197);
|
||||
public static final Texture TERMINAL_SCREEN_TEXTURE = new Texture("textures/gui/widget/terminal_screen.png", 336, 208);
|
||||
public static final Texture BUS_INTERFACE_SCREEN_TEXTURE = new Texture("textures/gui/widget/bus_interface_screen.png", 240, 30);
|
||||
|
||||
public static final Texture TERMINAL_FOCUSED_TEXTURE = new Texture("textures/gui/overlay/terminal_focused.png", 336, 208);
|
||||
public static final Texture SLOT_SELECTION_TEXTURE = new Texture("textures/gui/overlay/slot_selection.png", 18, 270);
|
||||
public static final Texture INFO_ICON_TEXTURE = new Texture("textures/gui/overlay/slot_info.png", 28, 28);
|
||||
public static final Texture WARN_ICON_TEXTURE = new Texture("textures/gui/overlay/slot_warn.png", 28, 28);
|
||||
|
||||
public static final Texture HOTBAR_TEXTURE = new Texture("textures/gui/widget/hotbar.png", 224, 26);
|
||||
public static final Texture SIDEBAR_2_TEXTURE = new Texture("textures/gui/widget/sidebar_2.png", 19, 34);
|
||||
public static final Texture SIDEBAR_3_TEXTURE = new Texture("textures/gui/widget/sidebar_3.png", 19, 48);
|
||||
|
||||
public static final Texture CONFIRM_BUTTON_TEXTURE = new Texture("textures/gui/widget/confirm_button.png", 27, 14);
|
||||
public static final Texture CANCEL_BUTTON_TEXTURE = new Texture("textures/gui/widget/cancel_button.png", 27, 14);
|
||||
public static final Texture ENERGY_TEXTURE = new Texture("textures/gui/widget/energy.png", 24, 26);
|
||||
public static final Texture POWER_BUTTON_TEXTURE = new Texture("textures/gui/widget/power_button.png", 42, 14);
|
||||
public static final Texture INPUT_BUTTON_TEXTURE = new Texture("textures/gui/widget/input_button.png", 42, 14);
|
||||
public static final Texture INVENTORY_BUTTON_TEXTURE = new Texture("textures/gui/widget/inventory_button.png", 42, 14);
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
package li.cil.oc2.client.gui.util;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.api.bus.device.DeviceType;
|
||||
import li.cil.oc2.api.bus.device.DeviceTypes;
|
||||
import li.cil.oc2.client.gui.widget.Sprite;
|
||||
import li.cil.oc2.common.container.TypedSlotItemHandler;
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
@@ -21,9 +19,6 @@ import java.util.Optional;
|
||||
import static li.cil.oc2.common.util.TranslationUtils.text;
|
||||
|
||||
public final class GuiUtils {
|
||||
public static final ResourceLocation WARN_ICON = new ResourceLocation(API.MOD_ID, "textures/gui/overlay/slot_warn.png");
|
||||
public static final ResourceLocation INFO_ICON = new ResourceLocation(API.MOD_ID, "textures/gui/overlay/slot_info.png");
|
||||
|
||||
private static final Map<DeviceType, ITextComponent> WARNING_BY_DEVICE_TYPE = Util.make(() -> {
|
||||
final HashMap<DeviceType, ITextComponent> map = new HashMap<>();
|
||||
|
||||
@@ -40,20 +35,10 @@ public final class GuiUtils {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static <TContainer extends Container> void renderMissingDeviceInfoIcon(final MatrixStack matrixStack, final ContainerScreen<TContainer> 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 <TContainer extends Container> void renderMissingDeviceInfoIcon(final MatrixStack matrixStack, final ContainerScreen<TContainer> 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 <TContainer extends Container> void renderMissingDeviceInfoTooltip(final MatrixStack matrixStack, final ContainerScreen<TContainer> screen, final int mouseX, final int mouseY, final DeviceType type) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
24
src/main/java/li/cil/oc2/client/gui/widget/Texture.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 9.9 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src/main/resources/assets/oc2/textures/gui/widget/energy.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
src/main/resources/assets/oc2/textures/gui/widget/hotbar.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 11 KiB |
BIN
src/main/resources/assets/oc2/textures/gui/widget/sidebar_2.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src/main/resources/assets/oc2/textures/gui/widget/sidebar_3.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 3.2 KiB |