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

Rework MuTEGUI structure #2429

Merged
merged 7 commits into from
Dec 27, 2023
Merged
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
56 changes: 56 additions & 0 deletions src/main/java/gregtech/api/gui/GUIHost.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package gregtech.api.gui;

import java.util.Objects;

import javax.annotation.Nonnull;

import net.minecraft.item.ItemStack;

import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;

public interface GUIHost extends ITileWithModularUI {

@Nonnull
@Override
default ModularWindow createWindow(UIBuildContext uiContext) {
Objects.requireNonNull(uiContext);
GUIProvider<?> gui = getGUI(uiContext);
return gui.openGUI(uiContext);
}

/**
* Width of the GUI when its being displayed
*/
default int getWidth() {
return 170;
}

default int getHeight() {
return 192;
}

@Nonnull
GUIProvider<?> getGUI(@Nonnull UIBuildContext uiContext);

ItemStack getAsItem();

String getMachineName();

default boolean hasItemInput() {
return true;
}

default boolean hasItemOutput() {
return true;
}

default boolean hasFluidInput() {
return true;
}

default boolean hasFluidOutput() {
return true;
}
}
38 changes: 38 additions & 0 deletions src/main/java/gregtech/api/gui/GUIProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package gregtech.api.gui;

import java.util.Objects;

import javax.annotation.Nonnull;

import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.ModularWindow.Builder;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;

public abstract class GUIProvider<T extends GUIHost> {

@Nonnull
protected final T host;

public GUIProvider(@Nonnull T host) {
this.host = host;
}

@Nonnull
public ModularWindow openGUI(@Nonnull UIBuildContext uiContext) {
Builder builder = Objects.requireNonNull(ModularWindow.builder(host.getWidth(), host.getHeight()));
if (shouldBindPlayerInventory()) {
builder.bindPlayerInventory(uiContext.getPlayer());
}
attachSynchHandlers(builder, uiContext);
addWidgets(builder, uiContext);
return Objects.requireNonNull(builder.build());
}

protected abstract void attachSynchHandlers(@Nonnull Builder builder, @Nonnull UIBuildContext uiContext);

protected abstract void addWidgets(@Nonnull Builder builder, @Nonnull UIBuildContext uiContext);

protected boolean shouldBindPlayerInventory() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public interface IMachineProgress extends IHasWorldObjectAndCoords {
*/
boolean isAllowedToWork();

default void setAllowedToWork(Boolean allowedToWork) {
if (allowedToWork) {
enableWorking();
} else {
disableWorking();
}
}

/**
* used to control Machines via Redstone Signal Strength by special Covers In case of 0 the Machine is very likely
* doing nothing, or is just not being controlled at all.
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/gregtech/api/logic/FluidInventoryLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,21 @@ public Map<Fluid, Long> getMapOfStoredFluids() {
return map;
}

/**
* Return a scrollable widget with only the inventory.
*/
@Nonnull
public Widget getGuiPart() {
return getGUIPart(DEFAULT_COLUMNS_PER_ROW);
}

/**
* Return a scrollable widget with only the inventory.
*/
@Nonnull
public Widget getGUIPart(int columnsPerRow) {
final Scrollable scrollable = new Scrollable().setVerticalScroll();
final Scrollable scrollable = new Scrollable();
scrollable.setVerticalScroll();
for (int rows = 0; rows * 4 < inventory.getTanks(); rows++) {
final int columnsToMake = Math.min(inventory.getTanks() - rows * 4, 4);
for (int column = 0; column < columnsToMake; column++) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/gregtech/api/logic/ItemInventoryLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,17 @@ public void update(boolean shouldSort) {
}
}

/**
* Return a scrollable widget with only the inventory.
*/
@Nonnull
public Widget getGuiPart() {
return getGUIPart(DEFAULT_COLUMNS_PER_ROW);
}

/**
* Return a scrollable widget with only the inventory.
*/
@Nonnull
public Widget getGUIPart(int columnsPerRow) {
final Scrollable scrollable = new Scrollable();
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/gregtech/api/logic/MuTEProcessingLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.fluids.FluidStack;

import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.widget.Widget;
import com.gtnewhorizons.modularui.common.widget.Scrollable;

import gregtech.api.enums.InventoryType;
import gregtech.api.logic.interfaces.ProcessingLogicHost;
import gregtech.api.recipe.check.CheckRecipeResult;
Expand Down Expand Up @@ -251,5 +255,13 @@ public void loadFromNBT(@Nonnull NBTTagCompound logicNBT) {
}
}

/**
* Returns a gui part, which will be displayed in a separate tab on the machine's gui.
*/
@Nonnull
public Widget getGUIPart(ModularWindow.Builder builder) {
return new Scrollable();
}

// #endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,40 @@ public interface ProcessingLogicHost<P extends MuTEProcessingLogic<P>>

boolean isInputSeparated();

void setInputSeparation(Boolean inputSeparation);

default boolean supportsInputSeparation() {
return true;
}

default boolean getDefaultInputSeparationMode() {
return false;
}

boolean isRecipeLockingEnabled();

void setRecipeLocking(Boolean recipeLocked);

default boolean supportsSingleRecipeLocking() {
return true;
}

default boolean getDefaultRecipeLockingMode() {
return false;
}

default boolean supportsBatchMode() {
return true;
}

void setBatchMode(Boolean batchMode);

boolean isBatchModeEnabled();

default boolean getDefaultBatchMode() {
return false;
}

/**
* Get what the machine can void or not
*/
Expand Down
23 changes: 0 additions & 23 deletions src/main/java/gregtech/api/metatileentity/BaseTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -603,29 +603,6 @@ public boolean useModularUI() {
return false;
}

@Override
public ModularWindow createWindow(UIBuildContext buildContext) {
if (!useModularUI()) return null;

buildContext.setValidator(getValidator());
final ModularWindow.Builder builder = ModularWindow.builder(getGUIWidth(), getGUIHeight());
builder.setBackground(getGUITextureSet().getMainBackground());
builder.setGuiTint(getGUIColorization());
if (doesBindPlayerInventory()) {
bindPlayerInventoryUI(builder, buildContext);
}
addUIWidgets(builder, buildContext);
addTitleToUI(builder);
addCoverTabs(builder, buildContext);
final IConfigurationCircuitSupport csc = getConfigurationCircuitSupport();
if (csc != null && csc.allowSelectCircuit()) {
addConfigurationCircuitSlot(builder);
} else {
addGregTechLogo(builder);
}
return builder.build();
}

/*
* IC2 Energy Compat
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,27 @@ public GUITextureSet getGUITextureSet() {
public ItemStack getMachineCraftingIcon() {
return getMetaTileEntity() != null ? getMetaTileEntity().getMachineCraftingIcon() : null;
}

@Override
public ModularWindow createWindow(UIBuildContext buildContext) {
if (!useModularUI()) return null;

buildContext.setValidator(getValidator());
final ModularWindow.Builder builder = ModularWindow.builder(getGUIWidth(), getGUIHeight());
builder.setBackground(getGUITextureSet().getMainBackground());
builder.setGuiTint(getGUIColorization());
if (doesBindPlayerInventory()) {
bindPlayerInventoryUI(builder, buildContext);
}
addUIWidgets(builder, buildContext);
addTitleToUI(builder);
addCoverTabs(builder, buildContext);
final IConfigurationCircuitSupport csc = getConfigurationCircuitSupport();
if (csc != null && csc.allowSelectCircuit()) {
addConfigurationCircuitSlot(builder);
} else {
addGregTechLogo(builder);
}
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import net.minecraft.util.ChunkCoordinates;
import net.minecraftforge.common.util.ForgeDirection;

import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;

import gregtech.api.enums.InventoryType;
import gregtech.api.gui.GUIHost;
import gregtech.api.logic.FluidInventoryLogic;
import gregtech.api.logic.ItemInventoryLogic;
import gregtech.api.logic.interfaces.FluidInventoryLogicHost;
Expand All @@ -20,7 +18,7 @@
import gregtech.api.multitileentity.enums.MultiTileCasingPurpose;

public interface IMultiBlockController
extends IMultiTileEntity, FluidInventoryLogicHost, ItemInventoryLogicHost, UpgradableMuTE, PowerLogicHost {
extends IMultiTileEntity, FluidInventoryLogicHost, ItemInventoryLogicHost, UpgradableMuTE, PowerLogicHost, GUIHost {

boolean checkStructure(boolean aForceReset);

Expand All @@ -40,6 +38,8 @@ public interface IMultiBlockController

ModularWindow createWindowGUI(UIBuildContext buildContext);

PowerLogic getPowerLogic();

UUID registerItemInventory(int slots, int tier, @Nonnull InventoryType type, boolean isUpgradeInventory);

ItemInventoryLogic unregisterItemInventory(@Nonnull UUID id, @Nonnull InventoryType type);
Expand Down
Loading
Loading