Skip to content

Fix(ui) mouse event#30

Merged
1brucben merged 2 commits into
mainfrom
fix-mouse-event
Oct 6, 2025
Merged

Fix(ui) mouse event#30
1brucben merged 2 commits into
mainfrom
fix-mouse-event

Conversation

@El-Magico777
Copy link
Copy Markdown
Collaborator

@El-Magico777 El-Magico777 commented Sep 6, 2025

Description:

This pull request addresses two UI bugs that were impacting the user experience: #29

  1. Sticky Map Dragging: Previously, if a user started dragging the map and their mouse cursor passed over the PlayerInfoOverlay, the map would continue to drag even after the mouse button was released. This required an extra click to stop the map movement. This was caused by the pointerup event not being correctly handled when the cursor was over a UI element.

    This has been fixed in InputHandler.ts by ensuring that the pointerDown state is always reset on any pointerup event, regardless of the target element. This prevents the "sticky drag" behavior and makes the map dragging more reliable.

  2. Persistent Build Selection: When a user selected a unit to build (e.g., an Atom Bomb) and then switched to a different tab in the build menu (e.g., from "Attack" to "Buildings"), the unit would remain selected. This could lead to confusion and accidental builds, as the crosshair for the selected unit would still be active.

    This has been resolved by introducing a new _changeTab method in ControlPanel2.ts. This method is now called whenever a tab is clicked, and it ensures that pendingBuildUnitType is set to null, effectively clearing the build selection. This makes the UI more intuitive and prevents unexpected behavior.

Changes:

  • src/client/InputHandler.ts: Modified the onPointerUp method to always reset the pointerDown state, fixing the sticky map dragging bug.
  • src/client/graphics/layers/ControlPanel2.ts:
    • Added a new _changeTab method to handle tab switching and clear the build selection.
    • Updated the @click handlers for each tab to use the new _changeTab method.

These changes improve the overall user experience by making the UI more predictable and less prone to errors.

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:

el_magico777

This change clears the pending build unit type when the user switches tabs in the control panel.

Previously, if a user selected a unit to build and then switched to another tab (e.g., to check their economy), the build selection would persist. This could lead to accidental builds if the user later clicked on the map without realizing they were still in build mode.

This commit introduces a new `_changeTab` method that is called when any tab is clicked. This method updates the active tab and clears the `pendingBuildUnitType` in the `uiState`, ensuring that the build selection is reset when the user changes context.
@El-Magico777 El-Magico777 added this to the V1.0 milestone Sep 6, 2025
@El-Magico777 El-Magico777 self-assigned this Sep 6, 2025
@El-Magico777 El-Magico777 added the bug Something isn't working label Sep 6, 2025
@El-Magico777 El-Magico777 marked this pull request as ready for review September 6, 2025 21:55
@El-Magico777 El-Magico777 changed the title Fix mouse event Fix(ui) mouse event Sep 12, 2025
@El-Magico777 El-Magico777 modified the milestones: V1.0, v0.1.10 Sep 20, 2025
El-Magico777 added a commit that referenced this pull request Sep 20, 2025
@1brucben 1brucben merged commit e7574e2 into main Oct 6, 2025
16 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants