diff --git a/fabric/src/main/java/com/lx862/jcm/mod/block/RVPIDSBlock.java b/fabric/src/main/java/com/lx862/jcm/mod/block/RVPIDSBlock.java index 885a964d..18a8bc83 100644 --- a/fabric/src/main/java/com/lx862/jcm/mod/block/RVPIDSBlock.java +++ b/fabric/src/main/java/com/lx862/jcm/mod/block/RVPIDSBlock.java @@ -33,7 +33,7 @@ public void onServerUse(BlockState state, World world, BlockPos pos, PlayerEntit RVPIDSBlockEntity thisEntity = (RVPIDSBlockEntity) world.getBlockEntity(pos).data; if (JCMUtil.playerHoldingBrush(player)) { - Networking.sendPacketToClient(player, new PIDSGUIPacket(pos, thisEntity.getCustomMessages(), thisEntity.getRowHidden(), thisEntity.getHidePlatformNumber(), thisEntity.getPresetId())); + Networking.sendPacketToClient(player, new PIDSGUIPacket(pos, thisEntity.getCustomMessages(), thisEntity.getRowHidden(), thisEntity.platformNumberHidden(), thisEntity.getPresetId())); } } diff --git a/fabric/src/main/java/com/lx862/jcm/mod/block/entity/PIDSBlockEntity.java b/fabric/src/main/java/com/lx862/jcm/mod/block/entity/PIDSBlockEntity.java index 8925bc51..222a9c55 100644 --- a/fabric/src/main/java/com/lx862/jcm/mod/block/entity/PIDSBlockEntity.java +++ b/fabric/src/main/java/com/lx862/jcm/mod/block/entity/PIDSBlockEntity.java @@ -75,7 +75,7 @@ public void setData(String[] customMessages, boolean[] rowHidden, boolean hidePl this.markDirty2(); } - public boolean getHidePlatformNumber() { + public boolean platformNumberHidden() { return hidePlatformNumber; } diff --git a/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/RVPIDSPreset.java b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/RVPIDSPreset.java index 054c1cbd..1064cea0 100644 --- a/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/RVPIDSPreset.java +++ b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/RVPIDSPreset.java @@ -2,18 +2,23 @@ import com.lx862.jcm.mod.block.entity.PIDSBlockEntity; import com.lx862.jcm.mod.config.ConfigEntry; +import com.lx862.jcm.mod.data.pids.preset.drawcalls.*; +import com.lx862.jcm.mod.data.pids.preset.drawcalls.base.TextDrawCall; +import com.lx862.jcm.mod.data.pids.preset.drawcalls.base.TextureDrawCall; import com.lx862.jcm.mod.render.RenderHelper; -import com.lx862.jcm.mod.render.text.TextAlignment; -import com.lx862.jcm.mod.render.text.TextInfo; +import com.lx862.jcm.mod.data.pids.preset.drawcalls.base.DrawCall; import com.lx862.jcm.mod.render.text.TextRenderingManager; -import com.lx862.jcm.mod.util.TextUtil; import org.mtr.core.operation.ArrivalResponse; import org.mtr.core.operation.ArrivalsResponse; import org.mtr.mapping.holder.*; import org.mtr.mapping.mapper.GraphicsHolder; -import org.mtr.mapping.mapper.WorldHelper; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; public class RVPIDSPreset extends PIDSPresetBase { + private static final int HEADER_HEIGHT = 11; private static final int PIDS_MARGIN = 7; private static final float ARRIVAL_TEXT_SCALE = 1.35F; private static final Identifier TEXTURE_PLATFORM_CIRCLE = new Identifier("jsblock:textures/block/pids/plat_circle.png"); @@ -26,11 +31,11 @@ public RVPIDSPreset() { } public void render(PIDSBlockEntity be, GraphicsHolder graphicsHolder, World world, Direction facing, ArrivalsResponse arrivals, boolean[] rowHidden, float tickDelta, int x, int y, int width, int height) { + int startX = PIDS_MARGIN; int contentWidth = width - (PIDS_MARGIN * 2); - int rowAmount = be.getRowAmount(); - boolean hidePlatform = be.getHidePlatformNumber(); + int contentHeight = height - HEADER_HEIGHT; - // Draw Textures + // Draw Background graphicsHolder.createVertexConsumer(RenderLayer.getText(TEXTURE_BACKGROUND)); RenderHelper.drawTexture(graphicsHolder, TEXTURE_BACKGROUND, 0, 0, 0, width, height, facing, ARGB_WHITE, MAX_RENDER_LIGHT); @@ -40,104 +45,56 @@ public void render(PIDSBlockEntity be, GraphicsHolder graphicsHolder, World worl drawAtlasBackground(graphicsHolder, width, height, facing); } - graphicsHolder.translate(PIDS_MARGIN, 0, -0.5); - // Weather icon - drawWeatherIcon(graphicsHolder, world, facing, 0); + graphicsHolder.translate(startX, 0, -0.5); + + List drawCalls = new ArrayList<>(); + drawCalls.add(new ClockDrawCall(getFont(), ARGB_WHITE, contentWidth, 2, contentWidth, 10)); + drawCalls.add(new WeatherIconDrawCall(ICON_WEATHER_SUNNY, ICON_WEATHER_RAINY, ICON_WEATHER_THUNDER, 0, 0, 11, 11)); + + drawArrivals(arrivals, rowHidden, 0, 15, contentWidth, contentHeight, be.getRowAmount(), ARGB_BLACK, be.platformNumberHidden(), drawCalls); + + List textureDrawCall = drawCalls.stream().filter(e -> e instanceof TextureDrawCall).collect(Collectors.toList()); + List textDrawCall = drawCalls.stream().filter(e -> e instanceof TextDrawCall).collect(Collectors.toList()); + + // Texture + for(DrawCall drawCall : textureDrawCall) { + graphicsHolder.push(); + drawCall.render(graphicsHolder, world, facing); + graphicsHolder.pop(); + } // Text graphicsHolder.translate(0, 0, -0.5); TextRenderingManager.bind(graphicsHolder); - drawClock(graphicsHolder, facing, world, contentWidth, 2, ARGB_WHITE); - - int headerHeight = 11; - drawArrivals(graphicsHolder, arrivals, rowHidden, facing, 0, 15, contentWidth, height - headerHeight, rowAmount, ARGB_BLACK, hidePlatform); + for(DrawCall drawCall : textDrawCall) { + graphicsHolder.push(); + drawCall.render(graphicsHolder, world, facing); + graphicsHolder.pop(); + } } - private void drawArrivals(GraphicsHolder graphicsHolder, ArrivalsResponse arrivals, boolean[] rowHidden, Direction facing, int x, int y, int width, int height, int rows, int textColor, boolean hidePlatform) { - graphicsHolder.push(); - graphicsHolder.translate(x, y, 0); - graphicsHolder.scale(ARRIVAL_TEXT_SCALE, ARRIVAL_TEXT_SCALE, ARRIVAL_TEXT_SCALE); - + private void drawArrivals(ArrivalsResponse arrivals, boolean[] rowHidden, int x, int y, int width, int height, int rows, int textColor, boolean hidePlatform, List drawCalls) { int arrivalIndex = 0; + double rowY = y; for(int i = 0; i < rows; i++) { if(arrivalIndex >= arrivals.getArrivals().size()) return; if(!rowHidden[i]) { ArrivalResponse arrival = arrivals.getArrivals().get(arrivalIndex); - drawArrival(graphicsHolder, facing, (int)(width / ARRIVAL_TEXT_SCALE), arrival, textColor, false, hidePlatform); - arrivalIndex++; - } - - graphicsHolder.translate(0, (height / 7.25) * ARRIVAL_TEXT_SCALE, 0); - } - graphicsHolder.pop(); - } + float destinationMaxWidth = !hidePlatform ? (65 * ARRIVAL_TEXT_SCALE) : (75 * ARRIVAL_TEXT_SCALE); + drawCalls.add(new DestinationDrawCall(arrival, getFont(), textColor, x, rowY, destinationMaxWidth, 10, ARRIVAL_TEXT_SCALE)); - private void drawArrival(GraphicsHolder graphicsHolder, Direction facing, int width, ArrivalResponse arrival, int textColor, boolean showCar, boolean hidePlatform) { - String routeNo = arrival.getRouteNumber().isEmpty() ? "" : arrival.getRouteNumber() + " "; - String leftDestination = routeNo + cycleString(arrival.getDestination()); - TextInfo destinationText = new TextInfo(leftDestination).withColor(textColor).withFont(getFont()); + if(!hidePlatform) { + drawCalls.add(new PlatformDrawCall(arrival, getFont(), RenderHelper.ARGB_WHITE, 65 * ARRIVAL_TEXT_SCALE, rowY, 9, 9)); + drawCalls.add(new PlatformCircleDrawCall(arrival, TEXTURE_PLATFORM_CIRCLE, 65 * ARRIVAL_TEXT_SCALE, rowY, 11, 11)); + } - int destinationWidth = TextRenderingManager.getTextWidth(destinationText); - float destinationMaxWidth = !hidePlatform ? (44 * ARRIVAL_TEXT_SCALE) : (54 * ARRIVAL_TEXT_SCALE); - - graphicsHolder.push(); - if(destinationWidth > destinationMaxWidth) { - RenderHelper.scaleToFit(graphicsHolder, destinationWidth, destinationMaxWidth - 2, false); - // TODO: Make marquee an option in custom PIDS Preset - //drawPIDSScrollingText(graphicsHolder, facing, leftDestination, 0, 0, textColor, (int)destinationMaxWidth - 2); - } - - drawPIDSText(graphicsHolder, TextAlignment.LEFT, facing, destinationText, 0, 0, textColor); - graphicsHolder.pop(); - - // Platform Indicator - if(!hidePlatform) { - graphicsHolder.push(); - // Icon - graphicsHolder.createVertexConsumer(RenderLayer.getText(TEXTURE_PLATFORM_CIRCLE)); - RenderHelper.drawTexture(graphicsHolder, 44 * ARRIVAL_TEXT_SCALE, 0, 0.3F, 9, 9, facing, arrival.getRouteColor() + ARGB_BLACK, MAX_RENDER_LIGHT); - - // Text - graphicsHolder.translate((44 * ARRIVAL_TEXT_SCALE) + 4.5, 1.75, 0); - - TextInfo platformText = new TextInfo(arrival.getPlatformName()).withFont(getFont()); - int platformTextWidth = TextRenderingManager.getTextWidth(platformText); - - TextRenderingManager.bind(graphicsHolder); - graphicsHolder.scale(0.75F, 0.75F, 1); - RenderHelper.scaleToFit(graphicsHolder, platformTextWidth, 8, true, 12); - drawPIDSText(graphicsHolder, TextAlignment.CENTER, facing, platformText, 0, 0, ARGB_WHITE); - graphicsHolder.pop(); - } - - // Draw ETA - long remTime = arrival.getArrival() - System.currentTimeMillis(); - long remSec = remTime / 1000L; - - if((int)remSec > 0) { - MutableText etaText = remSec > 60 ? TextUtil.translatable("gui.mtr.arrival_min", remSec / 60) : TextUtil.translatable("gui.mtr.arrival_sec", remSec % 60); - drawPIDSText(graphicsHolder, TextAlignment.RIGHT, facing, new TextInfo(etaText), width, 0, textColor); - } - } - - private void drawClock(GraphicsHolder graphicsHolder, Direction facing, World world, int x, int y, int textColor) { - long timeNow = WorldHelper.getTimeOfDay(world) + 6000; - long hours = timeNow / 1000; - long minutes = Math.round((timeNow - (hours * 1000)) / 16.8); - String timeString = String.format("%02d:%02d", hours % 24, minutes % 60); - drawPIDSText(graphicsHolder, TextAlignment.RIGHT, facing, timeString, x, y, textColor); - } + drawCalls.add(new ETADrawCall(arrival, getFont(), textColor, width, rowY, 100, 20, ARRIVAL_TEXT_SCALE)); + arrivalIndex++; + } - private void drawWeatherIcon(GraphicsHolder graphicsHolder, World world, Direction facing, float x) { - if(world.isRaining()) { - graphicsHolder.createVertexConsumer(RenderLayer.getText(ICON_WEATHER_RAINY)); - } else if(world.isThundering()) { - graphicsHolder.createVertexConsumer(RenderLayer.getText(ICON_WEATHER_THUNDER)); - } else { - graphicsHolder.createVertexConsumer(RenderLayer.getText(ICON_WEATHER_SUNNY)); + rowY += (height / 5.25) * ARRIVAL_TEXT_SCALE; } - RenderHelper.drawTexture(graphicsHolder, x, 0, 0, 11, 11, facing, ARGB_WHITE, MAX_RENDER_LIGHT); } @Override diff --git a/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/ClockDrawCall.java b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/ClockDrawCall.java new file mode 100644 index 00000000..e1bc5ed8 --- /dev/null +++ b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/ClockDrawCall.java @@ -0,0 +1,25 @@ +package com.lx862.jcm.mod.data.pids.preset.drawcalls; + +import com.lx862.jcm.mod.data.pids.preset.drawcalls.base.TextDrawCall; +import com.lx862.jcm.mod.render.TextOverflowMode; +import com.lx862.jcm.mod.render.text.TextAlignment; +import org.mtr.mapping.holder.Direction; +import org.mtr.mapping.holder.World; +import org.mtr.mapping.mapper.GraphicsHolder; +import org.mtr.mapping.mapper.WorldHelper; + +public class ClockDrawCall extends TextDrawCall { + // TODO: (Maybe next version) Add 12/24h toggle + public ClockDrawCall(String font, int textColor, double x, double y, double width, double height) { + super(font, textColor, x, y, width, height); + } + + @Override + public void render(GraphicsHolder graphicsHolder, World world, Direction facing) { + long timeNow = WorldHelper.getTimeOfDay(world) + 6000; + long hours = timeNow / 1000; + long minutes = Math.round((timeNow - (hours * 1000)) / 16.8); + String timeString = String.format("%02d:%02d", hours % 24, minutes % 60); + drawText(graphicsHolder, TextAlignment.RIGHT, facing, timeString, TextOverflowMode.STRETCH); + } +} diff --git a/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/DestinationDrawCall.java b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/DestinationDrawCall.java new file mode 100644 index 00000000..bc57c011 --- /dev/null +++ b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/DestinationDrawCall.java @@ -0,0 +1,39 @@ +package com.lx862.jcm.mod.data.pids.preset.drawcalls; + +import com.lx862.jcm.mod.data.pids.preset.drawcalls.base.TextDrawCall; +import com.lx862.jcm.mod.render.RenderHelper; +import com.lx862.jcm.mod.render.TextOverflowMode; +import com.lx862.jcm.mod.render.text.TextAlignment; +import com.lx862.jcm.mod.render.text.TextInfo; +import com.lx862.jcm.mod.render.text.TextRenderingManager; +import org.mtr.core.operation.ArrivalResponse; +import org.mtr.mapping.holder.Direction; +import org.mtr.mapping.holder.World; +import org.mtr.mapping.mapper.GraphicsHolder; + +public class DestinationDrawCall extends TextDrawCall { + private final ArrivalResponse arrival; + public DestinationDrawCall(ArrivalResponse arrival, String font, int textColor, double x, double y, double width, double height, double scale) { + super(font, textColor, x, y, width, height, scale); + this.arrival = arrival; + } + + @Override + public void render(GraphicsHolder graphicsHolder, World world, Direction facing) { + String routeNo = arrival.getRouteNumber().isEmpty() ? "" : arrival.getRouteNumber() + " "; + String leftDestination = routeNo + arrival.getDestination(); + TextInfo destinationText = new TextInfo(leftDestination).withColor(textColor).withFont(font); + + int destinationWidth = TextRenderingManager.getTextWidth(destinationText); + + graphicsHolder.push(); + if(destinationWidth > width) { + RenderHelper.scaleToFit(graphicsHolder, destinationWidth, width, false); + // TODO: Make marquee an option in custom PIDS Preset + //drawPIDSScrollingText(graphicsHolder, facing, leftDestination, 0, 0, textColor, (int)destinationMaxWidth - 2); + } + + drawText(graphicsHolder, TextAlignment.LEFT, facing, destinationText, TextOverflowMode.STRETCH); + graphicsHolder.pop(); + } +} diff --git a/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/ETADrawCall.java b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/ETADrawCall.java new file mode 100644 index 00000000..e3bff5e7 --- /dev/null +++ b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/ETADrawCall.java @@ -0,0 +1,32 @@ +package com.lx862.jcm.mod.data.pids.preset.drawcalls; + +import com.lx862.jcm.mod.data.pids.preset.drawcalls.base.TextDrawCall; +import com.lx862.jcm.mod.render.TextOverflowMode; +import com.lx862.jcm.mod.render.text.TextAlignment; +import com.lx862.jcm.mod.render.text.TextInfo; +import com.lx862.jcm.mod.util.TextUtil; +import org.mtr.core.operation.ArrivalResponse; +import org.mtr.mapping.holder.Direction; +import org.mtr.mapping.holder.MutableText; +import org.mtr.mapping.holder.World; +import org.mtr.mapping.mapper.GraphicsHolder; + +public class ETADrawCall extends TextDrawCall { + // TODO: (Maybe next version) Add absolute time? + private final ArrivalResponse arrival; + public ETADrawCall(ArrivalResponse arrival, String font, int textColor, double x, double y, double width, double height, double scale) { + super(font, textColor, x, y, width, height, scale); + this.arrival = arrival; + } + + @Override + public void render(GraphicsHolder graphicsHolder, World world, Direction facing) { + long remTime = arrival.getArrival() - System.currentTimeMillis(); + long remSec = remTime / 1000L; + + if((int)remSec > 0) { + MutableText etaText = remSec > 60 ? TextUtil.translatable("gui.mtr.arrival_min", remSec / 60) : TextUtil.translatable("gui.mtr.arrival_sec", remSec % 60); + drawText(graphicsHolder, TextAlignment.RIGHT, facing, new TextInfo(etaText), TextOverflowMode.STRETCH); + } + } +} diff --git a/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/PlatformCircleDrawCall.java b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/PlatformCircleDrawCall.java new file mode 100644 index 00000000..9775f6bc --- /dev/null +++ b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/PlatformCircleDrawCall.java @@ -0,0 +1,21 @@ +package com.lx862.jcm.mod.data.pids.preset.drawcalls; + +import com.lx862.jcm.mod.data.pids.preset.drawcalls.base.TextureDrawCall; +import org.mtr.core.operation.ArrivalResponse; +import org.mtr.mapping.holder.Direction; +import org.mtr.mapping.holder.Identifier; +import org.mtr.mapping.holder.World; +import org.mtr.mapping.mapper.GraphicsHolder; + +public class PlatformCircleDrawCall extends TextureDrawCall { + private final ArrivalResponse arrival; + public PlatformCircleDrawCall(ArrivalResponse arrival, Identifier textureId, double x, double y, double width, double height) { + super(textureId, x, y, width, height); + this.arrival = arrival; + } + + @Override + public void render(GraphicsHolder graphicsHolder, World world, Direction facing) { + drawTexture(graphicsHolder, facing, texture, 0, 0, width, height, arrival.getRouteColor() + ARGB_BLACK); + } +} diff --git a/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/PlatformDrawCall.java b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/PlatformDrawCall.java new file mode 100644 index 00000000..0a6af2d1 --- /dev/null +++ b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/PlatformDrawCall.java @@ -0,0 +1,26 @@ +package com.lx862.jcm.mod.data.pids.preset.drawcalls; + +import com.lx862.jcm.mod.data.pids.preset.drawcalls.base.TextDrawCall; +import com.lx862.jcm.mod.render.RenderHelper; +import com.lx862.jcm.mod.render.TextOverflowMode; +import com.lx862.jcm.mod.render.text.TextAlignment; +import com.lx862.jcm.mod.render.text.TextInfo; +import com.lx862.jcm.mod.render.text.TextRenderingManager; +import org.mtr.core.operation.ArrivalResponse; +import org.mtr.mapping.holder.Direction; +import org.mtr.mapping.holder.World; +import org.mtr.mapping.mapper.GraphicsHolder; + +public class PlatformDrawCall extends TextDrawCall { + private final ArrivalResponse arrival; + public PlatformDrawCall(ArrivalResponse arrival, String font, int textColor, double x, double y, double width, double height) { + super(font, textColor, x, y, width, height, 1); + this.arrival = arrival; + } + + @Override + public void render(GraphicsHolder graphicsHolder, World world, Direction facing) { + graphicsHolder.translate(width / 1.6, 2, 0); + drawText(graphicsHolder, TextAlignment.CENTER, facing, arrival.getPlatformName(), TextOverflowMode.SCALE); + } +} diff --git a/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/WeatherIconDrawCall.java b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/WeatherIconDrawCall.java new file mode 100644 index 00000000..385616de --- /dev/null +++ b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/WeatherIconDrawCall.java @@ -0,0 +1,32 @@ +package com.lx862.jcm.mod.data.pids.preset.drawcalls; + +import com.lx862.jcm.mod.data.pids.preset.drawcalls.base.TextureDrawCall; +import org.mtr.mapping.holder.Direction; +import org.mtr.mapping.holder.Identifier; +import org.mtr.mapping.holder.World; +import org.mtr.mapping.mapper.GraphicsHolder; + +public class WeatherIconDrawCall extends TextureDrawCall { + private final Identifier iconSunny; + private final Identifier iconThunder; + private final Identifier iconRainy; + public WeatherIconDrawCall(Identifier iconSunny, Identifier iconRainy, Identifier iconThunder, double x, double y, double width, double height) { + super(null, x, y, width, height); + this.iconSunny = iconSunny; + this.iconRainy = iconRainy; + this.iconThunder = iconThunder; + } + + @Override + public void render(GraphicsHolder graphicsHolder, World world, Direction facing) { + Identifier textureId; + if(world.isRaining()) { + textureId = iconRainy; + } else if(world.isThundering()) { + textureId = iconThunder; + } else { + textureId = iconSunny; + } + drawTexture(graphicsHolder, facing, textureId, 0, 0, width, height, ARGB_WHITE); + } +} diff --git a/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/base/DrawCall.java b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/base/DrawCall.java new file mode 100644 index 00000000..3bf506d2 --- /dev/null +++ b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/base/DrawCall.java @@ -0,0 +1,22 @@ +package com.lx862.jcm.mod.data.pids.preset.drawcalls.base; + +import com.lx862.jcm.mod.render.RenderHelper; +import org.mtr.mapping.holder.Direction; +import org.mtr.mapping.holder.World; +import org.mtr.mapping.mapper.GraphicsHolder; + +public abstract class DrawCall implements RenderHelper { + protected final double x; + protected final double y; + protected final double width; + protected final double height; + + public DrawCall(double x, double y, double width, double height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + public abstract void render(GraphicsHolder graphicsHolder, World world, Direction facing); +} diff --git a/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/base/TextDrawCall.java b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/base/TextDrawCall.java new file mode 100644 index 00000000..31864c77 --- /dev/null +++ b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/base/TextDrawCall.java @@ -0,0 +1,40 @@ +package com.lx862.jcm.mod.data.pids.preset.drawcalls.base; + +import com.lx862.jcm.mod.render.RenderHelper; +import com.lx862.jcm.mod.render.TextOverflowMode; +import com.lx862.jcm.mod.render.text.TextAlignment; +import com.lx862.jcm.mod.render.text.TextInfo; +import com.lx862.jcm.mod.render.text.TextRenderingManager; +import org.mtr.mapping.holder.Direction; +import org.mtr.mapping.mapper.GraphicsHolder; + +public abstract class TextDrawCall extends DrawCall { + protected final String font; + protected final int textColor; + protected final double scale; + + public TextDrawCall(String font, int textColor, double x, double y, double width, double height, double scale) { + super(x, y, width, height); + this.font = font; + this.textColor = textColor; + this.scale = scale; + } + + public TextDrawCall(String font, int textColor, double x, double y, double width, double height) { + this(font, textColor, x, y, width, height, 1); + } + + protected void drawText(GraphicsHolder graphicsHolder, TextAlignment textAlignment, Direction facing, String text, TextOverflowMode textOverflowMode) { + drawText(graphicsHolder, textAlignment, facing, new TextInfo(text), textOverflowMode); + } + + protected void drawText(GraphicsHolder graphicsHolder, TextAlignment textAlignment, Direction facing, TextInfo text, TextOverflowMode textOverflowMode) { + TextInfo finalText = text.withColor(textColor).withFont(font).withTextAlignment(textAlignment); + graphicsHolder.push(); + graphicsHolder.translate(x, y, 0); + graphicsHolder.scale((float)scale, (float)scale, (float)scale); + RenderHelper.scaleToFit(graphicsHolder, TextRenderingManager.getTextWidth(finalText), width, textOverflowMode == TextOverflowMode.SCALE, 12); + TextRenderingManager.draw(graphicsHolder, finalText, facing, 0, 0); + graphicsHolder.pop(); + } +} diff --git a/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/base/TextureDrawCall.java b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/base/TextureDrawCall.java new file mode 100644 index 00000000..383f6901 --- /dev/null +++ b/fabric/src/main/java/com/lx862/jcm/mod/data/pids/preset/drawcalls/base/TextureDrawCall.java @@ -0,0 +1,30 @@ +package com.lx862.jcm.mod.data.pids.preset.drawcalls.base; + +import com.lx862.jcm.mod.render.RenderHelper; +import org.mtr.mapping.holder.Direction; +import org.mtr.mapping.holder.Identifier; +import org.mtr.mapping.holder.RenderLayer; +import org.mtr.mapping.holder.World; +import org.mtr.mapping.mapper.GraphicsHolder; + +public class TextureDrawCall extends DrawCall { + protected final Identifier texture; + public TextureDrawCall(Identifier texture, double x, double y, double width, double height) { + super(x, y, width, height); + this.texture = texture; + } + + @Override + public void render(GraphicsHolder graphicsHolder, World world, Direction facing) { + if(texture != null) { + drawTexture(graphicsHolder, facing, texture, 0, 0, width, height, ARGB_WHITE); + } + } + + public void drawTexture(GraphicsHolder graphicsHolder, Direction facing, Identifier identifier, double x, double y, double width, double height, int color) { + graphicsHolder.push(); + graphicsHolder.createVertexConsumer(RenderLayer.getText(identifier)); + RenderHelper.drawTexture(graphicsHolder, (float)(this.x + x), (float)(this.y + y), 0, (float)width, (float)height, facing, color, RenderHelper.MAX_RENDER_LIGHT); + graphicsHolder.pop(); + } +} diff --git a/fabric/src/main/java/com/lx862/jcm/mod/render/text/TextRenderingManager.java b/fabric/src/main/java/com/lx862/jcm/mod/render/text/TextRenderingManager.java index 6be0b4a6..fbbf1784 100644 --- a/fabric/src/main/java/com/lx862/jcm/mod/render/text/TextRenderingManager.java +++ b/fabric/src/main/java/com/lx862/jcm/mod/render/text/TextRenderingManager.java @@ -38,15 +38,15 @@ public static void drawScrollingText(GraphicsHolder graphicsHolder, TextInfo tex draw(graphicsHolder, text.withMaxWidth(textWidth).withScrollingText(), facing, x, y); } - public static void draw(GraphicsHolder graphicsHolder, MutableText text, Direction facing, int x, int y) { + public static void draw(GraphicsHolder graphicsHolder, MutableText text, Direction facing, double x, double y) { draw(graphicsHolder, new TextInfo(text), facing, x, y); } - public static void draw(GraphicsHolder graphicsHolder, TextInfo text, Direction facing, int x, int y) { + public static void draw(GraphicsHolder graphicsHolder, TextInfo text, Direction facing, double x, double y) { drawInternal(graphicsHolder, text, facing, x, y); } - private static void drawInternal(GraphicsHolder graphicsHolder, TextInfo text, Direction facing, int x, int y) { + private static void drawInternal(GraphicsHolder graphicsHolder, TextInfo text, Direction facing, double x, double y) { if(!ConfigEntry.NEW_TEXT_RENDERER.getBool()) { if(text.isForScrollingText()) { VanillaTextRenderer.drawScrollingText(graphicsHolder, text.getContent(), (int)text.getWidthInfo().getMaxWidth(), x, y, text.getTextColor()); diff --git a/fabric/src/main/java/com/lx862/jcm/mod/render/text/TextureTextRenderer.java b/fabric/src/main/java/com/lx862/jcm/mod/render/text/TextureTextRenderer.java index 7ce8a416..d9c9c03a 100644 --- a/fabric/src/main/java/com/lx862/jcm/mod/render/text/TextureTextRenderer.java +++ b/fabric/src/main/java/com/lx862/jcm/mod/render/text/TextureTextRenderer.java @@ -237,7 +237,7 @@ private static TextSlot getTextSlot(TextInfo textInfo) { return null; } - public static void draw(GraphicsHolder graphicsHolder, TextInfo text, Direction facing, int x, int y) { + public static void draw(GraphicsHolder graphicsHolder, TextInfo text, Direction facing, double x, double y) { ensureInitialized(); TextSlot textSlot = getTextSlot(text); @@ -249,7 +249,7 @@ public static void draw(GraphicsHolder graphicsHolder, TextInfo text, Direction if(textSlot != null) { float finalX = (float)text.getTextAlignment().getX(x, textSlot.getRenderedWidth()); - drawToWorld(graphicsHolder, textSlot, facing, finalX, y); + drawToWorld(graphicsHolder, textSlot, facing, finalX, (float)y); } } diff --git a/fabric/src/main/java/com/lx862/jcm/mod/render/text/VanillaTextRenderer.java b/fabric/src/main/java/com/lx862/jcm/mod/render/text/VanillaTextRenderer.java index 65d77496..50b4d1e4 100644 --- a/fabric/src/main/java/com/lx862/jcm/mod/render/text/VanillaTextRenderer.java +++ b/fabric/src/main/java/com/lx862/jcm/mod/render/text/VanillaTextRenderer.java @@ -10,18 +10,18 @@ * Wrapper around vanilla text rendering */ public class VanillaTextRenderer implements RenderHelper { - public static void draw(GraphicsHolder graphicsHolder, TextInfo text, int x, int y) { + public static void draw(GraphicsHolder graphicsHolder, TextInfo text, double x, double y) { drawInternal(graphicsHolder, text, x, y); } - private static void drawInternal(GraphicsHolder graphicsHolder, TextInfo text, int x, int y) { + private static void drawInternal(GraphicsHolder graphicsHolder, TextInfo text, double x, double y) { int textWidth = GraphicsHolder.getTextWidth(text.toMutableText()); double finalX = text.getTextAlignment().getX(x, textWidth); MutableText finalText = text.toMutableText(); - graphicsHolder.drawText(finalText, (int)finalX, y, text.getTextColor(), false, MAX_RENDER_LIGHT); + graphicsHolder.drawText(finalText, (int)finalX, (int)y, text.getTextColor(), false, MAX_RENDER_LIGHT); } - public static void drawScrollingText(GraphicsHolder graphicsHolder, String text, int maxW, int x, int y, int textColor) { + public static void drawScrollingText(GraphicsHolder graphicsHolder, String text, int maxW, double x, double y, int textColor) { String str = text; int scrollSpeed = str.length() * 6; int fullTick = (JCMStats.getGameTick() % (int)(scrollSpeed * 1.5)); @@ -64,7 +64,7 @@ public static void drawScrollingText(GraphicsHolder graphicsHolder, String text, graphicsHolder.translate(-((prg - start) * nextCharWidth), 0, 0); } - graphicsHolder.drawText(newText, x, y, textColor, false, MAX_RENDER_LIGHT); + graphicsHolder.drawText(newText, (int)x, (int)y, textColor, false, MAX_RENDER_LIGHT); graphicsHolder.pop(); }