Jump to content

[1.7.10] Text box switches to NEI search box every few seconds


Recommended Posts

Posted

In my modding environment I've got NEI (Not Enough Items) installed, but when I try to type in a text box in my GUI, it switches over to the NEI one every few seconds and types in both ones; how can I prevent this?

 

This is my code for the text box so far:

public void initGui(){
	super.initGui();
	inputText = new GuiTextField(fontRendererObj, guiTop + 10, guiLeft + 10, 80, 12);
	inputText.setFocused(true);
	inputText.setCanLoseFocus(false);
	inputText.setMaxStringLength(40);
}


@Override
public void keyTyped(char c, int i){
	super.keyTyped(c, i);
	if(inputText.isFocused()){
		inputText.textboxKeyTyped(c, i);
	}
}

public void mouseClicked(int i, int j, int k){
	super.mouseClicked(i, j, k);
	if(inputText.isFocused())
		inputText.mouseClicked(i, j, k);
}

protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
	Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
	drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
	inputText.drawTextBox();
}

 

Also, when pressing like e.g. 'E', it exits out of the inventory; of course, one solution to this would be something like

if(i != Keyboard.KEY_E) super.keyTyped(c, i)

but is there a better way?

Posted

You just need to check if the text field is focused and if this is true, you have to check if the char is in the valid pools. If it's not focused, you have to call super.keyTyped(c, keyCode).

 

Here's an example how I did it: (tfFrequency is a Number-only textfield. 48 - 57 are the numbers from 0-9 and 8 is Backspace/Delete and 43,45 are +/-

 

 

@Override
    protected void keyTyped(char c, int keyCode)
    {
        if(tfFrequency.isFocused() && (c>=48 && c<=57 || c==8 || c==45 || c==43))
        {
            tfFrequency.textboxKeyTyped(c,keyCode);
        }
        else if(!tfName.isFocused())
        {
            super.keyTyped(c,keyCode);
        }
    }

 

 

 

I hope it helps,

Julian

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.