#42: panels at phone scale
On phones (MobilePort.active()) the morning sign, the end screens, and the workbench's and shed's menus sit in the safe area; their long part scrolls (UiTheme.TouchScroll: a finger drag scrolls and never presses, a tap does) with Start the day / the end buttons / Close always in view below it; rows and buttons are at least the touch target; long text wraps. Desktop layout is unchanged (panels_test checks the 1920x1080 rects against the old ones). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5392ae09af
commit
e8729b41e8
6 changed files with 835 additions and 34 deletions
|
|
@ -11,12 +11,22 @@ extends CenterContainer
|
|||
## Escape / B, interact again, by walking off, or at nightfall. The scarecrow stands still and
|
||||
## can't shoot while either is open. Hand-drawn like the HUD's pouch panel (UiTheme.sketch): the
|
||||
## title over a pen rule, the tracks' names dim like the pouch's column headings, a slot per row.
|
||||
## On a phone (UiTheme's panels) it sits in the safe area: the rows are a list that scrolls
|
||||
## (UiTheme.TouchScroll: a finger that drags the list scrolls it and buys nothing, a tap on a row
|
||||
## buys), each row at least the touch target tall with its text wrapped to the room's width (up
|
||||
## to PHONE_ROW), and Close stays below the list, always in view.
|
||||
|
||||
## A purchase's result text. Nothing shows it on screen since #23 (the rows say what's missing);
|
||||
## tests listen to it.
|
||||
signal message(text: String, color: Color)
|
||||
signal bought(id: String)
|
||||
|
||||
const ROW := Vector2(860.0, 46.0)
|
||||
const CLOSE := Vector2(200.0, 48.0)
|
||||
const MARGIN := 8
|
||||
## A row's widest on a phone (an iPad's room is wider): about the workbench's longest.
|
||||
const PHONE_ROW := 1150.0
|
||||
|
||||
var campaign: CampaignController
|
||||
var structures: StructureSystem
|
||||
var player: PlayerCharacter
|
||||
|
|
@ -33,6 +43,11 @@ var slot: int = 0
|
|||
var _rows := {} # upgrade id -> Button
|
||||
var _title: Label
|
||||
var _close: Button
|
||||
var _safe: MarginContainer
|
||||
var _panel: PanelContainer
|
||||
var _scroll: UiTheme.TouchScroll
|
||||
var _list: VBoxContainer
|
||||
var _fit_queued := false
|
||||
|
||||
|
||||
func setup(p_campaign: CampaignController, p_structures: StructureSystem, p_player: PlayerCharacter, p_shop: String = "workbench") -> void:
|
||||
|
|
@ -40,7 +55,7 @@ func setup(p_campaign: CampaignController, p_structures: StructureSystem, p_play
|
|||
structures = p_structures
|
||||
player = p_player
|
||||
shop = p_shop
|
||||
var box := get_node("Panel/Margin/Box") as VBoxContainer
|
||||
var box := _list
|
||||
var track := ""
|
||||
for id in Upgrades.ORDER:
|
||||
var u: Dictionary = campaign.config.upgrades.get(id, {})
|
||||
|
|
@ -55,31 +70,27 @@ func setup(p_campaign: CampaignController, p_structures: StructureSystem, p_play
|
|||
box.add_child(head)
|
||||
var b := Button.new()
|
||||
b.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||
b.custom_minimum_size = Vector2(860.0, 46.0)
|
||||
b.custom_minimum_size = ROW
|
||||
b.add_theme_font_size_override("font_size", 25)
|
||||
b.pressed.connect(func() -> void: _buy(id))
|
||||
box.add_child(b)
|
||||
_rows[id] = b
|
||||
_close = Button.new()
|
||||
_close.text = "Close"
|
||||
_close.custom_minimum_size = Vector2(200.0, 48.0)
|
||||
_close.add_theme_font_size_override("font_size", 28)
|
||||
_close.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
|
||||
_close.pressed.connect(close)
|
||||
box.add_child(_close)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
theme = UiTheme.sketch()
|
||||
var panel := PanelContainer.new()
|
||||
panel.name = "Panel"
|
||||
add_child(panel)
|
||||
_safe = MarginContainer.new() # the safe area's margins on a phone (none on desktop)
|
||||
_safe.name = "Safe"
|
||||
add_child(_safe)
|
||||
_panel = PanelContainer.new()
|
||||
_panel.name = "Panel"
|
||||
_safe.add_child(_panel)
|
||||
var margin := MarginContainer.new()
|
||||
margin.name = "Margin"
|
||||
for side in ["left", "right", "top", "bottom"]:
|
||||
margin.add_theme_constant_override("margin_" + side, 8)
|
||||
panel.add_child(margin)
|
||||
margin.add_theme_constant_override("margin_" + side, MARGIN)
|
||||
_panel.add_child(margin)
|
||||
var box := VBoxContainer.new()
|
||||
box.name = "Box"
|
||||
box.add_theme_constant_override("separation", 6)
|
||||
|
|
@ -88,8 +99,24 @@ func _ready() -> void:
|
|||
_title.add_theme_font_size_override("font_size", 36)
|
||||
box.add_child(_title)
|
||||
box.add_child(HSeparator.new())
|
||||
_scroll = UiTheme.TouchScroll.new(Sketch.TEXT, 4.0) # the rows (setup), scrolling on a phone
|
||||
box.add_child(_scroll)
|
||||
_list = VBoxContainer.new()
|
||||
_list.name = "List"
|
||||
_list.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
_list.add_theme_constant_override("separation", 6)
|
||||
_scroll.add_child(_list)
|
||||
_close = Button.new()
|
||||
_close.text = "Close"
|
||||
_close.custom_minimum_size = CLOSE
|
||||
_close.add_theme_font_size_override("font_size", 28)
|
||||
_close.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
|
||||
_close.pressed.connect(close)
|
||||
box.add_child(_close)
|
||||
visible = false
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_list.minimum_size_changed.connect(_queue_fit) # rows rewritten or reflowed
|
||||
get_viewport().size_changed.connect(_queue_fit)
|
||||
|
||||
|
||||
func open() -> void:
|
||||
|
|
@ -100,6 +127,8 @@ func open() -> void:
|
|||
mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
player.start_channel(&"Idle_A")
|
||||
refresh()
|
||||
_fit()
|
||||
_scroll.scroll_vertical = 0
|
||||
var first: Button = _close
|
||||
for id in Upgrades.ORDER:
|
||||
if _rows.has(id) and not (_rows[id] as Button).disabled:
|
||||
|
|
@ -117,6 +146,42 @@ func close() -> void:
|
|||
player.stop_channel()
|
||||
|
||||
|
||||
## Lays the menu out: on desktop as it always was; on a phone (UiTheme's panels) inside the safe
|
||||
## area, the rows wrapped to the room's width and at least the touch target tall, and the list
|
||||
## scrolling past what the height leaves for it.
|
||||
func _fit() -> void:
|
||||
var phone := MobilePort.active()
|
||||
_scroll.set_phone(phone)
|
||||
var target := MobilePort.minimum_target(self) if phone else 0.0
|
||||
_close.custom_minimum_size = Vector2(CLOSE.x, maxf(CLOSE.y, target))
|
||||
var room := UiTheme.panel_room(self) if phone else Rect2()
|
||||
UiTheme.fit_margins(_safe, room)
|
||||
var width := ROW.x
|
||||
if phone:
|
||||
var frame := _panel.get_theme_stylebox("panel").get_minimum_size().x + 2.0 * MARGIN + _scroll.frame_width()
|
||||
width = floorf(minf(PHONE_ROW, room.size.x - frame))
|
||||
for id: String in _rows:
|
||||
var b := _rows[id] as Button
|
||||
b.custom_minimum_size = Vector2(width, maxf(ROW.y, target))
|
||||
b.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART if phone else TextServer.AUTOWRAP_OFF
|
||||
if phone:
|
||||
_scroll.fit(room.size.y - (_panel.get_combined_minimum_size().y - _scroll.get_combined_minimum_size().y))
|
||||
|
||||
|
||||
## Fits again once this frame's changes are in (rows rewritten, the screen changed size).
|
||||
func _queue_fit() -> void:
|
||||
if _fit_queued or not is_open:
|
||||
return
|
||||
_fit_queued = true
|
||||
_refit.call_deferred()
|
||||
|
||||
|
||||
func _refit() -> void:
|
||||
_fit_queued = false
|
||||
if is_open:
|
||||
_fit()
|
||||
|
||||
|
||||
## Rewrites every row for what's owned and affordable now.
|
||||
func refresh() -> void:
|
||||
var cfg := campaign.config
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue