-
Notifications
You must be signed in to change notification settings - Fork 1
/
Join.cs
60 lines (54 loc) · 1.87 KB
/
Join.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using Godot;
using System;
using GodotTask;
public partial class Join : Control
{
public override void _Ready()
{
Multiplayer.ConnectedToServer+=connected;
var save=new ConfigFile();
save.Load("user://LocalChat.ini");
GetNode<LineEdit>("VBoxContainer/HBoxContainer2/LineEdit").Text=(string)save.GetValue("User","UsedIP","");
GetNode<LineEdit>("VBoxContainer/HBoxContainer2/LineEdit2").Text=(string)save.GetValue("User","UsedPort",1145);
}
public override void _Process(double delta)
{
if (GetNode<LineEdit>("VBoxContainer/HBoxContainer2/LineEdit").Text=="" || GetNode<LineEdit>("VBoxContainer/HBoxContainer2/LineEdit").Text==null || GetNode<LineEdit>("VBoxContainer/HBoxContainer2/LineEdit2").Text=="" || GetNode<LineEdit>("VBoxContainer/HBoxContainer2/LineEdit2").Text==null)
{
GetNode<Button>("VBoxContainer/HBoxContainer/Join").Disabled=true;
}
else
{
GetNode<Button>("VBoxContainer/HBoxContainer/Join").Disabled=false;
}
}
public void _on_back_pressed()
{
GetTree().ChangeSceneToFile("res://Menu.tscn");
}
public void _on_join_pressed()
{
var ip=GetNode<LineEdit>("VBoxContainer/HBoxContainer2/LineEdit").Text;
var port=GetNode<LineEdit>("VBoxContainer/HBoxContainer2/LineEdit2").Text.ToInt();
SaveIP(ip,port);
GetNode<AutoLoad>("/root/AutoLoad").ip=ip;
GetNode<AutoLoad>("/root/AutoLoad").port=port;
var client=new ENetMultiplayerPeer();
var err=client.CreateClient(ip,port);
Multiplayer.MultiplayerPeer=client;
GD.Print(err.ToString()+" "+ip.ToString()+":"+port.ToString()+" ");
}
private static void SaveIP(string ip,int port)
{
var save=new ConfigFile();
save.Load("user://LocalChat.ini");
save.SetValue("User","UsedIP",ip);
save.SetValue("User","UsedPort",port);
save.Save("user://LocalChat.ini");
}
private async void connected()
{
await GDTask.Delay(1000);
GetTree().ChangeSceneToFile("res://ChatRoom/ChatRoom.tscn");
}
}