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

@@ -163,7 +163,7 @@ namespace OpenRA
Timer.Time("----end LoadMap"); Timer.Time("----end LoadMap");
Debug("Map change {0} -> {1}".F(Game.mapName, mapName)); Debug("Map change {0} -> {1}".F(Game.mapName, mapName));
} }
public static void MoveViewport(int2 loc) public static void MoveViewport(int2 loc)
{ {
viewport.Center(loc); viewport.Center(loc);
@@ -255,7 +255,10 @@ namespace OpenRA
Log.Write("sync", "Sync for net frame {0} -------------", f.First); Log.Write("sync", "Sync for net frame {0} -------------", f.First);
Log.Write("sync", "{0}", f.Second); Log.Write("sync", "{0}", f.Second);
} }
public static event Action ConnectionStateChanged = () => { };
static ConnectionState lastConnectionState = ConnectionState.PreConnecting;
static void Tick() static void Tick()
{ {
if (packageChangePending) if (packageChangePending)
@@ -273,8 +276,14 @@ namespace OpenRA
mapName = LobbyInfo.GlobalSettings.Map; mapName = LobbyInfo.GlobalSettings.Map;
mapChangePending = false; mapChangePending = false;
return; return;
} }
if (orderManager.Connection.ConnectionState != lastConnectionState)
{
lastConnectionState = orderManager.Connection.ConnectionState;
ConnectionStateChanged();
}
int t = Environment.TickCount; int t = Environment.TickCount;
int dt = t - lastTime; int dt = t - lastTime;
if (dt >= Settings.Timestep) if (dt >= Settings.Timestep)
@@ -397,7 +406,8 @@ namespace OpenRA
gs.GameStarted(world); gs.GameStarted(world);
orderManager.StartGame(); orderManager.StartGame();
} }
public static event Action OnGameStart = () => { };
internal static void StartGame() internal static void StartGame()
{ {
LoadMap(LobbyInfo.GlobalSettings.Map); LoadMap(LobbyInfo.GlobalSettings.Map);
@@ -410,7 +420,8 @@ namespace OpenRA
gs.GameStarted(world); gs.GameStarted(world);
viewport.GoToStartLocation(world.LocalPlayer); viewport.GoToStartLocation(world.LocalPlayer);
orderManager.StartGame(); orderManager.StartGame();
OnGameStart();
} }
public static Stance ChooseInitialStance(Player p, Player q) public static Stance ChooseInitialStance(Player p, Player q)

View File

@@ -64,8 +64,6 @@ namespace OpenRA.Graphics
this.scrollPosition = Game.CellSize* mapStart; this.scrollPosition = Game.CellSize* mapStart;
} }
ConnectionState lastConnectionState = ConnectionState.PreConnecting;
bool gameWasStarted = false;
public void DrawRegions( World world ) public void DrawRegions( World world )
{ {
Timer.Time( "DrawRegions start" ); Timer.Time( "DrawRegions start" );
@@ -79,55 +77,7 @@ namespace OpenRA.Graphics
renderer.BeginFrame(r1, r2, scrollPosition.ToInt2()); renderer.BeginFrame(r1, r2, scrollPosition.ToInt2());
world.WorldRenderer.Draw(); world.WorldRenderer.Draw();
Timer.Time( "worldRenderer: {0}" ); 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); Game.chrome.Draw(world);
Timer.Time( "widgets: {0}" ); Timer.Time( "widgets: {0}" );

View File

@@ -18,6 +18,8 @@
*/ */
#endregion #endregion
using OpenRA.Network;
namespace OpenRA.Widgets.Delegates namespace OpenRA.Widgets.Delegates
{ {
public class ConnectionDialogsDelegate : IWidgetDelegate public class ConnectionDialogsDelegate : IWidgetDelegate
@@ -45,6 +47,26 @@ namespace OpenRA.Widgets.Delegates
r.GetWidget<LabelWidget>("CONNECTION_FAILED_DESC").GetText = () => r.GetWidget<LabelWidget>("CONNECTION_FAILED_DESC").GetText = () =>
"Could not connect to {0}:{1}".F(Game.CurrentHost, Game.CurrentPort); "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

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