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