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 Type = "Conquest";
public string PreviewVideo;
public string Description;
public string Author;
public string Tileset;

View File

@@ -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 }

View File

@@ -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<ScrollPanelWidget>("MISSION_LIST");
var headerTemplate = widget.Get<ScrollItemWidget>("HEADER");
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;
var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW");
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");
description = widget.Get<LabelWidget>("MISSION_DESCRIPTION");
description = descriptionPanel.Get<LabelWidget>("MISSION_DESCRIPTION");
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();
missionList.RemoveChildren();
@@ -86,15 +107,37 @@ namespace OpenRA.Mods.RA.Widgets.Logic
widget.Get<ButtonWidget>("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;

View File

@@ -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

View File

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

View File

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

View File

@@ -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

View File

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

View File

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