generated from Persson-dev/Godot-Xmake
moved network interface
This commit is contained in:
@@ -9,8 +9,6 @@ namespace blitz {
|
||||
|
||||
void MainMenu::_bind_methods() {
|
||||
godot::ClassDB::bind_method(godot::D_METHOD("on_connected"), &MainMenu::OnConnected);
|
||||
ADD_SIGNAL(MethodInfo("create_game", PropertyInfo(Variant::INT, "port"), PropertyInfo(Variant::BOOL, "dedicated")));
|
||||
ADD_SIGNAL(MethodInfo("join_game", PropertyInfo(Variant::STRING, "address"), PropertyInfo(Variant::INT, "port")));
|
||||
ADD_SIGNAL(MethodInfo("change_scene"));
|
||||
}
|
||||
|
||||
@@ -30,9 +28,15 @@ void MainMenu::_ready() {
|
||||
DEV_ASSERT(m_CreateButton);
|
||||
DEV_ASSERT(m_QuitButton);
|
||||
|
||||
m_NetworkInterface = Object::cast_to<NetworkInterface>(get_parent()->find_child("Network"));
|
||||
DEV_ASSERT(m_NetworkInterface);
|
||||
|
||||
m_JoinButton->connect("pressed", callable_mp(this, &MainMenu::OnJoinPressed));
|
||||
m_CreateButton->connect("pressed", callable_mp(this, &MainMenu::OnCreatePressed));
|
||||
m_QuitButton->connect("pressed", callable_mp(this, &MainMenu::OnQuitPressed));
|
||||
|
||||
m_NetworkInterface->connect("local_player_connected", callable_mp(this, &MainMenu::OnConnected));
|
||||
m_NetworkInterface->connect("server_disconnected", callable_mp(this, &MainMenu::OnDisconnected));
|
||||
}
|
||||
|
||||
void MainMenu::OnConnected() {
|
||||
@@ -40,16 +44,33 @@ void MainMenu::OnConnected() {
|
||||
set_visible(false);
|
||||
}
|
||||
|
||||
void MainMenu::OnDisconnected() {
|
||||
set_visible(true);
|
||||
EnableButtons();
|
||||
}
|
||||
|
||||
void MainMenu::OnJoinPressed() {
|
||||
emit_signal("join_game", "localhost", 25565);
|
||||
DisableButtons();
|
||||
m_NetworkInterface->JoinGame("localhost", 25565);
|
||||
}
|
||||
|
||||
void MainMenu::OnCreatePressed() {
|
||||
emit_signal("create_game", 25565, false);
|
||||
DisableButtons();
|
||||
m_NetworkInterface->CreateGame(25565);
|
||||
}
|
||||
|
||||
void MainMenu::OnQuitPressed() {
|
||||
get_tree()->quit();
|
||||
}
|
||||
|
||||
void MainMenu::DisableButtons() {
|
||||
m_JoinButton->set_disabled(true);
|
||||
m_CreateButton->set_disabled(true);
|
||||
}
|
||||
|
||||
void MainMenu::EnableButtons() {
|
||||
m_JoinButton->set_disabled(false);
|
||||
m_CreateButton->set_disabled(false);
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
Reference in New Issue
Block a user