Update LobbyLogic to use the new MapCache map tracking
This commit is contained in:
@@ -42,10 +42,9 @@ namespace OpenRA
|
|||||||
readonly List<MapDirectoryTracker> mapDirectoryTrackers = new List<MapDirectoryTracker>();
|
readonly List<MapDirectoryTracker> mapDirectoryTrackers = new List<MapDirectoryTracker>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If a map was added oldUID will be null, if updated oldUId will point to the outdated map
|
/// The most recenly modified or loaded map at runtime
|
||||||
/// Event is not called when map is deleted
|
|
||||||
/// </summary>
|
/// </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>();
|
readonly Dictionary<string, string> mapUpdates = new Dictionary<string, string>();
|
||||||
|
|
||||||
public MapCache(ModData modData)
|
public MapCache(ModData modData)
|
||||||
@@ -110,6 +109,9 @@ namespace OpenRA
|
|||||||
foreach (var map in kv.Key.Contents)
|
foreach (var map in kv.Key.Contents)
|
||||||
LoadMap(map, kv.Key, kv.Value, mapGrid, null);
|
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)
|
public void LoadMap(string map, IReadOnlyPackage package, MapClassification classification, MapGrid mapGrid, string oldMap)
|
||||||
@@ -127,6 +129,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
if (oldMap != uid)
|
if (oldMap != uid)
|
||||||
{
|
{
|
||||||
|
LastModifiedMap = uid;
|
||||||
if (oldMap != null)
|
if (oldMap != null)
|
||||||
mapUpdates.Add(oldMap, uid);
|
mapUpdates.Add(oldMap, uid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,9 +59,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
MapPreview map;
|
MapPreview map;
|
||||||
Session.MapStatus mapStatus;
|
Session.MapStatus mapStatus;
|
||||||
string oldMapUid;
|
|
||||||
string newMapUid;
|
string lastUpdatedMap = null;
|
||||||
string lastUpdatedUid;
|
|
||||||
|
|
||||||
bool chatEnabled;
|
bool chatEnabled;
|
||||||
bool addBotOnMapLoad;
|
bool addBotOnMapLoad;
|
||||||
@@ -131,7 +130,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
Game.LobbyInfoChanged += UpdateSpawnOccupants;
|
Game.LobbyInfoChanged += UpdateSpawnOccupants;
|
||||||
Game.BeforeGameStart += OnGameStart;
|
Game.BeforeGameStart += OnGameStart;
|
||||||
Game.ConnectionStateChanged += ConnectionStateChanged;
|
Game.ConnectionStateChanged += ConnectionStateChanged;
|
||||||
modData.MapCache.MapUpdated += TrackRelevantMapUpdates;
|
|
||||||
|
|
||||||
var name = lobby.GetOrNull<LabelWidget>("SERVER_NAME");
|
var name = lobby.GetOrNull<LabelWidget>("SERVER_NAME");
|
||||||
if (name != null)
|
if (name != null)
|
||||||
@@ -192,9 +190,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
orderManager.IssueOrder(Order.Command("map " + uid));
|
orderManager.IssueOrder(Order.Command("map " + uid));
|
||||||
Game.Settings.Server.Map = uid;
|
Game.Settings.Server.Map = uid;
|
||||||
Game.Settings.Save();
|
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
|
// 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()
|
Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs()
|
||||||
{
|
{
|
||||||
{ "initialMap", lastUpdatedUid ?? map.Uid },
|
{ "initialMap", SelectRecentMap(map.Uid) },
|
||||||
{ "initialTab", MapClassification.System },
|
{ "initialTab", MapClassification.System },
|
||||||
{ "onExit", Game.IsHost ? (Action)UpdateSelectedMap : modData.MapCache.UpdateMaps },
|
{ "onExit", Game.IsHost ? (Action)UpdateSelectedMap : modData.MapCache.UpdateMaps },
|
||||||
{ "onSelect", Game.IsHost ? onSelect : null },
|
{ "onSelect", Game.IsHost ? onSelect : null },
|
||||||
@@ -498,7 +493,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
Game.LobbyInfoChanged -= UpdateSpawnOccupants;
|
Game.LobbyInfoChanged -= UpdateSpawnOccupants;
|
||||||
Game.BeforeGameStart -= OnGameStart;
|
Game.BeforeGameStart -= OnGameStart;
|
||||||
Game.ConnectionStateChanged -= ConnectionStateChanged;
|
Game.ConnectionStateChanged -= ConnectionStateChanged;
|
||||||
modData.MapCache.MapUpdated -= TrackRelevantMapUpdates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
@@ -838,35 +832,30 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
onStart();
|
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()
|
void UpdateSelectedMap()
|
||||||
{
|
{
|
||||||
if (modData.MapCache[map.Uid].Status == MapStatus.Available)
|
if (modData.MapCache[map.Uid].Status == MapStatus.Available)
|
||||||
return;
|
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));
|
orderManager.IssueOrder(Order.Command("map " + uid));
|
||||||
Game.Settings.Server.Map = newMapUid;
|
Game.Settings.Server.Map = uid;
|
||||||
Game.Settings.Save();
|
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
|
public class LobbyFaction
|
||||||
|
|||||||
Reference in New Issue
Block a user