Skip to content

Commit

Permalink
fix changing size of the interface terminal switching to a different …
Browse files Browse the repository at this point in the history
…GUI entirely (#242)
  • Loading branch information
Alexdoru authored Nov 17, 2024
1 parent 8a37e08 commit adc2a1f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> 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<T> c) {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit adc2a1f

Please sign in to comment.