#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:
Forrest 2026-10-14 15:28:25 -04:00
parent 5392ae09af
commit e8729b41e8
6 changed files with 835 additions and 34 deletions

View file

@ -9,6 +9,10 @@ extends CenterContainer
## Each row has its icon; a type or material with none isn't listed. "Start the day" (focused,
## so Enter / A work) ends it. The first morning explains the vacation instead of results. It
## stays down while the opening intro has the farm (intro.running).
## On a phone (UiTheme's panels) the sign stands in the safe area: the paper's text scrolls
## (drag it) and Start the day stays below it, in view and at least the touch target tall; the
## text is narrower if need be, and in a room shorter than TIGHT (a phone's, not an iPad's) the
## paper's margins and the posts' tops are a little shorter.
const CATEGORIES := ["Crops", "Animals", "Supplies"]
const ENEMY_TYPES := [EnemySystem.TYPE_CROW, EnemySystem.TYPE_THIEF, EnemySystem.TYPE_BREAKER, EnemySystem.TYPE_UFO]
@ -18,13 +22,38 @@ const SIDE := 64.0
const BEAM := 92.0
const BOTTOM := 70.0
const WIDTH := 880.0
## The paper's margins around its text: either side, above, and below (PHONE_SHEET in a tight
## room, below).
const SHEET_SIDE := 48
const SHEET := Vector2i(26, 32)
const PHONE_SHEET := Vector2i(14, 16)
const START := Vector2(300.0, 62.0)
## How far the drawing reaches past the board: the top beam's ends either side (24, and their
## end grain), the posts above the top beam (POST_TOP, PHONE_POST_TOP in a tight room; their end
## grain END_GRAIN more), and the posts' feet below the board (into the ground: on a phone they
## may run past the safe area).
const BEAM_END := 40.0
const POST_TOP := 36.0
const PHONE_POST_TOP := 16.0
const END_GRAIN := 10.0
const FEET := 52.0
## A phone's room is shorter than this (an iPad's isn't): the paper's margins and the posts' tops
## shrink to give the text more of it.
const TIGHT := 1000.0
var campaign: CampaignController
## Set by FarmSim: the night plans (last night's title), and the opening intro.
var waves: WaveDirector
var intro: OpeningIntro
var _safe: MarginContainer
var _board: PanelContainer
var _sheet: MarginContainer
var _scroll: UiTheme.TouchScroll
var _box: VBoxContainer
var _start_gap: Control
var _post_top := POST_TOP
var _fit_queued := false
var _title: Label
var _last_head: Label
var _rule: HSeparator
@ -48,6 +77,8 @@ func setup(p_campaign: CampaignController) -> void:
func _ready() -> void:
set_anchors_preset(Control.PRESET_FULL_RECT)
theme = UiTheme.sketch()
_safe = MarginContainer.new() # the safe area's margins on a phone (none on desktop)
add_child(_safe)
_board = PanelContainer.new()
var margins := StyleBoxEmpty.new()
margins.content_margin_left = SIDE
@ -55,7 +86,7 @@ func _ready() -> void:
margins.content_margin_bottom = BOTTOM
_board.add_theme_stylebox_override("panel", margins)
_board.draw.connect(_draw_board)
add_child(_board)
_safe.add_child(_board)
var column := VBoxContainer.new()
column.add_theme_constant_override("separation", 0)
_board.add_child(column)
@ -65,16 +96,23 @@ func _ready() -> void:
_title.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
_title.custom_minimum_size = Vector2(0.0, BEAM)
column.add_child(_title)
var sheet := MarginContainer.new()
_sheet = MarginContainer.new()
for side: String in ["left", "right"]:
sheet.add_theme_constant_override("margin_" + side, 48)
sheet.add_theme_constant_override("margin_top", 26)
sheet.add_theme_constant_override("margin_bottom", 32)
column.add_child(sheet)
_sheet.add_theme_constant_override("margin_" + side, SHEET_SIDE)
_sheet.add_theme_constant_override("margin_top", SHEET.x)
_sheet.add_theme_constant_override("margin_bottom", SHEET.y)
column.add_child(_sheet)
var page := VBoxContainer.new() # the paper: its text (scrolling on a phone), then Start the day
page.add_theme_constant_override("separation", 10)
_sheet.add_child(page)
_scroll = UiTheme.TouchScroll.new(Sketch.PAPER_INK)
page.add_child(_scroll)
var box := VBoxContainer.new()
box.custom_minimum_size = Vector2(WIDTH, 0.0)
box.size_flags_horizontal = Control.SIZE_EXPAND_FILL
box.add_theme_constant_override("separation", 10)
sheet.add_child(box)
_scroll.add_child(box)
_box = box
_last_head = _ink(box, 38)
_last_head.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
_rule = HSeparator.new()
@ -124,7 +162,7 @@ func _ready() -> void:
_intro.add_theme_constant_override("paragraph_spacing", 14)
_start = Button.new()
_start.text = "Start the day"
_start.custom_minimum_size = Vector2(300.0, 62.0)
_start.custom_minimum_size = START
_start.add_theme_font_size_override("font_size", 32)
_start.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
var wood := {
@ -135,9 +173,12 @@ func _ready() -> void:
for key: String in wood:
_start.add_theme_stylebox_override(key, wood[key])
_start.pressed.connect(func() -> void: campaign.begin_day())
box.add_child(_spacer(6.0))
box.add_child(_start)
_start_gap = _spacer(6.0)
page.add_child(_start_gap)
page.add_child(_start)
visible = false
box.minimum_size_changed.connect(_queue_fit) # the text reflowed (a new width, new results)
get_viewport().size_changed.connect(_queue_fit)
## The dark, nearly opaque panel behind the menus and the end screens.
@ -178,10 +219,53 @@ func refresh() -> void:
_fill_grid(e)
_fill_list(_enemies, _no_enemies, func(t: int) -> int: return int(e.get("killed_" + EnemySystem.TYPE_NAMES[t], 0)))
_fill_list(_materials, _no_materials, func(m: String) -> int: return int(e.get("gathered_" + m, 0)))
_fit()
_scroll.scroll_vertical = 0 # each morning's sheet from its top
_board.queue_redraw()
_focus_start.call_deferred()
## Lays the sign out for the screen: on desktop as it always was; on a phone (UiTheme's panels)
## inside the safe area (its posts' tops and its top beam's ends too), as wide as that allows up
## to WIDTH, with the paper's text scrolling past what the height leaves for it.
func _fit() -> void:
var phone := MobilePort.active()
var room := UiTheme.panel_room(self) if phone else Rect2()
var tight := phone and room.size.y < TIGHT
_scroll.set_phone(phone)
_post_top = PHONE_POST_TOP if tight else POST_TOP
var sheet := PHONE_SHEET if tight else SHEET
UiTheme.set_constant(_sheet, "margin_top", sheet.x)
UiTheme.set_constant(_sheet, "margin_bottom", sheet.y)
_start_gap.visible = not tight
_start.custom_minimum_size = Vector2(START.x, maxf(START.y, MobilePort.minimum_target(self))) if phone else START
if not phone:
UiTheme.fit_margins(_safe, Rect2())
_box.custom_minimum_size.x = WIDTH
return
var top := _post_top + END_GRAIN
UiTheme.fit_margins(_safe, room, Vector4(BEAM_END, top, BEAM_END, 0.0))
var frame := 2.0 * (BEAM_END + SIDE + SHEET_SIDE) + _scroll.frame_width()
_box.custom_minimum_size.x = floorf(minf(WIDTH, room.size.x - frame))
var others := _board.get_combined_minimum_size().y - _scroll.get_combined_minimum_size().y
_scroll.fit(room.size.y - top - others)
_board.queue_redraw()
## Fits again once this frame's changes are in (the text reflowed, the screen changed size).
func _queue_fit() -> void:
if _fit_queued or not visible:
return
_fit_queued = true
_refit.call_deferred()
func _refit() -> void:
_fit_queued = false
if visible:
_fit()
## Start the day takes the focus (unless the sign went down again meanwhile: a hidden button
## would still take Enter).
func _focus_start() -> void:
@ -289,9 +373,10 @@ func _draw_board() -> void:
var h := b.size.y
var paper := Rect2(SIDE - 14.0, BEAM - 26.0, w - 2.0 * SIDE + 28.0, h - BEAM - BOTTOM + 52.0)
var posts: Array[float] = [SIDE + 34.0, w - SIDE - 34.0]
var reach := _post_top + h + FEET # a post's length, from its top to its feet
for k in 2:
b.draw_set_transform(Vector2(posts[k], h * 0.5 + 8.0), PI * 0.5)
Sketch.plank(b, Rect2(-h * 0.5 - 44.0, -27.0, h + 88.0, 54.0), Sketch.WOOD.darkened(0.08), 601.0 + k)
b.draw_set_transform(Vector2(posts[k], (h + FEET - _post_top) * 0.5), PI * 0.5)
Sketch.plank(b, Rect2(-reach * 0.5, -27.0, reach, 54.0), Sketch.WOOD.darkened(0.08), 601.0 + k)
b.draw_set_transform_matrix(Transform2D.IDENTITY)
Sketch.paper(b, paper, 611.0)
Sketch.plank(b, Rect2(0.0, h - BOTTOM - 4.0, w, 62.0), Sketch.WOOD.darkened(0.04), 621.0)