From 5d32e97ef1228d84b9cf4e482ddf74bd9bce6b3d Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 7 Oct 2014 21:46:52 +1300 Subject: [PATCH] Add support for briefing videos in the mission menu. --- OpenRA.Game/Map/Map.cs | 1 + OpenRA.Mods.RA/Widgets/Logic/MainMenuLogic.cs | 2 +- .../Widgets/Logic/MissionBrowserLogic.cs | 59 ++++++++++++- mods/cnc/chrome/missionbrowser.yaml | 85 +++++++++++-------- mods/cnc/mod.yaml | 3 + mods/d2k/mod.yaml | 3 + mods/ra/chrome/missionbrowser.yaml | 76 +++++++++++------ mods/ra/mod.yaml | 3 + mods/ts/mod.yaml | 3 + 9 files changed, 170 insertions(+), 65 deletions(-) diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 30b8751024..ed276aa344 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -70,6 +70,7 @@ namespace OpenRA public string Title; public string Type = "Conquest"; + public string PreviewVideo; public string Description; public string Author; public string Tileset; diff --git a/OpenRA.Mods.RA/Widgets/Logic/MainMenuLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/MainMenuLogic.cs index fe6a885022..2aee8c1f08 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/MainMenuLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/MainMenuLogic.cs @@ -79,7 +79,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic missionsButton.OnClick = () => { menuType = MenuType.None; - Ui.OpenWindow("MISSIONBROWSER_PANEL", new WidgetArgs + Game.OpenWindow("MISSIONBROWSER_PANEL", new WidgetArgs { { "onExit", () => menuType = MenuType.Singleplayer }, { "onStart", RemoveShellmapUI } diff --git a/OpenRA.Mods.RA/Widgets/Logic/MissionBrowserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/MissionBrowserLogic.cs index da606bf6ec..96eff6bdb1 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/MissionBrowserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/MissionBrowserLogic.cs @@ -12,6 +12,7 @@ using System; using System.IO; using System.Linq; using System.Net; +using OpenRA.FileSystem; using OpenRA.Graphics; using OpenRA.Network; using OpenRA.Widgets; @@ -24,27 +25,47 @@ namespace OpenRA.Mods.RA.Widgets.Logic readonly ScrollPanelWidget descriptionPanel; readonly LabelWidget description; readonly SpriteFont descriptionFont; + readonly ButtonWidget startVideoButton; + readonly ButtonWidget stopVideoButton; + readonly VqaPlayerWidget videoPlayer; MapPreview selectedMapPreview; + bool showVideoPlayer; + [ObjectCreator.UseCtor] public MissionBrowserLogic(Widget widget, Action onStart, Action onExit) { this.onStart = onStart; var missionList = widget.Get("MISSION_LIST"); + var headerTemplate = widget.Get("HEADER"); var template = widget.Get("TEMPLATE"); + var title = widget.GetOrNull("MISSIONBROWSER_TITLE"); + if (title != null) + title.GetText = () => showVideoPlayer ? selectedMapPreview.Title : title.Text; + widget.Get("MISSION_INFO").IsVisible = () => selectedMapPreview != null; var previewWidget = widget.Get("MISSION_PREVIEW"); previewWidget.Preview = () => selectedMapPreview; + previewWidget.IsVisible = () => !showVideoPlayer; + + videoPlayer = widget.Get("MISSION_VIDEO"); + widget.Get("MISSION_BIN").IsVisible = () => showVideoPlayer; descriptionPanel = widget.Get("MISSION_DESCRIPTION_PANEL"); - description = widget.Get("MISSION_DESCRIPTION"); + + description = descriptionPanel.Get("MISSION_DESCRIPTION"); descriptionFont = Game.Renderer.Fonts[description.Font]; + startVideoButton = widget.Get("START_VIDEO_BUTTON"); + stopVideoButton = widget.Get("STOP_VIDEO_BUTTON"); + stopVideoButton.IsVisible = () => showVideoPlayer; + stopVideoButton.OnClick = StopVideo; + var yaml = new MiniYaml(null, Game.modData.Manifest.Missions.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergeLiberal)).ToDictionary(); missionList.RemoveChildren(); @@ -86,15 +107,37 @@ namespace OpenRA.Mods.RA.Widgets.Logic widget.Get("BACK_BUTTON").OnClick = () => { + StopVideo(); Game.Disconnect(); Ui.CloseWindow(); onExit(); }; } + float cachedSoundVolume; + float cachedMusicVolume; void SelectMap(Map map) { + StopVideo(); + selectedMapPreview = Game.modData.MapCache[map.Uid]; + var video = selectedMapPreview.Map.PreviewVideo; + var videoVisible = video != null; + var videoDisabled = !(videoVisible && GlobalFileSystem.Exists(video)); + + startVideoButton.IsVisible = () => videoVisible && !showVideoPlayer; + startVideoButton.IsDisabled = () => videoDisabled; + startVideoButton.OnClick = () => + { + showVideoPlayer = true; + videoPlayer.Load(video); + videoPlayer.PlayThen(StopVideo); + + // Mute other distracting sounds + cachedSoundVolume = Sound.SoundVolume; + cachedMusicVolume = Sound.MusicVolume; + Sound.SoundVolume = Sound.MusicVolume = 0; + }; var text = map.Description != null ? map.Description.Replace("\\n", "\n") : ""; text = WidgetUtils.WrapText(text, description.Bounds.Width, descriptionFont); @@ -104,8 +147,22 @@ namespace OpenRA.Mods.RA.Widgets.Logic descriptionPanel.Layout.AdjustChildren(); } + void StopVideo() + { + if (!showVideoPlayer) + return; + + Sound.SoundVolume = cachedSoundVolume; + Sound.MusicVolume = cachedMusicVolume; + + videoPlayer.Stop(); + showVideoPlayer = false; + } + void StartMission() { + StopVideo(); + OrderManager om = null; Action lobbyReady = null; diff --git a/mods/cnc/chrome/missionbrowser.yaml b/mods/cnc/chrome/missionbrowser.yaml index 995559029e..c4e27df95b 100644 --- a/mods/cnc/chrome/missionbrowser.yaml +++ b/mods/cnc/chrome/missionbrowser.yaml @@ -2,10 +2,10 @@ Container@MISSIONBROWSER_PANEL: Logic: MissionBrowserLogic X: (WINDOW_RIGHT - WIDTH)/2 Y: (WINDOW_BOTTOM - HEIGHT)/2 - Width: 629 - Height: 399 + Width: 642 + Height: 377 Children: - Label@MISSIONBROWSER_LABEL_TITLE: + Label@MISSIONBROWSER_TITLE: Y: 0-25 Width: PARENT_RIGHT Text: Missions @@ -13,21 +13,20 @@ Container@MISSIONBROWSER_PANEL: Contrast: true Font: BigBold Background@BG: - Width: 629 - Height: 360 + Width: 642 + Height: 377 Background: panel-black Children: ScrollPanel@MISSION_LIST: X: 15 Y: 15 - Width: 260 - Height: 330 + Width: 239 + Height: 347 Children: ScrollItem@HEADER: Width: PARENT_RIGHT-27 Height: 13 X: 2 - Y: 0 Visible: false Children: Label@LABEL: @@ -39,7 +38,6 @@ Container@MISSIONBROWSER_PANEL: Width: PARENT_RIGHT-27 Height: 25 X: 2 - Y: 0 Visible: False Children: Label@TITLE: @@ -47,50 +45,67 @@ Container@MISSIONBROWSER_PANEL: Width: PARENT_RIGHT-20 Height: 25 Container@MISSION_INFO: - X: 290 + X: 265 Y: 15 - Width: 324 - Height: 334 + Width: 362 + Height: 349 Children: Background@MISSION_BG: - X: 0 - Y: 0 - Width: 324 - Height: 160 - Background: panel-gray + Width: PARENT_RIGHT + Height: 202 + Background: panel-black Children: MapPreview@MISSION_PREVIEW: - X: 2 - Y: 2 - Width: PARENT_RIGHT-4 - Height: PARENT_BOTTOM-4 + X: 1 + Y: 1 + Width: PARENT_RIGHT-2 + Height: PARENT_BOTTOM-2 IgnoreMouseOver: True IgnoreMouseInput: True ShowSpawnPoints: False ScrollPanel@MISSION_DESCRIPTION_PANEL: - X: 0 - Y: 171 - Width: 324 - Height: 159 + Y: 213 + Width: PARENT_RIGHT + Height: 134 Children: Label@MISSION_DESCRIPTION: - X: 5 - Y: 5 - Width: 290 + X: 4 + Y: 1 + Width: PARENT_RIGHT - 32 VAlign: Top + Font: Small Button@BACK_BUTTON: - X: 0 - Y: 359 + Y: 376 Width: 140 Height: 35 Text: Back Font: Bold Key: escape - Button@STARTGAME_BUTTON: - X: PARENT_RIGHT - 140 - Y: 359 + Button@START_VIDEO_BUTTON: + X: PARENT_RIGHT - 290 + Y: 376 Width: 140 Height: 35 - Text: Start Game + Text: View Briefing Font: Bold - + Button@STOP_VIDEO_BUTTON: + X: PARENT_RIGHT - 290 + Y: 376 + Width: 140 + Height: 35 + Text: Stop Briefing + Font: Bold + Button@STARTGAME_BUTTON: + X: PARENT_RIGHT - 140 + Y: 376 + Width: 140 + Height: 35 + Text: Play + Font: Bold + Container@MISSION_BIN: + Children: + VqaPlayer@MISSION_VIDEO: + X: 1 + Y: 1 + Width: 640 + Height: 375 diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index f6704dbba1..6a26411a6a 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -170,6 +170,9 @@ ChromeMetrics: ./mods/cnc/metrics.yaml Fonts: + Small: + Font:FreeSans.ttf + Size:12 Regular: Font:./FreeSans.ttf Size:14 diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index 353c509d7f..a7b8a80ab8 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -166,6 +166,9 @@ Fonts: BigBold: Font:./FreeSansBold.ttf Size:24 + Small: + Font:FreeSans.ttf + Size:12 Tiny: Font:./FreeSans.ttf Size:10 diff --git a/mods/ra/chrome/missionbrowser.yaml b/mods/ra/chrome/missionbrowser.yaml index fdd60ce8dc..65bfb17581 100644 --- a/mods/ra/chrome/missionbrowser.yaml +++ b/mods/ra/chrome/missionbrowser.yaml @@ -2,11 +2,10 @@ Background@MISSIONBROWSER_PANEL: Logic: MissionBrowserLogic X: (WINDOW_RIGHT - WIDTH)/2 Y: (WINDOW_BOTTOM - HEIGHT)/2 - Width: 634 - Height: 440 + Width: 682 + Height: 487 Children: - Label@MISSIONBROWSER_LABEL_TITLE: - X: 0 + Label@MISSIONBROWSER_TITLE: Y: 20 Width: PARENT_RIGHT Height: 25 @@ -16,15 +15,14 @@ Background@MISSIONBROWSER_PANEL: ScrollPanel@MISSION_LIST: X: 20 Y: 50 - Width: 260 - Height: 330 + Width: 270 + Height: 377 Children: ScrollItem@HEADER: BaseName: scrollheader Width: PARENT_RIGHT-27 Height: 13 X: 2 - Y: 0 Visible: false Children: Label@LABEL: @@ -36,50 +34,61 @@ Background@MISSIONBROWSER_PANEL: Width: PARENT_RIGHT-27 Height: 25 X: 2 - Y: 0 Children: Label@TITLE: X: 10 Width: PARENT_RIGHT-20 Height: 25 Container@MISSION_INFO: - X: 290 + X: 300 Y: 50 - Width: 324 - Height: 330 + Width: 362 + Height: 363 Children: Background@MISSION_BG: - X: 0 - Y: 0 - Width: 324 - Height: 160 + Width: PARENT_RIGHT + Height: 202 Background: dialog3 Children: MapPreview@MISSION_PREVIEW: - X: 2 - Y: 2 - Width: PARENT_RIGHT-4 - Height: PARENT_BOTTOM-4 + X: 1 + Y: 1 + Width: PARENT_RIGHT-2 + Height: PARENT_BOTTOM-2 IgnoreMouseOver: True IgnoreMouseInput: True ShowSpawnPoints: False ScrollPanel@MISSION_DESCRIPTION_PANEL: - X: 0 - Y: 170 - Width: 324 - Height: 160 + Y: 212 + Width: PARENT_RIGHT + Height: 165 Children: Label@MISSION_DESCRIPTION: - X: 5 - Y: 5 - Width: 290 + X: 4 + Y: 1 + Width: PARENT_RIGHT - 32 VAlign: Top + Font: Small + Button@START_VIDEO_BUTTON: + X: 20 + Y: PARENT_BOTTOM - 45 + Width: 120 + Height: 25 + Text: Play Briefing + Font: Bold + Button@STOP_VIDEO_BUTTON: + X: 20 + Y: PARENT_BOTTOM - 45 + Width: 120 + Height: 25 + Text: Stop Briefing + Font: Bold Button@STARTGAME_BUTTON: X: PARENT_RIGHT - 140 - 130 Y: PARENT_BOTTOM - 45 Width: 120 Height: 25 - Text: Start Game + Text: Play Font: Bold Button@BACK_BUTTON: X: PARENT_RIGHT - 140 @@ -89,4 +98,15 @@ Background@MISSIONBROWSER_PANEL: Text: Back Font: Bold Key: escape - + Background@MISSION_BIN: + X: 20 + Y: 50 + Width: 642 + Height: 377 + Background: dialog3 + Children: + VqaPlayer@MISSION_VIDEO: + X: 1 + Y: 1 + Width: 640 + Height: 375 diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index 4781530520..ce28346587 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -182,6 +182,9 @@ Fonts: BigBold: Font:./FreeSansBold.ttf Size:24 + Small: + Font:FreeSans.ttf + Size:12 Tiny: Font:./FreeSans.ttf Size:10 diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index 002a037ebd..3eef8e96d1 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -207,6 +207,9 @@ Fonts: BigBold: Font:./FreeSansBold.ttf Size:24 + Small: + Font:FreeSans.ttf + Size:12 Tiny: Font:./FreeSans.ttf Size:10