Neutvoorking Mennu

This commit is contained in:
MarcEricMartel 2023-06-10 14:38:07 -04:00
parent 59eca4500c
commit 0137bbfd31

View File

@ -1,9 +1,9 @@
using Godot;
using System;
public partial class start_game_menu : Control
{
enum _state { START, LAN, QUIT };
public partial class start_game_menu : Control {
enum _state { START, LAN, HOST, QUIT };
enum _gameType { SINGLE, LOCAL, LAN };
private _state _currState = _state.START;
@ -67,6 +67,21 @@ public partial class start_game_menu : Control
_ip.Set("visible", false);
_lip.Set("visible", false);
break;
case _state.HOST:
Error = "Waiting for peer to join...";
_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;
}}
@ -85,11 +100,11 @@ public partial class start_game_menu : Control
_error = GetNode<Label>(_path + "lbl_err");
_ip = GetNode<TextEdit>(_path + "txt_IP");
_lip = GetNode<Label>(_path + "lbl_IP");
_single.Pressed += () => startSingleGame();
_localMulti.Pressed += () => startLocalMultiGame();
_single.Pressed += () => startGame(_gameType.SINGLE);
_localMulti.Pressed += () => startGame(_gameType.LOCAL);
_LANMulti.Pressed += () => State = _state.LAN;
_host.Pressed += () => startLANMultiGame();
_join.Pressed += () => startLANMultiGame(false);
_host.Pressed += () => setupLANMultiGame();
_join.Pressed += () => setupLANMultiGame(false);
_quit.Pressed += () => State = _state.QUIT;
_cancel.Pressed += () => State = _state.START;
_no.Pressed += () => State = _state.START;
@ -100,34 +115,41 @@ public partial class start_game_menu : Control
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta){}
private void startSingleGame() {
private void startGame(_gameType type) {
switch (type) {
case _gameType.SINGLE:
break;
case _gameType.LOCAL:
break;
case _gameType.LAN:
break;
default: return;
}
}
private void startLocalMultiGame() {
}
private void startLANMultiGame(bool isHost = true) {
private void setupLANMultiGame(bool isHost = true) {
const string ERR = "Invalid IP address.";
if (isHost) {
ENetMultiplayerPeer peer = new ENetMultiplayerPeer ();
ENetMultiplayerPeer peer = new ENetMultiplayerPeer();
peer.CreateServer(666, 2);
Multiplayer.MultiplayerPeer = peer;
State = _state.HOST;
}
else {
string ip = _ip.Get("text").ToString();
if (!ip.Contains('.')) {
Error = ERR;
return;
}
string[] ips = ip.Split('.');
if (ips.Length != 4) {
Error = ERR;
return;
}
for (int x =0; x < 4; ++x) {
int val = 0;
if (!int.TryParse(ips[0], out val) || val < 0 || val > 255) {
@ -135,8 +157,7 @@ public partial class start_game_menu : Control
return;
}
}
ENetMultiplayerPeer peer = new ENetMultiplayerPeer ();
ENetMultiplayerPeer peer = new ENetMultiplayerPeer();
peer.CreateClient(ip, 666);
Multiplayer.MultiplayerPeer = peer;
}