Move mission briefing to rules.

This commit is contained in:
Paul Chote
2016-03-02 20:56:46 +00:00
parent 668e13b849
commit 01a14d9ae5
8 changed files with 68 additions and 70 deletions

View File

@@ -17,6 +17,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Defines the FMVs that can be played by missions.")]
public class MissionDataInfo : TraitInfo<MissionData>
{
[Desc("Briefing text displayed in the mission browser.")]
public readonly string Briefing;
[Desc("Played by the \"Background Info\" button in the mission browser.")]
public readonly string BackgroundVideo;

View File

@@ -67,8 +67,6 @@ namespace OpenRA.Mods.Common.UtilityCommands
Author = "Westwood Studios"
};
Map.Description = ExtractBriefing(file);
Map.RequiresMod = modData.Manifest.Mod.Id;
SetBounds(Map, mapSection);
@@ -77,6 +75,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
ReadTrees(file);
LoadVideos(file, "BASIC");
LoadBriefing(file);
ReadActors(file);
@@ -120,17 +119,34 @@ namespace OpenRA.Mods.Common.UtilityCommands
public abstract void ValidateMapFormat(int format);
static string ExtractBriefing(IniFile file)
void LoadBriefing(IniFile file)
{
var briefingSection = file.GetSection("Briefing", true);
if (briefingSection == null)
return string.Empty;
return;
var briefing = new StringBuilder();
foreach (var s in briefingSection)
briefing.AppendLine(s.Value);
return briefing.Replace("\n", " ").ToString();
if (briefing.Length == 0)
return;
var worldNode = Rules.Nodes.FirstOrDefault(n => n.Key == "World");
if (worldNode == null)
{
worldNode = new MiniYamlNode("World", new MiniYaml("", new List<MiniYamlNode>()));
Rules.Nodes.Add(worldNode);
}
var missionData = worldNode.Value.Nodes.FirstOrDefault(n => n.Key == "MissionData");
if (missionData == null)
{
missionData = new MiniYamlNode("MissionData", new MiniYaml("", new List<MiniYamlNode>()));
worldNode.Value.Nodes.Add(missionData);
}
missionData.Value.Nodes.Add(new MiniYamlNode("Briefing", briefing.Replace("\n", " ").ToString()));
}
static void SetBounds(Map map, IniSection mapSection)

View File

@@ -52,10 +52,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var author = widget.Get<TextFieldWidget>("AUTHOR");
author.Text = map.Author;
// TODO: This should use a multi-line textfield once they exist
var description = widget.Get<TextFieldWidget>("DESCRIPTION");
description.Text = map.Description;
// TODO: This should use a multi-selection dropdown once they exist
var visibilityDropdown = widget.Get<DropDownButtonWidget>("VISIBILITY_DROPDOWN");
{
@@ -160,7 +156,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return;
map.Title = title.Text;
map.Description = description.Text;
map.Author = author.Text;
map.Visibility = (MapVisibility)Enum.Parse(typeof(MapVisibility), visibilityDropdown.Text);

View File

@@ -9,6 +9,7 @@
*/
#endregion
using OpenRA.Mods.Common.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
@@ -24,12 +25,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var mapDescriptionPanel = widget.Get<ScrollPanelWidget>("MAP_DESCRIPTION_PANEL");
var mapDescription = widget.Get<LabelWidget>("MAP_DESCRIPTION");
var mapFont = Game.Renderer.Fonts[mapDescription.Font];
var text = world.Map.Description != null ? world.Map.Description.Replace("\\n", "\n") : "";
text = WidgetUtils.WrapText(text, mapDescription.Bounds.Width, mapFont);
mapDescription.Text = text;
mapDescription.Bounds.Height = mapFont.Measure(text).Y;
mapDescriptionPanel.ScrollToTop();
mapDescriptionPanel.Layout.AdjustChildren();
var missionData = world.Map.Rules.Actors["world"].TraitInfoOrDefault<MissionDataInfo>();
if (missionData != null)
{
var text = WidgetUtils.WrapText(missionData.Briefing.Replace("\\n", "\n"), mapDescription.Bounds.Width, mapFont);
mapDescription.Text = text;
mapDescription.Bounds.Height = mapFont.Measure(text).Y;
mapDescriptionPanel.ScrollToTop();
mapDescriptionPanel.Layout.AdjustChildren();
}
}
}
}

View File

@@ -189,16 +189,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var infoVideoVisible = false;
var infoVideoDisabled = true;
var map = selectedMap;
new Thread(() =>
{
selectedMap.PreloadRules();
var mapOptions = selectedMap.Rules.Actors["world"].TraitInfo<MapOptionsInfo>();
map.PreloadRules();
var mapOptions = map.Rules.Actors["world"].TraitInfo<MapOptionsInfo>();
difficulty = mapOptions.Difficulty ?? mapOptions.Difficulties.FirstOrDefault();
difficulties = mapOptions.Difficulties;
difficultyDisabled = mapOptions.DifficultyLocked || mapOptions.Difficulties.Length <= 1;
var missionData = selectedMap.Rules.Actors["world"].TraitInfoOrDefault<MissionDataInfo>();
var missionData = map.Rules.Actors["world"].TraitInfoOrDefault<MissionDataInfo>();
if (missionData != null)
{
briefingVideo = missionData.BriefingVideo;
@@ -208,6 +209,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
infoVideo = missionData.BackgroundVideo;
infoVideoVisible = infoVideo != null;
infoVideoDisabled = !(infoVideoVisible && modData.DefaultFileSystem.Exists(infoVideo));
var briefing = WidgetUtils.WrapText(missionData.Briefing.Replace("\\n", "\n"), description.Bounds.Width, descriptionFont);
var height = descriptionFont.Measure(briefing).Y;
Game.RunAfterTick(() =>
{
if (map == selectedMap)
{
description.Text = briefing;
description.Bounds.Height = height;
descriptionPanel.Layout.AdjustChildren();
}
});
}
}).Start();
@@ -219,12 +232,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
startInfoVideoButton.IsDisabled = () => infoVideoDisabled || playingVideo != PlayingVideo.None;
startInfoVideoButton.OnClick = () => PlayVideo(videoPlayer, infoVideo, PlayingVideo.Info, () => StopVideo(videoPlayer));
var text = selectedMap.Description != null ? selectedMap.Description.Replace("\\n", "\n") : "";
text = WidgetUtils.WrapText(text, description.Bounds.Width, descriptionFont);
description.Text = text;
description.Bounds.Height = descriptionFont.Measure(text).Y;
descriptionPanel.ScrollToTop();
descriptionPanel.Layout.AdjustChildren();
if (difficultyButton != null)
{