#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

@ -12,6 +12,8 @@ extends Control
## [Backspace / Back] skips the rest of the conversation. One that doesn't pause the game takes no
## input and goes on by itself (Conversation.line_hold). Works while the game is paused
## (DialogueDirector pauses it for a conversation); waits while blocked (a menu is up over it).
## On a phone (MobilePort.active()) a tap is the click, and a conversation that pauses the game
## has a Skip button on the paper (a ScarecrowHud.HitTarget) that skips it, as Backspace does.
signal finished(conversation: Conversation)
@ -31,12 +33,19 @@ const OPEN_TIME := 0.18
const PAUSES := {".": 0.32, "!": 0.32, "?": 0.32, "…": 0.32, ",": 0.14, ";": 0.14, ":": 0.14}
const TALK_FPS := 9.0
const SEED := 701.0
## Phones: the Skip button drawn on the paper (its hit target may be bigger), its right edge and
## bottom this far in from the paper's bottom-right corner (left of the pen arrow).
const SKIP_SIZE := Vector2(118.0, 50.0)
const SKIP_INSET := Vector2(104.0, 26.0)
const SKIP_FONT := 30
## Optional: whether a menu is up over the box (it waits: no input, no writing).
var blocked: Callable
## The conversation up (null when none), and its line on the paper.
var conversation: Conversation
var index: int = -1
## Phones: the Skip button (null on desktop), shown while a conversation pauses the game.
var skip_target: ScarecrowHud.HitTarget
static var _narrator := DialogueSpeaker.new()
static var _variants := {} # "font id/slant/bold" -> FontVariation
@ -99,6 +108,13 @@ func _ready() -> void:
_more.size = Vector2(40.0, 40.0)
_more.draw.connect(_draw_more)
_sheet.add_child(_more)
if MobilePort.active():
skip_target = ScarecrowHud.HitTarget.new()
skip_target.name = "Skip"
skip_target.visible = false
skip_target.tapped.connect(_on_skip_tapped)
skip_target.draw.connect(_draw_skip)
_sheet.add_child(skip_target)
_voice = AudioStreamPlayer.new()
_voice.bus = &"SFX"
add_child(_voice)
@ -368,10 +384,25 @@ func _place() -> void:
_text.size = Vector2(inner, r.size.y - top - 36.0)
_more.position = Vector2(r.size.x - 50.0 - _more.size.x, r.size.y - 30.0 - _more.size.y)
_more.visible = conversation != null and conversation.pause_game and is_written()
if skip_target != null:
skip_target.visible = conversation != null and conversation.pause_game
skip_target.cover(skip_rect())
skip_target.queue_redraw()
_stage.queue_redraw()
_more.queue_redraw()
## Phones: where the Skip button is drawn on the paper (the sheet's coordinates).
func skip_rect() -> Rect2:
var r := _sheet_rect()
return Rect2(r.size - SKIP_INSET - SKIP_SIZE, SKIP_SIZE)
func _on_skip_tapped() -> void:
if conversation != null and conversation.pause_game and not is_blocked():
skip()
func _sheet_rect() -> Rect2:
var w := minf(WIDTH, size.x - 2.0 * SIDE_GAP)
return Rect2((size.x - w) * 0.5, size.y - BOTTOM - HEIGHT, w, HEIGHT)
@ -450,6 +481,25 @@ func _frame(h: Head) -> Texture2D:
return h.face if k == 0 else sp.talk_frames[k - 1]
## Phones: the Skip button, a pen-drawn box on the paper with the word and a double arrow.
func _draw_skip() -> void:
var ink := Sketch.PAPER_INK
var r := Rect2((skip_target.size - SKIP_SIZE) * 0.5, SKIP_SIZE)
Sketch.box(skip_target, r, Color(Sketch.PAPER.darkened(0.1), 0.9), Color(ink, 0.85), 2.0, SEED + 21.0)
var word := Sketch.text_width("Skip", SKIP_FONT)
var arrows := 26.0
var x := r.get_center().x - (word + 8.0 + arrows) * 0.5
var f := Sketch.font()
var top := r.get_center().y - (f.get_ascent(SKIP_FONT) + f.get_descent(SKIP_FONT)) * 0.5
Sketch.text(skip_target, Vector2(x, top), "Skip", SKIP_FONT, ink, HORIZONTAL_ALIGNMENT_LEFT, 0)
var c := Vector2(x + word + 8.0, r.get_center().y)
for k in 2:
var a := c + Vector2(k * 12.0, 0.0)
var tip := PackedVector2Array([a + Vector2(0.0, -9.0), a + Vector2(13.0, 0.0), a + Vector2(0.0, 9.0)])
skip_target.draw_colored_polygon(tip, Color(ink, 0.85))
Sketch.outline(skip_target, tip, ink, 1.5, SEED + 30.0 + k, 0.6, 1)
## The pen arrow in the corner when the line is written and the player goes on.
func _draw_more() -> void:
var ink: Color = _text.get_theme_color("default_color")