diff --git a/src/client/graphics/layers/EventsDisplay.ts b/src/client/graphics/layers/EventsDisplay.ts index 1e255df66..8458c1faf 100644 --- a/src/client/graphics/layers/EventsDisplay.ts +++ b/src/client/graphics/layers/EventsDisplay.ts @@ -24,7 +24,9 @@ import { CancelAttackIntentEvent, SendAllianceReplyIntentEvent, } from "../../Transport"; -import { unsafeHTML } from "lit/directives/unsafe-html.js"; +import { unsafeHTML, UnsafeHTMLDirective } from "lit/directives/unsafe-html.js"; +import { DirectiveResult } from "lit/directive.js"; + import { onlyImages, sanitize } from "../../../core/Util"; import { GameView, PlayerView } from "../../../core/game/GameView"; import { renderTroops } from "../../Utils"; @@ -46,6 +48,7 @@ interface Event { // lower number: lower on the display priority?: number; duration?: Tick; + focusID?: number; } @customElement("events-display") @@ -218,6 +221,7 @@ export class EventsDisplay extends LitElement implements Layer { ), priority: 0, duration: 150, + focusID: update.requestorID, }); } @@ -238,6 +242,7 @@ export class EventsDisplay extends LitElement implements Layer { type: update.accepted ? MessageType.SUCCESS : MessageType.ERROR, highlight: true, createdAt: this.game.ticks(), + focusID: update.request.recipientID, }); } @@ -254,6 +259,7 @@ export class EventsDisplay extends LitElement implements Layer { type: MessageType.ERROR, highlight: true, createdAt: this.game.ticks(), + focusID: update.betrayedID, }); } else if (betrayed === myPlayer) { this.addEvent({ @@ -261,6 +267,7 @@ export class EventsDisplay extends LitElement implements Layer { type: MessageType.ERROR, highlight: true, createdAt: this.game.ticks(), + focusID: update.traitorID, }); } } @@ -283,6 +290,7 @@ export class EventsDisplay extends LitElement implements Layer { type: MessageType.WARN, highlight: true, createdAt: this.game.ticks(), + focusID: otherID, }); } @@ -298,6 +306,7 @@ export class EventsDisplay extends LitElement implements Layer { type: MessageType.INFO, highlight: true, createdAt: this.game.ticks(), + focusID: event.targetID, }); } @@ -307,6 +316,12 @@ export class EventsDisplay extends LitElement implements Layer { this.eventBus.emit(new CancelAttackIntentEvent(myPlayer.id(), id)); } + emitGoToPlayerEvent(attackerID: number) { + const attacker = this.game.playerBySmallID(attackerID) as PlayerView; + if (!attacker) return; + this.eventBus.emit(new GoToPlayerEvent(attacker)); + } + onEmojiMessageEvent(update: EmojiUpdate) { const myPlayer = this.game.playerByClientID(this.clientID); if (!myPlayer) return; @@ -326,6 +341,7 @@ export class EventsDisplay extends LitElement implements Layer { type: MessageType.INFO, highlight: true, createdAt: this.game.ticks(), + focusID: update.emoji.senderID, }); } else if (sender === myPlayer && recipient !== AllPlayers) { this.addEvent({ @@ -336,6 +352,7 @@ export class EventsDisplay extends LitElement implements Layer { type: MessageType.INFO, highlight: true, createdAt: this.game.ticks(), + focusID: recipient.smallID(), }); } } @@ -355,6 +372,14 @@ export class EventsDisplay extends LitElement implements Layer { } } + private getEventDescription( + event: Event, + ): string | DirectiveResult { + return event.unsafeDescription + ? unsafeHTML(onlyImages(event.description)) + : event.description; + } + private renderAttacks() { if ( this.incomingAttacks.length === 0 && @@ -370,25 +395,18 @@ export class EventsDisplay extends LitElement implements Layer { ${this.incomingAttacks.map( (attack) => html` -
+ -
+ `, )} @@ -401,22 +419,26 @@ export class EventsDisplay extends LitElement implements Layer { ${this.outgoingAttacks.map( (attack) => html` -
+ ` - : "(retreating...)"} -
+ + + ${!attack.retreating + ? html`` + : "(retreating...)"} `, )} @@ -491,9 +513,15 @@ export class EventsDisplay extends LitElement implements Layer { )}" > - ${event.unsafeDescription - ? unsafeHTML(onlyImages(event.description)) - : event.description} + ${event.focusID + ? html`` + : this.getEventDescription(event)} ${event.buttons ? html`