mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-16 22:10:26 +00:00
## Description: - **Dynamic sidebar offset for top bars** - GameLeftSidebar, GameRightSidebar, and PlayerInfoOverlay now shift down when SpawnTimer and/or ImmunityTimer bars are visible (7px per bar). Implemented via events. - **Fixed text overflow** in HeadsUpMessage.ts (Random spawn message is long) - **Fixed inconsistent text sizing** in EventsDisplay - **Alliance icon horizontal** in PlayerInfoOverlay so the size of the overlay doesn't change if there is an alliance - **Nation relation coloring** - Nation player names are now colored based on their relation - **Background & Blur Unification** - **Border Radius & Page Edge Gap Standardization** - **EventsDisplay collapsed button:** Fixed badge hidden / inline-block CSS conflict (conditional rendering), added gap-2 between text and badge - **Right panel spacing:** Changed right container from sm:w-1/2 to sm:flex-1 to fill remaining space - **Leaderboard**: Rounded grid corners (rounded-lg overflow-hidden), removed last-row border, added `willUpdate` for auto-refresh on hide/show click, plus button styled to match toggle buttons - Other little CSS fixes (margins etc) Showcase: (Note the red mexico name on betrayal) https://github.com/user-attachments/assets/f0ed91de-3a07-4564-a209-3d7723edee55 Two progress bars at the top, mobile UI not cut off: https://github.com/user-attachments/assets/83f1fd64-ceab-4a74-8d16-6e1eeea1709d HeadsUpMessage text overflow fixed, SpawnTimer does not cut off the PlayerInfoOverlay: <img width="516" height="929" alt="Screenshot 2026-02-14 214410" src="https://github.com/user-attachments/assets/74f0edea-8c01-4394-a3d0-a3245922e0da" /> Previous: <img width="306" height="118" alt="Screenshot 2026-02-14 213705" src="https://github.com/user-attachments/assets/a7c7e8f3-f0e8-4213-8a8f-4f3677e9fc98" /> Smaller event panel text: <img width="594" height="975" alt="Screenshot 2026-02-14 215738" src="https://github.com/user-attachments/assets/33e80570-9260-40b0-b810-c71eda4861fc" /> ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: FloPinguin
233 lines
6.6 KiB
TypeScript
233 lines
6.6 KiB
TypeScript
import { html, LitElement } from "lit";
|
|
import { customElement, state } from "lit/decorators.js";
|
|
import { EventBus } from "../../../core/EventBus";
|
|
import { GameType } from "../../../core/game/Game";
|
|
import { GameView } from "../../../core/game/GameView";
|
|
import { crazyGamesSDK } from "../../CrazyGamesSDK";
|
|
import { PauseGameIntentEvent, SendWinnerEvent } from "../../Transport";
|
|
import { translateText } from "../../Utils";
|
|
import { ImmunityBarVisibleEvent } from "./ImmunityTimer";
|
|
import { Layer } from "./Layer";
|
|
import { ShowReplayPanelEvent } from "./ReplayPanel";
|
|
import { ShowSettingsModalEvent } from "./SettingsModal";
|
|
import { SpawnBarVisibleEvent } from "./SpawnTimer";
|
|
import exitIcon from "/images/ExitIconWhite.svg?url";
|
|
import FastForwardIconSolid from "/images/FastForwardIconSolidWhite.svg?url";
|
|
import pauseIcon from "/images/PauseIconWhite.svg?url";
|
|
import playIcon from "/images/PlayIconWhite.svg?url";
|
|
import settingsIcon from "/images/SettingIconWhite.svg?url";
|
|
|
|
@customElement("game-right-sidebar")
|
|
export class GameRightSidebar extends LitElement implements Layer {
|
|
public game: GameView;
|
|
public eventBus: EventBus;
|
|
|
|
@state()
|
|
private _isSinglePlayer: boolean = false;
|
|
|
|
@state()
|
|
private _isReplayVisible: boolean = false;
|
|
|
|
@state()
|
|
private _isVisible: boolean = true;
|
|
|
|
@state()
|
|
private isPaused: boolean = false;
|
|
|
|
@state()
|
|
private timer: number = 0;
|
|
|
|
private hasWinner = false;
|
|
private isLobbyCreator = false;
|
|
private spawnBarVisible = false;
|
|
private immunityBarVisible = false;
|
|
|
|
createRenderRoot() {
|
|
return this;
|
|
}
|
|
|
|
init() {
|
|
this._isSinglePlayer =
|
|
this.game?.config()?.gameConfig()?.gameType === GameType.Singleplayer ||
|
|
this.game.config().isReplay();
|
|
this._isVisible = true;
|
|
this.game.inSpawnPhase();
|
|
|
|
this.eventBus.on(SpawnBarVisibleEvent, (e) => {
|
|
this.spawnBarVisible = e.visible;
|
|
this.updateParentOffset();
|
|
});
|
|
this.eventBus.on(ImmunityBarVisibleEvent, (e) => {
|
|
this.immunityBarVisible = e.visible;
|
|
this.updateParentOffset();
|
|
});
|
|
|
|
this.eventBus.on(SendWinnerEvent, () => {
|
|
this.hasWinner = true;
|
|
this.requestUpdate();
|
|
});
|
|
|
|
this.requestUpdate();
|
|
}
|
|
|
|
getTickIntervalMs() {
|
|
return 250;
|
|
}
|
|
|
|
tick() {
|
|
// Timer logic
|
|
// Check if the player is the lobby creator
|
|
if (!this.isLobbyCreator && this.game.myPlayer()?.isLobbyCreator()) {
|
|
this.isLobbyCreator = true;
|
|
this.requestUpdate();
|
|
}
|
|
|
|
const maxTimerValue = this.game.config().gameConfig().maxTimerValue;
|
|
const spawnPhaseTurns = this.game.config().numSpawnPhaseTurns();
|
|
const ticks = this.game.ticks();
|
|
const gameTicks = Math.max(0, ticks - spawnPhaseTurns);
|
|
const elapsedSeconds = Math.floor(gameTicks / 10); // 10 ticks per second
|
|
|
|
if (this.game.inSpawnPhase()) {
|
|
this.timer = maxTimerValue !== undefined ? maxTimerValue * 60 : 0;
|
|
return;
|
|
}
|
|
|
|
if (this.hasWinner) {
|
|
return;
|
|
}
|
|
|
|
if (maxTimerValue !== undefined) {
|
|
this.timer = Math.max(0, maxTimerValue * 60 - elapsedSeconds);
|
|
} else {
|
|
this.timer = elapsedSeconds;
|
|
}
|
|
}
|
|
|
|
private updateParentOffset(): void {
|
|
const offset =
|
|
(this.spawnBarVisible ? 7 : 0) + (this.immunityBarVisible ? 7 : 0);
|
|
const parent = this.parentElement as HTMLElement;
|
|
if (parent) {
|
|
parent.style.marginTop = `${offset}px`;
|
|
}
|
|
}
|
|
|
|
private secondsToHms = (d: number): string => {
|
|
const pad = (n: number) => (n < 10 ? `0${n}` : n);
|
|
|
|
const h = Math.floor(d / 3600);
|
|
const m = Math.floor((d % 3600) / 60);
|
|
const s = Math.floor((d % 3600) % 60);
|
|
|
|
if (h !== 0) {
|
|
return `${pad(h)}:${pad(m)}:${pad(s)}`;
|
|
} else {
|
|
return `${pad(m)}:${pad(s)}`;
|
|
}
|
|
};
|
|
|
|
private toggleReplayPanel(): void {
|
|
this._isReplayVisible = !this._isReplayVisible;
|
|
this.eventBus.emit(
|
|
new ShowReplayPanelEvent(this._isReplayVisible, this._isSinglePlayer),
|
|
);
|
|
}
|
|
|
|
private onPauseButtonClick() {
|
|
this.isPaused = !this.isPaused;
|
|
if (this.isPaused) {
|
|
crazyGamesSDK.gameplayStop();
|
|
} else {
|
|
crazyGamesSDK.gameplayStart();
|
|
}
|
|
this.eventBus.emit(new PauseGameIntentEvent(this.isPaused));
|
|
}
|
|
|
|
private async onExitButtonClick() {
|
|
const isAlive = this.game.myPlayer()?.isAlive();
|
|
if (isAlive) {
|
|
const isConfirmed = confirm(
|
|
translateText("help_modal.exit_confirmation"),
|
|
);
|
|
if (!isConfirmed) return;
|
|
}
|
|
await crazyGamesSDK.requestMidgameAd();
|
|
await crazyGamesSDK.gameplayStop();
|
|
// redirect to the home page
|
|
window.location.href = "/";
|
|
}
|
|
|
|
private onSettingsButtonClick() {
|
|
this.eventBus.emit(
|
|
new ShowSettingsModalEvent(true, this._isSinglePlayer, this.isPaused),
|
|
);
|
|
}
|
|
|
|
render() {
|
|
if (this.game === undefined) return html``;
|
|
|
|
const timerColor =
|
|
this.game.config().gameConfig().maxTimerValue !== undefined &&
|
|
this.timer < 60
|
|
? "text-red-400"
|
|
: "";
|
|
|
|
return html`
|
|
<aside
|
|
class=${`w-fit flex flex-row items-center gap-3 py-2 px-3 bg-gray-800/70 backdrop-blur-xs shadow-xs min-[1200px]:rounded-lg rounded-bl-lg transition-transform duration-300 ease-out transform text-white ${
|
|
this._isVisible ? "translate-x-0" : "translate-x-full"
|
|
}`}
|
|
@contextmenu=${(e: Event) => e.preventDefault()}
|
|
>
|
|
<!-- In-game time -->
|
|
<div class=${timerColor}>${this.secondsToHms(this.timer)}</div>
|
|
|
|
<!-- Buttons -->
|
|
${this.maybeRenderReplayButtons()}
|
|
|
|
<div class="cursor-pointer" @click=${this.onSettingsButtonClick}>
|
|
<img src=${settingsIcon} alt="settings" width="20" height="20" />
|
|
</div>
|
|
|
|
<div class="cursor-pointer" @click=${this.onExitButtonClick}>
|
|
<img src=${exitIcon} alt="exit" width="20" height="20" />
|
|
</div>
|
|
</aside>
|
|
`;
|
|
}
|
|
|
|
maybeRenderReplayButtons() {
|
|
const isReplayOrSingleplayer =
|
|
this._isSinglePlayer || this.game?.config()?.isReplay();
|
|
const showPauseButton = isReplayOrSingleplayer || this.isLobbyCreator;
|
|
|
|
return html`
|
|
${isReplayOrSingleplayer
|
|
? html`
|
|
<div class="cursor-pointer" @click=${this.toggleReplayPanel}>
|
|
<img
|
|
src=${FastForwardIconSolid}
|
|
alt="replay"
|
|
width="20"
|
|
height="20"
|
|
/>
|
|
</div>
|
|
`
|
|
: ""}
|
|
${showPauseButton
|
|
? html`
|
|
<div class="cursor-pointer" @click=${this.onPauseButtonClick}>
|
|
<img
|
|
src=${this.isPaused ? playIcon : pauseIcon}
|
|
alt="play/pause"
|
|
width="20"
|
|
height="20"
|
|
/>
|
|
</div>
|
|
`
|
|
: ""}
|
|
`;
|
|
}
|
|
}
|