mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-26 18:44:37 +00:00
ctrl + click brings up build menu
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { EventBus, GameEvent } from "../core/EventBus";
|
||||
import { Game } from "../core/game/Game";
|
||||
|
||||
|
||||
export class MouseUpEvent implements GameEvent {
|
||||
@@ -48,10 +49,14 @@ export class AlternateViewEvent implements GameEvent {
|
||||
constructor(public readonly alternateView: boolean) { }
|
||||
}
|
||||
|
||||
export class RefreshGraphicsEvent implements GameEvent {
|
||||
export class RefreshGraphicsEvent implements GameEvent { }
|
||||
|
||||
export class ShowBuildMenuEvent implements GameEvent {
|
||||
constructor(public readonly x: number, public readonly y: number) { }
|
||||
}
|
||||
|
||||
|
||||
|
||||
export class InputHandler {
|
||||
|
||||
private lastPointerX: number = 0;
|
||||
@@ -113,6 +118,7 @@ export class InputHandler {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
this.pointerDown = true
|
||||
this.pointers.set(event.pointerId, event);
|
||||
|
||||
@@ -136,6 +142,11 @@ export class InputHandler {
|
||||
this.pointerDown = false
|
||||
this.pointers.clear()
|
||||
|
||||
if (event.ctrlKey) {
|
||||
this.eventBus.emit(new ShowBuildMenuEvent(event.clientX, event.clientY))
|
||||
return
|
||||
}
|
||||
|
||||
const dist = Math.abs(event.x - this.lastPointerDownX) + Math.abs(event.y - this.lastPointerDownY);
|
||||
if (dist < 10) {
|
||||
if (event.pointerType == "touch") {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { EventBus } from "../../../../core/EventBus";
|
||||
import { AllPlayers, Cell, Game, Player, UnitType } from "../../../../core/game/Game";
|
||||
import { ClientID } from "../../../../core/Schemas";
|
||||
import { and, bfs, dist, manhattanDist, manhattanDistWrapped, sourceDstOceanShore, targetTransportTile } from "../../../../core/Util";
|
||||
import { ContextMenuEvent, MouseUpEvent } from "../../../InputHandler";
|
||||
import { ContextMenuEvent, MouseUpEvent, ShowBuildMenuEvent } from "../../../InputHandler";
|
||||
import { SendAllianceRequestIntentEvent, SendAttackIntentEvent, SendBoatAttackIntentEvent, SendBreakAllianceIntentEvent, SendDonateIntentEvent, SendEmojiIntentEvent, SendSpawnIntentEvent, SendTargetPlayerIntentEvent } from "../../../Transport";
|
||||
import { TransformHandler } from "../../TransformHandler";
|
||||
import { Layer } from "../Layer";
|
||||
@@ -64,6 +64,20 @@ export class RadialMenu implements Layer {
|
||||
init() {
|
||||
this.eventBus.on(ContextMenuEvent, e => this.onContextMenu(e))
|
||||
this.eventBus.on(MouseUpEvent, e => this.onPointerUp(e))
|
||||
this.eventBus.on(ShowBuildMenuEvent, e => {
|
||||
const clickedCell = this.transformHandler.screenToWorldCoordinates(e.x, e.y)
|
||||
if (clickedCell == null) {
|
||||
return
|
||||
}
|
||||
if (!this.game.isOnMap(clickedCell)) {
|
||||
return
|
||||
}
|
||||
const p = this.game.playerByClientID(this.clientID)
|
||||
if (p == null) {
|
||||
return
|
||||
}
|
||||
this.buildMenu.showMenu(p, clickedCell)
|
||||
})
|
||||
this.createMenuElement();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user