Remove BS from Viewport

This commit is contained in:
Paul Chote
2010-07-11 16:17:20 +12:00
parent b4a84deb86
commit 6d49dcece1
4 changed files with 41 additions and 56 deletions

View File

@@ -256,6 +256,9 @@ namespace OpenRA
Log.Write("sync", "{0}", f.Second);
}
public static event Action ConnectionStateChanged = () => { };
static ConnectionState lastConnectionState = ConnectionState.PreConnecting;
static void Tick()
{
if (packageChangePending)
@@ -275,6 +278,12 @@ namespace OpenRA
return;
}
if (orderManager.Connection.ConnectionState != lastConnectionState)
{
lastConnectionState = orderManager.Connection.ConnectionState;
ConnectionStateChanged();
}
int t = Environment.TickCount;
int dt = t - lastTime;
if (dt >= Settings.Timestep)
@@ -398,6 +407,7 @@ namespace OpenRA
orderManager.StartGame();
}
public static event Action OnGameStart = () => { };
internal static void StartGame()
{
LoadMap(LobbyInfo.GlobalSettings.Map);
@@ -411,6 +421,7 @@ namespace OpenRA
viewport.GoToStartLocation(world.LocalPlayer);
orderManager.StartGame();
OnGameStart();
}
public static Stance ChooseInitialStance(Player p, Player q)

View File

@@ -64,8 +64,6 @@ namespace OpenRA.Graphics
this.scrollPosition = Game.CellSize* mapStart;
}
ConnectionState lastConnectionState = ConnectionState.PreConnecting;
bool gameWasStarted = false;
public void DrawRegions( World world )
{
Timer.Time( "DrawRegions start" );
@@ -79,55 +77,7 @@ namespace OpenRA.Graphics
renderer.BeginFrame(r1, r2, scrollPosition.ToInt2());
world.WorldRenderer.Draw();
Timer.Time( "worldRenderer: {0}" );
if( Game.orderManager.GameStarted && world.LocalPlayer != null)
{
if (!gameWasStarted)
{
Chrome.rootWidget.OpenWindow("INGAME_ROOT");
gameWasStarted = true;
}
}
else
{
// Still hacky, but at least it uses widgets
// TODO: Clean up the logic of this beast
// TODO: Have a proper "In main menu" state
ConnectionState state = Game.orderManager.Connection.ConnectionState;
if (state != lastConnectionState)
{
switch( Game.orderManager.Connection.ConnectionState )
{
case ConnectionState.PreConnecting:
Chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
Chrome.rootWidget.GetWidget("CONNECTING_BG").Visible = false;
Chrome.rootWidget.GetWidget("CONNECTION_FAILED_BG").Visible = false;
break;
case ConnectionState.Connecting:
Chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
Chrome.rootWidget.GetWidget("CONNECTING_BG").Visible = true;
Chrome.rootWidget.GetWidget("CONNECTION_FAILED_BG").Visible = false;
break;
case ConnectionState.NotConnected:
Chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
Chrome.rootWidget.GetWidget("CONNECTING_BG").Visible = false;
Chrome.rootWidget.GetWidget("CONNECTION_FAILED_BG").Visible = true;
break;
case ConnectionState.Connected:
Chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
Chrome.rootWidget.GetWidget("CONNECTING_BG").Visible = false;
Chrome.rootWidget.GetWidget("CONNECTION_FAILED_BG").Visible = false;
break;
}
// TODO: Kill this (hopefully!) soon
if (state == ConnectionState.Connected)
Chrome.rootWidget.OpenWindow( "SERVER_LOBBY" );
}
lastConnectionState = state;
Timer.Time( "connectionState: {0}" );
}
Game.chrome.Draw(world);
Timer.Time( "widgets: {0}" );

View File

@@ -18,6 +18,8 @@
*/
#endregion
using OpenRA.Network;
namespace OpenRA.Widgets.Delegates
{
public class ConnectionDialogsDelegate : IWidgetDelegate
@@ -45,6 +47,26 @@ namespace OpenRA.Widgets.Delegates
r.GetWidget<LabelWidget>("CONNECTION_FAILED_DESC").GetText = () =>
"Could not connect to {0}:{1}".F(Game.CurrentHost, Game.CurrentPort);
Game.ConnectionStateChanged += () =>
{
r.CloseWindow();
switch( Game.orderManager.Connection.ConnectionState )
{
case ConnectionState.PreConnecting:
r.OpenWindow("MAINMENU_BG");
break;
case ConnectionState.Connecting:
r.OpenWindow("CONNECTING_BG");
break;
case ConnectionState.NotConnected:
r.OpenWindow("CONNECTION_FAILED_BG");
break;
case ConnectionState.Connected:
r.OpenWindow("SERVER_LOBBY");
break;
}
};
}
}
}

View File

@@ -31,6 +31,8 @@ namespace OpenRA.Widgets.Delegates
var gameRoot = r.GetWidget("INGAME_ROOT");
var optionsBG = gameRoot.GetWidget("INGAME_OPTIONS_BG");
Game.OnGameStart += () => r.OpenWindow("INGAME_ROOT");
r.GetWidget("INGAME_OPTIONS_BUTTON").OnMouseUp = mi => {
optionsBG.Visible = !optionsBG.Visible;
return true;