mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-10 12:33:57 +01:00
Goggle Tooltip code cleanup and ModernUI compat (#6477)
* Goggle Tooltip code cleanup and ModernUI compat fixes Creators-of-Create#6404 * Calculate indents based on font thanks @Tidy-Bear * exactPositioning workaround --------- Co-authored-by: zelophed <github@zelophed.me>
This commit is contained in:
parent
3c9c668b56
commit
a5dc53ba5f
@ -207,6 +207,7 @@ dependencies {
|
||||
// runtimeOnly fg.deobf("maven.modrinth:spark:1.10.38-forge")
|
||||
//runtimeOnly fg.deobf("curse.maven:forbidden-arcanus-309858:4729924")
|
||||
//runtimeOnly fg.deobf("curse.maven:valhelsia-core-416935:3886212")
|
||||
// implementation fg.deobf("curse.maven:modern-ui-352491:5229350")
|
||||
// runtimeOnly fg.deobf("curse.maven:sophisticated-storage-619320:5194748")
|
||||
// runtimeOnly fg.deobf("curse.maven:sophisticated-core-618298:5296312")
|
||||
// runtimeOnly fg.deobf("curse.maven:functional-storage-556861:5271589")
|
||||
|
@ -25,7 +25,8 @@ public enum Mods {
|
||||
SOPHISTICATEDSTORAGE,
|
||||
STORAGEDRAWERS,
|
||||
TCONSTRUCT,
|
||||
XLPACKETS;
|
||||
XLPACKETS,
|
||||
MODERNUI;
|
||||
|
||||
private final String id;
|
||||
|
||||
|
@ -22,15 +22,13 @@ public interface IDisplayAssemblyExceptions {
|
||||
if (!tooltip.isEmpty())
|
||||
tooltip.add(Components.immutableEmpty());
|
||||
|
||||
tooltip.add(IHaveGoggleInformation.componentSpacing.plainCopy()
|
||||
.append(Lang.translateDirect("gui.assembly.exception")
|
||||
.withStyle(ChatFormatting.GOLD)));
|
||||
Lang.translate("gui.assembly.exception").style(ChatFormatting.GOLD)
|
||||
.forGoggles(tooltip);
|
||||
|
||||
String text = e.component.getString();
|
||||
Arrays.stream(text.split("\n"))
|
||||
.forEach(l -> TooltipHelper.cutStringTextComponent(l, Palette.GRAY_AND_WHITE)
|
||||
.forEach(c -> tooltip.add(IHaveGoggleInformation.componentSpacing.plainCopy()
|
||||
.append(c))));
|
||||
.forEach(c -> Lang.text(c.getString()).forGoggles(tooltip)));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -27,14 +27,14 @@ public class ElevatorContactEditPacket extends BlockEntityConfigurationPacket<El
|
||||
@Override
|
||||
protected void writeSettings(FriendlyByteBuf buffer) {
|
||||
buffer.writeUtf(shortName, 4);
|
||||
buffer.writeUtf(longName, 30);
|
||||
buffer.writeUtf(longName, 90);
|
||||
buffer.writeVarInt(doorControl.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readSettings(FriendlyByteBuf buffer) {
|
||||
shortName = buffer.readUtf(4);
|
||||
longName = buffer.readUtf(30);
|
||||
longName = buffer.readUtf(90);
|
||||
doorControl = DoorControl.values()[Mth.clamp(buffer.readVarInt(), 0, DoorControl.values().length)];
|
||||
}
|
||||
|
||||
|
@ -112,8 +112,7 @@ public class WhistleBlockEntity extends SmartBlockEntity implements IHaveGoggleI
|
||||
String[] pitches = Lang.translateDirect("generic.notes")
|
||||
.getString()
|
||||
.split(";");
|
||||
MutableComponent textComponent = Components.literal(spacing);
|
||||
tooltip.add(textComponent.append(Lang.translateDirect("generic.pitch", pitches[pitch % pitches.length])));
|
||||
Lang.translate("generic.pitch", pitches[pitch % pitches.length]).forGoggles(tooltip);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -4,10 +4,12 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.mojang.blaze3d.platform.Window;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.CreateClient;
|
||||
import com.simibubi.create.compat.Mods;
|
||||
import com.simibubi.create.content.contraptions.IDisplayAssemblyExceptions;
|
||||
import com.simibubi.create.content.contraptions.piston.MechanicalPistonBlock;
|
||||
import com.simibubi.create.content.contraptions.piston.PistonExtensionPoleBlock;
|
||||
@ -16,6 +18,7 @@ import com.simibubi.create.foundation.blockEntity.behaviour.ValueBox;
|
||||
import com.simibubi.create.foundation.gui.RemovedGuiUtils;
|
||||
import com.simibubi.create.foundation.gui.Theme;
|
||||
import com.simibubi.create.foundation.gui.element.GuiGameElement;
|
||||
import com.simibubi.create.foundation.mixin.accessor.MouseHandlerAccessor;
|
||||
import com.simibubi.create.foundation.outliner.Outline;
|
||||
import com.simibubi.create.foundation.outliner.Outliner.OutlineEntry;
|
||||
import com.simibubi.create.foundation.utility.Color;
|
||||
@ -26,6 +29,7 @@ import com.simibubi.create.infrastructure.config.AllConfigs;
|
||||
import com.simibubi.create.infrastructure.config.CClient;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.MouseHandler;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
@ -154,9 +158,8 @@ public class GoggleOverlayRenderer {
|
||||
if (!tooltip.isEmpty())
|
||||
tooltip.add(Components.immutableEmpty());
|
||||
|
||||
tooltip.add(IHaveGoggleInformation.componentSpacing.plainCopy()
|
||||
.append(Lang.translateDirect("gui.goggles.pole_length"))
|
||||
.append(Components.literal(" " + poles)));
|
||||
Lang.translate("gui.goggles.pole_length").text(" " + poles)
|
||||
.forGoggles(tooltip);
|
||||
}
|
||||
|
||||
if (tooltip.isEmpty()) {
|
||||
@ -205,14 +208,44 @@ public class GoggleOverlayRenderer {
|
||||
colorBorderBot.scaleAlpha(fade);
|
||||
}
|
||||
|
||||
RemovedGuiUtils.drawHoveringText(poseStack, tooltip, posX, posY, width, height, -1, colorBackground.getRGB(),
|
||||
colorBorderTop.getRGB(), colorBorderBot.getRGB(), mc.font);
|
||||
|
||||
|
||||
GuiGameElement.of(item)
|
||||
.at(posX + 10, posY - 16, 450)
|
||||
.render(poseStack);
|
||||
|
||||
if (!Mods.MODERNUI.isLoaded()) {
|
||||
// default tooltip rendering when modernUI is not loaded
|
||||
RemovedGuiUtils.drawHoveringText(poseStack, tooltip, posX, posY, width, height, -1, colorBackground.getRGB(),
|
||||
colorBorderTop.getRGB(), colorBorderBot.getRGB(), mc.font);
|
||||
|
||||
poseStack.popPose();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* special handling for modernUI
|
||||
*
|
||||
* their tooltip handler causes the overlay to jiggle each frame,
|
||||
* if the mouse is moving, guiScale is anything but 1 and exactPositioning is enabled
|
||||
*
|
||||
* this is a workaround to fix this behavior
|
||||
*/
|
||||
MouseHandler mouseHandler = Minecraft.getInstance().mouseHandler;
|
||||
Window window = Minecraft.getInstance().getWindow();
|
||||
double guiScale = window.getGuiScale();
|
||||
double cursorX = mouseHandler.xpos();
|
||||
double cursorY = mouseHandler.ypos();
|
||||
((MouseHandlerAccessor) mouseHandler).create$setXPos(Math.round(cursorX / guiScale) * guiScale);
|
||||
((MouseHandlerAccessor) mouseHandler).create$setYPos(Math.round(cursorY / guiScale) * guiScale);
|
||||
|
||||
RemovedGuiUtils.drawHoveringText(poseStack, tooltip, posX, posY, width, height, -1, colorBackground.getRGB(),
|
||||
colorBorderTop.getRGB(), colorBorderBot.getRGB(), mc.font);
|
||||
|
||||
((MouseHandlerAccessor) mouseHandler).create$setXPos(cursorX);
|
||||
((MouseHandlerAccessor) mouseHandler).create$setYPos(cursorY);
|
||||
|
||||
poseStack.popPose();
|
||||
|
||||
}
|
||||
|
||||
public static BlockPos proxiedOverlayPosition(Level level, BlockPos pos) {
|
||||
|
@ -147,20 +147,13 @@ public class BoilerData {
|
||||
if (!isActive())
|
||||
return false;
|
||||
|
||||
Component indent = Components.literal(IHaveGoggleInformation.spacing);
|
||||
Component indent2 = Components.literal(IHaveGoggleInformation.spacing + " ");
|
||||
|
||||
calcMinMaxForSize(boilerSize);
|
||||
|
||||
tooltip.add(indent.plainCopy()
|
||||
.append(
|
||||
Lang.translateDirect("boiler.status", getHeatLevelTextComponent().withStyle(ChatFormatting.GREEN))));
|
||||
tooltip.add(indent2.plainCopy()
|
||||
.append(getSizeComponent(true, false)));
|
||||
tooltip.add(indent2.plainCopy()
|
||||
.append(getWaterComponent(true, false)));
|
||||
tooltip.add(indent2.plainCopy()
|
||||
.append(getHeatComponent(true, false)));
|
||||
Lang.translate("boiler.status", getHeatLevelTextComponent().withStyle(ChatFormatting.GREEN))
|
||||
.forGoggles(tooltip);
|
||||
Lang.text(getSizeComponent(true, false).getString()).forGoggles(tooltip, 1);
|
||||
Lang.text(getWaterComponent(true, false).getString()).forGoggles(tooltip, 1);
|
||||
Lang.text(getHeatComponent(true, false).getString()).forGoggles(tooltip, 1);
|
||||
|
||||
if (attachedEngines == 0)
|
||||
return true;
|
||||
|
@ -48,7 +48,7 @@ public abstract class GaugeBlockEntity extends KineticBlockEntity implements IHa
|
||||
|
||||
@Override
|
||||
public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
|
||||
tooltip.add(componentSpacing.plainCopy().append(Lang.translateDirect("gui.gauge.info_header")));
|
||||
Lang.translate("gui.gauge.info_header").forGoggles(tooltip);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -784,20 +784,13 @@ public class BrassTunnelBlockEntity extends BeltTunnelBlockEntity implements IHa
|
||||
if (allStacks.isEmpty())
|
||||
return false;
|
||||
|
||||
tooltip.add(componentSpacing.plainCopy()
|
||||
.append(Lang.translateDirect("tooltip.brass_tunnel.contains"))
|
||||
.withStyle(ChatFormatting.WHITE));
|
||||
Lang.translate("tooltip.brass_tunnel.contains").style(ChatFormatting.WHITE).forGoggles(tooltip);
|
||||
for (ItemStack item : allStacks) {
|
||||
tooltip.add(componentSpacing.plainCopy()
|
||||
.append(Lang.translateDirect("tooltip.brass_tunnel.contains_entry",
|
||||
Components.translatable(item.getDescriptionId())
|
||||
.getString(),
|
||||
item.getCount()))
|
||||
.withStyle(ChatFormatting.GRAY));
|
||||
Lang.translate("tooltip.brass_tunnel.contains_entry",
|
||||
Components.translatable(item.getDescriptionId()).getString(), item.getCount())
|
||||
.style(ChatFormatting.GRAY).forGoggles(tooltip);
|
||||
}
|
||||
tooltip.add(componentSpacing.plainCopy()
|
||||
.append(Lang.translateDirect("tooltip.brass_tunnel.retrieve"))
|
||||
.withStyle(ChatFormatting.DARK_GRAY));
|
||||
Lang.translate("tooltip.brass_tunnel.retrieve").style(ChatFormatting.DARK_GRAY).forGoggles(tooltip);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public class AnalogLeverBlockEntity extends SmartBlockEntity implements IHaveGog
|
||||
|
||||
@Override
|
||||
public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
|
||||
tooltip.add(componentSpacing.plainCopy().append(Lang.translateDirect("tooltip.analogStrength", this.state)));
|
||||
Lang.translate("tooltip.analogStrength", this.state).forGoggles(tooltip);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.simibubi.create.content.equipment.goggles.IHaveGoggleInformation;
|
||||
import com.simibubi.create.foundation.utility.Components;
|
||||
import com.simibubi.create.foundation.utility.Couple;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
@ -30,15 +29,11 @@ public class TooltipHelper {
|
||||
}
|
||||
|
||||
public static void addHint(List<Component> tooltip, String hintKey, Object... messageParams) {
|
||||
Component spacing = IHaveGoggleInformation.componentSpacing;
|
||||
tooltip.add(spacing.plainCopy()
|
||||
.append(Lang.translateDirect(hintKey + ".title"))
|
||||
.withStyle(ChatFormatting.GOLD));
|
||||
Lang.translate(hintKey + ".title").style(ChatFormatting.GOLD).forGoggles(tooltip);
|
||||
Component hint = Lang.translateDirect(hintKey);
|
||||
List<Component> cutComponent = cutTextComponent(hint, Palette.GRAY_AND_WHITE);
|
||||
for (Component component : cutComponent)
|
||||
tooltip.add(spacing.plainCopy()
|
||||
.append(component));
|
||||
Lang.text(component.getString()).forGoggles(tooltip);
|
||||
}
|
||||
|
||||
public static String makeProgressBar(int length, int filledLength) {
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.simibubi.create.foundation.mixin.accessor;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import net.minecraft.client.MouseHandler;
|
||||
|
||||
@Mixin(MouseHandler.class)
|
||||
public interface MouseHandlerAccessor {
|
||||
|
||||
@Accessor("xpos")
|
||||
void create$setXPos(double xPos);
|
||||
|
||||
@Accessor("ypos")
|
||||
void create$setYPos(double yPos);
|
||||
}
|
@ -2,10 +2,15 @@ package com.simibubi.create.foundation.utility;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.simibubi.create.compat.Mods;
|
||||
|
||||
import joptsimple.internal.Strings;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public class LangBuilder {
|
||||
@ -150,11 +155,20 @@ public class LangBuilder {
|
||||
|
||||
public void forGoggles(List<? super MutableComponent> tooltip, int indents) {
|
||||
tooltip.add(Lang.builder()
|
||||
.text(Strings.repeat(' ', 4 + indents))
|
||||
.text(Strings.repeat(' ', getIndents(Minecraft.getInstance().font, 4 + indents)))
|
||||
.add(this)
|
||||
.component());
|
||||
}
|
||||
|
||||
public static final float DEFAULT_SPACE_WIDTH = 4.0F; // space width in vanilla's default font
|
||||
static int getIndents(Font font, int defaultIndents) {
|
||||
int spaceWidth = font.width(" ");
|
||||
if (DEFAULT_SPACE_WIDTH == spaceWidth) {
|
||||
return defaultIndents;
|
||||
}
|
||||
return Mth.ceil(DEFAULT_SPACE_WIDTH * defaultIndents / spaceWidth);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
private void assertComponent() {
|
||||
|
@ -29,6 +29,7 @@
|
||||
"accessor.AgeableListModelAccessor",
|
||||
"accessor.GameRendererAccessor",
|
||||
"accessor.HumanoidArmorLayerAccessor",
|
||||
"accessor.MouseHandlerAccessor",
|
||||
"accessor.ParticleEngineAccessor",
|
||||
"client.BlockDestructionProgressMixin",
|
||||
"client.CameraMixin",
|
||||
|
Loading…
Reference in New Issue
Block a user