aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/gui')
-rw-r--r--src/main/java/gregtech/api/gui/GT_GUICover.java307
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiFakeItemButton.java64
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java77
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java111
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiIntegerTextBox.java50
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java37
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiTooltipManager.java71
7 files changed, 717 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/gui/GT_GUICover.java b/src/main/java/gregtech/api/gui/GT_GUICover.java
new file mode 100644
index 0000000000..94346186a8
--- /dev/null
+++ b/src/main/java/gregtech/api/gui/GT_GUICover.java
@@ -0,0 +1,307 @@
+package gregtech.api.gui;
+
+import gregtech.api.enums.Dyes;
+import gregtech.api.gui.widgets.GT_GuiFakeItemButton;
+import gregtech.api.gui.widgets.GT_GuiIntegerTextBox;
+import gregtech.api.gui.widgets.GT_GuiTooltip;
+import gregtech.api.gui.widgets.GT_GuiTooltipManager;
+import gregtech.api.gui.widgets.GT_GuiTooltipManager.GT_IToolTipRenderer;
+import gregtech.api.interfaces.IGuiScreen;
+import gregtech.api.interfaces.tileentity.ICoverable;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.GuiButton;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraft.client.gui.GuiTextField;
+import net.minecraft.client.renderer.RenderHelper;
+import net.minecraft.client.renderer.entity.RenderItem;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.ResourceLocation;
+import org.lwjgl.input.Mouse;
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.opengl.GL12;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class GT_GUICover extends GuiScreen implements GT_IToolTipRenderer, IGuiScreen {
+
+ protected GT_GuiTooltipManager ttManager = new GT_GuiTooltipManager();
+
+ protected int gui_width = 176;
+ protected int gui_height = 107;
+ protected int guiTop, guiLeft;
+ protected boolean drawButtons = true;
+ private GuiButton selectedButton;
+ public String header;
+ public GT_GuiFakeItemButton headerIcon;
+ public final ICoverable tile;
+
+
+ protected List<IGuiElement> elements = new ArrayList<>();
+ protected List<GT_GuiIntegerTextBox> textBoxes = new ArrayList<>();
+
+ public GT_GUICover(ICoverable tile, int width, int height, ItemStack cover) {
+ this.tile = tile;
+ this.gui_width = width;
+ this.gui_height = height;
+ this.header = (cover != null) ? cover.getDisplayName() : "";
+ this.headerIcon = new GT_GuiFakeItemButton(this, 5, 5, null).setItem(cover);
+ }
+
+ @Override
+ public void initGui() {
+ guiLeft = (this.width - this.gui_width) / 2;
+ guiTop = (this.height - this.gui_height) / 2;
+
+ for (IGuiElement element : elements) {
+ if (element instanceof GuiButton)
+ buttonList.add(element);
+ if (element instanceof GT_GuiIntegerTextBox)
+ textBoxes.add((GT_GuiIntegerTextBox) element);
+ }
+
+ onInitGui(guiLeft, guiTop, gui_width, gui_height);
+
+ for (IGuiElement element : elements) {
+ element.onInit();
+ }
+ }
+
+ protected abstract void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height);
+
+ public void onMouseWheel(int x, int y, int delta) {
+ }
+
+ @Override
+ public void handleMouseInput() {
+ int delta = Mouse.getEventDWheel();
+ if (delta != 0) {
+ int i = Mouse.getEventX() * this.width / this.mc.displayWidth;
+ int j = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
+ onMouseWheel(i, j, delta);
+ }
+ super.handleMouseInput();
+ }
+
+ @Override
+ public void drawScreen(int mouseX, int mouseY, float parTicks) {
+ drawDefaultBackground();
+
+ drawBackground(mouseX, mouseY, parTicks);
+
+ RenderHelper.disableStandardItemLighting();
+ GL11.glDisable(GL11.GL_LIGHTING);
+ GL11.glDisable(GL11.GL_DEPTH_TEST);
+ GL11.glDisable(GL12.GL_RESCALE_NORMAL);
+ if (drawButtons) {
+ RenderHelper.enableGUIStandardItemLighting();
+ for (IGuiElement e : elements)
+ e.draw(mouseX, mouseY, parTicks);
+ }
+ GL11.glEnable(GL12.GL_RESCALE_NORMAL);
+
+ GL11.glPushMatrix();
+ GL11.glTranslatef(guiLeft, guiTop, 0.0F);
+ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
+
+ GL11.glDisable(GL11.GL_LIGHTING);
+ drawForegroundLayer(mouseX, mouseY, parTicks);
+ GL11.glEnable(GL11.GL_LIGHTING);
+
+ GL11.glPopMatrix();
+
+ GL11.glEnable(GL11.GL_LIGHTING);
+ GL11.glEnable(GL11.GL_DEPTH_TEST);
+ RenderHelper.enableStandardItemLighting();
+ }
+
+ public void drawForegroundLayer(int mouseX, int mouseY, float parTicks) {
+ drawExtras(mouseX, mouseY, parTicks);
+ ttManager.onTick(this, mouseX, mouseY);
+ }
+
+ public void drawBackground(int mouseX, int mouseY, float parTicks) {
+ short[] color = Dyes.MACHINE_METAL.getRGBA();
+ GL11.glColor3ub((byte) color[0], (byte) color[1], (byte) color[2]);
+ this.mc.renderEngine.bindTexture(new ResourceLocation("gregtech:textures/gui/GuiCover.png"));
+ drawTexturedModalRect(guiLeft, guiTop, 0,0, gui_width, gui_height);
+ }
+
+ public void drawExtras(int mouseX, int mouseY, float parTicks) {
+ this.fontRendererObj.drawString(header, 25, 9, 0xFF222222);
+ }
+
+ @Override
+ public boolean doesGuiPauseGame()
+ {
+ return false;
+ }
+
+ public void closeScreen() {
+ this.mc.displayGuiScreen((GuiScreen) null);
+ this.mc.setIngameFocus();
+ }
+
+ @Override
+ public void updateScreen() {
+ super.updateScreen();
+ if (!tile.isUseableByPlayer(mc.thePlayer)) {
+ closeScreen();
+ return;
+ }
+ for (GuiTextField f : textBoxes) {
+ f.updateCursorCounter();
+ }
+ }
+
+ public void mouseClicked(int x, int y, int button) {
+ for (GT_GuiIntegerTextBox tBox : textBoxes) {
+ boolean hadFocus = tBox.isFocused();
+ tBox.mouseClicked(x,y,button);
+ if (tBox.isFocused() && button == 1) //rightclick -> lcear it
+ tBox.setText("0");
+ else if (hadFocus && !tBox.isFocused())
+ applyTextBox(tBox);
+ }
+ super.mouseClicked(x, y, button);
+ }
+
+ @Override
+ public void keyTyped(char c, int key) {
+ GT_GuiIntegerTextBox focusedTextBox = null;
+ for (GT_GuiIntegerTextBox textBox : textBoxes) {
+ if (textBox.isFocused())
+ focusedTextBox = textBox;
+ }
+
+ if (key == 1) { //esc
+ if(focusedTextBox != null) {
+ resetTextBox(focusedTextBox);
+ setFocusedTextBox(null);
+ return;
+ } else {
+ closeScreen();
+ }
+ }
+
+ if (c == '\t') { //tab
+ for (int i = 0; i < textBoxes.size(); i++) {
+ GT_GuiIntegerTextBox box = textBoxes.get(i);
+ if (box.isFocused()) {
+ applyTextBox(box);
+ setFocusedTextBox(((i+1) < textBoxes.size()) ? textBoxes.get(i+1) : null);
+ return;
+ }
+ }
+ }
+
+ if (focusedTextBox != null && focusedTextBox.textboxKeyTyped(c, key)){
+ return;
+ }
+
+ if (key == 28 && focusedTextBox != null) { // enter
+ applyTextBox(focusedTextBox);
+ setFocusedTextBox(null);
+ return;
+ }
+
+ if (key == this.mc.gameSettings.keyBindInventory.getKeyCode()) {
+ if (focusedTextBox != null) {
+ applyTextBox(focusedTextBox);
+ setFocusedTextBox(null);
+ return;
+ }
+ closeScreen();
+ return;
+ }
+ super.keyTyped(c, key);
+ }
+
+ /**
+ * Button
+ */
+
+ public void actionPerformed(GuiButton button) {
+ selectedButton = button;
+ }
+
+ public void clearSelectedButton() {
+ selectedButton = null;
+ }
+ public GuiButton getSelectedButton(){return selectedButton;}
+
+ public void buttonClicked(GuiButton button) {
+
+ }
+
+ /**
+ * TextBoxes
+ */
+ private void setFocusedTextBox(GT_GuiIntegerTextBox boxToFocus) {
+ for (GT_GuiIntegerTextBox textBox : textBoxes) {
+ textBox.setFocused(textBox.equals(boxToFocus));
+ }
+ }
+ public void applyTextBox(GT_GuiIntegerTextBox box) {
+
+ }
+
+ public void resetTextBox(GT_GuiIntegerTextBox box) {
+
+ }
+
+ /**
+ * GT_IToolTipRenderer
+ */
+ @Override
+ public void drawHoveringText(List par1List, int par2, int par3, FontRenderer render) {
+ super.drawHoveringText(par1List, par2, par3, render);
+ }
+ @Override
+ public FontRenderer getFontRenderer() {
+ return super.fontRendererObj;
+ }
+ @Override
+ public void addToolTip(GT_GuiTooltip toolTip) {
+ ttManager.addToolTip(toolTip);
+ }
+ @Override
+ public boolean removeToolTip(GT_GuiTooltip toolTip) {
+ return ttManager.removeToolTip(toolTip);
+ }
+
+ /**
+ * Junk
+ */
+ @Override
+ public int getGuiTop() {
+ return guiTop;
+ }
+ @Override
+ public int getGuiLeft() {
+ return guiLeft;
+ }
+ @Override
+ public int getXSize() {
+ return gui_width;
+ }
+ @Override
+ public int getYSize() {
+ return gui_height;
+ }
+
+ public RenderItem getItemRenderer() {
+ return itemRender;
+ }
+
+ @Override
+ public void addElement(IGuiElement element) {
+ if (elements.contains(element))
+ return;
+ elements.add(element);
+ }
+ @Override
+ public boolean removeElement(IGuiElement element) {
+ return elements.remove(element);
+ }
+}
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiFakeItemButton.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiFakeItemButton.java
new file mode 100644
index 0000000000..db7029d60f
--- /dev/null
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiFakeItemButton.java
@@ -0,0 +1,64 @@
+package gregtech.api.gui.widgets;
+
+import gregtech.api.interfaces.IGuiScreen;
+import net.minecraft.client.Minecraft;
+import net.minecraft.item.ItemStack;
+import org.lwjgl.opengl.GL11;
+
+import java.awt.*;
+
+public class GT_GuiFakeItemButton implements IGuiScreen.IGuiElement {
+
+ private final GT_GuiIcon bgIcon;
+ private ItemStack item;
+ private IGuiScreen gui;
+ private int x0, y0, xPosition, yPosition;
+ private int width, height;
+
+ public GT_GuiFakeItemButton(IGuiScreen gui, int x, int y, GT_GuiIcon bgIcon) {
+ this.gui = gui;
+ this.x0 = x;
+ this.y0 = y;
+ this.bgIcon = bgIcon;
+ item = null;
+ width = 18;
+ height = 18;
+ gui.addElement(this);
+ }
+
+ public GT_GuiFakeItemButton setItem(ItemStack i) {
+ item = i;
+ return this;
+ }
+
+ public ItemStack getItem(){
+ return item;
+ }
+
+ @Override
+ public void onInit() {
+ xPosition = x0 + gui.getGuiLeft();
+ yPosition = y0 + gui.getGuiTop();
+ }
+
+ @Override
+ public void draw(int mouseX, int mouseY, float parTicks) {
+ GL11.glColor4f(1, 1, 1, 1);
+ GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
+ GL11.glEnable(GL11.GL_BLEND);
+ GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
+
+ if (bgIcon != null){
+ GT_GuiIcon.render(bgIcon, xPosition-1, yPosition-1, 18, 18,0,true);
+ }
+
+ if (item != null)
+ gui.getItemRenderer().renderItemAndEffectIntoGUI(gui.getFontRenderer(), Minecraft.getMinecraft().getTextureManager(), item, xPosition, yPosition);
+
+ GL11.glPopAttrib();
+ }
+
+ public Rectangle getBounds() {
+ return new Rectangle(x0, y0, width, height);
+ }
+}
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java
new file mode 100644
index 0000000000..1c31462e62
--- /dev/null
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java
@@ -0,0 +1,77 @@
+package gregtech.api.gui.widgets;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.util.ResourceLocation;
+
+public enum GT_GuiIcon {
+ BUTTON_NORMAL (0, 0, 0),
+ BUTTON_DOWN (0, 32, 0),
+ BUTTON_HIGHLIGHT (0, 32*2, 0),
+ BUTTON_HIGHLIGHT_DOWN (0, 32*3, 0),
+ BUTTON_DISABLED (0, 32*4, 0),
+
+ DISABLE (0, 0, 32),
+ REDSTONE_OFF (0, 32, 32),
+ REDSTONE_ON (0, 32*2, 32),
+ CHECKMARK (0, 32*3, 32),
+ CROSS (0, 32*4, 32),
+ WHITELIST (0, 32*5, 32),
+ BLACKLIST (0, 32*6, 32),
+
+ EXPORT (0, 0, 32*2),
+ IMPORT (0, 32, 32*2),
+ ALLOW_INPUT (0, 32*2, 32*2),
+ BLOCK_INPUT (0, 32*3, 32*2),
+
+ SLOT_DARKGRAY (1, 176,0,18,18),
+ SLOT_GRAY (1, 176,18,18,18);
+
+ private static final int T_SIZE = 256;
+ private static final ResourceLocation[] TEXTURES = {
+ new ResourceLocation("gregtech", "textures/gui/GuiButtons.png"),
+ new ResourceLocation("gregtech", "textures/gui/GuiCover.png")
+ };
+
+ public final int x, y, width, height;
+ public final GT_GuiIcon overlay;
+ private final int texID;
+
+ GT_GuiIcon(int texID, int x, int y, int width, int height, GT_GuiIcon overlay) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ this.overlay = overlay;
+ this.texID = texID;
+ }
+
+ GT_GuiIcon(int texID, int x, int y) {
+ this(texID, x, y,32,32,null);
+ }
+ GT_GuiIcon(int texID, int x, int y, int width, int height) {
+ this(texID, x, y, width, height,null);
+ }
+
+ public static void render(GT_GuiIcon icon, double x, double y, double width, double height, double zLevel, boolean doDraw) {
+ Tessellator tess = Tessellator.instance;
+ if (doDraw) {
+ Minecraft.getMinecraft().renderEngine.bindTexture(TEXTURES[icon.texID]);
+ tess.startDrawingQuads();
+ }
+ double minU = (double) icon.x / T_SIZE;
+ double maxU = (double) (icon.x + icon.width) / T_SIZE;
+ double minV = (double) icon.y / T_SIZE;
+ double maxV = (double) (icon.y + icon.height) / T_SIZE;
+ tess.addVertexWithUV(x, y + height, zLevel, minU, maxV);
+ tess.addVertexWithUV(x + width, y + height, zLevel, maxU, maxV);
+ tess.addVertexWithUV(x + width, y + 0, zLevel, maxU, minV);
+ tess.addVertexWithUV(x, y + 0, zLevel, minU, minV);
+
+ if (icon.overlay != null)
+ render(icon.overlay, x, y, width, height, zLevel, false);
+
+ if (doDraw)
+ tess.draw();
+ }
+}
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java
new file mode 100644
index 0000000000..f68962f58f
--- /dev/null
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java
@@ -0,0 +1,111 @@
+package gregtech.api.gui.widgets;
+
+import gregtech.api.interfaces.IGuiScreen;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiButton;
+import org.lwjgl.opengl.GL11;
+import java.awt.Rectangle;
+
+public class GT_GuiIconButton extends GuiButton implements IGuiScreen.IGuiElement {
+ public static final int DEFAULT_WIDTH = 16;
+ public static final int DEFAULT_HEIGHT = 16;
+
+ protected GT_GuiIcon icon;
+ private int x0, y0;
+ private IGuiScreen gui;
+ private String[] tooltipText;
+
+ private GT_GuiTooltip tooltip;
+
+
+ public GT_GuiIconButton(IGuiScreen gui, int id, int x, int y, GT_GuiIcon icon) {
+ super(id, x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, "");
+ this.gui = gui;
+ this.icon = icon;
+ this.x0 = x;
+ this.y0 = y;
+ gui.addElement(this);
+ }
+
+ public void onInit() {
+ if (tooltip != null)
+ gui.addToolTip(tooltip);
+ xPosition = x0 + gui.getGuiLeft();
+ yPosition = y0 + gui.getGuiTop();
+ }
+
+ @Override
+ public void draw(int mouseX, int mouseY, float parTicks) {
+ drawButton(Minecraft.getMinecraft(), mouseX, mouseY);
+ }
+
+ public void drawButton(Minecraft mc, int mouseX, int mouseY) {
+ if (this.tooltip != null)
+ this.tooltip.enabled = true;
+
+ if (this.visible) {
+ //moused over
+ this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + width && mouseY < this.yPosition + height;
+
+ mouseDragged(mc, mouseX, mouseY);
+
+ GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
+ GL11.glEnable(GL11.GL_BLEND);
+ GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
+
+ int x = xPosition;
+ int y = yPosition;
+ if(!this.field_146123_n) {
+ GL11.glColor4f(200F/255F, 210F/255F, 1, 1);
+ }
+ else
+ GL11.glColor4f(1, 1, 1, 1);
+
+ GT_GuiIcon.render(getButtonTexture(this.field_146123_n), x, y, width, height, 0, true);
+
+ GL11.glColor4f(1, 1, 1, 1);
+ if (icon != null) {
+ GT_GuiIcon.render(icon, x, y, width, height , 0, true);
+ }
+
+ GL11.glPopAttrib();
+ }
+ }
+
+ @Override
+ public void mouseReleased(int mouseX, int mouseY) {
+ this.gui.clearSelectedButton();
+ if(mousePressed(Minecraft.getMinecraft(), mouseX, mouseY))
+ this.gui.buttonClicked(this);
+ }
+
+ public GT_GuiIcon getButtonTexture(boolean mouseOver) {
+ if (!enabled)
+ return GT_GuiIcon.BUTTON_DISABLED;
+ if (this.equals(this.gui.getSelectedButton()))
+ return mouseOver ? GT_GuiIcon.BUTTON_HIGHLIGHT_DOWN : GT_GuiIcon.BUTTON_DOWN;
+ else
+ return mouseOver ? GT_GuiIcon.BUTTON_HIGHLIGHT : GT_GuiIcon.BUTTON_NORMAL;
+ }
+
+ public GT_GuiIcon getIcon() {
+ return icon;
+ }
+
+ public GT_GuiTooltip getTooltip() {
+ return tooltip;
+ }
+
+ public GT_GuiIconButton setTooltipText(String... text) {
+ if (tooltip == null)
+ tooltip = new GT_GuiTooltip(getBounds(), text);
+ else
+ tooltip.setToolTipText(text);
+ this.tooltipText = text;
+ return this;
+ }
+
+ public Rectangle getBounds() {
+ return new Rectangle(x0, y0, width, height);
+ }
+}
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIntegerTextBox.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIntegerTextBox.java
new file mode 100644
index 0000000000..3f6fe64e73
--- /dev/null
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIntegerTextBox.java
@@ -0,0 +1,50 @@
+package gregtech.api.gui.widgets;
+
+import gregtech.api.interfaces.IGuiScreen;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiTextField;
+
+import java.awt.*;
+
+public class GT_GuiIntegerTextBox extends GuiTextField implements IGuiScreen.IGuiElement {
+ private final int x0, y0;
+ private final IGuiScreen gui;
+ public final int id;
+
+ public GT_GuiIntegerTextBox(IGuiScreen gui, int id, int x, int y, int width, int height) {
+ super(Minecraft.getMinecraft().fontRenderer, x, y, width, height);
+ super.setText("");
+ this.id = id;
+ x0 = x;
+ y0 = y;
+ this.gui = gui;
+ gui.addElement(this);
+ }
+
+ @Override
+ public void onInit() {
+ xPosition = x0 + gui.getGuiLeft();
+ yPosition = y0 + gui.getGuiTop();
+ }
+
+ @Override
+ public void draw(int mouseX, int mouseY, float parTicks) {
+ super.drawTextBox();
+ }
+
+ public Rectangle getBounds() {
+ return new Rectangle(x0, y0, width, height);
+ }
+
+ public boolean validChar(char c, int key) {
+ return Character.isDigit(c);
+ }
+
+ @Override
+ public boolean textboxKeyTyped(char c, int key) {
+ if (validChar(c, key) || c == 1 || c == 3 || c == 22 || c == 24 || key == 14 || key == 199 || key == 203 || key == 205 || key == 207 || key == 211) {
+ return super.textboxKeyTyped(c, key);
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java
new file mode 100644
index 0000000000..d24437f018
--- /dev/null
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java
@@ -0,0 +1,37 @@
+package gregtech.api.gui.widgets;
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+
+public class GT_GuiTooltip {
+
+ protected Rectangle bounds;
+ private List<String> text;
+ public boolean enabled = true;
+
+ public GT_GuiTooltip(Rectangle bounds, String... text) {
+ this.bounds = bounds;
+ setToolTipText(text);
+ }
+
+ protected void updateText() {
+ }
+
+ public void setToolTipText(String... text) {
+ if (text != null) {
+ this.text = new ArrayList<>(text.length);
+ for (int i = 0; i < text.length; i++) {
+ if (i == 0)
+ this.text.add("\u00a7f" + text[i]);
+ else
+ this.text.add("\u00a77" + text[i]);
+ }
+ } else
+ this.text = new ArrayList<>();
+ }
+
+ public List<String> getToolTipText() {
+ return text;
+ }
+}
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiTooltipManager.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiTooltipManager.java
new file mode 100644
index 0000000000..d0e6964abc
--- /dev/null
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiTooltipManager.java
@@ -0,0 +1,71 @@
+package gregtech.api.gui.widgets;
+
+import net.minecraft.client.gui.FontRenderer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class GT_GuiTooltipManager {
+ public interface GT_IToolTipRenderer {
+ int getGuiLeft();
+ int getGuiTop();
+ int getXSize();
+ FontRenderer getFontRenderer();
+ void drawHoveringText(List<String> par1List, int par2, int par3, FontRenderer font);
+ }
+
+ private static final long DELAY = 5;
+ private int mouseStopped;
+ private int lastMouseX = -1;
+ private int lastMouseY = -1;
+ private final List<GT_GuiTooltip> tips = new ArrayList<>();
+
+ public void addToolTip(GT_GuiTooltip tip) {
+ if (!tips.contains(tip)) tips.add(tip);
+ }
+
+ public boolean removeToolTip(GT_GuiTooltip tip) {
+ return tips.remove(tip);
+ }
+
+ public final void onTick(GT_IToolTipRenderer render, int mouseX, int mouseY) {
+ if ((Math.abs(mouseX-lastMouseX) < 2 ) && (Math.abs(mouseY-lastMouseY) < 2 ))
+ mouseStopped = Math.min(mouseStopped+1, 50);
+ else
+ mouseStopped = 0;
+
+ lastMouseX = mouseX;
+ lastMouseY = mouseY;
+
+ if (mouseStopped > DELAY)
+ mouseX -= render.getGuiLeft();
+ mouseY -= render.getGuiTop();
+ for (GT_GuiTooltip tip : tips) {
+ if(tip.enabled && tip.bounds.contains(mouseX, mouseY)){
+ tip.updateText();
+ drawTooltip(tip, mouseX, mouseY, render);
+ break;
+ }
+ }
+ }
+
+ private void drawTooltip(GT_GuiTooltip tip, int mouseX, int mouseY, GT_IToolTipRenderer render) {
+ List<String> text = tip.getToolTipText();
+ if (text == null)
+ return;
+
+ if (mouseX > render.getGuiLeft() + render.getXSize()/2) {
+ int maxWidth = 0;
+ for (String s : text) {
+ int w = render.getFontRenderer().getStringWidth(s);
+ if (w > maxWidth) {
+ maxWidth = w;
+ }
+ }
+ mouseX -= (maxWidth + 18);
+ }
+
+ render.drawHoveringText(text, mouseX, mouseY, render.getFontRenderer());
+ }
+
+}