64 lines
2.2 KiB
GDScript
64 lines
2.2 KiB
GDScript
extends CanvasLayer
|
|
## Universal "rotate to landscape" prompt (autoload `OrientationGuard`). The cross-device
|
|
## half of landscape enforcement: screen.orientation.lock (controls_manager.gd) handles
|
|
## Android, but iOS Safari has no lock API, and some browsers only lock in fullscreen — so
|
|
## wherever the device ends up portrait, we simply ask the player to turn it. No canvas
|
|
## rotation or input remapping (those break touch coordinates), so it works on every phone
|
|
## and browser cleanly. Only ever shows on touch-primary devices, only while portrait.
|
|
|
|
var _panel: ColorRect
|
|
|
|
|
|
func _ready() -> void:
|
|
layer = 128 # above HUD, touch UI, everything
|
|
process_mode = Node.PROCESS_MODE_ALWAYS
|
|
|
|
_panel = ColorRect.new()
|
|
_panel.color = Color(0.05, 0.03, 0.02, 0.97)
|
|
_panel.set_anchors_preset(Control.PRESET_FULL_RECT)
|
|
_panel.mouse_filter = Control.MOUSE_FILTER_STOP # swallow taps to the game behind it
|
|
_panel.visible = false
|
|
add_child(_panel)
|
|
|
|
var center := CenterContainer.new()
|
|
center.set_anchors_preset(Control.PRESET_FULL_RECT)
|
|
center.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
_panel.add_child(center)
|
|
|
|
var box := VBoxContainer.new()
|
|
box.alignment = BoxContainer.ALIGNMENT_CENTER
|
|
box.add_theme_constant_override("separation", 14)
|
|
center.add_child(box)
|
|
|
|
var title := Label.new()
|
|
title.text = "Rotate your device"
|
|
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
title.add_theme_font_size_override("font_size", 44)
|
|
title.add_theme_color_override("font_color", Color(1.0, 0.78, 0.22))
|
|
box.add_child(title)
|
|
|
|
var sub := Label.new()
|
|
sub.text = "Turn it sideways to play in landscape"
|
|
sub.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
sub.add_theme_font_size_override("font_size", 22)
|
|
sub.add_theme_color_override("font_color", Color(0.85, 0.85, 0.85))
|
|
box.add_child(sub)
|
|
|
|
get_viewport().size_changed.connect(_update)
|
|
_update.call_deferred()
|
|
|
|
|
|
func _update() -> void:
|
|
_panel.visible = _should_guard() and _is_portrait()
|
|
|
|
|
|
func _is_portrait() -> bool:
|
|
var s := get_viewport().get_visible_rect().size
|
|
return s.y > s.x
|
|
|
|
|
|
# Touch-primary devices only — never a desktop browser with a tall window (they can't rotate
|
|
# a monitor). Reuses the same conservative detection the touch UI uses.
|
|
func _should_guard() -> bool:
|
|
return Controls.use_touch_ui()
|