Update LobbyLogic to use the new MapCache map tracking

This commit is contained in:
Gustas
2022-07-17 21:59:25 +03:00
committed by abcdefg30
parent 6bcf194874
commit b597c000d6
2 changed files with 24 additions and 32 deletions

View File

@@ -42,10 +42,9 @@ namespace OpenRA
readonly List<MapDirectoryTracker> mapDirectoryTrackers = new List<MapDirectoryTracker>();
/// <summary>
/// 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
/// </summary>
public event Action<string, string> MapUpdated = (oldUID, newUID) => { };
public string LastModifiedMap { get; private set; } = null;
readonly Dictionary<string, string> mapUpdates = new Dictionary<string, string>();
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);
}

View File

@@ -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<LabelWidget>("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