added multi

This commit is contained in:
algodoogle
2026-07-25 18:20:12 +01:00
parent 265dd12b37
commit f7024db98d
13 changed files with 1032 additions and 151 deletions
+105
View File
@@ -0,0 +1,105 @@
extends Control
## The 2D UI rendered inside the main menu's world-space viewport
## (XRToolsViewport2DIn3D). Lets the player pick John's scene, host a
## multiplayer game, or join one by IP, driving scene switches + NetworkManager
## directly.
const JON_SCENE := "res://Scenes/JonScene.tscn"
const MULTIPLAYER_SCENE := "res://Scenes/multiPlayer.tscn"
var _ip := "127.0.0.1"
@onready var _root_view: Control = %RootView
@onready var _join_view: Control = %JoinView
@onready var _ip_label: Label = %IPLabel
@onready var _status: Label = %Status
@onready var _keypad: GridContainer = %Keypad
@onready var _john_btn: Button = %JohnButton
@onready var _host_btn: Button = %HostButton
@onready var _join_menu_btn: Button = %JoinMenuButton
@onready var _join_btn: Button = %JoinButton
@onready var _back_btn: Button = %BackButton
func _ready() -> void:
if _bypass_menu_for_cmdline():
return
for child in _keypad.get_children():
if child is Button:
child.pressed.connect(_on_key.bind(child.text))
_john_btn.pressed.connect(_on_john_pressed)
_host_btn.pressed.connect(_on_host_pressed)
_join_menu_btn.pressed.connect(_show_join_view)
_join_btn.pressed.connect(_on_join_pressed)
_back_btn.pressed.connect(_show_root_view)
_show_root_view()
_refresh_ip()
## --server / --join <ip> on the command line skip straight to the multiplayer
## scene, same as the previously headless-tested main.tscn flow.
func _bypass_menu_for_cmdline() -> bool:
var args := OS.get_cmdline_user_args()
if args.has("--server"):
NetworkManager.request_host()
get_tree().change_scene_to_file.call_deferred(MULTIPLAYER_SCENE)
return true
if args.has("--join"):
var idx := args.find("--join")
var addr := "127.0.0.1"
if idx + 1 < args.size():
addr = args[idx + 1]
NetworkManager.request_join(addr)
get_tree().change_scene_to_file.call_deferred(MULTIPLAYER_SCENE)
return true
return false
func _show_root_view() -> void:
_root_view.visible = true
_join_view.visible = false
func _show_join_view() -> void:
_root_view.visible = false
_join_view.visible = true
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_ip()
func _refresh_ip() -> void:
_ip_label.text = _ip if not _ip.is_empty() else "_"
func _on_john_pressed() -> void:
NetworkManager.leave()
get_tree().change_scene_to_file.call_deferred(JON_SCENE)
func _on_host_pressed() -> void:
NetworkManager.request_host()
get_tree().change_scene_to_file.call_deferred(MULTIPLAYER_SCENE)
func _on_join_pressed() -> void:
if _ip.is_empty():
set_status("Enter an IP first")
return
NetworkManager.request_join(_ip)
get_tree().change_scene_to_file.call_deferred(MULTIPLAYER_SCENE)
## Called by network_manager (e.g. on connection_failed after a bounce back to
## this menu) to show feedback.
func set_status(text: String) -> void:
if _status:
_status.text = text
+1
View File
@@ -0,0 +1 @@
uid://crs47shds8bm4
+203
View File
@@ -0,0 +1,203 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://UI/main_menu_panel.gd" id="1_panel"]
[node name="MainMenuPanel" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource("1_panel")
[node name="Background" type="ColorRect" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
color = Color(0.09, 0.1, 0.13, 1)
[node name="Margin" type="MarginContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
theme_override_constants/margin_left = 24
theme_override_constants/margin_top = 16
theme_override_constants/margin_right = 24
theme_override_constants/margin_bottom = 16
[node name="Title" type="Label" parent="Margin"]
layout_mode = 2
size_flags_vertical = 0
theme_override_font_sizes/font_size = 26
text = "VRyHungry"
horizontal_alignment = 1
[node name="RootView" type="VBoxContainer" parent="Margin"]
unique_name_in_owner = true
layout_mode = 2
theme_override_constants/separation = 14
[node name="Spacer" type="Control" parent="Margin/RootView"]
custom_minimum_size = Vector2(0, 36)
layout_mode = 2
[node name="JohnButton" type="Button" parent="Margin/RootView"]
unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(0, 64)
theme_override_font_sizes/font_size = 26
text = "Play John's Scene"
[node name="HostButton" type="Button" parent="Margin/RootView"]
unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(0, 64)
theme_override_font_sizes/font_size = 26
text = "Host Multiplayer"
[node name="JoinMenuButton" type="Button" parent="Margin/RootView"]
unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(0, 64)
theme_override_font_sizes/font_size = 26
text = "Join Multiplayer"
[node name="JoinView" type="VBoxContainer" parent="Margin"]
unique_name_in_owner = true
visible = false
layout_mode = 2
theme_override_constants/separation = 10
[node name="Title" type="Label" parent="Margin/JoinView"]
layout_mode = 2
theme_override_font_sizes/font_size = 22
text = "Join Multiplayer"
horizontal_alignment = 1
[node name="IPLabel" type="Label" parent="Margin/JoinView"]
unique_name_in_owner = true
layout_mode = 2
theme_override_font_sizes/font_size = 34
text = "127.0.0.1"
horizontal_alignment = 1
[node name="Status" type="Label" parent="Margin/JoinView"]
unique_name_in_owner = true
layout_mode = 2
theme_override_colors/font_color = Color(0.8, 0.8, 0.5, 1)
theme_override_font_sizes/font_size = 16
text = "Enter host IP, then Join"
horizontal_alignment = 1
[node name="Keypad" type="GridContainer" parent="Margin/JoinView"]
unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 3
theme_override_constants/h_separation = 8
theme_override_constants/v_separation = 8
columns = 3
[node name="B1" type="Button" parent="Margin/JoinView/Keypad"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_font_sizes/font_size = 26
text = "1"
[node name="B2" type="Button" parent="Margin/JoinView/Keypad"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_font_sizes/font_size = 26
text = "2"
[node name="B3" type="Button" parent="Margin/JoinView/Keypad"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_font_sizes/font_size = 26
text = "3"
[node name="B4" type="Button" parent="Margin/JoinView/Keypad"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_font_sizes/font_size = 26
text = "4"
[node name="B5" type="Button" parent="Margin/JoinView/Keypad"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_font_sizes/font_size = 26
text = "5"
[node name="B6" type="Button" parent="Margin/JoinView/Keypad"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_font_sizes/font_size = 26
text = "6"
[node name="B7" type="Button" parent="Margin/JoinView/Keypad"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_font_sizes/font_size = 26
text = "7"
[node name="B8" type="Button" parent="Margin/JoinView/Keypad"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_font_sizes/font_size = 26
text = "8"
[node name="B9" type="Button" parent="Margin/JoinView/Keypad"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_font_sizes/font_size = 26
text = "9"
[node name="BDot" type="Button" parent="Margin/JoinView/Keypad"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_font_sizes/font_size = 26
text = "."
[node name="B0" type="Button" parent="Margin/JoinView/Keypad"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_font_sizes/font_size = 26
text = "0"
[node name="BDel" type="Button" parent="Margin/JoinView/Keypad"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_font_sizes/font_size = 22
text = "DEL"
[node name="Buttons" type="HBoxContainer" parent="Margin/JoinView"]
layout_mode = 2
theme_override_constants/separation = 10
[node name="JoinButton" type="Button" parent="Margin/JoinView/Buttons"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
custom_minimum_size = Vector2(0, 56)
theme_override_font_sizes/font_size = 24
text = "JOIN"
[node name="BackButton" type="Button" parent="Margin/JoinView/Buttons"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
custom_minimum_size = Vector2(0, 56)
theme_override_font_sizes/font_size = 24
text = "BACK"