aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java
diff options
context:
space:
mode:
authormiozune <miozune@gmail.com>2022-11-26 01:45:28 +0900
committerGitHub <noreply@github.com>2022-11-25 17:45:28 +0100
commit9a2741128a78bb52eba50a631126e090a5a2abd8 (patch)
treea90f47aa94951acb4050e45dc3ed60698e79cf32 /src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java
parent51537482fefc4f9c6d3fbd93d119c333a63dcd7b (diff)
downloadGT5-Unofficial-9a2741128a78bb52eba50a631126e090a5a2abd8.tar.gz
GT5-Unofficial-9a2741128a78bb52eba50a631126e090a5a2abd8.tar.bz2
GT5-Unofficial-9a2741128a78bb52eba50a631126e090a5a2abd8.zip
Rewrite GUIs with ModularUI (#1381)
* Base work for ModularUI compat * Remove useless interface * Add almost all the widgets * Invert method * Refactor NEI stack placement positions * NEI handlers on ModularUI * Add some more docs * AdvDebugStructureWriter * Fix NEI progressbar not working * PrimitiveBlastFurnace * clean * derp * clean * spotlessApply * Boilers * Buffers * clean * N by N slots containers * Fix boilers not having bucket interaction Put opening UI to individual MetaTEs * Maintenance Hatch * clean * spotlessApply * Add dependency * IndustrialApiary * Adapt to ModularUI change * Base work for covers & fix crash with MP * Fix crash with server * Rewrite base work for covers * Send initial cover data on cover GUI open so that the time of showing incorrect data will be eliminated * Covers part 1 * Rename package: ModularUI -> modularui * Rename class: GT_UIInfo -> GT_UIInfos * Fix build * Covers part2 * Fix missing client check with tile UI & fix title overlap * CoverTabLine * Move cover window creators to inner class * Fix crash with null base TE * Close GUI when tile is broken * Color cover window with tile colorization * Change signature of addUIWidgets * FluidFilter cover, FluidDisplaySlotWidget, BasicTank, BasicGenerator, Output Hatch, MicrowaveEnergyTransmitter, Teleporter, DigitalChest, DigitalTank * Add title tab * Move package: modularui -> modularui/widget * Programmed circuit + IConfigurationCircuitSupport * clean * VolumetricFlask * Remove integrated circuit overlay from recipe input slots * Input Hatch & Quadruple Input Hatch * Multiblock * Deprecate old cover GUI * BasicMachines * Finish BasicMachine & NEI * Expand DTPF NEI to 9 slots * Fix ME input bus on MP * Move AESlotWidget to public class * Move GT_Recipe_Map constructors with mNEIUnificateOutput to setter method * Move SteamTexture.Variant to outer enum * Switch to remote repository * oops * Update MUI * Update MUI * Minor refactor for change amount buttons * Display items and fluids that exceed usual count * blah * use +=, why didn't I do this * Update MUI * Move ModularUI to Base (#1510) * Move ModularUI to Base * Move most of the ModularUI functionality to `BaseTileEntity` (and `CoverableTileEntity`) * `CommonMetaTileEntity` delegates ato the MetaTileEntity * Added several interfaces (with defaults) to indicate if a tile/metatile override/implement certain behaviors. * Moved `IConfigurationCircuitSupport` interface such that it will work with BaseTileEntity or a MetaTileEntity * Address reviews Co-authored-by: miozune <miozune@gmail.com> * Update MUI * Minor changes to NEI * Return :facepalm: * IGetTabIconSet override * Some more changes to NEI * Merge texture getter interfaces to new class GUITextureSet * Remove BBF structure picture as it's auto-buildable now * Make unified title tab style of texture angular * Expose some boiler texture getters for addon * Fix crash with cover GUI on pipe * Lower the number of recipe per page for DTPF & update MUI * Update MUI * Fix crash with middle-clicking slot on circuit selection GUI * Fix circuit selection window not syncing item from base machine * Merge GT_NEI_AssLineHandler into GT_NEI_DefaultHandler * Update MUI * Add in TecTech multi message * Allow changing the way of binding player inventory * Update MUI * Update MUI * Update MUI * Update MUI * Update MUI * Make MUI non-transitive to allow addons to use their own version * Force enable mixin * Format fluid amount tooltip * Add GUITextureSet.STEAM * Add guard against null ModularWindow creation * Add constructors for Muffler Hatch with inventory * Fix output slot on digital chest and tank allowing insertion * Don't log null ModularWindow * Add default implementation for IHasWorldObjectAndCoords#openGUI * Make openGTTileEntityUI accept MultiTE & cleanup Co-authored-by: Jason Mitchell <mitchej@gmail.com>
Diffstat (limited to 'src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java')
-rw-r--r--src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java204
1 files changed, 204 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java b/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java
new file mode 100644
index 0000000000..2d776ce71e
--- /dev/null
+++ b/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java
@@ -0,0 +1,204 @@
+package gregtech.api.gui.modularui;
+
+import com.gtnewhorizons.modularui.api.UIInfos;
+import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI;
+import com.gtnewhorizons.modularui.api.screen.ModularUIContext;
+import com.gtnewhorizons.modularui.api.screen.ModularWindow;
+import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
+import com.gtnewhorizons.modularui.common.builder.UIBuilder;
+import com.gtnewhorizons.modularui.common.builder.UIInfo;
+import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils;
+import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui;
+import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import gregtech.api.enums.GT_Values;
+import gregtech.api.interfaces.tileentity.ICoverable;
+import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords;
+import gregtech.api.net.GT_Packet_SendCoverData;
+import gregtech.api.util.GT_CoverBehaviorBase;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraftforge.common.util.ForgeDirection;
+
+public class GT_UIInfos {
+
+ /**
+ * Generator for {@link UIInfo} which is responsible for registering and opening UIs.
+ * Unlike {@link com.gtnewhorizons.modularui.api.UIInfos#TILE_MODULAR_UI}, this accepts
+ * custom constructors for UI.
+ * <br> Do NOT run {@link UIBuilder#build} on-the-fly, otherwise MP client won't register UIs.
+ * Instead, store to static field, just like {@link #GTTileEntityDefaultUI}.
+ * Such mistake can be easily overlooked by testing only SP.
+ */
+ public static final Function<ContainerConstructor, UIInfo<?, ?>> GTTileEntityUIFactory =
+ containerConstructor -> UIBuilder.of()
+ .container((player, world, x, y, z) -> {
+ TileEntity te = world.getTileEntity(x, y, z);
+ if (te instanceof ITileWithModularUI) {
+ return createTileEntityContainer(
+ player,
+ ((ITileWithModularUI) te)::createWindow,
+ te::markDirty,
+ containerConstructor);
+ }
+ return null;
+ })
+ .gui(((player, world, x, y, z) -> {
+ if (!world.isRemote) return null;
+ TileEntity te = world.getTileEntity(x, y, z);
+ if (te instanceof ITileWithModularUI) {
+ return createTileEntityGuiContainer(
+ player, ((ITileWithModularUI) te)::createWindow, containerConstructor);
+ }
+ return null;
+ }))
+ .build();
+
+ private static final UIInfo<?, ?> GTTileEntityDefaultUI = GTTileEntityUIFactory.apply(ModularUIContainer::new);
+
+ private static final Map<Byte, UIInfo<?, ?>> coverUI = new HashMap<>();
+
+ static {
+ for (byte i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
+ final byte side = i;
+ coverUI.put(
+ side,
+ UIBuilder.of()
+ .container((player, world, x, y, z) -> {
+ TileEntity te = world.getTileEntity(x, y, z);
+ if (!(te instanceof ICoverable)) return null;
+ ICoverable gtTileEntity = (ICoverable) te;
+ GT_CoverBehaviorBase<?> cover = gtTileEntity.getCoverBehaviorAtSideNew(side);
+ return createCoverContainer(
+ player,
+ cover::createWindow,
+ te::markDirty,
+ gtTileEntity.getCoverIDAtSide(side),
+ side,
+ gtTileEntity);
+ })
+ .gui((player, world, x, y, z) -> {
+ if (!world.isRemote) return null;
+ TileEntity te = world.getTileEntity(x, y, z);
+ if (!(te instanceof ICoverable)) return null;
+ ICoverable gtTileEntity = (ICoverable) te;
+ GT_CoverBehaviorBase<?> cover = gtTileEntity.getCoverBehaviorAtSideNew(side);
+ return createCoverGuiContainer(
+ player,
+ cover::createWindow,
+ gtTileEntity.getCoverIDAtSide(side),
+ side,
+ gtTileEntity);
+ })
+ .build());
+ }
+ }
+
+ /**
+ * Opens TileEntity UI, created by {@link ITileWithModularUI#createWindow}.
+ */
+ public static void openGTTileEntityUI(IHasWorldObjectAndCoords aTileEntity, EntityPlayer aPlayer) {
+ if (aTileEntity.isClientSide()) return;
+ GTTileEntityDefaultUI.open(
+ aPlayer,
+ aTileEntity.getWorld(),
+ aTileEntity.getXCoord(),
+ aTileEntity.getYCoord(),
+ aTileEntity.getZCoord());
+ }
+
+ /**
+ * Opens cover UI, created by {@link GT_CoverBehaviorBase#createWindow}.
+ */
+ public static void openCoverUI(ICoverable tileEntity, EntityPlayer player, byte side) {
+ if (tileEntity.isClientSide()) return;
+
+ GT_Values.NW.sendToPlayer(
+ new GT_Packet_SendCoverData(
+ side,
+ tileEntity.getCoverIDAtSide(side),
+ tileEntity.getComplexCoverDataAtSide(side),
+ tileEntity),
+ (EntityPlayerMP) player);
+
+ coverUI.get(side)
+ .open(
+ player,
+ tileEntity.getWorld(),
+ tileEntity.getXCoord(),
+ tileEntity.getYCoord(),
+ tileEntity.getZCoord());
+ }
+
+ /**
+ * Opens UI for player's item, created by {@link com.gtnewhorizons.modularui.api.screen.IItemWithModularUI#createWindow}.
+ */
+ public static void openPlayerHeldItemUI(EntityPlayer player) {
+ if (NetworkUtils.isClient()) return;
+ UIInfos.PLAYER_HELD_ITEM_UI.open(player);
+ }
+
+ private static ModularUIContainer createTileEntityContainer(
+ EntityPlayer player,
+ Function<UIBuildContext, ModularWindow> windowCreator,
+ Runnable onWidgetUpdate,
+ ContainerConstructor containerCreator) {
+ UIBuildContext buildContext = new UIBuildContext(player);
+ ModularWindow window = windowCreator.apply(buildContext);
+ if (window == null) {
+ return null;
+ }
+ return containerCreator.of(new ModularUIContext(buildContext, onWidgetUpdate), window);
+ }
+
+ @SideOnly(Side.CLIENT)
+ private static ModularGui createTileEntityGuiContainer(
+ EntityPlayer player,
+ Function<UIBuildContext, ModularWindow> windowCreator,
+ ContainerConstructor containerConstructor) {
+ ModularUIContainer container = createTileEntityContainer(player, windowCreator, null, containerConstructor);
+ if (container == null) {
+ return null;
+ }
+ return new ModularGui(container);
+ }
+
+ private static ModularUIContainer createCoverContainer(
+ EntityPlayer player,
+ Function<GT_CoverUIBuildContext, ModularWindow> windowCreator,
+ Runnable onWidgetUpdate,
+ int coverID,
+ byte side,
+ ICoverable tile) {
+ GT_CoverUIBuildContext buildContext = new GT_CoverUIBuildContext(player, coverID, side, tile, false);
+ ModularWindow window = windowCreator.apply(buildContext);
+ if (window == null) {
+ return null;
+ }
+ return new ModularUIContainer(new ModularUIContext(buildContext, onWidgetUpdate), window);
+ }
+
+ @SideOnly(Side.CLIENT)
+ private static ModularGui createCoverGuiContainer(
+ EntityPlayer player,
+ Function<GT_CoverUIBuildContext, ModularWindow> windowCreator,
+ int coverID,
+ byte side,
+ ICoverable tile) {
+ ModularUIContainer container = createCoverContainer(player, windowCreator, null, coverID, side, tile);
+ if (container == null) {
+ return null;
+ }
+ return new ModularGui(container);
+ }
+
+ @FunctionalInterface
+ public interface ContainerConstructor {
+ ModularUIContainer of(ModularUIContext context, ModularWindow mainWindow);
+ }
+}