Skip to content

Feat: Add troop count bar to PlayerInfoOverlay - #2773

Merged
evanpelle merged 2 commits into
mainfrom
bijx/troop-count-bar
Jan 3, 2026
Merged

evanpelle merged 2 commits into
mainfrom
bijx/troop-count-bar

Conversation

@bijx

@bijx bijx commented Jan 2, 2026 •

Copy link
Copy Markdown
Contributor

Description:

This feature adds a troop count bar into the PlayerInfoOverlay that visualizes how many troops a player/nation has, how big of an attack they are sending, and in general the percentages of their overall troop count. I originally added the toggling of this feature as a setting but thought it might be too narrow to need it's own setting. Would appreciate anyone's thoughts on adding it back in or not.

Inspired by this comment in the Dev Discord.

Video Demo

Screen.Recording.2026-01-02.182901.mp4

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:

bijx

@bijx
bijx requested a review from a team as a code owner January 2, 2026 23:41
@coderabbitai

coderabbitai Bot commented Jan 2, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request adds a new troop-bar visualization to the PlayerInfoOverlay component. It introduces a private method that computes and renders a two-color bar showing total troops and attacking troops relative to a maximum capacity, integrated into the existing player information display.

Changes

Cohort / File(s) Summary
Troop Bar Visualization
src/client/graphics/layers/PlayerInfoOverlay.ts
Added new private method renderTroopBar() that calculates green and orange bar widths based on totalTroops and attackingTroops, clamped to [0,100]. Updated renderPlayerInfo() to compute totalTroops via player.troops() and invoke the new render method within the details section.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Redesign Player info overlay #2000: Modifies the same PlayerInfoOverlay file to change troop count and attacker-troop rendering with new UI elements and layout adjustments.

Suggested labels

UI/UX

Suggested reviewers

  • evanpelle

Poem

🎖️ A bar of green and orange bright,
Shows troops in battle, troops in might,
The overlay gains visual grace,
With percentages filling their space! ⚔️

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a troop count bar feature to the PlayerInfoOverlay component, which matches the actual changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining the feature's purpose, design decisions, and including a demo link. It provides meaningful context about the troop count bar visualization.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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: 1

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

458-477: Consider adding tooltips for clarity.

The bar has no visual legend explaining that green represents total troops and orange represents attacking troops. Consider adding a title attribute or tooltip on hover to clarify what users are seeing.

Possible enhancement with tooltips
 return html`
   <div
     class="w-full mt-2 mb-2 h-5 border border-gray-600 rounded-md bg-gray-900/60 overflow-hidden"
+    title="${translateText('player_info_overlay.troop_bar_tooltip')}"
   >

You'd also need to add the translation key to en.json:

"player_info_overlay.troop_bar_tooltip": "Green: troops available, Orange: troops attacking"

458-477: Consider accessibility for screen readers.

The troop bar is purely visual with no text alternative. Consider adding an aria-label to describe what the bar represents for screen reader users.

Possible accessibility enhancement
 return html`
   <div
     class="w-full mt-2 mb-2 h-5 border border-gray-600 rounded-md bg-gray-900/60 overflow-hidden"
+    role="progressbar"
+    aria-label="${translateText('player_info_overlay.troop_capacity')}: ${greenPercent.toFixed(0)}%"
+    aria-valuenow="${greenPercent}"
+    aria-valuemin="0"
+    aria-valuemax="100"
   >
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1eee8b4 and a1ae47e.

📒 Files selected for processing (1)
  • src/client/graphics/layers/PlayerInfoOverlay.ts
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: Foorack
Repo: openfrontio/OpenFrontIO PR: 2141
File: src/client/ClientGameRunner.ts:228-234
Timestamp: 2025-10-08T17:14:49.369Z
Learning: For the window close confirmation feature in `ClientGameRunner.ts`, the troop count requirement (>10,000 troops) from issue #2137 was intentionally removed because it was arbitrary and troop count can be reported as low despite having significant land. The confirmation now triggers for any alive player regardless of troop count.
Learnt from: 1brucben
Repo: openfrontio/OpenFrontIO PR: 977
File: src/core/execution/AttackExecution.ts:123-125
Timestamp: 2025-05-31T18:15:03.445Z
Learning: The removeTroops function in PlayerImpl.ts already prevents negative troop counts by using minInt(this._troops, toInt(troops)) to ensure it never removes more troops than available.
📚 Learning: 2025-05-31T18:15:03.445Z
Learnt from: 1brucben
Repo: openfrontio/OpenFrontIO PR: 977
File: src/core/execution/AttackExecution.ts:123-125
Timestamp: 2025-05-31T18:15:03.445Z
Learning: The removeTroops function in PlayerImpl.ts already prevents negative troop counts by using minInt(this._troops, toInt(troops)) to ensure it never removes more troops than available.

Applied to files:

  • src/client/graphics/layers/PlayerInfoOverlay.ts
📚 Learning: 2025-10-08T17:14:49.369Z
Learnt from: Foorack
Repo: openfrontio/OpenFrontIO PR: 2141
File: src/client/ClientGameRunner.ts:228-234
Timestamp: 2025-10-08T17:14:49.369Z
Learning: For the window close confirmation feature in `ClientGameRunner.ts`, the troop count requirement (>10,000 troops) from issue #2137 was intentionally removed because it was arbitrary and troop count can be reported as low despite having significant land. The confirmation now triggers for any alive player regardless of troop count.

Applied to files:

  • src/client/graphics/layers/PlayerInfoOverlay.ts
📚 Learning: 2025-08-12T00:31:50.144Z
Learnt from: scottanderson
Repo: openfrontio/OpenFrontIO PR: 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 (1)
src/client/graphics/layers/PlayerInfoOverlay.ts (3)
src/core/game/GameImpl.ts (1)
  • player (483-489)
src/core/game/GameView.ts (1)
  • player (732-738)
src/core/configuration/DefaultConfig.ts (1)
  • maxTroops (805-836)
🔇 Additional comments (2)
src/client/graphics/layers/PlayerInfoOverlay.ts (2)

262-262: Clean variable extraction.

Extracting totalTroops here makes line 382 more readable.


382-382: Good placement for the troop bar.

Rendering the bar between troop stats and resources makes sense.

@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 v29 milestone Jan 3, 2026
@evanpelle
evanpelle merged commit cdecdc5 into main Jan 3, 2026
11 of 12 checks passed
@evanpelle
evanpelle deleted the bijx/troop-count-bar branch January 3, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants