Skip to content

Commit

Permalink
✔ Filter Language
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed Feb 15, 2024
1 parent 6c5de63 commit f01ba2a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tianjin Metro

<img alt="Requires Java 16" height="30%" src="https://user-images.githubusercontent.com/63241389/235600700-20920db6-9677-41f6-8215-ba3f5f728213.svg" width="30%"/>
<img alt="Requires Java 16" height="100px" src="https://user-images.githubusercontent.com/63241389/235600700-20920db6-9677-41f6-8215-ba3f5f728213.svg" width="30%"/>

A small mod for [Minecraft Transit Railway](https://github.com/jonafanho/Minecraft-Transit-Railway), in developing stage.

Expand Down
27 changes: 24 additions & 3 deletions common/src/main/java/ziyue/tjmetro/IDrawingExtends.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ public interface IDrawingExtends
*/
Function<String, Style> LINK_STYLE = link -> Style.EMPTY.withUnderlined(true).withColor(ChatFormatting.BLUE).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, link)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(link)));

/**
* Remains the language string that the language option specified.
*
* @return filtered string
* @author ZiYueCommentary
* @see mtr.client.Config#languageOptions()
* @since beta-1
*/
static String filterLanguage(String text) {
final StringBuilder noCommentString = new StringBuilder(text);
final int commentIndex = noCommentString.indexOf("||");
final int separatorIndex = noCommentString.indexOf("|");
if (commentIndex != -1)
noCommentString.delete(commentIndex, noCommentString.length());
if (separatorIndex != -1) {
switch (mtr.client.Config.languageOptions()) {
case 1 -> noCommentString.delete(separatorIndex, noCommentString.length());
case 2 -> noCommentString.delete(0, separatorIndex);
}
}
return noCommentString.toString();
}

/**
* Drawing string with Tianjin Metro Font.
*
Expand All @@ -56,9 +79,7 @@ static void drawStringWithFont(PoseStack matrices, Font textRenderer, MultiBuffe
style = Style.EMPTY;
}

while (text.contains("||")) {
text = text.replace("||", "|");
}
text = IDrawingExtends.filterLanguage(text);
final String[] stringSplit = text.split("\\|");

final List<Boolean> isCJKList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public void render(T entity, float tickDelta, PoseStack matrices, MultiBufferSou
matrices.mulPose(Vector3f.ZP.rotationDegrees(180));
final MultiBufferSource.BufferSource immediate = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
matrices.translate(0, 0.023, 0.5 - entity.zOffset - SMALL_OFFSET);
drawStationName(entity, matrices, vertexConsumers, immediate, entity.content, light);
drawString(entity, matrices, vertexConsumers, immediate, IDrawingExtends.filterLanguage(entity.content), light);
immediate.endBatch();
matrices.popPose();
}

protected void drawStationName(T entity, PoseStack matrices, MultiBufferSource vertexConsumers, MultiBufferSource.BufferSource immediate, String content, int light) {
protected void drawString(T entity, PoseStack matrices, MultiBufferSource vertexConsumers, MultiBufferSource.BufferSource immediate, String content, int light) {
IDrawingExtends.drawStringWithFont(matrices, Minecraft.getInstance().font, immediate, content, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0.5f, -0.13f, 0.85F * 2 + 0.05f, 1f, 80, ARGB_WHITE, false, light, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void render(T entity, float tickDelta, PoseStack matrices, MultiBufferSou
matrices.mulPose(Vector3f.ZP.rotationDegrees(180));
matrices.translate(0, 0, 0.5 - entity.zOffset - SMALL_OFFSET);
final MultiBufferSource.BufferSource immediate = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
IDrawingExtends.drawStringWithFont(matrices, Minecraft.getInstance().font, immediate, Text.translatable("sign.tjmetro.service_corridor_sign").getString(), HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, -0.12f, 0.85F, 1F, 150, ARGB_BLACK, false, light, null);
IDrawingExtends.drawStringWithFont(matrices, Minecraft.getInstance().font, immediate, Text.translatable("sign.tjmetro.contact_station_for_help").getString(), HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, 0.02f, 0.85F, 1F, 270, ARGB_BLACK, false, light, null);
IDrawingExtends.drawStringWithFont(matrices, Minecraft.getInstance().font, immediate, Text.translatable("gui.tjmetro.service_corridor_sign").getString(), HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, -0.12f, 0.85F, 1F, 150, ARGB_BLACK, false, light, null);
IDrawingExtends.drawStringWithFont(matrices, Minecraft.getInstance().font, immediate, Text.translatable("gui.tjmetro.contact_station_for_help").getString(), HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, 0.02f, 0.85F, 1F, 270, ARGB_BLACK, false, light, null);
immediate.endBatch();
matrices.popPose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void render(T entity, float tickDelta, PoseStack matrices, MultiBufferSou
matrices.translate(0, 0, 0.5 - entity.zOffset - SMALL_OFFSET);
final MultiBufferSource.BufferSource immediate = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
final Station station = RailwayData.getStation(ClientData.STATIONS, ClientData.DATA_CACHE, entity.getBlockPos());
drawStationName(matrices, immediate, entity.content.equals("") ? station == null ? Text.translatable("gui.mtr.untitled").getString() : station.name : entity.content, color, light);
drawStationName(matrices, immediate, entity.content.isEmpty() ? station == null ? Text.translatable("gui.mtr.untitled").getString() : IDrawingExtends.filterLanguage(station.name) : IDrawingExtends.filterLanguage(entity.content), color, light);
immediate.endBatch();
matrices.popPose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraft.core.Direction;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;
import ziyue.tjmetro.IDrawingExtends;
import ziyue.tjmetro.blocks.BlockStationNameWallLegacy;

/**
Expand Down Expand Up @@ -52,7 +53,7 @@ public void render(T entity, float f, PoseStack matrices, MultiBufferSource vert
final MultiBufferSource.BufferSource immediate = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
final Station station = RailwayData.getStation(ClientData.STATIONS, ClientData.DATA_CACHE, pos);
matrices.translate(0, 0.023, 0.5 - entity.zOffset - SMALL_OFFSET);
drawStationName(matrices, vertexConsumers, immediate, station == null ? Text.translatable("gui.mtr.untitled").getString() : station.name, entity.getColor(state), light);
drawStationName(matrices, vertexConsumers, immediate, station == null ? Text.translatable("gui.mtr.untitled").getString() : IDrawingExtends.filterLanguage(station.name), entity.getColor(state), light);
immediate.endBatch();
matrices.popPose();
}
Expand Down
5 changes: 2 additions & 3 deletions common/src/main/resources/assets/tjmetro/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
"block.tjmetro.railway_sign_tianjin": "Railway Sign (Tianjin)",
"block.tjmetro.service_corridor_sign": "\"Serivce Corridor\" Sign",

"sign.tjmetro.service_corridor_sign": "Service Corridor",
"sign.tjmetro.contact_station_for_help": "Please contact the station for help.",

"gui.tjmetro.service_corridor_sign": "Service Corridor",
"gui.tjmetro.contact_station_for_help": "Please contact the station for help.",
"gui.tjmetro.metal_detection_door": "Metal Detection Door",
"gui.tjmetro.options": "Tianjin Metro Options",
"gui.tjmetro.default_color": "Default Color",
Expand Down

0 comments on commit f01ba2a

Please sign in to comment.