diff --git a/src/main/java/com/glodblock/github/client/gui/GuiInterfaceWireless.java b/src/main/java/com/glodblock/github/client/gui/GuiInterfaceWireless.java index 65ff62eb2..5f3968ed5 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiInterfaceWireless.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiInterfaceWireless.java @@ -321,7 +321,7 @@ protected void actionPerformed(final GuiButton btn) { if (btn == this.terminalStyleBox) { AEConfig.instance.settings.putSetting(iBtn.getSetting(), next); - initGui(); + super.scheduleGuiResize(); } else if (btn == searchStringSave) { AEConfig.instance.preserveSearchBar = next == YesNo.YES; } diff --git a/src/main/java/com/glodblock/github/client/gui/GuiLevelTerminal.java b/src/main/java/com/glodblock/github/client/gui/GuiLevelTerminal.java index f7ea91f56..c298c9fa7 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiLevelTerminal.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiLevelTerminal.java @@ -348,8 +348,7 @@ protected void actionPerformed(final GuiButton btn) { if (btn == terminalStyleBox) { AEConfig.instance.settings.putSetting(iBtn.getSetting(), next); - - reinitialize(); + super.scheduleGuiResize(); } iBtn.set(next); @@ -358,11 +357,6 @@ protected void actionPerformed(final GuiButton btn) { super.actionPerformed(btn); } - private void reinitialize() { - buttonList.clear(); - initGui(); - } - @Override public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { mc.getTextureManager().bindTexture(TEX_BG); diff --git a/src/main/java/com/glodblock/github/client/gui/base/FCBaseMEGui.java b/src/main/java/com/glodblock/github/client/gui/base/FCBaseMEGui.java index 90f29f01f..0b0c8b254 100644 --- a/src/main/java/com/glodblock/github/client/gui/base/FCBaseMEGui.java +++ b/src/main/java/com/glodblock/github/client/gui/base/FCBaseMEGui.java @@ -137,6 +137,28 @@ protected void addSwitchGuiBtns() { this.buttonList.addAll(termBtns); } + private boolean scheduleGuiResize; + + @Override + protected void mouseClicked(int xCoord, int yCoord, int btn) { + super.mouseClicked(xCoord, yCoord, btn); + if (scheduleGuiResize) { + // in the GuiScreen class, the implementation of super.mouseClicked + // ends up looping on the button list and execute the action for any + // button below the mouse. + // Therefore, if we initGui() the terminal in the actionPerformed method below + // it will run the actionPerformed a second time for the new button + // that will end up being below the mouse (if any) after the initGui() + buttonList.clear(); + initGui(); + scheduleGuiResize = false; + } + } + + protected final void scheduleGuiResize() { + scheduleGuiResize = true; + } + @Override protected void actionPerformed(final GuiButton btn) { if (btn instanceof GuiFCImgButton) { diff --git a/src/main/java/com/glodblock/github/client/gui/base/FCGuiMonitor.java b/src/main/java/com/glodblock/github/client/gui/base/FCGuiMonitor.java index 131b97b9d..c25960bc7 100644 --- a/src/main/java/com/glodblock/github/client/gui/base/FCGuiMonitor.java +++ b/src/main/java/com/glodblock/github/client/gui/base/FCGuiMonitor.java @@ -103,7 +103,6 @@ public abstract class FCGuiMonitor> extends FCBaseMEGui protected GuiImgButton searchStringSave; protected GuiImgButton typeFilter; protected boolean hasShiftKeyDown = false; - private boolean reInitializationRequested = false; @SuppressWarnings("unchecked") public FCGuiMonitor(final InventoryPlayer inventoryPlayer, final ITerminalHost te, final FCContainerMonitor c) { @@ -163,17 +162,13 @@ protected void actionPerformed(final GuiButton btn) { iBtn.set(next); if (next.getClass() == SearchBoxMode.class || next.getClass() == TerminalStyle.class) { memoryText = this.searchField.getText(); - this.reInitalize(); + super.scheduleGuiResize(); } } } super.actionPerformed(btn); } - protected void reInitalize() { - reInitializationRequested = true; - } - @Override @SuppressWarnings("unchecked") public void initGui() { @@ -670,11 +665,6 @@ protected void keyTyped(final char character, final int key) { @Override public void updateScreen() { - if (reInitializationRequested) { - reInitializationRequested = false; - this.buttonList.clear(); - this.initGui(); - } this.repo.setPowered(this.monitorableContainer.isPowered()); super.updateScreen(); }