Skip to content

Commit

Permalink
Cross Line Train To sign
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed Oct 20, 2024
1 parent 0670fa2 commit f2ae0f6
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ static boolean signIsLine(String signId) {

static boolean signIsPlatform(String signId) {
List<String> 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);
}

Expand All @@ -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;
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
121 changes: 121 additions & 0 deletions fabric/src/main/java/ziyue/tjmetro/mod/client/RouteMapGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<String> 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<String> 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;
Expand Down
7 changes: 7 additions & 0 deletions fabric/src/main/resources/assets/tjmetro/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"ZiYueCommentary"
],
"contributors": [
"user111192"
"user111192",
"白云-burgeoning"
],
"contact": {
"homepage": "https://modrinth.com/mod/tianjin-metro",
Expand Down
27 changes: 27 additions & 0 deletions icons/to_subway.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f2ae0f6

Please sign in to comment.