1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/client/mainmenu/CPrologEpilogVideo.cpp

69 lines
2.1 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 "../CMusicHandler.h"
#include "../CVideoHandler.h"
#include "../gui/CGuiHandler.h"
#include "../widgets/TextControls.h"
#include "../render/Canvas.h"
CPrologEpilogVideo::CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::function<void()> callback)
2023-10-08 20:27:56 +02:00
: CWindowObject(BORDERED), spe(_spe), positionCounter(0), voiceSoundHandle(-1), videoSoundHandle(-1), exitCb(callback)
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
addUsedEvents(LCLICK);
pos = center(Rect(0, 0, 800, 600));
updateShadow();
2023-10-07 23:07:10 +02:00
auto audioData = CCS->videoh->getAudio(spe.prologVideo);
2023-10-08 20:27:56 +02:00
videoSoundHandle = CCS->soundh->playSound(audioData);
CCS->videoh->open(spe.prologVideo);
2023-09-04 12:03:15 +02:00
CCS->musich->playMusic(spe.prologMusic, true, true);
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;
};
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());
text->scrollTextTo(-100);
}
void CPrologEpilogVideo::show(Canvas & to)
{
to.drawColor(pos, Colors::BLACK);
2024-01-01 16:25:42 +02:00
//some videos are 800x600 in size while some are 800x400
CCS->videoh->update(pos.x, pos.y + (CCS->videoh->size().y == 400 ? 100 : 0), to.getInternalSurface(), true, false);
//move text every 5 calls/frames; seems to be good enough
++positionCounter;
if(positionCounter % 5 == 0)
text->scrollTextBy(1);
else
text->showAll(to); // blit text over video, if needed
2023-09-11 14:44:07 +02:00
if(text->textSize.y + 100 < positionCounter / 5 && voiceStopped)
clickPressed(GH.getCursorPosition());
}
void CPrologEpilogVideo::clickPressed(const Point & cursorPosition)
{
close();
CCS->soundh->stopSound(voiceSoundHandle);
2023-10-08 20:27:56 +02:00
CCS->soundh->stopSound(videoSoundHandle);
exitCb();
}