Remove Map usage from MissionBrowerLogic.
This commit is contained in:
@@ -43,11 +43,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
readonly ScrollPanelWidget missionList;
|
readonly ScrollPanelWidget missionList;
|
||||||
readonly ScrollItemWidget headerTemplate;
|
readonly ScrollItemWidget headerTemplate;
|
||||||
readonly ScrollItemWidget template;
|
readonly ScrollItemWidget template;
|
||||||
readonly Cache<MapPreview, Map> mapCache;
|
|
||||||
|
|
||||||
MapPreview selectedMapPreview;
|
|
||||||
Map selectedMap;
|
|
||||||
|
|
||||||
|
MapPreview selectedMap;
|
||||||
PlayingVideo playingVideo;
|
PlayingVideo playingVideo;
|
||||||
|
|
||||||
string difficulty;
|
string difficulty;
|
||||||
@@ -56,7 +53,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public MissionBrowserLogic(Widget widget, ModData modData, World world, Action onStart, Action onExit)
|
public MissionBrowserLogic(Widget widget, ModData modData, World world, Action onStart, Action onExit)
|
||||||
{
|
{
|
||||||
mapCache = new Cache<MapPreview, Map>(p => new Map(modData, p.Package));
|
|
||||||
this.modData = modData;
|
this.modData = modData;
|
||||||
this.onStart = onStart;
|
this.onStart = onStart;
|
||||||
|
|
||||||
@@ -67,12 +63,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
var title = widget.GetOrNull<LabelWidget>("MISSIONBROWSER_TITLE");
|
var title = widget.GetOrNull<LabelWidget>("MISSIONBROWSER_TITLE");
|
||||||
if (title != null)
|
if (title != null)
|
||||||
title.GetText = () => playingVideo != PlayingVideo.None ? selectedMapPreview.Title : title.Text;
|
title.GetText = () => playingVideo != PlayingVideo.None ? selectedMap.Title : title.Text;
|
||||||
|
|
||||||
widget.Get("MISSION_INFO").IsVisible = () => selectedMapPreview != null;
|
widget.Get("MISSION_INFO").IsVisible = () => selectedMap != null;
|
||||||
|
|
||||||
var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW");
|
var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW");
|
||||||
previewWidget.Preview = () => selectedMapPreview;
|
previewWidget.Preview = () => selectedMap;
|
||||||
previewWidget.IsVisible = () => playingVideo == PlayingVideo.None;
|
previewWidget.IsVisible = () => playingVideo == PlayingVideo.None;
|
||||||
|
|
||||||
videoPlayer = widget.Get<VqaPlayerWidget>("MISSION_VIDEO");
|
videoPlayer = widget.Get<VqaPlayerWidget>("MISSION_VIDEO");
|
||||||
@@ -132,11 +128,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
if (allPreviews.Any())
|
if (allPreviews.Any())
|
||||||
SelectMap(allPreviews.First());
|
SelectMap(allPreviews.First());
|
||||||
|
|
||||||
// Preload map and preview data to reduce jank
|
// Preload map preview and rules to reduce jank
|
||||||
new Thread(() =>
|
new Thread(() =>
|
||||||
{
|
{
|
||||||
foreach (var p in allPreviews)
|
foreach (var p in allPreviews)
|
||||||
modData.MapCache[mapCache[p].Uid].GetMinimap();
|
{
|
||||||
|
p.GetMinimap();
|
||||||
|
var unused = p.Rules;
|
||||||
|
}
|
||||||
}).Start();
|
}).Start();
|
||||||
|
|
||||||
var startButton = widget.Get<ButtonWidget>("STARTGAME_BUTTON");
|
var startButton = widget.Get<ButtonWidget>("STARTGAME_BUTTON");
|
||||||
@@ -163,7 +162,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var preview = p;
|
var preview = p;
|
||||||
|
|
||||||
var item = ScrollItemWidget.Setup(template,
|
var item = ScrollItemWidget.Setup(template,
|
||||||
() => selectedMapPreview != null && selectedMapPreview.Uid == preview.Uid,
|
() => selectedMap != null && selectedMap.Uid == preview.Uid,
|
||||||
() => SelectMap(preview),
|
() => SelectMap(preview),
|
||||||
StartMissionClicked);
|
StartMissionClicked);
|
||||||
|
|
||||||
@@ -174,8 +173,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
void SelectMap(MapPreview preview)
|
void SelectMap(MapPreview preview)
|
||||||
{
|
{
|
||||||
selectedMap = mapCache[preview];
|
selectedMap = preview;
|
||||||
selectedMapPreview = preview;
|
|
||||||
|
|
||||||
// Cache the rules on a background thread to avoid jank
|
// Cache the rules on a background thread to avoid jank
|
||||||
var difficultyDisabled = true;
|
var difficultyDisabled = true;
|
||||||
@@ -189,17 +187,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var infoVideoVisible = false;
|
var infoVideoVisible = false;
|
||||||
var infoVideoDisabled = true;
|
var infoVideoDisabled = true;
|
||||||
|
|
||||||
var map = selectedMap;
|
|
||||||
new Thread(() =>
|
new Thread(() =>
|
||||||
{
|
{
|
||||||
map.PreloadRules();
|
var mapOptions = preview.Rules.Actors["world"].TraitInfo<MapOptionsInfo>();
|
||||||
var mapOptions = map.Rules.Actors["world"].TraitInfo<MapOptionsInfo>();
|
|
||||||
|
|
||||||
difficulty = mapOptions.Difficulty ?? mapOptions.Difficulties.FirstOrDefault();
|
difficulty = mapOptions.Difficulty ?? mapOptions.Difficulties.FirstOrDefault();
|
||||||
difficulties = mapOptions.Difficulties;
|
difficulties = mapOptions.Difficulties;
|
||||||
difficultyDisabled = mapOptions.DifficultyLocked || mapOptions.Difficulties.Length <= 1;
|
difficultyDisabled = mapOptions.DifficultyLocked || mapOptions.Difficulties.Length <= 1;
|
||||||
|
|
||||||
var missionData = map.Rules.Actors["world"].TraitInfoOrDefault<MissionDataInfo>();
|
var missionData = preview.Rules.Actors["world"].TraitInfoOrDefault<MissionDataInfo>();
|
||||||
if (missionData != null)
|
if (missionData != null)
|
||||||
{
|
{
|
||||||
briefingVideo = missionData.BriefingVideo;
|
briefingVideo = missionData.BriefingVideo;
|
||||||
@@ -214,7 +210,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var height = descriptionFont.Measure(briefing).Y;
|
var height = descriptionFont.Measure(briefing).Y;
|
||||||
Game.RunAfterTick(() =>
|
Game.RunAfterTick(() =>
|
||||||
{
|
{
|
||||||
if (map == selectedMap)
|
if (preview == selectedMap)
|
||||||
{
|
{
|
||||||
description.Text = briefing;
|
description.Text = briefing;
|
||||||
description.Bounds.Height = height;
|
description.Bounds.Height = height;
|
||||||
@@ -348,11 +344,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
PlayVideo(fsPlayer, missionData.StartVideo, PlayingVideo.GameStart, () =>
|
PlayVideo(fsPlayer, missionData.StartVideo, PlayingVideo.GameStart, () =>
|
||||||
{
|
{
|
||||||
StopVideo(fsPlayer);
|
StopVideo(fsPlayer);
|
||||||
Game.CreateAndStartLocalServer(selectedMapPreview.Uid, orders, onStart);
|
Game.CreateAndStartLocalServer(selectedMap.Uid, orders, onStart);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Game.CreateAndStartLocalServer(selectedMapPreview.Uid, orders, onStart);
|
Game.CreateAndStartLocalServer(selectedMap.Uid, orders, onStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DropDownOption
|
class DropDownOption
|
||||||
|
|||||||
Reference in New Issue
Block a user