Skip to content

Commit

Permalink
Fixed: Platform text is shows even there is no platform info
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterJulsen committed Apr 10, 2024
1 parent 0ad7d17 commit f4b8a6e
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public class BERPlatformSimple implements IBERRenderSubtype<AdvancedDisplayBlockEntity, AdvancedDisplayRenderInstance, Boolean> {

private static final String keyTrainDeparture = "gui.createrailwaysnavigator.route_overview.notification.journey_begins";
private static final String keyTrainDepartureWithPlatform = "gui.createrailwaysnavigator.route_overview.notification.journey_begins_with_platform";
private static final String keyTime = "gui.createrailwaysnavigator.time";

private Collection<UUID> lastTrainOrder = new ArrayList<>();
Expand Down Expand Up @@ -64,7 +65,12 @@ public void update(Level level, BlockPos pos, BlockState state, AdvancedDisplayB
parent.labels.add(new BERText(parent.getFontUtils(), () -> {
List<Component> texts = new ArrayList<>();
texts.add(Utils.translate(keyTime, TimeUtils.parseTime((int)(blockEntity.getLevel().getDayTime() % 24000 + Constants.TIME_SHIFT), ModClientConfig.TIME_FORMAT.get())));
texts.addAll(preds.stream().map(x -> Utils.translate(keyTrainDeparture, x.trainName(), x.scheduleTitle(), TimeUtils.parseTime((int)(blockEntity.getLastRefreshedTime() % 24000 + Constants.TIME_SHIFT + x.departureTicks()), ModClientConfig.TIME_FORMAT.get()), x.stationInfo().platform())).toList());
texts.addAll(preds.stream().map(x -> {
if (x.stationInfo().platform() == null || x.stationInfo().platform().isBlank()) {
return Utils.translate(keyTrainDeparture, x.trainName(), x.scheduleTitle(), TimeUtils.parseTime((int)(blockEntity.getLastRefreshedTime() % 24000 + Constants.TIME_SHIFT + x.departureTicks()), ModClientConfig.TIME_FORMAT.get()), x.stationInfo().platform());
}
return Utils.translate(keyTrainDepartureWithPlatform, x.trainName(), x.scheduleTitle(), TimeUtils.parseTime((int)(blockEntity.getLastRefreshedTime() % 24000 + Constants.TIME_SHIFT + x.departureTicks()), ModClientConfig.TIME_FORMAT.get()));
}).toList());

return List.of(ModUtils.concat(texts.toArray(Component[]::new)));
}, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public class RouteDetailsOverlayScreen implements IHudOverlay, IJourneyListenerC
private static final String keyTrainDetails = "gui.createrailwaysnavigator.route_overview.train_details";
private static final String keyTrainSpeed = "gui.createrailwaysnavigator.route_overview.train_speed";
private static final String keyTransfer = "gui.createrailwaysnavigator.route_overview.transfer";
private static final String keyTransferWithPlatform = "gui.createrailwaysnavigator.route_overview.transfer_with_platform";
private static final String keyTransferCount = "gui.createrailwaysnavigator.navigator.route_entry.transfer";
private static final String keyTrainCanceled = "gui.createrailwaysnavigator.route_overview.stop_canceled";
private static final String keyAfterJourney = "gui.createrailwaysnavigator.route_overview.after_journey";
Expand Down Expand Up @@ -356,7 +357,13 @@ private void setPageTransfer() {
currentPage = Page.TRANSFER;
StationEntry station = getListener().currentStation();
if (station != null) {
this.messageLabel = MultiLineLabel.create(shadowlessFont, Utils.translate(keyTransfer,
this.messageLabel = MultiLineLabel.create(shadowlessFont,
station.getInfo().platform() == null || station.getInfo().platform().isBlank() ?
Utils.translate(keyTransfer,
station.getTrain().trainName(),
station.getTrain().scheduleTitle()
) :
Utils.translate(keyTransferWithPlatform,
station.getTrain().trainName(),
station.getTrain().scheduleTitle(),
station.getInfo().platform()
Expand Down
70 changes: 53 additions & 17 deletions src/main/java/de/mrjulsen/crn/event/listeners/JourneyListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ public class JourneyListener {
private boolean isStarted;

private static final String keyJourneyBegins = "gui.createrailwaysnavigator.route_overview.journey_begins";
private static final String keyJourneyBeginsWithPlatform = "gui.createrailwaysnavigator.route_overview.journey_begins_with_platform";
private static final String keyNextStop = "gui.createrailwaysnavigator.route_overview.next_stop";
private static final String keyTransfer = "gui.createrailwaysnavigator.route_overview.transfer";
private static final String keyTransferWithPlatform = "gui.createrailwaysnavigator.route_overview.transfer_with_platform";
private static final String keyAfterJourney = "gui.createrailwaysnavigator.route_overview.after_journey";
private static final String keyJourneyInterruptedTitle = "gui.createrailwaysnavigator.route_overview.train_canceled_title";
private static final String keyJourneyInterrupted = "gui.createrailwaysnavigator.route_overview.train_canceled_info";
Expand All @@ -51,12 +53,14 @@ public class JourneyListener {
private static final String keyKeybindOptions = "key.createrailwaysnavigator.route_overlay_options";
private static final String keyNotificationJourneyBeginsTitle = "gui.createrailwaysnavigator.route_overview.notification.journey_begins.title";
private static final String keyNotificationJourneyBegins = "gui.createrailwaysnavigator.route_overview.notification.journey_begins";
private static final String keyNotificationJourneyBeginsWithPlatform = "gui.createrailwaysnavigator.route_overview.notification.journey_begins_with_platform";
private static final String keyNotificationPlatformChangedTitle = "gui.createrailwaysnavigator.route_overview.notification.platform_changed.title";
private static final String keyNotificationPlatformChanged = "gui.createrailwaysnavigator.route_overview.notification.platform_changed";
private static final String keyNotificationTrainDelayedTitle = "gui.createrailwaysnavigator.route_overview.notification.train_delayed.title";
private static final String keyNotificationTrainDelayed = "gui.createrailwaysnavigator.route_overview.notification.train_delayed";
private static final String keyNotificationTransferTitle = "gui.createrailwaysnavigator.route_overview.notification.transfer.title";
private static final String keyNotificationTransfer = "gui.createrailwaysnavigator.route_overview.notification.transfer";
private static final String keyNotificationTransferWithPlatform = "gui.createrailwaysnavigator.route_overview.notification.transfer_with_platform";
private static final String keyNotificationConnectionEndangeredTitle = "gui.createrailwaysnavigator.route_overview.notification.connection_endangered.title";
private static final String keyNotificationConnectionEndangered = "gui.createrailwaysnavigator.route_overview.notification.connection_endangered";
private static final String keyNotificationConnectionMissedTitle = "gui.createrailwaysnavigator.route_overview.notification.connection_missed.title";
Expand Down Expand Up @@ -107,7 +111,13 @@ public static JourneyListener listenTo(SimpleRoute route) {
}

public JourneyListener start() {
Component text = Utils.translate(keyJourneyBegins,
Component text = currentStation().getInfo().platform() == null || currentStation().getInfo().platform().isBlank() ?
Utils.translate(keyJourneyBegins,
currentStation().getTrain().trainName(),
currentStation().getTrain().scheduleTitle(),
TimeUtils.parseTime((int)currentStation().getEstimatedTimeWithThreshold() + Constants.TIME_SHIFT, ModClientConfig.TIME_FORMAT.get())
) :
Utils.translate(keyJourneyBeginsWithPlatform,
currentStation().getTrain().trainName(),
currentStation().getTrain().scheduleTitle(),
TimeUtils.parseTime((int)currentStation().getEstimatedTimeWithThreshold() + Constants.TIME_SHIFT, ModClientConfig.TIME_FORMAT.get()),
Expand Down Expand Up @@ -300,12 +310,19 @@ public void tick() {
Component title = Utils.translate(keyNotificationJourneyBeginsTitle,
lastStation().getStationName()
);
Component description = Utils.translate(keyNotificationJourneyBegins,
currentStation().getTrain().trainName(),
currentStation().getTrain().scheduleTitle(),
TimeUtils.parseTime((int)currentStation().getEstimatedTimeWithThreshold() + Constants.TIME_SHIFT, ModClientConfig.TIME_FORMAT.get()),
currentStation().getInfo().platform()
);
Component description = currentStation().getInfo().platform() == null || currentStation().getInfo().platform().isBlank() ?
Utils.translate(keyNotificationJourneyBegins,
currentStation().getTrain().trainName(),
currentStation().getTrain().scheduleTitle(),
TimeUtils.parseTime((int)currentStation().getEstimatedTimeWithThreshold() + Constants.TIME_SHIFT, ModClientConfig.TIME_FORMAT.get())
)
:
Utils.translate(keyNotificationJourneyBeginsWithPlatform,
currentStation().getTrain().trainName(),
currentStation().getTrain().scheduleTitle(),
TimeUtils.parseTime((int)currentStation().getEstimatedTimeWithThreshold() + Constants.TIME_SHIFT, ModClientConfig.TIME_FORMAT.get()),
currentStation().getInfo().platform()
);

setNotificationText(new NotificationData(currentState, title, description));
setNarratorText(title.getString() + " " + description.getString());
Expand Down Expand Up @@ -644,18 +661,30 @@ private void announceNextStop() {
currentStation().getStationName()
);
if (currentStation().getTag() == StationTag.PART_END && currentStation().getIndex() + 1 < route.getStationCount(true)) {
Component transferText = textB = Utils.translate(keyTransfer,
Component transferText = textB = nextStation().get().getInfo().platform() == null || nextStation().get().getInfo().platform().isBlank() ?
Utils.translate(keyTransfer,
nextStation().get().getTrain().trainName(),
nextStation().get().getTrain().scheduleTitle()
) :
Utils.translate(keyTransferWithPlatform,
nextStation().get().getTrain().trainName(),
nextStation().get().getTrain().scheduleTitle(),
nextStation().get().getInfo().platform()
);
text = ModUtils.concat(text, transferText);
setState(State.BEFORE_TRANSFER);
setNotificationText(new NotificationData(currentState, Utils.translate(keyNotificationTransferTitle), Utils.translate(keyNotificationTransfer,
nextStation().get().getTrain().trainName(),
nextStation().get().getTrain().scheduleTitle(),
nextStation().get().getInfo().platform()
)));
setNotificationText(new NotificationData(currentState, Utils.translate(keyNotificationTransferTitle),
nextStation().get().getInfo().platform() == null || nextStation().get().getInfo().platform().isBlank() ?
Utils.translate(keyNotificationTransfer,
nextStation().get().getTrain().trainName(),
nextStation().get().getTrain().scheduleTitle()
) :
Utils.translate(keyNotificationTransferWithPlatform,
nextStation().get().getTrain().trainName(),
nextStation().get().getTrain().scheduleTitle(),
nextStation().get().getInfo().platform()
)
));
} else {
setState(State.BEFORE_NEXT_STOP);
}
Expand Down Expand Up @@ -689,10 +718,17 @@ private void reachNextStop() {
}

private void reachTransferStop() {
Component text = nextStation().isPresent() ? Utils.translate(keyTransfer,
nextStation().get().getTrain().trainName(),
nextStation().get().getTrain().scheduleTitle(),
nextStation().get().getInfo().platform()
Component text = nextStation().isPresent() ? (
nextStation().get().getInfo().platform() == null || nextStation().get().getInfo().platform().isBlank() ?
Utils.translate(keyTransfer,
nextStation().get().getTrain().trainName(),
nextStation().get().getTrain().scheduleTitle()
) :
Utils.translate(keyTransferWithPlatform,
nextStation().get().getTrain().trainName(),
nextStation().get().getTrain().scheduleTitle(),
nextStation().get().getInfo().platform()
)
) : Utils.emptyText();
String narratorText = text.getString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@
"gui.createrailwaysnavigator.route_details.save_route": "Route speichern",

"gui.createrailwaysnavigator.route_overview.title": "Streckendetails",
"gui.createrailwaysnavigator.route_overview.journey_begins": "Ihre Reise beginnt! %s nach %s, Abfahrt %s von Gleis %s",
"gui.createrailwaysnavigator.route_overview.journey_begins": "Ihre Reise beginnt! %s nach %s, Abfahrt %s",
"gui.createrailwaysnavigator.route_overview.journey_begins_with_platform": "Ihre Reise beginnt! %s nach %s, Abfahrt %s von Gleis %s",
"gui.createrailwaysnavigator.route_overview.train_details": "%s nach %s",
"gui.createrailwaysnavigator.route_overview.train_speed": "%s km/h",
"gui.createrailwaysnavigator.route_overview.next_stop": "Nächster Halt: %s",
"gui.createrailwaysnavigator.route_overview.transfer": "Umstieg in %s → %s auf Gleis %s",
"gui.createrailwaysnavigator.route_overview.transfer": "Umstieg in %s → %s",
"gui.createrailwaysnavigator.route_overview.transfer_with_platform": "Umstieg in %s → %s auf Gleis %s",
"gui.createrailwaysnavigator.route_overview.journey_completed": "Reise abgeschlossen",
"gui.createrailwaysnavigator.route_overview.after_journey": "Sie haben %s erreicht. Wir bedanken uns für Ihre Reise und wünschen einen schönen Tag.",
"gui.createrailwaysnavigator.route_overview.next_connections": "Nächste Anschlüsse",
Expand All @@ -109,7 +111,8 @@
"gui.createrailwaysnavigator.route_overview.journey_interrupted_info": "Ihre Reise nach %s kann nicht fortgesetzt werden. Suchen Sie nach einer Alternative im Navigator.",
"gui.createrailwaysnavigator.route_overview.options": "Drücke %s für Optionen.",
"gui.createrailwaysnavigator.route_overview.notification.journey_begins.title": "Ihre Reise nach %s beginnt!",
"gui.createrailwaysnavigator.route_overview.notification.journey_begins": "%s nach %s, Abfahrt %s von Gleis %s",
"gui.createrailwaysnavigator.route_overview.notification.journey_begins": "%s nach %s, Abfahrt %s",
"gui.createrailwaysnavigator.route_overview.notification.journey_begins_with_platform": "%s nach %s, Abfahrt %s von Gleis %s",
"gui.createrailwaysnavigator.route_overview.notification.platform_changed.title": "Ihr Gleis hat sich geändert!",
"gui.createrailwaysnavigator.route_overview.notification.platform_changed": "Ihr Zug in %s fährt heute von Gleis %s ab.",
"gui.createrailwaysnavigator.route_overview.notification.train_delayed.title": "%s: Ankunft %s verspätet.",
Expand All @@ -118,6 +121,7 @@
"gui.createrailwaysnavigator.route_overview.notification.train_canceled": "%s nach %s fällt heute aus.",
"gui.createrailwaysnavigator.route_overview.notification.transfer.title": "Ihr Umstieg steht bevor",
"gui.createrailwaysnavigator.route_overview.notification.transfer": "Steigen Sie in %s → %s auf Gleis %s um",
"gui.createrailwaysnavigator.route_overview.notification.transfer_with_platform": "Steigen Sie in %s → %s um",
"gui.createrailwaysnavigator.route_overview.notification.connection_endangered.title": "Ihr Anschluss ist gefährdet!",
"gui.createrailwaysnavigator.route_overview.notification.connection_endangered": "Sie werden voraussichtlich Ihren Anschluss %s nach %s nicht erreichen.",
"gui.createrailwaysnavigator.route_overview.notification.connection_missed.title": "Anschluss verpasst",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@
"gui.createrailwaysnavigator.route_details.save_route": "Save Connection",

"gui.createrailwaysnavigator.route_overview.title": "Route Details",
"gui.createrailwaysnavigator.route_overview.journey_begins": "Your journey begins! %s to %s, departure %s on platform %s",
"gui.createrailwaysnavigator.route_overview.journey_begins": "Your journey begins! %s to %s, departure %s",
"gui.createrailwaysnavigator.route_overview.journey_begins_with_platform": "Your journey begins! %s to %s, departure %s on platform %s",
"gui.createrailwaysnavigator.route_overview.train_details": "%s to %s",
"gui.createrailwaysnavigator.route_overview.train_speed": "%s km/h",
"gui.createrailwaysnavigator.route_overview.next_stop": "Next Stop: %s",
"gui.createrailwaysnavigator.route_overview.transfer": "Change to %s → %s on platform %s",
"gui.createrailwaysnavigator.route_overview.transfer": "Change to %s → %s",
"gui.createrailwaysnavigator.route_overview.transfer_with_platform": "Change to %s → %s on platform %s",
"gui.createrailwaysnavigator.route_overview.journey_completed": "Journey completed",
"gui.createrailwaysnavigator.route_overview.after_journey": "You have reached %s. Thank you for traveling and have a nice day.",
"gui.createrailwaysnavigator.route_overview.next_connections": "Next connections",
Expand All @@ -109,7 +111,8 @@
"gui.createrailwaysnavigator.route_overview.journey_interrupted_info": "Your journey to %s cannot be continued. Search for an alternative in the navigator.",
"gui.createrailwaysnavigator.route_overview.options": "Press %s for options.",
"gui.createrailwaysnavigator.route_overview.notification.journey_begins.title": "Your journey to %s begins!",
"gui.createrailwaysnavigator.route_overview.notification.journey_begins": "%s to %s, departure %s from platform %s",
"gui.createrailwaysnavigator.route_overview.notification.journey_begins": "%s to %s, departure %s",
"gui.createrailwaysnavigator.route_overview.notification.journey_begins_with_platform": "%s to %s, departure %s from platform %s",
"gui.createrailwaysnavigator.route_overview.notification.platform_changed.title": "Your platform has changed!",
"gui.createrailwaysnavigator.route_overview.notification.platform_changed": "Your train in %s leaves from platform %s today.",
"gui.createrailwaysnavigator.route_overview.notification.train_delayed.title": "%s: Arrival %s delayed.",
Expand All @@ -118,6 +121,7 @@
"gui.createrailwaysnavigator.route_overview.notification.train_canceled": "%s to %s is canceled today.",
"gui.createrailwaysnavigator.route_overview.notification.transfer.title": "Transfer is coming",
"gui.createrailwaysnavigator.route_overview.notification.transfer": "Change to %s → %s on platform %s",
"gui.createrailwaysnavigator.route_overview.notification.transfer_with_platform": "Change to %s → %s on platform %s",
"gui.createrailwaysnavigator.route_overview.notification.connection_endangered.title": "Your connection is endangered!",
"gui.createrailwaysnavigator.route_overview.notification.connection_endangered": "You probably won't be able to reach %s to %s.",
"gui.createrailwaysnavigator.route_overview.notification.connection_missed.title": "Missed connection",
Expand Down

0 comments on commit f4b8a6e

Please sign in to comment.