diff --git a/OpenRA.Game/Map/MapCache.cs b/OpenRA.Game/Map/MapCache.cs index 86c3af351d..cc868dd6b9 100644 --- a/OpenRA.Game/Map/MapCache.cs +++ b/OpenRA.Game/Map/MapCache.cs @@ -42,10 +42,9 @@ namespace OpenRA readonly List mapDirectoryTrackers = new List(); /// - /// If a map was added oldUID will be null, if updated oldUId will point to the outdated map - /// Event is not called when map is deleted + /// The most recenly modified or loaded map at runtime /// - public event Action MapUpdated = (oldUID, newUID) => { }; + public string LastModifiedMap { get; private set; } = null; readonly Dictionary mapUpdates = new Dictionary(); public MapCache(ModData modData) @@ -110,6 +109,9 @@ namespace OpenRA foreach (var map in kv.Key.Contents) LoadMap(map, kv.Key, kv.Value, mapGrid, null); } + + // We only want to track maps in runtime, not at loadtime + LastModifiedMap = null; } public void LoadMap(string map, IReadOnlyPackage package, MapClassification classification, MapGrid mapGrid, string oldMap) @@ -127,6 +129,7 @@ namespace OpenRA if (oldMap != uid) { + LastModifiedMap = uid; if (oldMap != null) mapUpdates.Add(oldMap, uid); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index a5627d56fb..63a95e7823 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -59,9 +59,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic MapPreview map; Session.MapStatus mapStatus; - string oldMapUid; - string newMapUid; - string lastUpdatedUid; + + string lastUpdatedMap = null; bool chatEnabled; bool addBotOnMapLoad; @@ -131,7 +130,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic Game.LobbyInfoChanged += UpdateSpawnOccupants; Game.BeforeGameStart += OnGameStart; Game.ConnectionStateChanged += ConnectionStateChanged; - modData.MapCache.MapUpdated += TrackRelevantMapUpdates; var name = lobby.GetOrNull("SERVER_NAME"); if (name != null) @@ -192,9 +190,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic orderManager.IssueOrder(Order.Command("map " + uid)); Game.Settings.Server.Map = uid; Game.Settings.Save(); - newMapUid = null; - oldMapUid = null; - lastUpdatedUid = null; }); // Check for updated maps, if the user has edited a map we'll preselect it for them @@ -202,7 +197,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs() { - { "initialMap", lastUpdatedUid ?? map.Uid }, + { "initialMap", SelectRecentMap(map.Uid) }, { "initialTab", MapClassification.System }, { "onExit", Game.IsHost ? (Action)UpdateSelectedMap : modData.MapCache.UpdateMaps }, { "onSelect", Game.IsHost ? onSelect : null }, @@ -498,7 +493,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic Game.LobbyInfoChanged -= UpdateSpawnOccupants; Game.BeforeGameStart -= OnGameStart; Game.ConnectionStateChanged -= ConnectionStateChanged; - modData.MapCache.MapUpdated -= TrackRelevantMapUpdates; } base.Dispose(disposing); @@ -838,35 +832,30 @@ namespace OpenRA.Mods.Common.Widgets.Logic onStart(); } - void TrackRelevantMapUpdates(string oldUid, string newUid) - { - // We need to handle map being updated multiple times without a refresh - if (map.Uid == oldUid || oldUid == newMapUid) - { - if (oldMapUid == null) - oldMapUid = oldUid; - newMapUid = newUid; - } - - if (newUid != null) - lastUpdatedUid = newUid; - } - void UpdateSelectedMap() { if (modData.MapCache[map.Uid].Status == MapStatus.Available) return; - if (oldMapUid == map.Uid && modData.MapCache[newMapUid].Status == MapStatus.Available) + var uid = modData.MapCache.GetUpdatedMap(map.Uid); + if (uid != null) { - orderManager.IssueOrder(Order.Command("map " + newMapUid)); - Game.Settings.Server.Map = newMapUid; + orderManager.IssueOrder(Order.Command("map " + uid)); + Game.Settings.Server.Map = uid; Game.Settings.Save(); - newMapUid = null; - oldMapUid = null; - lastUpdatedUid = null; } } + + string SelectRecentMap(string currentUid) + { + if (lastUpdatedMap != modData.MapCache.LastModifiedMap) + { + lastUpdatedMap = modData.MapCache.LastModifiedMap; + return lastUpdatedMap; + } + + return currentUid; + } } public class LobbyFaction