Skip to content

Commit 8e9efb7

Browse files
authored
Fix Filter Popup Panels deleting cached panel (GregTechCEu#2718)
1 parent 68f6e52 commit 8e9efb7

File tree

6 files changed

+60
-25
lines changed

6 files changed

+60
-25
lines changed

src/main/java/gregtech/api/mui/GTGuis.java

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,47 +72,82 @@ public static ModularPanel defaultPanel(MetaItem<?>.MetaValueItem valueItem) {
7272
return createPanel(valueItem.unlocalizedName);
7373
}
7474

75-
public static ModularPanel createPopupPanel(String name, int width, int height) {
76-
return createPopupPanel(name, width, height, false, false);
75+
public static PopupPanel createPopupPanel(String name, int width, int height) {
76+
return defaultPopupPanel(name)
77+
.size(width, height);
7778
}
7879

79-
public static ModularPanel createPopupPanel(String name, int width, int height, boolean disableBelow,
80-
boolean closeOnOutsideClick) {
81-
return new PopupPanel(name, width, height, disableBelow, closeOnOutsideClick);
80+
public static PopupPanel createPopupPanel(String name, int width, int height, boolean deleteCachedPanel) {
81+
return createPopupPanel(name, width, height)
82+
.deleteCachedPanel(deleteCachedPanel);
8283
}
8384

84-
public static ModularPanel defaultPopupPanel(String name) {
85-
return defaultPopupPanel(name, false, false);
85+
public static PopupPanel defaultPopupPanel(String name) {
86+
return new PopupPanel(name)
87+
.size(DEFAULT_WIDTH, DEFAULT_HIEGHT);
8688
}
8789

88-
public static ModularPanel defaultPopupPanel(String name, boolean disableBelow,
89-
boolean closeOnOutsideClick) {
90-
return new PopupPanel(name, DEFAULT_WIDTH, DEFAULT_HIEGHT, disableBelow, closeOnOutsideClick);
90+
public static PopupPanel defaultPopupPanel(String name, boolean disableBelow,
91+
boolean closeOnOutsideClick, boolean deleteCachedPanel) {
92+
return defaultPopupPanel(name)
93+
.disablePanelsBelow(disableBelow)
94+
.closeOnOutOfBoundsClick(closeOnOutsideClick)
95+
.deleteCachedPanel(deleteCachedPanel);
9196
}
9297

93-
private static class PopupPanel extends ModularPanel {
98+
public static class PopupPanel extends ModularPanel {
9499

95-
private final boolean disableBelow;
96-
private final boolean closeOnOutsideClick;
100+
private boolean disableBelow;
101+
private boolean closeOnOutsideClick;
102+
private boolean deleteCachedPanel;
97103

98-
public PopupPanel(@NotNull String name, int width, int height, boolean disableBelow,
99-
boolean closeOnOutsideClick) {
104+
private PopupPanel(@NotNull String name) {
100105
super(name);
101-
size(width, height).align(Alignment.Center);
106+
align(Alignment.Center);
102107
background(GTGuiTextures.BACKGROUND_POPUP);
103108
child(ButtonWidget.panelCloseButton().top(5).right(5)
104109
.onMousePressed(mouseButton -> {
105110
if (mouseButton == 0 || mouseButton == 1) {
106111
this.closeIfOpen(true);
107-
if (isSynced() && getSyncHandler() instanceof IPanelHandler handler) {
108-
handler.deleteCachedPanel();
109-
}
110112
return true;
111113
}
112114
return false;
113115
}));
116+
}
117+
118+
@Override
119+
public void onClose() {
120+
super.onClose();
121+
if (deleteCachedPanel && isSynced() && getSyncHandler() instanceof IPanelHandler handler) {
122+
handler.deleteCachedPanel();
123+
}
124+
}
125+
126+
public PopupPanel disablePanelsBelow(boolean disableBelow) {
114127
this.disableBelow = disableBelow;
128+
return this;
129+
}
130+
131+
public PopupPanel closeOnOutOfBoundsClick(boolean closeOnOutsideClick) {
115132
this.closeOnOutsideClick = closeOnOutsideClick;
133+
return this;
134+
}
135+
136+
public PopupPanel deleteCachedPanel(boolean deleteCachedPanel) {
137+
this.deleteCachedPanel = deleteCachedPanel;
138+
return this;
139+
}
140+
141+
@Override
142+
public PopupPanel size(int w, int h) {
143+
super.size(w, h);
144+
return this;
145+
}
146+
147+
@Override
148+
public PopupPanel size(int val) {
149+
super.size(val);
150+
return this;
116151
}
117152

118153
@Override

src/main/java/gregtech/common/covers/ender/CoverAbstractEnderLink.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ protected PanelSyncHandler.IPanelBuilder entrySelector(EntryTypes<T> type) {
288288
for (String name : VirtualEnderRegistry.getEntryNames(getOwner(), type)) {
289289
rows.add(createRow(name, syncManager, type));
290290
}
291-
return GTGuis.createPopupPanel("entry_selector", 168, 112)
291+
return GTGuis.createPopupPanel("entry_selector", 168, 112, true)
292292
.child(IKey.lang("cover.generic.ender.known_channels")
293293
.color(UI_TITLE_COLOR)
294294
.asWidget()
@@ -310,7 +310,7 @@ protected PanelSyncHandler.IPanelBuilder entrySelector(EntryTypes<T> type) {
310310
protected PanelSyncHandler.IPanelBuilder entryDescription(String key, T entry) {
311311
return (syncManager, syncHandler) -> {
312312
var sync = new StringSyncValue(entry::getDescription, entry::setDescription);
313-
return GTGuis.createPopupPanel(key, 168, 36 + 6)
313+
return GTGuis.createPopupPanel(key, 168, 36 + 6, true)
314314
.child(IKey.lang("cover.generic.ender.set_description.title", entry.getColorStr())
315315
.color(UI_TITLE_COLOR)
316316
.asWidget()

src/main/java/gregtech/common/covers/filter/OreDictionaryItemFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void initUI(Consumer<gregtech.api.gui.Widget> widgetGroup) {}
7575

7676
@Override
7777
public @NotNull ModularPanel createPopupPanel(PanelSyncManager syncManager) {
78-
return GTGuis.createPopupPanel("ore_dict_filter", 188, 76)
78+
return GTGuis.createPopupPanel("ore_dict_filter", 188, 76, false)
7979
.padding(7)
8080
.child(CoverWithUI.createTitleRow(getContainerStack()))
8181
.child(createWidgets(syncManager).top(22));

src/main/java/gregtech/common/covers/filter/SimpleFluidFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void configureFilterTanks(int amount) {
3939

4040
@Override
4141
public @NotNull ModularPanel createPopupPanel(PanelSyncManager syncManager) {
42-
return GTGuis.createPopupPanel("simple_fluid_filter", 98, 81)
42+
return GTGuis.createPopupPanel("simple_fluid_filter", 98, 81, false)
4343
.padding(4)
4444
.child(CoverWithUI.createTitleRow(getContainerStack()))
4545
.child(createWidgets(syncManager).top(22));

src/main/java/gregtech/common/covers/filter/SimpleItemFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void initUI(Consumer<gregtech.api.gui.Widget> widgetGroup) {
9494

9595
@Override
9696
public @NotNull ModularPanel createPopupPanel(PanelSyncManager syncManager) {
97-
return GTGuis.createPopupPanel("simple_item_filter", 98, 81)
97+
return GTGuis.createPopupPanel("simple_item_filter", 98, 81, false)
9898
.child(CoverWithUI.createTitleRow(getContainerStack()))
9999
.child(createWidgets(syncManager).top(22).left(4));
100100
}

src/main/java/gregtech/common/covers/filter/SmartItemFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void initUI(Consumer<gregtech.api.gui.Widget> widgetGroup) {
9898

9999
@Override
100100
public @NotNull ModularPanel createPopupPanel(PanelSyncManager syncManager) {
101-
return GTGuis.createPopupPanel("smart_item_filter", 98 + 27, 81)
101+
return GTGuis.createPopupPanel("smart_item_filter", 98 + 27, 81, false)
102102
.child(CoverWithUI.createTitleRow(getContainerStack()))
103103
.child(createWidgets(syncManager).top(22).left(4));
104104
}

0 commit comments

Comments
 (0)