|
20 | 20 | import com.gregtechceu.gtceu.api.mui.factory.PosGuiData; |
21 | 21 | import com.gregtechceu.gtceu.api.mui.utils.Alignment; |
22 | 22 | import com.gregtechceu.gtceu.api.mui.value.sync.FloatSyncValue; |
| 23 | +import com.gregtechceu.gtceu.api.mui.value.sync.InteractionSyncHandler; |
23 | 24 | import com.gregtechceu.gtceu.api.mui.value.sync.PanelSyncManager; |
24 | 25 | import com.gregtechceu.gtceu.api.mui.widgets.ButtonWidget; |
25 | 26 | import com.gregtechceu.gtceu.api.mui.widgets.TextWidget; |
26 | 27 | import com.gregtechceu.gtceu.api.mui.widgets.layout.Flow; |
27 | 28 | import com.gregtechceu.gtceu.api.mui.widgets.slot.ItemSlot; |
| 29 | +import com.gregtechceu.gtceu.api.mui.widgets.slot.ModularSlot; |
28 | 30 | import com.gregtechceu.gtceu.api.mui.widgets.textfield.TextFieldWidget; |
29 | 31 | import com.gregtechceu.gtceu.client.model.machine.MachineRenderState; |
30 | 32 | import com.gregtechceu.gtceu.client.mui.screen.ModularPanel; |
@@ -405,61 +407,70 @@ public InteractionResult onUse(BlockState state, Level world, BlockPos pos, Play |
405 | 407 |
|
406 | 408 | @Override |
407 | 409 | public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager syncManager, UISettings uiSettings) { |
408 | | - return new ModularPanel(this.getDefinition().getName()) |
409 | | - .child(GTMuiWidgets.createTitleBar(this.getDefinition(), 176)) |
410 | | - .child(Flow.column() |
411 | | - .crossAxisAlignment(Alignment.CrossAxis.START) |
412 | | - .childIf(this.isConfigurable, () -> Flow.column() |
413 | | - .coverChildren() |
414 | | - .padding(5) |
415 | | - .horizontalCenter() |
416 | | - .child(Flow.row() |
417 | | - .coverChildren() |
418 | | - .childPadding(5) |
419 | | - .child(new TextWidget<>(IKey.lang("gtceu.maintenance.configurable_duration.modify"))) |
420 | | - .child(new TextFieldWidget() |
421 | | - .setNumbersDouble(() -> MIN_DURATION_MULTIPLIER, () -> MAX_DURATION_MULTIPLIER) |
422 | | - .setDefaultNumber(1) |
423 | | - .value(new FloatSyncValue(this::getDurationMultiplier, this::setDurationMultiplier)) |
424 | | - .addTooltipElement(IKey.lang(() -> getDurationMultiplier() == 1.0 ? |
425 | | - "gtceu.maintenance.configurable_duration.unchanged_description" : |
426 | | - "gtceu.maintenance.configurable_duration.changed_description")))) |
427 | | - .child(Flow.row() |
428 | | - .coverChildren() |
429 | | - .childPadding(5) |
430 | | - .child(new TextWidget<>(IKey.lang("gtceu.maintenance.configurable_time", () -> new Object[]{this.getTimeMultiplier()}))))) |
| 410 | + InteractionSyncHandler syncHandler = new InteractionSyncHandler(); |
| 411 | + //syncManager.syncValue("button_idk", syncHandler); |
| 412 | + Flow maintenanceStatusWidget = Flow.column() |
| 413 | + .crossAxisAlignment(Alignment.CrossAxis.START) |
| 414 | + .coverChildren() |
| 415 | + .padding(5) |
| 416 | + .childPadding(2); |
| 417 | + Runnable updateWidget = () -> { |
| 418 | + while (!maintenanceStatusWidget.getChildren().isEmpty()) maintenanceStatusWidget.remove(0); |
| 419 | + maintenanceStatusWidget.child(new TextWidget<>(IKey.lang(() -> hasMaintenanceProblems() ? |
| 420 | + "gtceu.top.maintenance_broken" : |
| 421 | + "gtceu.top.maintenance_fixed"))) |
431 | 422 | .child(Flow.row() |
432 | 423 | .coverChildren() |
433 | | - .padding(5) |
434 | | - .child(new ItemSlot() |
435 | | - .slot(itemStackHandler, 0) |
436 | | - .background(GTGuiTextures.SLOT, GTGuiTextures.DUCT_TAPE_OVERLAY)) |
437 | | - .child(new ButtonWidget<>() |
438 | | - .background(GTGuiTextures.BUTTON_MAINTENANCE) |
439 | | - .disableHoverBackground() |
440 | | - .addTooltipElement(IKey.lang("gtceu.machine.maintenance_hatch_tool_slot.tooltip")) |
441 | | - .onMousePressed((mouseX, mouseY, button) -> { |
442 | | - fixMaintenanceProblems(guiData.getPlayer()); |
443 | | - return true; |
444 | | - }))) |
445 | | - .child(Flow.column() |
446 | | - .crossAxisAlignment(Alignment.CrossAxis.START) |
447 | | - .coverChildren() |
448 | | - .padding(5) |
449 | | - .childPadding(2) |
450 | | - .child(new TextWidget<>(IKey.lang(() -> hasMaintenanceProblems() ? |
451 | | - "gtceu.top.maintenance_broken" : |
452 | | - "gtceu.top.maintenance_fixed"))) |
453 | 424 | .children(Stream.iterate(Byte.valueOf("0"), i -> i < 6, i -> ++i) |
454 | 425 | .filter(i -> ((getMaintenanceProblems() >> i) & 1) == 0) |
455 | 426 | .map(GTUtil::getMaintenanceText) |
456 | | - .map(i -> Flow.row() |
457 | | - .coverChildren() |
458 | | - .childPadding(2) |
459 | | - .child(new IDrawable.DrawableWidget(new ItemDrawable(i.getA()))) |
460 | | - .child(new TextWidget<>(IKey.dynamic(i::getB)))) |
| 427 | + .map(i -> new IDrawable.DrawableWidget(new ItemDrawable(i.getA()))) |
461 | 428 | .map(IWidget.class::cast) |
462 | | - .toList()))); |
| 429 | + .toList())); |
| 430 | + }; |
| 431 | + syncHandler.setOnMousePressed((button) -> { |
| 432 | + fixMaintenanceProblems(guiData.getPlayer()); |
| 433 | + updateWidget.run(); |
| 434 | + }); |
| 435 | + updateWidget.run(); |
| 436 | + return new ModularPanel(this.getDefinition().getName()) |
| 437 | + .size(176, 200) |
| 438 | + .bindPlayerInventory() |
| 439 | + .child(GTMuiWidgets.createTitleBar(this.getDefinition(), 176)) |
| 440 | + .child(Flow.column() |
| 441 | + .crossAxisAlignment(Alignment.CrossAxis.START) |
| 442 | + .childIf(this.isConfigurable, () -> Flow.column() |
| 443 | + .coverChildren() |
| 444 | + .padding(5) |
| 445 | + .paddingLeft(0) |
| 446 | + .marginLeft(5) |
| 447 | + .child(Flow.row() |
| 448 | + .coverChildren() |
| 449 | + .childPadding(5) |
| 450 | + .alignX(0) |
| 451 | + .child(new TextWidget<>(IKey.lang("gtceu.maintenance.configurable_duration.modify"))) |
| 452 | + .child(new TextFieldWidget() |
| 453 | + .setNumbersDouble(() -> MIN_DURATION_MULTIPLIER, () -> MAX_DURATION_MULTIPLIER) |
| 454 | + .setDefaultNumber(1) |
| 455 | + .value(new FloatSyncValue(this::getDurationMultiplier, this::setDurationMultiplier)) |
| 456 | + .addTooltipElement(IKey.lang(() -> getDurationMultiplier() == 1.0 ? |
| 457 | + "gtceu.maintenance.configurable_duration.unchanged_description" : |
| 458 | + "gtceu.maintenance.configurable_duration.changed_description")))) |
| 459 | + .child(new TextWidget<>(IKey.lang("gtceu.maintenance.configurable_time", () -> new Object[]{this.getTimeMultiplier()})) |
| 460 | + .alignX(0))) |
| 461 | + .child(Flow.row() |
| 462 | + .coverChildren() |
| 463 | + .padding(5) |
| 464 | + .child(new ItemSlot() |
| 465 | + .slot(new ModularSlot(itemStackHandler, 0).changeListener( |
| 466 | + (newItem, onlyAmountChanged, client, init) -> updateWidget.run())) |
| 467 | + .background(GTGuiTextures.SLOT, GTGuiTextures.DUCT_TAPE_OVERLAY)) |
| 468 | + .child(new ButtonWidget<>() |
| 469 | + .background(GTGuiTextures.BUTTON_MAINTENANCE) |
| 470 | + .disableHoverBackground() |
| 471 | + .addTooltipElement(IKey.lang("gtceu.machine.maintenance_hatch_tool_slot.tooltip")) |
| 472 | + .syncHandler(syncHandler))) |
| 473 | + .child(maintenanceStatusWidget)); |
463 | 474 | } |
464 | 475 |
|
465 | 476 | private static Component getTextWidgetText(String type, DoubleSupplier multiplier) { |
|
0 commit comments