Skip to content

Commit 0d7a15b

Browse files
committed
make panel handler based on stack translation key
spotless
1 parent 4302d4d commit 0d7a15b

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

src/main/java/gregtech/api/cover/CoverWithUI.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.cleanroommc.modularui.api.IGuiHolder;
1616
import com.cleanroommc.modularui.api.drawable.IDrawable;
1717
import com.cleanroommc.modularui.api.drawable.IKey;
18+
import com.cleanroommc.modularui.drawable.DynamicDrawable;
1819
import com.cleanroommc.modularui.drawable.ItemDrawable;
1920
import com.cleanroommc.modularui.factory.SidedPosGuiData;
2021
import com.cleanroommc.modularui.screen.ModularPanel;
@@ -28,10 +29,13 @@
2829
import com.cleanroommc.modularui.value.sync.IntSyncValue;
2930
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
3031
import com.cleanroommc.modularui.widget.ParentWidget;
32+
import com.cleanroommc.modularui.widget.Widget;
3133
import com.cleanroommc.modularui.widgets.ToggleButton;
3234
import com.cleanroommc.modularui.widgets.layout.Flow;
3335
import org.jetbrains.annotations.ApiStatus;
3436

37+
import java.util.function.Supplier;
38+
3539
public interface CoverWithUI extends Cover, IUIHolder, IGuiHolder<SidedPosGuiData> {
3640

3741
default void openUI(EntityPlayerMP player) {
@@ -85,11 +89,22 @@ default void markAsDirty() {
8589
* Create the Title bar widget for a Cover.
8690
*/
8791
static Flow createTitleRow(ItemStack stack) {
92+
return createTitleRow(() -> stack);
93+
}
94+
95+
/**
96+
* Create the Title bar widget for a Cover.
97+
*/
98+
static Flow createTitleRow(Supplier<ItemStack> stack) {
99+
ItemDrawable itemDrawable = new ItemDrawable();
88100
return Flow.row()
89101
.pos(4, 4)
90102
.height(16).coverChildrenWidth()
91-
.child(new ItemDrawable(stack).asWidget().size(16).marginRight(4))
92-
.child(IKey.str(stack.getDisplayName())
103+
.child(new Widget<>()
104+
.overlay(new DynamicDrawable(() -> itemDrawable.setItem(stack.get())))
105+
.size(16)
106+
.marginRight(4))
107+
.child(IKey.dynamic(() -> stack.get().getDisplayName())
93108
.color(UI_TITLE_COLOR)
94109
.asWidget().heightRel(1.0f));
95110
}

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,22 +206,23 @@ public void handleLegacyNBT(NBTTagCompound nbt) {
206206
getFilter().getFilterReader().handleLegacyNBT(nbt);
207207
}
208208

209+
public IPanelHandler getFilterHandler(PanelSyncManager syncManager) {
210+
if (hasFilter()) {
211+
return getFilter().createPanelHandler(syncManager);
212+
}
213+
return BaseFilter.ERROR_FILTER.createPanelHandler(syncManager);
214+
}
215+
209216
/** Uses Cleanroom MUI */
210217
public IWidget initUI(GuiData data, PanelSyncManager manager) {
211-
IPanelHandler panel = manager.panel("filter_panel", (syncManager, syncHandler) -> {
212-
if (hasFilter()) {
213-
return getFilter().createPopupPanel(syncManager);
214-
}
215-
return BaseFilter.ERROR_FILTER.createPopupPanel(syncManager);
216-
}, true);
217-
218218
return Flow.row().coverChildrenHeight()
219219
.marginBottom(2).widthRel(1f)
220220
.child(new ItemSlot()
221221
.slot(SyncHandlers.itemSlot(this, 0)
222222
.filter(this::isItemValid)
223223
.singletonSlotGroup(101)
224224
.changeListener((newItem, onlyAmountChanged, client, init) -> {
225+
IPanelHandler panel = getFilterHandler(manager);
225226
if (!isItemValid(newItem) || (newItem.isEmpty() && panel.isPanelOpen())) {
226227
panel.closePanel();
227228
}
@@ -234,6 +235,7 @@ public IWidget initUI(GuiData data, PanelSyncManager manager) {
234235
GTGuiTextures.FILTER_SETTINGS_OVERLAY.asIcon().size(16))
235236
.setEnabledIf(w -> hasFilter())
236237
.onMousePressed(i -> {
238+
IPanelHandler panel = getFilterHandler(manager);
237239
if (!panel.isPanelOpen()) {
238240
setMaxTransferSize(getMaxTransferSize());
239241
panel.openPanel();

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.item.ItemStack;
77
import net.minecraft.nbt.NBTTagCompound;
88

9+
import com.cleanroommc.modularui.api.IPanelHandler;
910
import com.cleanroommc.modularui.screen.ModularPanel;
1011
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
1112
import com.cleanroommc.modularui.widget.Widget;
@@ -27,6 +28,11 @@ public interface IFilter {
2728
@NotNull
2829
Widget<?> createWidgets(PanelSyncManager syncManager);
2930

31+
default IPanelHandler createPanelHandler(PanelSyncManager syncManager) {
32+
return syncManager.panel(getContainerStack().getTranslationKey(), (syncManager1, syncHandler) ->
33+
createPopupPanel(syncManager).child(createWidgets(syncManager)), true);
34+
}
35+
3036
ItemStack getContainerStack();
3137

3238
void setDirtyNotifiable(@Nullable IDirtyNotifiable dirtyNotifiable);

src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityItemCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ protected ModularUI createUI(EntityPlayer entityPlayer) {
252252
}
253253
}
254254

255-
// this.itemFilter.initUI(45 + rowSize * 18 + 5, builder::widget);
255+
// this.itemFilter.initUI(45 + rowSize * 18 + 5, builder::widget);
256256
builder.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, 7, 45 + rowSize * 18 + 105);
257257
return builder.build(getHolder(), entityPlayer);
258258
}

0 commit comments

Comments
 (0)