mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 13:20:43 +00:00
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 <img width="1009" height="872" alt="image" src="https://github.com/user-attachments/assets/31c028a8-13d8-4d82-ba4a-385b8372c9ac" /> ### Alternative View (spacebar) <img width="1124" height="956" alt="image" src="https://github.com/user-attachments/assets/f4f3bb38-7233-4f2c-9bbf-a407196b0124" /> ### Other nation colors remain unchanged <img width="1566" height="1447" alt="image" src="https://github.com/user-attachments/assets/c4dde970-20f1-480b-959d-876d4eb0f32b" /> ## 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
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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<TileRef, RailRef>();
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user