Icon Button Tooltip

This commit is contained in:
kirillsaint 2023-09-03 14:05:03 +06:00
parent b6dd9d2658
commit d3c9efc4f3
4 changed files with 45 additions and 13 deletions

View File

@ -0,0 +1,31 @@
package net.silentclient.client.gui.elements;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
import net.silentclient.client.Client;
import net.silentclient.client.gui.font.SilentFontRenderer;
import net.silentclient.client.gui.lite.clickgui.utils.RenderUtils;
import net.silentclient.client.gui.theme.Theme;
public class TooltipIconButton extends IconButton {
private final String tooltipText;
public TooltipIconButton(int buttonId, int x, int y, int widthIn, int heightIn, int iconWidth, int iconHeight, ResourceLocation icon, String tooltipText) {
super(buttonId, x, y, widthIn, heightIn, iconWidth, iconHeight, icon);
this.tooltipText = tooltipText;
}
@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
super.drawButton(mc, mouseX, mouseY);
if(this.hovered) {
float tooltipWidth = Client.getInstance().getSilentFontRenderer().getStringWidth(this.tooltipText, 10, SilentFontRenderer.FontType.TITLE) + 4;
float tooltipX = this.xPosition + ((this.width / 2) - (tooltipWidth / 2));
if(tooltipX < 2) {
tooltipX = 2;
}
RenderUtils.drawRect(tooltipX, this.yPosition + this.height + 2, tooltipWidth, 14, Theme.backgroundColor().getRGB());
Client.getInstance().getSilentFontRenderer().drawString(this.tooltipText, tooltipX + 2, this.yPosition + this.height + 2 + 2, 10, SilentFontRenderer.FontType.TITLE);
}
}
}

View File

@ -9,6 +9,7 @@ import net.silentclient.client.gui.SilentScreen;
import net.silentclient.client.gui.animation.SimpleAnimation;
import net.silentclient.client.gui.elements.Button;
import net.silentclient.client.gui.elements.IconButton;
import net.silentclient.client.gui.elements.TooltipIconButton;
import net.silentclient.client.gui.font.SilentFontRenderer;
import net.silentclient.client.gui.lite.LiteAccountPicker;
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
@ -47,7 +48,7 @@ public class FriendsListOverlay extends SilentScreen {
this.buttonList.add(new Button(2, 3, 26, 70, 15, "Friends", 12, false, !showRequests ? new SelectedButtonTheme() : new DefaultButtonTheme()));
this.buttonList.add(new Button(3, 76, 26, 70, 15, "Requests", 12, false, showRequests ? new SelectedButtonTheme() : new DefaultButtonTheme()));
this.buttonList.add(new IconButton(4, 116, 6, 14, 14, 8, 8, new ResourceLocation("silentclient/icons/friends-add.png")));
this.buttonList.add(new TooltipIconButton(4, 116, 6, 14, 14, 8, 8, new ResourceLocation("silentclient/icons/friends-add.png"), "Add friend"));
}
@Override

View File

@ -8,7 +8,7 @@ import net.silentclient.client.cosmetics.gui.CosmeticsGui;
import net.silentclient.client.gui.SilentScreen;
import net.silentclient.client.gui.animation.SimpleAnimation;
import net.silentclient.client.gui.elements.Button;
import net.silentclient.client.gui.elements.IconButton;
import net.silentclient.client.gui.elements.TooltipIconButton;
import net.silentclient.client.gui.font.SilentFontRenderer;
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
import net.silentclient.client.gui.silentmainmenu.MainMenuConcept;
@ -35,11 +35,11 @@ public class LiteMainMenu extends SilentScreen
Client.backgroundPanorama.updateWidthHeight(this.width, this.height);
this.buttonList.clear();
this.buttonList.add(new IconButton(1, 4, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/news.png")));
this.buttonList.add(new IconButton(2, 24, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/settings/cosmetics.png")));
this.buttonList.add(new IconButton(3, 44, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/store_icon.png")));
this.buttonList.add(new IconButton(4, 64, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/language.png")));
this.buttonList.add(new IconButton(5, 84, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/back.png")));
this.buttonList.add(new TooltipIconButton(1, 4, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/news.png"), "News"));
this.buttonList.add(new TooltipIconButton(2, 24, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/settings/cosmetics.png"), "Cosmetics"));
this.buttonList.add(new TooltipIconButton(3, 44, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/store_icon.png"), "Store"));
this.buttonList.add(new TooltipIconButton(4, 64, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/language.png"), "Language"));
this.buttonList.add(new TooltipIconButton(5, 84, 5, 18, 18, 10, 10, new ResourceLocation("silentclient/icons/back.png"), "Switch to SLC"));
int buttonY = this.height / 2 - 18;

View File

@ -15,7 +15,7 @@ import net.silentclient.client.event.impl.ServerLeaveEvent;
import net.silentclient.client.gui.GuiMultiplayerInGame;
import net.silentclient.client.gui.SilentScreen;
import net.silentclient.client.gui.elements.Button;
import net.silentclient.client.gui.elements.IconButton;
import net.silentclient.client.gui.elements.TooltipIconButton;
import net.silentclient.client.gui.friends.FriendsListOverlay;
import net.silentclient.client.gui.hud.Watermark;
import net.silentclient.client.gui.lite.clickgui.ClickGUI;
@ -52,18 +52,18 @@ public class GuiIngameMenu extends SilentScreen
this.buttonList.add(new Button(9, 2, this.height - 10 + i, 95, 20, "Reload Resources", true));
int iconX = 4;
this.buttonList.add(new IconButton(5, iconX, 5, 15, 15, 7, 7, new ResourceLocation("silentclient/icons/trophy.png")));
this.buttonList.add(new TooltipIconButton(5, iconX, 5, 15, 15, 7, 7, new ResourceLocation("silentclient/icons/trophy.png"), "Achievements"));
iconX += 18;
this.buttonList.add(new IconButton(6, iconX, 5, 15, 15, 7, 7, new ResourceLocation("silentclient/icons/graph.png")));
this.buttonList.add(new TooltipIconButton(6, iconX, 5, 15, 15, 7, 7, new ResourceLocation("silentclient/icons/graph.png"), "Statistics"));
iconX += 18;
if(mc.isSingleplayer() && !mc.getIntegratedServer().getPublic()) {
this.buttonList.add(new IconButton(12, iconX, 5, 15, 15, 7, 7, new ResourceLocation("silentclient/icons/lan.png")));
this.buttonList.add(new TooltipIconButton(12, iconX, 5, 15, 15, 7, 7, new ResourceLocation("silentclient/icons/lan.png"), "Open to LAN"));
iconX += 18;
}
this.buttonList.add(new IconButton(13, iconX, 5, 15, 15, 7, 7, new ResourceLocation("silentclient/icons/friends.png")));
this.buttonList.add(new TooltipIconButton(13, iconX, 5, 15, 15, 7, 7, new ResourceLocation("silentclient/icons/friends.png"), "Friends"));
iconX += 18;
if(Client.getInstance().getAccount().isStaff()) {
this.buttonList.add(new IconButton(14, iconX, 5, 15, 15, 7, 7, new ResourceLocation("silentclient/icons/store_icon.png")));
this.buttonList.add(new TooltipIconButton(14, iconX, 5, 15, 15, 7, 7, new ResourceLocation("silentclient/icons/store_icon.png"), "Admin Render"));
}
}