Skip to content
Open
4 changes: 2 additions & 2 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -1938,8 +1938,8 @@
"config.gtceu.option.treeFellingDelay": "ʎɐןǝᗡbuıןןǝℲǝǝɹʇ",
"config.gtceu.option.tungstensteelBoilerHeatSpeed": "pǝǝdSʇɐǝHɹǝןıoᗺןǝǝʇsuǝʇsbunʇ",
"config.gtceu.option.tungstensteelBoilerMaxTemperature": "ǝɹnʇɐɹǝdɯǝ⟘xɐWɹǝןıoᗺןǝǝʇsuǝʇsbunʇ",
"config.gtceu.option.ui": "ın",
"config.gtceu.option.type": "ǝdʎʇ",
"config.gtceu.option.ui": "ın",
"config.gtceu.option.universalHazards": "spɹɐzɐHןɐsɹǝʌıun",
"config.gtceu.option.updateIntervals": "sןɐʌɹǝʇuIǝʇɐpdn",
"config.gtceu.option.useDarkThemeByDefault": "ʇןnɐɟǝᗡʎᗺǝɯǝɥ⟘ʞɹɐᗡǝsn",
Expand Down Expand Up @@ -3572,7 +3572,7 @@
"gtceu.packer": "ɹǝʞɔɐԀ",
"gtceu.part_sharing.disabled": "pǝןqɐsıᗡㄣ§ buıɹɐɥS ʞɔoןqıʇןnW",
"gtceu.part_sharing.enabled": "pǝןqɐuƎɐ§ buıɹɐɥS ʞɔoןqıʇןnW",
"gtceu.placeholder_editor.constant_value": "˙ʇuɐʇsuoɔ ɐ ɥʇıʍ ʇı buıɔɐןdǝɹ ɹǝpısuoƆ\n˙ʇןnsǝɹ ǝɯɐs ǝɥʇ oʇ sǝʇɐnןɐʌǝ sʎɐʍןɐ uoıssǝɹdxǝ sıɥ⟘",
"gtceu.placeholder_editor.constant_value": "˙ʇuɐʇsuoɔ ɐ ɥʇıʍ ʇı buıɔɐןdǝɹ ɹǝpısuoƆ\n˙,%s, oʇ sǝʇɐnןɐʌǝ sʎɐʍןɐ uoıssǝɹdxǝ sıɥ⟘",
"gtceu.placeholder_editor.extra_closing_bracket": "ʇǝʞɔɐɹq buısoןɔ ɐɹʇxƎ",
"gtceu.placeholder_editor.no_placeholder": "ʇsıxǝ ʇou sǝop ,%s, ǝɯɐu ɥʇıʍ ɹǝpןoɥǝɔɐןԀ",
"gtceu.placeholder_editor.unclosed_bracket": ")\"}\"( ʇǝʞɔɐɹq pǝsoןɔu∩",
Expand Down
4 changes: 2 additions & 2 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1938,8 +1938,8 @@
"config.gtceu.option.treeFellingDelay": "treeFellingDelay",
"config.gtceu.option.tungstensteelBoilerHeatSpeed": "tungstensteelBoilerHeatSpeed",
"config.gtceu.option.tungstensteelBoilerMaxTemperature": "tungstensteelBoilerMaxTemperature",
"config.gtceu.option.ui": "ui",
"config.gtceu.option.type": "type",
"config.gtceu.option.ui": "ui",
"config.gtceu.option.universalHazards": "universalHazards",
"config.gtceu.option.updateIntervals": "updateIntervals",
"config.gtceu.option.useDarkThemeByDefault": "useDarkThemeByDefault",
Expand Down Expand Up @@ -3572,7 +3572,7 @@
"gtceu.packer": "Packer",
"gtceu.part_sharing.disabled": "Multiblock Sharing §4Disabled",
"gtceu.part_sharing.enabled": "Multiblock Sharing §aEnabled",
"gtceu.placeholder_editor.constant_value": "This expression always evaluates to the same result.\nConsider replacing it with a constant.",
"gtceu.placeholder_editor.constant_value": "This expression always evaluates to '%s'.\nConsider replacing it with a constant.",
"gtceu.placeholder_editor.extra_closing_bracket": "Extra closing bracket",
"gtceu.placeholder_editor.no_placeholder": "Placeholder with name '%s' does not exist",
"gtceu.placeholder_editor.unclosed_bracket": "Unclosed bracket (\"}\")",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.gregtechceu.gtceu.api.placeholder.exceptions.UnexpectedBracketException;
import com.gregtechceu.gtceu.api.placeholder.exceptions.UnknownPlaceholderException;
import com.gregtechceu.gtceu.client.renderer.monitor.IMonitorRenderer;
import com.gregtechceu.gtceu.common.mui.drawable.BorderDrawable;
import com.gregtechceu.gtceu.common.mui.widgets.textfield.CodeEditorWidget;
import com.gregtechceu.gtceu.data.lang.LangHandler;
import com.gregtechceu.gtceu.utils.GTUtil;
Expand All @@ -23,18 +22,15 @@
import brachy.modularui.api.drawable.IDrawable;
import brachy.modularui.api.drawable.Text;
import brachy.modularui.api.value.IBoolValue;
import brachy.modularui.api.value.IIntValue;
import brachy.modularui.api.value.IStringValue;
import brachy.modularui.api.widget.IWidget;
import brachy.modularui.drawable.GuiTextures;
import brachy.modularui.screen.ModularPanel;
import brachy.modularui.screen.RichTooltip;
import brachy.modularui.screen.viewport.GuiContext;
import brachy.modularui.value.StringValue;
import brachy.modularui.value.sync.*;
import brachy.modularui.widgets.ButtonWidget;
import brachy.modularui.widgets.SortableListWidget;
import brachy.modularui.widgets.TextWidget;
import brachy.modularui.widgets.ToggleButton;
import brachy.modularui.widgets.*;
import brachy.modularui.widgets.layout.Flow;
import brachy.modularui.widgets.slot.ItemSlot;
import brachy.modularui.widgets.textfield.TextFieldWidget;
Expand Down Expand Up @@ -246,18 +242,30 @@ public static IPanelHandler createPlaceholderEditor(String name, PanelSyncManage
PlaceholderContext ctx,
IStringValue<?> code,
@Nullable DoubleSyncValue scaleDouble,
@Nullable IIntValue<?> updateInterval,
@Nullable IStringValue<?> updateInterval,
@Nullable IBoolValue<?> pause,
@Nullable Runnable updateText) {
IPanelHandler helpPanel = syncManager.syncedPanel("placeholder_language_help",
true,
(syncManager1, panelHandler1) -> createHelpPanel());
InteractionSyncHandler runCodeOnce = new InteractionSyncHandler();
if (updateText != null) runCodeOnce.setOnMousePressed(mouseData -> updateText.run());
syncManager.syncValue("run_code_sync_handler", runCodeOnce);
// because the args are nullable, intellij complains about everything, even though childIf is used
// noinspection DataFlowIssue
return syncManager.syncedPanel(name, true, (psm, handler) -> new ModularPanel<>(name)
InteractionSyncHandler runCodeOnce = updateText == null ? null : new InteractionSyncHandler();
if (updateText != null) runCodeOnce.setOnMousePressed(mouseData -> {
if (!mouseData.isClient())
updateText.run();
});
return syncManager.syncedPanel(name, true, (psm, handler) -> createPlaceholderEditorPanel(
name, ctx, code, scaleDouble, updateInterval, pause, helpPanel, runCodeOnce));
}

public static ModularPanel<?> createPlaceholderEditorPanel(String name,
PlaceholderContext ctx,
IStringValue<?> code,
@Nullable DoubleSyncValue scaleDouble,
@Nullable IStringValue<?> updateInterval,
@Nullable IBoolValue<?> pause,
IPanelHandler helpPanel,
@Nullable InteractionSyncHandler runCodeOnce) {
return new ModularPanel<>(name)
.size(400, 250)
.resizeableOnDrag(true)
.excludeAreaInRecipeViewer()
Expand All @@ -272,7 +280,7 @@ public static IPanelHandler createPlaceholderEditor(String name, PanelSyncManage
.addTooltipLine(
Text.lang("gtceu.gui.computer_monitor_cover.slot_tooltip", i))))
.child(Flow.column()
.widthRel(.8f)
.widthRel(.7f)
.padding(5)
.child(Flow.row()
.height(20)
Expand All @@ -290,56 +298,57 @@ public static IPanelHandler createPlaceholderEditor(String name, PanelSyncManage
.childIf(updateInterval != null, () -> new TextFieldWidget()
.setNumbers(1, 1000)
.setDefaultNumber(1)
.value(SyncHandlers.string(
() -> String.valueOf(updateInterval.getIntValue()),
s -> updateInterval.setIntValue(Integer.parseInt(s))))
.value(updateInterval)
.marginLeft(4))
.childIf(pause != null, () -> new ToggleButton()
.value(pause)
.background(false, GuiTextures.PAUSE)
.background(true, GuiTextures.PLAY)
.marginLeft(10)
.marginRight(10)
.background(true, GuiTextures.MC_BUTTON)
.hoverBackground(true, GuiTextures.MC_BUTTON_HOVERED)
.background(false, GuiTextures.MC_BUTTON)
.hoverBackground(false, GuiTextures.MC_BUTTON_HOVERED)
.overlay(false, GuiTextures.PAUSE)
.overlay(true, GuiTextures.PLAY)
.addTooltip(false, Text.lang("gtceu.gui.central_monitor.pause"))
.addTooltip(true, Text.lang("gtceu.gui.central_monitor.resume"))
.margin(4))
.childIf(updateText != null, () -> new ButtonWidget<>()
.background(GuiTextures.RIGHTLOAD)
.hoverBackground(GuiTextures.RIGHTLOAD, new BorderDrawable())
.addTooltip(true, Text.lang("gtceu.gui.central_monitor.resume")))
.childIf(runCodeOnce != null, () -> new ButtonWidget<>()
.overlay(GuiTextures.RIGHTLOAD)
.addTooltipLine(Text.lang("gtceu.gui.central_monitor.update_once"))
.syncHandler("run_code_sync_handler"))
.syncHandler(runCodeOnce))
.child(new ButtonWidget<>()
.background(GuiTextures.HELP)
.hoverBackground(GuiTextures.HELP, new BorderDrawable())
.margin(4)
.right(0)
.overlay(GuiTextures.HELP)
.onMousePressed((GuiContext context, int button) -> {
helpPanel.openPanel();
return true;
})))
.child(new CodeEditorWidget<>(PlaceholderHandler.LANG_DEFINITION)
.child(new CodeEditorWidget<>(LANG_DEFINITION)
.value(code)
.langContext(ctx)
.widthRel(.95f)
.fullWidth()
.heightRelOffset(1, -25)))
.child(new SortableListWidget<String>()
.widthRel(.2f)
.child(new ListWidget<>()
.widthRel(.25f)
.right(0)
.paddingBottom(5)
.excludeAreaInRecipeViewer()
.fullHeight()
.children(PlaceholderHandler.getAllPlaceholderNames()
.stream()
.sorted()
.map(SortableListWidget.Item::new)
.map(w -> w
.child(new TextWidget<>(w.getWidgetValue())
.sizeRel(1)
.map(s -> (IWidget) Flow.row()
.coverChildren()
.child(new TextWidget<>(s)
.center())
.tooltip(new RichTooltip()
.addDrawableLines(LangHandler
.getSingleOrMultiLang(
"gtceu.placeholder_info." + w.getWidgetValue())
"gtceu.placeholder_info." + s)
.stream()
.map(Text::of)
.map(key -> (IDrawable) key)
.toList())))
.toList()))));
.toList())));
}

public static ModularPanel<?> createHelpPanel() {
Expand Down Expand Up @@ -377,7 +386,6 @@ public static class TokenFormatter implements CodeEditorWidget.ITokenFormatter<P
private final Stack<Integer> viewStarts = new Stack<>();
private final Stack<String> openPlaceholders = new Stack<>();
private int ifDepth = 0;
private Component endOfLineValue = null;

@Override
public Component apply(String s, @Nullable PlaceholderContext ctx) {
Expand Down Expand Up @@ -469,36 +477,20 @@ public Component apply(String s, @Nullable PlaceholderContext ctx) {
openPlaceholders.pop();
}
if (!pureStarts.empty()) {
String result = processPlaceholders(everything.substring(pureStarts.peek()), ctx).toString();
result = result.replaceAll("\\n", "\\\\n");
String result = processPlaceholders(everything.substring(pureStarts.peek()), ctx)
.toString()
.replaceAll("\\n", "\\\\n");
int popped = pureStarts.peek();
pureStarts.pop();
viewStarts.pop();
if (!everything.substring(popped).contains(" ")) return Component.literal(s);
if (result.length() > 10) {
result = result.substring(0, 10) + "…";
}
endOfLineValue = null;
return Component.literal(s)
.append(Component.literal("='%s'".formatted(result))
.withStyle(ChatFormatting.GRAY, ChatFormatting.UNDERLINE)
.withStyle(style -> style.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
Component.translatable("gtceu.placeholder_editor.constant_value")))
.withInsertion("")));
.withStyle(style -> style.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
Component.translatable("gtceu.placeholder_editor.constant_value", result)))
Comment thread
TarLaboratories marked this conversation as resolved.
.withInsertion(""));
}
if (!viewStarts.empty() && ctx != null && !ctx.level().isClientSide()) {
String result = processPlaceholders(everything.substring(viewStarts.peek()), ctx).toString();
result = result.replaceAll("\\n", "\\\\n");
if (result.length() > 10) {
result = result.substring(0, 10) + "…";
}
viewStarts.pop();
endOfLineValue = Component.literal("='%s'".formatted(result))
Comment thread
TarLaboratories marked this conversation as resolved.
.withStyle(ChatFormatting.DARK_GRAY)
.withStyle(style -> style.withInsertion(""));
return Component.literal(s);
} else if (!viewStarts.empty()) viewStarts.pop();
if (!viewStarts.empty()) viewStarts.pop();
return Component.literal(s);
}
}
Expand Down Expand Up @@ -533,21 +525,13 @@ else if (ifDepth > 0 && !placeholders.get(s).isView()) {
}
}
everything.append(s);
if (s.contains("\n") && endOfLineValue != null) {
String start = s.substring(0, s.indexOf('\n'));
String end = s.substring(s.indexOf('\n'));
Component ret = Component.literal(start).append(endOfLineValue).append(end);
endOfLineValue = null;
return ret;
}
return Component.literal(s);
}

private void onEncounteredError() {
viewStarts.clear();
pureStarts.clear();
openPlaceholders.clear();
endOfLineValue = null;
ifDepth = 0;
unclosedSingleEscapes = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public MonitorImageRenderer(String url) {
@Override
public void render(CentralMonitorMachine machine, MonitorGroup group, float partialTick, PoseStack poseStack,
MultiBufferSource buffer, int packedLight, int packedOverlay) {
if (group.isEmpty()) return;
BlockPos rel = group.getRow(0, machine::toRelative).get(0);
BlockPos size = GTUtil.getLast(group.getRow(-1, machine::toRelative))
.offset(-rel.getX() + 1, -rel.getY() + 1, -rel.getZ() + 1);
Expand Down
Loading
Loading