Skip to content

Commit

Permalink
Adds status messages, action buttons to UI of multiblock drills (GTNe…
Browse files Browse the repository at this point in the history
…wHorizons#2270)

* Adds several UI elements to multiblock drills

* Spotless

* Adds formatNumbers calls in places where it'd been missed

* Eliminate wildcard import

* Add @NotNull annotations to new fields and methods
  • Loading branch information
querns authored Sep 8, 2023
1 parent e4f17b7 commit 7f83771
Show file tree
Hide file tree
Showing 15 changed files with 808 additions and 56 deletions.
13 changes: 13 additions & 0 deletions src/main/java/gregtech/api/gui/modularui/GT_UITextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ public class GT_UITextures {
.fullImage(GregTech.ID, "gui/overlay_button/batch_mode_off_disabled");
public static final UITexture OVERLAY_BUTTON_FORBIDDEN = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/forbidden");
public static final UITexture OVERLAY_BUTTON_LOCKED = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/lock_small");
public static final UITexture OVERLAY_BUTTON_DOWN_TIERING_ON = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/down_tiering_on");
public static final UITexture OVERLAY_BUTTON_DOWN_TIERING_OFF = UITexture
Expand Down Expand Up @@ -366,6 +368,17 @@ public class GT_UITextures {
.fullImage(GregTech.ID, "gui/overlay_button/use_processing_state.png");
public static final UITexture OVERLAY_BUTTON_USE_INVERTED_PROCESSING_STATE = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/use_inverted_processing_state.png");
public static final UITexture OVERLAY_CHUNK_LOADING = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/chunkloading");
public static final UITexture OVERLAY_CHUNK_LOADING_OFF = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/chunkloading_off");
public static final UITexture OVERLAY_WORK_AREA = UITexture.fullImage(GregTech.ID, "gui/overlay_button/work_area");
public static final UITexture OVERLAY_REPLACE_COBBLE_ON = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/replace_cobble_on");
public static final UITexture OVERLAY_REPLACE_COBBLE_OFF = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/replace_cobble_off");
public static final UITexture OVERLAY_RETRACT_PIPE = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/retract_pipes");

/**
* Can adjust size as needed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package gregtech.api.gui.widgets;

import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Supplier;

import net.minecraft.util.StatCollector;

import org.jetbrains.annotations.NotNull;

import com.google.common.collect.ImmutableList;
import com.gtnewhorizons.modularui.api.drawable.IDrawable;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.widget.Widget;
import com.gtnewhorizons.modularui.common.widget.ButtonWidget;
import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget;

import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.interfaces.tileentity.IMachineProgress;

public class GT_DisabledWhileActiveButton extends ButtonWidget {

@NotNull
private final WeakReference<IMachineProgress> machineRef;

public GT_DisabledWhileActiveButton(@NotNull IMachineProgress machine, @NotNull ModularWindow.Builder builder) {
super();
machineRef = new WeakReference<>(machine);

super.attachSyncer(
new FakeSyncWidget.BooleanSyncer(() -> isMachineActive().orElse(true), a -> {}),
builder,
(widget, aBoolean) -> widget.notifyTooltipChange());

super.dynamicTooltip(this::generateTooltip);
}

@NotNull
@Override
public ButtonWidget setOnClick(@NotNull BiConsumer<ClickData, Widget> clickAction) {
return super.setOnClick((clickData, widget) -> isMachineActive().ifPresent(isActive -> {
if (!isActive) {
clickAction.accept(clickData, widget);
}
}));
}

@NotNull
@Override
public Widget setBackground(@NotNull IDrawable... drawables) {
return super.setBackground(() -> appendLockedOverlay(drawables));
}

@NotNull
@Override
public Widget setBackground(@NotNull Supplier<IDrawable[]> drawablesSupplier) {
return super.setBackground(() -> appendLockedOverlay(drawablesSupplier.get()));
}

@NotNull
@Override
public Widget dynamicTooltip(@NotNull Supplier<List<String>> dynamicTooltip) {
return super.dynamicTooltip(() -> {
ImmutableList.Builder<String> tooltips = ImmutableList.<String>builder()
.addAll(dynamicTooltip.get());
tooltips.addAll(generateTooltip());

return tooltips.build();
});
}

@NotNull
private Optional<Boolean> isMachineActive() {
return Optional.ofNullable(machineRef.get())
.map(IMachineProgress::isActive);
}

@NotNull
private IDrawable[] appendLockedOverlay(@NotNull IDrawable[] drawables) {
return isMachineActive().map(isActive -> {
if (isActive) {
final IDrawable[] copy = Arrays.copyOf(drawables, drawables.length + 1);
copy[drawables.length] = GT_UITextures.OVERLAY_BUTTON_LOCKED;
return copy;
}
return drawables;
})
.orElse(drawables);
}

@NotNull
private List<String> generateTooltip() {
return isMachineActive().map(isActive -> {
if (isActive) {
return ImmutableList.of(StatCollector.translateToLocal("GT5U.gui.button.forbidden_while_running"));
}
return ImmutableList.<String>of();
})
.orElse(ImmutableList.of());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ public static boolean isRegistered(String id) {
* Machine had an internal error
*/
public static final CheckRecipeResult INTERNAL_ERROR = SimpleCheckRecipeResult.ofFailure("internal_error");
/** Multiblock ore drill has no drilling fluid */
public static final CheckRecipeResult NO_DRILLING_FLUID = SimpleCheckRecipeResult.ofFailure("no_drilling_fluid");
/** Multiblock drill is missing mining pipe */
public static final CheckRecipeResult MISSING_MINING_PIPE = SimpleCheckRecipeResult.ofFailure("no_mining_pipe");
/** Concrete backfiller is out of concrete */
public static final CheckRecipeResult BACKFILLER_NO_CONCRETE = SimpleCheckRecipeResult
.ofFailure("backfiller_no_concrete");

/**
* Cannot process recipe because the machine cannot handle required EUt.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,42 @@
import java.util.List;

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

import com.google.common.collect.ImmutableList;
import com.gtnewhorizons.modularui.api.math.Alignment;
import com.gtnewhorizons.modularui.common.widget.DynamicPositionedColumn;
import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget;
import com.gtnewhorizons.modularui.common.widget.SlotWidget;
import com.gtnewhorizons.modularui.common.widget.TextWidget;

import gregtech.api.GregTech_API;
import gregtech.api.enums.Materials;
import gregtech.api.interfaces.IHatchElement;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_Utility;

public abstract class GT_MetaTileEntity_ConcreteBackfillerBase extends GT_MetaTileEntity_DrillerBase {

private int mLastXOff = 0, mLastZOff = 0;

/** Used to drive the readout in the GUI for the backfiller's current y-level. */
private int clientYHead;

public GT_MetaTileEntity_ConcreteBackfillerBase(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
initRecipeResults();
}

public GT_MetaTileEntity_ConcreteBackfillerBase(String aName) {
super(aName);
initRecipeResults();
}

private void initRecipeResults() {
addResultMessage(STATE_UPWARD, true, "backfiller_working");
}

protected GT_Multiblock_Tooltip_Builder createTooltip(String aStructureName) {
Expand Down Expand Up @@ -107,6 +123,7 @@ protected boolean workingUpward(ItemStack aStack, int xDrill, int yDrill, int zD
} else {
workState = STATE_DOWNWARD;
stopMachine();
setShutdownReason(StatCollector.translateToLocal("GT5U.gui.text.backfiller_finished"));
return false;
}
}
Expand All @@ -123,7 +140,10 @@ private boolean isRefillableBlock(int aX, int aY, int aZ) {
}

private boolean tryRefillBlock(int aX, int aY, int aZ) {
if (!tryConsumeFluid()) return false;
if (!tryConsumeFluid()) {
setRuntimeFailureReason(CheckRecipeResultRegistry.BACKFILLER_NO_CONCRETE);
return false;
}
getBaseMetaTileEntity().getWorld()
.setBlock(aX, aY, aZ, GregTech_API.sBlockConcretes, 8, 3);
return true;
Expand All @@ -136,4 +156,21 @@ private boolean tryConsumeFluid() {
}
return true;
}

@Override
protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inventorySlot) {
super.drawTexts(screenElements, inventorySlot);
screenElements
.widget(
TextWidget
.dynamicString(
() -> StatCollector.translateToLocalFormatted(
"GT5U.gui.text.backfiller_current_area",
GT_Utility.formatNumbers(clientYHead)))
.setSynced(false)
.setTextAlignment(Alignment.CenterLeft)
.setEnabled(widget -> getBaseMetaTileEntity().isActive() && workState == STATE_UPWARD))
.widget(new FakeSyncWidget.IntegerSyncer(this::getYHead, newInt -> clientYHead = newInt))
.widget(new FakeSyncWidget.IntegerSyncer(() -> workState, newInt -> workState = newInt));
}
}
Loading

0 comments on commit 7f83771

Please sign in to comment.