diff --git a/fabric/src/main/java/ziyue/tjmetro/mod/block/base/IRailwaySign.java b/fabric/src/main/java/ziyue/tjmetro/mod/block/base/IRailwaySign.java index d8aaa65..a40d7be 100644 --- a/fabric/src/main/java/ziyue/tjmetro/mod/block/base/IRailwaySign.java +++ b/fabric/src/main/java/ziyue/tjmetro/mod/block/base/IRailwaySign.java @@ -84,7 +84,9 @@ static boolean signIsLine(String signId) { static boolean signIsPlatform(String signId) { List platforms = Arrays.asList("platform", "platform_flipped", - SignType.BOUND_FOR_TEXT.signId, SignType.BOUND_FOR_TEXT_FLIPPED.signId); + SignType.BOUND_FOR_TEXT.signId, SignType.BOUND_FOR_TEXT_FLIPPED.signId, + SignType.TRAIN_TO_TEXT.signId, SignType.TRAIN_TO_TEXT_FLIPPED.signId, + SignType.CROSS_LINE_TRAIN_TO_TEXT.signId, SignType.CROSS_LINE_TRAIN_TO_TEXT_FLIPPED.signId); return platforms.contains(signId); } @@ -109,6 +111,10 @@ static Identifier getExitSignResource(String signId, String exitLetter, String e static Identifier getPlatformSignResource(String signId, long platformId, IGui.HorizontalAlignment horizontalAlignment, float paddingScale, float aspectRatio, int backgroundColor, int textColor, int transparentColor, boolean forceMTRFont) { if (signId.equals(SignType.BOUND_FOR_TEXT.signId) || signId.equals(SignType.BOUND_FOR_TEXT_FLIPPED.signId)) { return DynamicTextureCache.instance.getBoundFor(platformId, horizontalAlignment, aspectRatio, paddingScale, backgroundColor, textColor, forceMTRFont).identifier; + } else if (signId.equals(SignType.TRAIN_TO_TEXT.signId) || signId.equals(SignType.TRAIN_TO_TEXT_FLIPPED.signId)) { + return DynamicTextureCache.instance.getTrainTo(platformId, horizontalAlignment, aspectRatio, paddingScale, backgroundColor, textColor, forceMTRFont).identifier; + } else if (signId.equals(SignType.CROSS_LINE_TRAIN_TO_TEXT.signId) || signId.equals(SignType.CROSS_LINE_TRAIN_TO_TEXT_FLIPPED.signId)) { + return DynamicTextureCache.instance.getCrossLineTrainTo(platformId, horizontalAlignment, aspectRatio, paddingScale, backgroundColor, textColor, forceMTRFont).identifier; } else { if (forceMTRFont) { return org.mtr.mod.client.DynamicTextureCache.instance.getDirectionArrow(platformId, false, false, horizontalAlignment, false, paddingScale, aspectRatio, backgroundColor, textColor, transparentColor).identifier; @@ -157,6 +163,12 @@ enum SignType ACCESSIBLE_PASSAGE_TEXT_FLIPPED("accessible_passage", "accessible_passage", true, true), TOILET_TEXT("toilet", "toilet", false, false), TOILET_TEXT_FLIPPED("toilet", "toilet", false, true), + TO_SUBWAY_TEXT("to_subway", "to_subway", false, false), + TO_SUBWAY_TEXT_FLIPPED("to_subway", "to_subway", false, true), + TRAIN_TO_TEXT("to_subway", "train_to", false, false), + TRAIN_TO_TEXT_FLIPPED("to_subway", "train_to", false, true), + CROSS_LINE_TRAIN_TO_TEXT("to_subway", "cross_line_train_to", false, false), + CROSS_LINE_TRAIN_TO_TEXT_FLIPPED("to_subway", "cross_line_train_to", false, true), TIANJIN_METRO_LOGO("tianjin_metro_logo", false), TIANJIN_METRO_MOD_LOGO("tianjin_metro_mod_logo", false), @@ -180,6 +192,7 @@ enum SignType ESCALATOR("escalator", false), ESCALATOR_FLIPPED("escalator", true), TOILET("toilet", false), + TO_SUBWAY("to_subway", false), // Tianjin Binhai Mass Transit (BMT, Tianjin Metro Line 9) NO_ENTRY_BMT_TEXT("no_entry_bmt", "no_entry_bmt", false, false), @@ -208,25 +221,33 @@ enum SignType public final String signId; public final SignResource sign; - SignType(String texture, String translation, boolean flipTexture, boolean flipCustomText, boolean hasCustomText, int backgroundColor) { - this.signId = String.format(this.toString().contains("BMT") ? "\1_TJMETRO_%s" : "\0_TJMETRO_%s", this.toString()).toLowerCase(); // Make sure that signs will always order in front of custom signs, and BMT signs are after TRT ;) + SignType(String texture, String translation, boolean flipTexture, boolean flipCustomText, boolean hasCustomText, boolean small, int backgroundColor) { + this.signId = String.format(this.toString().contains("BMT") ? "\1_TJMETRO_%s" : "\0_TJMETRO_%s", this).toLowerCase(); // Make sure that signs will always order in front of custom signs, and BMT signs are after TRT ;) final JsonObject object = new JsonObject(); object.addProperty("id", this.signId); object.addProperty("textureResource", Reference.MOD_ID + ":textures/sign/" + texture + ".png"); object.addProperty("flipTexture", flipTexture); object.addProperty("customText", hasCustomText ? "sign.tjmetro." + translation : ""); object.addProperty("flipCustomText", flipCustomText); - object.addProperty("small", true); + object.addProperty("small", small); object.addProperty("backgroundColor", backgroundColor); this.sign = new SignResource(new JsonReader(object)); } SignType(String texture, String translation, boolean flipTexture, boolean flipCustomText) { - this(texture, translation, flipTexture, flipCustomText, true, 0); + this(texture, translation, flipTexture, flipCustomText, true, true, 0); + } + + SignType(String texture, String translation, boolean flipTexture, boolean flipCustomText, boolean small) { + this(texture, translation, flipTexture, flipCustomText, true, small, 0); } SignType(String texture, boolean flipTexture) { - this(texture, texture, flipTexture, false, false, 0); + this(texture, texture, flipTexture, false, false, true, 0); + } + + SignType(String texture, boolean flipTexture, boolean small) { + this(texture, texture, flipTexture, false, false, small, 0); } } } diff --git a/fabric/src/main/java/ziyue/tjmetro/mod/client/DynamicTextureCache.java b/fabric/src/main/java/ziyue/tjmetro/mod/client/DynamicTextureCache.java index 9e623fa..dd3370d 100644 --- a/fabric/src/main/java/ziyue/tjmetro/mod/client/DynamicTextureCache.java +++ b/fabric/src/main/java/ziyue/tjmetro/mod/client/DynamicTextureCache.java @@ -114,6 +114,14 @@ public DynamicResource getBoundFor(long platformId, IGui.HorizontalAlignment hor return getResource(String.format("tjmetro_bound_for_%s_%s_%s_%s_%s_%s_%s", platformId, horizontalAlignment, aspectRatio, paddingScale, backgroundColor, textColor, forceMTRFont), () -> RouteMapGenerator.generateBoundFor(platformId, horizontalAlignment, aspectRatio, paddingScale, backgroundColor, textColor, forceMTRFont), DefaultRenderingColor.TRANSPARENT); } + public DynamicResource getTrainTo(long platformId, IGui.HorizontalAlignment horizontalAlignment, float aspectRatio, float paddingScale, int backgroundColor, int textColor, boolean forceMTRFont) { + return getResource(String.format("tjmetro_train_to_%s_%s_%s_%s_%s_%s_%s", platformId, horizontalAlignment, aspectRatio, paddingScale, backgroundColor, textColor, forceMTRFont), () -> RouteMapGenerator.generateTrainTo(platformId, horizontalAlignment, aspectRatio, paddingScale, backgroundColor, textColor, forceMTRFont), DefaultRenderingColor.TRANSPARENT); + } + + public DynamicResource getCrossLineTrainTo(long platformId, IGui.HorizontalAlignment horizontalAlignment, float aspectRatio, float paddingScale, int backgroundColor, int textColor, boolean forceMTRFont) { + return getResource(String.format("tjmetro_cross_line_train_to_%s_%s_%s_%s_%s_%s_%s", platformId, horizontalAlignment, aspectRatio, paddingScale, backgroundColor, textColor, forceMTRFont), () -> RouteMapGenerator.generateCrossLineTrainTo(platformId, horizontalAlignment, aspectRatio, paddingScale, backgroundColor, textColor, forceMTRFont), DefaultRenderingColor.TRANSPARENT); + } + public DynamicResource getSignText(String string, IGui.HorizontalAlignment horizontalAlignment, float paddingScale, int backgroundColor, int textColor) { return getResource(String.format("tjmetro_sign_text_%s_%s_%s_%s_%s", string, horizontalAlignment, paddingScale, backgroundColor, textColor), () -> RouteMapGenerator.generateSignText(string, horizontalAlignment, paddingScale, backgroundColor, textColor), DefaultRenderingColor.TRANSPARENT); } diff --git a/fabric/src/main/java/ziyue/tjmetro/mod/client/RouteMapGenerator.java b/fabric/src/main/java/ziyue/tjmetro/mod/client/RouteMapGenerator.java index 5a4ebde..29879a1 100644 --- a/fabric/src/main/java/ziyue/tjmetro/mod/client/RouteMapGenerator.java +++ b/fabric/src/main/java/ziyue/tjmetro/mod/client/RouteMapGenerator.java @@ -48,6 +48,7 @@ public class RouteMapGenerator implements IGui protected static int fontSizeSmall; public static final int MIN_VERTICAL_SIZE = 5; + public static final Identifier SUBWAY_LOGO_RESOURCE = new Identifier(Reference.MOD_ID, "textures/sign/to_subway.png"); public static final Identifier TRAIN_LOGO_RESOURCE = new Identifier(Reference.MOD_ID, "textures/sign/train.png"); public static final Identifier TRAIN_BMT_LOGO_RESOURCE = new Identifier(Reference.MOD_ID, "textures/sign/to_subway_bmt.png"); public static final Identifier EXIT_RESOURCE = new Identifier(Init.MOD_ID, "textures/block/sign/exit_letter_blank.png"); @@ -857,6 +858,126 @@ public static NativeImage generateBoundFor(long platformId, HorizontalAlignment return null; } + public static NativeImage generateTrainTo(long platformId, HorizontalAlignment horizontalAlignment, float aspectRatio, float paddingScale, int backgroundColor, int textColor, boolean forceMTRFont) { + try { + final int height = scale; + final int width = (int) (height * aspectRatio); + final int padding = Math.round(height * paddingScale); + final int tileSize = height - padding * 2; + final boolean leftToRight = horizontalAlignment == HorizontalAlignment.LEFT; + + ObjectArrayList destinations = new ObjectArrayList<>(); + getRouteStream(platformId, (simplifiedRoute, currentStationIndex) -> { + final String tempMarker; + switch (simplifiedRoute.getCircularState()) { + case CLOCKWISE: + tempMarker = TEMP_CIRCULAR_MARKER_CLOCKWISE; + break; + case ANTICLOCKWISE: + tempMarker = TEMP_CIRCULAR_MARKER_ANTICLOCKWISE; + break; + default: + tempMarker = ""; + } + + destinations.add(tempMarker + simplifiedRoute.getPlatforms().get(currentStationIndex).getDestination()); + }); + final boolean isTerminating = destinations.isEmpty(); + final DynamicTextureCache.Text trainTo; + if (isTerminating) { + trainTo = DynamicTextureCache.instance.getText(IGuiExtension.mergeTranslation("gui.tjmetro.terminus_cjk", "gui.tjmetro.terminus"), width - padding * 2, height, tileSize * 3 / 5, tileSize * 3 / 10, padding, horizontalAlignment, forceMTRFont); + } else { + String destinationString = IGui.mergeStations(destinations); + final boolean isClockwise = destinationString.startsWith(TEMP_CIRCULAR_MARKER_CLOCKWISE); + final boolean isAnticlockwise = destinationString.startsWith(TEMP_CIRCULAR_MARKER_ANTICLOCKWISE); + destinationString = destinationString.replace(TEMP_CIRCULAR_MARKER_CLOCKWISE, "").replace(TEMP_CIRCULAR_MARKER_ANTICLOCKWISE, ""); + if (!destinationString.isEmpty()) { + if (isClockwise) { + destinationString = IGuiExtension.insertTranslation("gui.mtr.clockwise_via_cjk", "gui.mtr.clockwise_via", 1, destinationString); + } else if (isAnticlockwise) { + destinationString = IGuiExtension.insertTranslation("gui.mtr.anticlockwise_via_cjk", "gui.mtr.anticlockwise_via", 1, destinationString); + } else { + destinationString = IGuiExtension.insertTranslation("gui.tjmetro.train_to_cjk", "gui.tjmetro.train_to", 1, destinationString); + } + } + trainTo = DynamicTextureCache.instance.getText(destinationString, width - padding * 2 - tileSize, height, tileSize * 3 / 5, tileSize * 3 / 10, padding, horizontalAlignment, forceMTRFont); + } + + final NativeImage nativeImage = new NativeImage(NativeImageFormat.RGBA, width, height, false); + nativeImage.fillRect(0, 0, width, height, invertColor(backgroundColor)); + + drawResource(nativeImage, SUBWAY_LOGO_RESOURCE, leftToRight ? 0 : width - tileSize, padding, tileSize, tileSize, false, 0.0F, 1.0F, textColor, false); + drawString(nativeImage, trainTo, leftToRight ? tileSize : width - tileSize, height / 2, horizontalAlignment, VerticalAlignment.CENTER, backgroundColor, textColor, false); + clearColor(nativeImage, invertColor(backgroundColor)); + + return nativeImage; + } catch (Exception e) { + TianjinMetro.LOGGER.error(e.getMessage(), e); + } + + return null; + } + + public static NativeImage generateCrossLineTrainTo(long platformId, HorizontalAlignment horizontalAlignment, float aspectRatio, float paddingScale, int backgroundColor, int textColor, boolean forceMTRFont) { + try { + final int height = scale; + final int width = (int) (height * aspectRatio); + final int padding = Math.round(height * paddingScale); + final int tileSize = height - padding * 2; + final boolean leftToRight = horizontalAlignment == HorizontalAlignment.LEFT; + + ObjectArrayList destinations = new ObjectArrayList<>(); + getRouteStream(platformId, (simplifiedRoute, currentStationIndex) -> { + final String tempMarker; + switch (simplifiedRoute.getCircularState()) { + case CLOCKWISE: + tempMarker = TEMP_CIRCULAR_MARKER_CLOCKWISE; + break; + case ANTICLOCKWISE: + tempMarker = TEMP_CIRCULAR_MARKER_ANTICLOCKWISE; + break; + default: + tempMarker = ""; + } + + destinations.add(tempMarker + simplifiedRoute.getPlatforms().get(currentStationIndex).getDestination()); + }); + final boolean isTerminating = destinations.isEmpty(); + final DynamicTextureCache.Text trainTo; + if (isTerminating) { + trainTo = DynamicTextureCache.instance.getText(IGuiExtension.mergeTranslation("gui.tjmetro.terminus_cjk", "gui.tjmetro.terminus"), width - padding * 2, height, tileSize * 3 / 5, tileSize * 3 / 10, padding, horizontalAlignment, forceMTRFont); + } else { + String destinationString = IGui.mergeStations(destinations); + final boolean isClockwise = destinationString.startsWith(TEMP_CIRCULAR_MARKER_CLOCKWISE); + final boolean isAnticlockwise = destinationString.startsWith(TEMP_CIRCULAR_MARKER_ANTICLOCKWISE); + destinationString = destinationString.replace(TEMP_CIRCULAR_MARKER_CLOCKWISE, "").replace(TEMP_CIRCULAR_MARKER_ANTICLOCKWISE, ""); + if (!destinationString.isEmpty()) { + if (isClockwise) { + destinationString = IGuiExtension.insertTranslation("gui.mtr.clockwise_via_cjk", "gui.mtr.clockwise_via", 1, destinationString); + } else if (isAnticlockwise) { + destinationString = IGuiExtension.insertTranslation("gui.mtr.anticlockwise_via_cjk", "gui.mtr.anticlockwise_via", 1, destinationString); + } else { + destinationString = IGuiExtension.insertTranslation("gui.tjmetro.cross_line_train_to_cjk", "gui.tjmetro.cross_line_train_to", 1, destinationString); + } + } + trainTo = DynamicTextureCache.instance.getText(destinationString, width - padding * 2 - tileSize, height, tileSize * 3 / 5, tileSize * 3 / 10, padding, horizontalAlignment, forceMTRFont); + } + + final NativeImage nativeImage = new NativeImage(NativeImageFormat.RGBA, width, height, false); + nativeImage.fillRect(0, 0, width, height, invertColor(backgroundColor)); + + drawResource(nativeImage, SUBWAY_LOGO_RESOURCE, leftToRight ? 0 : width - tileSize, padding, tileSize, tileSize, false, 0.0F, 1.0F, textColor, false); + drawString(nativeImage, trainTo, leftToRight ? tileSize : width - tileSize, height / 2, horizontalAlignment, VerticalAlignment.CENTER, backgroundColor, textColor, false); + clearColor(nativeImage, invertColor(backgroundColor)); + + return nativeImage; + } catch (Exception e) { + TianjinMetro.LOGGER.error(e.getMessage(), e); + } + + return null; + } + public static NativeImage generateSignText(String string, HorizontalAlignment horizontalAlignment, float paddingScale, int backgroundColor, int textColor) { try { final int height = scale; diff --git a/fabric/src/main/resources/assets/tjmetro/lang/en_us.json b/fabric/src/main/resources/assets/tjmetro/lang/en_us.json index c8e8fbb..5a1c7d7 100644 --- a/fabric/src/main/resources/assets/tjmetro/lang/en_us.json +++ b/fabric/src/main/resources/assets/tjmetro/lang/en_us.json @@ -72,6 +72,10 @@ "gui.tjmetro.bound_for_bmt_cjk": "开往 %s", "gui.tjmetro.bound_for_cjk": "%s方向", "gui.tjmetro.bound_for": "To %s", + "gui.tjmetro.train_to_cjk": "开往%s", + "gui.tjmetro.train_to": "To %s", + "gui.tjmetro.cross_line_train_to_cjk": "跨线车往%s", + "gui.tjmetro.cross_line_train_to": "Cross Line Train To %s", "sign.tjmetro.tianjin_metro": "天津地铁|Tianjin Metro", "sign.tjmetro.train": "列车|Train", @@ -88,6 +92,9 @@ "sign.tjmetro.bound_for": "方向|To", "sign.tjmetro.accessible_passage": "无障碍通道|Accessible Passage", "sign.tjmetro.toilet": "卫生间|Toilet", + "sign.tjmetro.to_subway": "乘车|To Subway", + "sign.tjmetro.train_to": "开往|To", + "sign.tjmetro.cross_line_train_to": "跨线车往|Cross Line Train To", "sign.tjmetro.no_entry_bmt": "乘客止步|No Entry", "sign.tjmetro.to_subway_bmt": "乘车|To Subway", "sign.tjmetro.exit_bmt": "出口|Exit", diff --git a/fabric/src/main/resources/assets/tjmetro/textures/sign/to_subway.png b/fabric/src/main/resources/assets/tjmetro/textures/sign/to_subway.png new file mode 100644 index 0000000..0e7ae15 Binary files /dev/null and b/fabric/src/main/resources/assets/tjmetro/textures/sign/to_subway.png differ diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 533801b..de2d22c 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -8,7 +8,8 @@ "ZiYueCommentary" ], "contributors": [ - "user111192" + "user111192", + "白云-burgeoning" ], "contact": { "homepage": "https://modrinth.com/mod/tianjin-metro", diff --git a/icons/to_subway.svg b/icons/to_subway.svg new file mode 100644 index 0000000..ed59edc --- /dev/null +++ b/icons/to_subway.svg @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + +