Skip to content

Commit

Permalink
✔ More signs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed Jun 9, 2024
1 parent b4dcd14 commit 55ab3c9
Show file tree
Hide file tree
Showing 34 changed files with 699 additions and 55 deletions.
97 changes: 93 additions & 4 deletions common/src/main/java/ziyue/tjmetro/block/base/IRailwaySign.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package ziyue.tjmetro.block.base;

import mtr.block.BlockRailwaySign;
import mtr.block.IBlock;
import mtr.client.ClientData;
import mtr.client.CustomResources;
import mtr.data.IGui;
import mtr.mappings.Text;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -18,6 +21,10 @@
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import ziyue.tjmetro.Reference;
import ziyue.tjmetro.client.ClientCache;

import java.util.Arrays;
import java.util.List;

import static mtr.client.CustomResources.CUSTOM_SIGNS;
import static net.minecraft.world.level.block.HorizontalDirectionalBlock.FACING;
Expand Down Expand Up @@ -90,6 +97,53 @@ static BlockPos findEndWithDirection(Level world, BlockPos startPos, Direction d
}
}

static boolean signIsExit(String signId) {
List<String> exits = Arrays.asList(BlockRailwaySign.SignType.EXIT_LETTER.toString(), BlockRailwaySign.SignType.EXIT_LETTER_FLIPPED.toString(),
SignType.EXIT_LETTER_TEXT.signId, SignType.EXIT_LETTER_TEXT_FLIPPED.signId);
return exits.contains(signId);
}

static boolean signIsLine(String signId) {
List<String> lines = Arrays.asList(BlockRailwaySign.SignType.LINE.toString(), BlockRailwaySign.SignType.LINE_FLIPPED.toString());
return lines.contains(signId);
}

static boolean signIsPlatform(String signId) {
List<String> platforms = Arrays.asList(BlockRailwaySign.SignType.PLATFORM.toString(), BlockRailwaySign.SignType.PLATFORM_FLIPPED.toString(),
SignType.BOUND_FOR_TEXT.signId, SignType.BOUND_FOR_TEXT_FLIPPED.signId);
return platforms.contains(signId);
}

static boolean signIsStation(String signId) {
List<String> stations = Arrays.asList(BlockRailwaySign.SignType.STATION.toString(), BlockRailwaySign.SignType.STATION_FLIPPED.toString(),
SignType.STATION_TEXT.signId, SignType.STATION_TEXT_FLIPPED.signId);
return stations.contains(signId);
}

static ResourceLocation getExitSignResource(String signId, String exitLetter, String exitNumber, int backgroundColor, boolean forceMTRFont) {
if (signId.equals(SignType.EXIT_LETTER_TEXT.signId) || signId.equals(SignType.EXIT_LETTER_TEXT_FLIPPED.signId)) {
return ClientCache.DATA_CACHE.getExitSignLetterTianjin(exitLetter, exitNumber, backgroundColor, forceMTRFont).resourceLocation;
} else {
if (forceMTRFont) {
return ClientData.DATA_CACHE.getExitSignLetter(exitLetter, exitNumber, backgroundColor).resourceLocation;
} else {
return ClientCache.DATA_CACHE.getExitSignLetter(exitLetter, exitNumber, backgroundColor).resourceLocation;
}
}
}

static ResourceLocation 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 ClientCache.DATA_CACHE.getBoundFor(platformId, horizontalAlignment, aspectRatio, paddingScale, backgroundColor, forceMTRFont).resourceLocation;
} else {
if (forceMTRFont) {
return ClientData.DATA_CACHE.getDirectionArrow(platformId, false, false, horizontalAlignment, false, paddingScale, aspectRatio, backgroundColor, textColor, transparentColor).resourceLocation;
} else {
return ClientCache.DATA_CACHE.getDirectionArrow(platformId, false, false, horizontalAlignment, false, paddingScale, aspectRatio, backgroundColor, textColor, transparentColor).resourceLocation;
}
}
}

enum SignType
{
// Tianjin Rail Transit (TRT, Tianjin Metro)
Expand All @@ -101,6 +155,8 @@ enum SignType
TIANJIN_METRO_OLD_LOGO_TEXT_FLIPPED("tianjin_metro_old_logo", "tianjin_metro", false, true),
TRAIN_TEXT("train", "train", false, false),
TRAIN_TEXT_FLIPPED("train", "train", false, true),
STATION_TEXT("train", "station", false, false),
STATION_TEXT_FLIPPED("train", "station", false, true),
EMERGENCY_EXIT_TEXT("emergency_exit", "emergency_exit", false, false),
EMERGENCY_EXIT_TEXT_FLIPPED("emergency_exit", "emergency_exit", true, true),
NO_THROUGHFARE_TEXT("no_throughfare", "no_throughfare", false, false),
Expand All @@ -115,6 +171,18 @@ enum SignType
ACCESSIBLE_ELEVATOR_TEXT_FLIPPED("accessible_elevator", "accessible_elevator", false, true),
ACCESSIBLE_TOILET_TEXT("accessible_toilet", "accessible_toilet", false, false),
ACCESSIBLE_TOILET_TEXT_FLIPPED("accessible_toilet", "accessible_toilet", false, true),
FARE_ADJUSTMENT_TEXT("fare_adjustment", "fare_adjustment", false, false),
FARE_ADJUSTMENT_TEXT_FLIPPED("fare_adjustment", "fare_adjustment", false, true),
INQUIRY_TEXT("inquiry", "inquiry", false, false),
INQUIRY_TEXT_FLIPPED("inquiry", "inquiry", false, true),
EXIT_LETTER_TEXT("exit_letter", "exit_bmt", false, false),
EXIT_LETTER_TEXT_FLIPPED("exit_letter", "exit_bmt", false, true),
BOUND_FOR_TEXT("bound_for", "bound_for", false, false),
BOUND_FOR_TEXT_FLIPPED("bound_for", "bound_for", false, true),
ACCESSIBLE_PASSAGE_TEXT("accessible_passage", "accessible_passage", false, false),
ACCESSIBLE_PASSAGE_TEXT_FLIPPED("accessible_passage", "accessible_passage", true, true),
TOILET_TEXT("toilet", "toilet", false, false),
TOILET_TEXT_FLIPPED("toilet", "toilet", false, true),

TIANJIN_METRO_LOGO("tianjin_metro_logo", false),
TIANJIN_METRO_MOD_LOGO("tianjin_metro_mod_logo", false),
Expand All @@ -128,25 +196,46 @@ enum SignType
RAILWAY_STATION("railway_station", false),
ACCESSIBLE_ELEVATOR("accessible_elevator", false),
ACCESSIBLE_TOILET("accessible_toilet", false),
FARE_ADJUSTMENT("fare_adjustment", false),
INQUIRY("inquiry", false),
//EXIT("exit", false),
STAIRS("stairs", false),
STAIRS_FLIPPED("stairs", true),
ACCESSIBLE_PASSAGE("accessible_passage", false),
ACCESSIBLE_PASSAGE_FLIPPED("accessible_passage", true),
ESCALATOR("escalator", false),
ESCALATOR_FLIPPED("escalator", true),
TOILET("toilet", false),

// Tianjin Binhai Mass Transit (BMT, Tianjin Metro Line 9)
NO_ENTRY_BMT_TEXT("no_entry_bmt", "no_entry_bmt", false, false),
NO_ENTRY_BMT_TEXT_FLIPPED("no_entry_bmt", "no_entry_bmt", false, true),
TO_SUBWAY_BMT_TEXT("to_subway_bmt", "to_subway_bmt", false, false),
TO_SUBWAY_BMT_TEXT_FLIPPED("to_subway_bmt", "to_subway_bmt", true, true),
EXIT_BMT_UP_TEXT("exit_bmt_up", "exit_bmt", false, false),
EXIT_BMT_DOWN_TEXT("exit_bmt_down", "exit_bmt", false, false),
EXIT_BMT_UP_TEXT_FLIPPED("exit_bmt_up", "exit_bmt", false, true),
EXIT_BMT_DOWN_TEXT_FLIPPED("exit_bmt_down", "exit_bmt", false, true),
EXIT_BMT_LEFT_TEXT("exit_bmt_left", "exit_bmt", false, false),
EXIT_BMT_RIGHT_TEXT("exit_bmt_right", "exit_bmt", false, true),
TICKETS_BMT_TEXT("fare_adjustment", "tickets_bmt", false, false),
TICKETS_BMT_TEXT_FLIPPED("fare_adjustment", "tickets_bmt", false, true),

NO_ENTRY_BMT("no_entry_bmt", false),
TO_SUBWAY_BMT("to_subway_bmt", false),
TO_SUBWAY_BMT_FLIPPED("to_subway_bmt", true);
TO_SUBWAY_BMT_FLIPPED("to_subway_bmt", true),
//BINHAI_MASS_TRANSIT("binhai_mass_transit", false),
//BINHAI_MASS_TRANSIT_FLIPPED("binhai_mass_transit", true);
//BINHAI_MASS_TRANSIT_FLIPPED("binhai_mass_transit", true),
EXIT_BMT_UP("exit_bmt_up", false),
EXIT_BMT_DOWN("exit_bmt_down", false),
EXIT_BMT_LEFT("exit_bmt_left", false),
EXIT_BMT_RIGHT("exit_bmt_right", false);

public final String signId;
public final CustomResources.CustomSign sign;

SignType(String texture, String translation, boolean flipTexture, boolean flipCustomText, boolean hasCustomText, int backgroundColor) {
this.signId = (texture.endsWith("bmt") ? "\1tjmetro_%s_%s_%s_%s_%s_%s" : "\0tjmetro_%s_%s_%s_%s_%s_%s") // Make sure that signs will always order in front of custom signs, and BMT signs are after TRT ;)
.formatted(texture, translation, flipTexture, flipCustomText, hasCustomText, backgroundColor);
this.signId = (this.toString().contains("BMT") ? "\1_TJMETRO_%s" : "\0_TJMETRO_%s").formatted(this.toString()); // Make sure that signs will always order in front of custom signs, and BMT signs are after TRT ;)
this.sign = new CustomResources.CustomSign(new ResourceLocation(Reference.MOD_ID, "textures/sign/" + texture + ".png"), flipTexture, hasCustomText ? Text.translatable("sign.tjmetro." + translation + "_cjk").append("|").append(Text.translatable("sign.tjmetro." + translation)).getString() : "", flipCustomText, true, backgroundColor);
CUSTOM_SIGNS.put(signId, sign);
}
Expand Down
19 changes: 19 additions & 0 deletions common/src/main/java/ziyue/tjmetro/client/ClientCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mtr.MTR;
import mtr.client.ClientCache.ColorNameTuple;
import mtr.client.ClientCache.PlatformRouteDetails;
import mtr.client.ClientData;
import mtr.data.*;
import mtr.mappings.Utilities;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -149,6 +150,14 @@ public DynamicResource getExitSignLetter(String exitLetter, String exitNumber, i
return getResource(String.format("tjmetro_exit_sign_letter_%s_%s", exitLetter, exitNumber), () -> RouteMapGenerator.generateExitSignLetter(exitLetter, exitNumber, backgroundColor), DefaultRenderingColor.TRANSPARENT);
}

public DynamicResource getExitSignLetterTianjin(String exitLetter, String exitNumber, int backgroundColor, boolean forceMTRFont) {
return getResource(String.format("tjmetro_exit_sign_letter_tianjin_%s_%s_%s", exitLetter, exitNumber, forceMTRFont), () -> RouteMapGenerator.generateExitSignLetterTianjin(exitLetter, exitNumber, backgroundColor, forceMTRFont), DefaultRenderingColor.TRANSPARENT);
}

public DynamicResource getBoundFor(long platformId, IGui.HorizontalAlignment horizontalAlignment, float aspectRatio, float paddingScale, int backgroundColor, boolean forceMTRFont) {
return getResource(String.format("tjmetro_bound_for_%s_%s_%s_%s_%s_%s", platformId, horizontalAlignment, aspectRatio, paddingScale, backgroundColor, forceMTRFont), () -> RouteMapGenerator.generateBoundFor(platformId, horizontalAlignment, aspectRatio, paddingScale, backgroundColor, forceMTRFont), ClientCache.DefaultRenderingColor.TRANSPARENT);
}

public DynamicResource getSignText(String string, 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 Expand Up @@ -224,6 +233,16 @@ protected DynamicResource getResource(String key, Supplier<NativeImage> supplier
}

public Text getText(String text, int maxWidth, int maxHeight, int fontSizeCjk, int fontSize, int padding, IGui.HorizontalAlignment horizontalAlignment) {
return getText(text, maxWidth, maxHeight, fontSizeCjk, fontSize, padding, horizontalAlignment, false);
}

public Text getText(String text, int maxWidth, int maxHeight, int fontSizeCjk, int fontSize, int padding, IGui.HorizontalAlignment horizontalAlignment, boolean forceMTRFont) {
if (forceMTRFont) {
final int[] dimensions = new int[2];
final byte[] pixels = ClientData.DATA_CACHE.getTextPixels(text, dimensions, maxWidth, maxHeight, fontSizeCjk, fontSize, padding, horizontalAlignment);
return new ClientCache.Text(pixels, dimensions[0], dimensions[1], dimensions[0]);
}

if (maxWidth <= 0) {
return new Text(new byte[0], 0, 0, 0);
}
Expand Down
74 changes: 73 additions & 1 deletion common/src/main/java/ziyue/tjmetro/client/RouteMapGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public static NativeImage generateExitSignLetter(String exitLetter, String exitN
final NativeImage nativeImage = new NativeImage(NativeImage.Format.RGBA, size, size, false);
nativeImage.fillRect(0, 0, size, size, backgroundColor);
drawResource(nativeImage, EXIT_RESOURCE, 0, 0, size, size, false, 0, 1, 0, true);
drawString(nativeImage, letter, size / 2 - (noNumber ? 0 : textSize / 6 - size / 32), size / 2, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, ARGB_WHITE, false);
drawString(nativeImage, letter, size / 2 - (noNumber ? 0 : textSize / 6 - size / 32), size / 2, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, ARGB_WHITE, false);
if (!noNumber) {
drawString(nativeImage, number, size / 2 + textSize / 3 - size / 32, size / 2 + textSize / 8, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, ARGB_WHITE, false);
}
Expand All @@ -458,6 +458,78 @@ public static NativeImage generateExitSignLetter(String exitLetter, String exitN
return null;
}

public static NativeImage generateExitSignLetterTianjin(String exitLetter, String exitNumber, int backgroundColor, boolean forceMTRFont) {
try {
final int size = scale / 2;
final boolean noNumber = exitNumber.isEmpty();
final int textSize = (int) (size * 1.25F);

final ClientCache.Text letter = ClientCache.DATA_CACHE.getText(exitLetter, noNumber ? textSize : textSize * 2 / 3, textSize, textSize, size, size, HorizontalAlignment.CENTER, forceMTRFont);
final ClientCache.Text number = noNumber ? null : ClientCache.DATA_CACHE.getText(exitNumber, textSize / 3, textSize, textSize / 2, textSize / 2, size, HorizontalAlignment.CENTER, forceMTRFont);

final NativeImage nativeImage = new NativeImage(NativeImage.Format.RGBA, size, size, false);
nativeImage.fillRect(0, 0, size, size, backgroundColor);
drawString(nativeImage, letter, size / 2 - (noNumber ? 0 : textSize / 6 - size / 32), size / 2, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, ARGB_WHITE, false);
if (!noNumber) {
drawString(nativeImage, number, size / 2 + textSize / 3 - size / 32, size / 2 + textSize / 8, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, ARGB_WHITE, false);
}
return nativeImage;
} catch (Exception e) {
TianjinMetro.LOGGER.error(e.getMessage(), e);
}

return null;
}

public static NativeImage generateBoundFor(long platformId, HorizontalAlignment horizontalAlignment, float aspectRatio, float paddingScale, int backgroundColor, 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 List<String> destinations = new ArrayList<>();
//final List<Tuple<ClientCache.Text, Integer>> routes = new ArrayList<>();
final List<Route> allRoutes = getRouteStream(platformId, (route, currentStationIndex) -> destinations.add(ClientData.DATA_CACHE.getFormattedRouteDestination(route, currentStationIndex, TEMP_CIRCULAR_MARKER)));
//allRoutes.forEach(
// route -> {
// final ClientCache.Text name = ClientCache.DATA_CACHE.getText(route.name, Integer.MAX_VALUE, (int) ((fontSizeBig + fontSizeSmall) * mtr.client.ClientCache.LINE_HEIGHT_MULTIPLIER * 1.25F), (int) (fontSizeBig * 1.25F), (int) (fontSizeSmall * 1.25F), padding, horizontalAlignment, forceMTRFont);
// routes.add(new Tuple<>(name, route.color));
// width.addAndGet(routeSquarePadding * 5 + name.width());
// }
//);
final boolean isTerminating = destinations.isEmpty();
final ClientCache.Text boundFor;
if (isTerminating) {
boundFor = ClientCache.DATA_CACHE.getText(IGuiExtends.mergeTranslation("gui.tjmetro.terminus_cjk", "gui.tjmetro.terminus"), width, height, tileSize * 3 / 5, tileSize * 3 / 10, padding, horizontalAlignment, forceMTRFont);
} else {
String destinationString = IGui.mergeStations(destinations);
final boolean noToString = destinationString.startsWith(TEMP_CIRCULAR_MARKER);
destinationString = destinationString.replace(TEMP_CIRCULAR_MARKER, "");
if (!destinationString.isEmpty() && !noToString) {
destinationString = IGui.insertTranslation("sign.tjmetro.bound_for_cjk", "sign.tjmetro.bound_for", 1, destinationString);
}
boundFor = ClientCache.DATA_CACHE.getText(destinationString, width, height, tileSize * 3 / 5, tileSize * 3 / 10, padding, horizontalAlignment, forceMTRFont);
}

final NativeImage nativeImage = new NativeImage(NativeImage.Format.RGBA, width, height, false);
nativeImage.fillRect(0, 0, width, height, invertColor(backgroundColor));

//routes.forEach(route -> {
// nativeImage.fillRect(currentX.get(), 0, route.getA().width(), route.getA().height(), invertColor(ARGB_BLACK | route.getB()));
// drawString(nativeImage, route.getA(), currentX.get(), height / 2, horizontalAlignment, VerticalAlignment.CENTER, 0, ARGB_WHITE, false);
// currentX.addAndGet(routeSquarePadding * 3 + route.getA().width());
//});
drawString(nativeImage, boundFor, 0, height / 2, horizontalAlignment, VerticalAlignment.CENTER, backgroundColor, ARGB_WHITE, 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 {
Expand Down
Loading

0 comments on commit 55ab3c9

Please sign in to comment.