Replays with MapPreview (like in Lobby)
This commit is contained in:
@@ -34,8 +34,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
readonly Dictionary<ReplayMetadata, ReplayState> replayState = new Dictionary<ReplayMetadata, ReplayState>();
|
||||
readonly Action onStart;
|
||||
readonly ModData modData;
|
||||
readonly WebServices services;
|
||||
|
||||
Dictionary<CPos, SpawnOccupant> selectedSpawns;
|
||||
MapPreview Map { get; set; }
|
||||
ReplayMetadata selectedReplay;
|
||||
|
||||
volatile bool cancelLoadingReplays;
|
||||
@@ -43,8 +44,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
[ObjectCreator.UseCtor]
|
||||
public ReplayBrowserLogic(Widget widget, ModData modData, Action onExit, Action onStart)
|
||||
{
|
||||
Map = MapCache.UnknownMap;
|
||||
panel = widget;
|
||||
|
||||
services = modData.Manifest.Get<WebServices>();
|
||||
this.modData = modData;
|
||||
this.onStart = onStart;
|
||||
Game.BeforeGameStart += OnGameStart;
|
||||
@@ -66,31 +69,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
ThreadPool.QueueUserWorkItem(_ => LoadReplays(dir, template));
|
||||
|
||||
var watch = panel.Get<ButtonWidget>("WATCH_BUTTON");
|
||||
watch.IsDisabled = () => selectedReplay == null || selectedReplay.GameInfo.MapPreview.Status != MapStatus.Available;
|
||||
watch.IsDisabled = () => selectedReplay == null || Map.Status != MapStatus.Available;
|
||||
watch.OnClick = () => { WatchReplay(); };
|
||||
|
||||
panel.Get("REPLAY_INFO").IsVisible = () => selectedReplay != null;
|
||||
|
||||
var preview = panel.Get<MapPreviewWidget>("MAP_PREVIEW");
|
||||
preview.SpawnOccupants = () => selectedSpawns;
|
||||
preview.Preview = () => selectedReplay != null ? selectedReplay.GameInfo.MapPreview : null;
|
||||
|
||||
var titleLabel = panel.GetOrNull<LabelWidget>("MAP_TITLE");
|
||||
if (titleLabel != null)
|
||||
Ui.LoadWidget("MAP_PREVIEW", panel.Get("MAP_PREVIEW_ROOT"), new WidgetArgs
|
||||
{
|
||||
titleLabel.IsVisible = () => selectedReplay != null;
|
||||
|
||||
var font = Game.Renderer.Fonts[titleLabel.Font];
|
||||
var title = new CachedTransform<MapPreview, string>(m => WidgetUtils.TruncateText(m.Title, titleLabel.Bounds.Width, font));
|
||||
titleLabel.GetText = () => title.Update(selectedReplay.GameInfo.MapPreview);
|
||||
}
|
||||
|
||||
var type = panel.GetOrNull<LabelWidget>("MAP_TYPE");
|
||||
if (type != null)
|
||||
{
|
||||
var mapType = new CachedTransform<MapPreview, string>(m => m.Categories.FirstOrDefault() ?? "");
|
||||
type.GetText = () => mapType.Update(selectedReplay.GameInfo.MapPreview);
|
||||
}
|
||||
{ "orderManager", null },
|
||||
{ "getMap", (Func<MapPreview>)(() => Map) },
|
||||
{ "onMouseDown", (Action<MapPreviewWidget, MapPreview, MouseInput>)((preview, map, mi) => { }) },
|
||||
{ "getSpawnOccupants", (Func<MapPreview, Dictionary<CPos, SpawnOccupant>>)(map => LobbyUtils.GetSpawnOccupants(selectedReplay.GameInfo.Players, map)) },
|
||||
});
|
||||
|
||||
panel.Get<LabelWidget>("DURATION").GetText = () => WidgetUtils.FormatTimeSeconds((int)selectedReplay.GameInfo.Duration.TotalSeconds);
|
||||
|
||||
@@ -594,6 +584,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
SelectFirstVisibleReplay();
|
||||
|
||||
replayList.Layout.AdjustChildren();
|
||||
replayList.ScrollToSelectedItem();
|
||||
}
|
||||
|
||||
void SelectFirstVisibleReplay()
|
||||
@@ -604,15 +595,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
void SelectReplay(ReplayMetadata replay)
|
||||
{
|
||||
selectedReplay = replay;
|
||||
selectedSpawns = (selectedReplay != null)
|
||||
? LobbyUtils.GetSpawnOccupants(selectedReplay.GameInfo.Players, selectedReplay.GameInfo.MapPreview)
|
||||
: new Dictionary<CPos, SpawnOccupant>();
|
||||
Map = (selectedReplay != null) ? selectedReplay.GameInfo.MapPreview : MapCache.UnknownMap;
|
||||
|
||||
if (replay == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if (Map.Status != MapStatus.Available)
|
||||
{
|
||||
if (Map.Status == MapStatus.DownloadAvailable)
|
||||
LoadMapPreviewRules(Map);
|
||||
else if (Game.Settings.Game.AllowDownloading)
|
||||
modData.MapCache.QueryRemoteMapDetails(services.MapRepository, new[] { Map.Uid }, LoadMapPreviewRules);
|
||||
}
|
||||
|
||||
var players = replay.GameInfo.Players
|
||||
.GroupBy(p => p.Team)
|
||||
.OrderBy(g => g.Key);
|
||||
@@ -667,6 +664,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
}
|
||||
|
||||
void LoadMapPreviewRules(MapPreview map)
|
||||
{
|
||||
new Task(() =>
|
||||
{
|
||||
// Force map rules to be loaded on this background thread
|
||||
map.PreloadRules();
|
||||
}).Start();
|
||||
}
|
||||
|
||||
void WatchReplay()
|
||||
{
|
||||
if (selectedReplay != null && ReplayUtils.PromptConfirmReplayCompatibility(selectedReplay))
|
||||
|
||||
Reference in New Issue
Block a user