/**
* Copyright (c) Lambda Innovation, 2013-2016
* This file is part of LambdaLib modding library.
* https://github.com/LambdaInnovation/LambdaLib
* Licensed under MIT, see project root for more information.
*/
package cn.lambdalib.cgui.gui;

import cn.lambdalib.cgui.gui.component.TextBox;
import cn.lambdalib.util.client.HudUtils;
import cn.lambdalib.util.client.font.Fonts;
import cn.lambdalib.util.client.font.IFont;
import cn.lambdalib.util.client.font.IFont.FontOption;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

/**
 * A simple wrapper for fast {@link CGui} deploy as GuiContainer.
 * @author WeAthFolD
 */
public class CGuiScreenContainer extends GuiContainer {
    
    protected CGui gui;
    
    public CGuiScreenContainer(Container c) {
        super(c);
        gui = new CGui();
    }
    
    public CGuiScreenContainer(Container c, CGui _gui) {
        super(c);
        gui = _gui;
    }
    
    public CGui getGui() {
        return gui;
    }
    
    @Override
    protected void drawGuiContainerBackgroundLayer(float var1, int var2,
            int var3) {
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

        GL11.glColor4f(0, 1, 0, 0.2f);
        HudUtils.colorRect(guiLeft, guiTop, xSize, ySize);

        double relx = gui.mouseX - guiLeft, rely = gui.mouseY - guiTop;
        IFont font = Fonts.getDefault();
        font.draw(String.format("bounds: (%d,%d,%d,%d) mouse:(%.1f,%.1f)", guiLeft, guiTop, xSize, ySize, relx, rely),
                2, 2, new FontOption(10));

        gui.resize(width, height);
        gui.draw(var2, var3);
    }
    
    @Override
    public void drawScreen(int a, int b, float c) {
        if(isSlotActive()) {
            super.drawScreen(a, b, c);
        } else {
            gui.resize(width, height);
            this.drawDefaultBackground();
            gui.draw(a, b);
        }
    }

    @Override
    protected void mouseClicked(int par1, int par2, int par3) {
        if(isSlotActive()) super.mouseClicked(par1, par2, par3);
        gui.mouseClicked(par1, par2, par3);
    }
    
    @Override
    protected void mouseClickMove(int mx, int my, int btn, long time) {
        if(isSlotActive()) super.mouseClickMove(mx, my, btn, time);
        gui.mouseClickMove(mx, my, btn, time);
    }
    
    @Override
    public void onGuiClosed() {
        gui.dispose();
    }
    
    @Override
    protected void mouseMovedOrUp(int a, int b, int c) {
        if(isSlotActive()) {
            super.mouseMovedOrUp(a, b, c);
        }
    }
    
    @Override
    public void keyTyped(char ch, int key) {
        gui.keyTyped(ch, key);
        if(containerAcceptsKey(key) || key == Keyboard.KEY_ESCAPE)
            super.keyTyped(ch, key);
    }
    
    /**
     * @return Whether the inventory itself receives key input. (This should be disabled when you are handling some user input)
     */
    protected boolean containerAcceptsKey(int key) {
        // Don't delegate key event if current editing TextBox. Surely dirty hack, find a better route later
        TextBox temp;
        return (gui.focus == null ||
                (temp = TextBox.get(gui.focus)) == null ||
                !temp.canEdit);
    }
    
    /**
     * @return Whether inventory slots should be renderered this frame.
     */
    public boolean isSlotActive() {
        return true;
    }
}

@@ -1,12 +1,13 @@
 /**%0A
+ 
 * Copyri
@@ -43,16 +43,17 @@
 13-2016%0A
+ 
 * This f
@@ -94,16 +94,17 @@
 ibrary.%0A
+ 
 * https:
@@ -143,16 +143,17 @@
 mbdaLib%0A
+ 
 * Licens
@@ -205,16 +205,17 @@
 mation.%0A
+ 
 */%0Apacka
@@ -293,193 +293,8 @@
 ox;%0A
-import cn.lambdalib.util.client.HudUtils;%0Aimport cn.lambdalib.util.client.font.Fonts;%0Aimport cn.lambdalib.util.client.font.IFont;%0Aimport cn.lambdalib.util.client.font.IFont.FontOption;%0A
 impo
@@ -603,20 +603,16 @@
 ainer %7B%0A
-    
 %0A    pro
@@ -628,20 +628,16 @@
 ui gui;%0A
-    
 %0A    pub
@@ -717,36 +717,32 @@
 w CGui();%0A    %7D%0A
-    
 %0A    public CGui
@@ -823,28 +823,24 @@
 _gui;%0A    %7D%0A
-    
 %0A    public 
@@ -873,36 +873,32 @@
 turn gui;%0A    %7D%0A
-    
 %0A    @Override%0A 
@@ -969,16 +969,55 @@
 t var2,%0A
+                                       
         
@@ -1148,384 +1148,8 @@
 A);%0A
-%0A        GL11.glColor4f(0, 1, 0, 0.2f);%0A        HudUtils.colorRect(guiLeft, guiTop, xSize, ySize);%0A%0A        double relx = gui.mouseX - guiLeft, rely = gui.mouseY - guiTop;%0A        IFont font = Fonts.getDefault();%0A        font.draw(String.format(%22bounds: (%25d,%25d,%25d,%25d) mouse:(%25.1f,%25.1f)%22, guiLeft, guiTop, xSize, ySize, relx, rely),%0A                2, 2, new FontOption(10));%0A%0A
     
@@ -1207,36 +1207,32 @@
 2, var3);%0A    %7D%0A
-    
 %0A    @Override%0A 
@@ -1678,36 +1678,32 @@
 2, par3);%0A    %7D%0A
-    
 %0A    @Override%0A 
@@ -1886,36 +1886,32 @@
 n, time);%0A    %7D%0A
-    
 %0A    @Override%0A 
@@ -1966,28 +1966,24 @@
 se();%0A    %7D%0A
-    
 %0A    @Overri
@@ -2126,28 +2126,24 @@
     %7D%0A    %7D%0A
-    
 %0A    @Overri
@@ -2323,36 +2323,32 @@
 ch, key);%0A    %7D%0A
-    
 %0A    /**%0A     * 
@@ -2794,20 +2794,16 @@
 ;%0A    %7D%0A
-    
 %0A    /**

Revert changes for CGUIScreenContainer