diff --git a/OpenRA.FileFormats/Map/MapStub.cs b/OpenRA.FileFormats/Map/MapStub.cs index 614d4fa135..c8d52b5649 100644 --- a/OpenRA.FileFormats/Map/MapStub.cs +++ b/OpenRA.FileFormats/Map/MapStub.cs @@ -38,8 +38,9 @@ namespace OpenRA.FileFormats public string Author; public int PlayerCount; public string Tileset; - public Dictionary Waypoints = new Dictionary(); - + public Dictionary Waypoints = new Dictionary(); + public IEnumerable SpawnPoints { get { return Waypoints.Select(kv => kv.Value); } } + public int2 TopLeft; public int2 BottomRight; public int Width { get { return BottomRight.X - TopLeft.X; } } diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index 269e48ad08..b7cb86eb91 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -171,33 +171,5 @@ namespace OpenRA.Graphics (int)(bounds.Width * fx + bounds.Left), (int)(bounds.Height * fy + bounds.Top)); } - - public void DrawSpawnPoints(RectangleF rect) - { - var points = world.Map.SpawnPoints - .Select( (sp,i) => Pair.New(sp, Game.LobbyInfo.Clients.FirstOrDefault( - c => c.SpawnPoint == i + 1 ) )) - .ToList(); - - foreach (var p in points) - { - var pos = CellToMinimapPixel(rect, p.First) - new int2(8, 8); - - if (p.Second == null) - rgbaRenderer.DrawSprite(unownedSpawnPoint, pos, "chrome"); - else - { - lineRenderer.FillRect(new RectangleF( - Game.viewport.Location.X + pos.X + 2, - Game.viewport.Location.Y + pos.Y + 2, - 12, 12), Game.world.PlayerColors()[p.Second.PaletteIndex % Game.world.PlayerColors().Count()].Color); - - rgbaRenderer.DrawSprite(ownedSpawnPoint, pos, "chrome"); - } - } - - lineRenderer.Flush(); - rgbaRenderer.Flush(); - } } } diff --git a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs index 0f95552c17..e12d66b268 100644 --- a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs @@ -31,7 +31,7 @@ namespace OpenRA.Widgets.Delegates Widget Players, LocalPlayerTemplate, RemotePlayerTemplate; Dictionary CountryNames; - public LobbyDelegate () + public LobbyDelegate() { var r = Chrome.rootWidget; var lobby = r.GetWidget("SERVER_LOBBY"); @@ -39,6 +39,32 @@ namespace OpenRA.Widgets.Delegates LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL"); RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE"); + + var map = lobby.GetWidget("LOBBY_MAP_PREVIEW"); + map.Map = () => {return Game.chrome.currentMap;}; + map.OnSpawnClick = sp => + { + var owned = Game.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp); + if (sp == 0 || !owned) + Game.IssueOrder(Order.Chat("/spawn {0}".F(sp))); + }; + + map.SpawnColors = () => + { + var spawns = Game.chrome.currentMap.SpawnPoints; + var playerColors = Game.world.PlayerColors(); + var sc = new Dictionary(); + + for (int i = 1; i <= spawns.Count(); i++) + { + var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i); + if (client == null) + continue; + sc.Add(spawns.ElementAt(i-1),playerColors[client.PaletteIndex % playerColors.Count()].Color); + } + return sc; + }; + CountryNames = Rules.Info["world"].Traits.WithInterface().ToDictionary(a => a.Race, a => a.Name); CountryNames.Add("random", "Random"); @@ -230,20 +256,6 @@ namespace OpenRA.Widgets.Delegates Game.IssueOrder(Order.Chat("/ready")); return true; } - - bool CycleSpawnPoint(MouseInput mi) - { - var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.Map.SpawnPoints.Count(); - - var newIndex = (Game.LocalClient.SpawnPoint + d) % (Game.world.Map.SpawnPoints.Count()+1); - - while (!SpawnPointAvailable(newIndex) && newIndex != (int)Game.LocalClient.SpawnPoint) - newIndex = (newIndex + d) % (Game.world.Map.SpawnPoints.Count()+1); - - Game.IssueOrder( - Order.Chat("/spawn " + newIndex)); - return true; - } bool CycleTeam(MouseInput mi) { diff --git a/OpenRA.Game/Widgets/Delegates/MapChooserDelegate.cs b/OpenRA.Game/Widgets/Delegates/MapChooserDelegate.cs index abe5c56c87..737a35851f 100644 --- a/OpenRA.Game/Widgets/Delegates/MapChooserDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/MapChooserDelegate.cs @@ -33,6 +33,7 @@ namespace OpenRA.Widgets.Delegates var r = Chrome.rootWidget; var bg = r.GetWidget("MAP_CHOOSER"); + bg.GetWidget("MAPCHOOSER_MAP_PREVIEW").Map = () => {return Game.chrome.currentMap;}; bg.GetWidget("CURMAP_TITLE").GetText = () => {return Game.chrome.currentMap.Title;}; bg.GetWidget("CURMAP_SIZE").GetText = () => {return "{0}x{1}".F(Game.chrome.currentMap.Width, Game.chrome.currentMap.Height);}; bg.GetWidget("CURMAP_THEATER").GetText = () => {return Rules.TileSets[Game.chrome.currentMap.Tileset].Name;}; diff --git a/OpenRA.Game/Widgets/MapPreviewWidget.cs b/OpenRA.Game/Widgets/MapPreviewWidget.cs index 0b9217c736..fb2f40f26b 100755 --- a/OpenRA.Game/Widgets/MapPreviewWidget.cs +++ b/OpenRA.Game/Widgets/MapPreviewWidget.cs @@ -15,6 +15,10 @@ namespace OpenRA.Widgets bool mapPreviewDirty = true; MapStub lastMap; + public Func Map = () => {return null;}; + public Action OnSpawnClick = spawn => {}; + public Func> SpawnColors = () => {return new Dictionary(); }; + public MapPreviewWidget() : base() { } public MapPreviewWidget(Widget other) @@ -23,28 +27,25 @@ namespace OpenRA.Widgets lastMap = (other as MapPreviewWidget).lastMap; } - Session.Client ClientForSpawnpoint(int i) - { - return Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i + 1); - } - const int closeEnough = 50; - public override bool HandleInput(MouseInput mi) { if (Game.LocalClient.State == Session.ClientState.Ready) return false; + var map = Map(); + if (map == null) + return false; + if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Left) { var container = new Rectangle(DrawPosition().X, DrawPosition().Y, Parent.Bounds.Width, Parent.Bounds.Height); - - var p = Game.chrome.currentMap.Waypoints - .Select((sp, i) => Pair.New(Game.chrome.currentMap.ConvertToPreview(sp.Value, container), i)) - .Where(a => ClientForSpawnpoint(a.Second) == null && (a.First - mi.Location).LengthSquared < closeEnough) + + var p = map.Waypoints + .Select((sp, i) => Pair.New(map.ConvertToPreview(sp.Value, container), i)) + .Where(a => (a.First - mi.Location).LengthSquared < closeEnough) .Select(a => a.Second + 1) .FirstOrDefault(); - - Game.IssueOrder(Order.Chat("/spawn {0}".F(p))); + OnSpawnClick(p); return true; } @@ -55,14 +56,14 @@ namespace OpenRA.Widgets public override void DrawInner( World world ) { - var map = Game.chrome.currentMap; + var map = Map(); if( map == null ) return; - if (lastMap != map) { mapPreviewDirty = true; lastMap = map; } + var pos = DrawPosition(); var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height); var mapRect = map.PreviewBounds( new Rectangle( rect.X, rect.Y, rect.Width, rect.Height ) ); @@ -86,30 +87,25 @@ namespace OpenRA.Widgets } void DrawSpawnPoints(MapStub map, Rectangle container, World world) - { - 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 colors = SpawnColors(); + foreach (var p in map.SpawnPoints) { - var pos = map.ConvertToPreview(p.First.Value, container) - new int2(8, 8); - - if (p.Second == null) - Game.chrome.renderer.RgbaSpriteRenderer.DrawSprite( - ChromeProvider.GetImage(Game.chrome.renderer, "spawnpoints", "unowned"), pos, "chrome"); - else + var pos = map.ConvertToPreview(p, container) - new int2(8, 8); + var sprite = "unowned"; + + if (colors.ContainsKey(p)) { - var playerColors = Game.world.PlayerColors(); Game.chrome.lineRenderer.FillRect(new RectangleF( Game.viewport.Location.X + pos.X + 2, Game.viewport.Location.Y + pos.Y + 2, - 12, 12), playerColors[p.Second.PaletteIndex % playerColors.Count()].Color); + 12, 12), colors[p]); - Game.chrome.renderer.RgbaSpriteRenderer.DrawSprite( - ChromeProvider.GetImage(Game.chrome.renderer, "spawnpoints", "owned"), pos, "chrome"); + sprite = "owned"; } + + Game.chrome.renderer.RgbaSpriteRenderer.DrawSprite( + ChromeProvider.GetImage(Game.chrome.renderer, "spawnpoints", sprite), pos, "chrome"); } Game.chrome.lineRenderer.Flush(); diff --git a/mods/cnc/menus.yaml b/mods/cnc/menus.yaml index 89f548379a..b7a4f79a02 100644 --- a/mods/cnc/menus.yaml +++ b/mods/cnc/menus.yaml @@ -430,6 +430,7 @@ Container: Background:dialog3 Children: MapPreview@LOBBY_MAP_PREVIEW: + Id:LOBBY_MAP_PREVIEW X:4 Y:4 Width:244 @@ -744,6 +745,7 @@ Container: Background:dialog3 Children: MapPreview@MAPCHOOSER_MAP_PREVIEW: + Id:MAPCHOOSER_MAP_PREVIEW X:4 Y:4 Width:244