Skip to content
Open
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
5 changes: 2 additions & 3 deletions src/main/java/gregtech/api/GregTechAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import gregtech.api.block.IHeatingCoilBlockStats;
import gregtech.api.block.coil.CoilManager;
import gregtech.api.command.ICommandManager;
import gregtech.api.cover.CoverDefinition;
import gregtech.api.cover.registry.CoverRegistry;
import gregtech.api.event.HighTierEvent;
import gregtech.api.gui.UIFactory;
import gregtech.api.metatileentity.multiblock.IBatteryData;
Expand Down Expand Up @@ -74,8 +74,7 @@ public class GregTechAPI {
@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<>(
Integer.MAX_VALUE);
public static final CoverRegistry COVER_REGISTRY = new CoverRegistry(Integer.MAX_VALUE);

public static final Map<Material, Map<StoneType, IBlockOre>> oreBlockTable = new HashMap<>();
public static final Object2ObjectMap<IBlockState, IHeatingCoilBlockStats> HEATING_COILS = new Object2ObjectOpenHashMap<>();
Expand Down
110 changes: 1 addition & 109 deletions src/main/java/gregtech/api/cover/CoverWithUI.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
package gregtech.api.cover;

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.DynamicDrawable;
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.screen.UISettings;
import com.cleanroommc.modularui.utils.Alignment;
import com.cleanroommc.modularui.utils.Color;
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.IntSyncValue;
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
import com.cleanroommc.modularui.widget.ParentWidget;
import com.cleanroommc.modularui.widget.Widget;
import com.cleanroommc.modularui.widgets.ToggleButton;
import com.cleanroommc.modularui.widgets.layout.Flow;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -139,7 +131,7 @@ default ParentWidget<?> createSettingsRow() {
/**
* Create a dynamic lang key that switches between {@code cover.generic.enabled} and {@code cover.generic.disabled}
* depending on the result of the given boolean supplier. <br/>
*
*
* @param keyBase the base of the lang key to use. {@code .enabled} and {@code .disabled} will be appended.
*/
default IKey createEnabledKey(@NotNull String keyBase, @NotNull BooleanSupplier enabledState) {
Expand Down Expand Up @@ -173,104 +165,4 @@ default IKey createAdjustOverlay(boolean increment) {
.color(Color.WHITE.main)
.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.
*/
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));
}

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 Flow build() {
var row = Flow.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;
}
}
}
54 changes: 54 additions & 0 deletions src/main/java/gregtech/api/cover/registry/CoverRegistry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package gregtech.api.cover.registry;

import gregtech.api.cover.CoverDefinition;
import gregtech.api.items.metaitem.MetaItem;
import gregtech.api.util.GTControlledRegistry;
import gregtech.api.util.GTUtility;
import gregtech.common.covers.filter.BaseFilter;
import gregtech.common.covers.filter.IFilter;

import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.UnmodifiableView;

import java.util.EnumMap;
import java.util.List;

public final class CoverRegistry extends GTControlledRegistry<ResourceLocation, CoverDefinition> {

private static final EnumMap<IFilter.FilterType, List<ItemStack>> filterCovers = new EnumMap<>(
IFilter.FilterType.class);

public CoverRegistry(int maxId) {
super(maxId);
}

@Override
public void register(int id, @NotNull ResourceLocation key, @NotNull CoverDefinition coverDefinition) {
super.register(id, key, coverDefinition);

ItemStack coverStack = coverDefinition.getDropItemStack();
if (coverStack.getItem() instanceof MetaItem<?>metaItem) {
MetaItem<?>.MetaValueItem metaValueItem = metaItem.getItem(coverStack);
if (metaValueItem == null) return;

IFilter.Factory factory = metaValueItem.getFilterFactory();
if (factory == null) return;

BaseFilter filter = factory.create(coverStack);
IFilter.FilterType filterType = filter.getType();
if (filterType.isError()) return;

filterCovers.computeIfAbsent(filterType, $ -> new ObjectArrayList<>())
.add(coverStack);
}
}

@UnmodifiableView
public static @NotNull List<ItemStack> getFilterItems(@NotNull IFilter.FilterType filterType) {
return GTUtility.unmodifiableOrEmpty(filterCovers.get(filterType));
}
}
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/mui/GTGuiTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ private static String id(String path) {
18, 18 * 2, 18, 18, ColorType.DEFAULT);

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

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

public static final UITexture[] DISTRIBUTION_MODE_OVERLAY = slice(
"textures/gui/widget/button_distribution_mode.png",
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/gregtech/api/mui/util/ValueHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package gregtech.api.mui.util;

import com.cleanroommc.modularui.api.value.IBoolValue;
import com.cleanroommc.modularui.api.value.IByteValue;
import com.cleanroommc.modularui.api.value.IDoubleValue;
import com.cleanroommc.modularui.api.value.IEnumValue;
import com.cleanroommc.modularui.api.value.IIntValue;
import com.cleanroommc.modularui.api.value.ILongValue;
import com.cleanroommc.modularui.api.value.IStringValue;
import com.cleanroommc.modularui.api.value.IValue;
import com.cleanroommc.modularui.value.BoolValue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.UnknownNullability;

import java.util.Objects;

public final class ValueHelper {

public static BoolValue.Dynamic boolValueOf(@NotNull IBoolValue<?> value, boolean target) {
Objects.requireNonNull(value);
return new BoolValue.Dynamic(() -> value.getBoolValue() == target, $ -> value.setBoolValue(target));
}

public static BoolValue.Dynamic boolValueOf(@NotNull IByteValue<?> value, byte target) {
Objects.requireNonNull(value);
return new BoolValue.Dynamic(() -> value.getByteValue() == target, $ -> value.setByteValue(target));
}

public static BoolValue.Dynamic boolValueOf(@NotNull IDoubleValue<?> value, double target) {
Objects.requireNonNull(value);
return new BoolValue.Dynamic(() -> value.getDoubleValue() == target, $ -> value.setDoubleValue(target));
}

public static <T extends Enum<T>> BoolValue.Dynamic boolValueOf(@NotNull IEnumValue<T> value, T target) {
Objects.requireNonNull(value);
return new BoolValue.Dynamic(() -> value.getValue() == target, $ -> value.setValue(target));
}

public static BoolValue.Dynamic boolValueOf(@NotNull IIntValue<?> value, int target) {
Objects.requireNonNull(value);
return new BoolValue.Dynamic(() -> value.getIntValue() == target, $ -> value.setIntValue(target));
}

public static BoolValue.Dynamic boolValueOf(@NotNull ILongValue<?> value, long target) {
Objects.requireNonNull(value);
return new BoolValue.Dynamic(() -> value.getLongValue() == target, $ -> value.setLongValue(target));
}

public static BoolValue.Dynamic boolValueOf(@NotNull IStringValue<?> value, @UnknownNullability String target) {
Objects.requireNonNull(value);
return new BoolValue.Dynamic(() -> Objects.equals(value.getStringValue(), target),
$ -> value.setStringValue(target));
}

public static <T> BoolValue.Dynamic boolValueOf(@NotNull IValue<T> value, @UnknownNullability T target) {
Objects.requireNonNull(value);
return new BoolValue.Dynamic(() -> Objects.equals(value.getValue(), target), $ -> value.setValue(target));
}
}
Loading
Loading