Streamline SpawnOccupant management.

This commit is contained in:
Paul Chote
2020-10-01 23:37:16 +01:00
committed by reaperrr
parent 6f32196f89
commit 60df247416
7 changed files with 38 additions and 46 deletions

View File

@@ -62,6 +62,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
bool disableTeamChat;
bool teamChat;
bool updateDiscordStatus = true;
Dictionary<int, SpawnOccupant> spawnOccupants = new Dictionary<int, SpawnOccupant>();
readonly string chatLineSound = ChromeMetrics.Get<string>("ChatLineSound");
@@ -118,6 +119,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Game.LobbyInfoChanged += UpdateCurrentMap;
Game.LobbyInfoChanged += UpdatePlayerList;
Game.LobbyInfoChanged += UpdateDiscordStatus;
Game.LobbyInfoChanged += UpdateSpawnOccupants;
Game.BeforeGameStart += OnGameStart;
Game.ConnectionStateChanged += ConnectionStateChanged;
@@ -133,10 +135,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
"onMouseDown", (Action<MapPreviewWidget, MapPreview, MouseInput>)((preview, mapPreview, mi) =>
LobbyUtils.SelectSpawnPoint(orderManager, preview, mapPreview, mi))
},
{
"getSpawnOccupants", (Func<MapPreview, Dictionary<CPos, SpawnOccupant>>)(mapPreview =>
LobbyUtils.GetSpawnOccupants(orderManager.LobbyInfo, mapPreview))
},
{ "getSpawnOccupants", (Func<Dictionary<int, SpawnOccupant>>)(() => spawnOccupants) },
{ "showUnoccupiedSpawnpoints", true },
});
@@ -464,6 +463,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Game.LobbyInfoChanged -= UpdateCurrentMap;
Game.LobbyInfoChanged -= UpdatePlayerList;
Game.LobbyInfoChanged -= UpdateDiscordStatus;
Game.LobbyInfoChanged -= UpdateSpawnOccupants;
Game.BeforeGameStart -= OnGameStart;
Game.ConnectionStateChanged -= ConnectionStateChanged;
}
@@ -789,6 +789,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
}
void UpdateSpawnOccupants()
{
spawnOccupants = orderManager.LobbyInfo.Clients
.Where(c => c.SpawnPoint != 0)
.ToDictionary(c => c.SpawnPoint, c => new SpawnOccupant(c));
}
void OnGameStart()
{
Ui.CloseWindow();