fix: the Grid detailed tooltip now has a small font size again
This commit is contained in:
@@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- The Grid detailed tooltip now has a small font size again.
|
||||
|
||||
## [1.12.1] - 2023-07-03
|
||||
|
||||
### Fixed
|
||||
|
@@ -33,17 +33,22 @@ import com.refinedmods.refinedstorage.util.RenderUtils;
|
||||
import com.refinedmods.refinedstorage.util.TimeUtils;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.DefaultTooltipPositioner;
|
||||
import net.minecraft.client.resources.language.I18n;
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import yalter.mousetweaks.api.MouseTweaksDisableWheelTweak;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -492,25 +497,34 @@ public class GridScreen extends BaseScreen<GridContainerMenu> implements IScreen
|
||||
}
|
||||
|
||||
private void drawGridTooltip(GuiGraphics graphics, IGridStack gridStack, int mouseX, int mouseY) {
|
||||
List<Component> textLines = gridStack.getTooltip(true);
|
||||
|
||||
ItemStack stackContext = gridStack instanceof ItemGridStack ? ((ItemGridStack) gridStack).getStack() : ItemStack.EMPTY;
|
||||
|
||||
if (RS.CLIENT_CONFIG.getGrid().getDetailedTooltip()) {
|
||||
Style detailedTextStyle = Style.EMPTY.applyFormat(ChatFormatting.GRAY).withItalic(true);
|
||||
List<? extends FormattedText> textElements = gridStack.getTooltip(true);
|
||||
List<ClientTooltipComponent> components = new ArrayList<>(ForgeHooksClient.gatherTooltipComponents(
|
||||
stackContext,
|
||||
textElements,
|
||||
mouseX,
|
||||
minecraft.getWindow().getGuiScaledWidth(),
|
||||
minecraft.getWindow().getGuiScaledHeight(),
|
||||
font
|
||||
));
|
||||
|
||||
if (RS.CLIENT_CONFIG.getGrid().getDetailedTooltip()) {
|
||||
final float scale = (minecraft != null && minecraft.isEnforceUnicode()) ? 1F : 0.7F;
|
||||
if (!gridStack.isCraftable()) {
|
||||
textLines.add(Component.translatable("misc.refinedstorage.total", gridStack.getFormattedFullQuantity())
|
||||
.withStyle(detailedTextStyle));
|
||||
MutableComponent total = Component.translatable("misc.refinedstorage.total", gridStack.getFormattedFullQuantity())
|
||||
.withStyle(ChatFormatting.GRAY);
|
||||
components.add(new SmallClientTooltipComponent(total, scale));
|
||||
}
|
||||
|
||||
if (gridStack.getTrackerEntry() != null) {
|
||||
textLines.add(Component.translatable(TimeUtils.getAgo(gridStack.getTrackerEntry().getTime(), gridStack.getTrackerEntry().getName()))
|
||||
.withStyle(detailedTextStyle));
|
||||
MutableComponent time = Component.translatable(TimeUtils.getAgo(gridStack.getTrackerEntry().getTime(), gridStack.getTrackerEntry().getName()))
|
||||
.withStyle(ChatFormatting.GRAY);
|
||||
components.add(new SmallClientTooltipComponent(time, scale));
|
||||
}
|
||||
}
|
||||
|
||||
renderTooltip(graphics, stackContext, mouseX, mouseY, textLines);
|
||||
graphics.renderTooltipInternal(font, components, mouseX, mouseY, DefaultTooltipPositioner.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -0,0 +1,34 @@
|
||||
package com.refinedmods.refinedstorage.screen.grid;
|
||||
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
public class SmallClientTooltipComponent implements ClientTooltipComponent {
|
||||
private final Component component;
|
||||
private final float scale;
|
||||
|
||||
public SmallClientTooltipComponent(Component component, float scale) {
|
||||
this.component = component;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderText(Font font, int x, int y, Matrix4f pose, MultiBufferSource.BufferSource buffer) {
|
||||
Matrix4f scaled = new Matrix4f(pose);
|
||||
scaled.scale(scale, scale, 1);
|
||||
font.drawInBatch(component, x / scale, y / scale, -1, true, scaled, buffer, Font.DisplayMode.NORMAL, 0, 15728880);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth(Font font) {
|
||||
return (int) (font.width(component) * scale);
|
||||
}
|
||||
}
|
@@ -2,4 +2,5 @@ protected net.minecraft.world.inventory.AbstractContainerMenu f_38841_ # invento
|
||||
protected net.minecraft.world.inventory.AbstractContainerMenu f_38848_ # listeners
|
||||
protected net.minecraft.client.gui.components.EditBox f_94097_ # canLoseFocus
|
||||
public net.minecraft.client.gui.components.Checkbox f_93822_ # checked
|
||||
public-f net.minecraft.world.inventory.Slot f_40221_ # yPos
|
||||
public-f net.minecraft.world.inventory.Slot f_40221_ # yPos
|
||||
public net.minecraft.client.gui.GuiGraphics m_280497_(Lnet/minecraft/client/gui/Font;Ljava/util/List;IILnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner;)V # renderTooltipInternal
|
||||
|
Reference in New Issue
Block a user