Skip to content

Commit

Permalink
Fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed Sep 26, 2024
1 parent 4a6ccd0 commit 8a250d6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ public int height() {
public int renderWidth() {
return renderWidth;
}

public static Text empty() {
return new Text(null, 0, 0, 0);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -675,15 +675,14 @@ 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) {
final int lineHeight = lineSize * 2;
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);
}
}

Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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<String, String> 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:
Expand All @@ -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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ static String mergeTranslation(String keyCJK, String key) {
*/
static ImmutablePair<String, String> 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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<MutableText> tooltip, TooltipContext options) {
if (this.block.data instanceof BlockPSDAPGDoorBase) {
Expand Down

0 comments on commit 8a250d6

Please sign in to comment.