Server list, lighting/los optimization
This commit is contained in:
@@ -9,7 +9,7 @@ namespace Subsurface
|
||||
{
|
||||
class MainMenuScreen : Screen
|
||||
{
|
||||
public enum Tabs { Main = 0, NewGame = 1, LoadGame = 2, JoinServer = 3, HostServer = 4 }
|
||||
public enum Tabs { Main = 0, NewGame = 1, LoadGame = 2, HostServer = 3 }
|
||||
|
||||
private GUIFrame[] menuTabs;
|
||||
private GUIListBox mapList;
|
||||
@@ -49,8 +49,8 @@ namespace Subsurface
|
||||
//button.Enabled = false;
|
||||
|
||||
button = new GUIButton(new Rectangle(0, 120, 0, 30), "Join Server", Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.Main]);
|
||||
button.UserData = (int)Tabs.JoinServer;
|
||||
button.OnClicked = SelectTab;
|
||||
//button.UserData = (int)Tabs.JoinServer;
|
||||
button.OnClicked = JoinServerClicked;
|
||||
|
||||
button = new GUIButton(new Rectangle(0, 180, 0, 30), "Host Server", Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.Main]);
|
||||
button.UserData = (int)Tabs.HostServer;
|
||||
@@ -143,19 +143,22 @@ namespace Subsurface
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
menuTabs[(int)Tabs.JoinServer] = new GUIFrame(panelRect, GUI.style);
|
||||
//menuTabs[(int)Tabs.JoinServer].Padding = GUI.style.smallPadding;
|
||||
//menuTabs[(int)Tabs.JoinServer] = new GUIFrame(panelRect, GUI.style);
|
||||
////menuTabs[(int)Tabs.JoinServer].Padding = GUI.style.smallPadding;
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 0, 0, 30), "Join Server", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
|
||||
//new GUITextBlock(new Rectangle(0, 0, 0, 30), "Join Server", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 30, 0, 30), "Your Name:", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
|
||||
clientNameBox = new GUITextBox(new Rectangle(0, 60, 200, 30), Color.White, Color.Black, Alignment.CenterX, Alignment.CenterX, null, menuTabs[(int)Tabs.JoinServer]);
|
||||
//new GUITextBlock(new Rectangle(0, 30, 0, 30), "Your Name:", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
|
||||
//clientNameBox = new GUITextBox(new Rectangle(0, 60, 200, 30), Color.White, Color.Black, Alignment.CenterX, Alignment.CenterX, null, menuTabs[(int)Tabs.JoinServer]);
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server IP:", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
|
||||
ipBox = new GUITextBox(new Rectangle(0, 130, 200, 30), Color.White, Color.Black, Alignment.CenterX, Alignment.CenterX, null, menuTabs[(int)Tabs.JoinServer]);
|
||||
|
||||
GUIButton joinButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Join", Alignment.BottomCenter, GUI.style, menuTabs[(int)Tabs.JoinServer]);
|
||||
joinButton.OnClicked = JoinServer;
|
||||
//new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server IP:", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
|
||||
//ipBox = new GUITextBox(new Rectangle(0, 130, 200, 30), Color.White, Color.Black, Alignment.CenterX, Alignment.CenterX, null, menuTabs[(int)Tabs.JoinServer]);
|
||||
|
||||
//GUIButton joinButton = new GUIButton(new Rectangle(0, 200, 200, 30), "Join", Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.JoinServer]);
|
||||
//joinButton.OnClicked = JoinServer;
|
||||
|
||||
//GUIButton serverListButton = new GUIButton(new Rectangle(0, 0, 230, 30), "Server List", Alignment.BottomCenter, GUI.style, menuTabs[(int)Tabs.JoinServer]);
|
||||
//serverListButton.OnClicked = ServerListClicked;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
@@ -176,7 +179,7 @@ namespace Subsurface
|
||||
hostButton.OnClicked = HostServerClicked;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
for (int i = 1; i < 5; i++ )
|
||||
for (int i = 1; i < 4; i++ )
|
||||
{
|
||||
button = new GUIButton(new Rectangle(-20, -20, 100, 30), "Back", Alignment.TopLeft, GUI.style, menuTabs[i]);
|
||||
button.OnClicked = PreviousTab;
|
||||
@@ -196,16 +199,28 @@ namespace Subsurface
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool JoinServerClicked(GUIButton button, object obj)
|
||||
{
|
||||
Game1.ServerListScreen.Select();
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool HostServerClicked(GUIButton button, object obj)
|
||||
{
|
||||
string name = serverNameBox.Text;
|
||||
if (string.IsNullOrEmpty(name)) name = "Server";
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
serverNameBox.Flash();
|
||||
return false;
|
||||
}
|
||||
|
||||
int port;
|
||||
if (!int.TryParse(portBox.Text, out port))
|
||||
if (!int.TryParse(portBox.Text, out port) || port < 0 || port > 65535)
|
||||
{
|
||||
DebugConsole.ThrowError("ERROR: " + portBox.Text + " is not a valid port. Using the default port " + NetworkMember.DefaultPort);
|
||||
port = NetworkMember.DefaultPort;
|
||||
portBox.Text = NetworkMember.DefaultPort.ToString();
|
||||
portBox.Flash();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Game1.NetworkMember = new GameServer(name, port);
|
||||
|
||||
@@ -145,7 +145,7 @@ namespace Subsurface
|
||||
|
||||
//submarine list ------------------------------------------------------------------
|
||||
|
||||
int columnWidth = infoFrame.Rect.Width / 3 - 30;
|
||||
int columnWidth = infoFrame.Rect.Width / 5 - 30;
|
||||
int columnX = 0;
|
||||
|
||||
new GUITextBlock(new Rectangle(columnX, 120, columnWidth, 30), "Selected submarine:", GUI.style, infoFrame);
|
||||
@@ -177,7 +177,8 @@ namespace Subsurface
|
||||
|
||||
new GUITextBlock(new Rectangle(columnX, 120, 0, 30), "Selected game mode: ", GUI.style, infoFrame);
|
||||
modeList = new GUIListBox(new Rectangle(columnX, 150, columnWidth, infoFrame.Rect.Height - 150 - 80), GUI.style, infoFrame);
|
||||
|
||||
|
||||
|
||||
foreach (GameModePreset mode in GameModePreset.list)
|
||||
{
|
||||
if (mode.IsSinglePlayer) continue;
|
||||
@@ -191,7 +192,18 @@ namespace Subsurface
|
||||
textBlock.UserData = mode;
|
||||
}
|
||||
|
||||
columnX += columnWidth + 20;
|
||||
columnX += columnWidth;
|
||||
|
||||
//gamemode description ------------------------------------------------------------------
|
||||
|
||||
|
||||
var modeDescription = new GUITextBlock(
|
||||
new Rectangle(columnX, 150, (int)(columnWidth * 1.5f), infoFrame.Rect.Height - 150 - 80),
|
||||
"", Color.Black*0.3f, Color.White, Alignment.TopLeft, Alignment.TopLeft, GUI.style, infoFrame, true);
|
||||
|
||||
modeList.UserData = modeDescription;
|
||||
|
||||
columnX += modeDescription.Rect.Width + 40;
|
||||
|
||||
//duration ------------------------------------------------------------------
|
||||
|
||||
@@ -249,16 +261,18 @@ namespace Subsurface
|
||||
serverMessage.Enabled = Game1.Server != null;
|
||||
ServerName = (Game1.Server==null) ? "Server" : Game1.Server.Name;
|
||||
|
||||
modeList.OnSelected += SelectMode;
|
||||
|
||||
infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "startButton"));
|
||||
|
||||
if (IsServer && Game1.Server != null)
|
||||
{
|
||||
GUIButton startButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", Alignment.TopRight, GUI.style, infoFrame);
|
||||
GUIButton startButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", Alignment.BottomRight, GUI.style, infoFrame);
|
||||
startButton.OnClicked = Game1.Server.StartGame;
|
||||
startButton.UserData = "startButton";
|
||||
|
||||
//mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby);
|
||||
modeList.OnSelected = Game1.Server.UpdateNetLobby;
|
||||
modeList.OnSelected += Game1.Server.UpdateNetLobby;
|
||||
durationBar.OnMoved = Game1.Server.UpdateNetLobby;
|
||||
|
||||
if (subList.CountChildren > 0) subList.Select(0);
|
||||
@@ -412,7 +426,6 @@ namespace Subsurface
|
||||
GUI.Draw((float)deltaTime, spriteBatch, null);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
}
|
||||
|
||||
public void NewChatMessage(string message, Color color)
|
||||
@@ -478,6 +491,21 @@ namespace Subsurface
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool SelectMode(object obj)
|
||||
{
|
||||
GameModePreset modePreset = obj as GameModePreset;
|
||||
if (modePreset == null) return false;
|
||||
|
||||
GUITextBlock description = modeList.UserData as GUITextBlock;
|
||||
|
||||
description.Text = modePreset.Description;
|
||||
|
||||
//if (Game1.Server != null) Game1.Server.UpdateNetLobby(null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private bool SelectSeed(GUITextBox textBox, string seed)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(seed))
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
using System;
|
||||
using Lidgren.Network;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Subsurface.Networking;
|
||||
using FarseerPhysics;
|
||||
using FarseerPhysics.Factories;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using RestSharp;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class ServerListScreen : Screen
|
||||
{
|
||||
private GUIFrame menu;
|
||||
|
||||
private GUIListBox serverList;
|
||||
|
||||
private GUIButton joinButton;
|
||||
|
||||
private GUITextBox clientNameBox, ipBox;
|
||||
|
||||
public ServerListScreen()
|
||||
{
|
||||
int width = Math.Min(Game1.GraphicsWidth - 160, 1000);
|
||||
int height = Math.Min(Game1.GraphicsHeight - 160, 700);
|
||||
|
||||
Rectangle panelRect = new Rectangle(0, 0, width, height);
|
||||
|
||||
menu = new GUIFrame(panelRect, null, Alignment.Center, GUI.style);
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 0, 0, 30), "Join Server", GUI.style, Alignment.CenterX, Alignment.CenterX, menu);
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 30, 0, 30), "Your Name:", GUI.style, menu);
|
||||
clientNameBox = new GUITextBox(new Rectangle(0, 60, 200, 30), GUI.style, menu);
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server IP:", GUI.style, menu);
|
||||
ipBox = new GUITextBox(new Rectangle(0, 130, 200, 30), GUI.style, menu);
|
||||
|
||||
int middleX = (int)(width * 0.4f);
|
||||
|
||||
serverList = new GUIListBox(new Rectangle(middleX,60,0,(int)(height*0.7f)), GUI.style, menu);
|
||||
serverList.OnSelected = SelectServer;
|
||||
|
||||
new GUITextBlock(new Rectangle(middleX, 30, 0, 30), "Name", GUI.style, menu);
|
||||
new GUITextBlock(new Rectangle(middleX, 30, 0, 30), "Players", GUI.style, Alignment.TopLeft, Alignment.TopCenter, menu);
|
||||
new GUITextBlock(new Rectangle(middleX, 30, 0, 30), "Game running", GUI.style, Alignment.TopLeft, Alignment.TopRight, menu);
|
||||
|
||||
joinButton = new GUIButton(new Rectangle(-170, 0, 150, 30), "Refresh", Alignment.BottomRight, GUI.style, menu);
|
||||
joinButton.OnClicked = RefreshServers;
|
||||
|
||||
joinButton = new GUIButton(new Rectangle(0,0,150,30), "Join", Alignment.BottomRight, GUI.style, menu);
|
||||
joinButton.OnClicked = JoinServer;
|
||||
//joinButton.Enabled = false;
|
||||
}
|
||||
|
||||
public override void Select()
|
||||
{
|
||||
base.Select();
|
||||
|
||||
UpdateServerList();
|
||||
}
|
||||
|
||||
private bool SelectServer(object obj)
|
||||
{
|
||||
string ip = obj as string;
|
||||
if (string.IsNullOrWhiteSpace(ip)) return false;
|
||||
|
||||
ipBox.Text = ip;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RefreshServers(GUIButton button, object obj)
|
||||
{
|
||||
UpdateServerList();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void UpdateServerList()
|
||||
{
|
||||
serverList.ClearChildren();
|
||||
|
||||
string masterServerData = GetMasterServerData();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(masterServerData))
|
||||
{
|
||||
var nameText = new GUITextBlock(new Rectangle(0, 0, 0, 20), "Couldn't find any servers", GUI.style, serverList);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (masterServerData.Substring(0,5).ToLower()=="error")
|
||||
{
|
||||
DebugConsole.ThrowError("Error while connecting to master server ("+masterServerData+")!");
|
||||
return;
|
||||
}
|
||||
|
||||
string[] lines = masterServerData.Split('\n');
|
||||
|
||||
for (int i = 0; i<lines.Length; i++)
|
||||
{
|
||||
string[] arguments = lines[i].Split('|');
|
||||
if (arguments.Length < 3) continue;
|
||||
|
||||
string IP = arguments[0];
|
||||
string port = arguments[1];
|
||||
string serverName = arguments[2];
|
||||
string gameStarted = (arguments.Length > 3) ? arguments[3] : "";
|
||||
string playerCountStr = (arguments.Length > 4) ? arguments[4] : "";
|
||||
|
||||
var serverFrame = new GUIFrame(new Rectangle(0,0,0,20), (i%2 == 0) ? Color.Transparent : Color.White*0.2f, null, serverList);
|
||||
serverFrame.UserData = IP+":"+port;
|
||||
serverFrame.HoverColor = Color.Gold * 0.2f;
|
||||
serverFrame.SelectedColor = Color.Gold * 0.5f;
|
||||
|
||||
var nameText = new GUITextBlock(new Rectangle(0,0,0,0), serverName, GUI.style, serverFrame);
|
||||
|
||||
int playerCount, maxPlayers;
|
||||
playerCount = GameClient.ByteToPlayerCount((byte)int.Parse(playerCountStr), out maxPlayers);
|
||||
|
||||
var playerCountText = new GUITextBlock(new Rectangle(0, 0, 0, 0), playerCount+"/"+maxPlayers, GUI.style, Alignment.Left, Alignment.TopCenter, serverFrame);
|
||||
var gameStartedText = new GUITextBlock(new Rectangle(0, 0, 0, 0), gameStarted=="1" ? "Yes" : "No", GUI.style, Alignment.Left, Alignment.TopRight, serverFrame);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private string GetMasterServerData()
|
||||
{
|
||||
RestClient client = null;
|
||||
try
|
||||
{
|
||||
client = new RestClient(NetworkMember.MasterServerUrl);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Error while connecting to master server", e);
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
var request = new RestRequest("masterserver.php", Method.GET);
|
||||
request.AddParameter("gamename", "subsurface"); // adds to POST or URL querystring based on Method
|
||||
request.AddParameter("action", "listservers"); // adds to POST or URL querystring based on Method
|
||||
|
||||
|
||||
// easily add HTTP Headers
|
||||
//request.AddHeader("header", "value");
|
||||
|
||||
//// add files to upload (works with compatible verbs)
|
||||
//request.AddFile(path);
|
||||
|
||||
// execute the request
|
||||
RestResponse response = (RestResponse)client.Execute(request);
|
||||
|
||||
|
||||
if (response.StatusCode!= System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
DebugConsole.ThrowError("Error while connecting to master server (" +response.StatusCode+": "+response.StatusDescription+")");
|
||||
return "";
|
||||
}
|
||||
|
||||
return response.Content; // raw content as string
|
||||
|
||||
}
|
||||
|
||||
private bool JoinServer(GUIButton button, object obj)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(clientNameBox.Text))
|
||||
{
|
||||
clientNameBox.Flash();
|
||||
return false;
|
||||
}
|
||||
|
||||
string ip = ipBox.Text;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(ip))
|
||||
{
|
||||
ipBox.Flash();
|
||||
return false;
|
||||
}
|
||||
|
||||
Game1.NetworkMember = new GameClient(clientNameBox.Text);
|
||||
Game1.Client.ConnectToServer(ip);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||
{
|
||||
graphics.Clear(Color.CornflowerBlue);
|
||||
|
||||
Game1.GameScreen.DrawMap(graphics, spriteBatch);
|
||||
|
||||
spriteBatch.Begin();
|
||||
|
||||
menu.Draw(spriteBatch);
|
||||
|
||||
//if (previewPlayer!=null) previewPlayer.Draw(spriteBatch);
|
||||
|
||||
GUI.Draw((float)deltaTime, spriteBatch, null);
|
||||
|
||||
spriteBatch.End();
|
||||
}
|
||||
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
menu.Update((float)deltaTime);
|
||||
|
||||
GUI.Update((float)deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user