1
Fork 0
mirror of https://github.com/Steffo99/nanogolf.git synced 2024-11-21 15:44:21 +00:00

Start handling room creation and joining

This commit is contained in:
Steffo 2024-02-24 22:51:43 +01:00
parent 9a2097a207
commit 7143422cf6
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
4 changed files with 44 additions and 9 deletions

View file

@ -1,2 +1,27 @@
extends Node extends Node
class_name Main 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()

View file

@ -1,13 +1,11 @@
[gd_scene load_steps=4 format=3 uid="uid://b8f5t76nfdu5h"] [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="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="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"] [node name="Main" type="Node"]
script = ExtResource("1_a2cl7")
[node name="Interface" parent="." instance=ExtResource("1_bd856")] [node name="Interface" parent="." instance=ExtResource("1_bd856")]
theme = ExtResource("2_oe7am") theme = ExtResource("2_oe7am")
[node name="MainMenu" parent="Interface" instance=ExtResource("3_3lx7u")]
layout_mode = 2

View file

@ -2,6 +2,10 @@ extends Control
class_name MainMenu class_name MainMenu
signal room_created(server: ENetMultiplayerPeer, client: ENetMultiplayerPeer)
signal room_joined(client: ENetMultiplayerPeer)
enum MenuStage { enum MenuStage {
NAME_INPUT = 1, NAME_INPUT = 1,
COLOR_PICKER = 2, COLOR_PICKER = 2,
@ -83,12 +87,16 @@ func deinit_server_menu():
server_menu_instance.queue_free() server_menu_instance.queue_free()
func _on_hosting_confirmed(port: int): func _on_hosting_confirmed(port: int):
push_warning("TODO") var server = ENetMultiplayerPeer.new()
current_stage = MenuStage.NAME_INPUT 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): func _on_connecting_confirmed(address: String, port: int):
push_warning("TODO") var client = ENetMultiplayerPeer.new()
current_stage = MenuStage.NAME_INPUT client.create_client(address, port)
room_joined.emit(client)
func _ready(): func _ready():

View file

@ -4,7 +4,11 @@
[node name="MainMenu" type="Control"] [node name="MainMenu" type="Control"]
layout_mode = 3 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") script = ExtResource("1_6ex0u")
[node name="VBoxContainer" type="VBoxContainer" parent="."] [node name="VBoxContainer" type="VBoxContainer" parent="."]