Skip to content

Commit

Permalink
Fix Filter Popup Panels deleting cached panel (#2718)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude authored Feb 11, 2025
1 parent 68f6e52 commit 8e9efb7
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 25 deletions.
73 changes: 54 additions & 19 deletions src/main/java/gregtech/api/mui/GTGuis.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,47 +72,82 @@ public static ModularPanel defaultPanel(MetaItem<?>.MetaValueItem valueItem) {
return createPanel(valueItem.unlocalizedName);
}

public static ModularPanel createPopupPanel(String name, int width, int height) {
return createPopupPanel(name, width, height, false, false);
public static PopupPanel createPopupPanel(String name, int width, int height) {
return defaultPopupPanel(name)
.size(width, height);
}

public static ModularPanel createPopupPanel(String name, int width, int height, boolean disableBelow,
boolean closeOnOutsideClick) {
return new PopupPanel(name, width, height, disableBelow, closeOnOutsideClick);
public static PopupPanel createPopupPanel(String name, int width, int height, boolean deleteCachedPanel) {
return createPopupPanel(name, width, height)
.deleteCachedPanel(deleteCachedPanel);
}

public static ModularPanel defaultPopupPanel(String name) {
return defaultPopupPanel(name, false, false);
public static PopupPanel defaultPopupPanel(String name) {
return new PopupPanel(name)
.size(DEFAULT_WIDTH, DEFAULT_HIEGHT);
}

public static ModularPanel defaultPopupPanel(String name, boolean disableBelow,
boolean closeOnOutsideClick) {
return new PopupPanel(name, DEFAULT_WIDTH, DEFAULT_HIEGHT, disableBelow, closeOnOutsideClick);
public static PopupPanel defaultPopupPanel(String name, boolean disableBelow,
boolean closeOnOutsideClick, boolean deleteCachedPanel) {
return defaultPopupPanel(name)
.disablePanelsBelow(disableBelow)
.closeOnOutOfBoundsClick(closeOnOutsideClick)
.deleteCachedPanel(deleteCachedPanel);
}

private static class PopupPanel extends ModularPanel {
public static class PopupPanel extends ModularPanel {

private final boolean disableBelow;
private final boolean closeOnOutsideClick;
private boolean disableBelow;
private boolean closeOnOutsideClick;
private boolean deleteCachedPanel;

public PopupPanel(@NotNull String name, int width, int height, boolean disableBelow,
boolean closeOnOutsideClick) {
private PopupPanel(@NotNull String name) {
super(name);
size(width, height).align(Alignment.Center);
align(Alignment.Center);
background(GTGuiTextures.BACKGROUND_POPUP);
child(ButtonWidget.panelCloseButton().top(5).right(5)
.onMousePressed(mouseButton -> {
if (mouseButton == 0 || mouseButton == 1) {
this.closeIfOpen(true);
if (isSynced() && getSyncHandler() instanceof IPanelHandler handler) {
handler.deleteCachedPanel();
}
return true;
}
return false;
}));
}

@Override
public void onClose() {
super.onClose();
if (deleteCachedPanel && isSynced() && getSyncHandler() instanceof IPanelHandler handler) {
handler.deleteCachedPanel();
}
}

public PopupPanel disablePanelsBelow(boolean disableBelow) {
this.disableBelow = disableBelow;
return this;
}

public PopupPanel closeOnOutOfBoundsClick(boolean closeOnOutsideClick) {
this.closeOnOutsideClick = closeOnOutsideClick;
return this;
}

public PopupPanel deleteCachedPanel(boolean deleteCachedPanel) {
this.deleteCachedPanel = deleteCachedPanel;
return this;
}

@Override
public PopupPanel size(int w, int h) {
super.size(w, h);
return this;
}

@Override
public PopupPanel size(int val) {
super.size(val);
return this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ protected PanelSyncHandler.IPanelBuilder entrySelector(EntryTypes<T> type) {
for (String name : VirtualEnderRegistry.getEntryNames(getOwner(), type)) {
rows.add(createRow(name, syncManager, type));
}
return GTGuis.createPopupPanel("entry_selector", 168, 112)
return GTGuis.createPopupPanel("entry_selector", 168, 112, true)
.child(IKey.lang("cover.generic.ender.known_channels")
.color(UI_TITLE_COLOR)
.asWidget()
Expand All @@ -310,7 +310,7 @@ protected PanelSyncHandler.IPanelBuilder entrySelector(EntryTypes<T> type) {
protected PanelSyncHandler.IPanelBuilder entryDescription(String key, T entry) {
return (syncManager, syncHandler) -> {
var sync = new StringSyncValue(entry::getDescription, entry::setDescription);
return GTGuis.createPopupPanel(key, 168, 36 + 6)
return GTGuis.createPopupPanel(key, 168, 36 + 6, true)
.child(IKey.lang("cover.generic.ender.set_description.title", entry.getColorStr())
.color(UI_TITLE_COLOR)
.asWidget()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void initUI(Consumer<gregtech.api.gui.Widget> widgetGroup) {}

@Override
public @NotNull ModularPanel createPopupPanel(PanelSyncManager syncManager) {
return GTGuis.createPopupPanel("ore_dict_filter", 188, 76)
return GTGuis.createPopupPanel("ore_dict_filter", 188, 76, false)
.padding(7)
.child(CoverWithUI.createTitleRow(getContainerStack()))
.child(createWidgets(syncManager).top(22));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void configureFilterTanks(int amount) {

@Override
public @NotNull ModularPanel createPopupPanel(PanelSyncManager syncManager) {
return GTGuis.createPopupPanel("simple_fluid_filter", 98, 81)
return GTGuis.createPopupPanel("simple_fluid_filter", 98, 81, false)
.padding(4)
.child(CoverWithUI.createTitleRow(getContainerStack()))
.child(createWidgets(syncManager).top(22));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void initUI(Consumer<gregtech.api.gui.Widget> widgetGroup) {

@Override
public @NotNull ModularPanel createPopupPanel(PanelSyncManager syncManager) {
return GTGuis.createPopupPanel("simple_item_filter", 98, 81)
return GTGuis.createPopupPanel("simple_item_filter", 98, 81, false)
.child(CoverWithUI.createTitleRow(getContainerStack()))
.child(createWidgets(syncManager).top(22).left(4));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void initUI(Consumer<gregtech.api.gui.Widget> widgetGroup) {

@Override
public @NotNull ModularPanel createPopupPanel(PanelSyncManager syncManager) {
return GTGuis.createPopupPanel("smart_item_filter", 98 + 27, 81)
return GTGuis.createPopupPanel("smart_item_filter", 98 + 27, 81, false)
.child(CoverWithUI.createTitleRow(getContainerStack()))
.child(createWidgets(syncManager).top(22).left(4));
}
Expand Down

0 comments on commit 8e9efb7

Please sign in to comment.