Skip to content

Commit

Permalink
MUI cover skeleton and Machine Controller Cover port (#2312)
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss authored Jan 1, 2024
1 parent 6c2259a commit 79f179c
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 80 deletions.
9 changes: 6 additions & 3 deletions src/main/java/gregtech/api/cover/Cover.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@ default long getOffsetTimer() {

/**
* Called when the cover is first attached on the Server Side.
* Do NOT sync custom data to client here. It will overwrite the attach cover packet!
* Values set here will automatically be synced to the client, if you
* specify them in {@link #writeInitialSyncData}.
*
* @apiNote The CoverableView will not have your cover attached to it in this method.
*
* @param coverableView the CoverableView this cover is attached to
* @param side the side this cover is attached to
* @param coverableView the CoverableView this cover will be attached to
* @param side the side this cover will be attached to
* @param player the player attaching the cover
* @param itemStack the item used to place the cover
*/
Expand Down
57 changes: 56 additions & 1 deletion src/main/java/gregtech/api/cover/CoverWithUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import com.cleanroommc.modularui.api.IGuiHolder;
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.drawable.ItemDrawable;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.screen.ModularScreen;
import com.cleanroommc.modularui.value.BoolValue;
import com.cleanroommc.modularui.value.sync.EnumSyncValue;
import com.cleanroommc.modularui.value.sync.GuiSyncManager;
import com.cleanroommc.modularui.value.sync.IntSyncValue;
import com.cleanroommc.modularui.widget.ParentWidget;
import com.cleanroommc.modularui.widgets.layout.Row;
import org.jetbrains.annotations.ApiStatus;

public interface CoverWithUI extends Cover, IUIHolder, IGuiHolder<SidedPosGuiData> {
Expand Down Expand Up @@ -46,7 +54,7 @@ default ModularScreen createScreen(SidedPosGuiData guiData, ModularPanel mainPan
}

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

@Override
Expand All @@ -68,4 +76,51 @@ default boolean isRemote() {
default void markAsDirty() {
getCoverableView().markDirty();
}

/* Helper methods for UI creation with covers that are commonly used */

/**
* The color used for Cover UI titles, and used in {@link #createTitleRow}.
*/
int UI_TITLE_COLOR = 0xFF222222;
/**
* The color used for Cover UI text. Available for reference, but is
* handled automatically by the {@link GTGuiTheme#COVER} theme.
*/
int UI_TEXT_COLOR = 0xFF555555;

/**
* Create the Title bar widget for a Cover.
*/
default Row createTitleRow() {
ItemStack item = getDefinition().getDropItemStack();
return new Row()
.pos(4, 4)
.height(16).coverChildrenWidth()
.child(new ItemDrawable(getDefinition().getDropItemStack()).asWidget().size(16).marginRight(4))
.child(IKey.str(item.getDisplayName()).color(UI_TITLE_COLOR).asWidget().heightRel(1.0f));
}

/**
* Create a new settings row for a Cover setting.
*/
default ParentWidget<?> createSettingsRow() {
return new ParentWidget<>().height(16).widthRel(1.0f).marginBottom(2);
}

/**
* Get a BoolValue for use with toggle buttons which are "linked together,"
* meaning only one of them can be pressed at a time.
*/
default <T extends Enum<T>> BoolValue.Dynamic boolValueOf(EnumSyncValue<T> syncValue, T value) {
return new BoolValue.Dynamic(() -> syncValue.getValue() == value, $ -> syncValue.setValue(value));
}

/**
* Get a BoolValue for use with toggle buttons which are "linked together,"
* meaning only one of them can be pressed at a time.
*/
default BoolValue.Dynamic boolValueOf(IntSyncValue syncValue, int value) {
return new BoolValue.Dynamic(() -> syncValue.getValue() == value, $ -> syncValue.setValue(value));
}
}
7 changes: 7 additions & 0 deletions src/main/java/gregtech/api/cover/CoverableView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gregtech.api.cover;

import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
Expand Down Expand Up @@ -87,4 +88,10 @@ default boolean hasCover(@NotNull EnumFacing side) {
int getInputRedstoneSignal(@NotNull EnumFacing side, boolean ignoreCover);

void writeCoverData(@NotNull Cover cover, int discriminator, @NotNull Consumer<@NotNull PacketBuffer> buf);

/**
* @return an ItemStack representation of the CoverableView, or {@link ItemStack#EMPTY} if not possible.
*/
@NotNull
ItemStack getStackForm();
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ public EnumActionResult onItemUseFirst(EntityPlayer player, @NotNull World world

ItemStack itemStack = player.getHeldItem(hand);

coverHolder.addCover(coverSide, cover);
// Call onAttachment first so that the cover can set up any
// necessary variables needed for the S2C cover sync packet.
cover.onAttachment(coverHolder, coverSide, player, itemStack);
coverHolder.addCover(coverSide, cover);

AdvancementTriggers.FIRST_COVER_PLACE.trigger((EntityPlayerMP) player);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,8 @@ public final ItemStack getStackForm(int amount) {
return new ItemStack(GregTechAPI.MACHINE, amount, metaTileEntityIntId);
}

public final ItemStack getStackForm() {
@Override
public final @NotNull ItemStack getStackForm() {
return getStackForm(1);
}

Expand Down
23 changes: 21 additions & 2 deletions src/main/java/gregtech/api/mui/GTGuiTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class GTGuiTextures {
public static class IDs {

public static final String STANDARD_BACKGROUND = "gregtech_standard_bg";
public static final String COVER_BACKGROUND = "gregtech_cover_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";
Expand All @@ -34,9 +35,9 @@ public static class IDs {
}

// ICONS
/** @apiNote You may want {@link GTGuiTextures#getLogo()} instead. */
/** @apiNote You may want {@link GTGuiTextures#getLogo} instead. */
public static final UITexture GREGTECH_LOGO = fullImage("textures/gui/icon/gregtech_logo.png");
/** @apiNote You may want {@link GTGuiTextures#getLogo()} instead. */
/** @apiNote You may want {@link GTGuiTextures#getLogo} instead. */
public static final UITexture GREGTECH_LOGO_XMAS = fullImage("textures/gui/icon/gregtech_logo_xmas.png");
public static final UITexture GREGTECH_LOGO_DARK = fullImage("textures/gui/icon/gregtech_logo_dark.png");
// todo blinking GT logos
Expand All @@ -61,6 +62,7 @@ public static class IDs {
.location(GTValues.MODID, "textures/gui/base/background_popup.png")
.imageSize(195, 136)
.adaptable(4)
.name(IDs.COVER_BACKGROUND)
.canApplyTheme()
.build();

Expand Down Expand Up @@ -268,6 +270,19 @@ public static class IDs {
.canApplyTheme()
.build();

public static final UITexture MC_BUTTON = new UITexture.Builder()
.location("modularui", "gui/widgets/mc_button.png") // todo
.imageSize(16, 32)
.uv(0.0f, 0.0f, 1.0f, 0.5f)
.adaptable(1)
.build();

public static final UITexture MC_BUTTON_DISABLED = new UITexture.Builder()
.location("modularui", "gui/widgets/mc_button_disabled.png") // todo
.imageSize(16, 16)
.adaptable(1)
.build();

// BUTTON OVERLAYS

public static final UITexture BUTTON_ITEM_OUTPUT = fullImage("textures/gui/widget/button_item_output_overlay.png");
Expand All @@ -277,6 +292,10 @@ public static class IDs {
"textures/gui/widget/button_auto_collapse_overlay.png");
public static final UITexture BUTTON_X = fullImage("textures/gui/widget/button_x_overlay.png", true);

public static final UITexture BUTTON_CROSS = fullImage("textures/gui/widget/button_cross.png");
public static final UITexture BUTTON_REDSTONE_ON = fullImage("textures/gui/widget/button_redstone_on.png");
public static final UITexture BUTTON_REDSTONE_OFF = fullImage("textures/gui/widget/button_redstone_off.png");

// PROGRESS BARS
public static final UITexture PROGRESS_BAR_ARC_FURNACE = progressBar(
"textures/gui/progress_bar/progress_bar_arc_furnace.png", true);
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/gregtech/api/mui/GTGuiTheme.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gregtech.api.mui;

import gregtech.api.cover.CoverWithUI;
import gregtech.common.ConfigHolder;

import net.minecraftforge.common.MinecraftForge;
Expand Down Expand Up @@ -33,7 +34,15 @@ public class GTGuiTheme {
ConfigHolder.client.defaultUIColor)
.build();

// TODO Cover theme to utilize the GT5u-like button textures vs the standard ones
public static final GTGuiTheme COVER = templateBuilder("gregtech_cover")
.panel(GTGuiTextures.IDs.COVER_BACKGROUND)
.itemSlot(GTGuiTextures.IDs.STANDARD_SLOT)
.fluidSlot(GTGuiTextures.IDs.STANDARD_FLUID_SLOT)
.color(ConfigHolder.client.defaultUIColor)
.textColor(CoverWithUI.UI_TEXT_COLOR)
.build();

// TODO Multiblock theme for display texture, logo changes

public static final GTGuiTheme BRONZE = templateBuilder("gregtech_bronze")
.panel(GTGuiTextures.IDs.BRONZE_BACKGROUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public final void removeCover(@NotNull EnumFacing side) {
}

@SuppressWarnings("unchecked")
public ItemStack getStackForm() {
@Override
public @NotNull ItemStack getStackForm() {
BlockPipe pipeBlock = holder.getPipeBlock();
return pipeBlock.getDropItem(holder);
}
Expand Down
Loading

0 comments on commit 79f179c

Please sign in to comment.