mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:30:45 +00:00
Wire view-mode toggles (alt-view + coordinate grid) via new ViewModeController
Moves the AlternateViewEvent / ToggleCoordinateGridEvent subscriptions out of ClientGameRunner into a dedicated controller in src/client/controllers/. Also wires ToggleCoordinateGridEvent (M keybind) — previously emitted with no listener — so the persistent coordinate-grid toggle works. Grid + alt-view hide names only under alt-view; M keeps names visible.
This commit is contained in:
@@ -37,7 +37,6 @@ import {
|
||||
import { WorkerClient } from "../core/worker/WorkerClient";
|
||||
import { getPersistentID } from "./Auth";
|
||||
import {
|
||||
AlternateViewEvent,
|
||||
AutoUpgradeEvent,
|
||||
DoBoatAttackEvent,
|
||||
DoBreakAllianceEvent,
|
||||
@@ -473,11 +472,6 @@ async function createClientGame(
|
||||
(e) => applyDayNightMode((e as CustomEvent<string>).detail === "true"),
|
||||
);
|
||||
|
||||
// Space-hold (and the settings-modal toggle) drives the affiliation
|
||||
// recolor. InputHandler emits AlternateViewEvent; the WebGL view needs
|
||||
// setAltView called to switch passes into alt mode.
|
||||
eventBus.on(AlternateViewEvent, (e) => view.setAltView(e.alternateView));
|
||||
|
||||
view.setShowPatterns(userSettings.territoryPatterns());
|
||||
globalThis.addEventListener(
|
||||
`${USER_SETTINGS_CHANGED_EVENT}:settings.territoryPatterns`,
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* ViewModeController — forwards map view-mode toggles to the WebGL view.
|
||||
*
|
||||
* - AlternateViewEvent: space-hold (and the settings-modal toggle) drives the
|
||||
* affiliation recolor + grid overlay + hides names.
|
||||
* - ToggleCoordinateGridEvent: persistent coordinate-grid toggle (M keybind);
|
||||
* grid shows but names stay visible.
|
||||
*/
|
||||
|
||||
import { EventBus } from "../../core/EventBus";
|
||||
import { Controller } from "../Controller";
|
||||
import { AlternateViewEvent, ToggleCoordinateGridEvent } from "../InputHandler";
|
||||
import { GameView as WebGLGameView } from "../render/gl";
|
||||
|
||||
export class ViewModeController implements Controller {
|
||||
constructor(
|
||||
private eventBus: EventBus,
|
||||
private view: WebGLGameView,
|
||||
) {}
|
||||
|
||||
init() {
|
||||
this.eventBus.on(AlternateViewEvent, (e) =>
|
||||
this.view.setAltView(e.alternateView),
|
||||
);
|
||||
this.eventBus.on(ToggleCoordinateGridEvent, (e) =>
|
||||
this.view.setGridView(e.enabled),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { UIState } from "../UIState";
|
||||
import { BuildPreviewController } from "../controllers/BuildPreviewController";
|
||||
import { HoverHighlightController } from "../controllers/HoverHighlightController";
|
||||
import { StructureHighlightController } from "../controllers/StructureHighlightController";
|
||||
import { ViewModeController } from "../controllers/ViewModeController";
|
||||
import { WarshipSelectionController } from "../controllers/WarshipSelectionController";
|
||||
import { GameView as WebGLGameView } from "../render/gl";
|
||||
import { FrameProfiler } from "./FrameProfiler";
|
||||
@@ -281,6 +282,7 @@ export function createRenderer(
|
||||
),
|
||||
new HoverHighlightController(game, eventBus, transformHandler, view),
|
||||
new StructureHighlightController(eventBus, view),
|
||||
new ViewModeController(eventBus, view),
|
||||
new AttackingTroopsOverlay(game, transformHandler, eventBus, userSettings),
|
||||
eventsDisplay,
|
||||
actionableEvents,
|
||||
|
||||
@@ -371,6 +371,9 @@ export class GameView {
|
||||
setAltView(active: boolean): void {
|
||||
this.renderer?.setAltView(active);
|
||||
}
|
||||
setGridView(active: boolean): void {
|
||||
this.renderer?.setGridView(active);
|
||||
}
|
||||
setShowPatterns(active: boolean): void {
|
||||
this.renderer?.setShowPatterns(active);
|
||||
}
|
||||
|
||||
@@ -1176,8 +1176,10 @@ export class GPURenderer {
|
||||
this.worldTextPass.tick();
|
||||
this.worldTextPass.draw(cam, zoom);
|
||||
|
||||
if (this.gridView) this.coordinateGridPass.draw(cam, zoom);
|
||||
if (pe.name && !this.gridView)
|
||||
// Grid shows on either trigger; names hide only under alt-view (space
|
||||
// hold), not under the persistent M-key gridView toggle.
|
||||
if (this.gridView || this.altView) this.coordinateGridPass.draw(cam, zoom);
|
||||
if (pe.name && !this.altView)
|
||||
this.namePass.draw(cam, this.nightCompositePass.getAmbient());
|
||||
|
||||
this.radialMenuPass.draw();
|
||||
|
||||
@@ -255,7 +255,7 @@
|
||||
"gradientSolidEnd": 0.1
|
||||
},
|
||||
"altView": {
|
||||
"gridFontSize": 16,
|
||||
"gridFontSize": 24,
|
||||
"recolorStructures": true
|
||||
},
|
||||
"tileDrip": {
|
||||
|
||||
Reference in New Issue
Block a user