Temp lobby map preview (will be fixed properly when we widgetize)
This commit is contained in:
@@ -19,7 +19,8 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
namespace OpenRA.FileFormats
|
namespace OpenRA.FileFormats
|
||||||
@@ -37,6 +38,7 @@ namespace OpenRA.FileFormats
|
|||||||
public string Author;
|
public string Author;
|
||||||
public int PlayerCount;
|
public int PlayerCount;
|
||||||
public string Tileset;
|
public string Tileset;
|
||||||
|
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
|
||||||
|
|
||||||
public int2 TopLeft;
|
public int2 TopLeft;
|
||||||
public int2 BottomRight;
|
public int2 BottomRight;
|
||||||
@@ -55,14 +57,32 @@ namespace OpenRA.FileFormats
|
|||||||
Package = package;
|
Package = package;
|
||||||
var yaml = MiniYaml.FromStream(Package.GetContent("map.yaml"));
|
var yaml = MiniYaml.FromStream(Package.GetContent("map.yaml"));
|
||||||
FieldLoader.LoadFields(this, yaml, Fields);
|
FieldLoader.LoadFields(this, yaml, Fields);
|
||||||
|
|
||||||
|
// Waypoints
|
||||||
|
foreach (var wp in yaml["Waypoints"].Nodes)
|
||||||
|
{
|
||||||
|
string[] loc = wp.Value.Value.Split(',');
|
||||||
|
Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]), int.Parse(loc[1])));
|
||||||
|
}
|
||||||
|
|
||||||
Preview = Lazy.New(
|
Preview = Lazy.New(
|
||||||
() => { return new Bitmap(Package.GetContent("preview.png")); }
|
() => { return new Bitmap(Package.GetContent("preview.png")); }
|
||||||
);
|
);
|
||||||
|
|
||||||
Uid = Package.GetContent("map.uid").ReadAllText();
|
Uid = Package.GetContent("map.uid").ReadAllText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int2 ConvertToPreview(int2 point, Rectangle container)
|
||||||
|
{
|
||||||
|
float scale = Math.Min(container.Width * 1.0f / Width, container.Height * 1.0f / Height);
|
||||||
|
|
||||||
|
var size = Math.Max(Width, Height);
|
||||||
|
var dw = (int)(scale * (size - Width)) / 2;
|
||||||
|
var dh = (int)(scale * (size - Height)) / 2;
|
||||||
|
|
||||||
|
return new int2(container.X + dw + (int)(scale*(point.X - TopLeft.X)) , container.Y + dh + (int)(scale*(point.Y - TopLeft.Y)));
|
||||||
|
}
|
||||||
|
|
||||||
public Rectangle PreviewBounds(Rectangle container)
|
public Rectangle PreviewBounds(Rectangle container)
|
||||||
{
|
{
|
||||||
float scale = Math.Min(container.Width * 1.0f / Width, container.Height * 1.0f / Height);
|
float scale = Math.Min(container.Width * 1.0f / Width, container.Height * 1.0f / Height);
|
||||||
|
|||||||
@@ -288,15 +288,16 @@ namespace OpenRA
|
|||||||
mapChooserSprite = new Sprite(mapChooserSheet, new Rectangle(0,0,currentMap.Width, currentMap.Height), TextureChannel.Alpha);
|
mapChooserSprite = new Sprite(mapChooserSheet, new Rectangle(0,0,currentMap.Width, currentMap.Height), TextureChannel.Alpha);
|
||||||
mapPreviewDirty = false;
|
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 mapContainer = new Rectangle(r.Right - 280, r.Top + 30, 256, 256);
|
||||||
var mapRect = currentMap.PreviewBounds(new Rectangle(mapContainer.X+4,mapContainer.Y+4,mapContainer.Width-8,mapContainer.Height-8));
|
var mapRect = currentMap.PreviewBounds(new Rectangle(mapContainer.X,mapContainer.Y,mapContainer.Width,mapContainer.Height));
|
||||||
|
|
||||||
DrawDialogBackground(mapContainer, "dialog2");
|
DrawDialogBackground(mapBackground, "dialog3");
|
||||||
rgbaRenderer.DrawSprite(mapChooserSprite,
|
rgbaRenderer.DrawSprite(mapChooserSprite,
|
||||||
new float2(mapRect.Location),
|
new float2(mapRect.Location),
|
||||||
"chrome",
|
"chrome",
|
||||||
new float2(mapRect.Size));
|
new float2(mapRect.Size));
|
||||||
|
DrawSpawnPoints(currentMap,mapContainer);
|
||||||
rgbaRenderer.Flush();
|
rgbaRenderer.Flush();
|
||||||
|
|
||||||
var y = r.Top + 50;
|
var y = r.Top + 50;
|
||||||
@@ -391,7 +392,34 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void DrawWidgets(World world) { rootWidget.Draw(world); shpRenderer.Flush(); rgbaRenderer.Flush(); }
|
public void DrawWidgets(World world) { rootWidget.Draw(world); shpRenderer.Flush(); rgbaRenderer.Flush(); }
|
||||||
|
public void DrawSpawnPoints(MapStub map, Rectangle container)
|
||||||
|
{
|
||||||
|
var points = map.Waypoints;
|
||||||
|
// .Select( (sp,i) => Pair.New(sp, Game.LobbyInfo.Clients.FirstOrDefault(
|
||||||
|
// c => c.SpawnPoint == i + 1 ) ))
|
||||||
|
// .ToList();
|
||||||
|
|
||||||
|
foreach (var p in points)
|
||||||
|
{
|
||||||
|
var pos = map.ConvertToPreview(p.Value,container);
|
||||||
|
|
||||||
|
//if (p.Second == null)
|
||||||
|
rgbaRenderer.DrawSprite(ChromeProvider.GetImage(renderer, "spawnpoints", "unowned"), pos, "chrome");
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// lineRenderer.FillRect(new RectangleF(
|
||||||
|
// Game.viewport.Location.X + pos.X + 2,
|
||||||
|
// Game.viewport.Location.Y + pos.Y + 2,
|
||||||
|
// 12, 12), Player.PlayerColors[ p.Second.PaletteIndex % Player.PlayerColors.Count() ].c);
|
||||||
|
//
|
||||||
|
// rgbaRenderer.DrawSprite(ownedSpawnPoint, pos, "chrome");
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
lineRenderer.Flush();
|
||||||
|
rgbaRenderer.Flush();
|
||||||
|
}
|
||||||
|
|
||||||
public void DrawLobby()
|
public void DrawLobby()
|
||||||
{
|
{
|
||||||
buttons.Clear();
|
buttons.Clear();
|
||||||
@@ -409,16 +437,32 @@ namespace OpenRA
|
|||||||
DrawDialogBackground(r, "dialog");
|
DrawDialogBackground(r, "dialog");
|
||||||
DrawCentered("OpenRA Multiplayer Lobby", new int2(r.Left + w / 2, r.Top + 20), Color.White);
|
DrawCentered("OpenRA Multiplayer Lobby", new int2(r.Left + w / 2, r.Top + 20), Color.White);
|
||||||
rgbaRenderer.Flush();
|
rgbaRenderer.Flush();
|
||||||
|
|
||||||
DrawDialogBackground(new Rectangle(r.Right - 264, r.Top + 43, 244, 244),"dialog3");
|
|
||||||
|
|
||||||
var minimapRect = new Rectangle(r.Right - 262, r.Top + 45, 240, 240);
|
if (Game.LobbyInfo.GlobalSettings.Map != null)
|
||||||
|
{
|
||||||
/*
|
var mapBackground = new Rectangle(r.Right - 268, r.Top + 39, 252, 252);
|
||||||
world.Minimap.Update();
|
var mapContainer = new Rectangle(r.Right - 264, r.Top + 43, 244, 244);
|
||||||
world.Minimap.Draw(minimapRect, true);
|
var mapRect = Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map].PreviewBounds(new Rectangle(mapContainer.X,mapContainer.Y,mapContainer.Width,mapContainer.Height));
|
||||||
world.Minimap.DrawSpawnPoints(minimapRect);
|
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)
|
if (Game.IsHost)
|
||||||
{
|
{
|
||||||
@@ -426,7 +470,7 @@ namespace OpenRA
|
|||||||
_ =>
|
_ =>
|
||||||
{
|
{
|
||||||
showMapChooser = true;
|
showMapChooser = true;
|
||||||
currentMap = Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map.ToLowerInvariant()];
|
currentMap = Game.AvailableMaps[Game.LobbyInfo.GlobalSettings.Map];
|
||||||
mapPreviewDirty = true;
|
mapPreviewDirty = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user