#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:
parent
5392ae09af
commit
49e94874a6
7 changed files with 643 additions and 28 deletions
|
|
@ -4,6 +4,10 @@ extends Control
|
|||
## beside it, and a red dot once something new has gone into it since it was last opened (gone
|
||||
## again when the pouch is emptied). The pouch action (I / R3) opens the pouch panel over it, and
|
||||
## closes it again: each material carried, and how much of each the supply shed holds.
|
||||
## On a phone (MobilePort.active()) the backpack is a hit target (ScarecrowHud.HitTarget): a tap
|
||||
## opens or closes the panel, and a finger landing anywhere else but on the panel closes it (and
|
||||
## goes on to whatever is there: a thumbstick, a button). There the panel stays inside the safe
|
||||
## area (MobilePort.safe_rect).
|
||||
|
||||
## The backpack icon, from the screen's bottom-left corner.
|
||||
const ICON := Rect2(26.0, -136.0, 108.0, 108.0)
|
||||
|
|
@ -19,8 +23,11 @@ var slot: int = 0
|
|||
var open := false
|
||||
## Something went into the pouch since it was last opened.
|
||||
var new_items := false
|
||||
## Phones: the backpack's hit target (null on desktop).
|
||||
var backpack_target: ScarecrowHud.HitTarget
|
||||
|
||||
var _last := {}
|
||||
var _phone := false
|
||||
|
||||
|
||||
func setup(p_campaign: CampaignController) -> void:
|
||||
|
|
@ -31,6 +38,24 @@ func setup(p_campaign: CampaignController) -> void:
|
|||
func _ready() -> void:
|
||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_phone = MobilePort.active()
|
||||
set_process_input(_phone)
|
||||
if _phone:
|
||||
backpack_target = ScarecrowHud.HitTarget.new()
|
||||
backpack_target.name = "Backpack"
|
||||
backpack_target.visible = false
|
||||
backpack_target.tapped.connect(toggle)
|
||||
add_child(backpack_target)
|
||||
|
||||
|
||||
## Phones: a finger landing outside the backpack and the open panel closes the panel. It isn't
|
||||
## taken: it goes on to the HUD's buttons and the thumbsticks.
|
||||
func _input(event: InputEvent) -> void:
|
||||
var touch := event as InputEventScreenTouch
|
||||
if touch == null or not touch.pressed or not open or campaign == null or not is_visible_in_tree():
|
||||
return
|
||||
if not backpack_target.get_global_rect().has_point(touch.position) and not panel_rect().has_point(touch.position):
|
||||
toggle()
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
|
|
@ -45,6 +70,22 @@ func toggle() -> void:
|
|||
new_items = false
|
||||
|
||||
|
||||
## The backpack icon, at the screen's bottom-left.
|
||||
func icon_rect() -> Rect2:
|
||||
return Rect2(Vector2(ICON.position.x, size.y + ICON.position.y), ICON.size)
|
||||
|
||||
|
||||
## The pouch panel, over the backpack; on a phone moved inside the safe area if it isn't.
|
||||
func panel_rect() -> Rect2:
|
||||
var icon := icon_rect()
|
||||
var height := 52.0 + ResourceStore.MATERIALS.size() * ROW + 12.0 # its heading, then a row per material (rows())
|
||||
var r := Rect2(Vector2(icon.position.x - 4.0, icon.position.y - 14.0 - height), Vector2(PANEL_WIDTH, height))
|
||||
if _phone:
|
||||
var safe := MobilePort.safe_rect(self)
|
||||
r.position = r.position.clamp(safe.position, (safe.end - r.size).max(safe.position))
|
||||
return r
|
||||
|
||||
|
||||
## "6/15": what the pouch holds, of what it can.
|
||||
func count_text() -> String:
|
||||
var r := campaign.state.resources
|
||||
|
|
@ -62,6 +103,9 @@ func rows() -> Array[Dictionary]:
|
|||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if backpack_target != null:
|
||||
backpack_target.visible = campaign != null
|
||||
backpack_target.cover(icon_rect())
|
||||
if campaign == null:
|
||||
return
|
||||
var r := campaign.state.resources
|
||||
|
|
@ -78,7 +122,7 @@ func _process(_delta: float) -> void:
|
|||
func _draw() -> void:
|
||||
if campaign == null:
|
||||
return
|
||||
var icon := Rect2(Vector2(ICON.position.x, size.y + ICON.position.y), ICON.size)
|
||||
var icon := icon_rect()
|
||||
Sketch.icon(self, "backpack", icon)
|
||||
if new_items:
|
||||
var at := icon.position + Vector2(icon.size.x - 16.0, 16.0)
|
||||
|
|
@ -86,13 +130,12 @@ func _draw() -> void:
|
|||
Sketch.circle(self, at, 11.5, Sketch.INK, 2.0, 402.0)
|
||||
Sketch.text(self, Vector2(icon.end.x + 4.0, icon.get_center().y - 18.0), count_text(), 42)
|
||||
if open:
|
||||
_draw_panel(icon)
|
||||
_draw_panel()
|
||||
|
||||
|
||||
func _draw_panel(icon: Rect2) -> void:
|
||||
func _draw_panel() -> void:
|
||||
var list := rows()
|
||||
var height := 52.0 + list.size() * ROW + 12.0
|
||||
var r := Rect2(Vector2(icon.position.x - 4.0, icon.position.y - 14.0 - height), Vector2(PANEL_WIDTH, height))
|
||||
var r := panel_rect()
|
||||
Sketch.panel(self, r, 411.0)
|
||||
var pouch_x := r.position.x + 290.0
|
||||
var shed_x := r.end.x - 26.0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue