I'm having some problems with my GUIs in Minecraft Comes Alive.
I'm making a GUI that will behave like an installer does. Press next to go to the next page and back to go back to the previous page, etc. When I click Next and I'm on the first page, it goes to the second page. But when I click Next and I'm on the second page, it registers twice and clicks the Next button on the third and final page as well, completely skipping it and starting the game. (The "Next" button on the last page closes the GUI)
If I force it to the third page, the Back buttons don't show the same behavior. If I move the Next button on the final page, it of course works fine. But I don't wanna move it.
I've noticed it does this with some other GUIs in MCA as well.
Page 1 is Gender Select GUI.
Page 2 is Name Select GUI.
Page 3 is Options GUI.
My code is in the spoiler. Pasting made a mess of it.
package net.minecraft.src;
import org.lwjgl.input.Keyboard;
/* * * *
* Defines how the Setup GUI works.
*/
public class MCA_GuiSetup extends GuiScreen
{
private EntityPlayer entityplayer = mod_MCA.entityPlayer;
private int updateCounter;
private String selectedGender = "Male";
private String playerName = mod_MCA.entityPlayer.username;
private Boolean shouldGenerateFamily = false;
private GuiButton genderButton;
private GuiTextField nameTextField;
private Boolean containsInvalidCharacters = false;
private GuiButton generateFamilyButton;
private GuiButton backButton;
private GuiButton nextButton;
private boolean inNameSelectGUI = false;
private boolean inGenderSelectGUI = false;
private boolean inOptionsGUI = false;
/* * * *
* Constructor
*/
public MCA_GuiSetup()
{
updateCounter = 0;
}
/* * * *
* Draws the initial GUI after it is told to be shown.
*/
public void initGui()
{
controlList.clear();
drawGenderSelectGUI();
}
/* * * *
* Performs an action based on which button was pressed.
*/
protected void actionPerformed(GuiButton pressedButton)
{
if (pressedButton.equals(genderButton))
{
if (selectedGender.equals("Male"))
{
selectedGender = "Female";
}
else
{
selectedGender = "Male";
}
drawGenderSelectGUI();
}
if (pressedButton.equals(backButton))
{
if (inGenderSelectGUI)
{
return;
}
else if (inNameSelectGUI)
{
drawGenderSelectGUI();
}
else if (inOptionsGUI)
{
drawNameSelectGUI();
}
}
if (pressedButton.equals(generateFamilyButton))
{
if (shouldGenerateFamily)
{
shouldGenerateFamily = false;
}
else
{
shouldGenerateFamily = true;
}
drawOptionsGUI();
}
if (pressedButton.equals(nextButton))
{
if (inGenderSelectGUI)
{
drawNameSelectGUI();
}
else if (inNameSelectGUI)
{
drawOptionsGUI();
}
else if (inOptionsGUI)
{
mod_MCA.minecraft.displayGuiScreen(null);
}
}
}
/* * * *
* Updates the GUI screen.
*/
public void updateScreen()
{
super.updateScreen();
updateCounter++;
if (inNameSelectGUI)
{
nameTextField.updateCursorCounter();
}
}
/* * * *
* Draws everything on the GUI screen.
*/
public void drawScreen(int i, int j, float f)
{
drawDefaultBackground();
drawCenteredString(fontRenderer, "Minecraft Comes Alive Setup", width / 2, 20, 0xffffff);
if (inGenderSelectGUI)
{
drawCenteredString(fontRenderer, "Choose your gender.", width / 2, height / 2 - 80, 0xffffff);
drawCenteredString(fontRenderer, "or", width / 2 + 1, height / 2 - 10, 0xffffff);
}
if (inNameSelectGUI)
{
if (containsInvalidCharacters)
{
drawCenteredString(fontRenderer, "Your name contains invalid characters.", width / 2, (height / 2) + 20, 0xCC0000);
}
drawCenteredString(fontRenderer, "Enter your name.", width / 2, height / 2 - 80, 0xffffff);
nameTextField.drawTextBox();
}
if (inOptionsGUI)
{
drawCenteredString(fontRenderer, "Configure options.", width / 2 , height / 2 - 80, 0xffffff);
}
super.drawScreen(i, j, f);
}
/* * * *
* Called when the GUI is closed.
*/
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
}
/* * * *
* Called when a key is typed.
*/
protected void keyTyped(char c, int i)
{
nameTextField.func_50037_a(c, i);
String text = nameTextField.getText().trim();
if (text.contains("/") || text.contains("?") || text.contains("<") || text.contains(">") || text.contains("\\") || text.contains(":") || text.contains("*") || text.contains("|") || text.contains("\""))
{
containsInvalidCharacters = true;
((GuiButton)controlList.get(1)).enabled = false;
}
else
{
containsInvalidCharacters = false;
((GuiButton)controlList.get(1)).enabled = true;
}
playerName = text;
}
/* * * *
* Called when the mouse is clicked when the GUI screen is open.
*/
protected void mouseClicked(int i, int j, int k)
{
super.mouseClicked(i, j, k);
if (inNameSelectGUI)
{
nameTextField.mouseClicked(i, j, k);
}
}
/* * * *
* Draws the gender selection GUI.
*/
private void drawGenderSelectGUI()
{
inNameSelectGUI = false;
inGenderSelectGUI = true;
inOptionsGUI = false;
controlList.clear();
controlList.add(genderButton = new GuiButton(3, width / 2 - 70, height / 2 + -16, 140, 20, "Gender: " + selectedGender));
controlList.add(backButton = new GuiButton(2, width / 2 - 190, height / 2 + 105 + -16, 65, 20, "Back"));
backButton.enabled = false;
controlList.add(nextButton = new GuiButton(1, width / 2 + 135, height / 2 + 105 + -16, 65, 20, "Next"));
}
/* * * *
* Draws the name selection GUI.
*/
private void drawNameSelectGUI()
{
Keyboard.enableRepeatEvents(true);
inNameSelectGUI = true;
inGenderSelectGUI = false;
inOptionsGUI = false;
controlList.clear();
nameTextField = new GuiTextField(fontRenderer, width / 2 - 100, height / 2 + -16, 200, 20);
nameTextField.setText(playerName);
controlList.add(backButton = new GuiButton(2, width / 2 - 190, height / 2 + 105 + -16, 65, 20, "Back"));
controlList.add(nextButton = new GuiButton(1, width / 2 + 135, height / 2 + 105 + -16, 65, 20, "Next"));
nextButton.enabled = !containsInvalidCharacters;
nameTextField.setMaxStringLength(32);
}
/* * * *
* Draws the options GUI.
*/
private void drawOptionsGUI()
{
inNameSelectGUI = false;
inGenderSelectGUI = false;
inOptionsGUI = true;
controlList.clear();
controlList.add(generateFamilyButton = new GuiButton(4, width / 2 - 70, height / 2 - 20 -16, 140, 20, "Generate Family: " + shouldGenerateFamily.toString()));
controlList.add(backButton = new GuiButton(2, width / 2 - 190, height / 2 + 105 + -16, 65, 20, "Back"));
controlList.add(nextButton = new GuiButton(1, width / 2 + 135, height / 2 + 105 + -16, 65, 20, "Play"));
}
}
I had tried that before on another GUI and switching pages did not work...That's why I make multi-page GUIs like the example.
I'll give it another try though.
I'm making a GUI that will behave like an installer does. Press next to go to the next page and back to go back to the previous page, etc. When I click Next and I'm on the first page, it goes to the second page. But when I click Next and I'm on the second page, it registers twice and clicks the Next button on the third and final page as well, completely skipping it and starting the game. (The "Next" button on the last page closes the GUI)
If I force it to the third page, the Back buttons don't show the same behavior. If I move the Next button on the final page, it of course works fine. But I don't wanna move it.
I've noticed it does this with some other GUIs in MCA as well.
Page 1 is Gender Select GUI.
Page 2 is Name Select GUI.
Page 3 is Options GUI.
My code is in the spoiler. Pasting made a mess of it.
I'll give it another try though.