mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-28 16:06:48 +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
14 changed files with 105 additions and 61 deletions
|
@ -207,6 +207,7 @@ dependencies {
|
||||||
// runtimeOnly fg.deobf("maven.modrinth:spark:1.10.38-forge")
|
// runtimeOnly fg.deobf("maven.modrinth:spark:1.10.38-forge")
|
||||||
//runtimeOnly fg.deobf("curse.maven:forbidden-arcanus-309858:4729924")
|
//runtimeOnly fg.deobf("curse.maven:forbidden-arcanus-309858:4729924")
|
||||||
//runtimeOnly fg.deobf("curse.maven:valhelsia-core-416935:3886212")
|
//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-storage-619320:5194748")
|
||||||
// runtimeOnly fg.deobf("curse.maven:sophisticated-core-618298:5296312")
|
// runtimeOnly fg.deobf("curse.maven:sophisticated-core-618298:5296312")
|
||||||
// runtimeOnly fg.deobf("curse.maven:functional-storage-556861:5271589")
|
// runtimeOnly fg.deobf("curse.maven:functional-storage-556861:5271589")
|
||||||
|
|
|
@ -25,7 +25,8 @@ public enum Mods {
|
||||||
SOPHISTICATEDSTORAGE,
|
SOPHISTICATEDSTORAGE,
|
||||||
STORAGEDRAWERS,
|
STORAGEDRAWERS,
|
||||||
TCONSTRUCT,
|
TCONSTRUCT,
|
||||||
XLPACKETS;
|
XLPACKETS,
|
||||||
|
MODERNUI;
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
|
|
|
@ -22,15 +22,13 @@ public interface IDisplayAssemblyExceptions {
|
||||||
if (!tooltip.isEmpty())
|
if (!tooltip.isEmpty())
|
||||||
tooltip.add(Components.immutableEmpty());
|
tooltip.add(Components.immutableEmpty());
|
||||||
|
|
||||||
tooltip.add(IHaveGoggleInformation.componentSpacing.plainCopy()
|
Lang.translate("gui.assembly.exception").style(ChatFormatting.GOLD)
|
||||||
.append(Lang.translateDirect("gui.assembly.exception")
|
.forGoggles(tooltip);
|
||||||
.withStyle(ChatFormatting.GOLD)));
|
|
||||||
|
|
||||||
String text = e.component.getString();
|
String text = e.component.getString();
|
||||||
Arrays.stream(text.split("\n"))
|
Arrays.stream(text.split("\n"))
|
||||||
.forEach(l -> TooltipHelper.cutStringTextComponent(l, Palette.GRAY_AND_WHITE)
|
.forEach(l -> TooltipHelper.cutStringTextComponent(l, Palette.GRAY_AND_WHITE)
|
||||||
.forEach(c -> tooltip.add(IHaveGoggleInformation.componentSpacing.plainCopy()
|
.forEach(c -> Lang.text(c.getString()).forGoggles(tooltip)));
|
||||||
.append(c))));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,14 +27,14 @@ public class ElevatorContactEditPacket extends BlockEntityConfigurationPacket<El
|
||||||
@Override
|
@Override
|
||||||
protected void writeSettings(FriendlyByteBuf buffer) {
|
protected void writeSettings(FriendlyByteBuf buffer) {
|
||||||
buffer.writeUtf(shortName, 4);
|
buffer.writeUtf(shortName, 4);
|
||||||
buffer.writeUtf(longName, 30);
|
buffer.writeUtf(longName, 90);
|
||||||
buffer.writeVarInt(doorControl.ordinal());
|
buffer.writeVarInt(doorControl.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void readSettings(FriendlyByteBuf buffer) {
|
protected void readSettings(FriendlyByteBuf buffer) {
|
||||||
shortName = buffer.readUtf(4);
|
shortName = buffer.readUtf(4);
|
||||||
longName = buffer.readUtf(30);
|
longName = buffer.readUtf(90);
|
||||||
doorControl = DoorControl.values()[Mth.clamp(buffer.readVarInt(), 0, DoorControl.values().length)];
|
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")
|
String[] pitches = Lang.translateDirect("generic.notes")
|
||||||
.getString()
|
.getString()
|
||||||
.split(";");
|
.split(";");
|
||||||
MutableComponent textComponent = Components.literal(spacing);
|
Lang.translate("generic.pitch", pitches[pitch % pitches.length]).forGoggles(tooltip);
|
||||||
tooltip.add(textComponent.append(Lang.translateDirect("generic.pitch", pitches[pitch % pitches.length])));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,12 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.Window;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.simibubi.create.AllBlocks;
|
import com.simibubi.create.AllBlocks;
|
||||||
import com.simibubi.create.AllItems;
|
import com.simibubi.create.AllItems;
|
||||||
import com.simibubi.create.CreateClient;
|
import com.simibubi.create.CreateClient;
|
||||||
|
import com.simibubi.create.compat.Mods;
|
||||||
import com.simibubi.create.content.contraptions.IDisplayAssemblyExceptions;
|
import com.simibubi.create.content.contraptions.IDisplayAssemblyExceptions;
|
||||||
import com.simibubi.create.content.contraptions.piston.MechanicalPistonBlock;
|
import com.simibubi.create.content.contraptions.piston.MechanicalPistonBlock;
|
||||||
import com.simibubi.create.content.contraptions.piston.PistonExtensionPoleBlock;
|
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.RemovedGuiUtils;
|
||||||
import com.simibubi.create.foundation.gui.Theme;
|
import com.simibubi.create.foundation.gui.Theme;
|
||||||
import com.simibubi.create.foundation.gui.element.GuiGameElement;
|
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.Outline;
|
||||||
import com.simibubi.create.foundation.outliner.Outliner.OutlineEntry;
|
import com.simibubi.create.foundation.outliner.Outliner.OutlineEntry;
|
||||||
import com.simibubi.create.foundation.utility.Color;
|
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 com.simibubi.create.infrastructure.config.CClient;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.MouseHandler;
|
||||||
import net.minecraft.client.multiplayer.ClientLevel;
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
@ -154,9 +158,8 @@ public class GoggleOverlayRenderer {
|
||||||
if (!tooltip.isEmpty())
|
if (!tooltip.isEmpty())
|
||||||
tooltip.add(Components.immutableEmpty());
|
tooltip.add(Components.immutableEmpty());
|
||||||
|
|
||||||
tooltip.add(IHaveGoggleInformation.componentSpacing.plainCopy()
|
Lang.translate("gui.goggles.pole_length").text(" " + poles)
|
||||||
.append(Lang.translateDirect("gui.goggles.pole_length"))
|
.forGoggles(tooltip);
|
||||||
.append(Components.literal(" " + poles)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tooltip.isEmpty()) {
|
if (tooltip.isEmpty()) {
|
||||||
|
@ -205,14 +208,44 @@ public class GoggleOverlayRenderer {
|
||||||
colorBorderBot.scaleAlpha(fade);
|
colorBorderBot.scaleAlpha(fade);
|
||||||
}
|
}
|
||||||
|
|
||||||
RemovedGuiUtils.drawHoveringText(poseStack, tooltip, posX, posY, width, height, -1, colorBackground.getRGB(),
|
|
||||||
colorBorderTop.getRGB(), colorBorderBot.getRGB(), mc.font);
|
|
||||||
|
|
||||||
|
|
||||||
GuiGameElement.of(item)
|
GuiGameElement.of(item)
|
||||||
.at(posX + 10, posY - 16, 450)
|
.at(posX + 10, posY - 16, 450)
|
||||||
.render(poseStack);
|
.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();
|
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) {
|
public static BlockPos proxiedOverlayPosition(Level level, BlockPos pos) {
|
||||||
|
|
|
@ -147,20 +147,13 @@ public class BoilerData {
|
||||||
if (!isActive())
|
if (!isActive())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Component indent = Components.literal(IHaveGoggleInformation.spacing);
|
|
||||||
Component indent2 = Components.literal(IHaveGoggleInformation.spacing + " ");
|
|
||||||
|
|
||||||
calcMinMaxForSize(boilerSize);
|
calcMinMaxForSize(boilerSize);
|
||||||
|
|
||||||
tooltip.add(indent.plainCopy()
|
Lang.translate("boiler.status", getHeatLevelTextComponent().withStyle(ChatFormatting.GREEN))
|
||||||
.append(
|
.forGoggles(tooltip);
|
||||||
Lang.translateDirect("boiler.status", getHeatLevelTextComponent().withStyle(ChatFormatting.GREEN))));
|
Lang.text(getSizeComponent(true, false).getString()).forGoggles(tooltip, 1);
|
||||||
tooltip.add(indent2.plainCopy()
|
Lang.text(getWaterComponent(true, false).getString()).forGoggles(tooltip, 1);
|
||||||
.append(getSizeComponent(true, false)));
|
Lang.text(getHeatComponent(true, false).getString()).forGoggles(tooltip, 1);
|
||||||
tooltip.add(indent2.plainCopy()
|
|
||||||
.append(getWaterComponent(true, false)));
|
|
||||||
tooltip.add(indent2.plainCopy()
|
|
||||||
.append(getHeatComponent(true, false)));
|
|
||||||
|
|
||||||
if (attachedEngines == 0)
|
if (attachedEngines == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -48,7 +48,7 @@ public abstract class GaugeBlockEntity extends KineticBlockEntity implements IHa
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -784,20 +784,13 @@ public class BrassTunnelBlockEntity extends BeltTunnelBlockEntity implements IHa
|
||||||
if (allStacks.isEmpty())
|
if (allStacks.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
tooltip.add(componentSpacing.plainCopy()
|
Lang.translate("tooltip.brass_tunnel.contains").style(ChatFormatting.WHITE).forGoggles(tooltip);
|
||||||
.append(Lang.translateDirect("tooltip.brass_tunnel.contains"))
|
|
||||||
.withStyle(ChatFormatting.WHITE));
|
|
||||||
for (ItemStack item : allStacks) {
|
for (ItemStack item : allStacks) {
|
||||||
tooltip.add(componentSpacing.plainCopy()
|
Lang.translate("tooltip.brass_tunnel.contains_entry",
|
||||||
.append(Lang.translateDirect("tooltip.brass_tunnel.contains_entry",
|
Components.translatable(item.getDescriptionId()).getString(), item.getCount())
|
||||||
Components.translatable(item.getDescriptionId())
|
.style(ChatFormatting.GRAY).forGoggles(tooltip);
|
||||||
.getString(),
|
|
||||||
item.getCount()))
|
|
||||||
.withStyle(ChatFormatting.GRAY));
|
|
||||||
}
|
}
|
||||||
tooltip.add(componentSpacing.plainCopy()
|
Lang.translate("tooltip.brass_tunnel.retrieve").style(ChatFormatting.DARK_GRAY).forGoggles(tooltip);
|
||||||
.append(Lang.translateDirect("tooltip.brass_tunnel.retrieve"))
|
|
||||||
.withStyle(ChatFormatting.DARK_GRAY));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ public class AnalogLeverBlockEntity extends SmartBlockEntity implements IHaveGog
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
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.Components;
|
||||||
import com.simibubi.create.foundation.utility.Couple;
|
import com.simibubi.create.foundation.utility.Couple;
|
||||||
import com.simibubi.create.foundation.utility.Lang;
|
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) {
|
public static void addHint(List<Component> tooltip, String hintKey, Object... messageParams) {
|
||||||
Component spacing = IHaveGoggleInformation.componentSpacing;
|
Lang.translate(hintKey + ".title").style(ChatFormatting.GOLD).forGoggles(tooltip);
|
||||||
tooltip.add(spacing.plainCopy()
|
|
||||||
.append(Lang.translateDirect(hintKey + ".title"))
|
|
||||||
.withStyle(ChatFormatting.GOLD));
|
|
||||||
Component hint = Lang.translateDirect(hintKey);
|
Component hint = Lang.translateDirect(hintKey);
|
||||||
List<Component> cutComponent = cutTextComponent(hint, Palette.GRAY_AND_WHITE);
|
List<Component> cutComponent = cutTextComponent(hint, Palette.GRAY_AND_WHITE);
|
||||||
for (Component component : cutComponent)
|
for (Component component : cutComponent)
|
||||||
tooltip.add(spacing.plainCopy()
|
Lang.text(component.getString()).forGoggles(tooltip);
|
||||||
.append(component));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String makeProgressBar(int length, int filledLength) {
|
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 java.util.List;
|
||||||
|
|
||||||
|
import com.simibubi.create.compat.Mods;
|
||||||
|
|
||||||
import joptsimple.internal.Strings;
|
import joptsimple.internal.Strings;
|
||||||
import net.minecraft.ChatFormatting;
|
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.Component;
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
public class LangBuilder {
|
public class LangBuilder {
|
||||||
|
@ -150,11 +155,20 @@ public class LangBuilder {
|
||||||
|
|
||||||
public void forGoggles(List<? super MutableComponent> tooltip, int indents) {
|
public void forGoggles(List<? super MutableComponent> tooltip, int indents) {
|
||||||
tooltip.add(Lang.builder()
|
tooltip.add(Lang.builder()
|
||||||
.text(Strings.repeat(' ', 4 + indents))
|
.text(Strings.repeat(' ', getIndents(Minecraft.getInstance().font, 4 + indents)))
|
||||||
.add(this)
|
.add(this)
|
||||||
.component());
|
.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() {
|
private void assertComponent() {
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
"accessor.AgeableListModelAccessor",
|
"accessor.AgeableListModelAccessor",
|
||||||
"accessor.GameRendererAccessor",
|
"accessor.GameRendererAccessor",
|
||||||
"accessor.HumanoidArmorLayerAccessor",
|
"accessor.HumanoidArmorLayerAccessor",
|
||||||
|
"accessor.MouseHandlerAccessor",
|
||||||
"accessor.ParticleEngineAccessor",
|
"accessor.ParticleEngineAccessor",
|
||||||
"client.BlockDestructionProgressMixin",
|
"client.BlockDestructionProgressMixin",
|
||||||
"client.CameraMixin",
|
"client.CameraMixin",
|
||||||
|
|
Loading…
Reference in a new issue