Skip to content

Conversation

@evanpelle
Copy link
Collaborator

@evanpelle evanpelle commented Jun 21, 2025

Description:

Refactor & clean up the Radial menu.

  • Only show certain build menu items, depending on whether or not you clicked on your own territory
  • show items as greyed out instead of just the disabled icon
  • remove back button on hover trigger

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
  • I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors

Please put your Discord username so you can be contacted if a bug or regression is found:

evan

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 21, 2025

Warning

Rate limit exceeded

@evanpelle has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between a459213 and 1d59164.

📒 Files selected for processing (5)
  • src/client/graphics/GameRenderer.ts (0 hunks)
  • src/client/graphics/layers/MainRadialMenu.ts (5 hunks)
  • src/client/graphics/layers/MenuEventManager.ts (0 hunks)
  • src/client/graphics/layers/RadialMenu.ts (24 hunks)
  • src/client/graphics/layers/RadialMenuElements.ts (9 hunks)

Walkthrough

This update removes the MenuEventManager class and refactors how the radial menu is managed in the client. The MainRadialMenu now directly listens for context menu events, simplifies state management, and introduces a new approach for handling the center button and menu items using clearer TypeScript interfaces.

Changes

File(s) Change Summary
src/client/graphics/GameRenderer.ts Removes playerInfo from the initial MainRadialMenu constructor arguments; no other logic changed.
src/client/graphics/layers/MainRadialMenu.ts Removes MenuEventManager, handles context menu events directly, updates method signatures, adds closeMenu, simplifies menu logic.
src/client/graphics/layers/MenuEventManager.ts Deletes the entire MenuEventManager class and related types.
src/client/graphics/layers/RadialMenu.ts Refactors center button logic using a state enum and a new interface, removes redundant methods, updates menu item handling.
src/client/graphics/layers/RadialMenuElements.ts Removes tileOwner, introduces CenterButtonElement interface, updates menu item logic, and reorganizes menu items.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant EventBus
    participant MainRadialMenu
    participant RadialMenu

    User->>EventBus: Triggers ContextMenuEvent (right-click)
    EventBus->>MainRadialMenu: Emits ContextMenuEvent
    MainRadialMenu->>MainRadialMenu: Converts screen to world coords, validates
    MainRadialMenu->>MainRadialMenu: Fetches player actions for tile
    MainRadialMenu->>RadialMenu: Calls handlePlayerActions (with actions, screenX, screenY)
    RadialMenu->>User: Displays radial menu at cursor position
Loading

Possibly related PRs

Suggested labels

Feature - Revision

Poem

Radial rings now spin with ease,
No manager hides behind the trees.
Buttons at the center, state so clear,
Menus pop up right where you steer.
Simpler code, a tidy view—
The menu’s fresh, the logic 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

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

411-424: Simplify disabled logic for better readability

The nested conditions make the logic harder to follow. Consider extracting to named variables:

 disabled: (params: MenuElementParams): boolean => {
   const tileOwner = params.game.owner(params.tile);
   const isLand = params.game.isLand(params.tile);
-  if (!isLand) {
-    return true;
-  }
-  if (params.game.inSpawnPhase()) {
-    if (tileOwner.isPlayer()) {
-      return true;
-    }
-    return false;
-  }
-  return false;
+  const isNotLand = !isLand;
+  const isSpawnPhase = params.game.inSpawnPhase();
+  const isOwnedByPlayer = tileOwner.isPlayer();
+  
+  if (isNotLand) return true;
+  if (isSpawnPhase && isOwnedByPlayer) return true;
+  return false;
 },
src/client/graphics/layers/RadialMenu.ts (1)

296-297: Consider required params when menu is visible

The frequent null checks for params add complexity. Since the menu should not be visible without valid params, consider ensuring params is always set before showing the menu.

Consider adding a guard in showRadialMenu:

public showRadialMenu(x: number, y: number) {
  if (!this.params) {
    console.warn("Cannot show menu without params");
    return;
  }
  // ... rest of implementation
}

Also applies to: 370-371, 447-451

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b87f23a and 66fdcdd.

📒 Files selected for processing (5)
  • src/client/graphics/GameRenderer.ts (0 hunks)
  • src/client/graphics/layers/MainRadialMenu.ts (6 hunks)
  • src/client/graphics/layers/MenuEventManager.ts (0 hunks)
  • src/client/graphics/layers/RadialMenu.ts (24 hunks)
  • src/client/graphics/layers/RadialMenuElements.ts (5 hunks)
💤 Files with no reviewable changes (2)
  • src/client/graphics/GameRenderer.ts
  • src/client/graphics/layers/MenuEventManager.ts
🔇 Additional comments (9)
src/client/graphics/layers/RadialMenuElements.ts (4)

58-62: Good interface design

The CenterButtonElement interface follows a clean composition pattern with clear responsibilities.


236-280: Improved emoji menu UX

Good refactor: placing the "more" button first makes it more discoverable, and reducing initial emojis from 15 to 8 reduces visual clutter.


286-287: Correct disabled logic for spawn phase

The spawn phase check appropriately disables the info menu when players cannot interact.


29-41: Breaking change: Verify all usages of MenuElementParams

The removal of tileOwner property from MenuElementParams is a breaking change. Ensure all code that previously used params.tileOwner has been updated.

#!/bin/bash
# Description: Search for any remaining references to tileOwner in MenuElementParams

# Search for tileOwner references
rg -A 3 "tileOwner" --type ts
src/client/graphics/layers/MainRadialMenu.ts (2)

76-100: Clean event handling implementation

Good refactor: directly handling ContextMenuEvent simplifies the architecture and removes unnecessary abstraction.


188-204: Well-structured menu cleanup

The closeMenu method properly handles all related UI elements with appropriate visibility checks.

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

30-30: Clean state management refactor

Good use of typed union for CenterButtonState instead of multiple boolean flags. This makes state transitions clearer.

Also applies to: 47-48


840-887: Well-implemented center button state management

The unified state management with clear visual feedback improves code maintainability.


922-932: Good API design for menu configuration

The updated signature properly encapsulates both menu items and center button configuration.

Comment on lines +527 to +530
const disabled =
this.params === null ||
this.params.game.inSpawnPhase() ||
d.data.disabled(this.params);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove redundant spawn phase check

The spawn phase check here is redundant since individual menu elements already handle this in their disabled methods. This creates duplicate logic.

 const disabled =
   this.params === null ||
-  this.params.game.inSpawnPhase() ||
   d.data.disabled(this.params);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const disabled =
this.params === null ||
this.params.game.inSpawnPhase() ||
d.data.disabled(this.params);
const disabled =
this.params === null ||
d.data.disabled(this.params);
🤖 Prompt for AI Agents
In src/client/graphics/layers/RadialMenu.ts around lines 527 to 530, remove the
redundant check for spawn phase (this.params.game.inSpawnPhase()) from the
disabled variable assignment, since individual menu elements already handle this
condition in their disabled methods. Update the disabled assignment to only
check if this.params is null or if d.data.disabled(this.params) returns true.

@github-project-automation github-project-automation bot moved this from Triage to Development in OpenFront Release Management Jun 21, 2025
@evanpelle evanpelle force-pushed the evan-radial-disable branch from 66fdcdd to 877b4c3 Compare June 21, 2025 21:21
@evanpelle evanpelle marked this pull request as ready for review June 22, 2025 01:59
@evanpelle evanpelle requested a review from a team as a code owner June 22, 2025 01:59
@evanpelle evanpelle added this to the v24 milestone Jun 22, 2025
@evanpelle evanpelle force-pushed the evan-radial-disable branch from 24226c1 to a459213 Compare June 22, 2025 02:03
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

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

527-530: Remove redundant spawn phase check.

The spawn phase check here is redundant since individual menu elements already handle this in their disabled methods. This creates duplicate logic.

 const disabled =
   this.params === null ||
-  this.params.game.inSpawnPhase() ||
   d.data.disabled(this.params);
🧹 Nitpick comments (1)
src/client/graphics/layers/RadialMenuElements.ts (1)

407-437: Center button logic is correct but could be simplified.

The implementation handles spawn/attack logic correctly. Consider extracting the disabled logic into smaller, named functions for better readability:

+  private isWaterTile = (params: MenuElementParams): boolean => 
+    !params.game.isLand(params.tile);
+  
+  private isSpawnPhaseWithPlayerTile = (params: MenuElementParams): boolean => 
+    params.game.inSpawnPhase() && params.game.owner(params.tile).isPlayer();

   disabled: (params: MenuElementParams): boolean => {
-    const tileOwner = params.game.owner(params.tile);
-    const isLand = params.game.isLand(params.tile);
-    if (!isLand) {
-      return true;
-    }
-    if (params.game.inSpawnPhase()) {
-      if (tileOwner.isPlayer()) {
-        return true;
-      }
-      return false;
-    }
-    return false;
+    return this.isWaterTile(params) || this.isSpawnPhaseWithPlayerTile(params);
   },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24226c1 and a459213.

📒 Files selected for processing (5)
  • src/client/graphics/GameRenderer.ts (0 hunks)
  • src/client/graphics/layers/MainRadialMenu.ts (5 hunks)
  • src/client/graphics/layers/MenuEventManager.ts (0 hunks)
  • src/client/graphics/layers/RadialMenu.ts (24 hunks)
  • src/client/graphics/layers/RadialMenuElements.ts (8 hunks)
💤 Files with no reviewable changes (2)
  • src/client/graphics/GameRenderer.ts
  • src/client/graphics/layers/MenuEventManager.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Deploy to openfront.dev
🔇 Additional comments (6)
src/client/graphics/layers/RadialMenuElements.ts (2)

58-61: Good interface design!

The CenterButtonElement interface follows composition principles and provides a clean abstraction for center button behavior.


439-443: Menu reordering looks good.

Moving infoMenuElement to the first position improves the menu layout as intended.

src/client/graphics/layers/MainRadialMenu.ts (2)

74-99: Clean event handling implementation.

The direct context menu event handling is well-structured and removes unnecessary complexity from the previous MenuEventManager approach. The coordinate validation and async action fetching are handled correctly.


159-175: Excellent centralized cleanup method.

The closeMenu method provides a clean way to hide all menu-related UI components with proper visibility checks. This prevents UI state inconsistencies.

src/client/graphics/layers/RadialMenu.ts (2)

30-30: Excellent state management refactor.

The unified CenterButtonState enum and centerButtonElement approach is much cleaner than the previous multiple boolean flags. This follows good TypeScript practices with typed unions.

Also applies to: 47-48


818-830: Clean center button click handling.

The state-based approach for handling center button clicks is well-implemented and much clearer than the previous logic.

@evanpelle evanpelle force-pushed the evan-radial-disable branch from a459213 to 1d59164 Compare June 22, 2025 02:17
@evanpelle evanpelle merged commit ce991f9 into main Jun 22, 2025
10 of 11 checks passed
@evanpelle evanpelle deleted the evan-radial-disable branch June 22, 2025 02:29
@github-project-automation github-project-automation bot moved this from Development to Complete in OpenFront Release Management Jun 22, 2025
@coderabbitai coderabbitai bot mentioned this pull request Nov 9, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

2 participants