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

ModularUI setup #2264

Merged
merged 20 commits into from
Dec 8, 2023
Merged
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
// the CCL deobf jar uses very old MCP mappings, making it error at runtime in runClient/runServer
// therefore we manually deobf the regular jar
implementation rfg.deobf("curse.maven:codechicken-lib-1-8-242818:2779848") // CCL 3.2.3.358
implementation "curse.maven:modularui-624243:4856895"
serenibyss marked this conversation as resolved.
Show resolved Hide resolved

// Soft Dependencies
// Can change any of these from compileOnlyApi -> implementation to test them in-game.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gregtech/GregTechMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
acceptedMinecraftVersions = "[1.12.2,1.13)",
version = GTInternalTags.VERSION,
dependencies = "required:forge@[14.23.5.2847,);" + "required-after:codechickenlib@[3.2.3,);" +
"after:appliedenergistics2;" + "after:forestry;" + "after:extrabees;" + "after:extratrees;" +
"after:genetics;" + "after:magicbees;" + "after:jei@[4.15.0,);" + "after:crafttweaker@[4.1.20,);" +
"after:groovyscript@[0.7.0,);" + "after:theoneprobe;" + "after:hwyla;")
"required-after:modularui@[2,);" + "after:appliedenergistics2;" + "after:forestry;" + "after:extrabees;" +
"after:extratrees;" + "after:genetics;" + "after:magicbees;" + "after:jei@[4.15.0,);" +
"after:crafttweaker@[4.1.20,);" + "after:groovyscript@[0.7.0,);" + "after:theoneprobe;" + "after:hwyla;")
public class GregTechMod {

// Hold this so that we can reference non-interface methods without
Expand Down
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/GregTechAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class GregTechAPI {

public static final GTControlledRegistry<ResourceLocation, MetaTileEntity> MTE_REGISTRY = new GTControlledRegistry<>(
Short.MAX_VALUE);
@Deprecated
public static final GTControlledRegistry<ResourceLocation, UIFactory> UI_FACTORY_REGISTRY = new GTControlledRegistry<>(
Short.MAX_VALUE);
public static final GTControlledRegistry<ResourceLocation, CoverDefinition> COVER_REGISTRY = new GTControlledRegistry<>(
Expand Down
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/cover/CoverUIFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;

@Deprecated
public final class CoverUIFactory extends UIFactory<CoverWithUI> {

public static final CoverUIFactory INSTANCE = new CoverUIFactory();
Expand Down
45 changes: 42 additions & 3 deletions src/main/java/gregtech/api/cover/CoverWithUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,56 @@

import gregtech.api.gui.IUIHolder;
import gregtech.api.gui.ModularUI;
import gregtech.api.mui.GTGuiTheme;
import gregtech.api.mui.GTGuis;
import gregtech.api.mui.GregTechGuiScreen;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;

public interface CoverWithUI extends Cover, IUIHolder {
import com.cleanroommc.modularui.api.IGuiHolder;
import com.cleanroommc.modularui.manager.GuiCreationContext;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.screen.ModularScreen;
import com.cleanroommc.modularui.value.sync.GuiSyncManager;
import org.jetbrains.annotations.ApiStatus;

public interface CoverWithUI extends Cover, IUIHolder, IGuiHolder {

@ApiStatus.Experimental
default boolean usesMui2() {
return false;
}

default void openUI(EntityPlayerMP player) {
CoverUIFactory.INSTANCE.openUI(this, player);
if (usesMui2()) {
GTGuis.getCoverUiInfo(getAttachedSide())
.open(player, getCoverableView().getWorld(), getCoverableView().getPos());
} else {
CoverUIFactory.INSTANCE.openUI(this, player);
}
}

@Deprecated
default ModularUI createUI(EntityPlayer player) {
return null;
}

@ApiStatus.NonExtendable
@Override
default ModularScreen createScreen(GuiCreationContext creationContext, ModularPanel mainPanel) {
return new GregTechGuiScreen(mainPanel, getUITheme());
}

default GTGuiTheme getUITheme() {
return GTGuiTheme.STANDARD;
}

ModularUI createUI(EntityPlayer player);
@Override
default ModularPanel buildUI(GuiCreationContext guiCreationContext, GuiSyncManager guiSyncManager,
boolean isClient) {
return null;
}

@Override
default boolean isValid() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gregtech/api/gui/GuiTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ public class GuiTextures {
// BASE TEXTURES
public static final TextureArea BACKGROUND = AdoptableTextureArea.fullImage("textures/gui/base/background.png", 176,
166, 3, 3);
// todo try to remove
public static final TextureArea BORDERED_BACKGROUND = AdoptableTextureArea
.fullImage("textures/gui/base/bordered_background.png", 195, 136, 4, 4);
// todo try to remove
public static final TextureArea BOXED_BACKGROUND = AdoptableTextureArea
.fullImage("textures/gui/base/boxed_background.png", 256, 174, 11, 11);
public static final SteamTexture BACKGROUND_STEAM = SteamTexture.fullImage("textures/gui/base/background_%s.png",
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gregtech/api/gui/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@Deprecated
package gregtech.api.gui;
32 changes: 30 additions & 2 deletions src/main/java/gregtech/api/items/gui/ItemUIFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,42 @@

import gregtech.api.gui.ModularUI;
import gregtech.api.items.metaitem.stats.IItemComponent;
import gregtech.api.mui.GTGuiTheme;
import gregtech.api.mui.GregTechGuiScreen;

import net.minecraft.entity.player.EntityPlayer;

public interface ItemUIFactory extends IItemComponent {
import com.cleanroommc.modularui.api.IGuiHolder;
import com.cleanroommc.modularui.manager.GuiCreationContext;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.screen.ModularScreen;
import com.cleanroommc.modularui.value.sync.GuiSyncManager;
import org.jetbrains.annotations.ApiStatus;

public interface ItemUIFactory extends IItemComponent, IGuiHolder {

/**
* Creates new UI basing on given holder. Holder contains information
* about item stack and hand, and also player
*/
ModularUI createUI(PlayerInventoryHolder holder, EntityPlayer entityPlayer);
@Deprecated
default ModularUI createUI(PlayerInventoryHolder holder, EntityPlayer entityPlayer) {
return null;
}

@ApiStatus.NonExtendable
@Override
default ModularScreen createScreen(GuiCreationContext creationContext, ModularPanel mainPanel) {
return new GregTechGuiScreen(mainPanel, getUITheme());
}

default GTGuiTheme getUITheme() {
return GTGuiTheme.STANDARD;
}

@Override
default ModularPanel buildUI(GuiCreationContext guiCreationContext, GuiSyncManager guiSyncManager,
boolean isClient) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/**
* {@link UIFactory} implementation for {@link MetaItem}s
*/
@Deprecated
public class PlayerInventoryUIFactory extends UIFactory<PlayerInventoryHolder> {

public static final PlayerInventoryUIFactory INSTANCE = new PlayerInventoryUIFactory();
Expand Down
42 changes: 39 additions & 3 deletions src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import gregtech.api.items.toolitem.ToolHelper;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.metatileentity.interfaces.ISyncedTileEntity;
import gregtech.api.mui.GTGuiTheme;
import gregtech.api.mui.GTGuis;
import gregtech.api.mui.GregTechGuiScreen;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.util.GTLog;
import gregtech.api.util.GTTransferUtils;
Expand Down Expand Up @@ -66,6 +69,11 @@
import codechicken.lib.texture.TextureUtils;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import com.cleanroommc.modularui.api.IGuiHolder;
import com.cleanroommc.modularui.manager.GuiCreationContext;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.screen.ModularScreen;
import com.cleanroommc.modularui.value.sync.GuiSyncManager;
import com.google.common.base.Preconditions;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
Expand All @@ -82,7 +90,7 @@

import static gregtech.api.capability.GregtechDataCodes.*;

public abstract class MetaTileEntity implements ISyncedTileEntity, CoverHolder, IVoidable {
public abstract class MetaTileEntity implements ISyncedTileEntity, CoverHolder, IVoidable, IGuiHolder {

public static final IndexedCuboid6 FULL_CUBE_COLLISION = new IndexedCuboid6(null, Cuboid6.full);

Expand Down Expand Up @@ -412,12 +420,36 @@ protected boolean openGUIOnRightClick() {
* @param entityPlayer player opening inventory
* @return freshly created UI instance
*/
protected abstract ModularUI createUI(EntityPlayer entityPlayer);
@Deprecated
protected ModularUI createUI(EntityPlayer entityPlayer) {
return null;
}

@Deprecated
public ModularUI getModularUI(EntityPlayer entityPlayer) {
return createUI(entityPlayer);
}

@ApiStatus.Experimental
public boolean usesMui2() {
return false;
}

@Override
public final ModularScreen createScreen(GuiCreationContext creationContext, ModularPanel mainPanel) {
return new GregTechGuiScreen(mainPanel, getUITheme());
}

public GTGuiTheme getUITheme() {
return GTGuiTheme.STANDARD;
}

@Override
public ModularPanel buildUI(GuiCreationContext guiCreationContext, GuiSyncManager guiSyncManager,
boolean isClient) {
return null;
}

public final void onCoverLeftClick(EntityPlayer playerIn, CuboidRayTraceResult result) {
Cover cover = getCoverAtSide(result.sideHit);
if (cover == null || !cover.onLeftClick(playerIn, result)) {
Expand All @@ -435,7 +467,11 @@ public boolean onRightClick(EntityPlayer playerIn, EnumHand hand, EnumFacing fac
ItemStack heldStack = playerIn.getHeldItem(hand);
if (!playerIn.isSneaking() && openGUIOnRightClick()) {
if (getWorld() != null && !getWorld().isRemote) {
MetaTileEntityUIFactory.INSTANCE.openUI(getHolder(), (EntityPlayerMP) playerIn);
if (usesMui2()) {
GTGuis.MTE.open(playerIn, getWorld(), getPos());
} else {
MetaTileEntityUIFactory.INSTANCE.openUI(getHolder(), (EntityPlayerMP) playerIn);
}
}
return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/**
* {@link UIFactory} implementation for {@link MetaTileEntity}
*/
@Deprecated
public class MetaTileEntityUIFactory extends UIFactory<IGregTechTileEntity> {

public static final MetaTileEntityUIFactory INSTANCE = new MetaTileEntityUIFactory();
Expand Down
75 changes: 75 additions & 0 deletions src/main/java/gregtech/api/mui/GTGuiTextures.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package gregtech.api.mui;

import gregtech.api.GTValues;

import com.cleanroommc.modularui.drawable.UITexture;

// TODO: Move primitive slot and background to "textures/gui/base"
public class GTGuiTextures {

// Keys used for GT assets registered for use in Themes
public static class IDs {

public static final String STANDARD_BACKGROUND = "gregtech_standard_bg";
public static final String BRONZE_BACKGROUND = "gregtech_bronze_bg";
public static final String STEEL_BACKGROUND = "gregtech_steel_bg";
public static final String PRIMITIVE_BACKGROUND = "gregtech_primitive_bg";

public static final String BRONZE_SLOT = "gregtech_bronze_slot";
public static final String STEEL_SLOT = "gregtech_steel_slot";
public static final String PRIMITIVE_SLOT = "gregtech_primitive_slot";
}

// BACKGROUNDS
public static final UITexture BACKGROUND = UITexture.builder()
.location(GTValues.MODID, "textures/gui/base/background.png")
.imageSize(176, 166)
.adaptable(3)
.registerAsBackground(IDs.STANDARD_BACKGROUND, true)
.build();

public static final UITexture BACKGROUND_BRONZE = UITexture.builder()
.location(GTValues.MODID, "textures/gui/base/background_bronze.png")
.imageSize(176, 166)
.adaptable(3)
.registerAsBackground(IDs.BRONZE_BACKGROUND)
.build();

public static final UITexture BACKGROUND_STEEL = UITexture.builder()
.location(GTValues.MODID, "textures/gui/base/background_steel.png")
.imageSize(176, 166)
.adaptable(3)
.registerAsBackground(IDs.STEEL_BACKGROUND)
.build();

public static final UITexture BACKGROUND_PRIMITIVE = UITexture.builder()
.location(GTValues.MODID, "textures/gui/primitive/primitive_background.png")
.imageSize(176, 166)
.adaptable(3)
.registerAsBackground(IDs.PRIMITIVE_BACKGROUND)
.build();

// SLOTS
public static final UITexture SLOT_BRONZE = new UITexture.Builder()
.location(GTValues.MODID, "textures/gui/base/slot_bronze.png")
.imageSize(18, 18)
.adaptable(1)
.registerAsBackground(IDs.BRONZE_SLOT)
.build();

public static final UITexture SLOT_STEEL = new UITexture.Builder()
.location(GTValues.MODID, "textures/gui/base/slot_steel.png")
.imageSize(18, 18)
.adaptable(1)
.registerAsBackground(IDs.STEEL_SLOT)
.build();

public static final UITexture SLOT_PRIMITIVE = new UITexture.Builder()
.location(GTValues.MODID, "textures/gui/primitive/primitive_slot.png")
.imageSize(18, 18)
.adaptable(1)
.registerAsBackground(IDs.PRIMITIVE_SLOT)
.build();

public static void init() {/**/}
}
Loading