Compare commits

..
10 Commits
Author SHA1 Message Date
SuperSoupr 93485e1525 Clarify IWailaVariableWidthTooltipRenderer.getSize's documentation (#53) 2025-11-14 06:29:41 +01:00
ceb94e3e2c fix loader check (#45)
Co-authored-by: Martin Robertz <[email protected]>
Co-authored-by: SuperSoupr <[email protected]>
2025-11-11 18:29:45 +00:00
SuperSouprandsisyphussy 8ea26bf073 Add gradient to fluid bar to improve visibility (#49)
Co-authored-by: sisyphussy <[email protected]>
2025-11-11 18:50:58 +01:00
Worive 2aabfdb64c Rename hasAdvancedBody to hasWailaAdvancedBody (#48) 2025-10-25 14:04:28 +02:00
Martin Robertz a34460c159 update 2025-10-24 22:59:20 +02:00
SuperSouprandSuper 1f3fd64a38 Use special comma for renderer formatting (#47)
Co-authored-by: Super <[email protected]>
2025-10-24 13:29:56 +02:00
Martin Robertz 191a916896 update 2025-10-22 21:39:31 +02:00
SuperSouprandSuper ee1ed27a3a Add fancy fluid tooltip renderer (#43)
Co-authored-by: Super <[email protected]>
2025-10-22 21:33:06 +02:00
SuperSoupr 07b9d1bf92 Add documentation for IWailaVariableWidthTooltipRenderer (#44) 2025-10-20 21:47:51 +00:00
SuperSouprandSuper e82729a113 Add variable width tooltip renderer support (#42)
Co-authored-by: Super <[email protected]>
2025-10-20 21:55:03 +02:00
12 changed files with 161 additions and 85 deletions

No files matched your search

+2 -2
View File
@@ -1,9 +1,9 @@
// Add your dependencies here
dependencies {
implementation('com.github.GTNewHorizons:NotEnoughItems:2.8.16-GTNH:dev')
implementation('com.github.GTNewHorizons:NotEnoughItems:2.8.20-GTNH:dev')
shadowImplementation('au.com.bytecode:opencsv:2.4')
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.52.57:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.52.69:dev") { transitive = false }
}
+3 -1
View File
@@ -96,7 +96,9 @@ usesMixinDebug = false
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
mixinPlugin =
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
# Specify the package that contains all of your Mixins. The package must exist or
# the build will fail. If you have a package property defined in your mixins.<modid>.json,
# it must match with this or the build will fail.
mixinsPackage =
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
+1 -1
View File
@@ -17,7 +17,7 @@ pluginManagement {
}
plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.44'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.46'
}
@@ -72,7 +72,7 @@ public interface IWailaDataProvider {
* @param config Current configuration of Waila.
* @return True if advanced body information is available, false otherwise.
*/
default boolean hasAdvancedBody(ItemStack itemStack, IWailaDataAccessor accessor, IWailaConfigHandler config) {
default boolean hasWailaAdvancedBody(ItemStack itemStack, IWailaDataAccessor accessor, IWailaConfigHandler config) {
return false; // Default to false for backward compatibility
}
@@ -1,9 +1,42 @@
package mcp.mobius.waila.api;
import java.awt.Dimension;
/**
* Interface for tooltip renderers that adjust their width depending on the width of the rest of the tooltip.
* setMaxLineWidth is called by {@link mcp.mobius.waila.overlay.Tooltip} before every tooltip render to inform the
* renderer of the width of the longest line in the tooltip.
*/
public interface IWailaVariableWidthTooltipRenderer extends IWailaTooltipRenderer {
void setMaxStringW(int width);
/**
* Return the size of the tooltip. for variable width renderers it is recommended to return the minimum width needed
* for the line, then draw the actual width using getMaxLineWidth(). They do not need to actually match.
*
* @param params Array of string parameters as passed to the RENDER arg in the tooltip
* ({rendername,param1,param2,...})
* @param accessor A global accessor for TileEntities and Entities
* @return Dimension of the reserved area
*/
Dimension getSize(String[] params, IWailaCommonAccessor accessor);
int getMaxStringW();
/**
* Informs the renderer of what the length of the longest line is.</br>
* Called by {@link mcp.mobius.waila.overlay.Tooltip} before every tooltip render.</br>
*
* @param width The width of the longest line in the tooltip.
*
*/
void setMaxLineWidth(int width);
/**
* Returns the width of the longest line in the current tooltip.</br>
* With icons disabled the tooltip's background box is always 2 pixels wider to the right of the line than it is to
* the left.</br>
*
* @return The width of the longest line in the tooltip
*
*/
int getMaxLineWidth();
}
@@ -33,8 +33,6 @@ public class SpecialChars {
public static String WailaStyle = "\u00A4";
public static String WailaIcon = "\u00A5";
public static String WailaRenderer = "\u00A6";
public static String WailaRendererBracketLeft = "\u0080";
public static String WailaRendererBracketRight = "\u0081";
public static String WailaRendererComma = "\u0082";
public static String TAB = WailaStyle + WailaStyle + "a";
public static String ALIGNRIGHT = WailaStyle + WailaStyle + "b";
@@ -46,26 +44,19 @@ public class SpecialChars {
public static final Pattern patternMinecraft = Pattern.compile("(?i)" + MCStyle + "[0-9A-FK-OR]");
public static final Pattern patternWaila = Pattern.compile("(?i)(" + WailaStyle + "(?<type>..))");
// (?i)(¤¦a\U+0080(?<name>[^U+0082U+0081]*)U+0082?(?<args>[^U+0081]*)\U+0081)
// (?i)(¤¦a\{(?<name>[^U+0082}]*)U+0082?(?<args>[^}]*)\})
public static final Pattern patternRender = Pattern.compile(
"(?i)(" + RENDER
+ "\\"
+ WailaRendererBracketLeft
+ "(?<name>[^"
+ "\\{(?<name>[^"
+ WailaRendererComma
+ WailaRendererBracketRight
+ "]*)"
+ "}]*)"
+ WailaRendererComma
+ "?(?<args>[^"
+ WailaRendererBracketRight
+ "]*)\\"
+ WailaRendererBracketRight
+ ")");
+ "?(?<args>[^}]*)\\})");
public static final Pattern patternTab = Pattern.compile("(?i)" + TAB);
public static final Pattern patternRight = Pattern.compile("(?i)" + ALIGNRIGHT);
public static final Pattern patternCenter = Pattern.compile("(?i)" + ALIGNCENTER);
public static final Pattern patternIcon = Pattern.compile("(?i)(" + WailaStyle + WailaIcon + "(?<type>[0-9a-z]))");
// (?i)(¤¤[^¤]+|¤¥[0-9A-Z]|¤¦a\U+0080(?<name>[^U+0082U+0081]*)U+0082?(?<args>[^U+0081]*)\U+0081|[^¤]+)
// (?i)(¤¤[^¤]+|¤¥[0-9A-Z]|¤¦a\{(?<name>[^U+0082}]*)U+0082?(?<args>[^}]*)\}|[^¤]+)
public static final Pattern patternLineSplit = Pattern.compile(
"(?i)(" + WailaStyle
+ WailaStyle
@@ -77,18 +68,11 @@ public class SpecialChars {
+ "[0-9A-Z]|"
+ WailaStyle
+ WailaRenderer
+ "a\\"
+ WailaRendererBracketLeft
+ "(?<name>[^"
+ "a\\{(?<name>[^"
+ WailaRendererComma
+ WailaRendererBracketRight
+ "]*)"
+ "}]*)"
+ WailaRendererComma
+ "?(?<args>[^"
+ WailaRendererBracketRight
+ "]*)\\"
+ WailaRendererBracketRight
+ "|[^"
+ "?(?<args>[^}]*)\\}|[^"
+ WailaStyle
+ "]+)");
@@ -97,11 +81,11 @@ public class SpecialChars {
* give back a directly usable String for the tooltip.
*/
public static String getRenderString(String name, String... params) {
StringBuilder result = new StringBuilder(RENDER + WailaRendererBracketLeft + name);
StringBuilder result = new StringBuilder(RENDER + "{" + name);
for (String s : params) {
result.append(WailaRendererComma).append(s);
}
result.append(WailaRendererBracketRight);
result.append("}");
return result.toString();
}
}
@@ -34,6 +34,8 @@ public class ConfigHandler implements IWailaConfigHandler {
public HashMap<String, Boolean> forcedConfigs = new HashMap<>();
public Configuration config = null;
public String fluidUnit;
public void addModule(String modName, HashMap<String, String> options) {
this.addModule(modName, new ConfigModule(modName, options));
}
@@ -150,6 +152,7 @@ public class ConfigHandler implements IWailaConfigHandler {
config.get(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_KEYBIND, true);
config.get(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_NEWFILTERS, true);
config.get(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_SHOWICON, true);
fluidUnit = config.get(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_FLUIDUNIT, "mB").getString();
OverlayConfig.posX = config.get(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_POSX, 5000).getInt();
OverlayConfig.posY = config.get(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_POSY, 100).getInt();
@@ -155,7 +155,7 @@ public class MetaDataProvider {
for (IWailaDataProvider dataProvider : providersList) try {
currenttip = dataProvider.getWailaBody(itemStack, currenttip, accessor, ConfigHandler.instance());
if (dataProvider.hasAdvancedBody(itemStack, accessor, ConfigHandler.instance())) {
if (dataProvider.hasWailaAdvancedBody(itemStack, accessor, ConfigHandler.instance())) {
hasAdvancedBodyAvailable = true;
if (isAdvancedKeyDown) {
@@ -42,7 +42,6 @@ public class Tooltip {
ArrayList<Renderable> elements = new ArrayList<>();
ArrayList<Renderable> elements2nd = new ArrayList<>();
ArrayList<Renderable> elements3rd = new ArrayList<>();
int w, h, x, y, ty;
int offsetX;
@@ -184,10 +183,10 @@ public class Tooltip {
renderer,
new Point(offsetX, offsetY),
renderMatcher.group("args").split(SpecialChars.WailaRendererComma));
if (renderer instanceof IWailaVariableWidthTooltipRenderer) {
((IWailaVariableWidthTooltipRenderer) renderable.renderer).setMaxStringW(maxStringW);
this.elements3rd.add(renderable);
} else this.elements2nd.add(renderable);
if (renderer instanceof IWailaVariableWidthTooltipRenderer variableWidthRenderer) {
variableWidthRenderer.setMaxLineWidth(maxStringW);
}
this.elements2nd.add(renderable);
}
} else if (iconMatcher.find()) {
renderable = new Renderable(
@@ -250,6 +249,5 @@ public class Tooltip {
public void draw2nd() {
for (Renderable r : this.elements2nd) r.draw(accessor, x + offsetX, y + ty);
for (Renderable r : this.elements3rd) r.draw(accessor, x + offsetX, y + ty);
}
}
@@ -1,11 +1,15 @@
package mcp.mobius.waila.overlay.tooltiprenderers;
import java.awt.Dimension;
import java.util.function.Consumer;
import java.util.function.Function;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
@@ -13,77 +17,128 @@ import org.lwjgl.opengl.GL11;
import cpw.mods.fml.common.Loader;
import gregtech.api.util.GTUtil;
import gregtech.api.util.GTUtility;
import gregtech.common.fluid.GTFluid;
import gtPlusPlus.api.objects.minecraft.FluidGT6;
import gtPlusPlus.core.util.minecraft.FluidUtils;
import mcp.mobius.waila.api.IWailaCommonAccessor;
import mcp.mobius.waila.api.IWailaVariableWidthTooltipRenderer;
import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.overlay.DisplayUtil;
import mcp.mobius.waila.overlay.OverlayConfig;
public class TTRenderFluidBar implements IWailaVariableWidthTooltipRenderer {
int maxStringW;
private final Consumer<String> bindColor;
private final Function<Integer, String> formatNumber;
private static final int height = 12;
public TTRenderFluidBar() {
if (Loader.isModLoaded("gregtech_nh")) {
bindColor = (fluidName) -> {
FluidStack aCheck = FluidUtils.getWildcardFluidStack(fluidName, 1000);
if (aCheck != null && (aCheck.getFluid() instanceof FluidGT6 || aCheck.getFluid() instanceof GTFluid)) {
short[] RGBa = GTUtil.getRGBaArray(aCheck.getFluid().getColor());
GL11.glColor4f(RGBa[0] / 255F, RGBa[1] / 255F, RGBa[2] / 255F, 1F);
} else {
GL11.glColor4f(1F, 1F, 1F, 1F);
}
};
formatNumber = GTUtility::formatNumbers;
} else {
bindColor = (fluidName) -> GL11.glColor4f(1F, 1F, 1F, 1F);
formatNumber = (number) -> String.format("%,d", number);
}
}
@Override
public Dimension getSize(String[] params, IWailaCommonAccessor accessor) {
return new Dimension(DisplayUtil.getDisplayWidth(params[1] + 2), 12);
int commaCount = (int) (Math.floor((params[2].length() - 1) / 3D) + Math.floor((params[3].length() - 1) / 3D));
// ",".repeat(commaCount) doesn't exist in java 8 so do this instead.
StringBuilder sb = new StringBuilder(commaCount);
for (int i = 0; i < commaCount; i++) {
sb.append(",");
}
return new Dimension(
DisplayUtil.getDisplayWidth(
params[2] + " / " + params[3] + ConfigHandler.instance().fluidUnit + params[1] + sb) + 4,
height);
}
public static final ResourceLocation gradient = new ResourceLocation("waila", "textures/gradient.png");
@Override
public void draw(String[] params, IWailaCommonAccessor accessor) {
drawThickBeveledBox(0, 0, maxStringW, 12, 1, 0xFF505050, 0xFF505050, -1);
String fluidName = params[0];
String localizedName = params[1];
double amount = Double.parseDouble(params[2]);
double capacity = Double.parseDouble(params[3]);
Tessellator tessellator = Tessellator.instance;
IIcon icon = FluidRegistry.getFluid(params[0]).getIcon();
IIcon icon = FluidRegistry.getFluid(fluidName).getIcon();
Minecraft mc = Minecraft.getMinecraft();
mc.getTextureManager().bindTexture(net.minecraft.client.renderer.texture.TextureMap.locationBlocksTexture);
mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
if (Loader.isModLoaded("gregtech")) {
FluidStack aCheck = FluidUtils.getWildcardFluidStack(params[0], 1000);
if (aCheck != null && (aCheck.getFluid() instanceof FluidGT6 || aCheck.getFluid() instanceof GTFluid)) {
short[] RGBa = GTUtil.getRGBaArray(aCheck.getFluid().getColor());
GL11.glColor4f(RGBa[0] / 255F, RGBa[1] / 255F, RGBa[2] / 255F, 1F);
} else {
GL11.glColor4f(1F, 1F, 1F, 1F);
}
} else {
GL11.glColor4f(1F, 1F, 1F, 1F);
}
bindColor.accept(fluidName);
int i = (int) ((maxStringW - 2) * Double.parseDouble(params[2]));
tessellator.startDrawingQuads();
// Intentionally draw 2 pixels taller than needed than cover with the border to make the texture more visible
int i = (int) ((double) (maxStringW - 2) * amount / capacity);
int j = 0;
for (; i > 10; i = i - 10) {
drawTexturedModelRectFromIcon(1 + (j * 10), 1, icon, 10, 10, 100);
for (; i > height; i = i - height) {
drawRectFromIcon(tessellator, 1 + (j * height), 0, 0, icon, height, height);
j++;
}
if (i > 0) drawTexturedModelRectFromIcon(
1 + (j * 10),
1,
icon,
if (i > 0) drawRect(
tessellator,
1 + (j * height),
0,
0,
i,
10,
100,
icon.getMinU() + ((icon.getMaxU() - icon.getMinU()) * ((double) i / 10D)),
height,
icon.getMinU(),
icon.getMinV(),
icon.getMinU() + ((icon.getMaxU() - icon.getMinU()) * ((double) i / height)),
icon.getMaxV());
DisplayUtil.drawString(params[1], 2, 2, OverlayConfig.fontcolor, true);
}
public static void drawTexturedModelRectFromIcon(int x, int y, IIcon icon, int width, int height, double z) {
drawTexturedModelRectFromIcon(x, y, icon, width, height, z, icon.getMaxU(), icon.getMaxV());
}
public static void drawTexturedModelRectFromIcon(int x, int y, IIcon icon, int width, int height, double z,
double maxU, double maxV) {
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(x, y + height, z, icon.getMinU(), maxV);
tessellator.addVertexWithUV(x + width, y + height, z, maxU, maxV);
tessellator.addVertexWithUV(x + width, y, z, maxU, icon.getMinV());
tessellator.addVertexWithUV(x, y, z, icon.getMinU(), icon.getMinV());
tessellator.draw();
GL11.glEnable(GL11.GL_BLEND);
GL11.glColor4f(1F, 1F, 1F, 0.70F);
mc.getTextureManager().bindTexture(gradient);
tessellator.startDrawingQuads();
drawRect(tessellator, 1, 0, 0, maxStringW - 2, height - 1, 0, 0, 1, 1);
tessellator.draw();
drawThickBeveledBox(0, 0, maxStringW, height, 1, 0xFF505050, 0xFF505050, -1);
DisplayUtil.drawString(
formatNumber.apply((int) amount) + " / "
+ formatNumber.apply((int) capacity)
+ " "
+ ConfigHandler.instance().fluidUnit
+ " "
+ localizedName,
2,
2,
0xFFFFFFFF,
true);
}
public static void drawRectFromIcon(Tessellator tessellator, int x, int y, double z, IIcon icon, int width,
int height) {
drawRect(tessellator, x, y, z, width, height, icon.getMinU(), icon.getMinV(), icon.getMaxU(), icon.getMaxV());
}
public static void drawRect(Tessellator tessellator, int x, int y, double z, int width, int height, double minU,
double minV, double maxU, double maxV) {
tessellator.addVertexWithUV(x, y + height, z, minU, maxV);
tessellator.addVertexWithUV(x + width, y + height, z, maxU, maxV);
tessellator.addVertexWithUV(x + width, y, z, maxU, minV);
tessellator.addVertexWithUV(x, y, z, minU, minV);
}
public static void drawThickBeveledBox(int x1, int y1, int x2, int y2, int thickness, int topleftcolor,
@@ -98,12 +153,12 @@ public class TTRenderFluidBar implements IWailaVariableWidthTooltipRenderer {
}
@Override
public void setMaxStringW(int width) {
public void setMaxLineWidth(int width) {
maxStringW = width + 2;
}
@Override
public int getMaxStringW() {
public int getMaxLineWidth() {
return maxStringW;
}
}
@@ -29,6 +29,7 @@ public final class Constants {
public static String CFG_WAILA_NHEARTS = "waila.cfg.heartsperline";
public static String CFG_WAILA_MAXHP = "waila.cfg.maxhpbeforetext";
public static String CFG_WAILA_NEWFILTERS = "waila.cfg.newfilters";
public static String CFG_WAILA_FLUIDUNIT = "waila.cfg.fluid_unit";
public static String CFG_WAILA_ALPHA = "waila.cfg.alpha";
public static String CFG_WAILA_BGCOLOR = "waila.cfg.bgcolor";
Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B