mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 23:10:08 +01:00
Convert demos to Godot 4 using regular expressions in a script
This commit is contained in:
@@ -18,33 +18,33 @@ anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
||||
[node name="RichTextLabel" type="RichTextLabel" parent="HBoxContainer"]
|
||||
margin_right = 510.0
|
||||
margin_bottom = 600.0
|
||||
offset_right = 510.0
|
||||
offset_bottom = 600.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer"]
|
||||
margin_left = 514.0
|
||||
margin_right = 1024.0
|
||||
margin_bottom = 600.0
|
||||
offset_left = 514.0
|
||||
offset_right = 1024.0
|
||||
offset_bottom = 600.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Label" type="Label" parent="HBoxContainer/VBoxContainer"]
|
||||
margin_right = 510.0
|
||||
margin_bottom = 14.0
|
||||
offset_right = 510.0
|
||||
offset_bottom = 14.0
|
||||
text = "Players:"
|
||||
|
||||
[node name="ItemList" type="ItemList" parent="HBoxContainer/VBoxContainer"]
|
||||
margin_top = 18.0
|
||||
margin_right = 510.0
|
||||
margin_bottom = 576.0
|
||||
offset_top = 18.0
|
||||
offset_right = 510.0
|
||||
offset_bottom = 576.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
same_column_width = true
|
||||
|
||||
[node name="Action" type="Button" parent="HBoxContainer/VBoxContainer"]
|
||||
margin_top = 580.0
|
||||
margin_right = 510.0
|
||||
margin_bottom = 600.0
|
||||
offset_top = 580.0
|
||||
offset_right = 510.0
|
||||
offset_bottom = 600.0
|
||||
disabled = true
|
||||
text = "Do Action!"
|
||||
|
||||
|
||||
@@ -18,95 +18,95 @@ anchor_bottom = 1.0
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Panel"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 20.0
|
||||
margin_top = 20.0
|
||||
margin_right = -20.0
|
||||
margin_bottom = -20.0
|
||||
offset_left = 20.0
|
||||
offset_top = 20.0
|
||||
offset_right = -20.0
|
||||
offset_bottom = -20.0
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Panel/VBoxContainer"]
|
||||
margin_right = 984.0
|
||||
margin_bottom = 24.0
|
||||
offset_right = 984.0
|
||||
offset_bottom = 24.0
|
||||
|
||||
[node name="Label" type="Label" parent="Panel/VBoxContainer/HBoxContainer"]
|
||||
margin_top = 5.0
|
||||
margin_right = 326.0
|
||||
margin_bottom = 19.0
|
||||
offset_top = 5.0
|
||||
offset_right = 326.0
|
||||
offset_bottom = 19.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Name"
|
||||
|
||||
[node name="NameEdit" type="LineEdit" parent="Panel/VBoxContainer/HBoxContainer"]
|
||||
margin_left = 330.0
|
||||
margin_right = 984.0
|
||||
margin_bottom = 24.0
|
||||
offset_left = 330.0
|
||||
offset_right = 984.0
|
||||
offset_bottom = 24.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
text = "A Godot User"
|
||||
|
||||
[node name="HBoxContainer2" type="HBoxContainer" parent="Panel/VBoxContainer"]
|
||||
margin_top = 28.0
|
||||
margin_right = 984.0
|
||||
margin_bottom = 52.0
|
||||
offset_top = 28.0
|
||||
offset_right = 984.0
|
||||
offset_bottom = 52.0
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Panel/VBoxContainer/HBoxContainer2"]
|
||||
margin_right = 326.0
|
||||
margin_bottom = 24.0
|
||||
offset_right = 326.0
|
||||
offset_bottom = 24.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Host" type="Button" parent="Panel/VBoxContainer/HBoxContainer2/HBoxContainer"]
|
||||
margin_right = 42.0
|
||||
margin_bottom = 24.0
|
||||
offset_right = 42.0
|
||||
offset_bottom = 24.0
|
||||
text = "Host"
|
||||
|
||||
[node name="Control" type="Control" parent="Panel/VBoxContainer/HBoxContainer2/HBoxContainer"]
|
||||
margin_left = 46.0
|
||||
margin_right = 241.0
|
||||
margin_bottom = 24.0
|
||||
offset_left = 46.0
|
||||
offset_right = 241.0
|
||||
offset_bottom = 24.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Connect" type="Button" parent="Panel/VBoxContainer/HBoxContainer2/HBoxContainer"]
|
||||
margin_left = 245.0
|
||||
margin_right = 326.0
|
||||
margin_bottom = 24.0
|
||||
offset_left = 245.0
|
||||
offset_right = 326.0
|
||||
offset_bottom = 24.0
|
||||
text = "Connect to"
|
||||
|
||||
[node name="Disconnect" type="Button" parent="Panel/VBoxContainer/HBoxContainer2/HBoxContainer"]
|
||||
visible = false
|
||||
margin_left = 68.0
|
||||
margin_right = 152.0
|
||||
margin_bottom = 24.0
|
||||
offset_left = 68.0
|
||||
offset_right = 152.0
|
||||
offset_bottom = 24.0
|
||||
text = "Disconnect"
|
||||
|
||||
[node name="Hostname" type="LineEdit" parent="Panel/VBoxContainer/HBoxContainer2"]
|
||||
margin_left = 330.0
|
||||
margin_right = 984.0
|
||||
margin_bottom = 24.0
|
||||
offset_left = 330.0
|
||||
offset_right = 984.0
|
||||
offset_bottom = 24.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
text = "localhost"
|
||||
placeholder_text = "localhost"
|
||||
|
||||
[node name="Control" type="Control" parent="Panel/VBoxContainer"]
|
||||
margin_top = 56.0
|
||||
margin_right = 984.0
|
||||
margin_bottom = 76.0
|
||||
rect_min_size = Vector2( 0, 20 )
|
||||
offset_top = 56.0
|
||||
offset_right = 984.0
|
||||
offset_bottom = 76.0
|
||||
rect_min_size = Vector2(0, 20)
|
||||
|
||||
[node name="Game" parent="Panel/VBoxContainer" instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_top = 80.0
|
||||
margin_right = 984.0
|
||||
margin_bottom = 560.0
|
||||
offset_top = 80.0
|
||||
offset_right = 984.0
|
||||
offset_bottom = 560.0
|
||||
|
||||
[node name="AcceptDialog" type="AcceptDialog" parent="."]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -200.0
|
||||
margin_top = -100.0
|
||||
margin_right = 200.0
|
||||
margin_bottom = 100.0
|
||||
offset_left = -200.0
|
||||
offset_top = -100.0
|
||||
offset_right = 200.0
|
||||
offset_bottom = 100.0
|
||||
dialog_text = "Connection closed"
|
||||
|
||||
[connection signal="pressed" from="Panel/VBoxContainer/HBoxContainer2/HBoxContainer/Host" to="." method="_on_Host_pressed"]
|
||||
|
||||
@@ -2,8 +2,8 @@ extends Control
|
||||
|
||||
const _crown = preload("res://img/crown.png")
|
||||
|
||||
onready var _list = $HBoxContainer/VBoxContainer/ItemList
|
||||
onready var _action = $HBoxContainer/VBoxContainer/Action
|
||||
@onready var _list = $HBoxContainer/VBoxContainer/ItemList
|
||||
@onready var _action = $HBoxContainer/VBoxContainer/Action
|
||||
|
||||
var _players = []
|
||||
var _turn = -1
|
||||
|
||||
@@ -3,19 +3,19 @@ extends Control
|
||||
const DEF_PORT = 8080
|
||||
const PROTO_NAME = "ludus"
|
||||
|
||||
onready var _host_btn = $Panel/VBoxContainer/HBoxContainer2/HBoxContainer/Host
|
||||
onready var _connect_btn = $Panel/VBoxContainer/HBoxContainer2/HBoxContainer/Connect
|
||||
onready var _disconnect_btn = $Panel/VBoxContainer/HBoxContainer2/HBoxContainer/Disconnect
|
||||
onready var _name_edit = $Panel/VBoxContainer/HBoxContainer/NameEdit
|
||||
onready var _host_edit = $Panel/VBoxContainer/HBoxContainer2/Hostname
|
||||
onready var _game = $Panel/VBoxContainer/Game
|
||||
@onready var _host_btn = $Panel/VBoxContainer/HBoxContainer2/HBoxContainer/Host
|
||||
@onready var _connect_btn = $Panel/VBoxContainer/HBoxContainer2/HBoxContainer/Connect
|
||||
@onready var _disconnect_btn = $Panel/VBoxContainer/HBoxContainer2/HBoxContainer/Disconnect
|
||||
@onready var _name_edit = $Panel/VBoxContainer/HBoxContainer/NameEdit
|
||||
@onready var _host_edit = $Panel/VBoxContainer/HBoxContainer2/Hostname
|
||||
@onready var _game = $Panel/VBoxContainer/Game
|
||||
|
||||
var peer = null
|
||||
|
||||
func _ready():
|
||||
#warning-ignore-all:return_value_discarded
|
||||
get_tree().connect("network_peer_disconnected", self, "_peer_disconnected")
|
||||
get_tree().connect("network_peer_connected", self, "_peer_connected")
|
||||
get_tree().connect(&"network_peer_disconnected", self._peer_disconnected)
|
||||
get_tree().connect(&"network_peer_connected", self._peer_connected)
|
||||
$AcceptDialog.get_label().align = Label.ALIGN_CENTER
|
||||
$AcceptDialog.get_label().valign = Label.VALIGN_CENTER
|
||||
# Set the player name according to the system username. Fallback to the path.
|
||||
@@ -46,11 +46,11 @@ func stop_game():
|
||||
|
||||
func _close_network():
|
||||
if get_tree().is_connected("server_disconnected", self, "_close_network"):
|
||||
get_tree().disconnect("server_disconnected", self, "_close_network")
|
||||
get_tree().disconnect(&"server_disconnected", self._close_network)
|
||||
if get_tree().is_connected("connection_failed", self, "_close_network"):
|
||||
get_tree().disconnect("connection_failed", self, "_close_network")
|
||||
get_tree().disconnect(&"connection_failed", self._close_network)
|
||||
if get_tree().is_connected("connected_to_server", self, "_connected"):
|
||||
get_tree().disconnect("connected_to_server", self, "_connected")
|
||||
get_tree().disconnect(&"connected_to_server", self._connected)
|
||||
stop_game()
|
||||
$AcceptDialog.show_modal()
|
||||
$AcceptDialog.get_close_button().grab_focus()
|
||||
@@ -71,8 +71,8 @@ func _peer_disconnected(id):
|
||||
|
||||
func _on_Host_pressed():
|
||||
peer = WebSocketServer.new()
|
||||
peer.listen(DEF_PORT, PoolStringArray(["ludus"]), true)
|
||||
get_tree().connect("server_disconnected", self, "_close_network")
|
||||
peer.listen(DEF_PORT, PackedStringArray(["ludus"]), true)
|
||||
get_tree().connect(&"server_disconnected", self._close_network)
|
||||
get_tree().set_network_peer(peer)
|
||||
_game.add_player(1, _name_edit.text)
|
||||
start_game()
|
||||
@@ -84,8 +84,8 @@ func _on_Disconnect_pressed():
|
||||
|
||||
func _on_Connect_pressed():
|
||||
peer = WebSocketClient.new()
|
||||
peer.connect_to_url("ws://" + _host_edit.text + ":" + str(DEF_PORT), PoolStringArray([PROTO_NAME]), true)
|
||||
get_tree().connect("connection_failed", self, "_close_network")
|
||||
get_tree().connect("connected_to_server", self, "_connected")
|
||||
peer.connect_to_url("ws://" + _host_edit.text + ":" + str(DEF_PORT), PackedStringArray([PROTO_NAME]), true)
|
||||
get_tree().connect(&"connection_failed", self._close_network)
|
||||
get_tree().connect(&"connected_to_server", self._connected)
|
||||
get_tree().set_network_peer(peer)
|
||||
start_game()
|
||||
|
||||
Reference in New Issue
Block a user