#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
|
|
@ -10,12 +10,19 @@ extends CenterContainer
|
|||
## * The final assessment, once the farmers' return (FarmersReturn) has played or been
|
||||
## skipped: the rating and score (Assessment), the share kept per category with a bar, and
|
||||
## the vacation's totals, with Main menu (or New vacation).
|
||||
## On a phone (UiTheme's panels) it sits in the safe area: the text wraps to the room's width
|
||||
## (up to PHONE_WIDTH), scrolls (drag it) if it's still too tall, and the buttons stay below it,
|
||||
## in view and at least the touch target tall.
|
||||
|
||||
signal menu_requested
|
||||
|
||||
const DELAY := 1.4
|
||||
const GOLD := Color(0.95, 0.82, 0.45)
|
||||
const GREY := Color(0.75, 0.77, 0.72)
|
||||
const MARGIN := 34
|
||||
const BUTTON := Vector2(230.0, 56.0)
|
||||
## The text's widest on a phone (an iPad's room is wider): about the totals' longest line.
|
||||
const PHONE_WIDTH := 1180.0
|
||||
|
||||
var campaign: CampaignController
|
||||
## Set by Main: the Main menu button shows instead of New vacation.
|
||||
|
|
@ -37,6 +44,11 @@ var _menu: Button
|
|||
var _new: Button
|
||||
var _wait: float = -1.0
|
||||
var _pending_mode := ""
|
||||
var _safe: MarginContainer
|
||||
var _panel: PanelContainer
|
||||
var _scroll: UiTheme.TouchScroll
|
||||
var _box: VBoxContainer
|
||||
var _fit_queued := false
|
||||
|
||||
|
||||
func setup(p_campaign: CampaignController) -> void:
|
||||
|
|
@ -49,16 +61,25 @@ func setup(p_campaign: CampaignController) -> void:
|
|||
|
||||
func _ready() -> void:
|
||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
var panel := PanelContainer.new()
|
||||
panel.add_theme_stylebox_override("panel", ReviewPanel.backing())
|
||||
add_child(panel)
|
||||
_safe = MarginContainer.new() # the safe area's margins on a phone (none on desktop)
|
||||
add_child(_safe)
|
||||
_panel = PanelContainer.new()
|
||||
_panel.add_theme_stylebox_override("panel", ReviewPanel.backing())
|
||||
_safe.add_child(_panel)
|
||||
var margin := MarginContainer.new()
|
||||
for side in ["left", "right", "top", "bottom"]:
|
||||
margin.add_theme_constant_override("margin_" + side, 34)
|
||||
panel.add_child(margin)
|
||||
margin.add_theme_constant_override("margin_" + side, MARGIN)
|
||||
_panel.add_child(margin)
|
||||
var page := VBoxContainer.new() # the text (scrolling on a phone), then the buttons
|
||||
page.add_theme_constant_override("separation", 16)
|
||||
margin.add_child(page)
|
||||
_scroll = UiTheme.TouchScroll.new(UiTheme.TEXT)
|
||||
page.add_child(_scroll)
|
||||
var box := VBoxContainer.new()
|
||||
box.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
box.add_theme_constant_override("separation", 16)
|
||||
margin.add_child(box)
|
||||
_scroll.add_child(box)
|
||||
_box = box
|
||||
_title = _label(box, 46)
|
||||
_rating = _label(box, 30, GOLD)
|
||||
_detail = _label(box, 22)
|
||||
|
|
@ -92,7 +113,7 @@ func _ready() -> void:
|
|||
var buttons := HBoxContainer.new()
|
||||
buttons.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
buttons.add_theme_constant_override("separation", 24)
|
||||
box.add_child(buttons)
|
||||
page.add_child(buttons)
|
||||
_retry = _button(buttons, "Retry the night")
|
||||
_retry.pressed.connect(func() -> void: campaign.retry_night())
|
||||
_menu = _button(buttons, "Main menu")
|
||||
|
|
@ -100,6 +121,8 @@ func _ready() -> void:
|
|||
_new = _button(buttons, "New vacation")
|
||||
_new.pressed.connect(func() -> void: campaign.new_campaign())
|
||||
hide_panel()
|
||||
box.minimum_size_changed.connect(_queue_fit) # the text reflowed
|
||||
get_viewport().size_changed.connect(_queue_fit)
|
||||
|
||||
|
||||
func hide_panel() -> void:
|
||||
|
|
@ -230,9 +253,46 @@ func _show_buttons() -> void:
|
|||
func _open(focus: Button) -> void:
|
||||
visible = true
|
||||
mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
_fit()
|
||||
_scroll.scroll_vertical = 0
|
||||
focus.grab_focus()
|
||||
|
||||
|
||||
## Lays the screen out: on desktop as it always was; on a phone (UiTheme's panels) inside the
|
||||
## safe area, the text wrapped to the room's width and scrolling past what its height leaves.
|
||||
func _fit() -> void:
|
||||
var phone := MobilePort.active()
|
||||
_scroll.set_phone(phone)
|
||||
for l: Label in [_title, _rating, _detail, _stats]:
|
||||
l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART if phone else TextServer.AUTOWRAP_OFF
|
||||
for b: Button in [_retry, _menu, _new]:
|
||||
b.custom_minimum_size = Vector2(BUTTON.x, maxf(BUTTON.y, MobilePort.minimum_target(self))) if phone else BUTTON
|
||||
if not phone:
|
||||
UiTheme.fit_margins(_safe, Rect2())
|
||||
_box.custom_minimum_size.x = 0.0
|
||||
return
|
||||
var room := UiTheme.panel_room(self)
|
||||
UiTheme.fit_margins(_safe, room)
|
||||
var frame := 2.0 * MARGIN + _panel.get_theme_stylebox("panel").get_minimum_size().x + _scroll.frame_width()
|
||||
_box.custom_minimum_size.x = floorf(minf(PHONE_WIDTH, room.size.x - frame))
|
||||
var others := _panel.get_combined_minimum_size().y - _scroll.get_combined_minimum_size().y
|
||||
_scroll.fit(room.size.y - others)
|
||||
|
||||
|
||||
## 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()
|
||||
|
||||
|
||||
func _label(parent: Node, font_size: int, color: Color = Color(0.92, 0.92, 0.88)) -> Label:
|
||||
var l := Label.new()
|
||||
l.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
|
|
@ -245,7 +305,7 @@ func _label(parent: Node, font_size: int, color: Color = Color(0.92, 0.92, 0.88)
|
|||
func _button(parent: Control, text: String) -> Button:
|
||||
var b := Button.new()
|
||||
b.text = text
|
||||
b.custom_minimum_size = Vector2(230.0, 56.0)
|
||||
b.custom_minimum_size = BUTTON
|
||||
b.add_theme_font_size_override("font_size", 24)
|
||||
parent.add_child(b)
|
||||
return b
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue