Skip to content

Commit

Permalink
Port Filters and some Covers to MUI + Filter Rework (#2345)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude authored Apr 4, 2024
1 parent 06938f0 commit f33da7f
Show file tree
Hide file tree
Showing 78 changed files with 3,861 additions and 2,342 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
dependencies {
// Published dependencies
api("codechicken:codechickenlib:3.2.3.358")
api("com.cleanroommc:modularui:2.4.1") { transitive = false }
api("com.cleanroommc:modularui:2.4.3") { transitive = false }
api("com.cleanroommc:groovyscript:0.8.0") { transitive = false }
api("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.684")
api rfg.deobf("curse.maven:ae2-extended-life-570458:4402048") // AE2UEL 0.55.6
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/gregtech/api/capability/GregtechDataCodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public static int assignId() {
public static final int UPDATE_AUTO_OUTPUT_FLUIDS = assignId();
public static final int UPDATE_IS_VOIDING = assignId();

// Robotic Arm
public static final int UPDATE_TRANSFER_MODE = assignId();

// Drum
public static final int UPDATE_AUTO_OUTPUT = assignId();

Expand Down
122 changes: 118 additions & 4 deletions src/main/java/gregtech/api/cover/CoverWithUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@

import gregtech.api.gui.IUIHolder;
import gregtech.api.gui.ModularUI;
import gregtech.api.mui.GTGuiTextures;
import gregtech.api.mui.GTGuiTheme;
import gregtech.api.mui.GregTechGuiScreen;
import gregtech.api.mui.factory.CoverGuiFactory;

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

import com.cleanroommc.modularui.api.IGuiHolder;
import com.cleanroommc.modularui.api.drawable.IDrawable;
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.utils.Alignment;
import com.cleanroommc.modularui.utils.MouseData;
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.ToggleButton;
import com.cleanroommc.modularui.widgets.layout.Row;
import org.jetbrains.annotations.ApiStatus;

Expand Down Expand Up @@ -92,13 +98,12 @@ default void markAsDirty() {
/**
* Create the Title bar widget for a Cover.
*/
default Row createTitleRow() {
ItemStack item = getDefinition().getDropItemStack();
static Row createTitleRow(ItemStack stack) {
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));
.child(new ItemDrawable(stack).asWidget().size(16).marginRight(4))
.child(IKey.str(stack.getDisplayName()).color(UI_TITLE_COLOR).asWidget().heightRel(1.0f));
}

/**
Expand All @@ -108,6 +113,31 @@ default ParentWidget<?> createSettingsRow() {
return new ParentWidget<>().height(16).widthRel(1.0f).marginBottom(2);
}

default int getIncrementValue(MouseData data) {
int adjust = 1;
if (data.shift) adjust *= 4;
if (data.ctrl) adjust *= 16;
if (data.alt) adjust *= 64;
return adjust;
}

default IKey createAdjustOverlay(boolean increment) {
final StringBuilder builder = new StringBuilder();
builder.append(increment ? '+' : '-');
builder.append(getIncrementValue(MouseData.create(-1)));

float scale = 1f;
if (builder.length() == 3) {
scale = 0.8f;
} else if (builder.length() == 4) {
scale = 0.6f;
} else if (builder.length() > 4) {
scale = 0.5f;
}
return IKey.str(builder.toString())
.scale(scale);
}

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

class EnumRowBuilder<T extends Enum<T>> {

private EnumSyncValue<T> syncValue;
private final Class<T> enumValue;
private String lang;
private IDrawable[] background;
private IDrawable selectedBackground;
private IDrawable[] overlay;

public EnumRowBuilder(Class<T> enumValue) {
this.enumValue = enumValue;
}

public EnumRowBuilder<T> value(EnumSyncValue<T> syncValue) {
this.syncValue = syncValue;
return this;
}

public EnumRowBuilder<T> lang(String lang) {
this.lang = lang;
return this;
}

public EnumRowBuilder<T> background(IDrawable... background) {
this.background = background;
return this;
}

public EnumRowBuilder<T> selectedBackground(IDrawable selectedBackground) {
this.selectedBackground = selectedBackground;
return this;
}

public EnumRowBuilder<T> overlay(IDrawable... overlay) {
this.overlay = overlay;
return this;
}

public EnumRowBuilder<T> overlay(int size, IDrawable... overlay) {
this.overlay = new IDrawable[overlay.length];
for (int i = 0; i < overlay.length; i++) {
this.overlay[i] = overlay[i].asIcon().size(size);
}
return this;
}

private BoolValue.Dynamic boolValueOf(EnumSyncValue<T> syncValue, T value) {
return new BoolValue.Dynamic(() -> syncValue.getValue() == value, $ -> syncValue.setValue(value));
}

public Row build() {
var row = new Row().marginBottom(2).coverChildrenHeight().widthRel(1f);
if (this.enumValue != null && this.syncValue != null) {
for (var enumVal : enumValue.getEnumConstants()) {
var button = new ToggleButton().size(18).marginRight(2)
.value(boolValueOf(this.syncValue, enumVal));

if (this.background != null && this.background.length > 0)
button.background(this.background);
else
button.background(GTGuiTextures.MC_BUTTON);

if (this.selectedBackground != null)
button.selectedBackground(this.selectedBackground);
else
button.selectedBackground(GTGuiTextures.MC_BUTTON_DISABLED);

if (this.overlay != null)
button.overlay(this.overlay[enumVal.ordinal()]);

if (enumVal instanceof IStringSerializable serializable) {
button.addTooltipLine(IKey.lang(serializable.getName()));
}
row.child(button);
}
}

if (this.lang != null && !this.lang.isEmpty())
row.child(IKey.lang(this.lang).asWidget().align(Alignment.CenterRight).height(18));

return row;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import gregtech.api.gui.ingredient.IGhostIngredientTarget;
import gregtech.api.gui.ingredient.IIngredientSlot;
import gregtech.api.gui.resources.IGuiTexture;
import gregtech.api.util.*;
import gregtech.api.util.GTLog;
import gregtech.api.util.LocalizationUtils;
import gregtech.api.util.Position;
import gregtech.api.util.Size;
import gregtech.api.util.TextFormattingUtil;
import gregtech.client.utils.RenderUtil;
import gregtech.client.utils.TooltipHelper;

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/gregtech/api/items/metaitem/MetaItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import gregtech.api.util.Mods;
import gregtech.client.utils.ToolChargeBarRenderer;
import gregtech.common.ConfigHolder;
import gregtech.common.covers.filter.IFilter;
import gregtech.common.creativetab.GTCreativeTabs;

import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -781,6 +782,7 @@ public MetaItem<T> getMetaItem() {
private final List<IItemBehaviour> behaviours = new ArrayList<>();
private IItemUseManager useManager;
private ItemUIFactory uiManager;
private IFilter.Factory filterBehavior;
private IItemColorProvider colorProvider;
private IItemDurabilityManager durabilityManager;
private IEnchantabilityHelper enchantabilityHelper;
Expand Down Expand Up @@ -908,9 +910,12 @@ protected void addItemComponentsInternal(IItemComponent... stats) {
if (itemComponent instanceof IFoodBehavior) {
this.useManager = new FoodUseManager((IFoodBehavior) itemComponent);
}
if (itemComponent instanceof ItemUIFactory)
if (itemComponent instanceof ItemUIFactory) {
this.uiManager = (ItemUIFactory) itemComponent;

}
if (itemComponent instanceof IFilter.Factory) {
this.filterBehavior = (IFilter.Factory) itemComponent;
}
if (itemComponent instanceof IItemColorProvider) {
this.colorProvider = (IItemColorProvider) itemComponent;
}
Expand Down Expand Up @@ -956,6 +961,11 @@ public ItemUIFactory getUIManager() {
return uiManager;
}

@Nullable
public IFilter.Factory getFilterFactory() {
return filterBehavior;
}

@Nullable
public IItemColorProvider getColorProvider() {
return colorProvider;
Expand Down
83 changes: 80 additions & 3 deletions src/main/java/gregtech/api/mui/GTGuiTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* while MUI port is still ongoing. When MUI port is done, this annotation will be removed.
*/
// TODO ^
@SuppressWarnings("unused")
@ApiStatus.Experimental
public class GTGuiTextures {

Expand Down Expand Up @@ -153,6 +154,56 @@ public static class IDs {
.canApplyTheme()
.build();

public static final UITexture[] BUTTON_BLACKLIST = slice("textures/gui/widget/button_blacklist.png",
16, 32, 16, 16, true);
public static final UITexture[] BUTTON_IGNORE_DAMAGE = slice("textures/gui/widget/button_filter_damage.png",
16, 32, 16, 16, true);
public static final UITexture[] BUTTON_IGNORE_NBT = slice("textures/gui/widget/button_filter_nbt.png",
16, 32, 16, 16, true);

public static final UITexture[] BUTTON_CASE_SENSITIVE = slice(
"textures/gui/widget/ore_filter/button_case_sensitive.png",
16, 32, 16, 16, true);

public static final UITexture[] BUTTON_MATCH_ALL = slice("textures/gui/widget/ore_filter/button_match_all.png",
16, 32, 16, 16, true);

public static final UITexture OREDICT_ERROR = fullImage("textures/gui/widget/ore_filter/error.png");
public static final UITexture OREDICT_INFO = fullImage("textures/gui/widget/ore_filter/info.png");
public static final UITexture OREDICT_MATCH = fullImage("textures/gui/widget/ore_filter/match.png");
public static final UITexture OREDICT_NO_MATCH = fullImage("textures/gui/widget/ore_filter/no_match.png");
public static final UITexture OREDICT_SUCCESS = fullImage("textures/gui/widget/ore_filter/success.png");
public static final UITexture OREDICT_WAITING = fullImage("textures/gui/widget/ore_filter/waiting.png");
public static final UITexture OREDICT_WARN = fullImage("textures/gui/widget/ore_filter/warn.png");

public static final UITexture[] MANUAL_IO_OVERLAY = slice("textures/gui/overlay/manual_io_overlay.png",
18, 18 * 3, 18, 18, true);
public static final UITexture[] CONVEYOR_MODE_OVERLAY = slice("textures/gui/overlay/conveyor_mode_overlay.png",
18, 18 * 2, 18, 18, true);

public static final UITexture[] TRANSFER_MODE_OVERLAY = slice("textures/gui/overlay/transfer_mode_overlay.png",
18, 18 * 3, 18, 18, true);

public static final UITexture[] FLUID_TRANSFER_MODE_OVERLAY = slice(
"textures/gui/overlay/fluid_transfer_mode_overlay.png",
18, 18 * 3, 18, 18, true);

public static final UITexture[] DISTRIBUTION_MODE_OVERLAY = slice(
"textures/gui/widget/button_distribution_mode.png",
16, 48, 16, 16, true);

public static final UITexture[] VOIDING_MODE_OVERLAY = slice(
"textures/gui/overlay/voiding_mode_overlay.png",
16, 32, 16, 16, true);

public static final UITexture[] FILTER_MODE_OVERLAY = slice(
"textures/gui/overlay/filter_mode_overlay.png",
16, 48, 16, 16, true);

public static final UITexture[] PRIVATE_MODE_BUTTON = slice(
"textures/gui/widget/button_public_private.png",
18, 36, 18, 18, true);

// todo bronze/steel/primitive fluid slots?

// SLOT OVERLAYS
Expand Down Expand Up @@ -205,6 +256,9 @@ public static class IDs {
public static final UITexture EXTRACTOR_OVERLAY_STEEL = fullImage(
"textures/gui/overlay/extractor_overlay_steel.png");
public static final UITexture FILTER_SLOT_OVERLAY = fullImage("textures/gui/overlay/filter_slot_overlay.png", true);
public static final UITexture FILTER_SETTINGS_OVERLAY = fullImage(
"textures/gui/overlay/filter_settings_overlay.png",
true);
public static final UITexture FURNACE_OVERLAY_1 = fullImage("textures/gui/overlay/furnace_overlay_1.png", true);
public static final UITexture FURNACE_OVERLAY_2 = fullImage("textures/gui/overlay/furnace_overlay_2.png", true);
public static final UITexture FURNACE_OVERLAY_BRONZE = fullImage("textures/gui/overlay/furnace_overlay_bronze.png");
Expand Down Expand Up @@ -265,7 +319,7 @@ public static class IDs {
public static final UITexture BUTTON = new UITexture.Builder()
.location(GTValues.MODID, "textures/gui/widget/button.png")
.imageSize(18, 18)
.adaptable(1)
.adaptable(2)
.name(IDs.STANDARD_BUTTON)
.canApplyTheme()
.build();
Expand All @@ -274,13 +328,13 @@ public static class IDs {
.location("modularui", "gui/widgets/mc_button.png") // todo
.imageSize(16, 32)
.uv(0.0f, 0.0f, 1.0f, 0.5f)
.adaptable(1)
.adaptable(2)
.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)
.adaptable(2)
.build();

// BUTTON OVERLAYS
Expand Down Expand Up @@ -453,6 +507,29 @@ private static UITexture fullImage(String path, boolean canApplyTheme) {
return UITexture.fullImage(GTValues.MODID, path, canApplyTheme);
}

@SuppressWarnings("SameParameterValue")
private static UITexture[] slice(String path, int imageWidth, int imageHeight, int sliceWidth, int sliceHeight,
boolean canApplyTheme) {
if (imageWidth % sliceWidth != 0 || imageHeight % sliceHeight != 0)
throw new IllegalArgumentException("Slice height and slice width must divide the image evenly!");

int countX = imageWidth / sliceWidth;
int countY = imageHeight / sliceHeight;
UITexture[] slices = new UITexture[countX * countY];

for (int indexX = 0; indexX < countX; indexX++) {
for (int indexY = 0; indexY < countY; indexY++) {
slices[(indexX * countX) + indexY] = UITexture.builder()
.location(GTValues.MODID, path)
.canApplyTheme(canApplyTheme)
.imageSize(imageWidth, imageHeight)
.uv(indexX * sliceWidth, indexY * sliceHeight, sliceWidth, sliceHeight)
.build();
}
}
return slices;
}

private static UITexture progressBar(String path) {
return progressBar(path, 20, 40, false);
}
Expand Down
Loading

0 comments on commit f33da7f

Please sign in to comment.