mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 04:09:57 +00:00
Add Tooltips
This commit is contained in:
1 parent
c6810c05ea
commit
aeb0093b4d
6 files changed
+210
-11
No files matched your search
@@ -88,7 +88,9 @@ public class SubGuiConditionEdit extends SubGuiInterface implements ITextfieldLi
|
||||
|
||||
// Condition Type selector
|
||||
addLabel(new GuiNpcLabel(1, "gui.type", labelX, y + 5));
|
||||
addButton(new GuiNpcButton(1, fieldX, y, 115, 20, CONDITION_TYPES, selectedTypeIndex));
|
||||
GuiNpcButton typeBtn = new GuiNpcButton(1, fieldX, y, 115, 20, CONDITION_TYPES, selectedTypeIndex);
|
||||
typeBtn.setHoverText("condition.hover.type");
|
||||
addButton(typeBtn);
|
||||
y += 26;
|
||||
|
||||
// Type-specific fields
|
||||
@@ -99,6 +101,7 @@ public class SubGuiConditionEdit extends SubGuiInterface implements ITextfieldLi
|
||||
GuiNpcTextField hitsField = new GuiNpcTextField(2, this, fontRendererObj, fieldX, y, 40, 20, String.valueOf(requiredHits));
|
||||
hitsField.setIntegersOnly();
|
||||
hitsField.setMinMaxDefault(1, 100, 3);
|
||||
hitsField.setHoverText("condition.hover.hits");
|
||||
addTextField(hitsField);
|
||||
y += 24;
|
||||
|
||||
@@ -106,6 +109,7 @@ public class SubGuiConditionEdit extends SubGuiInterface implements ITextfieldLi
|
||||
GuiNpcTextField ticksField = new GuiNpcTextField(3, this, fontRendererObj, fieldX, y, 40, 20, String.valueOf(withinTicks));
|
||||
ticksField.setIntegersOnly();
|
||||
ticksField.setMinMaxDefault(1, 1200, 60);
|
||||
ticksField.setHoverText("condition.hover.within");
|
||||
addTextField(ticksField);
|
||||
} else {
|
||||
// HP threshold field (as percentage)
|
||||
@@ -114,6 +118,7 @@ public class SubGuiConditionEdit extends SubGuiInterface implements ITextfieldLi
|
||||
GuiNpcTextField thresholdField = new GuiNpcTextField(4, this, fontRendererObj, fieldX, y, 40, 20, String.valueOf(percent));
|
||||
thresholdField.setIntegersOnly();
|
||||
thresholdField.setMinMaxDefault(1, 99, 50);
|
||||
thresholdField.setHoverText("condition.hover.threshold");
|
||||
addTextField(thresholdField);
|
||||
addLabel(new GuiNpcLabel(4, "%", fieldX + 45, y + 5));
|
||||
}
|
||||
|
||||
@@ -74,13 +74,16 @@ public class SubGuiAbilityEffects extends SubGuiInterface implements ITextfieldL
|
||||
|
||||
// Type selector button
|
||||
int typeIndex = effect.getType().ordinal();
|
||||
addButton(new GuiNpcButton(baseId, guiLeft + 8, y, 100, 20, EFFECT_TYPE_NAMES, typeIndex));
|
||||
GuiNpcButton typeBtn = new GuiNpcButton(baseId, guiLeft + 8, y, 100, 20, EFFECT_TYPE_NAMES, typeIndex);
|
||||
typeBtn.setHoverText("effect.hover.type");
|
||||
addButton(typeBtn);
|
||||
|
||||
// Duration text field
|
||||
GuiNpcTextField durField = new GuiNpcTextField(baseId + 1, this, fontRendererObj,
|
||||
guiLeft + 112, y, 50, 20, String.valueOf(effect.getDurationTicks()));
|
||||
durField.setIntegersOnly();
|
||||
durField.setMinMaxDefault(1, 12000, 60);
|
||||
durField.setHoverText("effect.hover.duration");
|
||||
addTextField(durField);
|
||||
|
||||
// Amplifier selector (0-10)
|
||||
@@ -88,7 +91,9 @@ public class SubGuiAbilityEffects extends SubGuiInterface implements ITextfieldL
|
||||
for (int a = 0; a <= 10; a++) {
|
||||
ampValues[a] = String.valueOf(a);
|
||||
}
|
||||
addButton(new GuiNpcButton(baseId + 2, guiLeft + 168, y, 40, 20, ampValues, effect.getAmplifier()));
|
||||
GuiNpcButton ampBtn = new GuiNpcButton(baseId + 2, guiLeft + 168, y, 40, 20, ampValues, effect.getAmplifier());
|
||||
ampBtn.setHoverText("effect.hover.amplifier");
|
||||
addButton(ampBtn);
|
||||
|
||||
// Delete button
|
||||
addButton(new GuiNpcButton(baseId + 3, guiLeft + 215, y, 20, 20, "X"));
|
||||
|
||||
@@ -409,6 +409,11 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
button.drawHover(i, j, subGui);
|
||||
}
|
||||
}
|
||||
for (GuiNpcTextField textField : textfields.values()) {
|
||||
if (textField.hasHoverText()) {
|
||||
textField.drawHover(i, j, subGui);
|
||||
}
|
||||
}
|
||||
|
||||
for (GuiScreen gui : extra.values())
|
||||
gui.drawScreen(i, j, f);
|
||||
|
||||
@@ -3,6 +3,7 @@ package noppes.npcs.client.gui.util;
|
||||
import kamkeel.npcs.util.TextSplitter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
@@ -217,17 +218,27 @@ public class GuiNpcButton extends GuiButton {
|
||||
maxHeight += 2 + (textLines.size() - 1) * 10;
|
||||
}
|
||||
|
||||
int gameWidth = mc.displayWidth;
|
||||
int maxTooltipX = gameWidth - maxWidth - 4;
|
||||
// Get scaled screen dimensions
|
||||
ScaledResolution scaledRes = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int screenWidth = scaledRes.getScaledWidth();
|
||||
int screenHeight = scaledRes.getScaledHeight();
|
||||
|
||||
if (j2 > maxTooltipX) {
|
||||
int diff = j2 - maxTooltipX;
|
||||
j2 -= diff;
|
||||
GL11.glTranslatef(-300, 0, 0);
|
||||
// If tooltip would go off right edge, draw on left side of mouse
|
||||
if (j2 + maxWidth + 6 > screenWidth) {
|
||||
j2 = x - maxWidth - 16;
|
||||
}
|
||||
|
||||
if (k2 + maxHeight + 6 > mc.displayHeight) {
|
||||
k2 = mc.displayHeight - maxHeight - 6;
|
||||
// Keep tooltip on screen horizontally
|
||||
if (j2 < 4) {
|
||||
j2 = 4;
|
||||
}
|
||||
|
||||
// Keep tooltip on screen vertically
|
||||
if (k2 + maxHeight + 6 > screenHeight) {
|
||||
k2 = screenHeight - maxHeight - 6;
|
||||
}
|
||||
if (k2 < 4) {
|
||||
k2 = 4;
|
||||
}
|
||||
|
||||
this.zLevel = 300.0F;
|
||||
|
||||
@@ -4,6 +4,14 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import kamkeel.npcs.util.TextSplitter;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class GuiNpcTextField extends GuiTextField {
|
||||
public boolean enabled = true;
|
||||
@@ -18,6 +26,9 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
public float minFloat = 0, maxFloat = Float.MAX_VALUE, defFloat = 0;
|
||||
protected static GuiNpcTextField activeTextfield = null;
|
||||
public boolean canEdit = true;
|
||||
public String hoverableText = "";
|
||||
private boolean wasHovered = false;
|
||||
private int hoverCount = 0;
|
||||
|
||||
private final int[] allowedSpecialChars = {14, 211, 203, 205};
|
||||
|
||||
@@ -203,5 +214,151 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setHoverText(String text) {
|
||||
this.hoverableText = StatCollector.translateToLocal(text);
|
||||
}
|
||||
|
||||
public boolean hasHoverText() {
|
||||
return hoverableText != null && !hoverableText.isEmpty();
|
||||
}
|
||||
|
||||
public boolean isMouseOver(int mouseX, int mouseY) {
|
||||
return mouseX >= xPosition && mouseX < xPosition + width &&
|
||||
mouseY >= yPosition && mouseY < yPosition + height;
|
||||
}
|
||||
|
||||
public void drawHover(int mouseX, int mouseY, boolean hasSubGui) {
|
||||
if (hasSubGui || !enabled || hoverableText.isEmpty())
|
||||
return;
|
||||
|
||||
boolean isHovered = isMouseOver(mouseX, mouseY);
|
||||
if (!isHovered) {
|
||||
wasHovered = false;
|
||||
hoverCount = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wasHovered) {
|
||||
wasHovered = true;
|
||||
hoverCount = 0;
|
||||
} else if (hoverCount < 65) {
|
||||
hoverCount++;
|
||||
}
|
||||
|
||||
if (hoverCount > 60) {
|
||||
GL11.glPushMatrix();
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
List<String> lines = TextSplitter.splitText(hoverableText, 30);
|
||||
drawHoveringText(lines, mouseX, mouseY, mc);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawHoveringText(List<String> textLines, int x, int y, Minecraft mc) {
|
||||
if (mc.fontRenderer == null || textLines.isEmpty())
|
||||
return;
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
int maxWidth = 0;
|
||||
for (String s : textLines) {
|
||||
int lineWidth = mc.fontRenderer.getStringWidth(s);
|
||||
if (lineWidth > maxWidth) {
|
||||
maxWidth = lineWidth;
|
||||
}
|
||||
}
|
||||
|
||||
int j2 = x + 12;
|
||||
int k2 = y - 12;
|
||||
int maxHeight = 8;
|
||||
|
||||
if (textLines.size() > 1) {
|
||||
maxHeight += 2 + (textLines.size() - 1) * 10;
|
||||
}
|
||||
|
||||
// Get scaled screen dimensions
|
||||
ScaledResolution scaledRes = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int screenWidth = scaledRes.getScaledWidth();
|
||||
int screenHeight = scaledRes.getScaledHeight();
|
||||
|
||||
// If tooltip would go off right edge, draw on left side of mouse
|
||||
if (j2 + maxWidth + 6 > screenWidth) {
|
||||
j2 = x - maxWidth - 16;
|
||||
}
|
||||
|
||||
// Keep tooltip on screen horizontally
|
||||
if (j2 < 4) {
|
||||
j2 = 4;
|
||||
}
|
||||
|
||||
// Keep tooltip on screen vertically
|
||||
if (k2 + maxHeight + 6 > screenHeight) {
|
||||
k2 = screenHeight - maxHeight - 6;
|
||||
}
|
||||
if (k2 < 4) {
|
||||
k2 = 4;
|
||||
}
|
||||
|
||||
int zLevel = 300;
|
||||
int bgColor = 0xF0100010;
|
||||
int borderColor1 = 0x505000FF;
|
||||
int borderColor2 = (borderColor1 & 0xFEFEFE) >> 1 | borderColor1 & 0xFF000000;
|
||||
|
||||
drawGradientRect(j2 - 3, k2 - 4, j2 + maxWidth + 3, k2 - 3, bgColor, bgColor, zLevel);
|
||||
drawGradientRect(j2 - 3, k2 + maxHeight + 3, j2 + maxWidth + 3, k2 + maxHeight + 4, bgColor, bgColor, zLevel);
|
||||
drawGradientRect(j2 - 3, k2 - 3, j2 + maxWidth + 3, k2 + maxHeight + 3, bgColor, bgColor, zLevel);
|
||||
drawGradientRect(j2 - 4, k2 - 3, j2 - 3, k2 + maxHeight + 3, bgColor, bgColor, zLevel);
|
||||
drawGradientRect(j2 + maxWidth + 3, k2 - 3, j2 + maxWidth + 4, k2 + maxHeight + 3, bgColor, bgColor, zLevel);
|
||||
drawGradientRect(j2 - 3, k2 - 3 + 1, j2 - 3 + 1, k2 + maxHeight + 3 - 1, borderColor1, borderColor2, zLevel);
|
||||
drawGradientRect(j2 + maxWidth + 2, k2 - 3 + 1, j2 + maxWidth + 3, k2 + maxHeight + 3 - 1, borderColor1, borderColor2, zLevel);
|
||||
drawGradientRect(j2 - 3, k2 - 3, j2 + maxWidth + 3, k2 - 3 + 1, borderColor1, borderColor1, zLevel);
|
||||
drawGradientRect(j2 - 3, k2 + maxHeight + 2, j2 + maxWidth + 3, k2 + maxHeight + 3, borderColor2, borderColor2, zLevel);
|
||||
|
||||
for (int l = 0; l < textLines.size(); ++l) {
|
||||
String s1 = textLines.get(l);
|
||||
mc.fontRenderer.drawStringWithShadow(s1, j2, k2, -1);
|
||||
if (l == 0) {
|
||||
k2 += 2;
|
||||
}
|
||||
k2 += 10;
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
}
|
||||
|
||||
protected void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor, int zLevel) {
|
||||
float f = (float)(startColor >> 24 & 255) / 255.0F;
|
||||
float f1 = (float)(startColor >> 16 & 255) / 255.0F;
|
||||
float f2 = (float)(startColor >> 8 & 255) / 255.0F;
|
||||
float f3 = (float)(startColor & 255) / 255.0F;
|
||||
float f4 = (float)(endColor >> 24 & 255) / 255.0F;
|
||||
float f5 = (float)(endColor >> 16 & 255) / 255.0F;
|
||||
float f6 = (float)(endColor >> 8 & 255) / 255.0F;
|
||||
float f7 = (float)(endColor & 255) / 255.0F;
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||
net.minecraft.client.renderer.Tessellator tessellator = net.minecraft.client.renderer.Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setColorRGBA_F(f1, f2, f3, f);
|
||||
tessellator.addVertex((double)right, (double)top, (double)zLevel);
|
||||
tessellator.addVertex((double)left, (double)top, (double)zLevel);
|
||||
tessellator.setColorRGBA_F(f5, f6, f7, f4);
|
||||
tessellator.addVertex((double)left, (double)bottom, (double)zLevel);
|
||||
tessellator.addVertex((double)right, (double)bottom, (double)zLevel);
|
||||
tessellator.draw();
|
||||
GL11.glShadeModel(GL11.GL_FLAT);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user