Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use vanilla tooltip rendering for sidebar buttons and fix Z height #128

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.27'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.28'
}


48 changes: 19 additions & 29 deletions src/main/java/serverutils/client/gui/GuiSidebar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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();
Expand All @@ -151,6 +123,12 @@ public void drawButton(Minecraft mc, int mx, int my) {
lastDrawnArea = new Rectangle(xPosition, yPosition, width, height);
}

public void addTooltip(List<String> textLines) {
if (mouseOver != null) {
mouseOver.addTooltip(textLines);
}
}

@Override
public boolean mousePressed(Minecraft mc, int mx, int my) {
if (super.mousePressed(mc, mx, my)) {
Expand Down Expand Up @@ -213,7 +191,7 @@ private void addButtonsToSidebar() {
rx++;
addedAny = true;
}
};
}

if (placement != EnumPlacement.GROUPED) {
if (ry >= max) {
Expand Down Expand Up @@ -286,5 +264,17 @@ public GuiButtonSidebar(int x, int y, SidebarButton b) {
buttonY = y;
button = b;
}

public void addTooltip(List<String> textLines) {
textLines.add(StatCollector.translateToLocal(button.getLangKey()));

if (button.isDisabled()) {
textLines.add(EnumChatFormatting.RED + ClientUtils.getDisabledTip());
}

if (button.getTooltipHandler() != null) {
button.getTooltipHandler().accept(textLines);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,6 +62,8 @@ public class ServerUtilitiesClientEventHandler {
public static boolean shouldRenderIcons = false;
public static long shutdownTime = 0L;

private static final List<String> sidebarButtonTooltip = new ArrayList<>();

public static void readSyncData(NBTTagCompound nbt) {
shutdownTime = System.currentTimeMillis() + nbt.getLong("ShutdownTime");
}
Expand Down Expand Up @@ -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);
wlhlm marked this conversation as resolved.
Show resolved Hide resolved
}
});
}
}

@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void onGameOverlayRender(RenderGameOverlayEvent.Text event) {
if (currentNotification != null && !currentNotification.isImportant()) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/serverutil_at.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down