Refine tile drawer double-click behavior

This commit is contained in:
dingo
2026-05-08 11:16:47 -04:00
parent f7fc4fbdd3
commit 8cd71b838c
2 changed files with 55 additions and 12 deletions
@@ -5,7 +5,7 @@ extends Node
signal board_clicked(screen_pos: Vector2) # tap/click on board (no drag)
signal board_held(coord: Vector2i) # long press on tile (hold timer fired)
signal board_double_clicked(screen_pos: Vector2) # double-click on unit
signal board_double_clicked(screen_pos: Vector2) # double-click on board tile
signal board_orbit(delta: Vector2) # camera orbit delta
signal board_pan(delta: Vector2, cam_distance: float) # camera pan delta
signal board_zoom(amount: float) # scroll/pinch zoom
@@ -35,6 +35,7 @@ var gesture_finger_count: int = 0
var _deselect_pending: bool = false
var _hand_scroll_time: float = 0.0
var _suppress_click_release: bool = false
# ── References set by parent ──────────────────────────────────────────────────
@@ -177,12 +178,12 @@ func _unhandled_input(event: InputEvent) -> void:
if mb.pressed:
if _hand_blocks_pointer(mb.position):
return
# Double-click on a battlefield unit → show full card detail popup.
if mb.double_click:
var dbl_unit_id: String = ""
if fn_mouse_to_unit_id.is_valid():
dbl_unit_id = fn_mouse_to_unit_id.call(mb.position)
if not dbl_unit_id.is_empty():
var dbl_coord: Vector2i = Vector2i(-1, -1)
if fn_mouse_to_tile_coord.is_valid():
dbl_coord = fn_mouse_to_tile_coord.call(mb.position)
if dbl_coord.x >= 0:
_suppress_click_release = true
board_double_clicked.emit(mb.position)
return
last_mouse = mb.position
@@ -200,7 +201,9 @@ func _unhandled_input(event: InputEvent) -> void:
else:
if is_instance_valid(hold_timer):
hold_timer.stop()
if not drag_active and not touch_drag_active and press_was_on_board:
if _suppress_click_release:
_suppress_click_release = false
elif not drag_active and not touch_drag_active and press_was_on_board:
board_clicked.emit(mb.position)
drag_active = false
touch_drag_active = false
@@ -93,6 +93,10 @@ var _last_click_frame : int = -1
var _last_click_iid : String = ""
var _rebuild_pending : bool = false
var _pending_rebuild_state: Dictionary = {}
var _tile_drawer_pinned: bool = false
var _ignore_next_board_click_after_double: bool = false
var _last_double_click_coord: Vector2i = Vector2i(-1, -1)
var _last_double_click_msec: int = -1
var _cursor_highlight : MeshInstance3D = null
var _hover_team_overlay : MeshInstance3D = null
@@ -199,10 +203,7 @@ func _ready() -> void:
_sel_ctrl.highlights_cleared.connect(_clear_highlights)
_sel_ctrl.highlight_add_requested.connect(_add_highlight)
_sel_ctrl.highlight_tiles_requested.connect(_highlight_tiles)
_sel_ctrl.tile_drawer_open_requested.connect(
func(tile_data: Dictionary) -> void:
_tile_drawer.open_tile_drawer(tile_data)
)
_sel_ctrl.tile_drawer_open_requested.connect(_on_tile_drawer_open_requested)
_sel_ctrl.tile_drawer_close_requested.connect(_tile_drawer.close_tile_drawer)
_sel_ctrl.camera_follow_requested.connect(
func(world_pos: Vector3) -> void: _cam_ctrl.tween_to_pivot(world_pos)
@@ -245,6 +246,7 @@ func _ready() -> void:
return _mouse_to_unit_id(pos)
add_child(_input_handler)
_input_handler.board_clicked.connect(_on_board_clicked)
_input_handler.board_double_clicked.connect(_on_board_double_clicked)
_input_handler.board_held.connect(_on_board_held)
_input_handler.board_orbit.connect(_on_board_orbit)
_input_handler.board_pan.connect(_on_board_pan)
@@ -287,7 +289,7 @@ func _ready() -> void:
_cam_ctrl.on_cam_zoom_btn_toggled(p)
_input_handler.touch_cam_zoom = p and _cam_ctrl.cam_zoom_btn.button_pressed
)
_tile_drawer_toggle_btn.pressed.connect(_tile_drawer.on_tile_drawer_toggle_pressed)
_tile_drawer_toggle_btn.pressed.connect(_on_tile_drawer_toggle_pressed)
# ── 5. Route server prompt signals to components ──────────────────────────
Game.triggered_target_request.connect(_abt.on_triggered_target_request)
@@ -518,6 +520,12 @@ func _input(event: InputEvent) -> void:
func _on_board_clicked(screen_pos: Vector2) -> void:
var coord: Vector2i = _pathfinder.mouse_to_tile_coord(screen_pos, _board_ctrl.tile_bodies)
if _ignore_next_board_click_after_double:
var msec_since_double: int = Time.get_ticks_msec() - _last_double_click_msec
_ignore_next_board_click_after_double = false
if coord == _last_double_click_coord and msec_since_double <= 500:
_update_hover(screen_pos)
return
var unit_id: String = _mouse_to_unit_id(screen_pos)
if unit_id.is_empty() and coord.x >= 0:
var tile: Dictionary = Game.get_tile(coord.x, coord.y)
@@ -530,6 +538,38 @@ func _on_board_clicked(screen_pos: Vector2) -> void:
else:
_show_aura_hover_overlay(unit_id)
func _on_board_double_clicked(screen_pos: Vector2) -> void:
var coord: Vector2i = _pathfinder.mouse_to_tile_coord(screen_pos, _board_ctrl.tile_bodies)
if coord.x < 0:
return
_ignore_next_board_click_after_double = true
_last_double_click_coord = coord
_last_double_click_msec = Time.get_ticks_msec()
_tile_drawer.open_tile_drawer(Game.get_tile(coord.x, coord.y))
if Settings.click_to_focus_camera and _pathfinder != null:
var world: Vector3 = _pathfinder.coord_to_world(coord.x, coord.y)
_cam_ctrl.tween_to_pivot(world)
func _on_tile_drawer_open_requested(tile_data: Dictionary) -> void:
if _tile_drawer_pinned:
_tile_drawer.open_tile_drawer(tile_data)
return
_tile_drawer.set_tile_drawer_content(tile_data, Game.state)
if Time.get_ticks_msec() - _last_double_click_msec <= 500:
return
if _tile_drawer.tile_drawer_open:
_tile_drawer.close_tile_drawer()
func _on_tile_drawer_toggle_pressed() -> void:
if _tile_drawer.tile_drawer_open:
_tile_drawer_pinned = false
_tile_drawer.close_tile_drawer()
return
if _tile_drawer.tile_drawer_last_tile.is_empty():
return
_tile_drawer_pinned = true
_tile_drawer.open_tile_drawer(_tile_drawer.tile_drawer_last_tile)
func _on_board_held(coord: Vector2i) -> void:
_held_coord_show_popup(coord)