Files
windroost/p2_godot_sample/scripts/primary_cta_dock.gd
T
wushenghua 796ca6840d U1 UI slice: Skyport/World/Settlement shells with fixed CTA dock
Additive UI vertical slice on baseline 28e8247. Owned scope only: page
shells, PrimaryCTADock, UiTheme helpers, U1 probe/capture runner and
evidence. No battle, numeric, save or locale files touched.

48 real-render shots: 360/390/430 x zh/en x normal/reduced, plus
scrolled/locked/defeat states. Real InputEventScreenTouch fires the CTA
and changes world node selection; >=48px tap targets, fixed CTA position
across scroll, no missing text keys, no SCRIPT ERROR.
2026-11-28 01:44:08 +08:00

106 lines
2.5 KiB
GDScript

class_name PrimaryCTADock
extends Control
## U1: the single fixed primary action dock for every non-battle page.
## Never placed inside a ScrollContainer: it stays at the same pixels at any
## scroll offset. The dock owns exactly one gold solid Button (56px tall,
## screen width - 32, >=48x48 hit area) with >=24px bottom breathing room.
signal cta_pressed
const SIDE_INSET := 16
const TOP_GAP := 8
const BOTTOM_BREATH := 24
const DOCK_HEIGHT := 56 + TOP_GAP + BOTTOM_BREATH # 88 (+ injected safe_bottom)
var button: Button = null
var safe_bottom: int = 0
var _label: String = ""
var _icon_path: String = ""
func _init(label: String = "", icon_path: String = "", safe_bottom_px: int = 0) -> void:
_label = label
_icon_path = icon_path
safe_bottom = safe_bottom_px
mouse_filter = Control.MOUSE_FILTER_PASS
func _ready() -> void:
_build()
func _build() -> void:
for child in get_children():
remove_child(child)
child.free()
var bg := ColorRect.new()
bg.color = Color(0.03, 0.07, 0.12, 0.82)
bg.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
bg.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(bg)
var hairline := ColorRect.new()
hairline.color = Color("#5a4a2a")
hairline.set_anchors_and_offsets_preset(Control.PRESET_TOP_WIDE)
hairline.custom_minimum_size = Vector2(0, 2)
hairline.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(hairline)
button = UiTheme.make_primary_cta(_label, _icon_path)
button.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
button.offset_left = SIDE_INSET
button.offset_right = -SIDE_INSET
button.offset_top = TOP_GAP
button.offset_bottom = -(BOTTOM_BREATH + safe_bottom)
button.pressed.connect(_on_button_pressed)
add_child(button)
func _on_button_pressed() -> void:
cta_pressed.emit()
func set_label(text: String) -> void:
_label = text
if button != null:
button.text = text
func set_icon(path: String) -> void:
_icon_path = path
if button != null:
if path.is_empty():
button.icon = null
else:
button.icon = load(path) as Texture2D
func set_enabled(value: bool) -> void:
if button != null:
button.disabled = not value
func set_safe_bottom(value: int) -> void:
if value == safe_bottom:
return
safe_bottom = value
if button != null:
button.offset_bottom = -(BOTTOM_BREATH + safe_bottom)
func button_global_rect() -> Rect2:
if button == null:
return Rect2()
return button.get_global_rect()
func tap_center() -> Vector2:
var rect := button_global_rect()
return rect.position + rect.size * 0.5
func min_height() -> int:
return DOCK_HEIGHT