#39: tappable HUD

On phones (MobilePort.active()) the HUD's widgets take taps through small
STOP hit targets (ScarecrowHud.HitTarget, at least minimum_target()), and
everything beside them is still the thumbsticks':
- hotbar: a tap on a main slot picks it through the number keys' path
  (weapon_k, applied only when combat may switch); no number keys on phones
  (Prompts.hotbar_key)
- backpack: a tap toggles the pouch panel, a finger elsewhere (not on the
  panel) closes it; the panel stays inside safe_rect
- tip box: an × hides tips as Backspace does (Tutorial.hide_tips)
- dialogue: a Skip button on pausing conversations; a tap elsewhere advances
Desktop has no targets and draws as before. Test: mobile/hud_taps_test.gd.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-14 15:10:56 -04:00
parent 5392ae09af
commit 49e94874a6
7 changed files with 643 additions and 28 deletions

View file

@ -7,7 +7,8 @@ extends Control
## Night: fight (once enemies are in), fear (when crowded), recover (when something is
## dropped), patch up (when hurt)
## The most urgent one wins (recover, fear, patch, shoot, dusk, then the day's in order).
## [Backspace / Back] hides them until the game is restarted; Settings turns them off.
## [Backspace / Back] hides them until the game is restarted (hide_tips); on a phone so does the ×
## on the tip box's corner (a ScarecrowHud.HitTarget). Settings turns them off.
## Finished tips stay finished for the session, so a retry or a second vacation doesn't repeat
## them.
## None show while a talking-head conversation or the opening intro is up.
@ -28,6 +29,11 @@ const TEXT := {
const PRIORITY: Array[String] = ["recover", "fear", "patch", "shoot", "dusk", "move", "gather", "store", "build"]
const DONE_TIME := 0.9
const CROWD_RADIUS := 7.0
## Phones: the ×'s disc, centered this far in from the tip box's top-right corner.
const HIDE_RADIUS := 20.0
const HIDE_INSET := 6.0
const BOX_FILL := Color(0.08, 0.1, 0.08, 0.86)
const BOX_EDGE := Color(0.95, 0.82, 0.45)
var sim: FarmSim
## Off when the player turned tips off in Settings.
@ -36,6 +42,8 @@ var enabled := true
var dismissed := false
var done := {}
var current := ""
## Phones: the tip box's × (null on desktop).
var hide_target: ScarecrowHud.HitTarget
var _box: PanelContainer
var _text: Label
@ -63,8 +71,8 @@ func _ready() -> void:
mouse_filter = Control.MOUSE_FILTER_IGNORE
_box = PanelContainer.new()
var bg := StyleBoxFlat.new()
bg.bg_color = Color(0.08, 0.1, 0.08, 0.86)
bg.border_color = Color(0.95, 0.82, 0.45)
bg.bg_color = BOX_FILL
bg.border_color = BOX_EDGE
bg.set_border_width_all(2)
bg.set_corner_radius_all(6)
bg.content_margin_left = 18.0
@ -89,6 +97,14 @@ func _ready() -> void:
_hint.add_theme_color_override("font_color", Color(0.7, 0.72, 0.65))
col.add_child(_hint)
_box.visible = false
if MobilePort.active():
hide_target = ScarecrowHud.HitTarget.new()
hide_target.name = "HideTips"
hide_target.visible = false
hide_target.tapped.connect(hide_tips)
hide_target.draw.connect(_draw_hide)
add_child(hide_target)
_box.item_rect_changed.connect(_place_hide)
func _process(delta: float) -> void:
@ -163,15 +179,25 @@ func _finish(id: String) -> void:
_done_left = DONE_TIME
## Hides the tips until the game is restarted: [Backspace / Back], or the × on a phone.
func hide_tips() -> void:
dismissed = true
_show("")
func _show(id: String) -> void:
current = id
_box.visible = id != ""
if hide_target != null:
hide_target.visible = _box.visible
if id == "":
return
_text.text = Prompts.tip(id)
_text.remove_theme_color_override("font_color")
_box.reset_size()
_box.position = Vector2((size.x - _box.size.x) * 0.5, size.y - 250.0 - _box.size.y)
if hide_target != null:
_place_hide()
func _enemies_near() -> int:
@ -195,6 +221,23 @@ func _on_phase(phase: CampaignController.Phase, _previous: CampaignController.Ph
func _unhandled_input(event: InputEvent) -> void:
if _box.visible and event.is_action_pressed("hide_tips"):
dismissed = true
_show("")
hide_tips()
get_viewport().set_input_as_handled()
## Phones: the × at the tip box's top-right corner, over it.
func _place_hide() -> void:
var r := _box.get_rect()
var at := Vector2(r.end.x - HIDE_INSET, r.position.y + HIDE_INSET)
hide_target.cover(Rect2(at - Vector2(HIDE_RADIUS, HIDE_RADIUS), Vector2(HIDE_RADIUS, HIDE_RADIUS) * 2.0))
hide_target.queue_redraw()
## The ×: a disc of the tip box's own fill and edge, on its corner.
func _draw_hide() -> void:
var c := hide_target.size * 0.5
hide_target.draw_circle(c, HIDE_RADIUS, Color(BOX_FILL, 0.97))
Sketch.circle(hide_target, c, HIDE_RADIUS, BOX_EDGE, 2.5, 3.0)
var k := HIDE_RADIUS * 0.42
Sketch.line(hide_target, c + Vector2(-k, -k), c + Vector2(k, k), Sketch.TEXT, 3.5, 11.0, 0.5)
Sketch.line(hide_target, c + Vector2(k, -k), c + Vector2(-k, k), Sketch.TEXT, 3.5, 12.0, 0.5)