started moving Lobby/MapChooser to widgets

This commit is contained in:
Bob
2010-04-14 15:14:26 +12:00
committed by Chris Forbes
parent 1447946ea6
commit 8ee3785c2e
5 changed files with 137 additions and 93 deletions

View File

@@ -77,9 +77,7 @@ namespace OpenRA
static float2 powerOrigin = new float2(42, 205); // Relative to radarOrigin
static Size powerSize = new Size(138,5);
// mapchooser
Sheet mapChooserSheet;
Sprite mapChooserSprite;
internal MapStub currentMap;
public Chrome(Renderer r, Manifest m)
{
@@ -222,10 +220,6 @@ namespace OpenRA
}
bool showMapChooser = false;
MapStub currentMap;
bool mapPreviewDirty = true;
void AddUiButton(int2 pos, string text, Action<bool> a)
{
var rect = new Rectangle(pos.X - 160 / 2, pos.Y - 4, 160, 24);
@@ -237,49 +231,29 @@ namespace OpenRA
public void DrawMapChooser()
{
buttons.Clear();
var w = 800;
var h = 600;
var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h );
DrawDialogBackground(r, "dialog");
DrawCentered("Choose Map", new int2(r.Left + w / 2, r.Top + 20), Color.White);
rgbaRenderer.Flush();
AddUiButton(new int2(r.Left + 200, r.Bottom - 40), "OK",
_ =>
{
Game.IssueOrder(Order.Chat("/map " + currentMap.Uid));
showMapChooser = false;
mapPreviewDirty = true;
Chrome.rootWidget.CloseWindow();
});
AddUiButton(new int2(r.Right - 200, r.Bottom - 40), "Cancel",
_ =>
{
showMapChooser = false;
mapPreviewDirty = true;
Chrome.rootWidget.CloseWindow();
});
if (mapPreviewDirty)
{
if (mapChooserSheet == null || mapChooserSheet.Size.Width != currentMap.Width || mapChooserSheet.Size.Height != currentMap.Height)
mapChooserSheet = new Sheet(renderer, new Size(currentMap.Width, currentMap.Height));
mapChooserSheet.Texture.SetData(currentMap.Preview.Value);
mapChooserSprite = new Sprite(mapChooserSheet, new Rectangle(0,0,currentMap.Width, currentMap.Height), TextureChannel.Alpha);
mapPreviewDirty = false;
}
var mapBackground = new Rectangle(r.Right - 284, r.Top + 26, 264, 264);
var mapContainer = new Rectangle(r.Right - 280, r.Top + 30, 256, 256);
var mapRect = currentMap.PreviewBounds(new Rectangle(mapContainer.X,mapContainer.Y,mapContainer.Width,mapContainer.Height));
DrawDialogBackground(mapBackground, "dialog3");
rgbaRenderer.DrawSprite(mapChooserSprite,
new float2(mapRect.Location),
"chrome",
new float2(mapRect.Size));
DrawSpawnPoints(currentMap,mapContainer);
rgbaRenderer.Flush();
var y = r.Top + 50;
// Don't bother showing a subset of the data
@@ -300,7 +274,7 @@ namespace OpenRA
renderer.RegularFont.DrawText(map.Title, new int2(r.Left + 60, y), Color.White);
rgbaRenderer.Flush();
var closureMap = map;
AddButton(itemRect, _ => { currentMap = closureMap; mapPreviewDirty = true; });
AddButton(itemRect, _ => { currentMap = closureMap; });
y += 20;
}
@@ -399,65 +373,26 @@ namespace OpenRA
rgbaRenderer.Flush();
}
string lastMap = "";
public void DrawLobby()
{
buttons.Clear();
if (showMapChooser)
{
DrawMapChooser();
return;
}
// HACK HACK HACK
if (lastMap != Game.LobbyInfo.GlobalSettings.Map)
{
mapPreviewDirty = true;
lastMap = Game.LobbyInfo.GlobalSettings.Map;
}
if( Game.LobbyInfo.GlobalSettings.Map == null )
currentMap = null;
else
currentMap = Game.AvailableMaps[ Game.LobbyInfo.GlobalSettings.Map ];
var w = 800;
var h = 600;
var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h );
DrawDialogBackground(r, "dialog");
DrawCentered("OpenRA Multiplayer Lobby", new int2(r.Left + w / 2, r.Top + 20), Color.White);
rgbaRenderer.Flush();
if (Game.LobbyInfo.GlobalSettings.Map != null)
{
var mapBackground = new Rectangle(r.Right - 268, r.Top + 39, 252, 252);
var mapContainer = new Rectangle(r.Right - 264, r.Top + 43, 244, 244);
var mapRect = Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map].PreviewBounds(new Rectangle(mapContainer.X,mapContainer.Y,mapContainer.Width,mapContainer.Height));
DrawDialogBackground(mapBackground,"dialog3");
if (mapPreviewDirty)
{
if (mapChooserSheet == null || mapChooserSheet.Size.Width != Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map].Width || mapChooserSheet.Size.Height != Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map].Height)
mapChooserSheet = new Sheet(renderer, new Size(Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map].Width, Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map].Height));
mapChooserSheet.Texture.SetData(Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map].Preview.Value);
mapChooserSprite = new Sprite(mapChooserSheet, new Rectangle(0,0,Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map].Width, Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map].Height), TextureChannel.Alpha);
mapPreviewDirty = false;
}
rgbaRenderer.DrawSprite(mapChooserSprite,
new float2(mapRect.Location),
"chrome",
new float2(mapRect.Size));
DrawSpawnPoints(Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map],mapContainer);
rgbaRenderer.Flush();
}
if (Game.IsHost)
{
AddUiButton(new int2(r.Right - 100, r.Top + 300), "Change Map",
_ =>
{
showMapChooser = true;
currentMap = Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map];
mapPreviewDirty = true;
currentMap = Game.AvailableMaps[ Game.LobbyInfo.GlobalSettings.Map ];
rootWidget.OpenWindow( "MAP_CHOOSER" );
});
}

View File

@@ -122,16 +122,21 @@ namespace OpenRA.Graphics
Chrome.rootWidget.GetWidget("CONNECTION_FAILED_BG").Visible = false;
break;
}
}
// TODO: Kill this (hopefully!) soon
if (state == ConnectionState.Connected)
Game.chrome.DrawLobby();
Chrome.rootWidget.OpenWindow( "SERVER_LOBBY" );
}
lastConnectionState = state;
}
Game.chrome.DrawWidgets(world);
if( Chrome.rootWidget.GetWidget( "SERVER_LOBBY" ).Visible )
Game.chrome.DrawLobby();
else if( Chrome.rootWidget.GetWidget( "MAP_CHOOSER" ).Visible )
Game.chrome.DrawMapChooser();
Timer.Time( "widgets: {0}" );
var cursorName = Game.chrome.HitTest(mousePos) ? "default" : Game.controller.ChooseCursor( world );

View File

@@ -92,6 +92,7 @@
<Compile Include="Widgets\Delegates\ServerBrowserDelegate.cs" />
<Compile Include="Widgets\Delegates\SettingsMenuDelegate.cs" />
<Compile Include="Widgets\MoneyBinWidget.cs" />
<Compile Include="Widgets\MapPreviewWidget.cs" />
<Compile Include="Widgets\PostGameWidget.cs" />
<Compile Include="Widgets\WidgetUtils.cs" />
<Compile Include="Combat.cs" />

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRA.Graphics;
using System.Drawing;
using OpenRA.FileFormats;
namespace OpenRA.Widgets
{
class MapPreviewWidget : Widget
{
Sheet mapChooserSheet;
Sprite mapChooserSprite;
bool showMapChooser = false;
bool mapPreviewDirty = true;
MapStub lastMap;
public override void Draw( World world )
{
var map = Game.chrome.currentMap;
if( map == null ) return;
if (lastMap != map)
{
mapPreviewDirty = true;
lastMap = map;
}
var mapRect = map.PreviewBounds( new Rectangle( Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height ) );
if( mapPreviewDirty )
{
if( mapChooserSheet == null || mapChooserSheet.Size.Width != map.Width || mapChooserSheet.Size.Height != map.Height )
mapChooserSheet = new Sheet( Game.renderer, new Size( map.Width, map.Height ) );
mapChooserSheet.Texture.SetData( map.Preview.Value );
mapChooserSprite = new Sprite( mapChooserSheet, new Rectangle( 0, 0, map.Width, map.Height ), TextureChannel.Alpha );
mapPreviewDirty = false;
}
Game.chrome.renderer.RgbaSpriteRenderer.DrawSprite( mapChooserSprite,
new float2( mapRect.Location ),
"chrome",
new float2( mapRect.Size ) );
Game.chrome.DrawSpawnPoints( map, Parent.Bounds );
base.Draw( world );
}
}
}

View File

@@ -245,8 +245,60 @@ Container:
Width:160
Height:25
Text:Abort
Container@SERVER_LOBBY:
Background@SERVER_LOBBY:
Id:SERVER_LOBBY
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:800
Height:600
Visible:false
Children:
Label@LOBBY_TITLE:
X:0
Y:20
Align:Center
Width:800
Height:20
Text:OpenRA Multiplayer Lobby
Background@LOBBY_MAP_BG:
X:PARENT_RIGHT-268
Y:39
Width:252
Height:252
Background:dialog3
Children:
MapPreview@LOBBY_MAP_PREVIEW:
X:4
Y:4
Width:244
Height:244
Background@MAP_CHOOSER:
Id:MAP_CHOOSER
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:800
Height:600
Visible:false
Children:
Label@MAPCHOOSER_TITLE:
X:0
Y:20
Align:Center
Width:800
Height:20
Text:Choose Map
Background@MAPCHOOSER_MAP_BG:
X:PARENT_RIGHT-268
Y:39
Width:252
Height:252
Background:dialog3
Children:
MapPreview@MAPCHOOSER_MAP_PREVIEW:
X:4
Y:4
Width:244
Height:244
Container@INGAME_ROOT:
Id:INGAME_ROOT
Delegate:IngameChromeDelegate