TableTower/ui/mobile_layout.gd

68 lines
2.4 KiB
GDScript3
Raw Normal View History

class_name MobileLayout
extends RefCounted
## The phone layout (Android, or --mobile on a desktop to try it): the left
## dock (List, or the card palette from "+") fills the screen and a Spread/List
## button swaps it with the spread; the
## top bar drops its hint and zoom control; everything scales to the screen's
## density. Touch gestures come from TouchInput (added on every platform, so
## touch screens on laptops work too).
var m: Main
var showing_list := true
var swap: Button
var add_button: Button
func _init(p_main: Main) -> void:
m = p_main
static func wanted() -> bool:
return OS.has_feature("mobile") or OS.get_cmdline_user_args().has("--mobile")
func apply() -> void:
if OS.has_feature("mobile"):
m.get_window().content_scale_factor = clampf(DisplayServer.screen_get_dpi() / 160.0, 1.0, 3.0)
# Room is short: View, Help and Play/Build move into the ☰ menu
# (Actions.background adds them when the phone layout is on).
var bar := m.top_bar
for c: Control in [bar._hint, bar.zoom, bar.view_menu, bar.help_menu, bar.brand_title, bar._play_button.get_parent().get_parent()]:
if c:
c.visible = false
m.tray.side_panel.visible = false
m.tray.compact = true
m.left_dock.close_button.visible = false
m.left_dock.splitter.visible = false
m.left_dock.size_flags_horizontal = Control.SIZE_EXPAND_FILL
m.left_dock.show_tab(LeftDock.LIST)
m.board.minimap.visible = false
swap = Style.bar_button("Spread")
swap.tooltip_text = "Swap between the list and the spread"
swap.pressed.connect(func() -> void: show_list(not showing_list))
bar.actions_menu.get_parent().add_child(swap)
bar.actions_menu.get_parent().move_child(swap, bar.actions_menu.get_index())
# "+" opens the card palette full screen; picking a card goes back to the spread.
add_button = Style.bar_button("+")
add_button.tooltip_text = "Add a card"
add_button.custom_minimum_size = Vector2(44, 44)
add_button.pressed.connect(open_palette)
bar.actions_menu.get_parent().add_child(add_button)
bar.actions_menu.get_parent().move_child(add_button, swap.get_index())
show_list(true)
## The list or the spread fills the screen.
func show_list(on: bool) -> void:
showing_list = on
m.left_dock.visible = on
m.list_view._rev = -1
m.board.visible = not on
swap.text = "Spread" if on else "List"
## The card palette fills the screen (the left dock's Cards tab).
func open_palette() -> void:
m.left_dock.show_tab(LeftDock.CARDS)
show_list(true)