Add support for briefing videos in the mission menu.

This commit is contained in:
Paul Chote
2014-10-07 21:46:52 +13:00
parent 0a4117ec76
commit 5d32e97ef1
9 changed files with 170 additions and 65 deletions

View File

@@ -70,6 +70,7 @@ namespace OpenRA
public string Title; public string Title;
public string Type = "Conquest"; public string Type = "Conquest";
public string PreviewVideo;
public string Description; public string Description;
public string Author; public string Author;
public string Tileset; public string Tileset;

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
missionsButton.OnClick = () => missionsButton.OnClick = () =>
{ {
menuType = MenuType.None; menuType = MenuType.None;
Ui.OpenWindow("MISSIONBROWSER_PANEL", new WidgetArgs Game.OpenWindow("MISSIONBROWSER_PANEL", new WidgetArgs
{ {
{ "onExit", () => menuType = MenuType.Singleplayer }, { "onExit", () => menuType = MenuType.Singleplayer },
{ "onStart", RemoveShellmapUI } { "onStart", RemoveShellmapUI }

View File

@@ -12,6 +12,7 @@ using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using OpenRA.FileSystem;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Network; using OpenRA.Network;
using OpenRA.Widgets; using OpenRA.Widgets;
@@ -24,27 +25,47 @@ namespace OpenRA.Mods.RA.Widgets.Logic
readonly ScrollPanelWidget descriptionPanel; readonly ScrollPanelWidget descriptionPanel;
readonly LabelWidget description; readonly LabelWidget description;
readonly SpriteFont descriptionFont; readonly SpriteFont descriptionFont;
readonly ButtonWidget startVideoButton;
readonly ButtonWidget stopVideoButton;
readonly VqaPlayerWidget videoPlayer;
MapPreview selectedMapPreview; MapPreview selectedMapPreview;
bool showVideoPlayer;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public MissionBrowserLogic(Widget widget, Action onStart, Action onExit) public MissionBrowserLogic(Widget widget, Action onStart, Action onExit)
{ {
this.onStart = onStart; this.onStart = onStart;
var missionList = widget.Get<ScrollPanelWidget>("MISSION_LIST"); var missionList = widget.Get<ScrollPanelWidget>("MISSION_LIST");
var headerTemplate = widget.Get<ScrollItemWidget>("HEADER"); var headerTemplate = widget.Get<ScrollItemWidget>("HEADER");
var template = widget.Get<ScrollItemWidget>("TEMPLATE"); var template = widget.Get<ScrollItemWidget>("TEMPLATE");
var title = widget.GetOrNull<LabelWidget>("MISSIONBROWSER_TITLE");
if (title != null)
title.GetText = () => showVideoPlayer ? selectedMapPreview.Title : title.Text;
widget.Get("MISSION_INFO").IsVisible = () => selectedMapPreview != null; widget.Get("MISSION_INFO").IsVisible = () => selectedMapPreview != null;
var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW"); var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW");
previewWidget.Preview = () => selectedMapPreview; previewWidget.Preview = () => selectedMapPreview;
previewWidget.IsVisible = () => !showVideoPlayer;
videoPlayer = widget.Get<VqaPlayerWidget>("MISSION_VIDEO");
widget.Get("MISSION_BIN").IsVisible = () => showVideoPlayer;
descriptionPanel = widget.Get<ScrollPanelWidget>("MISSION_DESCRIPTION_PANEL"); descriptionPanel = widget.Get<ScrollPanelWidget>("MISSION_DESCRIPTION_PANEL");
description = widget.Get<LabelWidget>("MISSION_DESCRIPTION");
description = descriptionPanel.Get<LabelWidget>("MISSION_DESCRIPTION");
descriptionFont = Game.Renderer.Fonts[description.Font]; descriptionFont = Game.Renderer.Fonts[description.Font];
startVideoButton = widget.Get<ButtonWidget>("START_VIDEO_BUTTON");
stopVideoButton = widget.Get<ButtonWidget>("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(); var yaml = new MiniYaml(null, Game.modData.Manifest.Missions.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergeLiberal)).ToDictionary();
missionList.RemoveChildren(); missionList.RemoveChildren();
@@ -86,15 +107,37 @@ namespace OpenRA.Mods.RA.Widgets.Logic
widget.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => widget.Get<ButtonWidget>("BACK_BUTTON").OnClick = () =>
{ {
StopVideo();
Game.Disconnect(); Game.Disconnect();
Ui.CloseWindow(); Ui.CloseWindow();
onExit(); onExit();
}; };
} }
float cachedSoundVolume;
float cachedMusicVolume;
void SelectMap(Map map) void SelectMap(Map map)
{ {
StopVideo();
selectedMapPreview = Game.modData.MapCache[map.Uid]; 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") : ""; var text = map.Description != null ? map.Description.Replace("\\n", "\n") : "";
text = WidgetUtils.WrapText(text, description.Bounds.Width, descriptionFont); text = WidgetUtils.WrapText(text, description.Bounds.Width, descriptionFont);
@@ -104,8 +147,22 @@ namespace OpenRA.Mods.RA.Widgets.Logic
descriptionPanel.Layout.AdjustChildren(); descriptionPanel.Layout.AdjustChildren();
} }
void StopVideo()
{
if (!showVideoPlayer)
return;
Sound.SoundVolume = cachedSoundVolume;
Sound.MusicVolume = cachedMusicVolume;
videoPlayer.Stop();
showVideoPlayer = false;
}
void StartMission() void StartMission()
{ {
StopVideo();
OrderManager om = null; OrderManager om = null;
Action lobbyReady = null; Action lobbyReady = null;

View File

@@ -2,10 +2,10 @@ Container@MISSIONBROWSER_PANEL:
Logic: MissionBrowserLogic Logic: MissionBrowserLogic
X: (WINDOW_RIGHT - WIDTH)/2 X: (WINDOW_RIGHT - WIDTH)/2
Y: (WINDOW_BOTTOM - HEIGHT)/2 Y: (WINDOW_BOTTOM - HEIGHT)/2
Width: 629 Width: 642
Height: 399 Height: 377
Children: Children:
Label@MISSIONBROWSER_LABEL_TITLE: Label@MISSIONBROWSER_TITLE:
Y: 0-25 Y: 0-25
Width: PARENT_RIGHT Width: PARENT_RIGHT
Text: Missions Text: Missions
@@ -13,21 +13,20 @@ Container@MISSIONBROWSER_PANEL:
Contrast: true Contrast: true
Font: BigBold Font: BigBold
Background@BG: Background@BG:
Width: 629 Width: 642
Height: 360 Height: 377
Background: panel-black Background: panel-black
Children: Children:
ScrollPanel@MISSION_LIST: ScrollPanel@MISSION_LIST:
X: 15 X: 15
Y: 15 Y: 15
Width: 260 Width: 239
Height: 330 Height: 347
Children: Children:
ScrollItem@HEADER: ScrollItem@HEADER:
Width: PARENT_RIGHT-27 Width: PARENT_RIGHT-27
Height: 13 Height: 13
X: 2 X: 2
Y: 0
Visible: false Visible: false
Children: Children:
Label@LABEL: Label@LABEL:
@@ -39,7 +38,6 @@ Container@MISSIONBROWSER_PANEL:
Width: PARENT_RIGHT-27 Width: PARENT_RIGHT-27
Height: 25 Height: 25
X: 2 X: 2
Y: 0
Visible: False Visible: False
Children: Children:
Label@TITLE: Label@TITLE:
@@ -47,50 +45,67 @@ Container@MISSIONBROWSER_PANEL:
Width: PARENT_RIGHT-20 Width: PARENT_RIGHT-20
Height: 25 Height: 25
Container@MISSION_INFO: Container@MISSION_INFO:
X: 290 X: 265
Y: 15 Y: 15
Width: 324 Width: 362
Height: 334 Height: 349
Children: Children:
Background@MISSION_BG: Background@MISSION_BG:
X: 0 Width: PARENT_RIGHT
Y: 0 Height: 202
Width: 324 Background: panel-black
Height: 160
Background: panel-gray
Children: Children:
MapPreview@MISSION_PREVIEW: MapPreview@MISSION_PREVIEW:
X: 2 X: 1
Y: 2 Y: 1
Width: PARENT_RIGHT-4 Width: PARENT_RIGHT-2
Height: PARENT_BOTTOM-4 Height: PARENT_BOTTOM-2
IgnoreMouseOver: True IgnoreMouseOver: True
IgnoreMouseInput: True IgnoreMouseInput: True
ShowSpawnPoints: False ShowSpawnPoints: False
ScrollPanel@MISSION_DESCRIPTION_PANEL: ScrollPanel@MISSION_DESCRIPTION_PANEL:
X: 0 Y: 213
Y: 171 Width: PARENT_RIGHT
Width: 324 Height: 134
Height: 159
Children: Children:
Label@MISSION_DESCRIPTION: Label@MISSION_DESCRIPTION:
X: 5 X: 4
Y: 5 Y: 1
Width: 290 Width: PARENT_RIGHT - 32
VAlign: Top VAlign: Top
Font: Small
Button@BACK_BUTTON: Button@BACK_BUTTON:
X: 0 Y: 376
Y: 359
Width: 140 Width: 140
Height: 35 Height: 35
Text: Back Text: Back
Font: Bold Font: Bold
Key: escape Key: escape
Button@STARTGAME_BUTTON: Button@START_VIDEO_BUTTON:
X: PARENT_RIGHT - 140 X: PARENT_RIGHT - 290
Y: 359 Y: 376
Width: 140 Width: 140
Height: 35 Height: 35
Text: Start Game Text: View Briefing
Font: Bold 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

View File

@@ -170,6 +170,9 @@ ChromeMetrics:
./mods/cnc/metrics.yaml ./mods/cnc/metrics.yaml
Fonts: Fonts:
Small:
Font:FreeSans.ttf
Size:12
Regular: Regular:
Font:./FreeSans.ttf Font:./FreeSans.ttf
Size:14 Size:14

View File

@@ -166,6 +166,9 @@ Fonts:
BigBold: BigBold:
Font:./FreeSansBold.ttf Font:./FreeSansBold.ttf
Size:24 Size:24
Small:
Font:FreeSans.ttf
Size:12
Tiny: Tiny:
Font:./FreeSans.ttf Font:./FreeSans.ttf
Size:10 Size:10

View File

@@ -2,11 +2,10 @@ Background@MISSIONBROWSER_PANEL:
Logic: MissionBrowserLogic Logic: MissionBrowserLogic
X: (WINDOW_RIGHT - WIDTH)/2 X: (WINDOW_RIGHT - WIDTH)/2
Y: (WINDOW_BOTTOM - HEIGHT)/2 Y: (WINDOW_BOTTOM - HEIGHT)/2
Width: 634 Width: 682
Height: 440 Height: 487
Children: Children:
Label@MISSIONBROWSER_LABEL_TITLE: Label@MISSIONBROWSER_TITLE:
X: 0
Y: 20 Y: 20
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: 25 Height: 25
@@ -16,15 +15,14 @@ Background@MISSIONBROWSER_PANEL:
ScrollPanel@MISSION_LIST: ScrollPanel@MISSION_LIST:
X: 20 X: 20
Y: 50 Y: 50
Width: 260 Width: 270
Height: 330 Height: 377
Children: Children:
ScrollItem@HEADER: ScrollItem@HEADER:
BaseName: scrollheader BaseName: scrollheader
Width: PARENT_RIGHT-27 Width: PARENT_RIGHT-27
Height: 13 Height: 13
X: 2 X: 2
Y: 0
Visible: false Visible: false
Children: Children:
Label@LABEL: Label@LABEL:
@@ -36,50 +34,61 @@ Background@MISSIONBROWSER_PANEL:
Width: PARENT_RIGHT-27 Width: PARENT_RIGHT-27
Height: 25 Height: 25
X: 2 X: 2
Y: 0
Children: Children:
Label@TITLE: Label@TITLE:
X: 10 X: 10
Width: PARENT_RIGHT-20 Width: PARENT_RIGHT-20
Height: 25 Height: 25
Container@MISSION_INFO: Container@MISSION_INFO:
X: 290 X: 300
Y: 50 Y: 50
Width: 324 Width: 362
Height: 330 Height: 363
Children: Children:
Background@MISSION_BG: Background@MISSION_BG:
X: 0 Width: PARENT_RIGHT
Y: 0 Height: 202
Width: 324
Height: 160
Background: dialog3 Background: dialog3
Children: Children:
MapPreview@MISSION_PREVIEW: MapPreview@MISSION_PREVIEW:
X: 2 X: 1
Y: 2 Y: 1
Width: PARENT_RIGHT-4 Width: PARENT_RIGHT-2
Height: PARENT_BOTTOM-4 Height: PARENT_BOTTOM-2
IgnoreMouseOver: True IgnoreMouseOver: True
IgnoreMouseInput: True IgnoreMouseInput: True
ShowSpawnPoints: False ShowSpawnPoints: False
ScrollPanel@MISSION_DESCRIPTION_PANEL: ScrollPanel@MISSION_DESCRIPTION_PANEL:
X: 0 Y: 212
Y: 170 Width: PARENT_RIGHT
Width: 324 Height: 165
Height: 160
Children: Children:
Label@MISSION_DESCRIPTION: Label@MISSION_DESCRIPTION:
X: 5 X: 4
Y: 5 Y: 1
Width: 290 Width: PARENT_RIGHT - 32
VAlign: Top 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: Button@STARTGAME_BUTTON:
X: PARENT_RIGHT - 140 - 130 X: PARENT_RIGHT - 140 - 130
Y: PARENT_BOTTOM - 45 Y: PARENT_BOTTOM - 45
Width: 120 Width: 120
Height: 25 Height: 25
Text: Start Game Text: Play
Font: Bold Font: Bold
Button@BACK_BUTTON: Button@BACK_BUTTON:
X: PARENT_RIGHT - 140 X: PARENT_RIGHT - 140
@@ -89,4 +98,15 @@ Background@MISSIONBROWSER_PANEL:
Text: Back Text: Back
Font: Bold Font: Bold
Key: escape 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

View File

@@ -182,6 +182,9 @@ Fonts:
BigBold: BigBold:
Font:./FreeSansBold.ttf Font:./FreeSansBold.ttf
Size:24 Size:24
Small:
Font:FreeSans.ttf
Size:12
Tiny: Tiny:
Font:./FreeSans.ttf Font:./FreeSans.ttf
Size:10 Size:10

View File

@@ -207,6 +207,9 @@ Fonts:
BigBold: BigBold:
Font:./FreeSansBold.ttf Font:./FreeSansBold.ttf
Size:24 Size:24
Small:
Font:FreeSans.ttf
Size:12
Tiny: Tiny:
Font:./FreeSans.ttf Font:./FreeSans.ttf
Size:10 Size:10