#37: platform back button, no Quit on phones, flat labels, camera

- Android back: application/config/quit_on_go_back=false; Main.go_back()
  (from NOTIFICATION_WM_GO_BACK_REQUEST, phones only) closes the shop or
  pouch panel or leaves build mode, else pauses; paused it closes the
  question, then settings, then resumes (shared with the pause action);
  at the main menu it closes the question or settings, else quits.
- Phones hide the main menu's Quit and the pause menu's Quit the game.
- ScreenLabels.ensure() makes the one ScreenLabels (ToonLook's on
  desktop; Main's on phones, which watch()es the tree for Label3Ds).
  Label sizes grow with the window's content_scale_factor (1 on desktop).
- FollowCamera starts at PHONE_DISTANCE (12 m) on phones.
- MobilePort.forced for tests; game/tests/mobile/platform_test.gd.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-14 14:35:53 -04:00
parent f0291133fd
commit c47e67891e
10 changed files with 368 additions and 23 deletions

View file

@ -3,7 +3,11 @@ class_name FollowCamera
extends Camera3D
## Angled top-down camera that trails a target. The framing comes entirely from pitch / yaw /
## distance (the transform is overwritten every frame, also in the editor so the framing can be
## previewed). PlayerCharacter moves relative to this camera's yaw. Mouse wheel zooms.
## previewed). PlayerCharacter moves relative to this camera's yaw. Mouse wheel zooms. On a phone
## (MobilePort) it starts closer, at PHONE_DISTANCE.
## The phones' distance (the small screen), in place of distance's default when the game starts.
const PHONE_DISTANCE := 12.0
@export var target: Node3D
@export_range(5.0, 89.0) var pitch_deg := 50.0
@ -22,6 +26,8 @@ var _focus := Vector3.ZERO
func _ready() -> void:
physics_interpolation_mode = Node.PHYSICS_INTERPOLATION_MODE_OFF
if not Engine.is_editor_hint() and MobilePort.active():
distance = PHONE_DISTANCE
snap_to_target()

View file

@ -19,8 +19,10 @@ extends Node
## over GD-Sync (GDSyncLink), with voice chat. In co-op the menus don't pause the farm; the
## host's leaving ends the partner's game (back to this menu, which says why), the partner's
## leaving leaves the host alone. [M] mutes the microphone.
## * On a phone (MobilePort): no ToonLook, no co-op, two thumbsticks (TouchSticks), and leaving
## the app pauses. The iOS test build adds PerfTest (frame times and test buttons).
## * On a phone (MobilePort): no ToonLook (Main adds the ScreenLabels that draws the Label3Ds
## flat), no co-op, no Quit buttons, two thumbsticks (TouchSticks), and leaving the app
## pauses. Android's back button (go_back) closes what's on top or pauses, and quits from the
## main menu. The iOS test build adds PerfTest (frame times and test buttons).
## Main processes while paused; the farm doesn't. Tests set save_path and settings_path
## before adding it to the tree.
@ -63,6 +65,8 @@ func _ready() -> void:
var look := ToonLook.new() # toon shading and pixel outlines on the farm
look.name = "ToonLook"
add_child(look)
else:
ScreenLabels.ensure(self).watch(get_tree().root) # ToonLook's label drawing, without the look
if MobilePort.perf_test():
var perf := PerfTest.new()
perf.name = "PerfTest"
@ -267,6 +271,49 @@ func _notification(what: int) -> void:
quit_game()
elif what == NOTIFICATION_APPLICATION_PAUSED: # a phone app sent to the background
pause()
elif what == NOTIFICATION_WM_GO_BACK_REQUEST and MobilePort.active(): # Android's back button
go_back()
## The phone's back button (application/config/quit_on_go_back is off, so it comes here): what's
## on top closes. Playing: the workbench's or the shed's panel, the pouch panel, or build mode,
## else it pauses (over a conversation, a sign, the intro, or the end panel too, as Escape does).
## Paused: the question, then settings, then it resumes. The main menu: the question, then
## settings, else it quits (as Quit: quit_requested).
func go_back() -> void:
if quitting:
return
match screen:
Screen.PLAYING:
if sim.upgrade_panel != null and sim.upgrade_panel.is_open:
sim.upgrade_panel.close()
elif sim.shed_panel != null and sim.shed_panel.is_open:
sim.shed_panel.close()
elif sim.resource_hud != null and sim.resource_hud.open:
sim.resource_hud.toggle()
elif sim.build != null and sim.build.active:
sim.build.set_active(false)
else:
pause()
Screen.PAUSED:
_back_in_pause()
Screen.MENU:
if confirm.is_open:
confirm.close()
elif settings_menu.is_open:
settings_menu.close()
elif main_menu.visible: # (not the co-op menu's screens: no co-op on phones)
main_menu.quit_requested.emit()
## Paused, the pause action or back: the question closes first, then settings, then it resumes.
func _back_in_pause() -> void:
if confirm.is_open:
confirm.close()
elif settings_menu.is_open:
settings_menu.close()
else:
resume()
func _play() -> void:
@ -407,10 +454,5 @@ func _unhandled_input(event: InputEvent) -> void:
pause()
get_viewport().set_input_as_handled()
Screen.PAUSED:
if confirm.is_open:
confirm.close()
elif settings_menu.is_open:
settings_menu.close()
else:
resume()
_back_in_pause()
get_viewport().set_input_as_handled()

View file

@ -2,7 +2,8 @@ class_name MainMenu
extends Control
## The title screen over the farm (Main slowly circles a camera around it): the title, then
## Continue (with which morning it resumes at, or why the save can't be continued), New
## vacation, Play with a friend (co-op, CoopMenu; not on phones), Settings, and Quit, and a notice line (e.g.
## vacation, Play with a friend (co-op, CoopMenu; not on phones), Settings, and Quit (not on
## phones either), and a notice line (e.g.
## why a co-op game ended). Mouse, keyboard, and gamepad work through focus.
signal continue_requested
@ -62,6 +63,7 @@ func _ready() -> void:
settings_button.pressed.connect(func() -> void: settings_requested.emit())
quit_button = _button(box, "Quit")
quit_button.pressed.connect(func() -> void: quit_requested.emit())
quit_button.visible = not MobilePort.active() # phones: the system closes apps (Android's back here, Main)
notice = Label.new()
notice.add_theme_font_size_override("font_size", 22)
notice.add_theme_color_override("font_color", Color(1.0, 0.75, 0.5))

View file

@ -13,7 +13,13 @@ extends RefCounted
## on, to see the phone build without a phone (add --rendering-method mobile for its renderer).
## Tests: -1 detects the platform, 0 forces desktop, 1 forces a phone.
static var forced := -1
static func active() -> bool:
if forced >= 0:
return forced == 1
return OS.has_feature("mobile") or "--mobile" in OS.get_cmdline_user_args()

View file

@ -3,8 +3,8 @@ extends CenterContainer
## Escape / Start during play (Main pauses the tree), hand-drawn like the HUD's pouch panel
## (UiTheme.sketch): where you are and what's left to protect
## (crops, animals, supplies; asset_counts), then Resume, Restart the night, Settings, Save & quit
## to the menu, and Quit the game, with a reminder of what Continue picks up (the vacation is
## saved every morning).
## to the menu, and Quit the game (not on phones, MobilePort), with a reminder of what Continue
## picks up (the vacation is saved every morning).
signal resume_requested
signal restart_requested
@ -65,6 +65,7 @@ func _ready() -> void:
menu_button.pressed.connect(func() -> void: menu_requested.emit())
quit_button = _button(box, "Quit the game")
quit_button.pressed.connect(func() -> void: quit_requested.emit())
quit_button.visible = not MobilePort.active() # phones: the system closes apps
_note = Label.new()
_note.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
_note.custom_minimum_size = Vector2(520.0, 0.0)

View file

@ -1,10 +1,13 @@
class_name ScreenLabels
extends Control
## Draws the farm's Label3Ds as flat text over the 3D view, so they stay sharp and readable when
## the 3D view is pixelated (GameSettings.pixel_size). ToonLook tracks every Label3D; a tracked
## the 3D view is pixelated (GameSettings.pixel_size) and at a phone's interface scale. There's one
## per game (ensure()): ToonLook's on desktop, which tracks every Label3D, and on phones (no
## ToonLook, MobilePort) Main's, which watch()es the tree for them itself. A tracked
## label stops rendering in 3D (layers 0) and is drawn here instead, centered on where it projects,
## with its text, colors, and outline (in the HUD's handwritten font, Sketch, unless it has its own
## font), at the size it would have on screen but never smaller than
## font), at the size it would have on screen (times the interface scale, the window's
## content_scale_factor: phones', MobilePort; 1 on desktop) but never smaller than
## MIN_SIZE (far-off ones, under HIDE_BELOW, aren't drawn at all). Labels that would overlap are
## nudged apart: the lowest on screen keeps its place and the ones over it move up clear of it.
## The game's labels are all
@ -15,11 +18,30 @@ extends Control
const MIN_SIZE := 16.0 # canvas pixels (1080 high): smaller labels are drawn at this size...
const HIDE_BELOW := 6.0 # ...unless they'd be this small on screen, when they're not drawn
const GAP := 2.0 # canvas pixels between labels nudged apart
const GROUP := &"screen_labels"
var _labels: Array = [] # Label3D; untyped, so freed ones can be dropped
## The game's ScreenLabels: the one in the tree already, else a new one under host (which must
## be in the tree) on its own CanvasLayer, "Labels", over the 3D view and under the HUD (1) and
## the menus (10). ToonLook and Main (on phones) both get theirs here, so there's never two.
static func ensure(host: Node) -> ScreenLabels:
for n in host.get_tree().get_nodes_in_group(GROUP):
if not n.is_queued_for_deletion():
return n as ScreenLabels
var layer := CanvasLayer.new()
layer.name = "Labels"
layer.layer = -1
var labels := ScreenLabels.new()
labels.name = "ScreenLabels"
layer.add_child(labels)
host.add_child(layer)
return labels
func _ready() -> void:
add_to_group(GROUP)
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
mouse_filter = Control.MOUSE_FILTER_IGNORE
@ -31,6 +53,20 @@ func track(label: Label3D) -> void:
_labels.append(label)
## Without ToonLook to hand them over (phones): tracks every Label3D under root, and from now on
## each one as it enters the tree.
func watch(root: Node) -> void:
for l in root.find_children("*", "Label3D", true, false):
track(l as Label3D)
if not get_tree().node_added.is_connected(_on_node_added):
get_tree().node_added.connect(_on_node_added)
func _on_node_added(node: Node) -> void:
if node is Label3D:
track(node as Label3D)
func _process(_delta: float) -> void:
queue_redraw()
@ -45,6 +81,7 @@ func entries() -> Array[Dictionary]:
if cam == null:
return out
var up := cam.global_basis.y
var ui := get_window().content_scale_factor # the interface scale (phones; 1 on desktop): labels grow with the HUD
var fallback := Sketch.font()
for l: Label3D in _labels:
if l.text == "" or not l.is_visible_in_tree():
@ -53,7 +90,7 @@ func entries() -> Array[Dictionary]:
if cam.is_position_behind(world):
continue
var at := cam.unproject_position(world) # already in canvas units (the stretched 1080-high view)
var tall := at.distance_to(cam.unproject_position(world + up * l.font_size * l.pixel_size))
var tall := at.distance_to(cam.unproject_position(world + up * l.font_size * l.pixel_size)) * ui
if tall < HIDE_BELOW:
continue
var scale := maxf(tall, MIN_SIZE) / l.font_size

View file

@ -14,7 +14,7 @@ extends Node
## * A full-screen quad (pixel_outline.gdshader) darkens depth edges and lightens creases for
## whatever camera is current. It needs the Forward+ renderer.
## * Label3Ds aren't rendered in 3D (they'd be pixelated): ScreenLabels draws them as sharp text
## over the 3D view, under the HUD.
## over the 3D view, under the HUD. (Phones have no ToonLook; Main adds the ScreenLabels.)
## The pixel size (rendering the 3D view small and scaling it up with sharp pixels) is a display
## setting: GameSettings.pixel_size.
@ -32,13 +32,7 @@ var _pending: Array = [] # untyped: a node may be freed before the flush
func _ready() -> void:
outline = make_outline()
add_child(outline)
var layer := CanvasLayer.new()
layer.name = "Labels"
layer.layer = -1 # over the 3D view, under the HUD (1) and the menus (10)
add_child(layer)
labels = ScreenLabels.new()
labels.name = "ScreenLabels"
layer.add_child(labels)
labels = ScreenLabels.ensure(self) # its own Labels layer, under the HUD (or the one already there)
get_tree().node_added.connect(_on_node_added)
apply_to(get_tree().root)