Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Widget<?> getMainTextPanel(PanelSyncManager syncManager, int width, int h
listWidget.child(GTMultiblockTextUtil.addEnergyTierLine(workableElectricMachine, syncManager));
listWidget.child(GTMultiblockTextUtil.addEnergyUsageLine(workableElectricMachine, syncManager));
}

listWidget.child(GTMultiblockTextUtil.addWorkingStatusLine(rlMachine, syncManager));
listWidget.child(GTMultiblockTextUtil.addParallelLine(rlMachine, syncManager));
listWidget.child(GTMultiblockTextUtil.addBatchModeLine(rlMachine, syncManager));
listWidget.child(GTMultiblockTextUtil.addSubtickParallelsLine(rlMachine, syncManager));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.minecraftforge.fluids.FluidStack;

import java.util.Optional;
import java.util.function.Supplier;

public class GTMultiblockTextUtil {

Expand Down Expand Up @@ -68,6 +69,35 @@ public static TextWidget<?> addEnergyUsageLine(WorkableElectricMultiblockMachine
.setEnabledIf(widget -> isFormed.getBoolValue() && isActive.getBoolValue());
}

public static TextWidget<?> addEnergyUsageExactLine(WorkableElectricMultiblockMachine weMachine,
PanelSyncManager syncManager) {
LongSyncValue energyUsage = syncManager.getOrCreateSyncHandler("energyUsage", LongSyncValue.class,
() -> new LongSyncValue(() -> {
var energyList = weMachine.getEnergyContainer();
return Math.max(energyList.getInputVoltage(), energyList.getOutputVoltage());
}));
return addEnergyUsageExactLine(weMachine, syncManager, energyUsage);
}

public static TextWidget<?> addEnergyUsageExactLine(WorkableElectricMultiblockMachine weMachine,
PanelSyncManager syncManager, LongSyncValue energyUsage) {
BooleanSyncValue isFormed = syncManager.getOrCreateSyncHandler("isFormed", BooleanSyncValue.class,
() -> new BooleanSyncValue(weMachine::isFormed));

return IKey.dynamic(() -> {
if (energyUsage.getLongValue() <= 0) return Component.empty();
String energyFormatted = FormattingUtil.formatNumbers(energyUsage.getLongValue());
// wrap in text component to keep it from being formatted
Component voltageName = Component.literal(
GTValues.VNF[GTUtil.getTierByVoltage(energyUsage.getLongValue())]);

return Component.translatable("gtceu.multiblock.energy_consumption",
energyFormatted, voltageName).withStyle(ChatFormatting.GRAY);
})
.asWidget()
.setEnabledIf(widget -> isFormed.getBoolValue());
}

public static IKey addEnergyTierLine(boolean formed, int tier) {
if (!formed || tier < GTValues.ULV || tier > GTValues.MAX)
return IKey.EMPTY;
Expand Down Expand Up @@ -107,6 +137,24 @@ public static TextWidget<?> addProgressLine(IWorkableMultiController rlMachine,
.setEnabledIf(widget -> isFormed.getBoolValue() && isActive.getBoolValue());
}

public static TextWidget<?> addProgressLinePercentOnly(IWorkableMultiController rlMachine,
PanelSyncManager syncManager) {
BooleanSyncValue isFormed = syncManager.getOrCreateSyncHandler("isFormed", BooleanSyncValue.class,
() -> new BooleanSyncValue(rlMachine::isFormed));
BooleanSyncValue isActive = syncManager.getOrCreateSyncHandler("isActive", BooleanSyncValue.class,
() -> new BooleanSyncValue(() -> rlMachine.getRecipeLogic().isActive()));
DoubleSyncValue progressPercent = syncManager.getOrCreateSyncHandler("progressPercent", DoubleSyncValue.class,
() -> new DoubleSyncValue(() -> rlMachine.getRecipeLogic().getProgressPercent()));

return IKey.dynamic(() -> {
int currentProgress = (int) (progressPercent.getDoubleValue() * 100);
return Component.translatable("gtceu.multiblock.progress_percent", currentProgress);
})
.color(Color.WHITE.main)
.asWidget()
.setEnabledIf(widget -> isFormed.getBoolValue() && isActive.getBoolValue());
}

public static TextWidget<?> addEnergyTierLine(WorkableElectricMultiblockMachine rlMachine,
PanelSyncManager syncManager) {
BooleanSyncValue isFormed = syncManager.getOrCreateSyncHandler("isFormed", BooleanSyncValue.class,
Expand Down Expand Up @@ -222,6 +270,40 @@ public static TextWidget<?> addSteamUsageLine(SteamEnergyRecipeHandler steamRH,
.setEnabledIf((w) -> hasSteamHandler.getBoolValue());
}

public static TextWidget<?> addWorkingStatusLine(IWorkableMultiController rlMachine, PanelSyncManager syncManager) {
return addWorkingStatusLine(rlMachine, syncManager,
() -> Component.translatable("gtceu.multiblock.work_paused").withStyle(ChatFormatting.GOLD),
() -> Component.translatable("gtceu.multiblock.running").withStyle(ChatFormatting.GREEN),
() -> Component.translatable("gtceu.multiblock.idling").withStyle(ChatFormatting.GRAY));
}

public static TextWidget<?> addWorkingStatusLine(IWorkableMultiController rlMachine, PanelSyncManager syncManager,
Supplier<Component> workPaused,
Supplier<Component> runningPerfectly,
Supplier<Component> idling) {
BooleanSyncValue isFormed = syncManager.getOrCreateSyncHandler("isFormed", BooleanSyncValue.class,
() -> new BooleanSyncValue(rlMachine::isFormed));
BooleanSyncValue isActive = syncManager.getOrCreateSyncHandler("isActive", BooleanSyncValue.class,
() -> new BooleanSyncValue(() -> rlMachine.getRecipeLogic().isActive()));
BooleanSyncValue isWorkingEnabled = syncManager.getOrCreateSyncHandler("isWorkingEnabled",
BooleanSyncValue.class,
() -> new BooleanSyncValue(() -> rlMachine.getRecipeLogic().isWorkingEnabled()));

return IKey
.dynamic(() -> {
if (!isFormed.getBoolValue()) return Component.empty();
if (!isWorkingEnabled.getBoolValue()) {
return workPaused.get();
}
if (isActive.getBoolValue()) {
return runningPerfectly.get();
}
return idling.get();
})
.asWidget()
.setEnabledIf((w) -> isFormed.getBoolValue());
}

public static DynamicSyncedWidget<?> addOutputLines(IWorkableMultiController rlmachine,
PanelSyncManager syncManager) {
GenericSyncValue<GTRecipe> recipeSyncValue = syncManager.getOrCreateSyncHandler("GTRecipe",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,34 @@
import com.gregtechceu.gtceu.api.machine.multiblock.WorkableElectricMultiblockMachine;
import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic;
import com.gregtechceu.gtceu.api.misc.EnergyContainerList;
import com.gregtechceu.gtceu.api.mui.base.drawable.IKey;
import com.gregtechceu.gtceu.api.mui.drawable.Icon;
import com.gregtechceu.gtceu.api.mui.factory.PosGuiData;
import com.gregtechceu.gtceu.api.mui.utils.Alignment;
import com.gregtechceu.gtceu.api.mui.value.sync.BooleanSyncValue;
import com.gregtechceu.gtceu.api.mui.value.sync.LongSyncValue;
import com.gregtechceu.gtceu.api.mui.value.sync.PanelSyncManager;
import com.gregtechceu.gtceu.api.mui.widget.ParentWidget;
import com.gregtechceu.gtceu.api.mui.widget.Widget;
import com.gregtechceu.gtceu.api.mui.widgets.ListWidget;
import com.gregtechceu.gtceu.api.mui.widgets.SlotGroupWidget;
import com.gregtechceu.gtceu.api.mui.widgets.layout.Flow;
import com.gregtechceu.gtceu.api.pattern.TraceabilityPredicate;
import com.gregtechceu.gtceu.client.mui.screen.ModularPanel;
import com.gregtechceu.gtceu.client.mui.screen.UISettings;
import com.gregtechceu.gtceu.common.data.mui.GTMuiWidgets;
import com.gregtechceu.gtceu.common.mui.GTGuiTextures;
import com.gregtechceu.gtceu.common.mui.GTGuis;
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.gregtechceu.gtceu.utils.FormattingUtil;

import com.lowdragmc.lowdraglib.gui.widget.*;

import net.minecraft.ChatFormatting;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.Style;
import net.minecraft.world.level.block.Block;

import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
Expand Down Expand Up @@ -160,54 +182,136 @@ public static TraceabilityPredicate getHatchPredicates() {
.or(abilities(PartAbility.OUTPUT_LASER).setPreviewCount(1));
}

// @Override
// public void addDisplayText(List<Component> textList) {
// // super.addDisplayText(textList); idek what it does stop doing what you do for a minute pls
// // Assume That the Structure is ALWAYS formed, and has at least 1 In and 1 Out, there is never a case where this
// // does not occur.
// if (isFormed()) {
// if (!isWorkingEnabled()) {
// textList.add(Component.translatable("gtceu.multiblock.work_paused"));
// } else if (isActive()) {
// textList.add(Component.translatable("gtceu.multiblock.running"));
// textList.add(Component
// .translatable("gtceu.multiblock.active_transformer.max_input",
// FormattingUtil.formatNumbers(
// Math.abs(powerInput.getInputVoltage() * powerInput.getInputAmperage()))));
// textList.add(Component
// .translatable("gtceu.multiblock.active_transformer.max_output",
// FormattingUtil.formatNumbers(
// Math.abs(powerOutput.getOutputVoltage() * powerOutput.getOutputAmperage()))));
// textList.add(Component
// .translatable("gtceu.multiblock.active_transformer.average_in",
// FormattingUtil.formatNumbers(Math.abs(powerInput.getInputPerSec() / 20))));
// textList.add(Component
// .translatable("gtceu.multiblock.active_transformer.average_out",
// FormattingUtil.formatNumbers(Math.abs(powerOutput.getOutputPerSec() / 20))));
// if (!ConfigHolder.INSTANCE.machines.harmlessActiveTransformers) {
// textList.add(Component
// .translatable("gtceu.multiblock.active_transformer.danger_enabled"));
// }
// } else {
// textList.add(Component.translatable("gtceu.multiblock.idling"));
// }
// }
// }
//
// @Override
// public @NotNull Widget createUIWidget() {
// var group = new WidgetGroup(0, 0, 182 + 8, 117 + 8);
// group.addWidget(new DraggableScrollableWidgetGroup(4, 4, 182, 117).setBackground(getScreenTexture())
// .addWidget(new LabelWidget(4, 5, self().getBlockState().getBlock().getDescriptionId()))
// .addWidget(new ComponentPanelWidget(4, 17, this::addDisplayText)
// .setMaxWidthLimit(150)
// .clickHandler(this::handleDisplayClick)));
// group.setBackground(GuiTextures.BACKGROUND_INVERSE);
// return group;
// }

// @Override
// public @NotNull ModularUI createUI(@NotNull Player entityPlayer) {
// return new ModularUI(198, 208, this, entityPlayer).widget(new FancyMachineUIWidget(this, 198, 208));
// }
@Override
public ModularPanel buildUI(PosGuiData data, PanelSyncManager syncManager, UISettings settings) {
var panel = GTGuis.createPanel(this, 176, 176);

panel.child(GTMuiWidgets.createTitleBar(this.getDefinition(), 176))
.child(new ParentWidget<>()
.widthRel(0.95f)
.heightRel(.45f)
.margin(4, 0)
.left(3).top(5)
.child(Flow.row()
.child(getMainTextPanel(syncManager, 170, 84))))
.child(Flow.column()
.coverChildren()
.leftRel(1.0f)
.reverseLayout(true)
.bottom(16)
.padding(0, 8, 4, 4)
.childPadding(2)
.background(GTGuiTextures.BACKGROUND.getSubArea(0.25f, 0f, 1.0f, 1.0f))
.child(GTMuiWidgets.createPowerButton(this, syncManager))
.child(GTMuiWidgets.createVoidingButton(this, syncManager))
.excludeAreaInXei())
.child(SlotGroupWidget.playerInventory(false).left(7).bottom(7));
return panel;
}

public Widget<?> getMainTextPanel(PanelSyncManager syncManager, int width, int height) {
var parentWidget = new ParentWidget<>();
var listWidget = new ListWidget<>();
listWidget
.width(width - 6)
.height(height - 6)
.childSeparator(Icon.EMPTY_2PX)
.crossAxisAlignment(Alignment.CrossAxis.START)
.alignX(Alignment.CenterLeft)
.left(3)
.top(3);
parentWidget.size(width, height)
.background(GTGuiTextures.MUI_DISPLAY);
// Machine generic sync handlers
BooleanSyncValue isFormed = syncManager.getOrCreateSyncHandler("isFormed", BooleanSyncValue.class,
() -> new BooleanSyncValue(this::isFormed));
BooleanSyncValue workingEnabled = syncManager.getOrCreateSyncHandler("workingEnabled", BooleanSyncValue.class,
() -> new BooleanSyncValue(this.recipeLogic::isWorkingEnabled, this.recipeLogic::setWorkingEnabled));
BooleanSyncValue active = syncManager.getOrCreateSyncHandler("isActive", BooleanSyncValue.class,
() -> new BooleanSyncValue(this.recipeLogic::isActive));

// Machine specific sync handlers
// These will not be called anywhere else, so we can create them directly instead of using
// getOrCreateSyncHandler

LongSyncValue inputVoltage = new LongSyncValue(this.powerInput::getInputVoltage);
syncManager.syncValue("inputVoltage", inputVoltage);

LongSyncValue outputVoltage = new LongSyncValue(this.powerOutput::getOutputVoltage);
syncManager.syncValue("outputVoltage", outputVoltage);

LongSyncValue inputAmperage = new LongSyncValue(this.powerInput::getInputAmperage);
syncManager.syncValue("inputAmperage", inputAmperage);

LongSyncValue outputAmperage = new LongSyncValue(this.powerOutput::getOutputAmperage);
syncManager.syncValue("outputAmperage", outputAmperage);

LongSyncValue inputPerSec = new LongSyncValue(this.powerInput::getInputPerSec);
syncManager.syncValue("inputPerSec", inputPerSec);

LongSyncValue outputPerSec = new LongSyncValue(this.powerOutput::getOutputPerSec);
syncManager.syncValue("outputPerSec", outputPerSec);

listWidget.child(IKey.lang(Component.translatable("gtceu.multiblock.work_paused"))
.asWidget()
.setEnabledIf((widget) -> isFormed.getBoolValue() && !workingEnabled.getBoolValue()));

listWidget.child(IKey.lang(Component.translatable("gtceu.multiblock.running"))
.asWidget()
.setEnabledIf(
(widget) -> isFormed.getBoolValue() && workingEnabled.getBoolValue() && active.getBoolValue()));

listWidget.child(IKey.dynamic(() -> Component
.translatable("gtceu.multiblock.active_transformer.max_input",
FormattingUtil.formatNumbers(
Math.abs(inputVoltage.getLongValue() * inputAmperage.getLongValue()))))
.asWidget()
.setEnabledIf(
(widget) -> isFormed.getBoolValue() && workingEnabled.getBoolValue() && active.getBoolValue()));

listWidget.child(IKey.dynamic(() -> Component
.translatable("gtceu.multiblock.active_transformer.max_output",
FormattingUtil.formatNumbers(
Math.abs(outputVoltage.getLongValue() * outputAmperage.getLongValue()))))
.asWidget()
.setEnabledIf(
(widget) -> isFormed.getBoolValue() && workingEnabled.getBoolValue() && active.getBoolValue()));

listWidget.child(IKey.dynamic(() -> Component
.translatable("gtceu.multiblock.active_transformer.average_in",
FormattingUtil.formatNumbers(Math.abs(inputPerSec.getLongValue() / 20))))
.asWidget()
.setEnabledIf(
(widget) -> isFormed.getBoolValue() && workingEnabled.getBoolValue() && active.getBoolValue()));

listWidget.child(IKey.dynamic(() -> Component
.translatable("gtceu.multiblock.active_transformer.average_out",
FormattingUtil.formatNumbers(Math.abs(outputPerSec.getLongValue() / 20))))
.asWidget()
.setEnabledIf(
(widget) -> isFormed.getBoolValue() && workingEnabled.getBoolValue() && active.getBoolValue()));

listWidget.child(IKey.lang(Component.translatable("gtceu.multiblock.active_transformer.danger_enabled"))
.asWidget()
.setEnabledIf((widget) -> isFormed.getBoolValue() && workingEnabled.getBoolValue() &&
active.getBoolValue() && !ConfigHolder.INSTANCE.machines.harmlessActiveTransformers));

listWidget.child(IKey.lang(Component.translatable("gtceu.multiblock.idling"))
.asWidget()
.setEnabledIf((widget) -> isFormed.getBoolValue() && workingEnabled.getBoolValue() &&
!active.getBoolValue()));

listWidget.child(IKey.dynamic(() -> {
Component tooltip = Component.translatable("gtceu.multiblock.invalid_structure.tooltip")
.withStyle(ChatFormatting.GRAY);
return Component.translatable("gtceu.multiblock.invalid_structure")
.withStyle(Style.EMPTY.withColor(ChatFormatting.RED)
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, tooltip)));
})
.asWidget()
.setEnabledIf((widget) -> !isFormed.getBoolValue()));

parentWidget.child(listWidget);
return parentWidget;
}
}
Loading