Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replays - Install missing map #13233

Merged
merged 3 commits into from May 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/OpenRA.Mods.Common.csproj
Expand Up @@ -618,7 +618,7 @@
<Compile Include="Widgets\Logic\Lobby\KickClientLogic.cs" />
<Compile Include="Widgets\Logic\Lobby\KickSpectatorsLogic.cs" />
<Compile Include="Widgets\Logic\Lobby\LobbyLogic.cs" />
<Compile Include="Widgets\Logic\Lobby\LobbyMapPreviewLogic.cs" />
<Compile Include="Widgets\Logic\Lobby\MapPreviewLogic.cs" />
<Compile Include="Widgets\Logic\Lobby\LobbyUtils.cs" />
<Compile Include="Widgets\Logic\Lobby\SpawnSelectorTooltipLogic.cs" />
<Compile Include="Widgets\Logic\MainMenuLogic.cs" />
Expand Down
65 changes: 32 additions & 33 deletions OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs
Expand Up @@ -16,7 +16,6 @@
using System.Threading.Tasks;
using OpenRA.Chat;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Network;
using OpenRA.Traits;
using OpenRA.Widgets;
Expand All @@ -27,8 +26,6 @@ public class LobbyLogic : ChromeLogic
{
static readonly Action DoNothing = () => { };

public MapPreview Map { get; private set; }

readonly ModData modData;
readonly Action onStart;
readonly Action onExit;
Expand Down Expand Up @@ -64,10 +61,10 @@ enum ChatPanelType { Lobby, Global }
readonly TabCompletionLogic tabCompletion = new TabCompletionLogic();

readonly LabelWidget chatLabel;
bool teamChat;

MapPreview map;
bool addBotOnMapLoad;

bool teamChat;
int lobbyChatUnreadMessages;
int globalChatLastReadMessages;
int globalChatUnreadMessages;
Expand Down Expand Up @@ -106,7 +103,7 @@ void ConnectionStateChanged(OrderManager om)
internal LobbyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, OrderManager orderManager,
Action onExit, Action onStart, bool skirmishMode)
{
Map = MapCache.UnknownMap;
map = MapCache.UnknownMap;
lobby = widget;
this.modData = modData;
this.orderManager = orderManager;
Expand All @@ -130,10 +127,12 @@ void ConnectionStateChanged(OrderManager om)
if (name != null)
name.GetText = () => orderManager.LobbyInfo.GlobalSettings.ServerName;

Ui.LoadWidget("LOBBY_MAP_PREVIEW", lobby.Get("MAP_PREVIEW_ROOT"), new WidgetArgs
Ui.LoadWidget("MAP_PREVIEW", lobby.Get("MAP_PREVIEW_ROOT"), new WidgetArgs
{
{ "orderManager", orderManager },
{ "lobby", this }
{ "getMap", (Func<MapPreview>)(() => map) },
{ "onMouseDown", (Action<MapPreviewWidget, MapPreview, MouseInput>)((preview, map, mi) => LobbyUtils.SelectSpawnPoint(orderManager, preview, map, mi)) },
{ "getSpawnOccupants", (Func<MapPreview, Dictionary<CPos, SpawnOccupant>>)(map => LobbyUtils.GetSpawnOccupants(orderManager.LobbyInfo, map)) },
});

UpdateCurrentMap();
Expand All @@ -157,7 +156,7 @@ void ConnectionStateChanged(OrderManager om)
var gameStarting = false;
Func<bool> configurationDisabled = () => !Game.IsHost || gameStarting ||
panel == PanelType.Kick || panel == PanelType.ForceStart ||
!Map.RulesLoaded || Map.InvalidCustomRules ||
!map.RulesLoaded || map.InvalidCustomRules ||
orderManager.LocalClient == null || orderManager.LocalClient.IsReady;

var mapButton = lobby.GetOrNull<ButtonWidget>("CHANGEMAP_BUTTON");
Expand All @@ -170,7 +169,7 @@ void ConnectionStateChanged(OrderManager om)
var onSelect = new Action<string>(uid =>
{
// Don't select the same map again
if (uid == Map.Uid)
if (uid == map.Uid)
return;

orderManager.IssueOrder(Order.Command("map " + uid));
Expand All @@ -180,7 +179,7 @@ void ConnectionStateChanged(OrderManager om)

Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs()
{
{ "initialMap", Map.Uid },
{ "initialMap", map.Uid },
{ "initialTab", MapClassification.System },
{ "onExit", DoNothing },
{ "onSelect", Game.IsHost ? onSelect : null },
Expand All @@ -198,7 +197,7 @@ void ConnectionStateChanged(OrderManager om)

slotsButton.OnMouseDown = _ =>
{
var botNames = Map.Rules.Actors["player"].TraitInfos<IBotInfo>().Select(t => t.Name);
var botNames = map.Rules.Actors["player"].TraitInfos<IBotInfo>().Select(t => t.Name);
var options = new Dictionary<string, IEnumerable<DropDownOption>>();

var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
Expand Down Expand Up @@ -296,7 +295,7 @@ void ConnectionStateChanged(OrderManager om)

var optionsTab = lobby.Get<ButtonWidget>("OPTIONS_TAB");
optionsTab.IsHighlighted = () => panel == PanelType.Options;
optionsTab.IsDisabled = () => !Map.RulesLoaded || Map.InvalidCustomRules || panel == PanelType.Kick || panel == PanelType.ForceStart;
optionsTab.IsDisabled = () => !map.RulesLoaded || map.InvalidCustomRules || panel == PanelType.Kick || panel == PanelType.ForceStart;
optionsTab.OnClick = () => panel = PanelType.Options;

var playersTab = lobby.Get<ButtonWidget>("PLAYERS_TAB");
Expand All @@ -319,7 +318,7 @@ void ConnectionStateChanged(OrderManager om)
var startGameButton = lobby.GetOrNull<ButtonWidget>("START_GAME_BUTTON");
if (startGameButton != null)
{
startGameButton.IsDisabled = () => configurationDisabled() || Map.Status != MapStatus.Available ||
startGameButton.IsDisabled = () => configurationDisabled() || map.Status != MapStatus.Available ||
orderManager.LobbyInfo.Slots.Any(sl => sl.Value.Required && orderManager.LobbyInfo.ClientInSlot(sl.Key) == null) ||
(!orderManager.LobbyInfo.GlobalSettings.EnableSingleplayer && orderManager.LobbyInfo.IsSinglePlayer);

Expand Down Expand Up @@ -400,14 +399,14 @@ void ConnectionStateChanged(OrderManager om)
var getOptionLabel = new CachedTransform<string, string>(id =>
{
string value;
if (id == null || !option.Update(Map).Values.TryGetValue(id, out value))
if (id == null || !option.Update(map).Values.TryGetValue(id, out value))
return "Not Available";

return value;
});

dropdown.GetText = () => getOptionLabel.Update(optionValue.Update(orderManager.LobbyInfo.GlobalSettings).Value);
dropdown.IsVisible = () => option.Update(Map) != null;
dropdown.IsVisible = () => option.Update(map) != null;
dropdown.IsDisabled = () => configurationDisabled() ||
optionValue.Update(orderManager.LobbyInfo.GlobalSettings).Locked;

Expand All @@ -423,13 +422,13 @@ void ConnectionStateChanged(OrderManager om)
return item;
};

var options = option.Update(Map).Values;
var options = option.Update(map).Values;
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem);
};

var label = optionsBin.GetOrNull(kv.Key + "_DESC");
if (label != null)
label.IsVisible = () => option.Update(Map) != null;
label.IsVisible = () => option.Update(map) != null;
}
}

Expand Down Expand Up @@ -595,22 +594,22 @@ void LoadMapPreviewRules(MapPreview map)
void UpdateCurrentMap()
{
var uid = orderManager.LobbyInfo.GlobalSettings.Map;
if (Map.Uid == uid)
if (map.Uid == uid)
return;

Map = modData.MapCache[uid];
if (Map.Status == MapStatus.Available)
map = modData.MapCache[uid];
if (map.Status == MapStatus.Available)
{
// Maps need to be validated and pre-loaded before they can be accessed
var currentMap = Map;
var currentMap = map;
new Task(() =>
{
// Force map rules to be loaded on this background thread
currentMap.PreloadRules();
Game.RunAfterTick(() =>
{
// Map may have changed in the meantime
if (currentMap != Map)
if (currentMap != map)
return;

// Tell the server that we have the map
Expand All @@ -630,8 +629,8 @@ void UpdateCurrentMap()
});
}).Start();
}
else if (Map.Status == MapStatus.DownloadAvailable)
LoadMapPreviewRules(Map);
else if (map.Status == MapStatus.DownloadAvailable)
LoadMapPreviewRules(map);
else if (Game.Settings.Game.AllowDownloading)
modData.MapCache.QueryRemoteMapDetails(services.MapRepository, new[] { uid }, LoadMapPreviewRules);
}
Expand Down Expand Up @@ -661,7 +660,7 @@ void UpdatePlayerList()
template = emptySlotTemplate.Clone();

if (isHost)
LobbyUtils.SetupEditableSlotWidget(this, template, slot, client, orderManager);
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, map);
else
LobbyUtils.SetupSlotWidget(template, slot, client);

Expand All @@ -680,15 +679,15 @@ void UpdatePlayerList()
LobbyUtils.SetupClientWidget(template, client, orderManager, client.Bot == null);

if (client.Bot != null)
LobbyUtils.SetupEditableSlotWidget(this, template, slot, client, orderManager);
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, map);
else
LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager);

LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, shellmapWorld, colorPreview);
LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, factions);
LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, Map);
LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, Map);
LobbyUtils.SetupEditableReadyWidget(template, slot, client, orderManager, Map);
LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, map);
LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, map);
LobbyUtils.SetupEditableReadyWidget(template, slot, client, orderManager, map);
}
else
{
Expand All @@ -704,8 +703,8 @@ void UpdatePlayerList()
LobbyUtils.SetupFactionWidget(template, slot, client, factions);
if (isHost)
{
LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, Map);
LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, Map);
LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, map);
LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, map);
}
else
{
Expand Down Expand Up @@ -745,7 +744,7 @@ void UpdatePlayerList()
LobbyUtils.SetupEditableNameWidget(template, null, c, orderManager);

if (client.IsAdmin)
LobbyUtils.SetupEditableReadyWidget(template, null, client, orderManager, Map);
LobbyUtils.SetupEditableReadyWidget(template, null, client, orderManager, map);
}
else
{
Expand Down