Replays with MapPreview (like in Lobby)

This commit is contained in:
rob-v
2017-05-06 15:51:53 +02:00
committed by Paul Chote
parent 0e3cc1ad28
commit a26210f914
3 changed files with 44 additions and 100 deletions

View File

@@ -34,8 +34,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly Dictionary<ReplayMetadata, ReplayState> replayState = new Dictionary<ReplayMetadata, ReplayState>(); readonly Dictionary<ReplayMetadata, ReplayState> replayState = new Dictionary<ReplayMetadata, ReplayState>();
readonly Action onStart; readonly Action onStart;
readonly ModData modData; readonly ModData modData;
readonly WebServices services;
Dictionary<CPos, SpawnOccupant> selectedSpawns; MapPreview Map { get; set; }
ReplayMetadata selectedReplay; ReplayMetadata selectedReplay;
volatile bool cancelLoadingReplays; volatile bool cancelLoadingReplays;
@@ -43,8 +44,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public ReplayBrowserLogic(Widget widget, ModData modData, Action onExit, Action onStart) public ReplayBrowserLogic(Widget widget, ModData modData, Action onExit, Action onStart)
{ {
Map = MapCache.UnknownMap;
panel = widget; panel = widget;
services = modData.Manifest.Get<WebServices>();
this.modData = modData; this.modData = modData;
this.onStart = onStart; this.onStart = onStart;
Game.BeforeGameStart += OnGameStart; Game.BeforeGameStart += OnGameStart;
@@ -66,31 +69,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
ThreadPool.QueueUserWorkItem(_ => LoadReplays(dir, template)); ThreadPool.QueueUserWorkItem(_ => LoadReplays(dir, template));
var watch = panel.Get<ButtonWidget>("WATCH_BUTTON"); 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(); }; watch.OnClick = () => { WatchReplay(); };
panel.Get("REPLAY_INFO").IsVisible = () => selectedReplay != null; panel.Get("REPLAY_INFO").IsVisible = () => selectedReplay != null;
var preview = panel.Get<MapPreviewWidget>("MAP_PREVIEW"); Ui.LoadWidget("MAP_PREVIEW", panel.Get("MAP_PREVIEW_ROOT"), new WidgetArgs
preview.SpawnOccupants = () => selectedSpawns;
preview.Preview = () => selectedReplay != null ? selectedReplay.GameInfo.MapPreview : null;
var titleLabel = panel.GetOrNull<LabelWidget>("MAP_TITLE");
if (titleLabel != null)
{ {
titleLabel.IsVisible = () => selectedReplay != null; { "orderManager", null },
{ "getMap", (Func<MapPreview>)(() => Map) },
var font = Game.Renderer.Fonts[titleLabel.Font]; { "onMouseDown", (Action<MapPreviewWidget, MapPreview, MouseInput>)((preview, map, mi) => { }) },
var title = new CachedTransform<MapPreview, string>(m => WidgetUtils.TruncateText(m.Title, titleLabel.Bounds.Width, font)); { "getSpawnOccupants", (Func<MapPreview, Dictionary<CPos, SpawnOccupant>>)(map => LobbyUtils.GetSpawnOccupants(selectedReplay.GameInfo.Players, map)) },
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);
}
panel.Get<LabelWidget>("DURATION").GetText = () => WidgetUtils.FormatTimeSeconds((int)selectedReplay.GameInfo.Duration.TotalSeconds); panel.Get<LabelWidget>("DURATION").GetText = () => WidgetUtils.FormatTimeSeconds((int)selectedReplay.GameInfo.Duration.TotalSeconds);
@@ -594,6 +584,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
SelectFirstVisibleReplay(); SelectFirstVisibleReplay();
replayList.Layout.AdjustChildren(); replayList.Layout.AdjustChildren();
replayList.ScrollToSelectedItem();
} }
void SelectFirstVisibleReplay() void SelectFirstVisibleReplay()
@@ -604,15 +595,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void SelectReplay(ReplayMetadata replay) void SelectReplay(ReplayMetadata replay)
{ {
selectedReplay = replay; selectedReplay = replay;
selectedSpawns = (selectedReplay != null) Map = (selectedReplay != null) ? selectedReplay.GameInfo.MapPreview : MapCache.UnknownMap;
? LobbyUtils.GetSpawnOccupants(selectedReplay.GameInfo.Players, selectedReplay.GameInfo.MapPreview)
: new Dictionary<CPos, SpawnOccupant>();
if (replay == null) if (replay == null)
return; return;
try 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 var players = replay.GameInfo.Players
.GroupBy(p => p.Team) .GroupBy(p => p.Team)
.OrderBy(g => g.Key); .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() void WatchReplay()
{ {
if (selectedReplay != null && ReplayUtils.PromptConfirmReplayCompatibility(selectedReplay)) if (selectedReplay != null && ReplayUtils.PromptConfirmReplayCompatibility(selectedReplay))

View File

@@ -193,56 +193,25 @@ Container@REPLAYBROWSER_PANEL:
X: 10 X: 10
Width: PARENT_RIGHT - 20 Width: PARENT_RIGHT - 20
Height: 25 Height: 25
Container@MAP_BG_CONTAINER: Container@MAP_PREVIEW_ROOT:
X: PARENT_RIGHT - WIDTH - 20 X: PARENT_RIGHT - WIDTH - 20
Y: 20 Y: 50
Width: 194 Width: 194
Height: 30 + 194 Height: 250
Children:
Label@MAP_BG_TITLE:
Width: PARENT_RIGHT
Height: 25
Text: Preview
Align: Center
Font: Bold
Background@MAP_BG:
Y: 30
Width: 194
Height: 194
Background: panel-gray
Children:
MapPreview@MAP_PREVIEW:
X: 1
Y: 1
Width: 192
Height: 192
TooltipContainer: TOOLTIP_CONTAINER
Container@REPLAY_INFO: Container@REPLAY_INFO:
X: PARENT_RIGHT - WIDTH - 20 X: PARENT_RIGHT - WIDTH - 20
Y: 20 + 30 + 194 + 10 Y: 250
Width: 194 Width: 194
Height: PARENT_BOTTOM - 20 - 30 - 194 - 10 - 20 Height: PARENT_BOTTOM - 260
Children: Children:
Label@MAP_TITLE:
Y: 0
Width: PARENT_RIGHT
Height: 15
Font: Bold
Align: Center
Label@MAP_TYPE:
Y: 15
Width: PARENT_RIGHT
Height: 15
Font: TinyBold
Align: Center
Label@DURATION: Label@DURATION:
Y: 30 Y: 20
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: 15 Height: 15
Font: Tiny Font: Tiny
Align: Center Align: Center
ScrollPanel@PLAYER_LIST: ScrollPanel@PLAYER_LIST:
Y: 50 Y: 40
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: PARENT_BOTTOM - 50 Height: PARENT_BOTTOM - 50
IgnoreChildMouseOver: true IgnoreChildMouseOver: true

View File

@@ -181,56 +181,25 @@ Background@REPLAYBROWSER_PANEL:
X: 10 X: 10
Width: PARENT_RIGHT - 20 Width: PARENT_RIGHT - 20
Height: 25 Height: 25
Container@MAP_BG_CONTAINER: Container@MAP_PREVIEW_ROOT:
X: PARENT_RIGHT - WIDTH - 20 X: PARENT_RIGHT - WIDTH - 20
Y: 20 Y: 50
Width: 194 Width: 194
Height: 30 + 194 Height: 250
Children:
Label@MAP_BG_TITLE:
Width: PARENT_RIGHT
Height: 25
Text: Preview
Align: Center
Font: Bold
Background@MAP_BG:
Y: 30
Width: 194
Height: 194
Background: dialog3
Children:
MapPreview@MAP_PREVIEW:
X: 1
Y: 1
Width: 192
Height: 192
TooltipContainer: TOOLTIP_CONTAINER
Container@REPLAY_INFO: Container@REPLAY_INFO:
X: PARENT_RIGHT - WIDTH - 20 X: PARENT_RIGHT - WIDTH - 20
Y: 20 + 30 + 194 + 10 Y: 250
Width: 194 Width: 194
Height: PARENT_BOTTOM - 20 - 30 - 194 - 10 - 55 Height: PARENT_BOTTOM - 250 - 45
Children: Children:
Label@MAP_TITLE:
Y: 0
Width: PARENT_RIGHT
Height: 15
Font: Bold
Align: Center
Label@MAP_TYPE:
Y: 15
Width: PARENT_RIGHT
Height: 15
Font: TinyBold
Align: Center
Label@DURATION: Label@DURATION:
Y: 30 Y: 20
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: 15 Height: 15
Font: Tiny Font: Tiny
Align: Center Align: Center
ScrollPanel@PLAYER_LIST: ScrollPanel@PLAYER_LIST:
Y: 50 Y: 40
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: PARENT_BOTTOM - 50 Height: PARENT_BOTTOM - 50
IgnoreChildMouseOver: true IgnoreChildMouseOver: true