package org.cyclops.cyclopscore.client.gui.component.input;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.renderer.GlStateManager;
import org.cyclops.cyclopscore.client.gui.image.Images;

/**
 * An extended text field.
 * @author rubensworks
 */
public class GuiTextFieldExtended extends GuiTextField {

    private final boolean background;
    private IInputListener listener;

    public GuiTextFieldExtended(int componentId, FontRenderer fontrenderer, int x, int y, int width, int height, boolean background) {
        super(componentId, fontrenderer, x, y, width, height);
        this.background = background;
    }

    public void setListener(IInputListener listener) {
        this.listener = listener;
    }

    protected void drawBackground(Minecraft minecraft, int mouseX, int mouseY) {
        minecraft.renderEngine.bindTexture(Images.WIDGETS);
        GlStateManager.color(1, 1, 1, 1);

        x--;
        y--;
        drawTexturedModalRect(x, y, 0, 0, width / 2, height / 2);//top left
        drawTexturedModalRect(x + width / 2, y, 200 - width / 2, 0, width / 2, height / 2);//top right
        drawTexturedModalRect(x, y + height / 2, 0, 20 - height / 2, width / 2, height / 2);//bottom left
        drawTexturedModalRect(x + width / 2, y + height / 2, 200 - width / 2, 20 - height / 2, width / 2, height / 2);//bottom right
        x++;
        y++;
    }

    @Override
    public void setText(String value) {
        super.setText(value);
        if(listener != null) listener.onChanged();
    }

    /**
     * Draw the text box with mouse sensitive parameters.
     * @param minecraft Minecraft instance.
     * @param mouseX Mouse X
     * @param mouseY Mouse Y
     */
    public void drawTextBox(Minecraft minecraft, int mouseX, int mouseY) {
        if(background) {
            drawBackground(minecraft, mouseX, mouseY);
        }
        super.drawTextBox();
    }

    @Deprecated
    public void drawTextBox() {
        super.drawTextBox();
    }

}

@@ -726,24 +726,215 @@
 und;%0A    %7D%0A%0A
+    public GuiTextFieldExtended(int componentId, FontRenderer fontrenderer, int x, int y, int width, int height) %7B%0A        this(componentId, fontrenderer, x, y, width, height, false);%0A    %7D%0A%0A
     public v
@@ -2281,10 +2281,361 @@
 %0A    %7D%0A%0A
+    @Override%0A    public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) %7B%0A        if (mouseButton == 1) %7B%0A            // Select everything%0A            this.setCursorPosition(0);%0A            this.setSelectionPos(Integer.MAX_VALUE);%0A            return true;%0A        %7D%0A        return super.mouseClicked(mouseX, mouseY, mouseButton);%0A    %7D%0A
 %7D%0A

Allow text fields to become fully selected on right-click