diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index 3882180aa4..6c5e8b2822 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -74,6 +74,10 @@ namespace OpenRa static float2 powerOrigin = new float2(42, 205); // Relative to radarOrigin static Size powerSize = new Size(138,5); + // mapchooser + Sheet mapChooserSheet; + Sprite mapChooserSprite; + public Chrome(Renderer r) { this.renderer = r; @@ -137,6 +141,8 @@ namespace OpenRa ready = new Animation("pips"); ready.PlayRepeating("ready"); clock = new Animation("clock"); + + mapChooserSheet = new Sheet(r, new Size(128, 128)); } public void Tick() @@ -226,15 +232,13 @@ namespace OpenRa class MapInfo { public readonly string Filename; - readonly Map Map; + public readonly Map Map; public MapInfo(string filename) { Filename = filename.ToLowerInvariant(); Map = new Map(new IniFile(FileSystem.Open(Filename))); } - - public string Name { get { return Map.Title; } } }; Lazy> mapList = Lazy.New( @@ -247,6 +251,7 @@ namespace OpenRa bool showMapChooser = false; MapInfo currentMap; + bool mapPreviewDirty = true; void AddUiButton(int2 pos, string text, Action a) { @@ -258,7 +263,7 @@ namespace OpenRa public void DrawMapChooser() { - var w = 600; + var w = 800; var h = 600; var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h ); DrawDialogBackground(r, optionsSprites, true); @@ -280,17 +285,34 @@ namespace OpenRa showMapChooser = false; }); + if (mapPreviewDirty) + { + var b = Minimap.RenderTerrainBitmap(currentMap.Map, Game.world.TileSet); // tileset -> hack + mapChooserSheet.Texture.SetData(b); + mapChooserSprite = new Sprite(mapChooserSheet, + Minimap.MakeMinimapBounds(currentMap.Map), TextureChannel.Alpha); + mapPreviewDirty = false; + } + + var mapRect = new Rectangle(r.Right - 280, r.Top + 30, 256, 256); + DrawDialogBackground(mapRect, panelSprites, false); + rgbaRenderer.DrawSprite(mapChooserSprite, + new float2(mapRect.Location) + new float2(4, 4), + PaletteType.Chrome, + new float2(mapRect.Size) - new float2(8, 8)); + rgbaRenderer.Flush(); + var y = r.Top + 50; foreach (var map in mapList.Value) { - var itemRect = new Rectangle(r.Left + 50, y - 2, r.Width - 100, 20); + var itemRect = new Rectangle(r.Left + 50, y - 2, r.Width - 340, 20); if (map == currentMap) DrawDialogBackground(itemRect, panelSprites, false); - renderer.DrawText(map.Name, new int2(r.Left + 60, y), Color.White); + renderer.DrawText(map.Map.Title, new int2(r.Left + 60, y), Color.White); var closureMap = map; - AddButton(itemRect, _ => currentMap = closureMap); + AddButton(itemRect, _ => { currentMap = closureMap; mapPreviewDirty = true; }); y += 20; } @@ -342,6 +364,7 @@ namespace OpenRa showMapChooser = true; currentMap = mapList.Value.Single( m => m.Filename == Game.LobbyInfo.GlobalSettings.Map.ToLowerInvariant()); + mapPreviewDirty = true; } }); } diff --git a/OpenRa.Game/Graphics/Minimap.cs b/OpenRa.Game/Graphics/Minimap.cs index a0a1d9f1b0..73a1495591 100644 --- a/OpenRa.Game/Graphics/Minimap.cs +++ b/OpenRa.Game/Graphics/Minimap.cs @@ -4,6 +4,7 @@ using System.Linq; using OpenRa.Traits; using OpenRa.FileFormats; using System.Drawing.Imaging; +using IjwFramework.Collections; namespace OpenRa.Graphics { @@ -35,50 +36,63 @@ namespace OpenRa.Graphics mapOnlySprite = new Sprite(mapOnlySheet, rect, TextureChannel.Alpha); } - Color[] terrainTypeColors; + public static Rectangle MakeMinimapBounds(Map m) + { + var size = Math.Max(m.Width, m.Height); + var dw = (size - m.Width) / 2; + var dh = (size - m.Height) / 2; + + return new Rectangle(m.Offset.X - dw, m.Offset.Y - dh, size, size); + } + + static Cache terrainTypeColors = new Cache( + theater => + { + var pal = new Palette(FileSystem.Open(theater + ".pal")); + return new[] { + theater == "snow" ? 0xe3 :0x1a, + 0x63, 0x2f, 0x1f, 0x14, 0x64, 0x1f, 0x68, 0x6b, 0x6d, 0x88 } + .Select(a => Color.FromArgb(alpha, pal.GetColor(a))).ToArray(); + }); + Color[] playerColors; - Color shroudColor; + static Color shroudColor; string theater; public void InvalidateOre() { oreLayer = null; } + public static Bitmap RenderTerrainBitmap(Map map, TileSet tileset) + { + var colors = terrainTypeColors[map.Theater.ToLowerInvariant()]; + var terrain = new Bitmap(128, 128); + for (var y = 0; y < 128; y++) + for (var x = 0; x < 128; x++) + terrain.SetPixel(x, y, map.IsInMap(x, y) + ? colors[tileset.GetWalkability(map.MapTiles[x, y])] + : shroudColor); + + return terrain; + } + public void Update() { - if (world.Map.Theater != theater) - { - terrainTypeColors = null; - theater = world.Map.Theater; - } - if (terrainTypeColors == null) { - var pal = new Palette(FileSystem.Open(world.Map.Theater + ".pal")); - terrainTypeColors = new[] { - theater.ToLowerInvariant() == "snow" ? 0xe3 :0x1a, - 0x63, 0x2f, 0x1f, 0x14, 0x64, 0x1f, 0x68, 0x6b, 0x6d, 0x88 } - .Select( a => Color.FromArgb(alpha, pal.GetColor(a) )).ToArray(); - playerColors = Util.MakeArray( 8, b => Color.FromArgb(alpha, Chat.paletteColors[b]) ); shroudColor = Color.FromArgb(alpha, Color.Black); } - + if (terrain == null) - { - terrain = new Bitmap(128, 128); - for (var y = 0; y < 128; y++) - for (var x = 0; x < 128; x++) - terrain.SetPixel(x, y, world.Map.IsInMap(x, y) - ? terrainTypeColors[world.TileSet.GetWalkability(world.Map.MapTiles[x, y])] - : shroudColor); - } + terrain = RenderTerrainBitmap(world.Map, world.TileSet); if (oreLayer == null) { + var colors = terrainTypeColors[world.Map.Theater.ToLowerInvariant()]; oreLayer = new Bitmap(terrain); for (var y = 0; y < 128; y++) for (var x = 0; x < 128; x++) if (world.Map.ContainsResource(new int2(x, y))) - oreLayer.SetPixel(x, y, terrainTypeColors[(int)TerrainMovementType.Ore]); + oreLayer.SetPixel(x, y, colors[(int)TerrainMovementType.Ore]); } mapOnlySheet.Texture.SetData(oreLayer); @@ -92,6 +106,7 @@ namespace OpenRa.Graphics unsafe { + var colors = terrainTypeColors[world.Map.Theater.ToLowerInvariant()]; int* c = (int*)bitmapData.Scan0; for (var y = 0; y < 128; y++) @@ -100,7 +115,7 @@ namespace OpenRa.Graphics var b = world.BuildingInfluence.GetBuildingAt(new int2(x, y)); if (b != null) *(c + (y * bitmapData.Stride >> 2) + x) = - (b.Owner != null ? playerColors[(int)b.Owner.Palette] : terrainTypeColors[4]).ToArgb(); + (b.Owner != null ? playerColors[(int)b.Owner.Palette] : colors[4]).ToArgb(); } foreach (var a in world.Actors.Where(a => a.traits.Contains()))