Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
60a202f
feat: multi-warship selection with Shift+drag box
baculinivan-web Apr 15, 2026
7b44813
style: apply prettier formatting
baculinivan-web Apr 15, 2026
5f23c20
feat: use configurable shiftKey keybind for warship multi-select
baculinivan-web Apr 15, 2026
72b2b4c
fix: clear single-selection outline when box selection starts
baculinivan-web Apr 15, 2026
1a6af88
fix: filter inactive warships before multi-move; extract paintSelecti…
baculinivan-web Apr 15, 2026
edf42ea
fix: update ShiftRight test to use configured shiftKey keybind
baculinivan-web Apr 15, 2026
cf5c50a
fix: clear multi-selection boxes when single warship is selected
baculinivan-web Apr 15, 2026
19a5c75
feat: atomic move_multiple_warships intent
baculinivan-web Apr 15, 2026
de07436
feat: touch long-press + drag for warship multi-select on mobile
baculinivan-web Apr 15, 2026
568ce36
fix: cursor/state cleanup for selection box edge cases
baculinivan-web Apr 15, 2026
16e2b2d
feat: select all warships hotkey (default F)
baculinivan-web Apr 15, 2026
507a76d
refactor: reuse existing events and executions per evanpelle review
baculinivan-web Apr 21, 2026
91f600f
fix: guard against undefined units in UnitSelectionEvent
baculinivan-web Apr 21, 2026
4782fce
fix: address nitpick review comments
baculinivan-web Apr 21, 2026
f730eed
fix: update Warship.test.ts to use number[] API for MoveWarshipExecution
baculinivan-web Apr 21, 2026
2c9695e
fix: selection box continues after Shift release; suppress tap after …
baculinivan-web Apr 21, 2026
7922d40
Merge branch 'main' into feature/warship-selection-and-move
baculinivan-web Apr 21, 2026
f7b5717
fix: UnitSelectionEvent cursor logic; blur/Escape clear multiSelectio…
baculinivan-web Apr 21, 2026
8639c6b
fix: suppressNextTap reset on modifier early returns; DRAG_THRESHOLD_…
baculinivan-web Apr 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
"action_ratio_change": "Decrease/Increase attack ratio",
"action_reset_gfx": "Reset graphics",
"action_auto_upgrade": "Auto-upgrade nearest building",
"action_warship_multiselect": "Select multiple warships (drag to draw selection box)",
"action_warship_selectall": "Select all your warships",
"drag": "drag",
"ui_section": "Game UI",
"ui_leaderboard": "Leaderboard",
"ui_your_team": "Your team:",
Expand Down Expand Up @@ -761,6 +764,7 @@
"city": "Increases max population",
"factory": "Creates railroads and spawns trains"
},
"warship_shift_hint": "Hold Shift and drag to select multiple warships at once",
"not_enough_money": "Not enough money"
},
"win_modal": {
Expand Down
22 changes: 22 additions & 0 deletions src/client/HelpModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,28 @@ export class HelpModal extends BaseModal {
${translateText("help_modal.action_auto_upgrade")}
</td>
</tr>
<tr class="hover:bg-white/5 transition-colors">
<td class="py-3 pl-4 border-b border-white/5">
<div class="inline-flex items-center gap-2">
${this.renderKey(keybinds.shiftKey)}
<span class="text-white/40 font-bold">+</span>
<span class="text-white/50 text-xs"
>${translateText("help_modal.drag")}</span
>
</div>
</td>
<td class="py-3 border-b border-white/5 text-white/70">
${translateText("help_modal.action_warship_multiselect")}
</td>
</tr>
<tr class="hover:bg-white/5 transition-colors">
<td class="py-3 pl-4 border-b border-white/5">
${this.renderKey(keybinds.selectAllWarships)}
</td>
<td class="py-3 border-b border-white/5 text-white/70">
${translateText("help_modal.action_warship_selectall")}
</td>
</tr>
</tbody>
</table>
</div>
Expand Down
227 changes: 218 additions & 9 deletions src/client/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ export class TouchEvent implements GameEvent {
}

/**
* Event emitted when a unit is selected or deselected
* Event emitted when one or more warships are selected or deselected.
* For single selection: unit is set, units is empty.
* For multi selection: units contains all selected warships, unit is null.
* For deselection: isSelected is false.
*/
export class UnitSelectionEvent implements GameEvent {
constructor(
public readonly unit: UnitView | null,
public readonly isSelected: boolean,
public readonly units: UnitView[] = [],
) {}
}

Expand Down Expand Up @@ -98,6 +102,40 @@ export class SwapRocketDirectionEvent implements GameEvent {
constructor(public readonly rocketDirectionUp: boolean) {}
}

/** Emitted while the user is drawing a shift+drag selection rectangle */
export class WarshipSelectionBoxUpdateEvent implements GameEvent {
constructor(
public readonly startX: number,
public readonly startY: number,
public readonly endX: number,
public readonly endY: number,
) {}
}

/** Emitted when the user releases the mouse after drawing a selection rectangle */
export class WarshipSelectionBoxCompleteEvent implements GameEvent {
constructor(
public readonly startX: number,
public readonly startY: number,
public readonly endX: number,
public readonly endY: number,
) {}
}

/** Emitted when the selection box is cancelled (e.g. Escape or no drag) */
export class WarshipSelectionBoxCancelEvent implements GameEvent {}

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.

could this share the same event with single warship selection cancelled?

/** Emitted when the player triggers select-all-warships hotkey */
export class SelectAllWarshipsEvent implements GameEvent {}

/** Emitted when a touch long-press is detected (shows crosshair indicator) */
export class TouchLongPressStartEvent implements GameEvent {
constructor(
public readonly x: number,
public readonly y: number,
) {}
}

export class ShowBuildMenuEvent implements GameEvent {
constructor(
public readonly x: number,
Expand Down Expand Up @@ -166,13 +204,25 @@ export class InputHandler {

private alternateView = false;

// Warship selection box state
private selectionBoxActive: boolean = false;
// True while warships are selected via box (waiting for move target click)
private multiSelectionActive: boolean = false;

// Touch long-press state
private longPressTimer: ReturnType<typeof setTimeout> | null = null;
private longPressActive: boolean = false;
private suppressNextTap: boolean = false;
private readonly LONG_PRESS_MS = 800;

private moveInterval: NodeJS.Timeout | null = null;
private activeKeys = new Set<string>();
private keybinds: Record<string, string> = {};
private coordinateGridEnabled = false;

private readonly PAN_SPEED = 5;
private readonly ZOOM_SPEED = 10;
private readonly DRAG_THRESHOLD_PX = 10;

private readonly userSettings: UserSettings = new UserSettings();

Expand All @@ -186,8 +236,28 @@ export class InputHandler {
initialize() {
this.keybinds = this.userSettings.keybinds(Platform.isMac);

// Listen for warship selection to change cursor
this.eventBus.on(UnitSelectionEvent, (e) => {
if (e.isSelected && (e.units ?? []).length > 0) {
// Multi-selection active
this.multiSelectionActive = true;
this.canvas.style.cursor = "crosshair";
} else if (e.isSelected) {
// Single warship selected — cursor crosshair, but not multi
this.multiSelectionActive = false;
this.canvas.style.cursor = "crosshair";
} else {
// Deselected
this.multiSelectionActive = false;
if (!this.selectionBoxActive) {
this.canvas.style.cursor = "";
}
}
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

this.canvas.addEventListener("pointerdown", (e) => this.onPointerDown(e));
window.addEventListener("pointerup", (e) => this.onPointerUp(e));
window.addEventListener("pointercancel", (e) => this.onPointerUp(e));
this.canvas.addEventListener(
"wheel",
(e) => {
Expand Down Expand Up @@ -216,6 +286,18 @@ export class InputHandler {
}
this.pointerDown = false;
this.pointers.clear();
if (this.longPressTimer !== null) {
clearTimeout(this.longPressTimer);
this.longPressTimer = null;
}
this.longPressActive = false;
this.suppressNextTap = false;
if (this.selectionBoxActive || this.multiSelectionActive) {
this.selectionBoxActive = false;
this.multiSelectionActive = false;
this.eventBus.emit(new WarshipSelectionBoxCancelEvent());
}
this.canvas.style.cursor = "";
});
this.pointers.clear();

Expand All @@ -224,10 +306,7 @@ export class InputHandler {
let deltaY = 0;

// Skip if shift is held down
if (
this.activeKeys.has("ShiftLeft") ||
this.activeKeys.has("ShiftRight")
) {
if (this.activeKeys.has(this.keybinds.shiftKey)) {
return;
}

Expand Down Expand Up @@ -304,6 +383,11 @@ export class InputHandler {
e.preventDefault();
this.eventBus.emit(new CloseViewEvent());
this.setGhostStructure(null);
if (this.selectionBoxActive || this.multiSelectionActive) {
this.selectionBoxActive = false;
this.multiSelectionActive = false;
this.eventBus.emit(new WarshipSelectionBoxCancelEvent());
}
}

if (
Expand Down Expand Up @@ -347,12 +431,20 @@ export class InputHandler {
this.keybinds.centerCamera,
"ControlLeft",
"ControlRight",
"ShiftLeft",
"ShiftRight",
this.keybinds.shiftKey,
].includes(e.code)
) {
this.activeKeys.add(e.code);
}

// Shift = warship box selection mode.
// If a ghost structure is active, discard it first.
if (e.code === this.keybinds.shiftKey) {
if (this.uiState.ghostStructure !== null) {
this.setGhostStructure(null);
}
this.canvas.style.cursor = "crosshair";
}
});
window.addEventListener("keyup", (e) => {
const isTextInput = this.isTextInputTarget(e.target);
Expand Down Expand Up @@ -417,6 +509,11 @@ export class InputHandler {
this.eventBus.emit(new CenterCameraEvent());
}

if (e.code === this.keybinds.selectAllWarships) {
e.preventDefault();
this.eventBus.emit(new SelectAllWarshipsEvent());
}

// Two-phase build keybind matching: exact code match first, then digit/Numpad alias.
const matchedBuild = this.resolveBuildKeybind(e.code, e.shiftKey);
if (matchedBuild !== null) {
Expand Down Expand Up @@ -454,6 +551,15 @@ export class InputHandler {
}

this.activeKeys.delete(e.code);

// Reset crosshair when Shift is released (unless selection box or multi-selection still active)
if (
e.code === this.keybinds.shiftKey &&
!this.selectionBoxActive &&
!this.multiSelectionActive
) {
this.canvas.style.cursor = "";
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
});
}

Expand All @@ -479,7 +585,37 @@ export class InputHandler {
this.lastPointerDownY = event.clientY;

this.eventBus.emit(new MouseDownEvent(event.clientX, event.clientY));

// Start long-press timer for touch devices
if (event.pointerType === "touch") {
this.longPressActive = false;
if (this.longPressTimer !== null) {
clearTimeout(this.longPressTimer);
this.longPressTimer = null;
}
this.longPressTimer = setTimeout(() => {
this.longPressTimer = null;
this.longPressActive = true;
this.canvas.style.cursor = "crosshair";
this.eventBus.emit(
new TouchLongPressStartEvent(
this.lastPointerDownX,
this.lastPointerDownY,
),
);
}, this.LONG_PRESS_MS);
}
} else if (this.pointers.size === 2) {
// Second finger down — cancel any pending long-press to avoid
// triggering selection mode mid-pinch
if (this.longPressTimer !== null) {
clearTimeout(this.longPressTimer);
this.longPressTimer = null;
}
if (this.longPressActive) {
this.longPressActive = false;
this.canvas.style.cursor = "";
}
this.lastPinchDistance = this.getPinchDistance();
}
}
Expand All @@ -496,20 +632,64 @@ export class InputHandler {
this.pointerDown = false;
this.pointers.clear();

// Clean up long-press state
if (this.longPressTimer !== null) {
clearTimeout(this.longPressTimer);
this.longPressTimer = null;
}
const wasLongPress = this.longPressActive;
this.longPressActive = false;
if (wasLongPress) {
this.canvas.style.cursor = "";
// If long-press fired but no drag happened (selectionBoxActive is false),
// suppress the tap so we don't emit a spurious TouchEvent
if (!this.selectionBoxActive) {
this.suppressNextTap = true;
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

// Complete selection box if it was active
if (this.selectionBoxActive) {
this.selectionBoxActive = false;
const dist =
Math.abs(event.clientX - this.lastPointerDownX) +
Math.abs(event.clientY - this.lastPointerDownY);
if (dist >= this.DRAG_THRESHOLD_PX) {
this.eventBus.emit(
new WarshipSelectionBoxCompleteEvent(
this.lastPointerDownX,
this.lastPointerDownY,
event.clientX,
event.clientY,
),
);
return;
} else {
this.eventBus.emit(new WarshipSelectionBoxCancelEvent());
}
}

if (this.isModifierKeyPressed(event)) {
this.suppressNextTap = false;
this.eventBus.emit(new ShowBuildMenuEvent(event.clientX, event.clientY));
return;
}
if (this.isAltKeyPressed(event)) {
this.suppressNextTap = false;
this.eventBus.emit(new ShowEmojiMenuEvent(event.clientX, event.clientY));
return;
}

const dist =
Math.abs(event.x - this.lastPointerDownX) +
Math.abs(event.y - this.lastPointerDownY);
if (dist < 10) {
if (dist < this.DRAG_THRESHOLD_PX) {
if (event.pointerType === "touch") {
if (this.suppressNextTap) {
this.suppressNextTap = false;
event.preventDefault();
return;
}
this.eventBus.emit(new TouchEvent(event.x, event.y));
event.preventDefault();
return;
Expand Down Expand Up @@ -586,7 +766,36 @@ export class InputHandler {
const deltaX = event.clientX - this.lastPointerX;
const deltaY = event.clientY - this.lastPointerY;

this.eventBus.emit(new DragEvent(deltaX, deltaY));
// Cancel long-press if finger moved significantly before timer fires
if (this.longPressTimer !== null) {
const moveDist =
Math.abs(event.clientX - this.lastPointerDownX) +
Math.abs(event.clientY - this.lastPointerDownY);
if (moveDist >= this.DRAG_THRESHOLD_PX) {
clearTimeout(this.longPressTimer);
this.longPressTimer = null;
}
}

// If shift is held OR touch long-press is active OR selection box already
// started, continue emitting selection box updates
if (
this.selectionBoxActive ||
this.activeKeys.has(this.keybinds.shiftKey) ||
this.longPressActive
) {
this.selectionBoxActive = true;
this.eventBus.emit(
new WarshipSelectionBoxUpdateEvent(
this.lastPointerDownX,
this.lastPointerDownY,
event.clientX,
event.clientY,
),
);
} else {
this.eventBus.emit(new DragEvent(deltaX, deltaY));
}

this.lastPointerX = event.clientX;
this.lastPointerY = event.clientY;
Expand Down
Loading
Loading