Update start_game_menu.cs

This commit is contained in:
MarcEricMartel 2023-06-10 14:49:20 -04:00
parent f86013b117
commit 0c6838e710

View File

@ -2,7 +2,7 @@ using Godot;
using System;
public partial class start_game_menu : Control {
enum _state { START, LAN, HOST, QUIT };
enum _state { START, LAN, HOST, JOIN, QUIT };
enum _gameType { SINGLE, LOCAL, LAN };
private _state _currState = _state.START;
@ -81,6 +81,20 @@ public partial class start_game_menu : Control {
_ip.Set("visible", false);
_lip.Set("visible", false);
break;
case _state.JOIN:
Error = "Waiting for server...";
_single.Set("visible", false);
_localMulti.Set("visible", false);
_LANMulti.Set("visible", false);
_cancel.Set("visible", true);
_yes.Set("visible", false);
_no.Set("visible", false);
_join.Set("visible", false);
_host.Set("visible", false);
_quit.Set("visible", false);
_ip.Set("visible", false);
_lip.Set("visible", false);
break;
default: return;
}
_currState = value;
@ -112,7 +126,7 @@ public partial class start_game_menu : Control {
State = _state.START;
}
private void startGame(_gameType type) {
private void startGame(_gameType type, long id = 0) {
switch (type) {
case _gameType.SINGLE:
@ -121,7 +135,7 @@ public partial class start_game_menu : Control {
break;
case _gameType.LAN:
Error = "YIPPE! " + id.ToString();
break;
default: return;
}
@ -133,9 +147,8 @@ public partial class start_game_menu : Control {
ENetMultiplayerPeer peer = new ENetMultiplayerPeer();
peer.CreateServer(666, 2);
Multiplayer.MultiplayerPeer = peer;
peer.PeerConnected += (long id) => startGame(_gameType.LAN, id);
State = _state.HOST;
startGame(_gameType.LAN);
}
else {
string ip = _ip.Get("text").ToString();
@ -158,8 +171,7 @@ public partial class start_game_menu : Control {
ENetMultiplayerPeer peer = new ENetMultiplayerPeer();
peer.CreateClient(ip, 666);
Multiplayer.MultiplayerPeer = peer;
startGame(_gameType.LAN);
State = _state.JOIN;
}
}
}