#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
|
## * 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
|
## 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).
|
## 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
|
signal menu_requested
|
||||||
|
|
||||||
const DELAY := 1.4
|
const DELAY := 1.4
|
||||||
const GOLD := Color(0.95, 0.82, 0.45)
|
const GOLD := Color(0.95, 0.82, 0.45)
|
||||||
const GREY := Color(0.75, 0.77, 0.72)
|
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
|
var campaign: CampaignController
|
||||||
## Set by Main: the Main menu button shows instead of New vacation.
|
## Set by Main: the Main menu button shows instead of New vacation.
|
||||||
|
|
@ -37,6 +44,11 @@ var _menu: Button
|
||||||
var _new: Button
|
var _new: Button
|
||||||
var _wait: float = -1.0
|
var _wait: float = -1.0
|
||||||
var _pending_mode := ""
|
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:
|
func setup(p_campaign: CampaignController) -> void:
|
||||||
|
|
@ -49,16 +61,25 @@ func setup(p_campaign: CampaignController) -> void:
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||||
var panel := PanelContainer.new()
|
_safe = MarginContainer.new() # the safe area's margins on a phone (none on desktop)
|
||||||
panel.add_theme_stylebox_override("panel", ReviewPanel.backing())
|
add_child(_safe)
|
||||||
add_child(panel)
|
_panel = PanelContainer.new()
|
||||||
|
_panel.add_theme_stylebox_override("panel", ReviewPanel.backing())
|
||||||
|
_safe.add_child(_panel)
|
||||||
var margin := MarginContainer.new()
|
var margin := MarginContainer.new()
|
||||||
for side in ["left", "right", "top", "bottom"]:
|
for side in ["left", "right", "top", "bottom"]:
|
||||||
margin.add_theme_constant_override("margin_" + side, 34)
|
margin.add_theme_constant_override("margin_" + side, MARGIN)
|
||||||
panel.add_child(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()
|
var box := VBoxContainer.new()
|
||||||
|
box.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||||
box.add_theme_constant_override("separation", 16)
|
box.add_theme_constant_override("separation", 16)
|
||||||
margin.add_child(box)
|
_scroll.add_child(box)
|
||||||
|
_box = box
|
||||||
_title = _label(box, 46)
|
_title = _label(box, 46)
|
||||||
_rating = _label(box, 30, GOLD)
|
_rating = _label(box, 30, GOLD)
|
||||||
_detail = _label(box, 22)
|
_detail = _label(box, 22)
|
||||||
|
|
@ -92,7 +113,7 @@ func _ready() -> void:
|
||||||
var buttons := HBoxContainer.new()
|
var buttons := HBoxContainer.new()
|
||||||
buttons.alignment = BoxContainer.ALIGNMENT_CENTER
|
buttons.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||||
buttons.add_theme_constant_override("separation", 24)
|
buttons.add_theme_constant_override("separation", 24)
|
||||||
box.add_child(buttons)
|
page.add_child(buttons)
|
||||||
_retry = _button(buttons, "Retry the night")
|
_retry = _button(buttons, "Retry the night")
|
||||||
_retry.pressed.connect(func() -> void: campaign.retry_night())
|
_retry.pressed.connect(func() -> void: campaign.retry_night())
|
||||||
_menu = _button(buttons, "Main menu")
|
_menu = _button(buttons, "Main menu")
|
||||||
|
|
@ -100,6 +121,8 @@ func _ready() -> void:
|
||||||
_new = _button(buttons, "New vacation")
|
_new = _button(buttons, "New vacation")
|
||||||
_new.pressed.connect(func() -> void: campaign.new_campaign())
|
_new.pressed.connect(func() -> void: campaign.new_campaign())
|
||||||
hide_panel()
|
hide_panel()
|
||||||
|
box.minimum_size_changed.connect(_queue_fit) # the text reflowed
|
||||||
|
get_viewport().size_changed.connect(_queue_fit)
|
||||||
|
|
||||||
|
|
||||||
func hide_panel() -> void:
|
func hide_panel() -> void:
|
||||||
|
|
@ -230,9 +253,46 @@ func _show_buttons() -> void:
|
||||||
func _open(focus: Button) -> void:
|
func _open(focus: Button) -> void:
|
||||||
visible = true
|
visible = true
|
||||||
mouse_filter = Control.MOUSE_FILTER_STOP
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
||||||
|
_fit()
|
||||||
|
_scroll.scroll_vertical = 0
|
||||||
focus.grab_focus()
|
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:
|
func _label(parent: Node, font_size: int, color: Color = Color(0.92, 0.92, 0.88)) -> Label:
|
||||||
var l := Label.new()
|
var l := Label.new()
|
||||||
l.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
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:
|
func _button(parent: Control, text: String) -> Button:
|
||||||
var b := Button.new()
|
var b := Button.new()
|
||||||
b.text = text
|
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)
|
b.add_theme_font_size_override("font_size", 24)
|
||||||
parent.add_child(b)
|
parent.add_child(b)
|
||||||
return b
|
return b
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ extends CenterContainer
|
||||||
## Each row has its icon; a type or material with none isn't listed. "Start the day" (focused,
|
## 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
|
## 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).
|
## 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 CATEGORIES := ["Crops", "Animals", "Supplies"]
|
||||||
const ENEMY_TYPES := [EnemySystem.TYPE_CROW, EnemySystem.TYPE_THIEF, EnemySystem.TYPE_BREAKER, EnemySystem.TYPE_UFO]
|
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 BEAM := 92.0
|
||||||
const BOTTOM := 70.0
|
const BOTTOM := 70.0
|
||||||
const WIDTH := 880.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
|
var campaign: CampaignController
|
||||||
## Set by FarmSim: the night plans (last night's title), and the opening intro.
|
## Set by FarmSim: the night plans (last night's title), and the opening intro.
|
||||||
var waves: WaveDirector
|
var waves: WaveDirector
|
||||||
var intro: OpeningIntro
|
var intro: OpeningIntro
|
||||||
|
|
||||||
|
var _safe: MarginContainer
|
||||||
var _board: PanelContainer
|
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 _title: Label
|
||||||
var _last_head: Label
|
var _last_head: Label
|
||||||
var _rule: HSeparator
|
var _rule: HSeparator
|
||||||
|
|
@ -48,6 +77,8 @@ func setup(p_campaign: CampaignController) -> void:
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||||
theme = UiTheme.sketch()
|
theme = UiTheme.sketch()
|
||||||
|
_safe = MarginContainer.new() # the safe area's margins on a phone (none on desktop)
|
||||||
|
add_child(_safe)
|
||||||
_board = PanelContainer.new()
|
_board = PanelContainer.new()
|
||||||
var margins := StyleBoxEmpty.new()
|
var margins := StyleBoxEmpty.new()
|
||||||
margins.content_margin_left = SIDE
|
margins.content_margin_left = SIDE
|
||||||
|
|
@ -55,7 +86,7 @@ func _ready() -> void:
|
||||||
margins.content_margin_bottom = BOTTOM
|
margins.content_margin_bottom = BOTTOM
|
||||||
_board.add_theme_stylebox_override("panel", margins)
|
_board.add_theme_stylebox_override("panel", margins)
|
||||||
_board.draw.connect(_draw_board)
|
_board.draw.connect(_draw_board)
|
||||||
add_child(_board)
|
_safe.add_child(_board)
|
||||||
var column := VBoxContainer.new()
|
var column := VBoxContainer.new()
|
||||||
column.add_theme_constant_override("separation", 0)
|
column.add_theme_constant_override("separation", 0)
|
||||||
_board.add_child(column)
|
_board.add_child(column)
|
||||||
|
|
@ -65,16 +96,23 @@ func _ready() -> void:
|
||||||
_title.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
_title.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||||
_title.custom_minimum_size = Vector2(0.0, BEAM)
|
_title.custom_minimum_size = Vector2(0.0, BEAM)
|
||||||
column.add_child(_title)
|
column.add_child(_title)
|
||||||
var sheet := MarginContainer.new()
|
_sheet = MarginContainer.new()
|
||||||
for side: String in ["left", "right"]:
|
for side: String in ["left", "right"]:
|
||||||
sheet.add_theme_constant_override("margin_" + side, 48)
|
_sheet.add_theme_constant_override("margin_" + side, SHEET_SIDE)
|
||||||
sheet.add_theme_constant_override("margin_top", 26)
|
_sheet.add_theme_constant_override("margin_top", SHEET.x)
|
||||||
sheet.add_theme_constant_override("margin_bottom", 32)
|
_sheet.add_theme_constant_override("margin_bottom", SHEET.y)
|
||||||
column.add_child(sheet)
|
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()
|
var box := VBoxContainer.new()
|
||||||
box.custom_minimum_size = Vector2(WIDTH, 0.0)
|
box.custom_minimum_size = Vector2(WIDTH, 0.0)
|
||||||
|
box.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||||
box.add_theme_constant_override("separation", 10)
|
box.add_theme_constant_override("separation", 10)
|
||||||
sheet.add_child(box)
|
_scroll.add_child(box)
|
||||||
|
_box = box
|
||||||
_last_head = _ink(box, 38)
|
_last_head = _ink(box, 38)
|
||||||
_last_head.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
_last_head.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||||
_rule = HSeparator.new()
|
_rule = HSeparator.new()
|
||||||
|
|
@ -124,7 +162,7 @@ func _ready() -> void:
|
||||||
_intro.add_theme_constant_override("paragraph_spacing", 14)
|
_intro.add_theme_constant_override("paragraph_spacing", 14)
|
||||||
_start = Button.new()
|
_start = Button.new()
|
||||||
_start.text = "Start the day"
|
_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.add_theme_font_size_override("font_size", 32)
|
||||||
_start.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
|
_start.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
|
||||||
var wood := {
|
var wood := {
|
||||||
|
|
@ -135,9 +173,12 @@ func _ready() -> void:
|
||||||
for key: String in wood:
|
for key: String in wood:
|
||||||
_start.add_theme_stylebox_override(key, wood[key])
|
_start.add_theme_stylebox_override(key, wood[key])
|
||||||
_start.pressed.connect(func() -> void: campaign.begin_day())
|
_start.pressed.connect(func() -> void: campaign.begin_day())
|
||||||
box.add_child(_spacer(6.0))
|
_start_gap = _spacer(6.0)
|
||||||
box.add_child(_start)
|
page.add_child(_start_gap)
|
||||||
|
page.add_child(_start)
|
||||||
visible = false
|
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.
|
## The dark, nearly opaque panel behind the menus and the end screens.
|
||||||
|
|
@ -178,10 +219,53 @@ func refresh() -> void:
|
||||||
_fill_grid(e)
|
_fill_grid(e)
|
||||||
_fill_list(_enemies, _no_enemies, func(t: int) -> int: return int(e.get("killed_" + EnemySystem.TYPE_NAMES[t], 0)))
|
_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)))
|
_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()
|
_board.queue_redraw()
|
||||||
_focus_start.call_deferred()
|
_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
|
## Start the day takes the focus (unless the sign went down again meanwhile: a hidden button
|
||||||
## would still take Enter).
|
## would still take Enter).
|
||||||
func _focus_start() -> void:
|
func _focus_start() -> void:
|
||||||
|
|
@ -289,9 +373,10 @@ func _draw_board() -> void:
|
||||||
var h := b.size.y
|
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 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 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:
|
for k in 2:
|
||||||
b.draw_set_transform(Vector2(posts[k], h * 0.5 + 8.0), PI * 0.5)
|
b.draw_set_transform(Vector2(posts[k], (h + FEET - _post_top) * 0.5), 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)
|
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)
|
b.draw_set_transform_matrix(Transform2D.IDENTITY)
|
||||||
Sketch.paper(b, paper, 611.0)
|
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)
|
Sketch.plank(b, Rect2(0.0, h - BOTTOM - 4.0, w, 62.0), Sketch.WOOD.darkened(0.04), 621.0)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ extends RefCounted
|
||||||
## boxes, and tabs to match. Labels keep the default look; the HUD sets its own sizes.
|
## boxes, and tabs to match. Labels keep the default look; the HUD sets its own sizes.
|
||||||
## sketch() is the hand-drawn theme the in-game panels use instead (the pause menu and its
|
## sketch() is the hand-drawn theme the in-game panels use instead (the pause menu and its
|
||||||
## questions, the workbench and shed shops), to match the HUD's pouch panel (Sketch).
|
## questions, the workbench and shed shops), to match the HUD's pouch panel (Sketch).
|
||||||
|
## The panels' phone layout (panel_room, fit_margins, TouchScroll) is at the end.
|
||||||
|
|
||||||
const TEXT := Color(0.95, 0.93, 0.85)
|
const TEXT := Color(0.95, 0.93, 0.85)
|
||||||
const GOLD := Color(0.95, 0.82, 0.45)
|
const GOLD := Color(0.95, 0.82, 0.45)
|
||||||
|
|
@ -174,3 +175,177 @@ static func _box(bg: Color, border: Color, width: int) -> StyleBoxFlat:
|
||||||
s.content_margin_top = 8.0
|
s.content_margin_top = 8.0
|
||||||
s.content_margin_bottom = 8.0
|
s.content_margin_bottom = 8.0
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
## --- Panels on a phone (#42) ---
|
||||||
|
## The morning sign (ReviewPanel), the end screens (EndPanel), and the workbench's and the shed's
|
||||||
|
## shops (UpgradePanel) on a phone (MobilePort.active(); at any interface scale, iPads too):
|
||||||
|
## * each sits in panel_room(), the safe area (MobilePort.safe_rect) less PANEL_GAP, through
|
||||||
|
## fit_margins() on a MarginContainer between the panel and its full-screen CenterContainer
|
||||||
|
## (which still dims and blocks the whole screen);
|
||||||
|
## * its long part is a TouchScroll at most as tall as the room leaves, with its buttons below
|
||||||
|
## it, always in view; long lines wrap to the room's width;
|
||||||
|
## * its buttons and rows are at least MobilePort.minimum_target() tall.
|
||||||
|
## On desktop the margins are 0 and a TouchScroll is a plain box, so each is laid out as before.
|
||||||
|
|
||||||
|
const PANEL_GAP := 8.0
|
||||||
|
|
||||||
|
|
||||||
|
## Where a panel goes on a phone: the safe rect less PANEL_GAP on every side, in ci's canvas.
|
||||||
|
static func panel_room(ci: CanvasItem) -> Rect2:
|
||||||
|
return MobilePort.safe_rect(ci).grow(-PANEL_GAP)
|
||||||
|
|
||||||
|
|
||||||
|
## Puts the panel inside `wrap` (a MarginContainer, the only child of a full-screen
|
||||||
|
## CenterContainer) in `room` (canvas coordinates): margins out to the room's edges, plus
|
||||||
|
## `extra` (left, top, right, bottom) kept clear for drawing past the panel's rect. An empty
|
||||||
|
## room (desktop) is no margins at all.
|
||||||
|
static func fit_margins(wrap: MarginContainer, room: Rect2, extra: Vector4 = Vector4.ZERO) -> void:
|
||||||
|
var m := Vector4.ZERO
|
||||||
|
if room.has_area():
|
||||||
|
var full := (wrap.get_parent() as Control).get_global_rect()
|
||||||
|
m = Vector4(room.position.x - full.position.x, room.position.y - full.position.y,
|
||||||
|
full.end.x - room.end.x, full.end.y - room.end.y) + extra
|
||||||
|
var sides: Array[String] = ["left", "top", "right", "bottom"]
|
||||||
|
for i in 4:
|
||||||
|
set_constant(wrap, "margin_" + sides[i], maxi(ceili(m[i] - 0.001), 0))
|
||||||
|
|
||||||
|
|
||||||
|
## A theme constant override, set only when it changes (each set lays the control out again).
|
||||||
|
static func set_constant(c: Control, constant: String, value: int) -> void:
|
||||||
|
if c.get_theme_constant(constant) != value:
|
||||||
|
c.add_theme_constant_override(constant, value)
|
||||||
|
|
||||||
|
|
||||||
|
## A panel's long part (its only child is the content). On desktop (set_phone(false), the
|
||||||
|
## default) it's a plain box as tall as its content: no scrolling, no clipping, no bar. On a
|
||||||
|
## phone (set_phone(true)) fit() makes it at most as tall as the panel's room leaves; past that
|
||||||
|
## it scrolls, with a thin bar, and a finger drags it: a press inside it that moves DRAG_PT
|
||||||
|
## points (about Apple's touch slop) scrolls with the finger, and the button it started on lets
|
||||||
|
## go (NOTIFICATION_SCROLL_BEGIN), so lifting the finger presses (buys) nothing; a press that
|
||||||
|
## doesn't move that far is a tap for whatever's under it. Godot's own touch dragging (only on a
|
||||||
|
## real touchscreen, and only from between the buttons) is off, so a phone, the desktop
|
||||||
|
## preview, and the tests all take this one path. To check on a device: the slop feels right;
|
||||||
|
## there's no fling (the list stops when the finger lifts).
|
||||||
|
class TouchScroll extends ScrollContainer:
|
||||||
|
const DRAG_PT := 10.0
|
||||||
|
|
||||||
|
## The press under way has turned into a scroll.
|
||||||
|
var dragging := false
|
||||||
|
var _bar: Color
|
||||||
|
var _pad: float
|
||||||
|
var _finger := -1
|
||||||
|
var _moved := Vector2.ZERO
|
||||||
|
|
||||||
|
## bar: the scroll bar's colour; pad: room kept clear around the content on a phone (where
|
||||||
|
## it clips), for its buttons' focus frames.
|
||||||
|
func _init(bar: Color, pad: float = 0.0) -> void:
|
||||||
|
_bar = bar
|
||||||
|
_pad = pad
|
||||||
|
horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||||
|
scroll_deadzone = 1 << 30 # Godot's own touch dragging never starts: _input does it
|
||||||
|
set_phone(false)
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
get_viewport().gui_focus_changed.connect(_on_focus)
|
||||||
|
|
||||||
|
func set_phone(on: bool) -> void:
|
||||||
|
vertical_scroll_mode = ScrollContainer.SCROLL_MODE_AUTO if on else ScrollContainer.SCROLL_MODE_DISABLED
|
||||||
|
clip_contents = on
|
||||||
|
if not on:
|
||||||
|
custom_minimum_size = Vector2.ZERO
|
||||||
|
remove_theme_stylebox_override("panel")
|
||||||
|
_finger = -1
|
||||||
|
dragging = false
|
||||||
|
return
|
||||||
|
if has_theme_stylebox_override("panel"):
|
||||||
|
return
|
||||||
|
var pad := StyleBoxEmpty.new()
|
||||||
|
pad.set_content_margin_all(_pad)
|
||||||
|
add_theme_stylebox_override("panel", pad)
|
||||||
|
var track := StyleBoxFlat.new()
|
||||||
|
track.bg_color = Color(_bar, 0.12)
|
||||||
|
track.set_corner_radius_all(4)
|
||||||
|
track.content_margin_left = 4.0
|
||||||
|
track.content_margin_right = 4.0
|
||||||
|
var grab := StyleBoxFlat.new()
|
||||||
|
grab.bg_color = Color(_bar, 0.5)
|
||||||
|
grab.set_corner_radius_all(4)
|
||||||
|
var lit := grab.duplicate() as StyleBoxFlat
|
||||||
|
lit.bg_color = Color(_bar, 0.75)
|
||||||
|
var v := get_v_scroll_bar()
|
||||||
|
for key: String in ["scroll", "scroll_focus"]:
|
||||||
|
v.add_theme_stylebox_override(key, track)
|
||||||
|
v.add_theme_stylebox_override("grabber", grab)
|
||||||
|
for key: String in ["grabber_highlight", "grabber_pressed"]:
|
||||||
|
v.add_theme_stylebox_override(key, lit)
|
||||||
|
|
||||||
|
## The width it adds around its content on a phone: the pad and the bar.
|
||||||
|
func frame_width() -> float:
|
||||||
|
return get_theme_stylebox("panel").get_minimum_size().x + get_v_scroll_bar().get_combined_minimum_size().x
|
||||||
|
|
||||||
|
## On a phone: as wide as its content and the bar, and as tall as its content up to `most`,
|
||||||
|
## past which it scrolls.
|
||||||
|
func fit(most: float) -> void:
|
||||||
|
if get_child_count() == 0:
|
||||||
|
return
|
||||||
|
var content := (get_child(0) as Control).get_combined_minimum_size()
|
||||||
|
var h := content.y + get_theme_stylebox("panel").get_minimum_size().y
|
||||||
|
custom_minimum_size = Vector2(content.x + frame_width(), h if h <= most else floorf(maxf(most, 0.0)))
|
||||||
|
|
||||||
|
## Whether there's more than it shows.
|
||||||
|
func scrolls() -> bool:
|
||||||
|
var v := get_v_scroll_bar()
|
||||||
|
return vertical_scroll_mode != ScrollContainer.SCROLL_MODE_DISABLED and v.max_value - v.page > 0.5
|
||||||
|
|
||||||
|
func _input(event: InputEvent) -> void:
|
||||||
|
var touch := event as InputEventScreenTouch
|
||||||
|
if touch != null:
|
||||||
|
if touch.pressed:
|
||||||
|
if _finger == -1 and is_visible_in_tree() and scrolls() and _grabs(touch.position):
|
||||||
|
_finger = touch.index
|
||||||
|
_moved = Vector2.ZERO
|
||||||
|
dragging = false
|
||||||
|
elif touch.index == _finger:
|
||||||
|
_finger = -1
|
||||||
|
if dragging:
|
||||||
|
dragging = false
|
||||||
|
scroll_ended.emit()
|
||||||
|
return
|
||||||
|
var drag := event as InputEventScreenDrag
|
||||||
|
if drag == null or drag.index != _finger:
|
||||||
|
return
|
||||||
|
if not is_visible_in_tree():
|
||||||
|
_finger = -1
|
||||||
|
dragging = false
|
||||||
|
return
|
||||||
|
var v := get_v_scroll_bar()
|
||||||
|
if not dragging:
|
||||||
|
_moved += drag.relative
|
||||||
|
if _moved.length() < DRAG_PT * MobilePort.minimum_target(self) / MobilePort.TARGET_PT:
|
||||||
|
return
|
||||||
|
dragging = true
|
||||||
|
propagate_notification(Control.NOTIFICATION_SCROLL_BEGIN) # the button under the finger lets go
|
||||||
|
scroll_started.emit()
|
||||||
|
v.value -= _moved.y
|
||||||
|
else:
|
||||||
|
v.value -= drag.relative.y
|
||||||
|
get_viewport().set_input_as_handled()
|
||||||
|
|
||||||
|
## On a phone, keys and a gamepad scroll the button they focus into view (once the layout's
|
||||||
|
## in); a finger's press doesn't (follow_focus would: the list would jump under it).
|
||||||
|
func _on_focus(c: Control) -> void:
|
||||||
|
if vertical_scroll_mode == ScrollContainer.SCROLL_MODE_DISABLED or Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) or not is_ancestor_of(c):
|
||||||
|
return
|
||||||
|
_follow.call_deferred(c.get_instance_id())
|
||||||
|
|
||||||
|
func _follow(id: int) -> void:
|
||||||
|
var c := instance_from_id(id) as Control
|
||||||
|
if c != null and c.has_focus() and is_ancestor_of(c):
|
||||||
|
ensure_control_visible(c)
|
||||||
|
|
||||||
|
## Whether a finger landing here (the viewport's canvas) drags it: inside it, off its bar.
|
||||||
|
func _grabs(at: Vector2) -> bool:
|
||||||
|
var local := get_global_transform_with_canvas().affine_inverse() * at
|
||||||
|
var v := get_v_scroll_bar()
|
||||||
|
return Rect2(Vector2.ZERO, size).has_point(local) and not (v.visible and v.get_rect().has_point(local))
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,22 @@ extends CenterContainer
|
||||||
## Escape / B, interact again, by walking off, or at nightfall. The scarecrow stands still and
|
## 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
|
## 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.
|
## 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);
|
## A purchase's result text. Nothing shows it on screen since #23 (the rows say what's missing);
|
||||||
## tests listen to it.
|
## tests listen to it.
|
||||||
signal message(text: String, color: Color)
|
signal message(text: String, color: Color)
|
||||||
signal bought(id: String)
|
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 campaign: CampaignController
|
||||||
var structures: StructureSystem
|
var structures: StructureSystem
|
||||||
var player: PlayerCharacter
|
var player: PlayerCharacter
|
||||||
|
|
@ -33,6 +43,11 @@ var slot: int = 0
|
||||||
var _rows := {} # upgrade id -> Button
|
var _rows := {} # upgrade id -> Button
|
||||||
var _title: Label
|
var _title: Label
|
||||||
var _close: Button
|
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:
|
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
|
structures = p_structures
|
||||||
player = p_player
|
player = p_player
|
||||||
shop = p_shop
|
shop = p_shop
|
||||||
var box := get_node("Panel/Margin/Box") as VBoxContainer
|
var box := _list
|
||||||
var track := ""
|
var track := ""
|
||||||
for id in Upgrades.ORDER:
|
for id in Upgrades.ORDER:
|
||||||
var u: Dictionary = campaign.config.upgrades.get(id, {})
|
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)
|
box.add_child(head)
|
||||||
var b := Button.new()
|
var b := Button.new()
|
||||||
b.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
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.add_theme_font_size_override("font_size", 25)
|
||||||
b.pressed.connect(func() -> void: _buy(id))
|
b.pressed.connect(func() -> void: _buy(id))
|
||||||
box.add_child(b)
|
box.add_child(b)
|
||||||
_rows[id] = 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:
|
func _ready() -> void:
|
||||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||||
theme = UiTheme.sketch()
|
theme = UiTheme.sketch()
|
||||||
var panel := PanelContainer.new()
|
_safe = MarginContainer.new() # the safe area's margins on a phone (none on desktop)
|
||||||
panel.name = "Panel"
|
_safe.name = "Safe"
|
||||||
add_child(panel)
|
add_child(_safe)
|
||||||
|
_panel = PanelContainer.new()
|
||||||
|
_panel.name = "Panel"
|
||||||
|
_safe.add_child(_panel)
|
||||||
var margin := MarginContainer.new()
|
var margin := MarginContainer.new()
|
||||||
margin.name = "Margin"
|
margin.name = "Margin"
|
||||||
for side in ["left", "right", "top", "bottom"]:
|
for side in ["left", "right", "top", "bottom"]:
|
||||||
margin.add_theme_constant_override("margin_" + side, 8)
|
margin.add_theme_constant_override("margin_" + side, MARGIN)
|
||||||
panel.add_child(margin)
|
_panel.add_child(margin)
|
||||||
var box := VBoxContainer.new()
|
var box := VBoxContainer.new()
|
||||||
box.name = "Box"
|
box.name = "Box"
|
||||||
box.add_theme_constant_override("separation", 6)
|
box.add_theme_constant_override("separation", 6)
|
||||||
|
|
@ -88,8 +99,24 @@ func _ready() -> void:
|
||||||
_title.add_theme_font_size_override("font_size", 36)
|
_title.add_theme_font_size_override("font_size", 36)
|
||||||
box.add_child(_title)
|
box.add_child(_title)
|
||||||
box.add_child(HSeparator.new())
|
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
|
visible = false
|
||||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
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:
|
func open() -> void:
|
||||||
|
|
@ -100,6 +127,8 @@ func open() -> void:
|
||||||
mouse_filter = Control.MOUSE_FILTER_STOP
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
||||||
player.start_channel(&"Idle_A")
|
player.start_channel(&"Idle_A")
|
||||||
refresh()
|
refresh()
|
||||||
|
_fit()
|
||||||
|
_scroll.scroll_vertical = 0
|
||||||
var first: Button = _close
|
var first: Button = _close
|
||||||
for id in Upgrades.ORDER:
|
for id in Upgrades.ORDER:
|
||||||
if _rows.has(id) and not (_rows[id] as Button).disabled:
|
if _rows.has(id) and not (_rows[id] as Button).disabled:
|
||||||
|
|
@ -117,6 +146,42 @@ func close() -> void:
|
||||||
player.stop_channel()
|
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.
|
## Rewrites every row for what's owned and affordable now.
|
||||||
func refresh() -> void:
|
func refresh() -> void:
|
||||||
var cfg := campaign.config
|
var cfg := campaign.config
|
||||||
|
|
|
||||||
415
game/tests/mobile/panels_test.gd
Normal file
415
game/tests/mobile/panels_test.gd
Normal file
|
|
@ -0,0 +1,415 @@
|
||||||
|
extends RefCounted
|
||||||
|
## #42: the panels at phone scale (UiTheme's panels), on the farm's HUD (farm.tscn) with
|
||||||
|
## MobilePort.forced:
|
||||||
|
## * Phones (PHONES): a 19.5:9 phone at about 1.6x with a notch and the home indicator inset; an
|
||||||
|
## iPhone SE at the 1.7 cap (1130x635); a 13 mini at the cap with its insets (the shortest
|
||||||
|
## room, about 600 tall); and a 4:3 iPad at 1x with an inset. On each, the morning sign (the
|
||||||
|
## first morning's, in touch words, and the longest later morning's review), the end screens
|
||||||
|
## (the failure and the final assessment, with the longest totals), and the workbench's and
|
||||||
|
## the shed's menus sit inside the safe rect (the sign's drawing too: its beam's ends and its
|
||||||
|
## posts' tops); Start the day, the end screens' buttons, and Close are in view below the
|
||||||
|
## scrolling part (no scrolling needed to reach them) and at least the touch target tall, as
|
||||||
|
## is every shop row; the end screens' text wraps to the panel; whatever doesn't fit scrolls,
|
||||||
|
## and scrolled to its end it's all there. The iPad's room needs no scrolling.
|
||||||
|
## * Fingers (the 19.5:9 phone): a drag on a shop's list scrolls it and buys nothing, even one
|
||||||
|
## that comes back to the row it started on; a tap on a row buys it, a little wobble still a
|
||||||
|
## tap; a drag on the sign scrolls it; Close closes.
|
||||||
|
## * Desktop (forced 0) at 1920x1080: every rect as it was before #42 (DESKTOP, recorded from the
|
||||||
|
## code before it), nothing scrolls or wraps, no safe-area margins.
|
||||||
|
|
||||||
|
const Touch := preload("res://game/tests/mobile/touch.gd")
|
||||||
|
|
||||||
|
## name, window pixels, density (0: by the window's shape), insets in window pixels (l, t, r, b).
|
||||||
|
const PHONES := [
|
||||||
|
["19.5:9 phone (1.6x), notch and home indicator", Vector2i(2340, 1080), 0.0, [140, 0, 140, 60]],
|
||||||
|
["iPhone SE (1.7x cap)", Vector2i(1334, 750), 326.0, []],
|
||||||
|
["iPhone 13 mini (1.7x cap), notch and home indicator", Vector2i(2340, 1080), 476.0, [140, 0, 140, 60]],
|
||||||
|
["4:3 iPad (1x), status bar and home indicator", Vector2i(1600, 1200), 0.0, [0, 40, 0, 40]],
|
||||||
|
]
|
||||||
|
## The desktop layout at 1920x1080 before #42 (position, size), with the content _later(),
|
||||||
|
## _failure(), _assessment(), and _fixed() give.
|
||||||
|
const DESKTOP := {
|
||||||
|
"sign, first morning": Rect2(408, 179, 1104, 721),
|
||||||
|
"sign, first morning: Start the day": Rect2(810, 736, 300, 62),
|
||||||
|
"sign, later morning": Rect2(408, 119, 1104, 841),
|
||||||
|
"sign, later morning: Start the day": Rect2(810, 796, 300, 62),
|
||||||
|
"sign, later morning: the results": Rect2(598, 315, 724, 202),
|
||||||
|
"sign, later morning: the lists": Rect2(520, 545, 880, 225),
|
||||||
|
"workbench": Rect2(373, 124, 1174, 831),
|
||||||
|
"workbench: first row": Rect2(407, 254, 1106, 46),
|
||||||
|
"workbench: last row": Rect2(407, 827, 1106, 46),
|
||||||
|
"workbench: Close": Rect2(860, 879, 200, 48),
|
||||||
|
"shed": Rect2(373, 237, 1174, 605),
|
||||||
|
"shed: first row": Rect2(407, 367, 1106, 46),
|
||||||
|
"shed: last row": Rect2(407, 714, 1106, 46),
|
||||||
|
"shed: Close": Rect2(860, 766, 200, 48),
|
||||||
|
"failure": Rect2(333, 265, 1254, 549),
|
||||||
|
"failure: Retry the night": Rect2(561, 722, 544, 56),
|
||||||
|
"failure: New vacation": Rect2(1129, 722, 230, 56),
|
||||||
|
"failure: totals": Rect2(369, 554, 1182, 152),
|
||||||
|
"assessment": Rect2(333, 235, 1254, 609),
|
||||||
|
"assessment: New vacation": Rect2(845, 752, 230, 56),
|
||||||
|
"assessment: totals": Rect2(369, 615, 1182, 121),
|
||||||
|
"assessment: shares kept": Rect2(511, 490, 898, 109),
|
||||||
|
}
|
||||||
|
## Every shop row's text for the desktop check (the real ones follow the tuning).
|
||||||
|
const FIXED_ROW := "Long-range defenses II — Turrets reach 15% farther (18 wood, 26 scrap) Need 16 wood, 24 scrap more"
|
||||||
|
const FIXED_TITLE := "Upgrades at the work area (0 of 10 done)"
|
||||||
|
|
||||||
|
var t
|
||||||
|
var farm: Node3D
|
||||||
|
var sim: FarmSim
|
||||||
|
|
||||||
|
|
||||||
|
func run(p_t) -> void:
|
||||||
|
t = p_t
|
||||||
|
var root: Window = t.root
|
||||||
|
MobilePort.forced = 0
|
||||||
|
root.size = Vector2i(1920, 1080)
|
||||||
|
GameSettings.new().apply_scale(root)
|
||||||
|
farm = (load("res://game/scenes/farm.tscn") as PackedScene).instantiate() as Node3D
|
||||||
|
root.add_child(farm)
|
||||||
|
await t.process_frame
|
||||||
|
await t.physics_frame
|
||||||
|
sim = farm.get_node("FarmSim") as FarmSim
|
||||||
|
sim.set_physics_process(false)
|
||||||
|
sim.waves.enabled = false
|
||||||
|
if sim.dialogue != null:
|
||||||
|
sim.dialogue.set_process(false) # no conversation over the panels
|
||||||
|
await _desktop()
|
||||||
|
MobilePort.forced = 1
|
||||||
|
for phone: Array in PHONES:
|
||||||
|
await _phone(phone)
|
||||||
|
await _fingers()
|
||||||
|
MobilePort.forced = -1
|
||||||
|
MobilePort.preview_dpi = 0.0
|
||||||
|
MobilePort.preview_insets = []
|
||||||
|
farm.queue_free()
|
||||||
|
await t.process_frame
|
||||||
|
|
||||||
|
|
||||||
|
func _settle() -> void:
|
||||||
|
for i in 3:
|
||||||
|
await t.process_frame
|
||||||
|
|
||||||
|
|
||||||
|
## Desktop: each panel exactly where and as big as before #42.
|
||||||
|
func _desktop() -> void:
|
||||||
|
var got := {}
|
||||||
|
var c := sim.campaign
|
||||||
|
var sign := sim.review_panel
|
||||||
|
c.new_campaign()
|
||||||
|
sign.refresh()
|
||||||
|
await _settle()
|
||||||
|
got["sign, first morning"] = sign._board.get_global_rect()
|
||||||
|
got["sign, first morning: Start the day"] = sign._start.get_global_rect()
|
||||||
|
_later(c)
|
||||||
|
sign.refresh()
|
||||||
|
await _settle()
|
||||||
|
got["sign, later morning"] = sign._board.get_global_rect()
|
||||||
|
got["sign, later morning: Start the day"] = sign._start.get_global_rect()
|
||||||
|
got["sign, later morning: the results"] = sign._grid.get_global_rect()
|
||||||
|
got["sign, later morning: the lists"] = sign._lists.get_global_rect()
|
||||||
|
t.check(sign._scroll.vertical_scroll_mode == ScrollContainer.SCROLL_MODE_DISABLED and not sign._scroll.clip_contents
|
||||||
|
and _margins(sign._safe) == Vector4.ZERO and sign._start_gap.visible, "desktop: the sign doesn't scroll and has no safe-area margins")
|
||||||
|
c.begin_day()
|
||||||
|
for p: Array in [[sim.upgrade_panel, "workbench"], [sim.shed_panel, "shed"]]:
|
||||||
|
var panel := p[0] as UpgradePanel
|
||||||
|
panel.open()
|
||||||
|
_fixed(panel)
|
||||||
|
await _settle()
|
||||||
|
var rows := panel._rows.values()
|
||||||
|
got[p[1]] = panel._panel.get_global_rect()
|
||||||
|
got[p[1] + ": first row"] = (rows[0] as Control).get_global_rect()
|
||||||
|
got[p[1] + ": last row"] = (rows[-1] as Control).get_global_rect()
|
||||||
|
got[p[1] + ": Close"] = panel._close.get_global_rect()
|
||||||
|
t.check(panel._scroll.vertical_scroll_mode == ScrollContainer.SCROLL_MODE_DISABLED and not panel._scroll.clip_contents
|
||||||
|
and _margins(panel._safe) == Vector4.ZERO and rows.all(func(b: Button) -> bool: return b.autowrap_mode == TextServer.AUTOWRAP_OFF),
|
||||||
|
"desktop: the %s's rows don't scroll or wrap" % p[1])
|
||||||
|
panel.close()
|
||||||
|
var end := sim.end_panel
|
||||||
|
_failure(c)
|
||||||
|
end.show_failure()
|
||||||
|
await _settle()
|
||||||
|
got["failure"] = end._panel.get_global_rect()
|
||||||
|
got["failure: Retry the night"] = end._retry.get_global_rect()
|
||||||
|
got["failure: New vacation"] = end._new.get_global_rect()
|
||||||
|
got["failure: totals"] = end._stats.get_global_rect()
|
||||||
|
t.check(end._stats.autowrap_mode == TextServer.AUTOWRAP_OFF and end._scroll.vertical_scroll_mode == ScrollContainer.SCROLL_MODE_DISABLED
|
||||||
|
and _margins(end._safe) == Vector4.ZERO, "desktop: the end screen's text doesn't wrap or scroll")
|
||||||
|
_assessment(c)
|
||||||
|
end.show_assessment()
|
||||||
|
await _settle()
|
||||||
|
got["assessment"] = end._panel.get_global_rect()
|
||||||
|
got["assessment: New vacation"] = end._new.get_global_rect()
|
||||||
|
got["assessment: totals"] = end._stats.get_global_rect()
|
||||||
|
got["assessment: shares kept"] = end._bars.get_global_rect()
|
||||||
|
end.hide_panel()
|
||||||
|
var moved: Array[String] = []
|
||||||
|
for k: String in DESKTOP:
|
||||||
|
var want: Rect2 = DESKTOP[k]
|
||||||
|
var r: Rect2 = got.get(k, Rect2())
|
||||||
|
if not (r.position.distance_to(want.position) < 0.5 and r.size.distance_to(want.size) < 0.5):
|
||||||
|
moved.append("%s: %s (was %s)" % [k, r, want])
|
||||||
|
t.check(moved.is_empty(), "desktop 1920x1080: all %d panel rects are as before %s" % [DESKTOP.size(), moved])
|
||||||
|
|
||||||
|
|
||||||
|
## One phone: every panel in its safe rect, the buttons in view and big enough, the rest scrolling.
|
||||||
|
func _phone(phone: Array) -> void:
|
||||||
|
var name: String = phone[0]
|
||||||
|
var root: Window = t.root
|
||||||
|
MobilePort.preview_dpi = phone[2]
|
||||||
|
MobilePort.preview_insets = phone[3]
|
||||||
|
root.size = phone[1]
|
||||||
|
GameSettings.new().apply_scale(root)
|
||||||
|
await _settle()
|
||||||
|
var safe := MobilePort.safe_rect(sim.review_panel)
|
||||||
|
var target := MobilePort.minimum_target(sim.review_panel)
|
||||||
|
var ipad := is_equal_approx(root.content_scale_factor, 1.0)
|
||||||
|
t.info("%s: canvas %s, safe rect %s, touch target %.0f" % [name, root.get_visible_rect().size, safe, target])
|
||||||
|
var c := sim.campaign
|
||||||
|
var sign := sim.review_panel
|
||||||
|
c.new_campaign()
|
||||||
|
sign.refresh()
|
||||||
|
await _settle()
|
||||||
|
t.check(sign._intro.visible and sign._intro.text.contains("(hold Use)"), "%s: (the first morning's sign, in touch words)" % name)
|
||||||
|
_check_sign(name + ", the first morning's sign", sign, safe, target, sign._intro, ipad)
|
||||||
|
await _reach_end(name + ", the first morning's sign", sign._scroll, sign._intro)
|
||||||
|
_later(c)
|
||||||
|
sign.refresh()
|
||||||
|
await _settle()
|
||||||
|
t.check(sign._lists.visible and sign.enemies_text().count(",") == 3 and sign.materials_text().count(",") == 3,
|
||||||
|
"%s: (the later morning's review, every enemy and material listed)" % name)
|
||||||
|
_check_sign(name + ", the later morning's review", sign, safe, target, sign._lists, ipad)
|
||||||
|
await _reach_end(name + ", the later morning's review", sign._scroll, sign._lists)
|
||||||
|
c.begin_day()
|
||||||
|
await t.process_frame
|
||||||
|
for p: Array in [[sim.upgrade_panel, "workbench"], [sim.shed_panel, "shed"]]:
|
||||||
|
var panel := p[0] as UpgradePanel
|
||||||
|
panel.open()
|
||||||
|
await _settle()
|
||||||
|
_check_shop("%s, the %s's menu" % [name, p[1]], panel, safe, target, ipad)
|
||||||
|
await _reach_end("%s, the %s's menu" % [name, p[1]], panel._scroll, panel._rows.values()[-1])
|
||||||
|
panel.close()
|
||||||
|
var end := sim.end_panel
|
||||||
|
_failure(c)
|
||||||
|
end.show_failure()
|
||||||
|
await _settle()
|
||||||
|
_check_end(name + ", the failure screen", end, safe, target, [end._retry, end._new])
|
||||||
|
await _reach_end(name + ", the failure screen", end._scroll, end._stats)
|
||||||
|
_assessment(c)
|
||||||
|
end.show_assessment()
|
||||||
|
await _settle()
|
||||||
|
_check_end(name + ", the final assessment", end, safe, target, [end._new])
|
||||||
|
await _reach_end(name + ", the final assessment", end._scroll, end._stats)
|
||||||
|
end.hide_panel()
|
||||||
|
|
||||||
|
|
||||||
|
func _check_sign(what: String, sign: ReviewPanel, safe: Rect2, target: float, last: Control, ipad: bool) -> void:
|
||||||
|
var board := sign._board.get_global_rect()
|
||||||
|
var top := sign._post_top + ReviewPanel.END_GRAIN
|
||||||
|
var drawn := Rect2(board.position - Vector2(ReviewPanel.BEAM_END, top), board.size + Vector2(2.0 * ReviewPanel.BEAM_END, top))
|
||||||
|
t.check(_inside(safe, drawn), "%s: inside the safe rect, its beam's ends and posts' tops too (%s in %s)" % [what, drawn, safe])
|
||||||
|
var start := sign._start.get_global_rect()
|
||||||
|
var paper := sign._scroll.get_global_rect()
|
||||||
|
t.check(start.size.y >= target - 0.01 and _inside(board, start) and start.position.y >= paper.end.y,
|
||||||
|
"%s: Start the day is in view below the text, %.0f tall (target %.0f)" % [what, start.size.y, target])
|
||||||
|
t.check(_inside(board, paper), "%s: the text's view is on the paper" % what)
|
||||||
|
if ipad:
|
||||||
|
t.check(not sign._scroll.scrolls() and _inside(paper, last.get_global_rect()), "%s: it all fits, no scrolling" % what)
|
||||||
|
|
||||||
|
|
||||||
|
func _check_shop(what: String, panel: UpgradePanel, safe: Rect2, target: float, ipad: bool) -> void:
|
||||||
|
var rect := panel._panel.get_global_rect()
|
||||||
|
t.check(_inside(safe, rect), "%s: inside the safe rect (%s in %s)" % [what, rect, safe])
|
||||||
|
var close := panel._close.get_global_rect()
|
||||||
|
var list := panel._scroll.get_global_rect()
|
||||||
|
t.check(close.size.y >= target - 0.01 and _inside(rect, close) and close.position.y >= list.end.y,
|
||||||
|
"%s: Close is in view below the list, %.0f tall" % [what, close.size.y])
|
||||||
|
var short: Array[String] = []
|
||||||
|
var wide := 0
|
||||||
|
for id: String in panel._rows:
|
||||||
|
var r := (panel._rows[id] as Control).get_global_rect()
|
||||||
|
if r.size.y < target - 0.01:
|
||||||
|
short.append("%s %.0f" % [id, r.size.y])
|
||||||
|
if r.position.x < list.position.x - 0.5 or r.end.x > list.end.x + 0.5:
|
||||||
|
wide += 1
|
||||||
|
t.check(short.is_empty() and wide == 0, "%s: every row (%d) is at least %.0f tall and fits across, its text wrapped %s" % [what, panel._rows.size(), target, short])
|
||||||
|
if ipad:
|
||||||
|
t.check(not panel._scroll.scrolls(), "%s: all its rows fit, no scrolling" % what)
|
||||||
|
|
||||||
|
|
||||||
|
func _check_end(what: String, end: EndPanel, safe: Rect2, target: float, buttons: Array) -> void:
|
||||||
|
var rect := end._panel.get_global_rect()
|
||||||
|
t.check(_inside(safe, rect), "%s: inside the safe rect (%s in %s)" % [what, rect, safe])
|
||||||
|
var view := end._scroll.get_global_rect()
|
||||||
|
var ok := true
|
||||||
|
for b: Button in buttons:
|
||||||
|
var r := b.get_global_rect()
|
||||||
|
ok = ok and b.visible and r.size.y >= target - 0.01 and _inside(rect, r) and r.position.y >= view.end.y
|
||||||
|
t.check(ok, "%s: its buttons are in view below the text, at least %.0f tall" % [what, target])
|
||||||
|
var stats := end._stats.get_global_rect()
|
||||||
|
t.check(end._stats.autowrap_mode != TextServer.AUTOWRAP_OFF and stats.position.x >= view.position.x - 0.5 and stats.end.x <= view.end.x + 0.5,
|
||||||
|
"%s: the totals wrap to the panel (%d lines in %.0f px)" % [what, end._stats.get_line_count(), stats.size.x])
|
||||||
|
|
||||||
|
|
||||||
|
## Scrolled to its end, the last of a panel's scrolling part is in its view.
|
||||||
|
func _reach_end(what: String, scroll: UiTheme.TouchScroll, last: Control) -> void:
|
||||||
|
scroll.scroll_vertical = 1000000
|
||||||
|
await _settle()
|
||||||
|
var view := scroll.get_global_rect()
|
||||||
|
var r := last.get_global_rect()
|
||||||
|
t.check(r.end.y <= view.end.y + 0.5 and r.end.y >= view.position.y + minf(r.size.y, view.size.y) - 0.5,
|
||||||
|
"%s: scrolled to the end, all of it is there (%s scrolls: %s)" % [what, "it" if scroll.scrolls() else "nothing", scroll.scrolls()])
|
||||||
|
scroll.scroll_vertical = 0
|
||||||
|
await _settle()
|
||||||
|
|
||||||
|
|
||||||
|
## Fingers on the 19.5:9 phone: drags scroll and never buy; taps buy; Close closes.
|
||||||
|
func _fingers() -> void:
|
||||||
|
var root: Window = t.root
|
||||||
|
MobilePort.preview_dpi = 0.0
|
||||||
|
MobilePort.preview_insets = [140, 0, 140, 60]
|
||||||
|
root.size = Vector2i(2340, 1080)
|
||||||
|
GameSettings.new().apply_scale(root)
|
||||||
|
await _settle()
|
||||||
|
var c := sim.campaign
|
||||||
|
var slop := UiTheme.TouchScroll.DRAG_PT * MobilePort.minimum_target(sim.review_panel) / MobilePort.TARGET_PT
|
||||||
|
# The sign: a drag scrolls its paper.
|
||||||
|
c.new_campaign()
|
||||||
|
var s := c.state
|
||||||
|
_later(c)
|
||||||
|
sim.review_panel.refresh()
|
||||||
|
await _settle()
|
||||||
|
var paper := sim.review_panel._scroll
|
||||||
|
var at := paper.get_global_rect().get_center()
|
||||||
|
t.check(paper.scrolls(), "(the later morning's review scrolls on this phone)")
|
||||||
|
await _drag(at, at + Vector2(0.0, -120.0))
|
||||||
|
t.check(paper.scroll_vertical >= 110 and s.phase == CampaignController.Phase.MORNING,
|
||||||
|
"a finger dragging the sign's paper up scrolls it (%d px), and the day doesn't start" % paper.scroll_vertical)
|
||||||
|
c.begin_day()
|
||||||
|
await _settle()
|
||||||
|
t.check(not sim.review_panel.visible, "(day: the sign is down)")
|
||||||
|
for p: Array in [[sim.upgrade_panel, "workbench"], [sim.shed_panel, "shed"]]:
|
||||||
|
var panel := p[0] as UpgradePanel
|
||||||
|
var shop: String = p[1]
|
||||||
|
s.resources.shed = {"wood": 9999, "scrap": 9999, "straw": 9999, "alien_goop": 9999}
|
||||||
|
s.night = 20 # everything in stock
|
||||||
|
s.upgrades.clear()
|
||||||
|
s.upgrades["corn_shooter"] = 1 # (the corn shooter's upgrades open)
|
||||||
|
var bought: Array[String] = []
|
||||||
|
var count := func(id: String) -> void: bought.append(id)
|
||||||
|
panel.bought.connect(count)
|
||||||
|
panel.open()
|
||||||
|
await _settle()
|
||||||
|
var list := panel._scroll
|
||||||
|
t.check(list.scrolls(), "(the %s's list scrolls on this phone)" % shop)
|
||||||
|
# Press on a row and drag up: the list scrolls, nothing's bought.
|
||||||
|
var row := _row_in_view(panel)
|
||||||
|
var from := (panel._rows[row] as Control).get_global_rect().get_center()
|
||||||
|
var levels := s.upgrades.duplicate()
|
||||||
|
await _drag(from, from + Vector2(0.0, -150.0))
|
||||||
|
t.check(list.scroll_vertical >= 140 and bought.is_empty() and s.upgrades == levels,
|
||||||
|
"%s: a finger that presses a row and drags up scrolls the list (%d px) and buys nothing" % [shop, list.scroll_vertical])
|
||||||
|
# Press, drag down, and back up to the same row: still a drag, not a buy.
|
||||||
|
row = _row_in_view(panel)
|
||||||
|
from = (panel._rows[row] as Control).get_global_rect().get_center()
|
||||||
|
var was := list.scroll_vertical
|
||||||
|
Touch.touch(0, from, true)
|
||||||
|
Touch.drag(0, from, from + Vector2(0.0, 80.0))
|
||||||
|
Touch.drag(0, from + Vector2(0.0, 80.0), from)
|
||||||
|
await t.process_frame
|
||||||
|
Touch.touch(0, from, false)
|
||||||
|
await _settle()
|
||||||
|
t.check(bought.is_empty() and s.upgrades == levels and list.scroll_vertical == was and panel.is_open,
|
||||||
|
"%s: one that drags away and comes back to the row it pressed buys nothing either" % shop)
|
||||||
|
# A tap (with a little wobble, under the slop) buys.
|
||||||
|
row = _row_in_view(panel)
|
||||||
|
from = (panel._rows[row] as Control).get_global_rect().get_center()
|
||||||
|
Touch.touch(0, from, true)
|
||||||
|
Touch.drag(0, from, from + Vector2(0.0, slop * 0.4))
|
||||||
|
Touch.touch(0, from + Vector2(0.0, slop * 0.4), false)
|
||||||
|
await _settle()
|
||||||
|
t.check(bought == [row] and Upgrades.level(s, row) == int(levels.get(row, 0)) + 1,
|
||||||
|
"%s: a tap on a row buys it, even with a little wobble (%s)" % [shop, bought])
|
||||||
|
row = _row_in_view(panel)
|
||||||
|
Touch.tap(0, (panel._rows[row] as Control).get_global_rect().get_center())
|
||||||
|
await _settle()
|
||||||
|
t.check(bought.size() == 2 and bought[1] == row, "%s: and a plain tap on another buys that (%s)" % [shop, bought])
|
||||||
|
Touch.tap(0, panel._close.get_global_rect().get_center())
|
||||||
|
await _settle()
|
||||||
|
t.check(not panel.is_open and not panel.visible, "%s: a tap on Close closes the menu" % shop)
|
||||||
|
panel.bought.disconnect(count)
|
||||||
|
|
||||||
|
|
||||||
|
## A row all in the list's view that can be bought.
|
||||||
|
func _row_in_view(panel: UpgradePanel) -> String:
|
||||||
|
var view := panel._scroll.get_global_rect()
|
||||||
|
for id: String in panel._rows:
|
||||||
|
var b := panel._rows[id] as Button
|
||||||
|
if not b.disabled and view.encloses(b.get_global_rect()):
|
||||||
|
return id
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
## Finger 0 presses at `from`, drags to `to` in one move, and lifts there.
|
||||||
|
func _drag(from: Vector2, to: Vector2) -> void:
|
||||||
|
Touch.touch(0, from, true)
|
||||||
|
Touch.drag(0, from, to)
|
||||||
|
await t.process_frame
|
||||||
|
Touch.touch(0, to, false)
|
||||||
|
await _settle()
|
||||||
|
|
||||||
|
|
||||||
|
static func _inside(outer: Rect2, inner: Rect2) -> bool:
|
||||||
|
return outer.grow(0.5).encloses(inner)
|
||||||
|
|
||||||
|
|
||||||
|
static func _margins(m: MarginContainer) -> Vector4:
|
||||||
|
return Vector4(m.get_theme_constant("margin_left"), m.get_theme_constant("margin_top"),
|
||||||
|
m.get_theme_constant("margin_right"), m.get_theme_constant("margin_bottom"))
|
||||||
|
|
||||||
|
|
||||||
|
## The longest later morning: 28 nights logged, the last with night 3's title (the longest), every
|
||||||
|
## loss, every enemy type and material, and three-digit counts.
|
||||||
|
static func _later(c: CampaignController) -> void:
|
||||||
|
var s := c.state
|
||||||
|
s.night_log.clear()
|
||||||
|
for n in range(1, 29):
|
||||||
|
var e := {}
|
||||||
|
for key in FarmState.LOG_KEYS:
|
||||||
|
e[key] = 0
|
||||||
|
e["night"] = n
|
||||||
|
for key in ["crops_stolen", "crops_recovered", "crops_lost", "animals_stolen", "animals_strayed", "animals_recovered",
|
||||||
|
"animals_lost", "supplies_stolen", "supplies_recovered", "supplies_lost"]:
|
||||||
|
e[key] = 12 + n
|
||||||
|
for key in ["killed_crow", "killed_thief", "killed_breaker", "killed_ufo"]:
|
||||||
|
e[key] = 100 + n * 3
|
||||||
|
for key in ["gathered_wood", "gathered_scrap", "gathered_straw", "gathered_alien_goop",
|
||||||
|
"spent_wood", "spent_scrap", "spent_straw", "spent_alien_goop"]:
|
||||||
|
e[key] = 140 + n
|
||||||
|
for key in ["escaped", "scarecrow_damage", "patches", "structures_built", "structures_damaged",
|
||||||
|
"structures_destroyed", "repairs", "upgrades_bought"]:
|
||||||
|
e[key] = 9 + n
|
||||||
|
s.night_log.append(e)
|
||||||
|
s.night_log[s.night_log.size() - 1]["night"] = 3
|
||||||
|
s.night = 29
|
||||||
|
|
||||||
|
|
||||||
|
## The failure screen's longest: the scarecrow fallen on night 29 of a vacation like _later's.
|
||||||
|
static func _failure(c: CampaignController) -> void:
|
||||||
|
_later(c)
|
||||||
|
c.outcome = CampaignController.Outcome.GAME_OVER_SCARECROW
|
||||||
|
c.state.night = 29
|
||||||
|
|
||||||
|
|
||||||
|
static func _assessment(c: CampaignController) -> void:
|
||||||
|
_later(c)
|
||||||
|
c.outcome = CampaignController.Outcome.VACATION_COMPLETE
|
||||||
|
|
||||||
|
|
||||||
|
## Fixed row and title texts, so the desktop check doesn't follow the costs' tuning.
|
||||||
|
static func _fixed(p: UpgradePanel) -> void:
|
||||||
|
p._title.text = FIXED_TITLE
|
||||||
|
for id: String in p._rows:
|
||||||
|
(p._rows[id] as Button).text = FIXED_ROW
|
||||||
1
game/tests/mobile/panels_test.gd.uid
Normal file
1
game/tests/mobile/panels_test.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://c3b8nvghm8hx3
|
||||||
Loading…
Add table
Add a link
Reference in a new issue