Skip to content

Enhance InputHandler to allow using NumPad#3317

Open
wozniakpl wants to merge 2 commits intoopenfrontio:mainfrom
wozniakpl:feature/build-hotkeys-enter-confirm-numpad
Open

Enhance InputHandler to allow using NumPad#3317
wozniakpl wants to merge 2 commits intoopenfrontio:mainfrom
wozniakpl:feature/build-hotkeys-enter-confirm-numpad

Conversation

@wozniakpl
Copy link

Description:

Adds Enter and Numpad Enter as confirmation for placing a ghost structure after selecting a building with hotkeys (1–0 or numpad). Players can cancel with Esc but previously had to click to confirm; they can now confirm with Enter or Numpad Enter at the current cursor position. This supports keyboard-only or mouse + numpad workflows (e.g. one hand on numpad for select + confirm, one on mouse for aiming).

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:

.wozniakpl

…press when a ghost structure is set. Refactor event handling for build keybinds to use a helper function for improved readability. Update tests to cover new functionality and ensure proper event emissions.
@CLAassistant
Copy link

CLAassistant commented Mar 1, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 802cc7f and 3f3be01.

📒 Files selected for processing (3)
  • src/client/InputHandler.ts
  • src/client/graphics/layers/StructureIconsLayer.ts
  • tests/InputHandler.test.ts

Walkthrough

This change introduces keyboard-based confirmation for ghost structures and enables numeric keybinds for build actions. A new ConfirmGhostStructureEvent fires when Enter or NumpadEnter is pressed with an active ghost structure, while a helper method allows digit keys to map to build actions through numeric extraction.

Changes

Cohort / File(s) Summary
Ghost Structure Confirmation
src/client/InputHandler.ts, src/client/graphics/layers/StructureIconsLayer.ts
Introduces ConfirmGhostStructureEvent emitted on Enter/NumpadEnter key press when ghost structure is active. StructureIconsLayer listens for this event and invokes structure placement at current mouse position. Event enables keyboard-driven structure confirmation workflow.
Numeric Build Keybinds
src/client/InputHandler.ts
Adds digitFromKeyCode() and buildKeybindMatches() helper methods to extract digits from DigitX and NumpadX key codes and match them against keybind values, enabling both direct key codes and digit-based mappings for build actions (City, Factory, etc.).
Test Coverage
tests/InputHandler.test.ts
Exports ConfirmGhostStructureEvent from public API and adds comprehensive tests for ghost structure keyboard confirmation and Numpad numeric build keybinds (Numpad1/5/0 mapping to City, MissileSilo, MIRV).

Sequence Diagram

sequenceDiagram
    participant User as User/Keyboard
    participant IH as InputHandler
    participant SIL as StructureIconsLayer
    participant Game as Game Logic

    User->>IH: Press Enter/NumpadEnter<br/>(ghost structure active)
    activate IH
    IH->>IH: Detect Enter key +<br/>ghostStructure set
    IH->>SIL: Emit ConfirmGhostStructureEvent
    deactivate IH

    activate SIL
    SIL->>SIL: Listen to event
    SIL->>SIL: confirmGhostStructure()
    SIL->>Game: createStructure(MouseUpEvent<br/>at current position)
    deactivate SIL

    activate Game
    Game->>Game: Place structure<br/>at ghost position
    Game->>User: Structure confirmed
    deactivate Game
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🔨 Press Enter, ghost takes form,
Numbers map to builds—digits transform!
Keyboards click, structures rise,
A builder's dream in keybind size. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: enabling NumPad key support in the InputHandler for ghost structure confirmation and build actions.
Description check ✅ Passed The description clearly explains the feature: Enter/Numpad Enter now confirm ghost structure placement, supporting keyboard-only and mouse+numpad workflows.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

@wozniakpl wozniakpl marked this pull request as ready for review March 2, 2026 17:19
@wozniakpl wozniakpl requested a review from a team as a code owner March 2, 2026 17:19
@VariableVince VariableVince added UI/UX UI/UX changes including assets, menus, QoL, etc. Feature labels Mar 4, 2026
@VariableVince
Copy link
Contributor

@wozniakpl If you want (in this PR or a follow-up) could you also add the existing Esc and the new Enter key actions to the Help modal? Some hotkeys are displayed there with an icon, an Esc and Enter icon of the same style could be added. The help text could say something like "Closes menu. Cancels unit build preview." (for Esc) and "Confirms input. Confirms unit build preview." (for Enter).

Also if you want i can assign the issue #3064 to you, if you comment on it.

@wozniakpl
Copy link
Author

@wozniakpl If you want (in this PR or a follow-up) could you also add the existing Esc and the new Enter key actions to the Help modal? Some hotkeys are displayed there with an icon, an Esc and Enter icon of the same style could be added. The help text could say something like "Closes menu. Cancels unit build preview." (for Esc) and "Confirms input. Confirms unit build preview." (for Enter).

Also if you want i can assign the issue #3064 to you, if you comment on it.

Sure, I'd be happy to. This can be done in scope of another PR. I'll comment in that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

Feature/UX: add Enter as confirmation for building using Hotkeys

3 participants