Skip to content

Commit

Permalink
Request drill changes, eliminates recipe info in drill GUI (GTNewHori…
Browse files Browse the repository at this point in the history
  • Loading branch information
querns authored Sep 9, 2023
1 parent 505850f commit cac7761
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
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;

Expand All @@ -21,17 +19,17 @@
import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.interfaces.tileentity.IMachineProgress;

public class GT_DisabledWhileActiveButton extends ButtonWidget {
public class GT_LockedWhileActiveButton extends ButtonWidget {

@NotNull
private final WeakReference<IMachineProgress> machineRef;
private final IMachineProgress machine;

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

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

Expand All @@ -41,11 +39,11 @@ public GT_DisabledWhileActiveButton(@NotNull IMachineProgress machine, @NotNull
@NotNull
@Override
public ButtonWidget setOnClick(@NotNull BiConsumer<ClickData, Widget> clickAction) {
return super.setOnClick((clickData, widget) -> isMachineActive().ifPresent(isActive -> {
if (!isActive) {
return super.setOnClick((clickData, widget) -> {
if (!machine.isActive()) {
clickAction.accept(clickData, widget);
}
}));
});
}

@NotNull
Expand All @@ -72,33 +70,21 @@ public Widget dynamicTooltip(@NotNull Supplier<List<String>> dynamicTooltip) {
});
}

@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);
if (machine.isActive()) {
final IDrawable[] copy = Arrays.copyOf(drawables, drawables.length + 1);
copy[drawables.length] = GT_UITextures.OVERLAY_BUTTON_LOCKED;
return copy;
}
return 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());
if (machine.isActive()) {
return ImmutableList.of(StatCollector.translateToLocal("GT5U.gui.button.forbidden_while_running"));
}
return ImmutableList.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2289,28 +2289,30 @@ protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inve
&& shouldDisplayCheckRecipeResult()))
.widget(new CheckRecipeResultSyncer(() -> checkRecipeResult, (result) -> checkRecipeResult = result));

// Display current recipe
screenElements.widget(
TextWidget.dynamicString(this::generateCurrentRecipeInfoString)
.setSynced(false)
.setTextAlignment(Alignment.CenterLeft)
.setEnabled(
widget -> (mOutputFluids != null && mOutputFluids.length > 0)
|| (mOutputItems != null && mOutputItems.length > 0)))
.widget(
new FakeSyncWidget.ListSyncer<>(
() -> mOutputFluids != null ? Arrays.asList(mOutputFluids) : Collections.emptyList(),
val -> mOutputFluids = val.toArray(new FluidStack[0]),
NetworkUtils::writeFluidStack,
NetworkUtils::readFluidStack))
.widget(
new FakeSyncWidget.ListSyncer<>(
() -> mOutputItems != null ? Arrays.asList(mOutputItems) : Collections.emptyList(),
val -> mOutputItems = val.toArray(new ItemStack[0]),
NetworkUtils::writeItemStack,
NetworkUtils::readItemStack))
.widget(new FakeSyncWidget.IntegerSyncer(() -> mProgresstime, val -> mProgresstime = val))
.widget(new FakeSyncWidget.IntegerSyncer(() -> mMaxProgresstime, val -> mMaxProgresstime = val));
if (showRecipeTextInGUI()) {
// Display current recipe
screenElements.widget(
TextWidget.dynamicString(this::generateCurrentRecipeInfoString)
.setSynced(false)
.setTextAlignment(Alignment.CenterLeft)
.setEnabled(
widget -> (mOutputFluids != null && mOutputFluids.length > 0)
|| (mOutputItems != null && mOutputItems.length > 0)))
.widget(
new FakeSyncWidget.ListSyncer<>(
() -> mOutputFluids != null ? Arrays.asList(mOutputFluids) : Collections.emptyList(),
val -> mOutputFluids = val.toArray(new FluidStack[0]),
NetworkUtils::writeFluidStack,
NetworkUtils::readFluidStack))
.widget(
new FakeSyncWidget.ListSyncer<>(
() -> mOutputItems != null ? Arrays.asList(mOutputItems) : Collections.emptyList(),
val -> mOutputItems = val.toArray(new ItemStack[0]),
NetworkUtils::writeItemStack,
NetworkUtils::readItemStack))
.widget(new FakeSyncWidget.IntegerSyncer(() -> mProgresstime, val -> mProgresstime = val))
.widget(new FakeSyncWidget.IntegerSyncer(() -> mMaxProgresstime, val -> mMaxProgresstime = val));
}

screenElements.widget(
new TextWidget(GT_Utility.trans("144", "Missing Turbine Rotor")).setDefaultColor(COLOR_TEXT_WHITE.get())
Expand All @@ -2328,6 +2330,10 @@ && shouldDisplayCheckRecipeResult()))
}));
}

protected boolean showRecipeTextInGUI() {
return true;
}

@TestOnly
protected void setEnergyHatches(ArrayList<GT_MetaTileEntity_Hatch_Energy> EnergyHatches) {
this.mEnergyHatches = EnergyHatches;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import gregtech.api.enums.ItemList;
import gregtech.api.enums.Materials;
import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.gui.widgets.GT_DisabledWhileActiveButton;
import gregtech.api.gui.widgets.GT_LockedWhileActiveButton;
import gregtech.api.interfaces.IChunkLoader;
import gregtech.api.interfaces.IHatchElement;
import gregtech.api.interfaces.ITexture;
Expand Down Expand Up @@ -789,6 +789,11 @@ protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inve
.widget(new FakeSyncWidget.StringSyncer(() -> shutdownReason, newString -> shutdownReason = newString));
}

@Override
protected boolean showRecipeTextInGUI() {
return false;
}

/**
* Adds additional buttons to the main button row. You do not need to set the position.
*
Expand All @@ -805,7 +810,7 @@ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildCont
final int BUTTON_Y_LEVEL = 91;

builder.widget(
new GT_DisabledWhileActiveButton(this.getBaseMetaTileEntity(), builder)
new GT_LockedWhileActiveButton(this.getBaseMetaTileEntity(), builder)
.setOnClick((clickData, widget) -> mChunkLoadingEnabled = !mChunkLoadingEnabled)
.setPlayClickSound(true)
.setBackground(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.SoundResource;
import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.gui.widgets.GT_DisabledWhileActiveButton;
import gregtech.api.gui.widgets.GT_LockedWhileActiveButton;
import gregtech.api.interfaces.IHatchElement;
import gregtech.api.objects.GT_ChunkManager;
import gregtech.api.objects.ItemData;
Expand Down Expand Up @@ -623,7 +623,7 @@ protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inve
@Override
protected List<ButtonWidget> getAdditionalButtons(ModularWindow.Builder builder, UIBuildContext buildContext) {
return ImmutableList.of(
(ButtonWidget) new GT_DisabledWhileActiveButton(this.getBaseMetaTileEntity(), builder)
(ButtonWidget) new GT_LockedWhileActiveButton(this.getBaseMetaTileEntity(), builder)
.setOnClick((clickData, widget) -> adjustChunkRadius(clickData.mouseButton == 0))
.setPlayClickSound(true)
.setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_WORK_AREA)
Expand All @@ -639,12 +639,12 @@ protected List<ButtonWidget> getAdditionalButtons(ModularWindow.Builder builder,
StatCollector.translateToLocal("GT5U.gui.button.ore_drill_radius_2")))
.setTooltipShowUpDelay(TOOLTIP_DELAY)
.setSize(16, 16),
(ButtonWidget) new GT_DisabledWhileActiveButton(this.getBaseMetaTileEntity(), builder)
(ButtonWidget) new GT_LockedWhileActiveButton(this.getBaseMetaTileEntity(), builder)
.setOnClick((clickData, widget) -> replaceWithCobblestone = !replaceWithCobblestone)
.setPlayClickSound(true)
.setBackground(() -> {
if (replaceWithCobblestone) {
return new IDrawable[] { GT_UITextures.BUTTON_STANDARD,
return new IDrawable[] { GT_UITextures.BUTTON_STANDARD_PRESSED,
GT_UITextures.OVERLAY_REPLACE_COBBLE_ON };
}
return new IDrawable[] { GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_REPLACE_COBBLE_OFF };
Expand Down

0 comments on commit cac7761

Please sign in to comment.