From c357fdd801c2c7842e64ba137088730e86fc74c1 Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 4 Oct 2023 20:15:17 +0200 Subject: [PATCH] ref: better code performance; better UIs --- linkableapi | 2 +- .../guis/PathwayRequesterContainer.java | 2 + .../signals/guis/PathwayRequesterGui.java | 55 +++++++++++++++---- .../signalbox/SignalBoxTileEntity.java | 2 +- 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/linkableapi b/linkableapi index c82024cee..24bb2d9c3 160000 --- a/linkableapi +++ b/linkableapi @@ -1 +1 @@ -Subproject commit c82024ceeeae850374674fd0cbebc2a1820dc0ee +Subproject commit 24bb2d9c315bc94c3f8a1b1ba0ad29e7be5813df diff --git a/src/main/java/com/troblecodings/signals/guis/PathwayRequesterContainer.java b/src/main/java/com/troblecodings/signals/guis/PathwayRequesterContainer.java index 1242afcb7..2bd3eb402 100644 --- a/src/main/java/com/troblecodings/signals/guis/PathwayRequesterContainer.java +++ b/src/main/java/com/troblecodings/signals/guis/PathwayRequesterContainer.java @@ -70,6 +70,8 @@ public void deserializeClient(ReadBuffer buffer) { validStarts.clear(); validEnds.clear(); + if (linkedPos == null) + return; final int validStartsSize = buffer.getByteToUnsignedInt(); for (int i = 0; i < validStartsSize; i++) { validStarts.add(Point.of(buffer)); diff --git a/src/main/java/com/troblecodings/signals/guis/PathwayRequesterGui.java b/src/main/java/com/troblecodings/signals/guis/PathwayRequesterGui.java index 72f056099..ccfdfeac1 100644 --- a/src/main/java/com/troblecodings/signals/guis/PathwayRequesterGui.java +++ b/src/main/java/com/troblecodings/signals/guis/PathwayRequesterGui.java @@ -24,6 +24,8 @@ public PathwayRequesterGui(GuiInfo info) { super(info); this.container = (PathwayRequesterContainer) info.base; this.player = info.player; + this.entity.clear(); + this.entity.add(new UILabel("Not connected")); } private void initOwn() { @@ -50,17 +52,48 @@ private void initOwn() { final IIntegerable end = SizeIntegerables.of("EndPoint", container.validStarts.size(), e -> container.validEnds.get(e).toShortString()); - inner.add(GuiElements.createEnumElement(start, e -> { - container.start = container.validStarts.get(e); - }, container.start != null ? container.start.equals(new Point()) ? 0 - : container.validStarts.indexOf(container.start) : 0)); - inner.add(GuiElements.createEnumElement(end, e -> { - container.end = container.validStarts.get(e); - }, container.end != null - ? container.end.equals(new Point()) ? 0 : container.validEnds.indexOf(container.end) - : 0)); - - inner.add(GuiElements.createButton(I18Wrapper.format("btn.save"), e -> sendToServer())); + if (!container.validStarts.isEmpty()) { + inner.add(GuiElements.createEnumElement(start, e -> { + container.start = container.validStarts.get(e); + }, container.start != null ? container.start.equals(new Point()) ? 0 + : container.validStarts.indexOf(container.start) : 0)); + } else { + final UIEntity infoLabelEntity = new UIEntity(); + infoLabelEntity.setInheritWidth(true); + infoLabelEntity.setHeight(20); + final UILabel infoLabel = new UILabel("No start to set!"); + infoLabel.setCenterY(false); + infoLabelEntity.add(infoLabel); + inner.add(infoLabelEntity); + } + + if (!container.validEnds.isEmpty()) { + inner.add(GuiElements.createEnumElement(end, e -> { + container.end = container.validStarts.get(e); + }, container.end != null ? container.end.equals(new Point()) ? 0 + : container.validEnds.indexOf(container.end) : 0)); + } else { + final UIEntity infoLabelEntity = new UIEntity(); + infoLabelEntity.setInheritWidth(true); + infoLabelEntity.setHeight(20); + final UILabel infoLabel = new UILabel("No end to set!"); + infoLabel.setCenterY(false); + infoLabelEntity.add(infoLabel); + inner.add(infoLabelEntity); + } + + if (!container.validStarts.isEmpty() && !container.validEnds.isEmpty()) { + inner.add(GuiElements.createButton(I18Wrapper.format("btn.save"), e -> sendToServer())); + } else { + final UIEntity infoLabelEntity = new UIEntity(); + infoLabelEntity.setInheritWidth(true); + infoLabelEntity.setHeight(20); + final UILabel infoLabel = new UILabel("Nothing to save!"); + infoLabel.setCenterY(false); + infoLabelEntity.add(infoLabel); + inner.add(infoLabelEntity); + } + inner.add(GuiElements.createSpacerV(5)); final UILabel Linkedlabel = new UILabel("Linked SignalBox: " diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxTileEntity.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxTileEntity.java index bb6cc0265..9437733b8 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxTileEntity.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxTileEntity.java @@ -64,7 +64,7 @@ public void loadWrapper(final NBTWrapper wrapper) { @Override public boolean hasLink() { - return SignalBoxHandler.isTileEmpty(new PosIdentifier(worldPosition, level)); + return !SignalBoxHandler.isTileEmpty(new PosIdentifier(worldPosition, level)); } @Override