diff --git a/scenes/main.gd b/scenes/main.gd index dd20c28..02e804f 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -1,2 +1,27 @@ extends Node class_name Main + + +@onready var interface_instance: MarginContainer = $"Interface" + +const main_menu_scene: PackedScene = preload("res://scenes/main_menu.tscn") +var main_menu_instance: MainMenu = null + +func init_main_menu(): + main_menu_instance = main_menu_scene.instantiate() + main_menu_instance.room_created.connect(_on_room_created) + main_menu_instance.room_joined.connect(_on_room_joined) + interface_instance.add_child(main_menu_instance) + + +func _on_room_created(server: ENetMultiplayerPeer, client: ENetMultiplayerPeer): + print(server, client) + +func _on_room_joined(client: ENetMultiplayerPeer): + print(client) + + +func _ready(): + init_main_menu() + + diff --git a/scenes/main.tscn b/scenes/main.tscn index dda0ab1..629cdfd 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -1,13 +1,11 @@ [gd_scene load_steps=4 format=3 uid="uid://b8f5t76nfdu5h"] +[ext_resource type="Script" path="res://scenes/main.gd" id="1_a2cl7"] [ext_resource type="PackedScene" uid="uid://dtwi2nyjbvr82" path="res://scenes/interface.tscn" id="1_bd856"] [ext_resource type="Theme" uid="uid://mau3moiintkp" path="res://themes/nanogolf_theme.tres" id="2_oe7am"] -[ext_resource type="PackedScene" uid="uid://c3lhhndbdq67s" path="res://scenes/main_menu.tscn" id="3_3lx7u"] [node name="Main" type="Node"] +script = ExtResource("1_a2cl7") [node name="Interface" parent="." instance=ExtResource("1_bd856")] theme = ExtResource("2_oe7am") - -[node name="MainMenu" parent="Interface" instance=ExtResource("3_3lx7u")] -layout_mode = 2 diff --git a/scenes/main_menu.gd b/scenes/main_menu.gd index d8d4596..b64e821 100644 --- a/scenes/main_menu.gd +++ b/scenes/main_menu.gd @@ -2,6 +2,10 @@ extends Control class_name MainMenu +signal room_created(server: ENetMultiplayerPeer, client: ENetMultiplayerPeer) +signal room_joined(client: ENetMultiplayerPeer) + + enum MenuStage { NAME_INPUT = 1, COLOR_PICKER = 2, @@ -83,12 +87,16 @@ func deinit_server_menu(): server_menu_instance.queue_free() func _on_hosting_confirmed(port: int): - push_warning("TODO") - current_stage = MenuStage.NAME_INPUT + var server = ENetMultiplayerPeer.new() + server.create_server(port) + var client = ENetMultiplayerPeer.new() + client.create_client("127.0.0.1", port) + room_created.emit(server, client) func _on_connecting_confirmed(address: String, port: int): - push_warning("TODO") - current_stage = MenuStage.NAME_INPUT + var client = ENetMultiplayerPeer.new() + client.create_client(address, port) + room_joined.emit(client) func _ready(): diff --git a/scenes/main_menu.tscn b/scenes/main_menu.tscn index 20f32a5..f1370a4 100644 --- a/scenes/main_menu.tscn +++ b/scenes/main_menu.tscn @@ -4,7 +4,11 @@ [node name="MainMenu" type="Control"] layout_mode = 3 -anchors_preset = 0 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 script = ExtResource("1_6ex0u") [node name="VBoxContainer" type="VBoxContainer" parent="."]