-
Notifications
You must be signed in to change notification settings - Fork 1
/
Create.cs
52 lines (47 loc) · 1.34 KB
/
Create.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
using Godot;
using System;
public partial class Create : Control
{
public override void _Ready()
{
var save=new ConfigFile();
save.Load("user://LocalChat.ini");
GetNode<LineEdit>("VBoxContainer/HBoxContainer2/LineEdit").Text=(string)save.GetValue("Host","Port",1145);
}
public override void _Process(double delta)
{
if (GetNode<LineEdit>("VBoxContainer/HBoxContainer2/LineEdit").Text=="" || GetNode<LineEdit>("VBoxContainer/HBoxContainer2/LineEdit").Text==null)
{
GetNode<Button>("VBoxContainer/HBoxContainer/Create").Disabled=true;
}
else
{
GetNode<Button>("VBoxContainer/HBoxContainer/Create").Disabled=false;
}
}
public void _on_back_pressed()
{
GetTree().ChangeSceneToFile("res://Menu.tscn");
}
public void _on_create_pressed()
{
var port=GetNode<LineEdit>("VBoxContainer/HBoxContainer2/LineEdit").Text.ToInt();
SavePort(port);
GetNode<AutoLoad>("/root/AutoLoad").port=port;
var server=new ENetMultiplayerPeer();
var err=server.CreateServer(port);
Multiplayer.MultiplayerPeer=server;
if (err==Error.Ok)
{
GetTree().ChangeSceneToFile("res://ChatRoom/ChatRoom.tscn");
}
GD.Print(err.ToString()+" "+port.ToString()+" ");
}
private static void SavePort(int ip)
{
var save=new ConfigFile();
save.Load("user://LocalChat.ini");
save.SetValue("Host","Port",ip);
save.Save("user://LocalChat.ini");
}
}