|
@@ -9,6 +9,7 @@
|
|
|
*/
|
|
|
#include "StdInc.h"
|
|
|
#include "VideoWidget.h"
|
|
|
+#include "TextControls.h"
|
|
|
|
|
|
#include "../CGameInfo.h"
|
|
|
#include "../gui/CGuiHandler.h"
|
|
@@ -16,6 +17,8 @@
|
|
|
#include "../media/IVideoPlayer.h"
|
|
|
#include "../render/Canvas.h"
|
|
|
|
|
|
+#include "../../lib/filesystem/Filesystem.h"
|
|
|
+
|
|
|
VideoWidgetBase::VideoWidgetBase(const Point & position, const VideoPath & video, bool playAudio)
|
|
|
: VideoWidgetBase(position, video, playAudio, 1.0)
|
|
|
{
|
|
@@ -33,11 +36,22 @@ VideoWidgetBase::~VideoWidgetBase() = default;
|
|
|
|
|
|
void VideoWidgetBase::playVideo(const VideoPath & fileToPlay)
|
|
|
{
|
|
|
+ OBJECT_CONSTRUCTION;
|
|
|
+
|
|
|
+ JsonPath subTitlePath = fileToPlay.toType<EResType::JSON>();
|
|
|
+ JsonPath subTitlePathVideoDir = subTitlePath.addPrefix("VIDEO/");
|
|
|
+ if(CResourceHandler::get()->existsResource(subTitlePath))
|
|
|
+ subTitleData = JsonNode(subTitlePath);
|
|
|
+ else if(CResourceHandler::get()->existsResource(subTitlePathVideoDir))
|
|
|
+ subTitleData = JsonNode(subTitlePathVideoDir);
|
|
|
+
|
|
|
videoInstance = CCS->videoh->open(fileToPlay, scaleFactor);
|
|
|
if (videoInstance)
|
|
|
{
|
|
|
pos.w = videoInstance->size().x;
|
|
|
pos.h = videoInstance->size().y;
|
|
|
+ if(!subTitleData.isNull())
|
|
|
+ subTitle = std::make_unique<CMultiLineLabel>(Rect(0, (pos.h / 5) * 4, pos.w, pos.h / 5), EFonts::FONT_HIGH_SCORE, ETextAlignment::CENTER, Colors::WHITE);
|
|
|
}
|
|
|
|
|
|
if (playAudio)
|
|
@@ -52,6 +66,8 @@ void VideoWidgetBase::show(Canvas & to)
|
|
|
{
|
|
|
if(videoInstance)
|
|
|
videoInstance->show(pos.topLeft(), to);
|
|
|
+ if(subTitle)
|
|
|
+ subTitle->showAll(to);
|
|
|
}
|
|
|
|
|
|
void VideoWidgetBase::loadAudio(const VideoPath & fileToPlay)
|
|
@@ -77,7 +93,7 @@ void VideoWidgetBase::startAudio()
|
|
|
{
|
|
|
this->audioHandle = -1;
|
|
|
}
|
|
|
- );
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -91,22 +107,43 @@ void VideoWidgetBase::stopAudio()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+std::string VideoWidgetBase::getSubTitleLine(double timestamp)
|
|
|
+{
|
|
|
+ if(subTitleData.isNull())
|
|
|
+ return {};
|
|
|
+
|
|
|
+ for(auto & segment : subTitleData.Vector())
|
|
|
+ if(timestamp > segment["timeStart"].Float() && timestamp < segment["timeEnd"].Float())
|
|
|
+ return segment["text"].String();
|
|
|
+
|
|
|
+ return {};
|
|
|
+}
|
|
|
+
|
|
|
void VideoWidgetBase::activate()
|
|
|
{
|
|
|
CIntObject::activate();
|
|
|
- startAudio();
|
|
|
+ if(audioHandle != -1)
|
|
|
+ CCS->soundh->resumeSound(audioHandle);
|
|
|
+ else
|
|
|
+ startAudio();
|
|
|
+ if(videoInstance)
|
|
|
+ videoInstance->activate();
|
|
|
}
|
|
|
|
|
|
void VideoWidgetBase::deactivate()
|
|
|
{
|
|
|
CIntObject::deactivate();
|
|
|
- stopAudio();
|
|
|
+ CCS->soundh->pauseSound(audioHandle);
|
|
|
+ if(videoInstance)
|
|
|
+ videoInstance->deactivate();
|
|
|
}
|
|
|
|
|
|
void VideoWidgetBase::showAll(Canvas & to)
|
|
|
{
|
|
|
if(videoInstance)
|
|
|
videoInstance->show(pos.topLeft(), to);
|
|
|
+ if(subTitle)
|
|
|
+ subTitle->showAll(to);
|
|
|
}
|
|
|
|
|
|
void VideoWidgetBase::tick(uint32_t msPassed)
|
|
@@ -122,6 +159,8 @@ void VideoWidgetBase::tick(uint32_t msPassed)
|
|
|
onPlaybackFinished();
|
|
|
}
|
|
|
}
|
|
|
+ if(subTitle && videoInstance)
|
|
|
+ subTitle->setText(getSubTitleLine(videoInstance->timeStamp()));
|
|
|
}
|
|
|
|
|
|
VideoWidget::VideoWidget(const Point & position, const VideoPath & prologue, const VideoPath & looped, bool playAudio)
|