Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Filter Popup Panels deleting cached panel #2718

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 53 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,81 @@ 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);
kumquat-ir marked this conversation as resolved.
Show resolved Hide resolved
}

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