Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide choice to spawn an avatar for the host #283

Merged
merged 17 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions examples/forest-brawl/forest-brawl.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ font_size = 64
[node name="Network" type="Node" parent="."]

[node name="Brawler Spawner" type="Node" parent="Network" node_paths=PackedStringArray("spawn_root", "camera", "joining_screen", "name_input")]
unique_name_in_owner = true
script = ExtResource("5_qv1fx")
player_scene = ExtResource("7_tcy3g")
spawn_root = NodePath("../../Players")
Expand Down Expand Up @@ -196,6 +197,11 @@ text = "16384"
layout_mode = 2
size_flags_horizontal = 4

[node name="Host Only Button" type="Button" parent="UI/Network Popup/LAN/Actions Row"]
layout_mode = 2
size_flags_horizontal = 4
text = "Host Only"

[node name="Host Button" type="Button" parent="UI/Network Popup/LAN/Actions Row"]
layout_mode = 2
size_flags_horizontal = 4
Expand Down Expand Up @@ -265,6 +271,10 @@ placeholder_text = "Host OID"
[node name="Connect Actions Row" type="HBoxContainer" parent="UI/Network Popup/Noray"]
layout_mode = 2

[node name="Host Only Button" type="Button" parent="UI/Network Popup/Noray/Connect Actions Row"]
layout_mode = 2
text = "Host Only"

[node name="Host Button" type="Button" parent="UI/Network Popup/Noray/Connect Actions Row"]
layout_mode = 2
text = "Host"
Expand All @@ -277,26 +287,20 @@ text = "Join"
layout_mode = 2
text = "Force Relay"

[node name="Noray Bootstrapper" type="Node" parent="UI/Network Popup" node_paths=PackedStringArray("connect_ui", "noray_address_input", "noray_connect_button", "noray_disconnect_button", "oid_input", "host_oid_input", "host_button", "join_button", "force_relay_check")]
[node name="LAN Bootstrapper" type="Node" parent="UI/Network Popup" node_paths=PackedStringArray("connect_ui", "address_input", "port_input")]
script = ExtResource("12_gjc7i")
connect_ui = NodePath("..")
address_input = NodePath("../LAN/Address Row/Address LineEdit")
port_input = NodePath("../LAN/Address Row/Port LineEdit")

[node name="Noray Bootstrapper" type="Node" parent="UI/Network Popup" node_paths=PackedStringArray("connect_ui", "noray_address_input", "oid_input", "host_oid_input", "force_relay_check")]
script = ExtResource("11_vpdh0")
connect_ui = NodePath("..")
noray_address_input = NodePath("../Noray/Noray Address Row/Address LineEdit")
noray_connect_button = NodePath("../Noray/Noray Actions Row/Connect Button")
noray_disconnect_button = NodePath("../Noray/Noray Actions Row/Disconnect Button")
oid_input = NodePath("../Noray/OID Row/OID Value")
host_oid_input = NodePath("../Noray/Connect Host Row/Host LineEdit")
host_button = NodePath("../Noray/Connect Actions Row/Host Button")
join_button = NodePath("../Noray/Connect Actions Row/Join Button")
force_relay_check = NodePath("../Noray/Connect Actions Row/Force Relay Checkbox")

[node name="LAN Bootstrapper" type="Node" parent="UI/Network Popup" node_paths=PackedStringArray("connect_ui", "address_input", "port_input", "host_button", "join_button")]
script = ExtResource("12_gjc7i")
connect_ui = NodePath("..")
address_input = NodePath("../LAN/Address Row/Address LineEdit")
port_input = NodePath("../LAN/Address Row/Port LineEdit")
host_button = NodePath("../LAN/Actions Row/Host Button")
join_button = NodePath("../LAN/Actions Row/Join Button")

[node name="Player stats" type="Control" parent="UI" node_paths=PackedStringArray("score_label", "score_manager")]
visible = false
layout_mode = 1
Expand Down Expand Up @@ -362,3 +366,12 @@ vertical_alignment = 1
[node name="Score Screen" parent="UI" instance=ExtResource("14_85lvt")]
visible = false
layout_mode = 1

[connection signal="pressed" from="UI/Network Popup/LAN/Actions Row/Host Only Button" to="UI/Network Popup/LAN Bootstrapper" method="host_only"]
[connection signal="pressed" from="UI/Network Popup/LAN/Actions Row/Host Button" to="UI/Network Popup/LAN Bootstrapper" method="host"]
[connection signal="pressed" from="UI/Network Popup/LAN/Actions Row/Join Button" to="UI/Network Popup/LAN Bootstrapper" method="join"]
[connection signal="pressed" from="UI/Network Popup/Noray/Noray Actions Row/Connect Button" to="UI/Network Popup/Noray Bootstrapper" method="connect_to_noray"]
[connection signal="pressed" from="UI/Network Popup/Noray/Noray Actions Row/Disconnect Button" to="UI/Network Popup/Noray Bootstrapper" method="disconnect_from_noray"]
[connection signal="pressed" from="UI/Network Popup/Noray/Connect Actions Row/Host Only Button" to="UI/Network Popup/Noray Bootstrapper" method="host_only"]
[connection signal="pressed" from="UI/Network Popup/Noray/Connect Actions Row/Host Button" to="UI/Network Popup/Noray Bootstrapper" method="host"]
[connection signal="pressed" from="UI/Network Popup/Noray/Connect Actions Row/Join Button" to="UI/Network Popup/Noray Bootstrapper" method="join"]
7 changes: 5 additions & 2 deletions examples/forest-brawl/scripts/brawler-spawner.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
extends Node
class_name BrawlerSpawner

@export var player_scene: PackedScene
@export var spawn_root: Node
@export var camera: FollowingCamera
@export var joining_screen: Control
@export var name_input: LineEdit

var spawn_host_avatar: bool = true
var avatars: Dictionary = {}

func _ready():
Expand All @@ -28,8 +30,9 @@ func _handle_connected(id: int):
joining_screen.visible = false

func _handle_host():
# Spawn own avatar on host machine
_spawn(1)
if spawn_host_avatar:
# Spawn own avatar on host machine
_spawn(1)

func _handle_new_peer(id: int):
# Spawn an avatar for new player
Expand Down
14 changes: 7 additions & 7 deletions examples/shared/scripts/lan-bootstrapper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ extends Node
@export var connect_ui: Control
@export var address_input: LineEdit
@export var port_input: LineEdit
@export var host_button: Button
@export var join_button: Button

func _ready():
join_button.button_up.connect(_join)
host_button.button_up.connect(_host)
@onready var brawler_spawner := %"Brawler Spawner" as BrawlerSpawner

func _host():
func host_only():
brawler_spawner.spawn_host_avatar = false
host()

func host():
var host = _parse_input()
if host.size() == 0:
return ERR_CANT_RESOLVE
Expand Down Expand Up @@ -48,7 +48,7 @@ func _host():
# are assumed to be absent, hence starting NetworkTime manually
NetworkTime.start()

func _join():
func join():
var host = _parse_input()
if host.size() == 0:
return ERR_CANT_RESOLVE
Expand Down
23 changes: 10 additions & 13 deletions examples/shared/scripts/noray-bootstrapper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,20 @@ enum Role { NONE, HOST, CLIENT }
@export_category("UI")
@export var connect_ui: Control
@export var noray_address_input: LineEdit
@export var noray_connect_button: Button
@export var noray_disconnect_button: Button
@export var oid_input: LineEdit
@export var host_oid_input: LineEdit
@export var host_button: Button
@export var join_button: Button
@export var force_relay_check: CheckBox

@onready var brawler_spawner := %"Brawler Spawner" as BrawlerSpawner

var role = Role.NONE

func _ready():
noray_connect_button.button_up.connect(_connect_to_noray)
noray_disconnect_button.button_up.connect(_disconnect_from_noray)
host_button.button_up.connect(_host)
join_button.button_up.connect(_join)

Noray.on_oid.connect(func(oid): oid_input.text = oid)
Noray.on_connect_nat.connect(_handle_connect_nat)
Noray.on_connect_relay.connect(_handle_connect_relay)

func _connect_to_noray():
func connect_to_noray():
# Connect to noray
var err = OK
var address = noray_address_input.text
Expand Down Expand Up @@ -55,11 +48,15 @@ func _connect_to_noray():
print("Registered local port: %d" % Noray.local_port)
return OK

func _disconnect_from_noray():
func disconnect_from_noray():
Noray.disconnect_from_host()
oid_input.clear()

func _host():
func host_only():
brawler_spawner.spawn_host_avatar = false
host()

func host():
if Noray.local_port <= 0:
return ERR_UNCONFIGURED

Expand Down Expand Up @@ -94,7 +91,7 @@ func _host():
# are assumed to be absent, hence starting NetworkTime manually
NetworkTime.start()

func _join():
func join():
role = Role.CLIENT

if force_relay_check.button_pressed:
Expand Down