1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

skippable video intro

This commit is contained in:
Laserlicht 2024-09-12 23:23:00 +02:00
parent 8fc3fe3cc3
commit 2fbdeb3a5d
7 changed files with 46 additions and 32 deletions

View File

@ -711,7 +711,7 @@ void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared
if(!ourCampaign->getOutroVideo().empty() && CCS->videoh->open(ourCampaign->getOutroVideo(), 1))
{
CCS->musich->stopMusic();
GH.windows().createAndPushWindow<CampaignRimVideo>(ourCampaign->getOutroVideo(), ourCampaign->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : ourCampaign->getVideoRim(), false, 1, [campaignScoreCalculator, statistic](){
GH.windows().createAndPushWindow<CampaignRimVideo>(ourCampaign->getOutroVideo(), ourCampaign->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : ourCampaign->getVideoRim(), false, 1, [campaignScoreCalculator, statistic](bool skipped){
GH.windows().createAndPushWindow<CHighScoreInputScreen>(true, *campaignScoreCalculator, statistic);
});
}

View File

@ -210,7 +210,7 @@ void ApplyOnLobbyScreenNetPackVisitor::visitLobbyUpdateState(LobbyUpdateState &
if(!handler.si->campState->conqueredScenarios().size() && !handler.si->campState->getIntroVideo().empty() && CCS->videoh->open(handler.si->campState->getIntroVideo(), 1))
{
CCS->musich->stopMusic();
GH.windows().createAndPushWindow<CampaignRimVideo>(handler.si->campState->getIntroVideo(), handler.si->campState->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : handler.si->campState->getVideoRim(), false, 1, [bonusSel](){
GH.windows().createAndPushWindow<CampaignRimVideo>(handler.si->campState->getIntroVideo(), handler.si->campState->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : handler.si->campState->getVideoRim(), false, 1, [bonusSel](bool skipped){
if(!CSH->si->campState->getMusic().empty())
CCS->musich->playMusic(CSH->si->campState->getMusic(), true, false);
GH.windows().pushWindow(bonusSel);

View File

@ -59,8 +59,8 @@
#include "../../lib/mapObjects/CGHeroInstance.h"
CampaignRimVideo::CampaignRimVideo(VideoPath video, ImagePath rim, bool showBackground, float scaleFactor, std::function<void()> closeCb)
: CWindowObject(BORDERED), closeCb(closeCb)
CampaignRimVideo::CampaignRimVideo(VideoPath video, ImagePath rim, bool showBackground, float scaleFactor, std::function<void(bool skipped)> closeCb)
: CWindowObject(BORDERED | NEEDS_ANIMATED_BACKGROUND), closeCb(closeCb)
{
OBJECT_CONSTRUCTION;
@ -68,12 +68,12 @@ CampaignRimVideo::CampaignRimVideo(VideoPath video, ImagePath rim, bool showBack
if(!rim.empty())
{
videoPlayer = std::make_shared<VideoWidgetOnce>(Point(80, 186), video, true, [this](){ exit(); });
videoPlayer = std::make_shared<VideoWidgetOnce>(Point(80, 186), video, true, [this](){ exit(false); });
pos = center(Rect(0, 0, 800, 600));
}
else
{
videoPlayer = std::make_shared<VideoWidgetOnce>(Point(0, 0), video, true, scaleFactor, [this](){ exit(); });
videoPlayer = std::make_shared<VideoWidgetOnce>(Point(0, 0), video, true, scaleFactor, [this](){ exit(false); });
pos = center(Rect(0, 0, videoPlayer->pos.w, videoPlayer->pos.h));
}
@ -84,21 +84,21 @@ CampaignRimVideo::CampaignRimVideo(VideoPath video, ImagePath rim, bool showBack
setBackground(rim);
}
void CampaignRimVideo::exit()
void CampaignRimVideo::exit(bool skipped)
{
close();
if(closeCb)
closeCb();
closeCb(skipped);
}
void CampaignRimVideo::clickPressed(const Point & cursorPosition)
{
exit();
exit(true);
}
void CampaignRimVideo::keyPressed(EShortcut key)
{
exit();
exit(true);
}
bool CampaignRimVideo::receiveEvent(const Point & position, int eventType) const

View File

@ -39,11 +39,11 @@ class CampaignRimVideo : public CWindowObject
std::shared_ptr<VideoWidgetOnce> videoPlayer;
std::shared_ptr<CFilledTexture> backgroundAroundWindow;
std::function<void()> closeCb;
std::function<void(bool)> closeCb;
void exit();
void exit(bool skipped);
public:
CampaignRimVideo(VideoPath video, ImagePath rim, bool showBackground, float scaleFactor, std::function<void()> closeCb);
CampaignRimVideo(VideoPath video, ImagePath rim, bool showBackground, float scaleFactor, std::function<void(bool)> closeCb);
void clickPressed(const Point & cursorPosition) override;
void keyPressed(EShortcut key) override;

View File

@ -293,24 +293,7 @@ CMainMenu::CMainMenu(bool playVideoIntro)
OBJECT_CONSTRUCTION;
backgroundAroundMenu = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), pos);
if(playVideoIntro)
{
auto playVideo = [](std::string video, bool rim, float scaleFactor, std::function<void()> cb){
if(CCS->videoh->open(VideoPath::builtin(video), scaleFactor))
GH.windows().createAndPushWindow<CampaignRimVideo>(VideoPath::builtin(video), rim ? ImagePath::builtin("INTRORIM") : ImagePath::builtin(""), true, scaleFactor, [cb](){ cb(); });
else
cb();
};
playVideo("3DOLOGO.SMK", false, 1, [playVideo](){
playVideo("NWCLOGO.SMK", false, 2, [playVideo](){
playVideo("H3INTRO.SMK", true, 1, [](){
CCS->musich->playMusic(AudioPath::builtin("Music/MainMenu"), true, true);
});
});
});
}
else
CCS->musich->playMusic(AudioPath::builtin("Music/MainMenu"), true, true);
playIntroVideos(playVideoIntro);
}
CMainMenu::~CMainMenu()
@ -319,6 +302,35 @@ CMainMenu::~CMainMenu()
GH.curInt = nullptr;
}
void CMainMenu::playIntroVideos(bool playVideoIntro)
{
auto playMusic = [](){ CCS->musich->playMusic(AudioPath::builtin("Music/MainMenu"), true, true); };
if(playVideoIntro)
{
auto playVideo = [](std::string video, bool rim, float scaleFactor, std::function<void(bool)> cb){
if(CCS->videoh->open(VideoPath::builtin(video), scaleFactor))
GH.windows().createAndPushWindow<CampaignRimVideo>(VideoPath::builtin(video), rim ? ImagePath::builtin("INTRORIM") : ImagePath::builtin(""), true, scaleFactor, [cb](bool skipped){ cb(skipped); });
else
cb(true);
};
playVideo("3DOLOGO.SMK", false, 1, [playVideo, playMusic](bool skipped){
if(!skipped)
playVideo("NWCLOGO.SMK", false, 2, [playVideo, playMusic](bool skipped){
if(!skipped)
playVideo("H3INTRO.SMK", true, 1, [playMusic](bool skipped){
playMusic();
});
else
playMusic();
});
else
playMusic();
});
}
else
playMusic();
}
void CMainMenu::activate()
{
// check if screen was resized while main menu was inactive - e.g. in gameplay mode

View File

@ -146,6 +146,8 @@ class CMainMenu : public CIntObject, public IUpdateable, public std::enable_shar
CMainMenu(bool playVideoIntro); //Use CMainMenu::create
void playIntroVideos(bool playVideoIntro);
public:
std::shared_ptr<CMenuScreen> menu;

View File

@ -59,7 +59,7 @@ CWindowObject::CWindowObject(int options_, const ImagePath & imageName):
background(createBg(imageName, options_ & PLAYER_COLORED))
{
if(!(options & NEEDS_ANIMATED_BACKGROUND)) //currently workaround for highscores (currently uses window as normal control, because otherwise videos are not played in background yet)
//assert(parent == nullptr); //Safe to remove, but windows should not have parent
assert(parent == nullptr); //Safe to remove, but windows should not have parent
if(options & RCLICK_POPUP)
CCS->curh->hide();