multyplayer
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
extends Control
|
||||
|
||||
## The 2D UI rendered inside the world-space menu (XRToolsViewport2DIn3D).
|
||||
## Lets the player type an IP on a numeric keypad and pick Host / Join / Solo.
|
||||
## Pure UI: it emits intents; main.gd performs the networking.
|
||||
|
||||
signal host_pressed()
|
||||
signal join_pressed(ip: String)
|
||||
signal solo_pressed()
|
||||
|
||||
var _ip := "127.0.0.1"
|
||||
|
||||
@onready var _ip_label: Label = %IPLabel
|
||||
@onready var _status: Label = %Status
|
||||
@onready var _keypad: GridContainer = %Keypad
|
||||
@onready var _host_btn: Button = %HostButton
|
||||
@onready var _join_btn: Button = %JoinButton
|
||||
@onready var _solo_btn: Button = %SoloButton
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
for child in _keypad.get_children():
|
||||
if child is Button:
|
||||
child.pressed.connect(_on_key.bind(child.text))
|
||||
_host_btn.pressed.connect(func(): host_pressed.emit())
|
||||
_join_btn.pressed.connect(func(): join_pressed.emit(_ip))
|
||||
_solo_btn.pressed.connect(func(): solo_pressed.emit())
|
||||
_refresh()
|
||||
|
||||
|
||||
func _on_key(key: String) -> void:
|
||||
match key:
|
||||
"DEL":
|
||||
_ip = _ip.substr(0, max(0, _ip.length() - 1))
|
||||
_:
|
||||
if _ip.length() < 21:
|
||||
_ip += key
|
||||
_refresh()
|
||||
|
||||
|
||||
func _refresh() -> void:
|
||||
_ip_label.text = _ip if not _ip.is_empty() else "_"
|
||||
|
||||
|
||||
## Called by main.gd (via network_menu) to show connection feedback.
|
||||
func set_status(text: String) -> void:
|
||||
if _status:
|
||||
_status.text = text
|
||||
Reference in New Issue
Block a user