diff --git a/OpenRA.Game/Map/MapPreview.cs b/OpenRA.Game/Map/MapPreview.cs index 2726f16a79..363ee31180 100644 --- a/OpenRA.Game/Map/MapPreview.cs +++ b/OpenRA.Game/Map/MapPreview.cs @@ -73,8 +73,6 @@ namespace OpenRA public MapVisibility Visibility { get; private set; } public bool SuitableForInitialMap { get; private set; } - public MapRuleStatus RuleStatus { get; private set; } - Download download; public long DownloadBytes { get; private set; } public int DownloadPercentage { get; private set; } @@ -174,7 +172,6 @@ namespace OpenRA if (!r.downloading) { Status = MapStatus.Unavailable; - RuleStatus = MapRuleStatus.Invalid; return; } @@ -252,11 +249,7 @@ namespace OpenRA } Log.Write("debug", "Downloaded map to '{0}'", mapPath); - Game.RunAfterTick(() => - { - UpdateFromMap(new Map(mapPath), MapClassification.User); - CacheRules(); - }); + Game.RunAfterTick(() => UpdateFromMap(new Map(mapPath), MapClassification.User)); }; download = new Download(mapUrl, mapPath, onDownloadProgress, onDownloadComplete); @@ -278,19 +271,9 @@ namespace OpenRA download = null; } - public void CacheRules() - { - if (RuleStatus != MapRuleStatus.Unknown) - return; - - Map.PreloadRules(); - RuleStatus = Map.InvalidCustomRules ? MapRuleStatus.Invalid : MapRuleStatus.Cached; - } - public void Invalidate() { Status = MapStatus.Unavailable; - RuleStatus = MapRuleStatus.Unknown; } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index 18bc17085a..24978d7f22 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -744,16 +744,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic // Maps need to be validated and pre-loaded before they can be accessed new Thread(_ => { - var currentMap = Map = MapPreview.Map; - var mapPreview = MapPreview; - mapPreview.CacheRules(); + var currentMap = Map = new Map(MapPreview.Path); + currentMap.PreloadRules(); Game.RunAfterTick(() => { // Map may have changed in the meantime if (currentMap != Map) return; - if (mapPreview.RuleStatus != MapRuleStatus.Invalid) + if (!currentMap.InvalidCustomRules) { // Tell the server that we have the map orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady))); @@ -821,7 +820,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, factions); LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, MapPreview); LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, MapPreview); - LobbyUtils.SetupEditableReadyWidget(template, slot, client, orderManager, MapPreview); + LobbyUtils.SetupEditableReadyWidget(template, slot, client, orderManager, MapPreview, Map == null || Map.InvalidCustomRules); } else { diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyMapPreviewLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyMapPreviewLogic.cs index 36a6b934bc..74dca76b8e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyMapPreviewLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyMapPreviewLogic.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var available = widget.GetOrNull("MAP_AVAILABLE"); if (available != null) { - available.IsVisible = () => lobby.MapPreview.Status == MapStatus.Available && lobby.MapPreview.RuleStatus == MapRuleStatus.Cached; + available.IsVisible = () => lobby.MapPreview.Status == MapStatus.Available && (lobby.Map == null || !lobby.Map.InvalidCustomRules); var preview = available.Get("MAP_PREVIEW"); preview.Preview = () => lobby.MapPreview; @@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var invalid = widget.GetOrNull("MAP_INVALID"); if (invalid != null) { - invalid.IsVisible = () => lobby.MapPreview.Status == MapStatus.Available && lobby.MapPreview.RuleStatus == MapRuleStatus.Invalid; + invalid.IsVisible = () => lobby.MapPreview.Status == MapStatus.Available && lobby.Map != null && lobby.Map.InvalidCustomRules; var preview = invalid.Get("MAP_PREVIEW"); preview.Preview = () => lobby.MapPreview; @@ -106,8 +106,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var progress = widget.GetOrNull("MAP_PROGRESS"); if (progress != null) { - progress.IsVisible = () => - (lobby.MapPreview.Status != MapStatus.Available || lobby.MapPreview.RuleStatus == MapRuleStatus.Unknown) && + progress.IsVisible = () => lobby.MapPreview.Status != MapStatus.Available && lobby.MapPreview.Status != MapStatus.DownloadAvailable; var preview = progress.Get("MAP_PREVIEW"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index 27b88dbabf..672f7621bb 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -455,12 +455,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic parent.Get("SPAWN").GetText = () => (c.SpawnPoint == 0) ? "-" : Convert.ToChar('A' - 1 + c.SpawnPoint).ToString(); } - public static void SetupEditableReadyWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapPreview map) + public static void SetupEditableReadyWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapPreview map, bool forceDisable) { var status = parent.Get("STATUS_CHECKBOX"); status.IsChecked = () => orderManager.LocalClient.IsReady || c.Bot != null; status.IsVisible = () => true; - status.IsDisabled = () => c.Bot != null || map.Status != MapStatus.Available || map.RuleStatus != MapRuleStatus.Cached; + status.IsDisabled = () => c.Bot != null || map.Status != MapStatus.Available || forceDisable; var state = orderManager.LocalClient.IsReady ? Session.ClientState.NotReady : Session.ClientState.Ready; status.OnClick = () => orderManager.IssueOrder(Order.Command("state {0}".F(state))); diff --git a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs index 5600281d3c..3b50f68acd 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs @@ -129,7 +129,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var startButton = widget.Get("STARTGAME_BUTTON"); startButton.OnClick = StartMissionClicked; - startButton.IsDisabled = () => selectedMapPreview == null || selectedMapPreview.RuleStatus != MapRuleStatus.Cached; + startButton.IsDisabled = () => selectedMap == null || selectedMap.InvalidCustomRules; widget.Get("BACK_BUTTON").OnClick = () => { @@ -166,7 +166,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic selectedMapPreview = Game.ModData.MapCache[map.Uid]; // Cache the rules on a background thread to avoid jank - new Thread(selectedMapPreview.CacheRules).Start(); + new Thread(() => selectedMap.PreloadRules()).Start(); var briefingVideo = map.Videos.Briefing; var briefingVideoVisible = briefingVideo != null; @@ -290,7 +290,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { StopVideo(videoPlayer); - if (selectedMapPreview.RuleStatus != MapRuleStatus.Cached) + if (selectedMap.InvalidCustomRules) return; var gameStartVideo = selectedMap.Videos.GameStart;