diff options
Diffstat (limited to 'src/main/java/gregtech/api/gui')
-rw-r--r-- | src/main/java/gregtech/api/gui/GT_GUICover.java | 153 | ||||
-rw-r--r-- | src/main/java/gregtech/api/gui/widgets/GT_GuiIntegerTextBox.java | 50 |
2 files changed, 183 insertions, 20 deletions
diff --git a/src/main/java/gregtech/api/gui/GT_GUICover.java b/src/main/java/gregtech/api/gui/GT_GUICover.java index b182f6f6d5..94346186a8 100644 --- a/src/main/java/gregtech/api/gui/GT_GUICover.java +++ b/src/main/java/gregtech/api/gui/GT_GUICover.java @@ -2,17 +2,21 @@ 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; @@ -30,14 +34,14 @@ public abstract class GT_GUICover extends GuiScreen implements GT_IToolTipRender 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() { - } - - public GT_GUICover(int width, int height, ItemStack cover) { + 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() : ""; @@ -50,17 +54,35 @@ public abstract class GT_GUICover extends GuiScreen implements GT_IToolTipRender guiTop = (this.height - this.gui_height) / 2; for (IGuiElement element : elements) { - element.onInit(); - 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(); @@ -115,26 +137,90 @@ public abstract class GT_GUICover extends GuiScreen implements GT_IToolTipRender return false; } - public void keyTyped(char p_73869_1_, int p_73869_2_) { - if (p_73869_2_ == this.mc.gameSettings.keyBindInventory.getKeyCode()) { - this.mc.displayGuiScreen((GuiScreen) null); - this.mc.setIngameFocus(); - return; - } - super.keyTyped(p_73869_1_, p_73869_2_); + public void closeScreen() { + this.mc.displayGuiScreen((GuiScreen) null); + this.mc.setIngameFocus(); } @Override - public void addElement(IGuiElement element) { - if (elements.contains(element)) + public void updateScreen() { + super.updateScreen(); + if (!tile.isUseableByPlayer(mc.thePlayer)) { + closeScreen(); return; - elements.add(element); + } + 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 boolean removeElement(IGuiElement element) { - return elements.remove(element); + 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; } @@ -148,8 +234,20 @@ public abstract class GT_GUICover extends GuiScreen implements GT_IToolTipRender } - public RenderItem getItemRenderer() { - return itemRender; + /** + * 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) { + } /** @@ -191,4 +289,19 @@ public abstract class GT_GUICover extends GuiScreen implements GT_IToolTipRender 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_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; + } +} |