Skip to content

Redesign Player info overlay - #2000

Merged
evanpelle merged 8 commits into
openfrontio:mainfrom
DevelopingTom:build_fx
Sep 8, 2025
Merged

evanpelle merged 8 commits into
openfrontio:mainfrom
DevelopingTom:build_fx

Conversation

@DevelopingTom

@DevelopingTom DevelopingTom commented Sep 3, 2025 •

Copy link
Copy Markdown
Contributor

Description:

Redesign the player info panel to match the bottom panel.

Changes:

  • Added alliance timeout
  • Various css restyling

Old:
image

New:
image

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • 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

@DevelopingTom DevelopingTom self-assigned this Sep 3, 2025
@DevelopingTom
DevelopingTom requested review from a team as code owners September 3, 2025 21:34
@DevelopingTom DevelopingTom added the UI/UX UI/UX changes including assets, menus, QoL, etc. label Sep 3, 2025
@coderabbitai

coderabbitai Bot commented Sep 3, 2025 •

Copy link
Copy Markdown
Contributor

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a shared renderDuration utility, updates PlayerInfoOverlay to show alliance expiration and unit icons, replaces PlayerPanel's private formatter with renderDuration, and updates English localization keys (removed d_troops, added troops and alliance_timeout). No public API removals.

Changes

Cohort / File(s) Summary of changes
Localization: player_info_overlay keys
resources/lang/en.json
Removed d_troops; added troops and alliance_timeout; reordered troop-related keys inside player_info_overlay.
Utilities: duration formatting
src/client/Utils.ts
Added export function renderDuration(totalSeconds: number): string to format seconds into compact strings like "Xm Ys"/"Ys" (returns "0s" for non-positive).
Player UI: overlay & icons
src/client/graphics/layers/PlayerInfoOverlay.ts
Added alliance-aware rendering and alliance expiration display using renderDuration; introduced unit icons and consolidated unit counts via displayUnitCount(icon, ...); layout and class adjustments; new icon imports and AllianceView usage.
Player UI: panel
src/client/graphics/layers/PlayerPanel.ts
Replaced internal duration formatter with import of renderDuration; removed private formatDuration helper; unchanged external behavior.
Public lobby time display
src/client/PublicLobby.ts
Switched manual minutes/seconds formatting to use renderDuration.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant O as PlayerInfoOverlay
  participant P as PlayerPanel
  participant S as GameState/Ticks
  participant R as Utils.renderDuration

  U->>O: open player info
  O->>S: read player, myPlayer, alliance.expiresAt
  alt allied
    O->>S: compute remainingSeconds
    O->>R: renderDuration(remainingSeconds)
    R-->>O: "Xm Ys" / "Ys"
    Note right of O #DFF2E1: render AllianceIcon + "Alliance ends in …"
  else not allied
    Note right of O #FFF3D6: render relation badge (Neutral/Hostile)
  end
  Note over O: render unit row (icons + counts)

  U->>P: open player panel
  P->>S: compute remainingSeconds (if any)
  alt has expiry
    P->>R: renderDuration(remainingSeconds)
    R-->>P: "Xm Ys"
    P->>U: show expiry text
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

Feature - Frontend, Translation

Suggested reviewers

  • evanpelle

Poem

Icons align, small timers sing,
Allies counted, seconds bring.
Troops in rows, a tidy view,
A tiny util tells time true.
UI hums—compact and new. ✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/client/graphics/layers/PlayerPanel.ts (1)

197-203: Fix stale alliance timer when it hits zero

When remainingTicks <= 0 you never update allianceExpiryText, leaving an old value on screen. Set it to "0s" (or null) to avoid stale UI.

-      if (remainingTicks > 0) {
-        const remainingSeconds = Math.max(
-          0,
-          Math.floor(remainingTicks / 10),
-        ); // 10 ticks per second
-        this.allianceExpiryText = renderDuration(remainingSeconds);
-      }
+      if (remainingTicks > 0) {
+        const remainingSeconds = Math.floor(remainingTicks / 10); // 10 ticks/s
+        this.allianceExpiryText = renderDuration(remainingSeconds);
+      } else {
+        this.allianceExpiryText = renderDuration(0); // "0s"
+      }
🧹 Nitpick comments (8)
src/client/Utils.ts (1)

5-13: Polish duration formatting (pad seconds; optional hours)

Readability nit: when minutes exist, pad seconds to 2 digits (e.g., 1m 05s). If alliances can last >59m, consider hours too. Safe-guard NaN input.

Apply:

 export function renderDuration(totalSeconds: number): string {
-  if (totalSeconds <= 0) return "0s";
-  const minutes = Math.floor(totalSeconds / 60);
-  const seconds = totalSeconds % 60;
-  let time = "";
-  if (minutes > 0) time += `${minutes}m `;
-  time += `${seconds}s`;
-  return time.trim();
+  if (!Number.isFinite(totalSeconds) || totalSeconds <= 0) return "0s";
+  const minutes = Math.floor(totalSeconds / 60);
+  const seconds = Math.floor(totalSeconds % 60);
+  const sec = minutes > 0 ? String(seconds).padStart(2, "0") : String(seconds);
+  return (minutes > 0 ? `${minutes}m ${sec}s` : `${sec}s`).trim();
 }
src/client/graphics/layers/PlayerPanel.ts (1)

15-15: Unify Utils imports to avoid duplicate module paths

Import translateText from the same Utils path to keep module identity stable and consistent.

-import { renderDuration, renderNumber, renderTroops } from "../../Utils";
+import { renderDuration, renderNumber, renderTroops, translateText } from "../../Utils";
@@
-import { translateText } from "../../../client/Utils";

Also applies to: 31-31

resources/lang/en.json (1)

486-488: Wording consistency: align alliance timeout labels

Player panel uses "Alliance Expires In" while overlay uses "Alliance ends in". Pick one phrase for both for a cleaner UX (suggest: “Alliance expires in”).

src/client/graphics/layers/PlayerInfoOverlay.ts (5)

12-12: Consolidate Utils imports (avoid duplicate paths)

Import translateText from the same Utils path as other helpers.

-import { renderDuration, renderNumber, renderTroops } from "../../Utils";
+import { renderDuration, renderNumber, renderTroops, translateText } from "../../Utils";
@@
-import { translateText } from "../../../client/Utils";

Also applies to: 28-28


204-217: De-duplicate tick-to-seconds magic number

10 is repeated across files. Consider a shared constant (e.g., TICKS_PER_SECOND = 10) in a small constants module and reuse it here and in PlayerPanel.


240-255: Improve accessibility for alliance timeout

Only an icon + numbers are shown; alt on the img may not be announced in all contexts. Add an sr-only label next to the timer.

-            <span class="flex gap-2 ml-auto mr-0 text-sm font-bold">
+            <span class="flex gap-2 ml-auto mr-0 text-sm font-bold">
               <img
                 src=${allianceIcon}
                 alt=${translateText("player_info_overlay.alliance_timeout")}
                 width="20"
                 height="20"
                 style="vertical-align: middle;"
               />
-              ${this.allianceExpirationText(alliance)}
+              <span class="sr-only">${translateText("player_info_overlay.alliance_timeout")}:</span>
+              ${this.allianceExpirationText(alliance)}
             </span>

222-223: Avoid boolean | undefined for isAllied

Coerce to boolean to simplify conditions.

-    const isAllied = myPlayer?.isAlliedWith(player);
+    const isAllied = !!(myPlayer && myPlayer.isAlliedWith(player));

272-272: Remove non-existent Tailwind class

"text-bold" isn’t a Tailwind class; "font-bold" already present.

-          class="items-center text-bold text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly
+          class="items-center text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1ae7ebc and e469b3b.

📒 Files selected for processing (4)
  • resources/lang/en.json (1 hunks)
  • src/client/Utils.ts (1 hunks)
  • src/client/graphics/layers/PlayerInfoOverlay.ts (4 hunks)
  • src/client/graphics/layers/PlayerPanel.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-12T00:31:50.144Z
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#1752
File: src/core/game/Game.ts:750-752
Timestamp: 2025-08-12T00:31:50.144Z
Learning: In the OpenFrontIO codebase, changes to the PlayerInteraction interface (like adding canDonateGold and canDonateTroops flags) do not require corresponding updates to src/core/Schemas.ts or server serialization code.

Applied to files:

  • src/client/graphics/layers/PlayerInfoOverlay.ts
🧬 Code graph analysis (2)
src/client/graphics/layers/PlayerPanel.ts (1)
src/client/Utils.ts (1)
  • renderDuration (5-13)
src/client/graphics/layers/PlayerInfoOverlay.ts (3)
src/core/game/GameView.ts (5)
  • type (93-95)
  • type (269-271)
  • player (514-520)
  • PlayerView (180-362)
  • isFriendly (313-315)
src/client/Utils.ts (3)
  • renderDuration (5-13)
  • renderNumber (19-43)
  • renderTroops (15-17)
src/core/game/GameUpdates.ts (1)
  • AllianceView (173-178)

Comment thread resources/lang/en.json Resolved
@github-project-automation github-project-automation Bot moved this from Triage to Development in OpenFront Release Management Sep 3, 2025
coderabbitai[bot]
coderabbitai Bot previously approved these changes Sep 3, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
src/client/graphics/layers/PlayerInfoOverlay.ts (1)

192-193: Class name typo from prior review is fixed — good catch

"text-sm opacity-80" is now correctly spaced; opacity applies as expected.

🧹 Nitpick comments (5)
src/client/graphics/layers/PlayerInfoOverlay.ts (5)

204-217: Don't hardcode 10 ticks/sec for alliance expiry

The 10 tps assumption can drift from server config and mislead users. Read tick rate from config (or a single source of truth) and fall back if missing. Please confirm the actual tick rate used by the game.

   private allianceExpirationText(
     alliance: AllianceView,
   ) {
     const { expiresAt } = alliance;
     const remainingTicks = expiresAt - this.game.ticks();
     let remainingSeconds = 0;
     if (remainingTicks > 0) {
-      remainingSeconds = Math.max(
-        0,
-        Math.floor(remainingTicks / 10),
-      ); // 10 ticks per second
+      const tps =
+        // Prefer config (or another central source of truth)
+        (this.game.config?.().ticksPerSecond as number | undefined) ?? 10;
+      remainingSeconds = Math.max(0, Math.floor(remainingTicks / tps));
     }
     return renderDuration(remainingSeconds);
   }

If ticksPerSecond isn’t available yet, consider adding a small helper in Utils: ticksToSeconds(ticks, tps).


272-275: Remove non-existent Tailwind class “text-bold”

Tailwind uses font-bold. text-bold is a no-op and adds noise.

-          class="items-center text-bold text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly
+          class="items-center text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly

276-278: Call requestUpdate directly

requestUpdate always exists on Lit elements; optional chaining is unnecessary here.

-            this.requestUpdate?.();
+            this.requestUpdate();

423-425: Drop duplicate/invalid shadow utility

shadow-xs isn’t a standard Tailwind class (unless custom). You already have shadow-lg; keep one to avoid conflicting styles.

-          class="bg-gray-800/70 backdrop-blur-sm shadow-xs rounded-lg shadow-lg
+          class="bg-gray-800/70 backdrop-blur-sm rounded-lg shadow-lg

271-279: Add minimal a11y: expose expansion state and live updates

  • Expose the details toggle state with aria-expanded on the button.
  • Mark the info container as complementary and live-updating for screen readers.
         <button
-          class="items-center text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly
+          class="items-center text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly
             ? "text-green-500"
             : "text-white"}"
+          aria-expanded=${String(this.showDetails)}
           @click=${() => {
             this.showDetails = !this.showDetails;
             this.requestUpdate();
           }}
         >
-        <div
-          class="bg-gray-800/70 backdrop-blur-sm rounded-lg shadow-lg
+        <div
+          role="complementary" aria-live="polite" aria-atomic="true"
+          class="bg-gray-800/70 backdrop-blur-sm rounded-lg shadow-lg
           transition-all duration-300  text-white text-lg md:text-base
           ${containerClasses}"
         >

Also applies to: 422-426

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e469b3b and 1d82dc0.

📒 Files selected for processing (1)
  • src/client/graphics/layers/PlayerInfoOverlay.ts (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/client/graphics/layers/PlayerInfoOverlay.ts (3)
src/core/game/GameView.ts (6)
  • type (93-95)
  • type (269-271)
  • player (514-520)
  • PlayerView (180-362)
  • myPlayer (509-512)
  • isFriendly (313-315)
src/client/Utils.ts (3)
  • renderDuration (5-13)
  • renderNumber (19-43)
  • renderTroops (15-17)
src/core/game/GameUpdates.ts (1)
  • AllianceView (173-178)

Comment thread src/client/Utils.ts Resolved
@evanpelle
evanpelle requested a review from a team as a code owner September 4, 2025 02:44
@evanpelle
evanpelle changed the base branch from main to main-old September 4, 2025 02:51
@evanpelle

Copy link
Copy Markdown
Collaborator

mind rebasing onto main, thanks

@Breush

Breush commented Sep 4, 2025

Copy link
Copy Markdown

Loving this PR.
No feedback on the code, some tweaks on your original proposal:

suggestion

@evanpelle
evanpelle changed the base branch from main-old to main September 4, 2025 18:38
evanpelle
evanpelle previously approved these changes Sep 5, 2025

@evanpelle evanpelle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@evanpelle evanpelle added this to the v26 milestone Sep 5, 2025
@CLAassistant

CLAassistant commented Sep 5, 2025 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@evanpelle
evanpelle enabled auto-merge September 5, 2025 18:31
@evanpelle

Copy link
Copy Markdown
Collaborator

Whoops, looks like I broke this when i moved assets around: 9d5c108

coderabbitai[bot]
coderabbitai Bot previously approved these changes Sep 5, 2025
@github-project-automation github-project-automation Bot moved this from Development to Final Review in OpenFront Release Management Sep 5, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (7)
src/client/PublicLobby.ts (2)

3-3: Normalize Utils import path

Use a direct, local path for clarity and to avoid brittle ups/downs.

-import { renderDuration, translateText } from "../client/Utils";
+import { renderDuration, translateText } from "./Utils";

99-103: Return an empty template instead of undefined

Lit’s render should consistently return a TemplateResult.

-  if (!lobby?.gameConfig) {
-      return;
-  }
+  if (!lobby?.gameConfig) {
+    return html``;
+  }
src/client/graphics/layers/PlayerInfoOverlay.ts (5)

188-212: Show unit counts, not level sums

UI labels (“cities”, “ports”, etc.) read as counts. Use number of units instead of total levels.

-          <span class="w-full text-right p-1"
-            >${player.totalUnitLevels(type)}</span
-          >
+          <span class="w-full text-right p-1"
+            >${this.game
+                .units(type)
+                .filter((u) => u.owner() === player).length}</span
+          >

If level-sum is intended, rename the labels to “... levels”.


284-287: Remove invalid Tailwind class “text-bold”

Tailwind uses font-bold; text-bold is a no-op.

-  class="items-center text-bold text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly
+  class="items-center text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly

4-11: Assets verified; suggest barrel import or path alias

All eight icon files exist under resources/images. To simplify imports and avoid deep relative paths, consider:

  • Adding resources/images/index.ts to re-export all icons.
  • Defining a Vite/TSConfig path alias (e.g. @images/* → resources/images/*) for cleaner imports.

445-446: Remove or define non-standard Tailwind class shadow-xs
No matching shadow-xs entry was found in your Tailwind config, so this utility isn’t applied. Either extend theme.extend.boxShadow with an xs key in tailwind.config.js or remove all shadow-xs occurrences.


214-222: Use serverConfig().turnIntervalMs() instead of hard-coding 10 tps
Replace the hard-coded tick rate with the server’s turn interval:

- const remainingTicks = expiresAt - this.game.ticks();
- let remainingSeconds = 0;
- if (remainingTicks > 0) {
-   remainingSeconds = Math.max(0, Math.floor(remainingTicks / 10)); // 10 ticks per second
- }
+ const remainingTicks = expiresAt - this.game.ticks();
+ const msPerTick = this.game.config().serverConfig().turnIntervalMs();
+ const remainingSeconds =
+   remainingTicks > 0
+     ? Math.max(0, Math.floor((remainingTicks * msPerTick) / 1000))
+     : 0;

This ensures the displayed duration stays correct if the server’s tick interval changes.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a1e255e and f5d983b.

📒 Files selected for processing (3)
  • resources/lang/en.json (1 hunks)
  • src/client/PublicLobby.ts (2 hunks)
  • src/client/graphics/layers/PlayerInfoOverlay.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • resources/lang/en.json
🔇 Additional comments (4)
src/client/PublicLobby.ts (1)

106-108: Good: centralized duration formatting

Using renderDuration(timeRemaining) keeps time display consistent across the app.

src/client/graphics/layers/PlayerInfoOverlay.ts (3)

25-30: LGTM: utilities consolidated

Importing renderDuration, renderNumber, renderTroops, translateText from one place is clean and consistent.


249-266: Allied expiration UI: clear and readable

Alliance icon + formatted duration is concise and localized. Nice.


360-397: Units grid looks good

Two-column, wrapped layout with icons improves scanability. Alt text is localized. 👍

@evanpelle
evanpelle added this pull request to the merge queue Sep 8, 2025
Merged via the queue into openfrontio:main with commit 63a1473 Sep 8, 2025
@github-project-automation github-project-automation Bot moved this from Final Review to Complete in OpenFront Release Management Sep 8, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Sep 12, 2025
4 tasks done
@coderabbitai coderabbitai Bot mentioned this pull request Sep 23, 2025
4 tasks done
@coderabbitai coderabbitai Bot mentioned this pull request Oct 18, 2025
4 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Jan 9, 2026
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

UI/UX UI/UX changes including assets, menus, QoL, etc.

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

5 participants