Skip to content

Commit ba67814

Browse files
authored
Fix subpanel SyncHandlers being cleared if the screen is just being replaced. (#153)
* Fix subpanel SyncHandlers being cleared when the screen is just being replaced * Move screen capture to the existing `GuiOpenEvent` even in `ClientScreenHandler`
1 parent 061d874 commit ba67814

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,26 @@ public class ClientScreenHandler {
7878
private static long ticks = 0L;
7979

8080
private static IMuiScreen lastMui;
81+
82+
public static boolean guiIsClosing;
8183

8284
// we need to know the actual gui and not some fake bs some other mod overwrites
8385
@SubscribeEvent(priority = EventPriority.LOWEST)
8486
public static void onGuiOpen(GuiOpenEvent event) {
87+
GuiScreen newGui = event.getGui();
88+
guiIsClosing = newGui == null;
89+
8590
defaultContext.reset();
86-
if (lastMui != null && event.getGui() == null) {
91+
if (lastMui != null && newGui == null) {
8792
if (lastMui.getScreen().getPanelManager().isOpen()) {
8893
lastMui.getScreen().getPanelManager().closeAll();
8994
}
9095
lastMui.getScreen().getPanelManager().dispose();
9196
lastMui = null;
92-
} else if (event.getGui() instanceof IMuiScreen screenWrapper) {
97+
} else if (newGui instanceof IMuiScreen screenWrapper) {
9398
if (lastMui == null) {
9499
lastMui = screenWrapper;
95-
} else if (lastMui == event.getGui()) {
100+
} else if (lastMui == newGui) {
96101
lastMui.getScreen().getPanelManager().reopen();
97102
} else {
98103
if (lastMui.getScreen().getPanelManager().isOpen()) {
@@ -103,7 +108,7 @@ public static void onGuiOpen(GuiOpenEvent event) {
103108
}
104109
}
105110

106-
if (event.getGui() instanceof IMuiScreen muiScreen) {
111+
if (newGui instanceof IMuiScreen muiScreen) {
107112
Objects.requireNonNull(muiScreen.getScreen(), "ModularScreen must not be null!");
108113
if (currentScreen != muiScreen.getScreen()) {
109114
if (hasScreen()) {
@@ -114,7 +119,7 @@ public static void onGuiOpen(GuiOpenEvent event) {
114119
currentScreen = muiScreen.getScreen();
115120
fpsCounter.reset();
116121
}
117-
} else if (hasScreen() && getMCScreen() != null && event.getGui() != getMCScreen()) {
122+
} else if (hasScreen() && getMCScreen() != null && newGui != getMCScreen()) {
118123
currentScreen.onCloseParent();
119124
currentScreen = null;
120125
lastChar = null;

src/main/java/com/cleanroommc/modularui/value/sync/ModularSyncManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.cleanroommc.modularui.value.sync;
22

33
import com.cleanroommc.modularui.ModularUI;
4+
import com.cleanroommc.modularui.screen.ClientScreenHandler;
45
import com.cleanroommc.modularui.screen.ModularContainer;
56
import com.cleanroommc.modularui.widgets.slot.SlotGroup;
67
import com.cleanroommc.bogosorter.api.ISortingContextBuilder;
@@ -61,7 +62,9 @@ public void detectAndSendChanges(boolean init) {
6162
}
6263

6364
public void onClose() {
64-
this.panelSyncManagerMap.values().forEach(PanelSyncManager::onClose);
65+
if (ClientScreenHandler.guiIsClosing) {
66+
this.panelSyncManagerMap.values().forEach(PanelSyncManager::onClose);
67+
}
6568
}
6669

6770
public void onOpen() {

0 commit comments

Comments
 (0)