Merge pull request #11461 from pchote/fmv-install-prompt
Prompt FMV installation when trying to play a missing video.
This commit is contained in:
@@ -16,78 +16,82 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
public static class ConfirmationDialogs
|
||||
{
|
||||
public static void PromptConfirmAction(
|
||||
public static void ButtonPrompt(
|
||||
string title,
|
||||
string text,
|
||||
Action onConfirm,
|
||||
Action onConfirm = null,
|
||||
Action onCancel = null,
|
||||
Action onOther = null,
|
||||
string confirmText = null,
|
||||
string cancelText = null,
|
||||
string otherText = null)
|
||||
{
|
||||
var promptName = onOther != null ? "CONFIRM_PROMPT_THREEBUTTON" : "CONFIRM_PROMPT_TWOBUTTON";
|
||||
var promptName = onOther != null ? "THREEBUTTON_PROMPT" : "TWOBUTTON_PROMPT";
|
||||
var prompt = Ui.OpenWindow(promptName);
|
||||
var confirmButton = prompt.Get<ButtonWidget>("CONFIRM_BUTTON");
|
||||
var confirmButton = prompt.GetOrNull<ButtonWidget>("CONFIRM_BUTTON");
|
||||
var cancelButton = prompt.GetOrNull<ButtonWidget>("CANCEL_BUTTON");
|
||||
var otherButton = prompt.GetOrNull<ButtonWidget>("OTHER_BUTTON");
|
||||
|
||||
prompt.Get<LabelWidget>("PROMPT_TITLE").GetText = () => title;
|
||||
prompt.Get<LabelWidget>("PROMPT_TEXT").GetText = () => text;
|
||||
if (!string.IsNullOrEmpty(confirmText))
|
||||
confirmButton.GetText = () => confirmText;
|
||||
if (!string.IsNullOrEmpty(otherText) && otherButton != null)
|
||||
otherButton.GetText = () => otherText;
|
||||
if (!string.IsNullOrEmpty(cancelText) && cancelButton != null)
|
||||
cancelButton.GetText = () => cancelText;
|
||||
|
||||
confirmButton.OnClick = () =>
|
||||
var headerTemplate = prompt.Get<LabelWidget>("PROMPT_TEXT");
|
||||
var headerLines = text.Replace("\\n", "\n").Split('\n');
|
||||
var headerHeight = 0;
|
||||
foreach (var l in headerLines)
|
||||
{
|
||||
Ui.CloseWindow();
|
||||
onConfirm();
|
||||
};
|
||||
var line = (LabelWidget)headerTemplate.Clone();
|
||||
line.GetText = () => l;
|
||||
line.Bounds.Y += headerHeight;
|
||||
prompt.AddChild(line);
|
||||
|
||||
headerHeight += headerTemplate.Bounds.Height;
|
||||
}
|
||||
|
||||
prompt.Bounds.Height += headerHeight;
|
||||
prompt.Bounds.Y -= headerHeight / 2;
|
||||
|
||||
if (onConfirm != null && confirmButton != null)
|
||||
{
|
||||
confirmButton.Visible = true;
|
||||
confirmButton.Bounds.Y += headerHeight;
|
||||
confirmButton.OnClick = () =>
|
||||
{
|
||||
Ui.CloseWindow();
|
||||
onConfirm();
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(confirmText))
|
||||
confirmButton.GetText = () => confirmText;
|
||||
}
|
||||
|
||||
if (onCancel != null && cancelButton != null)
|
||||
{
|
||||
cancelButton.IsVisible = () => true;
|
||||
cancelButton.Visible = true;
|
||||
cancelButton.Bounds.Y += headerHeight;
|
||||
cancelButton.OnClick = () =>
|
||||
{
|
||||
Ui.CloseWindow();
|
||||
if (onCancel != null)
|
||||
onCancel();
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(cancelText) && cancelButton != null)
|
||||
cancelButton.GetText = () => cancelText;
|
||||
}
|
||||
else if (cancelButton != null)
|
||||
cancelButton.IsVisible = () => false;
|
||||
|
||||
if (onOther != null && otherButton != null)
|
||||
{
|
||||
otherButton.IsVisible = () => true;
|
||||
otherButton.Visible = true;
|
||||
otherButton.Bounds.Y += headerHeight;
|
||||
otherButton.OnClick = () =>
|
||||
{
|
||||
if (onOther != null)
|
||||
onOther();
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(otherText) && otherButton != null)
|
||||
otherButton.GetText = () => otherText;
|
||||
}
|
||||
else if (otherButton != null)
|
||||
otherButton.IsVisible = () => false;
|
||||
}
|
||||
|
||||
public static void CancelPrompt(string title, string text, Action onCancel = null, string cancelText = null)
|
||||
{
|
||||
var prompt = Ui.OpenWindow("CANCEL_PROMPT");
|
||||
prompt.Get<LabelWidget>("PROMPT_TITLE").GetText = () => title;
|
||||
prompt.Get<LabelWidget>("PROMPT_TEXT").GetText = () => text;
|
||||
|
||||
if (!string.IsNullOrEmpty(cancelText))
|
||||
prompt.Get<ButtonWidget>("CANCEL_BUTTON").GetText = () => cancelText;
|
||||
|
||||
prompt.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () =>
|
||||
{
|
||||
Ui.CloseWindow();
|
||||
if (onCancel != null)
|
||||
onCancel();
|
||||
};
|
||||
}
|
||||
|
||||
public static void TextInputPrompt(
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
};
|
||||
}
|
||||
|
||||
ConfirmationDialogs.PromptConfirmAction(
|
||||
ConfirmationDialogs.ButtonPrompt(
|
||||
title: "Leave Mission",
|
||||
text: "Leave this game and return to the menu?",
|
||||
onConfirm: onQuit,
|
||||
@@ -132,7 +132,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
exitEditorButton.OnClick = () =>
|
||||
{
|
||||
hideMenu = true;
|
||||
ConfirmationDialogs.PromptConfirmAction(
|
||||
ConfirmationDialogs.ButtonPrompt(
|
||||
title: "Exit Map Editor",
|
||||
text: "Exit and lose all unsaved changes?",
|
||||
onConfirm: onQuit,
|
||||
@@ -152,7 +152,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
surrenderButton.OnClick = () =>
|
||||
{
|
||||
hideMenu = true;
|
||||
ConfirmationDialogs.PromptConfirmAction(
|
||||
ConfirmationDialogs.ButtonPrompt(
|
||||
title: "Surrender",
|
||||
text: "Are you sure you want to surrender?",
|
||||
onConfirm: onSurrender,
|
||||
|
||||
@@ -328,7 +328,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
void DeleteOneMap(string map, Action<string> after)
|
||||
{
|
||||
ConfirmationDialogs.PromptConfirmAction(
|
||||
ConfirmationDialogs.ButtonPrompt(
|
||||
title: "Delete map",
|
||||
text: "Delete the map '{0}'?".F(modData.MapCache[map].Title),
|
||||
onConfirm: () =>
|
||||
@@ -343,7 +343,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
void DeleteAllMaps(string[] maps, Action<string> after)
|
||||
{
|
||||
ConfirmationDialogs.PromptConfirmAction(
|
||||
ConfirmationDialogs.ButtonPrompt(
|
||||
title: "Delete maps",
|
||||
text: "Delete all maps on this page?",
|
||||
onConfirm: () =>
|
||||
|
||||
@@ -200,11 +200,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
var briefingVideo = "";
|
||||
var briefingVideoVisible = false;
|
||||
var briefingVideoDisabled = true;
|
||||
|
||||
var infoVideo = "";
|
||||
var infoVideoVisible = false;
|
||||
var infoVideoDisabled = true;
|
||||
|
||||
new Thread(() =>
|
||||
{
|
||||
@@ -219,11 +217,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
briefingVideo = missionData.BriefingVideo;
|
||||
briefingVideoVisible = briefingVideo != null;
|
||||
briefingVideoDisabled = !(briefingVideoVisible && modData.DefaultFileSystem.Exists(briefingVideo));
|
||||
|
||||
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;
|
||||
@@ -240,12 +236,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}).Start();
|
||||
|
||||
startBriefingVideoButton.IsVisible = () => briefingVideoVisible && playingVideo != PlayingVideo.Briefing;
|
||||
startBriefingVideoButton.IsDisabled = () => briefingVideoDisabled || playingVideo != PlayingVideo.None;
|
||||
startBriefingVideoButton.OnClick = () => PlayVideo(videoPlayer, briefingVideo, PlayingVideo.Briefing, () => StopVideo(videoPlayer));
|
||||
startBriefingVideoButton.OnClick = () => PlayVideo(videoPlayer, briefingVideo, PlayingVideo.Briefing);
|
||||
|
||||
startInfoVideoButton.IsVisible = () => infoVideoVisible && playingVideo != PlayingVideo.Info;
|
||||
startInfoVideoButton.IsDisabled = () => infoVideoDisabled || playingVideo != PlayingVideo.None;
|
||||
startInfoVideoButton.OnClick = () => PlayVideo(videoPlayer, infoVideo, PlayingVideo.Info, () => StopVideo(videoPlayer));
|
||||
startInfoVideoButton.OnClick = () => PlayVideo(videoPlayer, infoVideo, PlayingVideo.Info);
|
||||
|
||||
descriptionPanel.ScrollToTop();
|
||||
|
||||
@@ -318,18 +312,34 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Game.Sound.MusicVolume = cachedMusicVolume;
|
||||
}
|
||||
|
||||
void PlayVideo(VqaPlayerWidget player, string video, PlayingVideo pv, Action onComplete)
|
||||
void PlayVideo(VqaPlayerWidget player, string video, PlayingVideo pv, Action onComplete = null)
|
||||
{
|
||||
StopVideo(player);
|
||||
if (!modData.DefaultFileSystem.Exists(video))
|
||||
{
|
||||
ConfirmationDialogs.ButtonPrompt(
|
||||
title: "Video not installed",
|
||||
text: "The game videos can be installed from the\n\"Manage Content\" menu in the mod chooser.",
|
||||
cancelText: "Back",
|
||||
onCancel: () => { });
|
||||
}
|
||||
else
|
||||
{
|
||||
StopVideo(player);
|
||||
|
||||
playingVideo = pv;
|
||||
player.Load(video);
|
||||
playingVideo = pv;
|
||||
player.Load(video);
|
||||
|
||||
// video playback runs asynchronously
|
||||
player.PlayThen(onComplete);
|
||||
// video playback runs asynchronously
|
||||
player.PlayThen(() =>
|
||||
{
|
||||
StopVideo(player);
|
||||
if (onComplete != null)
|
||||
onComplete();
|
||||
});
|
||||
|
||||
// Mute other distracting sounds
|
||||
MuteSounds();
|
||||
// Mute other distracting sounds
|
||||
MuteSounds();
|
||||
}
|
||||
}
|
||||
|
||||
void StopVideo(VqaPlayerWidget player)
|
||||
@@ -362,7 +372,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
fullscreenVideoPlayer.Visible = true;
|
||||
PlayVideo(fsPlayer, missionData.StartVideo, PlayingVideo.GameStart, () =>
|
||||
{
|
||||
StopVideo(fsPlayer);
|
||||
Game.CreateAndStartLocalServer(selectedMap.Uid, orders);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -409,7 +409,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
Action<ReplayMetadata, Action> onDeleteReplay = (r, after) =>
|
||||
{
|
||||
ConfirmationDialogs.PromptConfirmAction(
|
||||
ConfirmationDialogs.ButtonPrompt(
|
||||
title: "Delete selected replay?",
|
||||
text: "Delete replay '{0}'?".F(Path.GetFileNameWithoutExtension(r.FilePath)),
|
||||
onConfirm: () =>
|
||||
@@ -450,7 +450,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
return;
|
||||
}
|
||||
|
||||
ConfirmationDialogs.PromptConfirmAction(
|
||||
ConfirmationDialogs.ButtonPrompt(
|
||||
title: "Delete all selected replays?",
|
||||
text: "Delete {0} replays?".F(list.Count),
|
||||
onConfirm: () =>
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var error = "It was recorded with an " + type;
|
||||
error += string.IsNullOrEmpty(name) ? "." : ":\n{0}".F(name);
|
||||
|
||||
ConfirmationDialogs.CancelPrompt("Incompatible Replay", error, onCancel);
|
||||
ConfirmationDialogs.ButtonPrompt("Incompatible Replay", error, onCancel: onCancel);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -128,14 +128,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
catch (System.Net.Sockets.SocketException e)
|
||||
{
|
||||
var err_msg = "Could not listen on port {0}.".F(Game.Settings.Server.ListenPort);
|
||||
var message = "Could not listen on port {0}.".F(Game.Settings.Server.ListenPort);
|
||||
if (e.ErrorCode == 10048) { // AddressAlreadyInUse (WSAEADDRINUSE)
|
||||
err_msg += "\n\nCheck if the port is already being used.";
|
||||
message += "\nCheck if the port is already being used.";
|
||||
} else {
|
||||
err_msg += "\n\nError is: \"{0}\" ({1})".F(e.Message, e.ErrorCode);
|
||||
message += "\nError is: \"{0}\" ({1})".F(e.Message, e.ErrorCode);
|
||||
}
|
||||
|
||||
ConfirmationDialogs.CancelPrompt("Server Creation Failed", err_msg, cancelText: "OK");
|
||||
ConfirmationDialogs.ButtonPrompt("Server Creation Failed", message, onCancel: () => { }, cancelText: "Back");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
OriginalGraphicsRenderer != current.Graphics.Renderer ||
|
||||
OriginalGraphicsWindowedSize != current.Graphics.WindowedSize ||
|
||||
OriginalGraphicsFullscreenSize != current.Graphics.FullscreenSize)
|
||||
ConfirmationDialogs.PromptConfirmAction(
|
||||
ConfirmationDialogs.ButtonPrompt(
|
||||
title: "Restart Now?",
|
||||
text: "Some changes will not be applied until\nthe game is restarted. Restart now?",
|
||||
onConfirm: Game.Restart,
|
||||
|
||||
Reference in New Issue
Block a user