mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-26 12:14:36 +00:00
0466eeac13
## Description: The game info panel was missing the gold generated with trains, which was recently added into the recorded stats. This PR adds the gold train ranking, grouped with the naval trade. Visually the game info panel is not matching the new visual identity, but this PR only focuses on the missing data. <img width="898" height="482" alt="image" src="https://github.com/user-attachments/assets/6366e5d2-23b6-40b0-b4d4-1227b5a2f811" /> ## 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: IngloriousTom
136 lines
3.7 KiB
TypeScript
136 lines
3.7 KiB
TypeScript
import { LitElement, html } from "lit";
|
|
import { customElement, property } from "lit/decorators.js";
|
|
import { translateText } from "../../../Utils";
|
|
import { RankType } from "./GameInfoRanking";
|
|
|
|
const economyRankings = new Set([
|
|
RankType.TotalGold,
|
|
RankType.StolenGold,
|
|
RankType.ConqueredGold,
|
|
RankType.NavalTrade,
|
|
RankType.TrainTrade,
|
|
]);
|
|
const tradeRankings = new Set([RankType.NavalTrade, RankType.TrainTrade]);
|
|
const bombRankings = new Set([RankType.Atoms, RankType.Hydros, RankType.MIRV]);
|
|
const warRankings = new Set([
|
|
RankType.Conquests,
|
|
RankType.Atoms,
|
|
RankType.Hydros,
|
|
RankType.MIRV,
|
|
]);
|
|
|
|
const isEconomyRanking = (t: RankType) => economyRankings.has(t);
|
|
const isTradeRanking = (t: RankType) => tradeRankings.has(t);
|
|
const isBombRanking = (t: RankType) => bombRankings.has(t);
|
|
const isWarRanking = (t: RankType) => warRankings.has(t);
|
|
|
|
@customElement("ranking-controls")
|
|
export class RankingControls extends LitElement {
|
|
@property({ type: String }) rankType = RankType.Lifetime;
|
|
|
|
private onSort(type: RankType) {
|
|
this.dispatchEvent(new CustomEvent("sort", { detail: type }));
|
|
}
|
|
|
|
private renderMainButtons() {
|
|
return html`
|
|
<div class="flex items-end justify-center p-6 pb-2 gap-5">
|
|
${this.renderButton(
|
|
RankType.Lifetime,
|
|
this.rankType === RankType.Lifetime,
|
|
"game_info_modal.duration",
|
|
)}
|
|
${this.renderButton(
|
|
RankType.Conquests,
|
|
isWarRanking(this.rankType),
|
|
"game_info_modal.war",
|
|
)}
|
|
${this.renderButton(
|
|
RankType.TotalGold,
|
|
isEconomyRanking(this.rankType),
|
|
"game_info_modal.economy",
|
|
)}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
private renderButton(type: RankType, active: boolean, label: string) {
|
|
return html`
|
|
<button
|
|
class="rounded-lg bg-blue-600 text-white text-lg p-3 hover:bg-blue-400 ${active
|
|
? "active outline-2 outline-white font-bold"
|
|
: ""}"
|
|
@click=${() => this.onSort(type)}
|
|
>
|
|
${translateText(label)}
|
|
</button>
|
|
`;
|
|
}
|
|
|
|
private renderWarSubranking() {
|
|
if (!isWarRanking(this.rankType)) return "";
|
|
|
|
return html`
|
|
<div class="flex justify-center gap-3 pb-1">
|
|
${this.renderSubButton(
|
|
RankType.MIRV,
|
|
isBombRanking(this.rankType),
|
|
"game_info_modal.bombs",
|
|
)}
|
|
${this.renderSubButton(
|
|
RankType.Conquests,
|
|
this.rankType === RankType.Conquests,
|
|
"game_info_modal.conquests",
|
|
)}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
private renderEconomySubranking() {
|
|
if (!isEconomyRanking(this.rankType)) return "";
|
|
|
|
const econButtons = [
|
|
[RankType.StolenGold, "game_info_modal.pirate"],
|
|
[RankType.ConqueredGold, "game_info_modal.conquered"],
|
|
[RankType.TotalGold, "game_info_modal.total_gold"],
|
|
];
|
|
|
|
return html`
|
|
<div class="flex justify-center gap-3 pb-1">
|
|
${this.renderSubButton(
|
|
RankType.NavalTrade,
|
|
isTradeRanking(this.rankType),
|
|
"game_info_modal.trade",
|
|
)}
|
|
${econButtons.map(([type, label]) =>
|
|
this.renderSubButton(type as RankType, this.rankType === type, label),
|
|
)}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
private renderSubButton(type: RankType, active: boolean, label: string) {
|
|
return html`
|
|
<button
|
|
@click=${() => this.onSort(type)}
|
|
class="rounded-md bg-blue-50 text-black text-sm p-2 hover:bg-blue-200 ${active
|
|
? "outline-2 outline-white font-bold"
|
|
: ""}"
|
|
>
|
|
${translateText(label)}
|
|
</button>
|
|
`;
|
|
}
|
|
|
|
render() {
|
|
return html`
|
|
${this.renderMainButtons()} ${this.renderWarSubranking()}
|
|
${this.renderEconomySubranking()}
|
|
`;
|
|
}
|
|
|
|
createRenderRoot() {
|
|
return this;
|
|
}
|
|
}
|