From c9f00a5eb83d4ca654bb7789a3820e635cd8bee2 Mon Sep 17 00:00:00 2001 From: bijx Date: Wed, 17 Dec 2025 22:46:32 -0500 Subject: [PATCH] feat: Factory Railway Tracks become more visible in Alternate View (#2626) ## Description: Adds network bright green highlighting to Railway tracks connecting _your_ factories and buildings together when in the alternate view (spacebar view). It is sometimes hard to see your own tracks on certain areas of the map (mountain terrains for example), so this change will highlight the tracks the same color as your border outline in the alternate view (#00FF00). Also suggested by [this comment](https://discord.com/channels/1284581928254701718/1445984695752855562/1445984695752855562) in the Discord. ### Normal Railway Connection image ### Alternative View (spacebar) image ### Other nation colors remain unchanged image ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: bijx --- src/client/graphics/GameRenderer.ts | 2 +- src/client/graphics/layers/RailroadLayer.ts | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/client/graphics/GameRenderer.ts b/src/client/graphics/GameRenderer.ts index 703479ad0..84fff4175 100644 --- a/src/client/graphics/GameRenderer.ts +++ b/src/client/graphics/GameRenderer.ts @@ -240,7 +240,7 @@ export function createRenderer( const layers: Layer[] = [ new TerrainLayer(game, transformHandler), new TerritoryLayer(game, eventBus, transformHandler, userSettings), - new RailroadLayer(game, transformHandler), + new RailroadLayer(game, eventBus, transformHandler), structureLayer, samRadiusLayer, new UnitLayer(game, eventBus, transformHandler), diff --git a/src/client/graphics/layers/RailroadLayer.ts b/src/client/graphics/layers/RailroadLayer.ts index d53ad2470..40157cec2 100644 --- a/src/client/graphics/layers/RailroadLayer.ts +++ b/src/client/graphics/layers/RailroadLayer.ts @@ -1,5 +1,6 @@ import { colord } from "colord"; import { Theme } from "../../../core/configuration/Config"; +import { EventBus } from "../../../core/EventBus"; import { PlayerID } from "../../../core/game/Game"; import { TileRef } from "../../../core/game/GameMap"; import { @@ -9,6 +10,7 @@ import { RailType, } from "../../../core/game/GameUpdates"; import { GameView } from "../../../core/game/GameView"; +import { AlternateViewEvent } from "../../InputHandler"; import { TransformHandler } from "../TransformHandler"; import { Layer } from "./Layer"; import { getBridgeRects, getRailroadRects } from "./RailroadSprites"; @@ -23,6 +25,7 @@ export class RailroadLayer implements Layer { private canvas: HTMLCanvasElement; private context: CanvasRenderingContext2D; private theme: Theme; + private alternativeView = false; // Save the number of railroads per tiles. Delete when it reaches 0 private existingRailroads = new Map(); private nextRailIndexToCheck = 0; @@ -33,6 +36,7 @@ export class RailroadLayer implements Layer { constructor( private game: GameView, + private eventBus: EventBus, private transformHandler: TransformHandler, ) { this.theme = game.config().theme(); @@ -88,6 +92,12 @@ export class RailroadLayer implements Layer { } init() { + this.eventBus.on(AlternateViewEvent, (e) => { + this.alternativeView = e.alternateView; + for (const { tile } of this.existingRailroads.values()) { + this.paintRail(tile); + } + }); this.redraw(); } @@ -244,9 +254,14 @@ export class RailroadLayer implements Layer { } const owner = this.game.owner(tile); const recipient = owner.isPlayer() ? owner : null; - const color = recipient + let color = recipient ? recipient.borderColor() : colord("rgba(255,255,255,1)"); + + if (this.alternativeView && recipient?.isMe()) { + color = colord("#00ff00"); + } + this.context.fillStyle = color.toRgbString(); this.paintRailRects(this.context, x, y, railType); }