#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

@ -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