Change crafting monitor task tooltip.
This commit is contained in:
@@ -89,6 +89,11 @@ public interface ICraftingTask {
|
||||
*/
|
||||
boolean isValid();
|
||||
|
||||
/**
|
||||
* @return the time in ms when this task has started
|
||||
*/
|
||||
long getExecutionStarted();
|
||||
|
||||
/**
|
||||
* @return the missing items
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.raoulvdberge.refinedstorage.api.network.grid;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
@@ -18,9 +19,15 @@ public interface IGridTab {
|
||||
List<IFilter> getFilters();
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
* Draws the tooltip of this tab at the given position.
|
||||
*
|
||||
* @param x the x position
|
||||
* @param y the y position
|
||||
* @param screenWidth the screen width
|
||||
* @param screenHeight the screen height
|
||||
* @param fontRenderer the font renderer
|
||||
*/
|
||||
String getName();
|
||||
void drawTooltip(int x, int y, int screenWidth, int screenHeight, FontRenderer fontRenderer);
|
||||
|
||||
/**
|
||||
* @return the icon
|
||||
|
||||
@@ -49,6 +49,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
private static final String NBT_TICKS = "Ticks";
|
||||
private static final String NBT_ID = "Id";
|
||||
private static final String NBT_MISSING = "Missing";
|
||||
private static final String NBT_EXECUTION_STARTED = "ExecutionStarted";
|
||||
|
||||
private INetwork network;
|
||||
private ItemStack requested;
|
||||
@@ -59,6 +60,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
private Set<ICraftingPattern> patternsUsed = new HashSet<>();
|
||||
private int ticks = 0;
|
||||
private long calculationStarted;
|
||||
private long executionStarted = -1;
|
||||
private UUID id = UUID.randomUUID();
|
||||
|
||||
private IStackList<ItemStack> toTake = API.instance().createItemStackList();
|
||||
@@ -104,6 +106,10 @@ public class CraftingTask implements ICraftingTask {
|
||||
|
||||
this.missing.add(missingItem);
|
||||
}
|
||||
|
||||
if (tag.hasKey(NBT_EXECUTION_STARTED)) {
|
||||
this.executionStarted = tag.getLong(NBT_EXECUTION_STARTED);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -297,6 +303,10 @@ public class CraftingTask implements ICraftingTask {
|
||||
|
||||
@Override
|
||||
public boolean update() {
|
||||
if (executionStarted == -1) {
|
||||
executionStarted = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
boolean allCompleted = true;
|
||||
|
||||
if (ticks % getTickInterval(pattern.getContainer().getSpeedUpgradeCount()) == 0) {
|
||||
@@ -513,6 +523,11 @@ public class CraftingTask implements ICraftingTask {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getExecutionStarted() {
|
||||
return executionStarted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStackList<ItemStack> getMissing() {
|
||||
return missing;
|
||||
@@ -531,6 +546,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
tag.setTag(NBT_INSERTER, inserter.writeToNbt());
|
||||
tag.setInteger(NBT_TICKS, ticks);
|
||||
tag.setUniqueId(NBT_ID, id);
|
||||
tag.setLong(NBT_EXECUTION_STARTED, executionStarted);
|
||||
|
||||
NBTTagList steps = new NBTTagList();
|
||||
for (CraftingStep step : this.steps) {
|
||||
|
||||
@@ -2,8 +2,11 @@ package com.raoulvdberge.refinedstorage.apiimpl.network.grid;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridTab;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.client.config.GuiUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GridTab implements IGridTab {
|
||||
@@ -23,8 +26,10 @@ public class GridTab implements IGridTab {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
public void drawTooltip(int x, int y, int screenWidth, int screenHeight, FontRenderer fontRenderer) {
|
||||
if (!name.trim().equals("")) {
|
||||
GuiUtils.drawHoveringText(Collections.singletonList(name), x, y, screenWidth, screenHeight, -1, fontRenderer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -92,6 +92,14 @@ public abstract class GuiBase extends GuiContainer {
|
||||
}
|
||||
}
|
||||
|
||||
public int getScreenWidth() {
|
||||
return screenWidth;
|
||||
}
|
||||
|
||||
public int getScreenHeight() {
|
||||
return screenHeight;
|
||||
}
|
||||
|
||||
public Scrollbar getScrollbar() {
|
||||
return scrollbar;
|
||||
}
|
||||
@@ -374,7 +382,7 @@ public abstract class GuiBase extends GuiContainer {
|
||||
|
||||
public void drawTooltip(@Nonnull ItemStack stack, int x, int y, List<String> lines) {
|
||||
GlStateManager.disableLighting();
|
||||
GuiUtils.drawHoveringText(stack, lines, x, y, width - guiLeft, height, -1, fontRenderer);
|
||||
GuiUtils.drawHoveringText(stack, lines, x, y, screenWidth, screenHeight, -1, fontRenderer);
|
||||
GlStateManager.enableLighting();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.raoulvdberge.refinedstorage.gui;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
@@ -15,6 +16,8 @@ import com.raoulvdberge.refinedstorage.gui.control.SideButtonRedstoneMode;
|
||||
import com.raoulvdberge.refinedstorage.gui.control.TabList;
|
||||
import com.raoulvdberge.refinedstorage.network.MessageCraftingMonitorCancel;
|
||||
import com.raoulvdberge.refinedstorage.tile.craftingmonitor.ICraftingMonitor;
|
||||
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
@@ -45,12 +48,14 @@ public class GuiCraftingMonitor extends GuiBase implements IResizableDisplay {
|
||||
private UUID id;
|
||||
private ItemStack requested;
|
||||
private int qty;
|
||||
private long executionStarted;
|
||||
private List<ICraftingMonitorElement> elements;
|
||||
|
||||
public CraftingMonitorTask(UUID id, ItemStack requested, int qty, List<ICraftingMonitorElement> elements) {
|
||||
public CraftingMonitorTask(UUID id, ItemStack requested, int qty, long executionStarted, List<ICraftingMonitorElement> elements) {
|
||||
this.id = id;
|
||||
this.requested = requested;
|
||||
this.qty = qty;
|
||||
this.executionStarted = executionStarted;
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
@@ -60,8 +65,18 @@ public class GuiCraftingMonitor extends GuiBase implements IResizableDisplay {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return qty + "x " + requested.getDisplayName();
|
||||
public void drawTooltip(int x, int y, int screenWidth, int screenHeight, FontRenderer fontRenderer) {
|
||||
List<String> textLines = Lists.newArrayList(requested.getDisplayName());
|
||||
List<String> smallTextLines = Lists.newArrayList();
|
||||
|
||||
int totalSecs = (int) (System.currentTimeMillis() - executionStarted) / 1000;
|
||||
int minutes = (totalSecs % 3600) / 60;
|
||||
int seconds = totalSecs % 60;
|
||||
|
||||
smallTextLines.add(I18n.format("gui.refinedstorage:crafting_monitor.tooltip.requested", qty));
|
||||
smallTextLines.add(String.format("%02d:%02d", minutes, seconds));
|
||||
|
||||
RenderUtils.drawTooltipWithSmallText(textLines, smallTextLines, true, ItemStack.EMPTY, x, y, screenWidth, screenHeight, fontRenderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,6 +104,7 @@ public class GuiCraftingMonitor extends GuiBase implements IResizableDisplay {
|
||||
super(container, 176, 230);
|
||||
|
||||
this.craftingMonitor = craftingMonitor;
|
||||
|
||||
this.tabs = new TabList(this, () -> tasks, () -> (int) Math.floor((float) Math.max(0, tasks.size() - 1) / (float) ICraftingMonitor.TABS_PER_PAGE), craftingMonitor::getTabPage, () -> {
|
||||
IGridTab tab = getCurrentTab();
|
||||
|
||||
@@ -98,6 +114,7 @@ public class GuiCraftingMonitor extends GuiBase implements IResizableDisplay {
|
||||
|
||||
return tasks.indexOf(tab);
|
||||
}, ICraftingMonitor.TABS_PER_PAGE);
|
||||
|
||||
this.tabs.addListener(new TabList.ITabListListener() {
|
||||
@Override
|
||||
public void onSelectionChanged(int tab) {
|
||||
|
||||
@@ -144,8 +144,8 @@ public class TabList {
|
||||
}
|
||||
|
||||
public void drawTooltip(FontRenderer fontRenderer, int mouseX, int mouseY) {
|
||||
if (tabHovering >= 0 && tabHovering < tabs.get().size() && !tabs.get().get(tabHovering).getName().equalsIgnoreCase("")) {
|
||||
gui.drawTooltip(mouseX, mouseY, tabs.get().get(tabHovering).getName());
|
||||
if (tabHovering >= 0 && tabHovering < tabs.get().size()) {
|
||||
tabs.get().get(tabHovering).drawTooltip(mouseX, mouseY, gui.getScreenWidth(), gui.getScreenHeight(), fontRenderer);
|
||||
}
|
||||
|
||||
if (pages.get() > 0) {
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.raoulvdberge.refinedstorage.tile.grid.portable.TilePortableGrid;
|
||||
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||
import com.raoulvdberge.refinedstorage.util.TimeUtils;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
@@ -34,11 +33,7 @@ import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.client.event.RenderTooltipEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.client.config.GuiCheckBox;
|
||||
import net.minecraftforge.fml.client.config.GuiUtils;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -377,154 +372,21 @@ public class GuiGrid extends GuiBase implements IResizableDisplay {
|
||||
tabs.drawTooltip(fontRenderer, mouseX, mouseY);
|
||||
}
|
||||
|
||||
// Copied with some tweaks from GuiUtils#drawHoveringText(@Nonnull final ItemStack stack, List<String> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight, int maxTextWidth, FontRenderer font)
|
||||
public void drawGridTooltip(IGridStack gridStack, int mouseX, int mouseY) {
|
||||
// RS BEGIN
|
||||
private void drawGridTooltip(IGridStack gridStack, int mouseX, int mouseY) {
|
||||
List<String> textLines = Lists.newArrayList(gridStack.getTooltip().split("\n"));
|
||||
List<String> smallTextLines = Lists.newArrayList();
|
||||
|
||||
if (RS.INSTANCE.config.detailedTooltip) {
|
||||
if (!(gridStack instanceof GridStackItem) || !((GridStackItem) gridStack).doesDisplayCraftText()) {
|
||||
textLines.add("");
|
||||
}
|
||||
if (!(gridStack instanceof GridStackItem) || !((GridStackItem) gridStack).doesDisplayCraftText()) {
|
||||
smallTextLines.add(I18n.format("misc.refinedstorage:total", gridStack.getFormattedFullQuantity()));
|
||||
}
|
||||
|
||||
if (gridStack.getTrackerEntry() != null) {
|
||||
textLines.add("");
|
||||
}
|
||||
if (gridStack.getTrackerEntry() != null) {
|
||||
smallTextLines.add(TimeUtils.getAgo(gridStack.getTrackerEntry().getTime(), gridStack.getTrackerEntry().getName()));
|
||||
}
|
||||
|
||||
ItemStack stack = gridStack instanceof GridStackItem ? ((GridStackItem) gridStack).getStack() : ItemStack.EMPTY;
|
||||
// RS END
|
||||
|
||||
if (!textLines.isEmpty()) {
|
||||
RenderTooltipEvent.Pre event = new RenderTooltipEvent.Pre(stack, textLines, mouseX, mouseY, screenWidth, screenHeight, -1, fontRenderer);
|
||||
if (MinecraftForge.EVENT_BUS.post(event)) {
|
||||
return;
|
||||
}
|
||||
mouseX = event.getX();
|
||||
mouseY = event.getY();
|
||||
screenWidth = event.getScreenWidth();
|
||||
screenHeight = event.getScreenHeight();
|
||||
FontRenderer font = event.getFontRenderer();
|
||||
|
||||
// RS BEGIN
|
||||
float textScale = font.getUnicodeFlag() ? 1F : 0.7F;
|
||||
// RS END
|
||||
|
||||
GlStateManager.disableRescaleNormal();
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableDepth();
|
||||
int tooltipTextWidth = 0;
|
||||
|
||||
for (String textLine : textLines) {
|
||||
int textLineWidth = font.getStringWidth(textLine);
|
||||
|
||||
if (textLineWidth > tooltipTextWidth) {
|
||||
tooltipTextWidth = textLineWidth;
|
||||
}
|
||||
}
|
||||
|
||||
// RS BEGIN
|
||||
if (RS.INSTANCE.config.detailedTooltip) {
|
||||
int size;
|
||||
|
||||
if (!(gridStack instanceof GridStackItem) || !((GridStackItem) gridStack).doesDisplayCraftText()) {
|
||||
size = (int) (font.getStringWidth(I18n.format("misc.refinedstorage:total", gridStack.getFormattedFullQuantity())) * textScale);
|
||||
|
||||
if (size > tooltipTextWidth) {
|
||||
tooltipTextWidth = size;
|
||||
}
|
||||
}
|
||||
|
||||
if (gridStack.getTrackerEntry() != null) {
|
||||
size = (int) (font.getStringWidth(TimeUtils.getAgo(gridStack.getTrackerEntry().getTime(), gridStack.getTrackerEntry().getName())) * textScale);
|
||||
|
||||
if (size > tooltipTextWidth) {
|
||||
tooltipTextWidth = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
// RS END
|
||||
|
||||
int titleLinesCount = 1;
|
||||
int tooltipX = mouseX + 12;
|
||||
|
||||
int tooltipY = mouseY - 12;
|
||||
int tooltipHeight = 8;
|
||||
|
||||
if (textLines.size() > 1) {
|
||||
tooltipHeight += (textLines.size() - 1) * 10;
|
||||
if (textLines.size() > titleLinesCount) {
|
||||
tooltipHeight += 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (tooltipY + tooltipHeight + 6 > screenHeight) {
|
||||
tooltipY = screenHeight - tooltipHeight - 6;
|
||||
}
|
||||
|
||||
final int zLevel = 300;
|
||||
final int backgroundColor = 0xF0100010;
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor);
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor);
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
|
||||
final int borderColorStart = 0x505000FF;
|
||||
final int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000;
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart);
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd);
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostBackground(stack, textLines, tooltipX, tooltipY, font, tooltipTextWidth, tooltipHeight));
|
||||
int tooltipTop = tooltipY;
|
||||
|
||||
for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) {
|
||||
String line = textLines.get(lineNumber);
|
||||
font.drawStringWithShadow(line, (float) tooltipX, (float) tooltipY, -1);
|
||||
|
||||
if (lineNumber + 1 == titleLinesCount) {
|
||||
tooltipY += 2;
|
||||
}
|
||||
|
||||
tooltipY += 10;
|
||||
}
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(stack, textLines, tooltipX, tooltipTop, font, tooltipTextWidth, tooltipHeight));
|
||||
|
||||
// RS BEGIN
|
||||
if (RS.INSTANCE.config.detailedTooltip) {
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(textScale, textScale, 1);
|
||||
|
||||
if (!(gridStack instanceof GridStackItem) || !((GridStackItem) gridStack).doesDisplayCraftText()) {
|
||||
font.drawStringWithShadow(
|
||||
TextFormatting.GRAY + I18n.format("misc.refinedstorage:total", gridStack.getFormattedFullQuantity()),
|
||||
RenderUtils.getOffsetOnScale(tooltipX, textScale),
|
||||
RenderUtils.getOffsetOnScale(tooltipTop + tooltipHeight - (gridStack.getTrackerEntry() != null ? 15 : 6) - (font.getUnicodeFlag() ? 2 : 0), textScale),
|
||||
-1
|
||||
);
|
||||
}
|
||||
|
||||
if (gridStack.getTrackerEntry() != null) {
|
||||
font.drawStringWithShadow(
|
||||
TextFormatting.GRAY + TimeUtils.getAgo(gridStack.getTrackerEntry().getTime(), gridStack.getTrackerEntry().getName()),
|
||||
RenderUtils.getOffsetOnScale(tooltipX, textScale),
|
||||
RenderUtils.getOffsetOnScale(tooltipTop + tooltipHeight - 6 - (font.getUnicodeFlag() ? 2 : 0), textScale),
|
||||
-1
|
||||
);
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
// RS END
|
||||
|
||||
GlStateManager.enableLighting();
|
||||
GlStateManager.enableDepth();
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
GlStateManager.enableRescaleNormal();
|
||||
}
|
||||
RenderUtils.drawTooltipWithSmallText(textLines, smallTextLines, RS.INSTANCE.config.detailedTooltip, stack, mouseX, mouseY, screenWidth, screenHeight, fontRenderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,16 +6,12 @@ import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageTrackerEntry;
|
||||
import com.raoulvdberge.refinedstorage.gui.GuiBase;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GridStackItem implements IGridStack {
|
||||
@@ -103,18 +99,7 @@ public class GridStackItem implements IGridStack {
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
try {
|
||||
List<String> lines = stack.getTooltip(Minecraft.getMinecraft().player, Minecraft.getMinecraft().gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL);
|
||||
|
||||
// From GuiScreen#renderToolTip
|
||||
for (int i = 0; i < lines.size(); ++i) {
|
||||
if (i == 0) {
|
||||
lines.set(i, stack.getRarity().rarityColor + lines.get(i));
|
||||
} else {
|
||||
lines.set(i, TextFormatting.GRAY + lines.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
return lines.stream().collect(Collectors.joining("\n"));
|
||||
return StackUtils.getItemTooltip(stack).stream().collect(Collectors.joining("\n"));
|
||||
} catch (Throwable t) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ItemFilter extends ItemBase {
|
||||
public String getItemStackDisplayName(ItemStack stack) {
|
||||
String name = getName(stack);
|
||||
|
||||
if (!name.equalsIgnoreCase("")) {
|
||||
if (!name.trim().equals("")) {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ public class MessageCraftingMonitorElements implements IMessage, IMessageHandler
|
||||
UUID id = UUID.fromString(ByteBufUtils.readUTF8String(buf));
|
||||
ItemStack requested = ByteBufUtils.readItemStack(buf);
|
||||
int qty = buf.readInt();
|
||||
long executionStarted = buf.readLong();
|
||||
|
||||
List<ICraftingMonitorElement> elements = new ArrayList<>();
|
||||
|
||||
int elementCount = buf.readInt();
|
||||
@@ -51,7 +53,7 @@ public class MessageCraftingMonitorElements implements IMessage, IMessageHandler
|
||||
}
|
||||
}
|
||||
|
||||
tasks.add(new GuiCraftingMonitor.CraftingMonitorTask(id, requested, qty, elements));
|
||||
tasks.add(new GuiCraftingMonitor.CraftingMonitorTask(id, requested, qty, executionStarted, elements));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +65,7 @@ public class MessageCraftingMonitorElements implements IMessage, IMessageHandler
|
||||
ByteBufUtils.writeUTF8String(buf, task.getId().toString());
|
||||
ByteBufUtils.writeItemStack(buf, task.getRequested());
|
||||
buf.writeInt(task.getQuantity());
|
||||
buf.writeLong(task.getExecutionStarted());
|
||||
|
||||
List<ICraftingMonitorElement> elements = task.getCraftingMonitorElements();
|
||||
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.raoulvdberge.refinedstorage.util;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
@@ -18,10 +20,15 @@ import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.client.event.RenderTooltipEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.client.config.GuiUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
import java.util.Collection;
|
||||
@@ -325,4 +332,136 @@ public final class RenderUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copied with some tweaks from GuiUtils#drawHoveringText(@Nonnull final ItemStack stack, List<String> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight, int maxTextWidth, FontRenderer font)
|
||||
public static void drawTooltipWithSmallText(List<String> textLines, List<String> smallTextLines, boolean showSmallText, @Nonnull ItemStack stack, int mouseX, int mouseY, int screenWidth, int screenHeight, FontRenderer fontRenderer) {
|
||||
// RS BEGIN
|
||||
if (showSmallText) {
|
||||
for (int i = 0; i < smallTextLines.size(); ++i) {
|
||||
textLines.add("");
|
||||
}
|
||||
}
|
||||
// RS END
|
||||
|
||||
if (!textLines.isEmpty()) {
|
||||
RenderTooltipEvent.Pre event = new RenderTooltipEvent.Pre(stack, textLines, mouseX, mouseY, screenWidth, screenHeight, -1, fontRenderer);
|
||||
if (MinecraftForge.EVENT_BUS.post(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
mouseX = event.getX();
|
||||
mouseY = event.getY();
|
||||
|
||||
screenWidth = event.getScreenWidth();
|
||||
screenHeight = event.getScreenHeight();
|
||||
|
||||
FontRenderer font = event.getFontRenderer();
|
||||
|
||||
// RS BEGIN
|
||||
float textScale = font.getUnicodeFlag() ? 1F : 0.7F;
|
||||
// RS END
|
||||
|
||||
GlStateManager.disableRescaleNormal();
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableDepth();
|
||||
int tooltipTextWidth = 0;
|
||||
|
||||
for (String textLine : textLines) {
|
||||
int textLineWidth = font.getStringWidth(textLine);
|
||||
|
||||
if (textLineWidth > tooltipTextWidth) {
|
||||
tooltipTextWidth = textLineWidth;
|
||||
}
|
||||
}
|
||||
|
||||
// RS BEGIN
|
||||
if (showSmallText) {
|
||||
int size;
|
||||
|
||||
for (String smallText : smallTextLines) {
|
||||
size = (int) (font.getStringWidth(smallText) * textScale);
|
||||
|
||||
if (size > tooltipTextWidth) {
|
||||
tooltipTextWidth = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
// RS END
|
||||
|
||||
int titleLinesCount = 1;
|
||||
int tooltipX = mouseX + 12;
|
||||
|
||||
int tooltipY = mouseY - 12;
|
||||
int tooltipHeight = 8;
|
||||
|
||||
if (textLines.size() > 1) {
|
||||
tooltipHeight += (textLines.size() - 1) * 10;
|
||||
if (textLines.size() > titleLinesCount) {
|
||||
tooltipHeight += 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (tooltipY + tooltipHeight + 6 > screenHeight) {
|
||||
tooltipY = screenHeight - tooltipHeight - 6;
|
||||
}
|
||||
|
||||
final int zLevel = 300;
|
||||
final int backgroundColor = 0xF0100010;
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor);
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor);
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
|
||||
final int borderColorStart = 0x505000FF;
|
||||
final int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000;
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart);
|
||||
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd);
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostBackground(stack, textLines, tooltipX, tooltipY, font, tooltipTextWidth, tooltipHeight));
|
||||
int tooltipTop = tooltipY;
|
||||
|
||||
for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) {
|
||||
String line = textLines.get(lineNumber);
|
||||
font.drawStringWithShadow(line, (float) tooltipX, (float) tooltipY, -1);
|
||||
|
||||
if (lineNumber + 1 == titleLinesCount) {
|
||||
tooltipY += 2;
|
||||
}
|
||||
|
||||
tooltipY += 10;
|
||||
}
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(stack, textLines, tooltipX, tooltipTop, font, tooltipTextWidth, tooltipHeight));
|
||||
|
||||
// RS BEGIN
|
||||
if (showSmallText) {
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(textScale, textScale, 1);
|
||||
|
||||
int y = tooltipTop + tooltipHeight - 6;
|
||||
|
||||
for (int i = smallTextLines.size() - 1; i >= 0; --i) {
|
||||
font.drawStringWithShadow(
|
||||
TextFormatting.GRAY + smallTextLines.get(i),
|
||||
RenderUtils.getOffsetOnScale(tooltipX, textScale),
|
||||
RenderUtils.getOffsetOnScale(y - (font.getUnicodeFlag() ? 2 : 0), textScale),
|
||||
-1
|
||||
);
|
||||
|
||||
y -= 9;
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
// RS END
|
||||
|
||||
GlStateManager.enableLighting();
|
||||
GlStateManager.enableDepth();
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
GlStateManager.enableRescaleNormal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskProvider;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -14,6 +16,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
@@ -31,6 +34,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -292,4 +296,19 @@ public final class StackUtils {
|
||||
|
||||
return Pair.of(null, null);
|
||||
}
|
||||
|
||||
public static List<String> getItemTooltip(ItemStack stack) {
|
||||
List<String> lines = stack.getTooltip(Minecraft.getMinecraft().player, Minecraft.getMinecraft().gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL);
|
||||
|
||||
// From GuiScreen#getItemToolTip
|
||||
for (int i = 0; i < lines.size(); ++i) {
|
||||
if (i == 0) {
|
||||
lines.set(i, stack.getRarity().rarityColor + lines.get(i));
|
||||
} else {
|
||||
lines.set(i, TextFormatting.GRAY + lines.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ gui.refinedstorage:interface.import=Interface Import
|
||||
gui.refinedstorage:interface.export=Interface Export
|
||||
gui.refinedstorage:crafting_monitor=Crafting Monitor
|
||||
gui.refinedstorage:wireless_crafting_monitor=Wireless Crafting Monitor
|
||||
gui.refinedstorage:crafting_monitor.tooltip.requested=%d requested
|
||||
gui.refinedstorage:crafting_monitor.fluids_taking=Fluids taking
|
||||
gui.refinedstorage:crafting_monitor.items_crafting=Items crafting
|
||||
gui.refinedstorage:crafting_monitor.items_processing=Items processing
|
||||
|
||||
Reference in New Issue
Block a user