Skip to content

Commit

Permalink
feat: added remove and show for saved pathways
Browse files Browse the repository at this point in the history
  • Loading branch information
Uhutown committed Oct 1, 2023
1 parent bd024d3 commit 735c303
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ public void deserializeServer(final ReadBuffer buffer) {
node.addAndSetEntry(modeSet, PathEntryType.SIGNAL_REPEATER, state);
}
}
case REMOVE_SAVEDPW: {
final Point start = Point.of(buffer);
final Point end = Point.of(buffer);
SignalBoxHandler.removeNextPathway(
new PosIdentifier(tile.getBlockPos(), info.world), start, end);
}
default:
break;
}
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/troblecodings/signals/guis/GuiSignalBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static float[] getLines() {
private final Map<Point, SignalBoxNode> changedModes = new HashMap<>();
private UIEntity plane = null;
private boolean allPacketsRecived = false;
private final Map<Point, UISignalBoxTile> allTiles = new HashMap<>();
protected final Map<Point, UISignalBoxTile> allTiles = new HashMap<>();
private SidePanel helpPage;
private final Map<BlockPos, SubsidiaryHolder> enabledSubsidiaries = new HashMap<>();
private final Map<Point, UIColor> colors = new HashMap<>();
Expand All @@ -119,7 +119,7 @@ public void infoUpdate(final String errorString) {
lowerEntity.add(tooltip);
new Thread(() -> {
try {
Thread.sleep(4000);
Thread.sleep(3000);
} catch (final InterruptedException e) {
e.printStackTrace();
}
Expand All @@ -128,7 +128,7 @@ public void infoUpdate(final String errorString) {
return;
}

private void resetTileSelection() {
protected void resetTileSelection() {
colors.values().forEach(color -> color.getParent().remove(color));
colors.clear();
this.lastTile = null;
Expand Down Expand Up @@ -971,6 +971,16 @@ private void sendSignalRepeater(final Point point, final ModeSet mode, final boo
OpenSignalsMain.network.sendTo(info.player, buffer);
}

protected void removeNextPathwayFromServer(final Point start, final Point end) {
if (!allPacketsRecived)
return;
final WriteBuffer buffer = new WriteBuffer();
buffer.putEnumValue(SignalBoxNetwork.REMOVE_SAVEDPW);
start.writeNetwork(buffer);
end.writeNetwork(buffer);
OpenSignalsMain.network.sendTo(info.player, buffer);
}

private void reset() {
lowerEntity.clear();
}
Expand Down
45 changes: 42 additions & 3 deletions src/main/java/com/troblecodings/signals/guis/SidePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,30 @@ public void helpUsageMode(final Map<BlockPos, SubsidiaryHolder> subsidiaries,
list.add(scrollbox);

gui.container.nextPathways.forEach(entry -> {
final UIEntity layout = new UIEntity();
layout.setHeight(20);
layout.setInheritWidth(true);
layout.add(new UIBox(UIBox.HBOX, 2));
final UIEntity button = GuiElements
.createButton("Start: " + entry.getKey().toString() + ", End: "
+ entry.getValue().toString());
list.add(button);
.createButton("Start: " + entry.getKey().toShortString()
+ ", End: " + entry.getValue().toShortString());
layout.add(button);
layout.add(GuiElements
.createButton(I18Wrapper.format("info.usage.show"), 40, _u -> {
gui.resetTileSelection();
gui.pop();
setShowHelpPage(false);
addColorToTile(entry.getKey(), entry.getValue(),
GuiSignalBox.SELECTION_COLOR);
// TODO Maby other color?
}));
layout.add(GuiElements.createButton("x", 20, _u -> {
gui.container.nextPathways.remove(entry);
list.remove(layout);
gui.removeNextPathwayFromServer(entry.getKey(), entry.getValue());
gui.pop();
}));
list.add(layout);
});

final UIScroll scroll = new UIScroll();
Expand Down Expand Up @@ -627,6 +647,25 @@ public void helpUsageMode(final Map<BlockPos, SubsidiaryHolder> subsidiaries,
addHelpPageToPlane();
}

private void addColorToTile(final Point start, final Point end, final int color) {
final UISignalBoxTile startTile = gui.allTiles.get(start);
final UISignalBoxTile endTile = gui.allTiles.get(end);
if (startTile == null || endTile == null)
return;
final UIColor uiColor = new UIColor(color);
new Thread(() -> {
startTile.getParent().add(uiColor);
endTile.getParent().add(uiColor);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
startTile.getParent().remove(uiColor);
endTile.getParent().remove(uiColor);
}, "GuiSignalBox:showNextPathway").start();
}

public void setDisableSubdsidiary(final BiConsumer<BlockPos, SubsidiaryHolder> consumer) {
this.disableSubsidiary = consumer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ public static boolean addNextPathway(final PosIdentifier identifier, final Point
return grid.addNextPathway(start, end);
}

public static void removeNextPathway(final PosIdentifier identifier, final Point start,
final Point end) {
if (identifier.world.isClientSide)
return;
PathwayHolder grid;
synchronized (ALL_GRIDS) {
grid = ALL_GRIDS.get(identifier);
}
if (grid == null)
return;
grid.removeNextPathway(start, end);
}

public static void resetAllPathways(final PosIdentifier identifier) {
if (identifier.world.isClientSide)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ public boolean addNextPathway(final Point start, final Point end) {
return false;
}

public void removeNextPathway(final Point start, final Point end) {
nextPathways.remove(Maps.immutableEntry(start, end));
}

public void resetPathway(final Point p1) {
if (startsToPath.isEmpty())
return;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/troblecodings/signals/signalbox/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public String toString() {
return "Point[x=" + this.x + ",y=" + this.y + "]";
}

public String toShortString() {
return "[x=" + this.x + ",y=" + this.y + "]";
}

@Override
public void write(final NBTWrapper tag) {
tag.putByte("x", (byte) x);
Expand Down

0 comments on commit 735c303

Please sign in to comment.