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

Cover Overlay UIs #2658

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
29 changes: 29 additions & 0 deletions src/main/java/gregtech/api/cover/CoverWithUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gregtech.api.gui.ModularUI;
import gregtech.api.mui.GTGuiTextures;
import gregtech.api.mui.GTGuiTheme;
import gregtech.api.mui.GTGuis;
import gregtech.api.mui.GregTechGuiScreen;
import gregtech.api.mui.factory.CoverGuiFactory;

Expand All @@ -17,6 +18,7 @@
import com.cleanroommc.modularui.api.IGuiHolder;
import com.cleanroommc.modularui.api.drawable.IDrawable;
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.api.widget.IWidget;
import com.cleanroommc.modularui.drawable.ItemDrawable;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
Expand All @@ -32,6 +34,8 @@
import com.cleanroommc.modularui.widgets.ToggleButton;
import com.cleanroommc.modularui.widgets.layout.Flow;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface CoverWithUI extends Cover, IUIHolder, IGuiHolder<SidedPosGuiData> {

Expand Down Expand Up @@ -66,9 +70,34 @@ default GTGuiTheme getUITheme() {

@Override
default ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncManager) {
var w = createUI(guiData, guiSyncManager);
return confgurePanel(GTGuis.defaultPanel(getPickItem()), false)
.childIf(w != null, w)
.child(createTitleRow(getPickItem()).pos(5, 5))
.bindPlayerInventory();
}

default ModularPanel confgurePanel(ModularPanel panel, boolean isSmallGui) {
return panel;
}

default @NotNull ModularPanel getSmallGUI(@NotNull SidedPosGuiData guiData,
@NotNull PanelSyncManager guiSyncManager) {
var w = createUI(guiData, guiSyncManager);
return confgurePanel(GTGuis.defaultPopupPanel(getPickItem().getTranslationKey()), true)
.childIf(w != null, w)
.child(createTitleRow(getPickItem()).pos(5, 5));
}

default @Nullable IWidget createUI(SidedPosGuiData data, PanelSyncManager manager) {
return null;
}

default boolean shouldShowSmallUI() {
// Check buildUI is not null?
return usesMui2();
}

@Override
default boolean isValid() {
return getCoverableView().isValid();
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/gregtech/common/covers/CoverConveyor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import gregtech.api.cover.CoverWithUI;
import gregtech.api.cover.CoverableView;
import gregtech.api.mui.GTGuiTextures;
import gregtech.api.mui.GTGuis;
import gregtech.api.util.GTTransferUtils;
import gregtech.api.util.ItemStackHashStrategy;
import gregtech.client.renderer.texture.Textures;
Expand Down Expand Up @@ -45,7 +44,6 @@
import com.cleanroommc.modularui.api.drawable.IDrawable;
import com.cleanroommc.modularui.api.widget.Interactable;
import com.cleanroommc.modularui.drawable.DynamicDrawable;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.utils.Color;
Expand Down Expand Up @@ -504,17 +502,13 @@ public boolean usesMui2() {
}

@Override
public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncManager) {
var panel = GTGuis.createPanel(this, 176, 192 + 18);
public ModularPanel confgurePanel(ModularPanel panel, boolean isSmallGui) {
return panel.height(210);
}

public @NotNull ParentWidget<?> createUI(SidedPosGuiData data, PanelSyncManager guiSyncManager) {
getItemFilterContainer().setMaxTransferSize(getMaxStackSize());

return panel.child(CoverWithUI.createTitleRow(getPickItem()))
.child(createUI(guiData, guiSyncManager))
.bindPlayerInventory();
}

protected ParentWidget<Flow> createUI(GuiData data, PanelSyncManager guiSyncManager) {
var column = Flow.column().top(24).margin(7, 0)
.widthRel(1f).coverChildrenHeight();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import net.minecraftforge.fml.relauncher.SideOnly;

import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.utils.Color;
Expand Down Expand Up @@ -243,12 +242,12 @@ private boolean shouldDisplayAmountSlider() {
}

@Override
public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncManager) {
return super.buildUI(guiData, guiSyncManager).height(192 + 36);
public ModularPanel confgurePanel(ModularPanel panel, boolean isSmallGui) {
return panel.height(228);
}

@Override
protected ParentWidget<?> createUI(GuiData data, PanelSyncManager syncManager) {
public @NotNull ParentWidget<?> createUI(SidedPosGuiData data, PanelSyncManager syncManager) {
var transferMode = new EnumSyncValue<>(TransferMode.class, this::getTransferMode, this::setTransferMode);
transferMode.updateCacheFromSource(true);
syncManager.syncValue("transfer_mode", transferMode);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/gregtech/common/covers/CoverFluidVoiding.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.utils.Color;
Expand Down Expand Up @@ -72,12 +71,12 @@ public void renderCover(@NotNull CCRenderState renderState, @NotNull Matrix4 tra
}

@Override
public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncManager) {
return super.buildUI(guiData, guiSyncManager).height(192 - 22);
public ModularPanel confgurePanel(ModularPanel panel, boolean isSmallGui) {
return panel.height(170);
}

@Override
protected ParentWidget<?> createUI(GuiData data, PanelSyncManager syncManager) {
public @NotNull ParentWidget<?> createUI(SidedPosGuiData data, PanelSyncManager syncManager) {
var isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);

return super.createUI(data, syncManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.utils.Color;
Expand Down Expand Up @@ -101,12 +100,13 @@ public VoidingMode getVoidingMode() {
}

@Override
public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncManager) {
return super.buildUI(guiData, guiSyncManager).height(192 + 20);
public ModularPanel confgurePanel(ModularPanel panel, boolean isSmallGui) {
return super.confgurePanel(panel, isSmallGui)
.height(212);
}

@Override
protected ParentWidget<?> createUI(GuiData data, PanelSyncManager syncManager) {
public @NotNull ParentWidget<?> createUI(SidedPosGuiData data, PanelSyncManager syncManager) {
var voidingMode = new EnumSyncValue<>(VoidingMode.class, this::getVoidingMode, this::setVoidingMode);
syncManager.syncValue("voiding_mode", voidingMode);

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/gregtech/common/covers/CoverItemVoiding.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.utils.Color;
Expand Down Expand Up @@ -73,12 +72,13 @@ void voidAny(IItemHandler myItemHandler) {
}

@Override
public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncManager) {
return super.buildUI(guiData, guiSyncManager).height(192 - 22);
public ModularPanel confgurePanel(ModularPanel panel, boolean isSmallGui) {
return super.confgurePanel(panel, isSmallGui)
.height(170);
}

@Override
protected ParentWidget<Flow> createUI(GuiData data, PanelSyncManager guiSyncManager) {
public @NotNull ParentWidget<?> createUI(SidedPosGuiData data, PanelSyncManager guiSyncManager) {
var isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);

return super.createUI(data, guiSyncManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.utils.Color;
Expand Down Expand Up @@ -89,12 +88,13 @@ protected void voidOverflow(IItemHandler myItemHandler) {
}

@Override
public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncManager) {
return super.buildUI(guiData, guiSyncManager).height(192 + 18);
public ModularPanel confgurePanel(ModularPanel panel, boolean isSmallGui) {
return super.confgurePanel(panel, isSmallGui)
.height(210);
}

@Override
protected ParentWidget<Flow> createUI(GuiData data, PanelSyncManager guiSyncManager) {
public @NotNull ParentWidget<?> createUI(SidedPosGuiData data, PanelSyncManager guiSyncManager) {
var voidingMode = new EnumSyncValue<>(VoidingMode.class, this::getVoidingMode, this::setVoidingMode);
guiSyncManager.syncValue("voiding_mode", voidingMode);

Expand Down
15 changes: 1 addition & 14 deletions src/main/java/gregtech/common/covers/CoverPump.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import gregtech.api.cover.CoverWithUI;
import gregtech.api.cover.CoverableView;
import gregtech.api.mui.GTGuiTextures;
import gregtech.api.mui.GTGuis;
import gregtech.api.util.GTTransferUtils;
import gregtech.client.renderer.texture.Textures;
import gregtech.client.renderer.texture.cube.SimpleSidedCubeRenderer;
Expand Down Expand Up @@ -43,9 +42,7 @@
import com.cleanroommc.modularui.api.drawable.IDrawable;
import com.cleanroommc.modularui.api.widget.Interactable;
import com.cleanroommc.modularui.drawable.DynamicDrawable;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.utils.Color;
import com.cleanroommc.modularui.utils.MouseData;
import com.cleanroommc.modularui.value.sync.EnumSyncValue;
Expand Down Expand Up @@ -189,18 +186,8 @@ public boolean usesMui2() {
return true;
}

@Override
public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncManager) {
var panel = GTGuis.createPanel(this, 176, 192);

public @NotNull ParentWidget<?> createUI(SidedPosGuiData data, PanelSyncManager syncManager) {
getFluidFilterContainer().setMaxTransferSize(getMaxTransferRate());

return panel.child(CoverWithUI.createTitleRow(getPickItem()))
.child(createUI(guiData, guiSyncManager))
.bindPlayerInventory();
}

protected ParentWidget<?> createUI(GuiData data, PanelSyncManager syncManager) {
var manualIOmode = new EnumSyncValue<>(ManualImportExportMode.class,
this::getManualImportExportMode, this::setManualImportExportMode);

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/gregtech/common/covers/CoverRoboticArm.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.utils.Color;
Expand Down Expand Up @@ -192,12 +191,13 @@ private boolean shouldDisplayAmountSlider() {
}

@Override
public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncManager) {
return super.buildUI(guiData, guiSyncManager).height(192 + 36 + 18 + 2);
public ModularPanel confgurePanel(ModularPanel panel, boolean isSmallGui) {
return super.confgurePanel(panel, isSmallGui)
.height(248);
}

@Override
protected ParentWidget<Flow> createUI(GuiData data, PanelSyncManager guiSyncManager) {
public @NotNull ParentWidget<?> createUI(SidedPosGuiData data, PanelSyncManager guiSyncManager) {
EnumSyncValue<TransferMode> transferMode = new EnumSyncValue<>(TransferMode.class, this::getTransferMode,
this::setTransferMode);
guiSyncManager.syncValue("transfer_mode", transferMode);
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/gregtech/common/covers/CoverStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import gregtech.api.cover.CoverDefinition;
import gregtech.api.cover.CoverWithUI;
import gregtech.api.cover.CoverableView;
import gregtech.api.mui.GTGuis;
import gregtech.client.renderer.texture.Textures;

import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -22,16 +21,17 @@
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.api.widget.IWidget;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
import com.cleanroommc.modularui.value.sync.SyncHandlers;
import com.cleanroommc.modularui.widget.ParentWidget;
import com.cleanroommc.modularui.widgets.ItemSlot;
import com.cleanroommc.modularui.widgets.layout.Grid;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -88,24 +88,24 @@ public boolean usesMui2() {
}

@Override
public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncManager) {
guiSyncManager.registerSlotGroup("item_inv", this.storageHandler.getSlots());
public ModularPanel confgurePanel(ModularPanel panel, boolean isSmallGui) {
return panel.height(MAX_HEIGHT);
}

@Override
public @Nullable ParentWidget<?> createUI(SidedPosGuiData data, PanelSyncManager manager) {
manager.registerSlotGroup("item_inv", this.storageHandler.getSlots());

int rowSize = this.storageHandler.getSlots();
List<List<IWidget>> widgets = new ArrayList<>();
widgets.add(new ArrayList<>());
List<IWidget> widgets = new ArrayList<>();
for (int i = 0; i < rowSize; i++) {
widgets.get(0)
.add(new ItemSlot().slot(SyncHandlers.itemSlot(this.storageHandler, i).slotGroup("item_inv")));
widgets.add(new ItemSlot().slot(SyncHandlers.itemSlot(this.storageHandler, i).slotGroup("item_inv")));
}
return GTGuis.createPanel(this, MAX_WIDTH, MAX_HEIGHT)
.child(IKey.lang("cover.storage.title").asWidget().pos(5, 5))
.bindPlayerInventory()
.child(new Grid()
.top((MAX_HEIGHT - SLOT_SIZE * 5) / 2).left(7).right(7).height(18)
.minElementMargin(0, 0)
.minColWidth(18).minRowHeight(18)
.matrix(widgets));
return new Grid()
.top((MAX_HEIGHT - SLOT_SIZE * 5) / 2).left(7).right(7).height(18)
.minElementMargin(0, 0)
.minColWidth(18).minRowHeight(18)
.mapTo(rowSize, widgets, (index, value) -> value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.cleanroommc.modularui.drawable.DynamicDrawable;
import com.cleanroommc.modularui.drawable.GuiTextures;
import com.cleanroommc.modularui.drawable.Rectangle;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.network.NetworkUtils;
import com.cleanroommc.modularui.screen.ModularPanel;
Expand All @@ -40,6 +39,7 @@
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
import com.cleanroommc.modularui.value.sync.StringSyncValue;
import com.cleanroommc.modularui.value.sync.SyncHandler;
import com.cleanroommc.modularui.widget.ParentWidget;
import com.cleanroommc.modularui.widgets.ButtonWidget;
import com.cleanroommc.modularui.widgets.ListWidget;
import com.cleanroommc.modularui.widgets.ToggleButton;
Expand Down Expand Up @@ -137,21 +137,16 @@ public boolean usesMui2() {
}

@Override
public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncManager) {
var panel = GTGuis.createPanel(this, 176, 192);

this.playerUUID = guiData.getPlayer().getUniqueID();

return panel.child(CoverWithUI.createTitleRow(getPickItem()))
.child(createWidgets(guiData, guiSyncManager))
.bindPlayerInventory();
public ModularPanel confgurePanel(ModularPanel panel, boolean isSmallGui) {
return panel.height(192);
}

protected Flow createWidgets(GuiData data, PanelSyncManager syncManager) {
public @NotNull ParentWidget<?> createUI(SidedPosGuiData data, PanelSyncManager manager) {
this.playerUUID = data.getPlayer().getUniqueID();
var name = new StringSyncValue(this::getColorStr, this::updateColor);

// todo unneeded cast in mui2 rc3
var entrySelectorSH = (PanelSyncHandler) syncManager.panel("entry_selector", entrySelector(getType()), true);
var entrySelectorSH = (PanelSyncHandler) manager.panel("entry_selector", entrySelector(getType()), true);

return Flow.column().coverChildrenHeight().top(24)
.margin(7, 0).widthRel(1f)
Expand Down
Loading
Loading