From 005e62e8c71f6141bbec17dd2b6f1fb5d9177a48 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 4 Jan 2010 00:09:01 +1300 Subject: [PATCH 1/2] in all its false-color glory... a working minimap for terrain --- OpenRa.Game/Chrome.cs | 2 +- OpenRa.Game/Graphics/Minimap.cs | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index b22b900585..a5835dfb67 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -144,7 +144,7 @@ namespace OpenRa.Game DrawBuildTabs(paletteHeight); DrawChat(); - Game.minimap.Draw(new float2(30,30)); + Game.minimap.Draw(new float2(Game.viewport.Width - 128,30)); } void AddButton(Rectangle r, Action b) { buttons.Add(Pair.New(r, b)); } diff --git a/OpenRa.Game/Graphics/Minimap.cs b/OpenRa.Game/Graphics/Minimap.cs index 0616404c20..79022d3c47 100644 --- a/OpenRa.Game/Graphics/Minimap.cs +++ b/OpenRa.Game/Graphics/Minimap.cs @@ -7,6 +7,7 @@ namespace OpenRa.Game.Graphics Sheet sheet; SpriteRenderer spriteRenderer; Sprite sprite; + Bitmap terrain; public void Tick() { } @@ -17,18 +18,41 @@ namespace OpenRa.Game.Graphics sprite = new Sprite(sheet, new Rectangle(0, 0, 128, 128), TextureChannel.Alpha); } + // todo: extract these from the palette + static readonly Color[] terrainTypeColors = { + Color.Green, + Color.Red, + Color.Blue, + Color.Yellow, + Color.Purple, + Color.Turquoise, + Color.Violet, + Color.Tomato, + Color.Teal, + }; + public void Update() { - var bitmap = new Bitmap(128, 128); + 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, Rules.Map.IsInMap(x, y) + ? terrainTypeColors[Rules.TileSet.GetWalkability(Rules.Map.MapTiles[x, y])] + : Color.Black); + } + + var bitmap = new Bitmap(terrain); for( var y = 0; y < 128; y++ ) for (var x = 0; x < 128; x++) { - // todo: terrain, units, perf. + // todo: units, perf. var b = Game.BuildingInfluence.GetBuildingAt(new int2(x, y)); - if (b != null && b.Owner != null) - bitmap.SetPixel(x, y, Chat.paletteColors[ (int)b.Owner.Palette ]); + if (b != null) + bitmap.SetPixel(x, y, b.Owner != null ? Chat.paletteColors[(int)b.Owner.Palette] : Color.Gray); } sheet.Texture.SetData(bitmap); From 5f5a0a8e725bca8e7b81f736d7563376bab64e3c Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 4 Jan 2010 00:16:48 +1300 Subject: [PATCH 2/2] added units to minimap --- OpenRa.Game/Graphics/Minimap.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/OpenRa.Game/Graphics/Minimap.cs b/OpenRa.Game/Graphics/Minimap.cs index 79022d3c47..a8dfcebf4c 100644 --- a/OpenRa.Game/Graphics/Minimap.cs +++ b/OpenRa.Game/Graphics/Minimap.cs @@ -1,4 +1,6 @@ using System.Drawing; +using System.Linq; +using OpenRa.Game.Traits; namespace OpenRa.Game.Graphics { @@ -48,13 +50,14 @@ namespace OpenRa.Game.Graphics for( var y = 0; y < 128; y++ ) for (var x = 0; x < 128; x++) { - // todo: units, perf. - var b = Game.BuildingInfluence.GetBuildingAt(new int2(x, y)); if (b != null) bitmap.SetPixel(x, y, b.Owner != null ? Chat.paletteColors[(int)b.Owner.Palette] : Color.Gray); } + foreach (var a in Game.world.Actors.Where(a => a.traits.Contains())) + bitmap.SetPixel(a.Location.X, a.Location.Y, Chat.paletteColors[(int)a.Owner.Palette]); + sheet.Texture.SetData(bitmap); }