diff --git a/dependencies.gradle b/dependencies.gradle index f76117ea..68e6ed83 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -2,7 +2,7 @@ dependencies { - api("com.github.GTNewHorizons:GTNHLib:0.5.17:dev") + api("com.github.GTNewHorizons:GTNHLib:0.5.18:dev") compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.6.44-GTNH:dev") compileOnly("com.github.GTNewHorizons:EnderIO:2.8.20:dev") compileOnly("com.github.GTNewHorizons:Navigator:1.0.15:dev") diff --git a/settings.gradle b/settings.gradle index 3d3ba12c..14cb8b7d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,7 +17,7 @@ pluginManagement { } plugins { - id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.27' + id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.28' } diff --git a/src/main/java/serverutils/client/gui/GuiSidebar.java b/src/main/java/serverutils/client/gui/GuiSidebar.java index 38543f33..6ea32596 100644 --- a/src/main/java/serverutils/client/gui/GuiSidebar.java +++ b/src/main/java/serverutils/client/gui/GuiSidebar.java @@ -115,34 +115,6 @@ public void drawButton(Minecraft mc, int mx, int my) { } } - if (mouseOver != null) { - int mx1 = mx + 10; - int my1 = Math.max(3, my - 9); - - List list = new ArrayList<>(); - list.add(StatCollector.translateToLocal(mouseOver.button.getLangKey())); - - if (mouseOver.button.isDisabled()) { - list.add(EnumChatFormatting.RED + ClientUtils.getDisabledTip()); - } - - if (mouseOver.button.getTooltipHandler() != null) { - mouseOver.button.getTooltipHandler().accept(list); - } - - int tw = 0; - - for (String s : list) { - tw = Math.max(tw, font.getStringWidth(s)); - } - - Color4I.DARK_GRAY.draw(mx1 - 3, my1 - 2, tw + 6, 2 + list.size() * 10); - - for (int i = 0; i < list.size(); i++) { - font.drawString(list.get(i), mx1, my1 + i * 10, 0xFFFFFFFF); - } - } - GlStateManager.color(1F, 1F, 1F, 1F); GlStateManager.disableDepth(); GlStateManager.popMatrix(); @@ -151,6 +123,12 @@ public void drawButton(Minecraft mc, int mx, int my) { lastDrawnArea = new Rectangle(xPosition, yPosition, width, height); } + public void addTooltip(List textLines) { + if (mouseOver != null) { + mouseOver.addTooltip(textLines); + } + } + @Override public boolean mousePressed(Minecraft mc, int mx, int my) { if (super.mousePressed(mc, mx, my)) { @@ -213,7 +191,7 @@ private void addButtonsToSidebar() { rx++; addedAny = true; } - }; + } if (placement != EnumPlacement.GROUPED) { if (ry >= max) { @@ -286,5 +264,17 @@ public GuiButtonSidebar(int x, int y, SidebarButton b) { buttonY = y; button = b; } + + public void addTooltip(List textLines) { + textLines.add(StatCollector.translateToLocal(button.getLangKey())); + + if (button.isDisabled()) { + textLines.add(EnumChatFormatting.RED + ClientUtils.getDisabledTip()); + } + + if (button.getTooltipHandler() != null) { + button.getTooltipHandler().accept(textLines); + } + } } } diff --git a/src/main/java/serverutils/handlers/ServerUtilitiesClientEventHandler.java b/src/main/java/serverutils/handlers/ServerUtilitiesClientEventHandler.java index 1177b62e..f464b826 100644 --- a/src/main/java/serverutils/handlers/ServerUtilitiesClientEventHandler.java +++ b/src/main/java/serverutils/handlers/ServerUtilitiesClientEventHandler.java @@ -7,6 +7,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.GuiContainer; @@ -61,6 +62,8 @@ public class ServerUtilitiesClientEventHandler { public static boolean shouldRenderIcons = false; public static long shutdownTime = 0L; + private static final List sidebarButtonTooltip = new ArrayList<>(); + public static void readSyncData(NBTTagCompound nbt) { shutdownTime = System.currentTimeMillis() + nbt.getLong("ShutdownTime"); } @@ -282,6 +285,23 @@ public void onClientTick(TickEvent.ClientTickEvent event) { } } + /** + * Renders sidebar button tooltips outside of {@link GuiSidebar#drawButton} so that other screen elements don't draw + * over it. + */ + @SubscribeEvent + public void onGuiScreenDraw(final GuiScreenEvent.DrawScreenEvent.Post event) { + if (ClientUtils.areButtonsVisible(event.gui)) { + event.gui.buttonList.forEach((GuiButton button) -> { + if (button instanceof GuiSidebar sidebar) { + sidebarButtonTooltip.clear(); + sidebar.addTooltip(sidebarButtonTooltip); + event.gui.func_146283_a(sidebarButtonTooltip, event.mouseX, event.mouseY); + } + }); + } + } + @SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true) public void onGameOverlayRender(RenderGameOverlayEvent.Text event) { if (currentNotification != null && !currentNotification.isImportant()) { diff --git a/src/main/resources/META-INF/serverutil_at.cfg b/src/main/resources/META-INF/serverutil_at.cfg index b033ed0b..b641655b 100644 --- a/src/main/resources/META-INF/serverutil_at.cfg +++ b/src/main/resources/META-INF/serverutil_at.cfg @@ -3,6 +3,8 @@ public net.minecraft.util.EnumChatFormatting field_96329_z # formattingCode public net.minecraft.command.CommandHandler field_71561_b # commandSet public net.minecraft.server.management.ServerConfigurationManager field_72407_n # commandsAllowedForAll public net.minecraft.client.gui.FontRenderer field_111274_c # unicodePageLocations +public net.minecraft.client.gui.GuiScreen field_146292_n # buttonList +public net.minecraft.client.gui.GuiScreen func_146283_a(Ljava/util/List;II)V public net.minecraft.util.ChatStyle field_150248_c # bold public net.minecraft.util.ChatStyle field_150245_d # italic public net.minecraft.util.ChatStyle field_150243_f # strikethrough