Better Tooltips

This commit is contained in:
kirillsaint 2023-09-09 16:45:04 +06:00
parent 2d936e53f2
commit 3337cd65ec
11 changed files with 145 additions and 38 deletions

View File

@ -101,6 +101,9 @@ public class OutfitsGui extends SilentScreen {
cursorType = MouseCursorHandler.CursorType.POINTER;
RenderUtil.drawRoundedRect(outfitX, outfitY, 80, 80, 3, new Color(255, 255, 255, 30).getRGB());
}
if(MouseUtils.isInside(mouseX, mouseY, outfitX + 80 - 3 - 10, outfitY + 3, 10, 10)) {
cursorType = MouseCursorHandler.CursorType.POINTER;
}
RenderUtil.drawRoundedOutline(outfitX, outfitY, 80, 80, 3, 1, Theme.borderColor().getRGB());
Client.getInstance().getSilentFontRenderer().drawString(outfit.name, outfitX + 3, (int) (outfitY + 3), 12, SilentFontRenderer.FontType.TITLE, 64);
RenderUtil.drawImage(new ResourceLocation("silentclient/icons/trash-icon.png"), outfitX + 80 - 3 - 10, outfitY + 3, 10, 10);

View File

@ -0,0 +1,32 @@
package net.silentclient.client.emotes;
import net.minecraft.client.model.ModelBiped;
import net.silentclient.client.emotes.animation.EmoteSimpleAnimation;
public class DabEmote {
private EmoteSimpleAnimation bipedRightArm = new EmoteSimpleAnimation();
private EmoteSimpleAnimation bipedLeftArm = new EmoteSimpleAnimation();
private EmoteSimpleAnimation bipedHead = new EmoteSimpleAnimation();
private EmoteSimpleAnimation modelRightArm = new EmoteSimpleAnimation();
private EmoteSimpleAnimation modelRightArmWear = new EmoteSimpleAnimation();
private EmoteSimpleAnimation modelLeftArm = new EmoteSimpleAnimation();
private EmoteSimpleAnimation modelLeftArmWear = new EmoteSimpleAnimation();
private EmoteSimpleAnimation modelHead = new EmoteSimpleAnimation();
private EmoteSimpleAnimation modelHeadWear = new EmoteSimpleAnimation();
public void initEmoteBiped(ModelBiped modelBiped) {
bipedHead.getX().setValue(modelBiped.bipedHead.rotateAngleX);
bipedHead.getY().setValue(modelBiped.bipedHead.rotateAngleY);
bipedHead.getZ().setValue(modelBiped.bipedHead.rotateAngleZ);
bipedRightArm.getX().setValue(modelBiped.bipedRightArm.rotateAngleX);
bipedRightArm.getY().setValue(modelBiped.bipedRightArm.rotateAngleY);
bipedRightArm.getZ().setValue(modelBiped.bipedRightArm.rotateAngleZ);
bipedLeftArm.getX().setValue(modelBiped.bipedLeftArm.rotateAngleX);
bipedLeftArm.getY().setValue(modelBiped.bipedLeftArm.rotateAngleY);
bipedLeftArm.getZ().setValue(modelBiped.bipedLeftArm.rotateAngleZ);
}
public void renderEmoteBiped(ModelBiped modelBiped) {
}
}

View File

@ -0,0 +1,21 @@
package net.silentclient.client.emotes.animation;
import net.silentclient.client.gui.animation.SimpleAnimation;
public class EmoteSimpleAnimation {
private SimpleAnimation xAnimation = new SimpleAnimation(0);
private SimpleAnimation yAnimation = new SimpleAnimation(0);
private SimpleAnimation zAnimation = new SimpleAnimation(0);
public SimpleAnimation getX() {
return xAnimation;
}
public SimpleAnimation getY() {
return yAnimation;
}
public SimpleAnimation getZ() {
return zAnimation;
}
}

View File

@ -8,16 +8,21 @@ import net.silentclient.client.gui.util.RenderUtil;
public class Switch {
public static void render(int mouseX, int mouseY, float x, float y, SimpleAnimation animation, boolean checked, boolean disabled) {
render(mouseX, mouseY, x, y, animation, checked, disabled, new DefaultSwitchTheme());
render(mouseX, mouseY, x, y, animation, checked, disabled, null, new DefaultSwitchTheme());
}
public static void render(int mouseX, int mouseY, float x, float y, SimpleAnimation animation, boolean checked, boolean disabled, ISwitchSchema theme) {
public static void render(int mouseX, int mouseY, float x, float y, SimpleAnimation animation, boolean checked, boolean disabled, String tooltip) {
render(mouseX, mouseY, x, y, animation, checked, disabled, tooltip, new DefaultSwitchTheme());
}
public static void render(int mouseX, int mouseY, float x, float y, SimpleAnimation animation, boolean checked, boolean disabled, String tooltip, ISwitchSchema theme) {
RenderUtil.drawRoundedRect(x, y, 15, 8, 8, disabled ? theme.getDisabledBackgroundColor().getRGB() : checked ? theme.getSelectedBackgroundColor().getRGB() : theme.getBackgroundColor().getRGB());
if(isHovered(mouseX, mouseY, x, y)) {
RenderUtil.drawRoundedOutline(x, y, 15, 8, 8, 2, theme.getBorderColor().getRGB());
}
RenderUtil.drawRoundedRect(x + 0.5F + (animation.getValue()), y + 0.5F, 7, 7, 7, theme.getCircleColor().getRGB());
animation.setAnimation(checked && !disabled ? 15 - 8 : 0, 20);
Tooltip.render(mouseX, mouseY, x, y, 15, 8, tooltip);
}
public static boolean isHovered(int mouseX, int mouseY, float x, float y) {

View File

@ -0,0 +1,31 @@
package net.silentclient.client.gui.elements;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.silentclient.client.Client;
import net.silentclient.client.gui.font.SilentFontRenderer;
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
import net.silentclient.client.gui.lite.clickgui.utils.RenderUtils;
import net.silentclient.client.gui.theme.Theme;
public class Tooltip {
public static void render(int mouseX, int mouseY, float x, float y, int width, int height, String text) {
if(MouseUtils.isInside(mouseX, mouseY, x, y, width, height) && text != null) {
float tooltipWidth = Client.getInstance().getSilentFontRenderer().getStringWidth(text, 10, SilentFontRenderer.FontType.TITLE) + 4;
float tooltipX = x + ((width / 2) - (tooltipWidth / 2));
float tooltipY = y + height + 2;
ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
if(tooltipX < 2) {
tooltipX = 2;
}
if(tooltipX + tooltipWidth > scaledResolution.getScaledWidth()) {
tooltipX = scaledResolution.getScaledWidth() - tooltipWidth - 2;
}
if(tooltipY + 14 > scaledResolution.getScaledHeight()) {
tooltipY = y - 16;
}
RenderUtils.drawRect(tooltipX, tooltipY, tooltipWidth, 14, Theme.backgroundColor().getRGB());
Client.getInstance().getSilentFontRenderer().drawString(text, tooltipX + 2, tooltipY + 2, 10, SilentFontRenderer.FontType.TITLE);
}
}
}

View File

@ -2,10 +2,6 @@ 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;
@ -18,14 +14,6 @@ public class TooltipIconButton extends IconButton {
@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);
}
Tooltip.render(mouseX, mouseY, this.xPosition, this.yPosition, this.width, this.height, this.tooltipText);
}
}

View File

@ -140,7 +140,7 @@ public class ClickGUI extends SilentScreen {
RenderUtil.drawImage(new ResourceLocation(m.getIcon()), modOffsetX + ((65 / 2) - 10), y + modOffsetY - scrollAnimation.getValue() + ((70 / 2) - 10), 20, 20, false);
}
if(selectedCategory.equals(ModCategory.MODS)) {
Switch.render(mouseX, mouseY, switchX, switchY, m.switchAniamation, m.isEnabled(), m.isForceDisabled());
Switch.render(mouseX, mouseY, switchX, switchY, m.switchAniamation, m.isEnabled(), m.isForceDisabled(), m.isForceDisabled() ? "Force disabled" : null);
}
if(switchHovered || isHovered) {

View File

@ -139,18 +139,7 @@ public class ModSettings extends SilentScreen {
ScaledResolution r = new ScaledResolution(mc);
int s = r.getScaleFactor();
int translatedY = r.getScaledHeight() - y - height;
GL11.glScissor(x * s, translatedY * s, width * s, height * s);
if(mod.getCategory() == ModCategory.MODS) {
RenderUtil.drawImage(new ResourceLocation("silentclient/icons/reset_settings.png"), x + width - (10 + 8) - 15, y + 5 + scrollAnimation.getValue(), 10, 10);
if(MouseUtils.isInside(mouseX, mouseY, x + width - (10 + 8) - 15, y + 5 + scrollAnimation.getValue(), 10, 10)) {
cursorType = MouseCursorHandler.CursorType.POINTER;
}
Switch.render(mouseX, mouseY, x + width - (10 + 8), y + 6 + scrollAnimation.getValue(), mod.switchAniamation, mod.isEnabled(), mod.isForceDisabled());
if(Switch.isHovered(mouseX, mouseY, x + width - (10 + 8), y + 6 + scrollAnimation.getValue())) {
cursorType = MouseCursorHandler.CursorType.POINTER;
}
}
GL11.glScissor(x * s, translatedY * s, this.width * s, height * s);
Client.getInstance().getSilentFontRenderer().drawString(mod.getName(), x + 100, (int) (y + 5) + scrollAnimation.getValue(), 14, SilentFontRenderer.FontType.TITLE);
MouseCursorHandler.CursorType cursorTypeCustom = mod.renderCustomLiteComponent(x + 100, (int) (y + 25 + scrollAnimation.getValue()), width, height, mouseX, mouseY);
@ -226,6 +215,17 @@ public class ModSettings extends SilentScreen {
settingIndex++;
settingY += settingHeight;
}
if(mod.getCategory() == ModCategory.MODS) {
RenderUtil.drawImage(new ResourceLocation("silentclient/icons/reset_settings.png"), x + width - (10 + 8) - 15, y + 5 + scrollAnimation.getValue(), 10, 10);
Tooltip.render(mouseX, mouseY, x + width - (10 + 8) - 15, y + 5 + scrollAnimation.getValue(), 10, 10, "Reset");
if(MouseUtils.isInside(mouseX, mouseY, x + width - (10 + 8) - 15, y + 5 + scrollAnimation.getValue(), 10, 10)) {
cursorType = MouseCursorHandler.CursorType.POINTER;
}
Switch.render(mouseX, mouseY, x + width - (10 + 8), y + 6 + scrollAnimation.getValue(), mod.switchAniamation, mod.isEnabled(), mod.isForceDisabled(), mod.isForceDisabled() ? "Force disabled" : null);
if(Switch.isHovered(mouseX, mouseY, x + width - (10 + 8), y + 6 + scrollAnimation.getValue())) {
cursorType = MouseCursorHandler.CursorType.POINTER;
}
}
GL11.glDisable(GL11.GL_SCISSOR_TEST);
GL11.glPopMatrix();

View File

@ -160,7 +160,7 @@ public class ModMenu extends SilentScreen {
Client.getInstance().getSilentFontRenderer().drawString(mod.getName(), modX, modY + 10 - 6, 12, SilentFontRenderer.FontType.TITLE);
if(modCategory == ModCategory.MODS) {
Switch.render(mouseX, mouseY, 129, modY + 10 - 4, mod.switchAniamation, mod.isEnabled(), mod.isForceDisabled());
Switch.render(mouseX, mouseY, 129, modY + 10 - 4, mod.switchAniamation, mod.isEnabled(), mod.isForceDisabled(), mod.isForceDisabled() ? "Force disabled" : null);
if(Switch.isHovered(mouseX, mouseY, 129, modY + 10 - 4)) {
cursorType = MouseCursorHandler.CursorType.POINTER;
}
@ -183,8 +183,10 @@ public class ModMenu extends SilentScreen {
boolean isHovered = mouseInContent(mouseX, mouseY, height) && MouseUtils.isInside(mouseX, mouseY, 3, configY, 144, 20);
if(isHovered) {
cursorType = MouseCursorHandler.CursorType.POINTER;
if(!MouseUtils.isInside(mouseX, mouseY, 132, configY + 10 - 6, 12, 12)) {
RenderUtil.drawRoundedRect(3, configY, 144, 20, 3, new Color(255, 255, 255, 30).getRGB());
}
}
RenderUtil.drawRoundedOutline(3, configY, 144, 20, 3, 1, Theme.borderColor().getRGB());
Client.getInstance().getSilentFontRenderer().drawString(Files.getNameWithoutExtension(config), 6, (int) configY + 10 - 6, 12, SilentFontRenderer.FontType.TITLE, 90);

View File

@ -16,9 +16,8 @@ import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
import net.silentclient.client.Client;
import net.silentclient.client.gui.font.SilentFontRenderer;
import net.silentclient.client.gui.elements.Tooltip;
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
import net.silentclient.client.gui.lite.clickgui.utils.RenderUtils;
import net.silentclient.client.gui.multiplayer.SilentMultiplayerGui;
import net.silentclient.client.gui.theme.Theme;
import net.silentclient.client.gui.util.RenderUtil;
@ -186,12 +185,7 @@ public class ServerComponent {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(Gui.icons);
Gui.drawModalRectWithCustomSizedTexture((int) x + 240 - 15, (int) y + 2, (float)(k * 10), (float)(176 + l * 8), 10, 8, 256.0F, 256.0F);
if(MouseUtils.isInside(mouseX, mouseY, x + 240 - 15, y + 2, 10, 8)) {
float toastWidth = Client.getInstance().getSilentFontRenderer().getStringWidth(s1, 10, SilentFontRenderer.FontType.TITLE) + 4;
float toastX = x + 240 - 15 + (10 / 2) - (toastWidth / 2);
RenderUtils.drawRect(toastX, y + 2 + 10 + 1, toastWidth, 14, Theme.backgroundColor().getRGB());
Client.getInstance().getSilentFontRenderer().drawString(s1, toastX + 2, y + 2 + 10 + 1 + 2, 10, SilentFontRenderer.FontType.TITLE);
}
Tooltip.render(mouseX, mouseY, x + 240 - 15, y + 2, 10, 8, s1);
return cursorType;
}

View File

@ -0,0 +1,31 @@
package net.silentclient.client.mods.player;
import net.silentclient.client.Client;
import net.silentclient.client.event.EventTarget;
import net.silentclient.client.event.impl.KeyEvent;
import net.silentclient.client.mods.Mod;
import net.silentclient.client.mods.ModCategory;
import org.lwjgl.input.Keyboard;
public class EmoteMod extends Mod {
public static boolean active = false;
public EmoteMod() {
super("Emotes", ModCategory.MODS, null);
}
@Override
public void setup() {
super.setup();
this.addKeybindSetting("Keybind", this, Keyboard.KEY_B);
}
@EventTarget
public void onKey(KeyEvent event) {
if(event.getKey() == Client.getInstance().getSettingsManager().getSettingByName(this, "Keybind").getKeybind()) {
active = !active;
if(active) {
}
}
}
}