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 3d4f0f1..9e623fa 100644 --- a/fabric/src/main/java/ziyue/tjmetro/mod/client/DynamicTextureCache.java +++ b/fabric/src/main/java/ziyue/tjmetro/mod/client/DynamicTextureCache.java @@ -349,6 +349,10 @@ public int height() { public int renderWidth() { return renderWidth; } + + public static Text empty() { + return new Text(null, 0, 0, 0); + } } /** 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 3df9cec..a099054 100644 --- a/fabric/src/main/java/ziyue/tjmetro/mod/client/RouteMapGenerator.java +++ b/fabric/src/main/java/ziyue/tjmetro/mod/client/RouteMapGenerator.java @@ -168,8 +168,8 @@ public static NativeImage generateStationName(long platformId, boolean isAPG, Ho final int leftSize = ((leftToRight ? 1 : 0)) * (tileSize + tilePadding); final int rightSize = ((leftToRight ? 0 : 1)) * (tileSize + tilePadding); - final DynamicTextureCache.Text destination = DynamicTextureCache.instance.getText(getStationName(platformId), isAPG ? width - padding : width - leftSize - rightSize - padding, (int) (tileSize * LINE_HEIGHT_MULTIPLIER), tileSize * 3, tileSize * 3 / 2, tilePadding, HorizontalAlignment.CENTER); - drawString(nativeImage, destination, width / 2, height / 2, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, backgroundColor, textColor, false); + final DynamicTextureCache.Text stationName = DynamicTextureCache.instance.getText(getStationName(platformId), isAPG ? width - padding : width - leftSize - rightSize - padding, (int) (tileSize * LINE_HEIGHT_MULTIPLIER), tileSize * 3, tileSize * 3 / 2, tilePadding, HorizontalAlignment.CENTER); + drawString(nativeImage, stationName, width / 2, height / 2, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, backgroundColor, textColor, false); if (transparentColor != 0) { clearColor(nativeImage, invertColor(transparentColor)); @@ -675,7 +675,6 @@ public static NativeImage generateRouteMapBMT(long platformId, boolean flip, flo final int y = Math.round((stationPositionGrouped.stationPosition.y + rawHeightPart + 0.4F) * scale * heightScale); final int lines = stationPositionGrouped.stationPosition.isCommon ? colorIndices[colorIndices.length - 1] : 0; final boolean currentStation = stationPositionGrouped.stationOffset == 0; - final boolean passed = stationPositionGrouped.stationOffset < 0; final IntArrayList interchangeColors = stationPositionGrouped.interchangeColors; if (!interchangeColors.isEmpty() && !currentStation) { @@ -683,7 +682,7 @@ public static NativeImage generateRouteMapBMT(long platformId, boolean flip, flo final int lineWidth = (int) Math.ceil((float) lineSize / 4); for (int drawX = 0; drawX < lineWidth; drawX++) { for (int drawY = 0; drawY < lineSize * 1.8; drawY++) { - drawPixelSafe(nativeImage, x + drawX - lineWidth / 2, y + lines * lineSpacing + drawY, passed ? ARGB_LIGHT_GRAY : ARGB_BLACK); + drawPixelSafe(nativeImage, x + drawX - lineWidth / 2, y + lines * lineSpacing + drawY, ARGB_BLACK); } } @@ -702,7 +701,7 @@ public static NativeImage generateRouteMapBMT(long platformId, boolean flip, flo int renderX = x - interchangesWidth / 2; for (int i = 0; i < interchanges.size(); i++) { nativeImage.fillRect(renderX, y + lines * lineSpacing + lineHeight, interchanges.get(i).renderWidth(), interchangesHeight, invertColor(ARGB_BLACK | interchangeColors.getInt(i))); - drawString(nativeImage, interchanges.get(i), renderX, y + lines * lineSpacing + lineHeight + interchangesHeight / 2, HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, passed ? ARGB_LIGHT_GRAY : ARGB_WHITE, false); + drawString(nativeImage, interchanges.get(i), renderX, y + lines * lineSpacing + lineHeight + interchangesHeight / 2, HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, ARGB_WHITE, false); renderX += interchanges.get(i).renderWidth() + padding; } } @@ -1289,8 +1288,20 @@ protected static void drawStationBMT(NativeImage nativeImage, int x, int y, floa protected static void drawVerticalString(NativeImage nativeImage, String text, int x, int y, int maxWidth, int maxHeight, int fontSizeCjk, int fontSize, int padding, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, int backgroundColor, int textColor) { final ImmutablePair pair = IGuiExtension.splitTranslation(text); - final DynamicTextureCache.Text textCJK = DynamicTextureCache.instance.getText(IGui.formatVerticalChinese(pair.left), maxWidth, maxHeight, fontSizeCjk, fontSizeCjk, ConfigClient.USE_TIANJIN_METRO_FONT.get() ? 0 : padding, HorizontalAlignment.LEFT, 1F, false); - final DynamicTextureCache.Text textNonCJK = DynamicTextureCache.instance.getText(pair.right, maxHeight, maxWidth, fontSize, fontSize, padding, HorizontalAlignment.LEFT, 1F, false); + final DynamicTextureCache.Text textCJK; + if (pair.left.isEmpty()) { + textCJK = DynamicTextureCache.Text.empty(); + padding = 0; + } else { + textCJK = DynamicTextureCache.instance.getText(IGui.formatVerticalChinese(pair.left), maxWidth, maxHeight, fontSizeCjk, fontSizeCjk, ConfigClient.USE_TIANJIN_METRO_FONT.get() ? 0 : padding, HorizontalAlignment.LEFT, 1F, false); + } + final DynamicTextureCache.Text textNonCJK; + if (pair.right.isEmpty()) { + textNonCJK = DynamicTextureCache.Text.empty(); + padding = 0; + } else { + textNonCJK = DynamicTextureCache.instance.getText(pair.right, maxHeight, maxWidth, fontSize, fontSize, padding, HorizontalAlignment.LEFT, 1F, false); + } final int width = textCJK.width() + textNonCJK.height() - padding * 2; switch (horizontalAlignment) { case LEFT: @@ -1308,6 +1319,8 @@ protected static void drawVerticalString(NativeImage nativeImage, String text, i } protected static void drawString(NativeImage nativeImage, DynamicTextureCache.Text text, int x, int y, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, int backgroundColor, int textColor, boolean rotate90) { + if (text == null || text.pixels() == null) return; + if (((backgroundColor >> 24) & 0xFF) > 0) { for (int drawX = 0; drawX < (rotate90 ? text.height() : text.renderWidth()); drawX++) { for (int drawY = 0; drawY < (rotate90 ? text.renderWidth() : text.height()); drawY++) { diff --git a/fabric/src/main/java/ziyue/tjmetro/mod/data/IGuiExtension.java b/fabric/src/main/java/ziyue/tjmetro/mod/data/IGuiExtension.java index 5dc49df..2067dcb 100644 --- a/fabric/src/main/java/ziyue/tjmetro/mod/data/IGuiExtension.java +++ b/fabric/src/main/java/ziyue/tjmetro/mod/data/IGuiExtension.java @@ -82,7 +82,11 @@ static String mergeTranslation(String keyCJK, String key) { */ static ImmutablePair splitTranslation(String text) { final int separatorIndex = text.indexOf("|"); - return new ImmutablePair<>(text.substring(0, separatorIndex), text.substring(separatorIndex + 1)); + if (separatorIndex == -1) { + if (IGui.isCjk(text)) return ImmutablePair.of(text, ""); + else return ImmutablePair.of("", text); + } + return ImmutablePair.of(text.substring(0, separatorIndex), text.substring(separatorIndex + 1)); } /** diff --git a/fabric/src/main/java/ziyue/tjmetro/mod/item/ItemPSDAPGTianjinBase.java b/fabric/src/main/java/ziyue/tjmetro/mod/item/ItemPSDAPGTianjinBase.java index e323ae6..4636fcd 100644 --- a/fabric/src/main/java/ziyue/tjmetro/mod/item/ItemPSDAPGTianjinBase.java +++ b/fabric/src/main/java/ziyue/tjmetro/mod/item/ItemPSDAPGTianjinBase.java @@ -49,7 +49,7 @@ public ItemPSDAPGTianjinBase(BlockRegistryObject block, ItemSettings settings) { @Override public ActionResult useOnBlock2(ItemUsageContext context) { final int horizontalBlocks = block.data instanceof BlockPSDAPGDoorBase ? 2 : 1; - if (blocksNotReplaceable(context, horizontalBlocks, 3, this.block)) return ActionResult.FAIL; + if (blocksNotReplaceable(context, horizontalBlocks, isAPG() ? 2 : 3, this.block)) return ActionResult.FAIL; final World world = context.getWorld(); final Direction playerFacing = context.getPlayerFacing(); @@ -78,6 +78,10 @@ public ActionResult useOnBlock2(ItemUsageContext context) { return ActionResult.SUCCESS; } + public boolean isAPG() { + return this.block.data instanceof BlockFlagAPGTianjin || this.block.data instanceof BlockFlagAPGTianjinBMT; + } + @Override public void addTooltips(ItemStack stack, @Nullable World world, List tooltip, TooltipContext options) { if (this.block.data instanceof BlockPSDAPGDoorBase) {