diff --git a/OpenRA.Game/Widgets/MapPreviewWidget.cs b/OpenRA.Game/Widgets/MapPreviewWidget.cs index 3416da1f22..d68cf983d4 100644 --- a/OpenRA.Game/Widgets/MapPreviewWidget.cs +++ b/OpenRA.Game/Widgets/MapPreviewWidget.cs @@ -26,7 +26,7 @@ namespace OpenRA.Widgets public bool IgnoreMouseInput = false; public bool ShowSpawnPoints = true; - static Cache PreviewCache = new Cache(stub => Minimap.RenderMapPreview( new Map( stub.Path ))); + static readonly Cache PreviewCache = new Cache(stub => Minimap.RenderMapPreview( new Map( stub.Path ))); public MapPreviewWidget() : base() { } @@ -118,5 +118,16 @@ namespace OpenRA.Widgets } } } + + /// + /// Forces loading the preview into the map cache. + /// + public Bitmap LoadMapPreview() + { + var map = Map(); + if( map == null ) return null; + + return PreviewCache[map]; + } } } diff --git a/OpenRA.Mods.RA/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/MapChooserLogic.cs index 2413e1571d..6ff69a7c55 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/MapChooserLogic.cs @@ -10,6 +10,7 @@ using System; using System.Linq; +using System.Threading; using OpenRA.FileFormats; using OpenRA.Widgets; @@ -21,7 +22,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic ScrollPanelWidget scrollpanel; ScrollItemWidget itemTemplate; string gameMode; - + [ObjectCreator.UseCtor] internal MapChooserLogic(Widget widget, string initialMap, Action onExit, Action onSelect) { @@ -38,18 +39,18 @@ namespace OpenRA.Mods.RA.Widgets.Logic var gameModeDropdown = widget.GetOrNull("GAMEMODE_FILTER"); if (gameModeDropdown != null) { - var selectableMaps = Game.modData.AvailableMaps.Where(m => m.Value.Selectable); + var selectableMaps = Game.modData.AvailableMaps.Where(m => m.Value.Selectable).ToList(); var gameModes = selectableMaps .GroupBy(m => m.Value.Type) .Select(g => Pair.New(g.Key, g.Count())).ToList(); // 'all game types' extra item - gameModes.Insert( 0, Pair.New( null as string, selectableMaps.Count() ) ); + gameModes.Insert(0, Pair.New(null as string, selectableMaps.Count())); - Func, string> showItem = - x => "{0} ({1})".F( x.First ?? "All Game Types", x.Second ); + Func, string> showItem = + x => "{0} ({1})".F(x.First ?? "All Game Types", x.Second); - Func, ScrollItemWidget, ScrollItemWidget> setupItem = (ii, template) => + Func, ScrollItemWidget, ScrollItemWidget> setupItem = (ii, template) => { var item = ScrollItemWidget.Setup(template, () => gameMode == ii.First, @@ -64,7 +65,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic gameModeDropdown.GetText = () => showItem(gameModes.First(m => m.First == gameMode)); } - EnumerateMaps(); + new Thread(EnumerateMaps).Start(); } void EnumerateMaps() @@ -91,6 +92,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic previewWidget.IgnoreMouseOver = true; previewWidget.IgnoreMouseInput = true; previewWidget.Map = () => m; + previewWidget.LoadMapPreview(); var detailsWidget = item.Get("DETAILS"); if (detailsWidget != null) @@ -112,7 +114,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic sizeWidget.GetText = () => size; } - scrollpanel.AddChild(item); + Game.RunAfterTick(() => scrollpanel.AddChild(item)); } } }