Skip to content

Commit

Permalink
ref: better code performance; better UIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Uhutown committed Oct 4, 2023
1 parent c48ba58 commit c357fdd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -50,17 +52,48 @@ private void initOwn() {
final IIntegerable<String> 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: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c357fdd

Please sign in to comment.