diff --git a/src/client/graphics/layers/PlayerPanel.ts b/src/client/graphics/layers/PlayerPanel.ts index 2ad88181f..fc598de53 100644 --- a/src/client/graphics/layers/PlayerPanel.ts +++ b/src/client/graphics/layers/PlayerPanel.ts @@ -145,8 +145,14 @@ export class PlayerPanel extends LitElement implements Layer { this.eventBus.on(MouseUpEvent, (e: MouseEvent) => this.hide()); } - tick() { - this.requestUpdate(); + async tick() { + if (this.isVisible && this.tile) { + const myPlayer = this.g.myPlayer(); + if (myPlayer !== null && myPlayer.isAlive()) { + this.actions = await myPlayer.actions(this.tile); + this.requestUpdate(); + } + } } getTotalNukesSent(otherId: PlayerID): number { diff --git a/src/client/graphics/layers/RadialMenu.ts b/src/client/graphics/layers/RadialMenu.ts index 75cd9c198..e161f7217 100644 --- a/src/client/graphics/layers/RadialMenu.ts +++ b/src/client/graphics/layers/RadialMenu.ts @@ -8,7 +8,7 @@ import swordIcon from "../../../../resources/images/SwordIconWhite.svg"; import traitorIcon from "../../../../resources/images/TraitorIconWhite.svg"; import { consolex } from "../../../core/Consolex"; import { EventBus } from "../../../core/EventBus"; -import { Cell, PlayerActions } from "../../../core/game/Game"; +import { Cell, PlayerActions, TerraNullius } from "../../../core/game/Game"; import { TileRef } from "../../../core/game/GameMap"; import { GameView, PlayerView } from "../../../core/game/GameView"; import { ClientID } from "../../../core/Schemas"; @@ -44,6 +44,7 @@ export class RadialMenu implements Layer { private clickedCell: Cell | null = null; private lastClosed: number = 0; + private originalTileOwner: PlayerView | TerraNullius; private menuElement: d3.Selection; private isVisible: boolean = false; private readonly menuItems = new Map([ @@ -267,8 +268,26 @@ export class RadialMenu implements Layer { .style("pointer-events", "none"); } - tick() { - // Update logic if needed + async tick() { + // Only update when menu is visible + if (!this.isVisible || this.clickedCell === null) return; + const myPlayer = this.g.myPlayer(); + if (myPlayer === null || !myPlayer.isAlive()) return; + const tile = this.g.ref(this.clickedCell.x, this.clickedCell.y); + if (this.originalTileOwner.isPlayer()) { + if (this.g.owner(tile) != this.originalTileOwner) { + this.closeMenu(); + return; + } + } else { + if (this.g.owner(tile).isPlayer() || this.g.owner(tile) == myPlayer) { + this.closeMenu(); + return; + } + } + const actions = await myPlayer.actions(tile); + this.disableAllButtons(); + this.handlePlayerActions(myPlayer, actions, tile); } renderLayer(context: CanvasRenderingContext2D) { @@ -291,12 +310,7 @@ export class RadialMenu implements Layer { } else { this.showRadialMenu(event.x, event.y); } - this.enableCenterButton(false); - for (const item of this.menuItems.values()) { - item.disabled = true; - this.updateMenuItemState(item); - } - + this.disableAllButtons(); this.clickedCell = this.transformHandler.screenToWorldCoordinates( event.x, event.y, @@ -305,7 +319,7 @@ export class RadialMenu implements Layer { return; } const tile = this.g.ref(this.clickedCell.x, this.clickedCell.y); - + this.originalTileOwner = this.g.owner(tile); if (this.g.inSpawnPhase()) { if (this.g.isLand(tile) && !this.g.hasOwner(tile)) { this.enableCenterButton(true); @@ -313,10 +327,8 @@ export class RadialMenu implements Layer { return; } - const myPlayer = this.g - .playerViews() - .find((p) => p.clientID() == this.clientID); - if (!myPlayer) { + const myPlayer = this.g.myPlayer(); + if (myPlayer === null) { consolex.warn("my player not found"); return; } @@ -430,6 +442,14 @@ export class RadialMenu implements Layer { this.hideRadialMenu(); } + private disableAllButtons() { + this.enableCenterButton(false); + for (const item of this.menuItems.values()) { + item.disabled = true; + this.updateMenuItemState(item); + } + } + private activateMenuElement( slot: Slot, color: string,