You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.3 KiB
74 lines
2.3 KiB
extends Node3D
|
|
## VR start screen UI panel.
|
|
## Renders a 2D UI in a SubViewport on a QuadMesh in VR space.
|
|
## Allows user to enter server URL/port, connect, and launch AR mode.
|
|
|
|
signal connect_requested(host: String, port: int)
|
|
signal launch_ar_requested()
|
|
|
|
@onready var ui_mesh: MeshInstance3D = $UIMesh
|
|
@onready var viewport: SubViewport = $UIMesh/SubViewport
|
|
@onready var host_input: LineEdit = $UIMesh/SubViewport/PanelContainer/MarginContainer/VBox/ServerRow/HostInput
|
|
@onready var port_input: LineEdit = $UIMesh/SubViewport/PanelContainer/MarginContainer/VBox/PortRow/PortInput
|
|
@onready var connect_button: Button = $UIMesh/SubViewport/PanelContainer/MarginContainer/VBox/ConnectButton
|
|
@onready var status_label: Label = $UIMesh/SubViewport/PanelContainer/MarginContainer/VBox/StatusLabel
|
|
@onready var launch_ar_button: Button = $UIMesh/SubViewport/PanelContainer/MarginContainer/VBox/LaunchARButton
|
|
|
|
var _is_connected: bool = false
|
|
|
|
|
|
func _ready() -> void:
|
|
add_to_group("start_screen")
|
|
connect_button.pressed.connect(_on_connect_pressed)
|
|
launch_ar_button.pressed.connect(_on_launch_ar_pressed)
|
|
|
|
# Set up the mesh material to display the SubViewport
|
|
var material := StandardMaterial3D.new()
|
|
material.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
|
material.albedo_texture = viewport.get_texture()
|
|
material.transparency = BaseMaterial3D.TRANSPARENCY_DISABLED
|
|
ui_mesh.material_override = material
|
|
|
|
print("[StartScreen] Ready")
|
|
|
|
|
|
func _on_connect_pressed() -> void:
|
|
var host := host_input.text.strip_edges()
|
|
if host.is_empty():
|
|
update_status("Please enter a server address")
|
|
return
|
|
|
|
var port := int(port_input.text.strip_edges())
|
|
if port <= 0 or port > 65535:
|
|
update_status("Invalid port number")
|
|
return
|
|
|
|
update_status("Connecting to %s:%d..." % [host, port])
|
|
connect_requested.emit(host, port)
|
|
|
|
|
|
func _on_launch_ar_pressed() -> void:
|
|
launch_ar_requested.emit()
|
|
|
|
|
|
func update_status(text: String) -> void:
|
|
status_label.text = text
|
|
|
|
|
|
func set_connected(connected: bool) -> void:
|
|
_is_connected = connected
|
|
if connected:
|
|
update_status("Connected!")
|
|
connect_button.text = "Disconnect"
|
|
else:
|
|
if connect_button.text == "Disconnect":
|
|
update_status("Disconnected")
|
|
connect_button.text = "Connect to Server"
|
|
|
|
|
|
func show_screen() -> void:
|
|
visible = true
|
|
|
|
|
|
func hide_screen() -> void:
|
|
visible = false
|