Added tooltips for slot info.
This commit is contained in:
@@ -5,11 +5,13 @@ 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.Constants;
|
||||
import li.cil.oc2.common.container.ComputerContainer;
|
||||
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 net.minecraft.util.text.TranslationTextComponent;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
@@ -35,6 +37,10 @@ public final class ComputerContainerScreen extends ContainerScreen<ComputerConta
|
||||
GuiUtils.renderMissingDeviceInfoIcon(matrixStack, this, DeviceTypes.MEMORY, GuiUtils.WARN_ICON);
|
||||
GuiUtils.renderMissingDeviceInfoIcon(matrixStack, this, DeviceTypes.HARD_DRIVE, GuiUtils.INFO_ICON);
|
||||
|
||||
GuiUtils.renderMissingDeviceInfoTooltip(matrixStack, this, mouseX, mouseY, DeviceTypes.FLASH_MEMORY, new TranslationTextComponent(Constants.TOOLTIP_FLASH_MEMORY_MISSING));
|
||||
GuiUtils.renderMissingDeviceInfoTooltip(matrixStack, this, mouseX, mouseY, DeviceTypes.MEMORY, new TranslationTextComponent(Constants.TOOLTIP_MEMORY_MISSING));
|
||||
GuiUtils.renderMissingDeviceInfoTooltip(matrixStack, this, mouseX, mouseY, DeviceTypes.HARD_DRIVE, new TranslationTextComponent(Constants.TOOLTIP_HARD_DRIVE_MISSING));
|
||||
|
||||
renderHoveredTooltip(matrixStack, mouseX, mouseY);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,12 +5,14 @@ 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.Constants;
|
||||
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;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
|
||||
public final class RobotContainerScreen extends ContainerScreen<RobotContainer> {
|
||||
private static final ResourceLocation BACKGROUND = new ResourceLocation(API.MOD_ID, "textures/gui/container/robot.png");
|
||||
@@ -51,6 +53,10 @@ public final class RobotContainerScreen extends ContainerScreen<RobotContainer>
|
||||
GuiUtils.renderMissingDeviceInfoIcon(matrixStack, this, DeviceTypes.MEMORY, GuiUtils.WARN_ICON);
|
||||
GuiUtils.renderMissingDeviceInfoIcon(matrixStack, this, DeviceTypes.HARD_DRIVE, GuiUtils.INFO_ICON);
|
||||
|
||||
GuiUtils.renderMissingDeviceInfoTooltip(matrixStack, this, mouseX, mouseY, DeviceTypes.FLASH_MEMORY, new TranslationTextComponent(Constants.TOOLTIP_FLASH_MEMORY_MISSING));
|
||||
GuiUtils.renderMissingDeviceInfoTooltip(matrixStack, this, mouseX, mouseY, DeviceTypes.MEMORY, new TranslationTextComponent(Constants.TOOLTIP_MEMORY_MISSING));
|
||||
GuiUtils.renderMissingDeviceInfoTooltip(matrixStack, this, mouseX, mouseY, DeviceTypes.HARD_DRIVE, new TranslationTextComponent(Constants.TOOLTIP_HARD_DRIVE_MISSING));
|
||||
|
||||
renderHoveredTooltip(matrixStack, mouseX, mouseY);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ 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.text.ITextComponent;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -36,6 +37,24 @@ public final class GuiUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static <TContainer extends Container> void renderMissingDeviceInfoTooltip(final MatrixStack matrixStack, final ContainerScreen<TContainer> screen, final int mouseX, final int mouseY, final DeviceType type, final ITextComponent tooltip) {
|
||||
final boolean isCursorHoldingStack = !screen.getMinecraft().player.inventory.getItemStack().isEmpty();
|
||||
if (isCursorHoldingStack) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Slot hoveredSlot = screen.getSlotUnderMouse();
|
||||
if (hoveredSlot != null && hoveredSlot.getHasStack()) {
|
||||
return;
|
||||
}
|
||||
|
||||
findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(screen.getContainer(), type).ifPresent(slot -> {
|
||||
if (slot == hoveredSlot) {
|
||||
screen.renderTooltip(matrixStack, tooltip, mouseX, mouseY);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static Optional<TypedSlotItemHandler> findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(final Container container, final DeviceType type) {
|
||||
TypedSlotItemHandler firstSlot = null;
|
||||
for (final Slot slot : container.inventorySlots) {
|
||||
|
||||
@@ -50,6 +50,9 @@ public final class Constants {
|
||||
|
||||
public static final String TOOLTIP_DESCRIPTION_SUFFIX = ".desc";
|
||||
public static final String TOOLTIP_DEVICE_NEEDS_REBOOT = "tooltip.oc2.device_needs_reboot";
|
||||
public static final String TOOLTIP_FLASH_MEMORY_MISSING = "tooltip.oc2.flash_memory_missing";
|
||||
public static final String TOOLTIP_MEMORY_MISSING = "tooltip.oc2.memory_missing";
|
||||
public static final String TOOLTIP_HARD_DRIVE_MISSING = "tooltip.oc2.hard_drive_missing";
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -58,5 +58,8 @@
|
||||
"message.oc2.connector.error.too_far": "Distance between connectors is too large.",
|
||||
"message.oc2.connector.error.obstructed": "No clear line of sight between connectors.",
|
||||
|
||||
"tooltip.oc2.device_needs_reboot": "Requires reboot"
|
||||
"tooltip.oc2.device_needs_reboot": "Requires reboot",
|
||||
"tooltip.oc2.flash_memory_missing": "A flash memory containing a firmware is required to boot.",
|
||||
"tooltip.oc2.memory_missing": "Some memory is required to load the flash memory for execution to boot.",
|
||||
"tooltip.oc2.hard_drive_missing": "Most systems will require a root file system to boot."
|
||||
}
|
||||
Reference in New Issue
Block a user