1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-23 00:28:08 +02:00
Files
.github
AI
CI
Mods
android
client
adventureMap
battle
eventsSDL
globalLobby
gui
icons
ios
lobby
mainmenu
CCampaignScreen.cpp
CCampaignScreen.h
CHighScoreScreen.cpp
CHighScoreScreen.h
CMainMenu.cpp
CMainMenu.h
CPrologEpilogVideo.cpp
CPrologEpilogVideo.h
CreditsScreen.cpp
CreditsScreen.h
mapView
media
render
renderSDL
widgets
windows
ArtifactsUIController.cpp
ArtifactsUIController.h
CFocusableHelper.cpp
CFocusableHelper.h
CGameInfo.cpp
CGameInfo.h
CMT.cpp
CMT.h
CMakeLists.txt
CPlayerInterface.cpp
CPlayerInterface.h
CServerHandler.cpp
CServerHandler.h
Client.cpp
Client.h
ClientCommandManager.cpp
ClientCommandManager.h
ClientNetPackVisitors.h
ConditionalWait.h
GameChatHandler.cpp
GameChatHandler.h
HeroMovementController.cpp
HeroMovementController.h
LobbyClientNetPackVisitors.h
NetPacksClient.cpp
NetPacksLobbyClient.cpp
PlayerLocalState.cpp
PlayerLocalState.h
ServerRunner.cpp
ServerRunner.h
StdInc.cpp
StdInc.h
VCMI_client.rc
resource.h
vcmi.ico
cmake_modules
config
debian
docs
include
ios
launcher
lib
lobby
mapeditor
osx
rpm
scripting
scripts
server
serverapp
test
win
xcode
.gitattributes
.gitignore
.gitmodules
.travis.yml
AUTHORS.h
CCallback.cpp
CCallback.h
CMakeLists.txt
CMakePresets.json
ChangeLog.md
Global.h
Version.cpp.in
Version.h
conanfile.py
fuzzylite.pc.in
license.txt
vcmibuilder
vcmi/client/mainmenu/CPrologEpilogVideo.cpp

98 lines
3.6 KiB
C++
Raw Normal View History

/*
* CPrologEpilogVideo.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "CPrologEpilogVideo.h"
#include "../CGameInfo.h"
#include "../media/IMusicPlayer.h"
#include "../media/ISoundPlayer.h"
//#include "../gui/WindowHandler.h"
#include "../gui/CGuiHandler.h"
//#include "../gui/FramerateManager.h"
#include "../widgets/TextControls.h"
#include "../widgets/VideoWidget.h"
2024-05-18 19:58:51 +02:00
#include "../widgets/Images.h"
#include "../render/Canvas.h"
CPrologEpilogVideo::CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::function<void()> callback)
2024-01-25 21:11:42 +01:00
: CWindowObject(BORDERED), spe(_spe), positionCounter(0), voiceSoundHandle(-1), videoSoundHandle(-1), exitCb(callback), elapsedTimeMilliseconds(0)
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
2024-01-26 11:17:38 +01:00
addUsedEvents(LCLICK | TIME);
pos = center(Rect(0, 0, 800, 600));
2024-05-18 19:58:51 +02:00
backgroundAroundMenu = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(-pos.x, -pos.y, GH.screenDimensions().x, GH.screenDimensions().y));
//TODO: remove hardcoded paths. Some of campaigns video actually consist from 2 parts
// however, currently our campaigns format expects only a single video file
static const std::map<VideoPath, VideoPath> pairedVideoFiles = {
{ VideoPath::builtin("EVIL2AP1"), VideoPath::builtin("EVIL2AP2") },
{ VideoPath::builtin("H3ABdb4"), VideoPath::builtin("H3ABdb4b") },
{ VideoPath::builtin("H3x2_RNe1"), VideoPath::builtin("H3x2_RNe2") },
};
if (pairedVideoFiles.count(spe.prologVideo))
videoPlayer = std::make_shared<VideoWidget>(Point(0, 0), spe.prologVideo, pairedVideoFiles.at(spe.prologVideo), true);
else
videoPlayer = std::make_shared<VideoWidget>(Point(0, 0), spe.prologVideo, true);
//some videos are 800x600 in size while some are 800x400
if (videoPlayer->pos.h == 400)
videoPlayer->moveBy(Point(0, 100));
2023-09-04 13:03:15 +03:00
CCS->musich->playMusic(spe.prologMusic, true, true);
2024-01-26 21:58:39 +01:00
voiceDurationMilliseconds = CCS->soundh->getSoundDurationMilliseconds(spe.prologVoice);
2023-09-11 14:11:16 +02:00
voiceSoundHandle = CCS->soundh->playSound(spe.prologVoice);
2023-09-11 14:44:07 +02:00
auto onVoiceStop = [this]()
{
voiceStopped = true;
2024-01-25 20:49:59 +01:00
elapsedTimeMilliseconds = 0;
2023-09-11 14:44:07 +02:00
};
CCS->soundh->setCallback(voiceSoundHandle, onVoiceStop);
2023-09-28 00:10:28 +02:00
text = std::make_shared<CMultiLineLabel>(Rect(100, 500, 600, 100), EFonts::FONT_BIG, ETextAlignment::CENTER, Colors::METALLIC_GOLD, spe.prologText.toString());
2024-01-25 20:49:59 +01:00
text->scrollTextTo(-50); // beginning of text in the vertical middle of black area
}
2024-01-25 20:49:59 +01:00
void CPrologEpilogVideo::tick(uint32_t msPassed)
{
2024-01-25 20:49:59 +01:00
elapsedTimeMilliseconds += msPassed;
2024-01-26 21:58:39 +01:00
const uint32_t speed = (voiceDurationMilliseconds == 0) ? 150 : (voiceDurationMilliseconds / (text->textSize.y));
2024-01-24 01:17:23 +01:00
2024-01-25 20:49:59 +01:00
if(elapsedTimeMilliseconds > speed && text->textSize.y - 50 > positionCounter)
2024-01-24 01:17:23 +01:00
{
text->scrollTextBy(1);
2024-01-25 20:49:59 +01:00
elapsedTimeMilliseconds -= speed;
2024-01-24 01:17:23 +01:00
++positionCounter;
}
2024-01-26 21:58:39 +01:00
else if(elapsedTimeMilliseconds > (voiceDurationMilliseconds == 0 ? 8000 : 3000) && voiceStopped) // pause after completed scrolling (longer for intros missing voice)
2024-01-26 20:13:02 +01:00
clickPressed(GH.getCursorPosition());
}
void CPrologEpilogVideo::show(Canvas & to)
{
to.drawColor(pos, Colors::BLACK);
videoPlayer->show(to);
2024-01-26 20:13:02 +01:00
text->showAll(to); // blit text over video, if needed
}
void CPrologEpilogVideo::clickPressed(const Point & cursorPosition)
{
close();
CCS->soundh->resetCallback(voiceSoundHandle); // reset callback to avoid memory corruption since 'this' will be destroyed
CCS->soundh->stopSound(voiceSoundHandle);
2023-10-08 20:27:56 +02:00
CCS->soundh->stopSound(videoSoundHandle);
2024-01-23 23:45:31 +01:00
if(exitCb)
exitCb();
}