Reorganize multiplayer menu

main
copygirl 11 months ago
parent e7b6c15600
commit 767debc813
  1. 11
      ui/MultiplayerMenu.cs
  2. 82
      ui/menu.tscn

@ -97,7 +97,16 @@ public partial class MultiplayerMenu : MarginContainer
{
var address = AddressInput.Text;
if (address == "") address = AddressInput.PlaceholderText;
var port = (ushort)RoundToInt(PortInput.Value);
ushort port;
var colonIndex = address.LastIndexOf(':');
if (colonIndex >= 0) {
if (!ushort.TryParse(address[(colonIndex+1)..], out port)) port = 0;
address = address[..colonIndex];
} else {
port = ushort.Parse(AddressInput.PlaceholderText.Split(':')[1]);
}
Game.Instance.MultiplayerManager.Connect(address, port);
UpdateStatus(Status.Connecting);
}

@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://c5ooi36ibspfo"]
[gd_scene load_steps=12 format=3 uid="uid://c5ooi36ibspfo"]
[ext_resource type="Script" path="res://ui/Menu.cs" id="1_5qxrt"]
[ext_resource type="Script" path="res://ui/MultiplayerMenu.cs" id="2_3ulcb"]
@ -10,6 +10,8 @@ font_size = 22
[sub_resource type="LabelSettings" id="LabelSettings_nmchh"]
font_color = Color(0.75, 0.75, 0.75, 1)
[sub_resource type="LabelSettings" id="LabelSettings_ianb0"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ulror"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_fwm45"]
@ -111,10 +113,10 @@ theme_override_constants/margin_bottom = 8
script = ExtResource("2_3ulcb")
StatusLabel = NodePath("VBoxContainer/HBoxContainer/Status")
WhenDisconnected = NodePath("VBoxContainer/WhenDisconnected")
AddressInput = NodePath("VBoxContainer/WhenDisconnected/GridContainer/Address")
PortInput = NodePath("VBoxContainer/WhenDisconnected/GridContainer/Port")
AddressInput = NodePath("VBoxContainer/WhenDisconnected/HBoxContainer/Address")
PortInput = NodePath("VBoxContainer/WhenDisconnected/HBoxContainer2/Port")
ConnectButton = NodePath("VBoxContainer/WhenDisconnected/HBoxContainer/Connect")
HostButton = NodePath("VBoxContainer/WhenDisconnected/HBoxContainer/Host")
HostButton = NodePath("VBoxContainer/WhenDisconnected/HBoxContainer2/Create")
WhenServer = NodePath("VBoxContainer/WhenServer")
PortDisplay = NodePath("VBoxContainer/WhenServer/HBoxContainer/Port")
WhenConnected = NodePath("VBoxContainer/WhenConnected")
@ -143,58 +145,68 @@ horizontal_alignment = 1
[node name="WhenDisconnected" type="VBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer"]
layout_mode = 2
[node name="GridContainer" type="GridContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected"]
[node name="HSeparator" type="HSeparator" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected"]
layout_mode = 2
columns = 3
[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/GridContainer"]
layout_mode = 2
text = "Address"
horizontal_alignment = 1
[node name="Control" type="Control" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/GridContainer"]
[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected"]
layout_mode = 2
text = "Connect to Server"
label_settings = SubResource("LabelSettings_ianb0")
[node name="Label2" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/GridContainer"]
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected"]
layout_mode = 2
text = "Port"
horizontal_alignment = 1
[node name="Address" type="LineEdit" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/GridContainer"]
[node name="Address" type="LineEdit" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
placeholder_text = "localhost"
placeholder_text = "localhost:9713"
virtual_keyboard_type = 6
secret = true
[node name="Label3" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/GridContainer"]
[node name="ShowAddress" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/HBoxContainer"]
custom_minimum_size = Vector2(30, 0)
layout_mode = 2
text = ":"
toggle_mode = true
text = "👁"
[node name="Port" type="SpinBox" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/GridContainer"]
[node name="Connect" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/HBoxContainer"]
custom_minimum_size = Vector2(112, 0)
layout_mode = 2
min_value = 1024.0
max_value = 65535.0
value = 9713.0
rounded = true
alignment = 2
text = "Connect"
[node name="ShowAddress" type="CheckButton" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected"]
[node name="HSeparator2" type="HSeparator" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected"]
layout_mode = 2
text = "Show Server Address"
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected"]
[node name="Label2" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected"]
layout_mode = 2
text = "Host a Server"
[node name="Connect" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/HBoxContainer"]
[node name="HBoxContainer2" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected"]
layout_mode = 2
size_flags_horizontal = 3
text = "Connect to Server"
[node name="Host" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/HBoxContainer"]
[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/HBoxContainer2"]
custom_minimum_size = Vector2(80, 0)
layout_mode = 2
text = "Port: "
horizontal_alignment = 2
[node name="Port" type="SpinBox" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/HBoxContainer2"]
layout_mode = 2
size_flags_horizontal = 3
text = "Host Server"
min_value = 1024.0
max_value = 65535.0
value = 9713.0
rounded = true
alignment = 2
[node name="Create" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/HBoxContainer2"]
custom_minimum_size = Vector2(112, 0)
layout_mode = 2
text = "Create
"
[node name="HBoxContainer3" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected"]
layout_mode = 2
[node name="WhenServer" type="VBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer"]
visible = false
@ -355,9 +367,9 @@ text = "Return to Game
"
[connection signal="tab_changed" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer" to="." method="OnTabChanged"]
[connection signal="toggled" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/ShowAddress" to="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer" method="OnShowAddressToggled"]
[connection signal="toggled" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/HBoxContainer/ShowAddress" to="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer" method="OnShowAddressToggled"]
[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/HBoxContainer/Connect" to="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer" method="OnConnectPressed"]
[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/HBoxContainer/Host" to="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer" method="OnHostPressed"]
[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenDisconnected/HBoxContainer2/Create" to="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer" method="OnHostPressed"]
[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer/VBoxContainer/WhenConnected/Disconnect" to="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer" method="OnDisconnectPressed"]
[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/Quit" to="." method="OnQuitPressed"]
[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/Return" to="." method="OnReturnPressed"]

Loading…
Cancel
Save