#35: interface scale, safe area, and the mobile test kit
MobilePort: ui_scale() (clampf(4.3 / the screen's shorter side in inches, 1, 1.8) times the
Interface size; 1 on desktop), a size-class fallback (below 500 pt = phone, 1.6) when the
density is 0 or implausible, safe_rect(ci) (the display's safe area mapped into ci's canvas
through the final transform), minimum_target() (44 pt in canvas pixels), and the `forced`
override for tests. The desktop preview (-- --mobile) plays the phone in the window:
--safe-area=l,t,r,b insets it, --dpi=N sets its density, and without --dpi a 16:9-or-wider
window is a 2.7 in phone (about 1.6x) and a squarer one a 6 in iPad (1x).
GameSettings: interface_size (0.8-1.3, saved under [touch]) and apply_scale(), which sets the
window's content_scale_factor (always 1 on desktop). PerfTest shows the screen, density, safe
area, and resulting scale, to check the density on a device.
Test kit: test_mobile (last in SUITES) runs game/tests/mobile/*_test.gd in name order and puts
the root window back between files; mobile/touch.gd sends touches through
Input.parse_input_event; scale_test covers phones, iPads, desktop, the safe rect, and the target;
sticks_test is the 8c81d81 driver's 24 checks. game/tools/capture_mobile.gd takes the phone
screenshots.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f0291133fd
commit
aee60b0ba2
14 changed files with 874 additions and 3 deletions
|
|
@ -11,6 +11,8 @@ extends RefCounted
|
|||
## resolution scale, used when the pixel size is 1 (the HUD stays sharp either way).
|
||||
## * Gameplay: whether the tips show on the first day and night (Tutorial).
|
||||
## * Co-op: your player name, and whether your microphone is sent in voice chat.
|
||||
## * Touch (phones): the interface size, times the scale the screen's size calls for
|
||||
## (MobilePort.ui_scale; it doesn't change desktop).
|
||||
## Values missing from the file or out of range fall back to the defaults, so an old or
|
||||
## hand-edited file never breaks the game.
|
||||
|
||||
|
|
@ -33,6 +35,8 @@ var show_tips := true
|
|||
## Co-op: your name for the lobby and the name tag, and whether your microphone is sent.
|
||||
var player_name := ""
|
||||
var microphone := true
|
||||
## Phones: the Interface size, 0.8-1.3 times the scale the screen calls for (MobilePort.ui_scale).
|
||||
var interface_size := 1.0
|
||||
|
||||
|
||||
static func load_from(path: String = PATH) -> GameSettings:
|
||||
|
|
@ -52,6 +56,7 @@ static func load_from(path: String = PATH) -> GameSettings:
|
|||
var n: Variant = f.get_value("coop", "player_name", "")
|
||||
g.player_name = String(n).strip_edges().left(20) if n is String else ""
|
||||
g.microphone = _flag(f.get_value("coop", "microphone", g.microphone), g.microphone)
|
||||
g.interface_size = _number(f.get_value("touch", "interface_size", g.interface_size), 0.8, 1.3, g.interface_size)
|
||||
return g
|
||||
|
||||
|
||||
|
|
@ -68,11 +73,12 @@ func save_to(path: String = PATH) -> Error:
|
|||
f.set_value("gameplay", "show_tips", show_tips)
|
||||
f.set_value("coop", "player_name", player_name)
|
||||
f.set_value("coop", "microphone", microphone)
|
||||
f.set_value("touch", "interface_size", interface_size)
|
||||
return f.save(path)
|
||||
|
||||
|
||||
## Applies everything: bus volumes, dead zones (into config too, when given), and the display
|
||||
## (skipped without a real display, e.g. headless).
|
||||
## Applies everything: bus volumes, dead zones (into config too, when given), the interface
|
||||
## scale, and the display (skipped without a real display, e.g. headless).
|
||||
func apply(viewport: Viewport, config: GameConfig = null) -> void:
|
||||
for bus in BUSES:
|
||||
var i := AudioServer.get_bus_index(bus)
|
||||
|
|
@ -88,6 +94,7 @@ func apply(viewport: Viewport, config: GameConfig = null) -> void:
|
|||
config.aim_dead_zone = aim_dead_zone
|
||||
if viewport != null:
|
||||
apply_pixels(viewport)
|
||||
apply_scale(viewport)
|
||||
if DisplayServer.get_name() == "headless":
|
||||
return
|
||||
var mode := DisplayServer.window_get_mode()
|
||||
|
|
@ -112,6 +119,15 @@ func apply_pixels(viewport: Viewport) -> void:
|
|||
viewport.msaa_3d = ProjectSettings.get_setting("rendering/anti_aliasing/quality/msaa_3d", Viewport.MSAA_DISABLED)
|
||||
|
||||
|
||||
## The interface scale (MobilePort.ui_scale: on a phone, the screen's size times
|
||||
## interface_size; always 1 on desktop) as the window's content_scale_factor, which scales every
|
||||
## CanvasLayer (the HUD, the menus, the sticks) and leaves the 3D view alone.
|
||||
func apply_scale(viewport: Viewport) -> void:
|
||||
var window := viewport.get_window()
|
||||
if window != null:
|
||||
window.content_scale_factor = MobilePort.ui_scale(interface_size)
|
||||
|
||||
|
||||
static func _number(v: Variant, lo: float, hi: float, fallback: float) -> float:
|
||||
if not (v is float or v is int):
|
||||
return fallback
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue