diff --git a/src/client/graphics/layers/PlayerInfoOverlay.ts b/src/client/graphics/layers/PlayerInfoOverlay.ts index 7cdf12a8f..250de942e 100644 --- a/src/client/graphics/layers/PlayerInfoOverlay.ts +++ b/src/client/graphics/layers/PlayerInfoOverlay.ts @@ -1,4 +1,4 @@ -import { LitElement, html, css } from 'lit'; +import { LitElement, html } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; import { Layer } from './Layer'; import { Game, GameType, Player, PlayerProfile, PlayerType, Relation, Unit, UnitType } from '../../../core/game/Game'; @@ -54,7 +54,7 @@ export class PlayerInfoOverlay extends LitElement implements Layer { private _isActive = false; - private lastMouseUpdate = 0 + private lastMouseUpdate = 0; init() { this.eventBus.on(MouseMoveEvent, (e: MouseMoveEvent) => this.onMouseEvent(e)); @@ -68,7 +68,6 @@ export class PlayerInfoOverlay extends LitElement implements Layer { } this.lastMouseUpdate = now - this.setVisible(false); this.unit = null; this.player = null; @@ -125,54 +124,58 @@ export class PlayerInfoOverlay extends LitElement implements Layer { return this.game.playerByClientID(this.clientID); } + private getRelationClass(relation: Relation): string { + switch (relation) { + case Relation.Hostile: + return 'text-red-500'; + case Relation.Distrustful: + return 'text-red-300'; + case Relation.Neutral: + return 'text-white'; + case Relation.Friendly: + return 'text-green-500'; + default: + return 'text-white'; + } + } + private renderPlayerInfo(player: PlayerView) { const myPlayer = this.myPlayer(); - const isAlly = myPlayer?.isAlliedWith(player) + const isAlly = myPlayer?.isAlliedWith(player); let relationHtml = null; + if (player.type() == PlayerType.FakeHuman && myPlayer != null) { - let classType = ''; - let relationName = ''; const relation = this.playerProfile?.relations[myPlayer.smallID()] ?? Relation.Neutral; - switch (relation) { - case Relation.Hostile: - classType = 'hostile'; - relationName = 'Hostile'; - break; - case Relation.Distrustful: - classType = 'distrustful'; - relationName = 'Distrustful'; - break; - case Relation.Neutral: - classType = 'neutral'; - relationName = 'Neutral'; - break; - case Relation.Friendly: - classType = 'friendly'; - relationName = 'Friendly'; - break; - } - - relationHtml = html`
Attitude: ${relationName}
`; + const relationClass = this.getRelationClass(relation); + const relationName = Relation[relation]; + + relationHtml = html` +
+ Attitude: ${relationName} +
+ `; } + return html` -
-
${player.name()}
-
Troops: ${renderTroops(player.troops())}
-
Gold: ${renderNumber(player.gold())}
- ${relationHtml == null ? '' : relationHtml} -
+
+
${player.name()}
+
Troops: ${renderTroops(player.troops())}
+
Gold: ${renderNumber(player.gold())}
+ ${relationHtml} +
`; } private renderUnitInfo(unit: UnitView) { const isAlly = (unit.owner() == this.myPlayer() || this.myPlayer()?.isAlliedWith(unit.owner())) ?? false; + return html` -
-
${unit.owner().name()}
-
-
${unit.type()}
+
+
${unit.owner().name()}
+
+
${unit.type()}
${unit.hasHealth() ? html` -
Health: ${unit.health()}
+
Health: ${unit.health()}
` : ''}
@@ -183,144 +186,20 @@ export class PlayerInfoOverlay extends LitElement implements Layer { if (!this._isActive) { return html``; } + + const containerClasses = this._isInfoVisible ? 'opacity-100 visible' : 'opacity-0 invisible pointer-events-none'; + return html` -
- -
- ${this.player != null ? this.renderPlayerInfo(this.player) : ''} - ${this.unit != null ? this.renderUnitInfo(this.unit) : ''} +
+
+ ${this.player != null ? this.renderPlayerInfo(this.player) : ''} + ${this.unit != null ? this.renderUnitInfo(this.unit) : ''} +
-
- `; + `; } - static styles = css` - :host { - display: block; - } - - .container { - position: fixed; - top: 90px; - right: 10px; - z-index: 9999; - display: flex; - flex-direction: column; - } - - .controls { - align-self: flex-end; - margin-bottom: 4px; - z-index: 2; - display: flex; - gap: 8px; - } - - .control-button { - background: rgba(30, 30, 30, 0.7); - border: none; - color: white; - font-size: 24px; - cursor: pointer; - padding: 4px 8px; - border-radius: 4px; - opacity: 0.7; - transition: opacity 0.2s, background-color 0.2s; - backdrop-filter: blur(5px); - } - - .control-button:hover { - opacity: 1; - background: rgba(40, 40, 40, 0.8); - } - - .pause-button { - font-size: 20px; - padding: 4px 10px; - } - - .player-info { - background-color: rgba(30, 30, 30, 0.7); - padding: 8px 12px; - border-radius: 6px; - box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); - backdrop-filter: blur(5px); - transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out; - color: white; - font-size: 18px; - min-width: 120px; - text-align: left; - } - - .hidden { - opacity: 0; - visibility: hidden; - pointer-events: none; - } - - .info-content { - margin-top: 8px; - } - - .player-name { - font-weight: bold; - margin-bottom: 4px; - } - - .player-name.ally { - color: #4CAF50; - } - - .type-label { - font-size: 14px; - opacity: 0.8; - } - - .unit-details { - margin-top: 4px; - } - - .hostile { - color: #ff4444; - } - .distrustful { - color: #ff8888; - } - .neutral { - color: #ffffff; - } - .friendly { - color: #4CAF50; - } - - @media (max-width: 768px) { - .container { - top: 5px; - right: 5px; - } - - .player-info { - padding: 6px 10px; - font-size: 12px; - min-width: 100px; - } - - .control-button { - font-size: 16px; - padding: 3px 6px; - } - - .pause-button { - font-size: 14px; - padding: 3px 8px; - } - - .type-label { - font-size: 12px; - } - } - `; + createRenderRoot() { + return this; // Disable shadow DOM to allow Tailwind styles + } } \ No newline at end of file