aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorLulonaut <67191924+Lulonaut@users.noreply.github.com>2022-07-12 19:14:32 +0200
committerGitHub <noreply@github.com>2022-07-12 19:14:32 +0200
commit36be173ff0505942fd9b54a39f64b703f1510d9e (patch)
tree5a50d973170f262299a9d847c99bffc4492e784b /src/main
parentecbb0f68bbbd0dcea6c1a75855010d633625cc62 (diff)
downloadNotEnoughUpdates-36be173ff0505942fd9b54a39f64b703f1510d9e.tar.gz
NotEnoughUpdates-36be173ff0505942fd9b54a39f64b703f1510d9e.tar.bz2
NotEnoughUpdates-36be173ff0505942fd9b54a39f64b703f1510d9e.zip
calculate tooltip offset (#181)
* calculate offset * consistency
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java73
1 files changed, 66 insertions, 7 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
index 440106bc..a3755984 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
@@ -2414,30 +2414,61 @@ public class NEUOverlay extends Gui {
}
}
}
- //top slot
- int tooltipXModifier = -175;
+
if (mouseY >= ((height + 60) / 2f - 105) && mouseY <= ((height + 60) / 2f - 105) + 16) {
tooltipToDisplay = slot1.getTooltip(Minecraft.getMinecraft().thePlayer, false);
if (shouldShowEquipmentTooltip(tooltipToDisplay)) {
- Utils.drawHoveringText(tooltipToDisplay, mouseX + tooltipXModifier, mouseY, width, height, -1, fr);
+ Utils.drawHoveringText(
+ tooltipToDisplay,
+ mouseX - calculateTooltipXOffset(tooltipToDisplay, fr),
+ mouseY,
+ width,
+ height,
+ -1,
+ fr
+ );
}
}
if (mouseY >= ((height + 60) / 2f - 105) + 18 && mouseY <= ((height + 60) / 2f - 105) + 34) {
tooltipToDisplay = slot2.getTooltip(Minecraft.getMinecraft().thePlayer, false);
if (shouldShowEquipmentTooltip(tooltipToDisplay)) {
- Utils.drawHoveringText(tooltipToDisplay, mouseX + tooltipXModifier, mouseY, width, height, -1, fr);
+ Utils.drawHoveringText(
+ tooltipToDisplay,
+ mouseX - calculateTooltipXOffset(tooltipToDisplay, fr),
+ mouseY,
+ width,
+ height,
+ -1,
+ fr
+ );
}
}
if (mouseY >= ((height + 60) / 2f - 105) + 36 && mouseY <= ((height + 60) / 2f - 105) + 52) {
tooltipToDisplay = slot3.getTooltip(Minecraft.getMinecraft().thePlayer, false);
if (shouldShowEquipmentTooltip(tooltipToDisplay)) {
- Utils.drawHoveringText(tooltipToDisplay, mouseX + tooltipXModifier, mouseY, width, height, -1, fr);
+ Utils.drawHoveringText(
+ tooltipToDisplay,
+ mouseX - calculateTooltipXOffset(tooltipToDisplay, fr),
+ mouseY,
+ width,
+ height,
+ -1,
+ fr
+ );
}
}
if (mouseY >= ((height + 60) / 2f - 105) + 54 && mouseY <= ((height + 60) / 2f - 105) + 70) {
tooltipToDisplay = slot4.getTooltip(Minecraft.getMinecraft().thePlayer, false);
if (shouldShowEquipmentTooltip(tooltipToDisplay)) {
- Utils.drawHoveringText(tooltipToDisplay, mouseX + tooltipXModifier, mouseY, width, height, -1, fr);
+ Utils.drawHoveringText(
+ tooltipToDisplay,
+ mouseX - calculateTooltipXOffset(tooltipToDisplay, fr),
+ mouseY,
+ width,
+ height,
+ -1,
+ fr
+ );
}
}
}
@@ -2540,7 +2571,15 @@ public class NEUOverlay extends Gui {
}
}
tooltipToDisplay = petInfo.getTooltip(Minecraft.getMinecraft().thePlayer, false);
- Utils.drawHoveringText(tooltipToDisplay, mouseX - 200, mouseY, width, height, -1, fr);
+ Utils.drawHoveringText(
+ tooltipToDisplay,
+ mouseX - calculateTooltipXOffset(tooltipToDisplay, fr),
+ mouseY,
+ width,
+ height,
+ -1,
+ fr
+ );
GL11.glTranslatef(0, 0, -80);
}
}
@@ -2551,6 +2590,26 @@ public class NEUOverlay extends Gui {
}
}
+ /**
+ * Calculates the width of the longest String in the tooltip, which can be used to offset the entire tooltip to the left more precisely
+ *
+ * @param tooltipToDisplay tooltip
+ * @param fr FontRenderer object
+ * @return offset to apply
+ */
+ private int calculateTooltipXOffset(List<String> tooltipToDisplay, FontRenderer fr) {
+ int offset = 0;
+ if (tooltipToDisplay != null) {
+ for (String line : tooltipToDisplay) {
+ int lineWidth = fr.getStringWidth(line);
+ if (lineWidth > offset) {
+ offset = lineWidth;
+ }
+ }
+ }
+ return offset + 20;
+ }
+
private boolean shouldShowEquipmentTooltip(List<String> toolTip) {
return !toolTip.get(0).equals("§o§7Empty Equipment Slot§r");
}