aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorRoman / Linnea Gräf <roman.graef@gmail.com>2023-04-04 20:37:03 +0200
committerGitHub <noreply@github.com>2023-04-04 20:37:03 +0200
commit93cdc3e03c3654f560204c23017fbf1e9f720a6c (patch)
treec4a7a296cf0a9997acfc14f7b2ed56b68ccc65e6 /src/main/java
parent42a7f35c7e1ed7b771f93e69e6bbd2a674a4f569 (diff)
downloadNotEnoughUpdates-93cdc3e03c3654f560204c23017fbf1e9f720a6c.tar.gz
NotEnoughUpdates-93cdc3e03c3654f560204c23017fbf1e9f720a6c.tar.bz2
NotEnoughUpdates-93cdc3e03c3654f560204c23017fbf1e9f720a6c.zip
Scrollable Tooltips a la text line removal. (#613)
* scrolling * Reverse scrolling * change trophy fish pv page to use the same tooltip system as the rest of the pv pages * Added the ability to use neu's tooltips instead of vanilla * Move config option * Add support for the custom tooltips * Fixed equipment overlay breaking * Fixed some guis going no * Use a new arraylist instead of modifying the old one (achievments) * fix merge conflict --------- Co-authored-by: nopo <nopotheemail@gmail.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/TooltipTextScrolling.java80
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiUtils.java16
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java17
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishPage.java23
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java100
5 files changed, 169 insertions, 67 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/TooltipTextScrolling.java b/src/main/java/io/github/moulberry/notenoughupdates/TooltipTextScrolling.java
new file mode 100644
index 00000000..ccb28dd6
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/TooltipTextScrolling.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2023 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates;
+
+import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe;
+import net.minecraftforge.client.event.GuiScreenEvent;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.common.gameevent.TickEvent;
+import org.lwjgl.input.Mouse;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+@NEUAutoSubscribe
+public class TooltipTextScrolling {
+ static List<String> lastRenderedTooltip = null;
+ static int scrollOffset = 0;
+ static boolean didRenderTooltip = false;
+
+ public static List<String> handleTextLineRendering(List<String> tooltip) {
+ didRenderTooltip = true;
+ if (!Objects.equals(tooltip, lastRenderedTooltip)) {
+ lastRenderedTooltip = new ArrayList<>(tooltip);
+ scrollOffset = 0;
+ return tooltip;
+ }
+ lastRenderedTooltip = new ArrayList<>(tooltip);
+ List<String> modifiableTooltip = new ArrayList<>(tooltip);
+ for (int i = 0; i < scrollOffset && modifiableTooltip.size() > 1; i++) {
+ modifiableTooltip.remove(0);
+ }
+ for (int i = 0; i < -scrollOffset && modifiableTooltip.size() > 1; i++) {
+ modifiableTooltip.remove(modifiableTooltip.size() - 1);
+ }
+ return modifiableTooltip;
+ }
+
+ @SubscribeEvent
+ public void onMouse(GuiScreenEvent.MouseInputEvent.Pre event) {
+ if (!NotEnoughUpdates.INSTANCE.config.tooltipTweaks.scrollableTooltips) return;
+ if (Mouse.getEventDWheel() < 0) {
+ scrollOffset = Math.max(
+ lastRenderedTooltip == null ? 0 : -Math.max(lastRenderedTooltip.size() - 1, 0)
+ , scrollOffset - 1
+ );
+ } else if (Mouse.getEventDWheel() > 0) {
+ scrollOffset = Math.min(
+ lastRenderedTooltip == null ? 0 : Math.max(lastRenderedTooltip.size() - 1, 0),
+ scrollOffset + 1
+ );
+ }
+ }
+
+ @SubscribeEvent
+ public void onTick(TickEvent.RenderTickEvent event) {
+ if (event.phase == TickEvent.Phase.START) {
+ didRenderTooltip = false;
+ } else if (!didRenderTooltip) {
+ lastRenderedTooltip = null;
+ }
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiUtils.java
index 0ad2a098..a4e83a11 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiUtils.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiUtils.java
@@ -20,6 +20,7 @@
package io.github.moulberry.notenoughupdates.mixins;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.TooltipTextScrolling;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
@@ -35,10 +36,15 @@ import java.util.List;
@Mixin(value = GuiUtils.class, remap = false)
public class MixinGuiUtils {
- @Inject(method = "drawHoveringText", at = @At("HEAD"))
+ @Inject(method = "drawHoveringText", at = @At("HEAD"), cancellable = true)
private static void drawHoveringText_head(
List<String> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight, int maxTextWidth, FontRenderer font, CallbackInfo ci) {
- Utils.pushGuiScale(NotEnoughUpdates.INSTANCE.config.tooltipTweaks.guiScale);
+ if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.customTooltips) {
+ Utils.drawHoveringText(textLines, mouseX, mouseY, screenWidth, screenHeight, maxTextWidth, font);
+ ci.cancel();
+ } else if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.guiScale != 0) {
+ Utils.pushGuiScale(NotEnoughUpdates.INSTANCE.config.tooltipTweaks.guiScale);
+ }
}
@ModifyVariable(method = "drawHoveringText", at = @At(value = "HEAD"), ordinal = 0, argsOnly = true)
@@ -68,4 +74,10 @@ public class MixinGuiUtils {
List<String> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight, int maxTextWidth, FontRenderer font, CallbackInfo ci) {
Utils.resetGuiScale();
}
+ @ModifyVariable(at = @At("HEAD"), method = "drawHoveringText")
+ private static List<String> onDrawHoveringText(
+ List<String> textLines
+ ) {
+ return TooltipTextScrolling.handleTextLineRendering(textLines);
+ }
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java
index 900ecf13..ae4a5aff 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java
@@ -167,6 +167,23 @@ public class TooltipTweaks {
@Expose
@ConfigOption(
+ name = "Custom tooltips",
+ desc = "Replace tooltips with neu's custom tooltips"
+ )
+ @ConfigEditorBoolean
+ public boolean customTooltips = false;
+
+ @Expose
+ @ConfigOption(
+ name = "Scrollable Tooltips",
+ desc = "Make tooltips text scrollable, by making some text lines disappear when using the mouse while hovering over an item."
+ )
+ @ConfigEditorBoolean
+ public boolean scrollableTooltips = false;
+
+
+ @Expose
+ @ConfigOption(
name = "Expand Pet Exp Requirement",
desc = "Show which the full amount of pet xp required"
)
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishPage.java
index d6746e1d..f4378926 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishPage.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/trophy/TrophyFishPage.java
@@ -128,6 +128,7 @@ public class TrophyFishPage extends GuiProfileViewerPage {
private final Map<String, Integer> total = new HashMap<>();
private final Map<String, TrophyFish> trophyFishList = new HashMap<>();
private long totalCount = 0;
+ private static List<String> tooltipToDisplay = null;
public TrophyFishPage(GuiProfileViewer instance) {
super(instance);
@@ -226,10 +227,8 @@ public class TrophyFishPage extends GuiProfileViewerPage {
if (mouseX >= x && mouseX < x + 24) {
if (mouseY >= y && mouseY <= y + 24) {
- Utils.drawHoveringText(
- getTooltip(value.getName(), value.getTrophyFishRarityIntegerMap()),
- mouseX, mouseY, width, height, -1
- );
+ tooltipToDisplay = new ArrayList<>();
+ tooltipToDisplay.addAll(getTooltip(value.getName(), value.getTrophyFishRarityIntegerMap()));
}
}
}
@@ -246,7 +245,8 @@ public class TrophyFishPage extends GuiProfileViewerPage {
Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(itemStack, x, y);
if (mouseX >= x && mouseX < x + 24) {
if (mouseY >= y && mouseY <= y + 24) {
- Utils.drawHoveringText(getTooltip(difference, null), mouseX, mouseY, width, height, -1);
+ tooltipToDisplay = new ArrayList<>();
+ tooltipToDisplay.addAll(getTooltip(difference, null));
GlStateManager.color(1, 1, 1, 1);
}
}
@@ -286,6 +286,19 @@ public class TrophyFishPage extends GuiProfileViewerPage {
i += 10;
}
+ if (tooltipToDisplay != null) {
+ Utils.drawHoveringText(
+ tooltipToDisplay,
+ mouseX,
+ mouseY,
+ getInstance().width,
+ getInstance().height,
+ -1,
+ Minecraft.getMinecraft().fontRendererObj
+ );
+ tooltipToDisplay = null;
+ }
+
GlStateManager.enableLighting();
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
index 49caa2b6..e3d52fe7 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
@@ -27,6 +27,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.TooltipTextScrolling;
import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking;
import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer;
import net.minecraft.block.Block;
@@ -1521,20 +1522,6 @@ public class Utils {
Minecraft.getMinecraft().fontRendererObj
);
}
-
- @Deprecated
- public static void drawHoveringText(
- List<String> textLines,
- final int mouseX,
- final int mouseY,
- final int screenWidth,
- final int screenHeight,
- final int maxTextWidth,
- FontRenderer font
- ) {
- drawHoveringText(textLines, mouseX, mouseY, screenWidth, screenHeight, maxTextWidth, font, true);
- }
-
public static JsonObject getConstant(String constant, Gson gson) {
return getConstant(constant, gson, JsonObject.class);
}
@@ -1668,39 +1655,38 @@ public class Utils {
scrollY.resetTimer();
}
- public static void drawHoveringText(
- List<String> textLines,
- final int mouseX,
- final int mouseY,
- final int screenWidth,
- final int screenHeight,
- final int maxTextWidth,
- boolean coloured
- ) {
- drawHoveringText(
- textLines,
- mouseX,
- mouseY,
- screenWidth,
- screenHeight,
- maxTextWidth,
- Minecraft.getMinecraft().fontRendererObj,
- coloured
- );
- }
-
@Deprecated
public static void drawHoveringText(
List<String> textLines,
- final int mouseX,
- final int mouseY,
- final int screenWidth,
- final int screenHeight,
+ int mouseX,
+ int mouseY,
+ int screenWidth,
+ int screenHeight,
final int maxTextWidth,
- FontRenderer font,
- boolean coloured
+ FontRenderer font
) {
if (!textLines.isEmpty()) {
+ int borderColorStart = 0x505000FF;
+ if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.tooltipBorderColours) {
+ if (textLines.size() > 0) {
+ String first = textLines.get(0);
+ borderColorStart = getPrimaryColour(first).getRGB() & 0x00FFFFFF |
+ ((NotEnoughUpdates.INSTANCE.config.tooltipTweaks.tooltipBorderOpacity) << 24);
+ }
+ }
+ textLines = TooltipTextScrolling.handleTextLineRendering(textLines);
+ if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.guiScale != 0) {
+ ScaledResolution scaledResolution = Utils.pushGuiScale(NotEnoughUpdates.INSTANCE.config.tooltipTweaks.guiScale);
+ mouseX = Mouse.getX() * scaledResolution.getScaledWidth() / Minecraft.getMinecraft().displayWidth;
+
+ mouseY = scaledResolution.getScaledHeight() -
+ Mouse.getY() * scaledResolution.getScaledHeight() / Minecraft.getMinecraft().displayHeight;
+
+ screenWidth = scaledResolution.getScaledWidth();
+
+ screenHeight = scaledResolution.getScaledHeight();
+ }
+
GlStateManager.disableRescaleNormal();
RenderHelper.disableStandardItemLighting();
GlStateManager.disableLighting();
@@ -1776,19 +1762,21 @@ public class Utils {
}
//Scrollable tooltips
- if (tooltipHeight + 6 > screenHeight) {
- if (scrollY.getTarget() < 0) {
- scrollY.setTarget(0);
- scrollY.resetTimer();
- } else if (screenHeight - tooltipHeight - 12 + (int) scrollY.getTarget() > 0) {
- scrollY.setTarget(-screenHeight + tooltipHeight + 12);
+ if (!NotEnoughUpdates.INSTANCE.config.tooltipTweaks.scrollableTooltips) {
+ if (tooltipHeight + 6 > screenHeight) {
+ if (scrollY.getTarget() < 0) {
+ scrollY.setTarget(0);
+ scrollY.resetTimer();
+ } else if (screenHeight - tooltipHeight - 12 + (int) scrollY.getTarget() > 0) {
+ scrollY.setTarget(-screenHeight + tooltipHeight + 12);
+ scrollY.resetTimer();
+ }
+ } else {
+ scrollY.setValue(0);
scrollY.resetTimer();
}
- } else {
- scrollY.setValue(0);
- scrollY.resetTimer();
+ scrollY.tick();
}
- scrollY.tick();
if (tooltipY + tooltipHeight + 6 > screenHeight) {
tooltipY = screenHeight - tooltipHeight - 6 + (int) scrollY.getValue();
@@ -1841,15 +1829,6 @@ public class Utils {
backgroundColor,
backgroundColor
);
- //TODO: Coloured Borders
- int borderColorStart = 0x505000FF;
- if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.tooltipBorderColours && coloured) {
- if (textLines.size() > 0) {
- String first = textLines.get(0);
- borderColorStart = getPrimaryColour(first).getRGB() & 0x00FFFFFF |
- ((NotEnoughUpdates.INSTANCE.config.tooltipTweaks.tooltipBorderOpacity) << 24);
- }
- }
final int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000;
drawGradientRect(
zLevel,
@@ -1904,6 +1883,7 @@ public class Utils {
GlStateManager.enableDepth();
RenderHelper.enableStandardItemLighting();
GlStateManager.enableRescaleNormal();
+ if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.guiScale != 0) Utils.pushGuiScale(0);
}
GlStateManager.disableLighting();
}