From 01a14d9ae5ffe5272537f4cc2257267d1314acf9 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 2 Mar 2016 20:56:46 +0000 Subject: [PATCH] Move mission briefing to rules. --- OpenRA.Game/Map/Map.cs | 3 -- .../Traits/World/MissionData.cs | 3 ++ .../UtilityCommands/ImportLegacyMapCommand.cs | 26 +++++++++++++--- .../Widgets/Logic/Editor/SaveMapLogic.cs | 5 --- .../Logic/Ingame/GameInfoBriefingLogic.cs | 17 ++++++---- .../Widgets/Logic/MissionBrowserLogic.cs | 24 +++++++++----- mods/cnc/chrome/editor.yaml | 31 ++++++------------- mods/ra/chrome/editor.yaml | 29 +++++------------ 8 files changed, 68 insertions(+), 70 deletions(-) diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 19fa1d1c78..476b201405 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -86,7 +86,6 @@ namespace OpenRA public string Title; public string Type = "Conquest"; - public string Description; public string Author; public string Tileset; public Bitmap CustomPreview; @@ -201,7 +200,6 @@ namespace OpenRA var tileRef = new TerrainTile(tileset.Templates.First().Key, 0); Title = "Name your map here"; - Description = "Describe your map here"; Author = "Your name here"; MapSize = new int2(size); @@ -429,7 +427,6 @@ namespace OpenRA "MapFormat", "RequiresMod", "Title", - "Description", "Author", "Tileset", "MapSize", diff --git a/OpenRA.Mods.Common/Traits/World/MissionData.cs b/OpenRA.Mods.Common/Traits/World/MissionData.cs index 04817ce7b5..5c7370974b 100644 --- a/OpenRA.Mods.Common/Traits/World/MissionData.cs +++ b/OpenRA.Mods.Common/Traits/World/MissionData.cs @@ -17,6 +17,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("Defines the FMVs that can be played by missions.")] public class MissionDataInfo : TraitInfo { + [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; diff --git a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs index 2a1e18e287..b64cfe17c9 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs @@ -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())); + 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())); + worldNode.Value.Nodes.Add(missionData); + } + + missionData.Value.Nodes.Add(new MiniYamlNode("Briefing", briefing.Replace("\n", " ").ToString())); } static void SetBounds(Map map, IniSection mapSection) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs index 5dcd4a7d8b..4f89cebd16 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs @@ -52,10 +52,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic var author = widget.Get("AUTHOR"); author.Text = map.Author; - // TODO: This should use a multi-line textfield once they exist - var description = widget.Get("DESCRIPTION"); - description.Text = map.Description; - // TODO: This should use a multi-selection dropdown once they exist var visibilityDropdown = widget.Get("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); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoBriefingLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoBriefingLogic.cs index ef0622cff6..b029c32c16 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoBriefingLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoBriefingLogic.cs @@ -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("MAP_DESCRIPTION_PANEL"); var mapDescription = widget.Get("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(); + 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(); + } } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs index c2d0bb9782..484fc132f6 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs @@ -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(); + map.PreloadRules(); + var mapOptions = map.Rules.Actors["world"].TraitInfo(); difficulty = mapOptions.Difficulty ?? mapOptions.Difficulties.FirstOrDefault(); difficulties = mapOptions.Difficulties; difficultyDisabled = mapOptions.DifficultyLocked || mapOptions.Difficulties.Length <= 1; - var missionData = selectedMap.Rules.Actors["world"].TraitInfoOrDefault(); + var missionData = map.Rules.Actors["world"].TraitInfoOrDefault(); 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) { diff --git a/mods/cnc/chrome/editor.yaml b/mods/cnc/chrome/editor.yaml index f36150d269..6da45a9ad9 100644 --- a/mods/cnc/chrome/editor.yaml +++ b/mods/cnc/chrome/editor.yaml @@ -78,7 +78,7 @@ Background@SAVE_MAP_PANEL: X: (WINDOW_RIGHT - WIDTH)/2 Y: (WINDOW_BOTTOM - HEIGHT)/2 Width: 345 - Height: 264 + Height: 229 Children: Label@LABEL_TITLE: Text: Save Map @@ -89,7 +89,7 @@ Background@SAVE_MAP_PANEL: Align: Center Background@SAVE_MAP_BACKGROUND: Width: PARENT_RIGHT - Height: 230 + Height: 195 Background: panel-black Children: Label@TITLE_LABEL: @@ -118,60 +118,47 @@ Background@SAVE_MAP_PANEL: Width: 220 MaxLength: 50 Height: 25 - Label@DESCRIPTION_LABEL: - X: 10 - Y: 84 - Width: 95 - Height: 25 - Align: Right - Text: Description: - TextField@DESCRIPTION: - X: 110 - Y: 85 - Width: 220 - MaxLength: 50 - Height: 25 Label@VISIBILITY_LABEL: X: 10 - Y: 119 + Y: 84 Width: 95 Height: 25 Align: Right Text: Visibility: DropDownButton@VISIBILITY_DROPDOWN: X: 110 - Y: 120 + Y: 85 Width: 220 Height: 25 Font: Regular Label@DIRECTORY_LABEL: X: 10 - Y: 154 + Y: 119 Width: 95 Height: 25 Align: Right Text: Directory: DropDownButton@DIRECTORY_DROPDOWN: X: 110 - Y: 155 + Y: 120 Width: 220 Height: 25 Font: Regular Label@FILENAME_LABEL: X: 10 - Y: 189 + Y: 154 Width: 95 Height: 25 Align: Right Text: Filename: TextField@FILENAME: X: 110 - Y: 190 + Y: 155 Width: 105 Height: 25 DropDownButton@TYPE_DROPDOWN: X: 220 - Y: 190 + Y: 155 Width: 110 Height: 25 Font: Regular diff --git a/mods/ra/chrome/editor.yaml b/mods/ra/chrome/editor.yaml index 864561c3b8..9cb9d32a56 100644 --- a/mods/ra/chrome/editor.yaml +++ b/mods/ra/chrome/editor.yaml @@ -75,7 +75,7 @@ Background@SAVE_MAP_PANEL: X: (WINDOW_RIGHT - WIDTH)/2 Y: (WINDOW_BOTTOM - HEIGHT)/2 Width: 350 - Height: 335 + Height: 300 Children: Label@LABEL_TITLE: X: (PARENT_RIGHT - WIDTH)/2 @@ -111,58 +111,45 @@ Background@SAVE_MAP_PANEL: Width: 220 MaxLength: 50 Height: 25 - Label@DESCRIPTION_LABEL: - X: 10 - Y: 129 - Width: 95 - Height: 25 - Align: Right - Text: Description: - TextField@DESCRIPTION: - X: 110 - Y: 130 - Width: 220 - MaxLength: 50 - Height: 25 Label@VISIBILITY_LABEL: X: 10 - Y: 164 + Y: 129 Width: 95 Height: 25 Align: Right Text: Visibility: DropDownButton@VISIBILITY_DROPDOWN: X: 110 - Y: 165 + Y: 130 Width: 220 Height: 25 Label@DIRECTORY_LABEL: X: 10 - Y: 199 + Y: 164 Width: 95 Height: 25 Align: Right Text: Directory: DropDownButton@DIRECTORY_DROPDOWN: X: 110 - Y: 200 + Y: 165 Width: 220 Height: 25 Label@FILENAME_LABEL: X: 10 - Y: 234 + Y: 199 Width: 95 Height: 25 Align: Right Text: Filename: TextField@FILENAME: X: 110 - Y: 235 + Y: 200 Width: 105 Height: 25 DropDownButton@TYPE_DROPDOWN: X: 220 - Y: 235 + Y: 200 Width: 110 Height: 25 Button@SAVE_BUTTON: