diff --git a/client/mainmenu/CPrologEpilogVideo.cpp b/client/mainmenu/CPrologEpilogVideo.cpp index a0d5a3458..3e026c762 100644 --- a/client/mainmenu/CPrologEpilogVideo.cpp +++ b/client/mainmenu/CPrologEpilogVideo.cpp @@ -18,6 +18,7 @@ #include "../widgets/VideoWidget.h" #include "../widgets/Images.h" #include "../render/Canvas.h" +#include "../lib/CConfigHandler.h" CPrologEpilogVideo::CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::function callback) : CWindowObject(BORDERED), spe(_spe), positionCounter(0), voiceSoundHandle(-1), videoSoundHandle(-1), exitCb(callback), elapsedTimeMilliseconds(0) @@ -56,6 +57,9 @@ CPrologEpilogVideo::CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::f }; ENGINE->sound().setCallback(voiceSoundHandle, onVoiceStop); + if(!settings["general"]["enableSubtitle"].Bool()) + return; + text = std::make_shared(Rect(100, 500, 600, 100), EFonts::FONT_BIG, ETextAlignment::CENTER, Colors::METALLIC_GOLD, spe.prologText.toString()); if(text->getLines().size() == 3) text->scrollTextTo(-25); // beginning of text in the vertical middle of black area @@ -67,9 +71,9 @@ void CPrologEpilogVideo::tick(uint32_t msPassed) { elapsedTimeMilliseconds += msPassed; - const uint32_t speed = (voiceDurationMilliseconds == 0) ? 150 : (voiceDurationMilliseconds / (text->textSize.y)); + const uint32_t speed = (!text || voiceDurationMilliseconds == 0) ? 150 : (voiceDurationMilliseconds / (text->textSize.y)); - if(elapsedTimeMilliseconds > speed && text->textSize.y - 50 > positionCounter) + if(text && elapsedTimeMilliseconds > speed && text->textSize.y - 50 > positionCounter) { text->scrollTextBy(1); elapsedTimeMilliseconds -= speed; @@ -84,7 +88,8 @@ void CPrologEpilogVideo::show(Canvas & to) to.drawColor(pos, Colors::BLACK); videoPlayer->show(to); - text->showAll(to); // blit text over video, if needed + if(text) + text->showAll(to); // blit text over video, if needed } void CPrologEpilogVideo::clickPressed(const Point & cursorPosition) diff --git a/client/widgets/VideoWidget.cpp b/client/widgets/VideoWidget.cpp index 6ff65b2d9..82cce32ac 100644 --- a/client/widgets/VideoWidget.cpp +++ b/client/widgets/VideoWidget.cpp @@ -18,6 +18,7 @@ #include "../render/Canvas.h" #include "../render/IScreenHandler.h" +#include "../../lib/CConfigHandler.h" #include "../../lib/filesystem/Filesystem.h" VideoWidgetBase::VideoWidgetBase(const Point & position, const VideoPath & video, bool playAudio) @@ -39,12 +40,15 @@ void VideoWidgetBase::playVideo(const VideoPath & fileToPlay) { OBJECT_CONSTRUCTION; - JsonPath subTitlePath = fileToPlay.toType(); - JsonPath subTitlePathVideoDir = subTitlePath.addPrefix("VIDEO/"); - if(CResourceHandler::get()->existsResource(subTitlePath)) - subTitleData = JsonNode(subTitlePath); - else if(CResourceHandler::get()->existsResource(subTitlePathVideoDir)) - subTitleData = JsonNode(subTitlePathVideoDir); + if(settings["general"]["enableSubtitle"].Bool()) + { + JsonPath subTitlePath = fileToPlay.toType(); + JsonPath subTitlePathVideoDir = subTitlePath.addPrefix("VIDEO/"); + if(CResourceHandler::get()->existsResource(subTitlePath)) + subTitleData = JsonNode(subTitlePath); + else if(CResourceHandler::get()->existsResource(subTitlePathVideoDir)) + subTitleData = JsonNode(subTitlePathVideoDir); + } float preScaleFactor = 1; VideoPath videoFile = fileToPlay; diff --git a/client/windows/settings/GeneralOptionsTab.cpp b/client/windows/settings/GeneralOptionsTab.cpp index dd1c89caa..c96e80aaa 100644 --- a/client/windows/settings/GeneralOptionsTab.cpp +++ b/client/windows/settings/GeneralOptionsTab.cpp @@ -185,6 +185,11 @@ GeneralOptionsTab::GeneralOptionsTab() setBoolSetting("general", "audioMuteFocus", value); }); + addCallback("enableSubtitleChanged", [](bool value) + { + setBoolSetting("general", "enableSubtitle", value); + }); + //moved from "other" tab that is disabled for now to avoid excessible tabs with barely any content addCallback("availableCreaturesAsDwellingChanged", [=](int value) { @@ -243,6 +248,10 @@ GeneralOptionsTab::GeneralOptionsTab() if (audioMuteFocusCheckbox) audioMuteFocusCheckbox->setSelected(settings["general"]["audioMuteFocus"].Bool()); + std::shared_ptr enableSubtitleCheckbox = widget("enableSubtitleCheckbox"); + if (enableSubtitleCheckbox) + enableSubtitleCheckbox->setSelected(settings["general"]["enableSubtitle"].Bool()); + std::shared_ptr musicSlider = widget("musicSlider"); musicSlider->scrollTo(ENGINE->music().getVolume()); diff --git a/config/schemas/settings.json b/config/schemas/settings.json index d30852d7c..a62d446a1 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -44,7 +44,8 @@ "enableUiEnhancements", "audioMuteFocus", "enableOverlay", - "lastKindomInterface" + "lastKindomInterface", + "enableSubtitle" ], "properties" : { "playerName" : { @@ -156,6 +157,10 @@ "lastKindomInterface" : { "type" : "number", "default" : 0 + }, + "enableSubtitle" : { + "type": "boolean", + "default": true } } }, diff --git a/config/widgets/settings/generalOptionsTab.json b/config/widgets/settings/generalOptionsTab.json index 269731c1f..26fc49c86 100644 --- a/config/widgets/settings/generalOptionsTab.json +++ b/config/widgets/settings/generalOptionsTab.json @@ -227,6 +227,9 @@ "items" : [ { "text": "vcmi.systemOptions.audioMuteFocus.hover" + }, + { + "text": "core.genrltxt.575" } ] }, @@ -239,6 +242,11 @@ "name": "audioMuteFocusCheckbox", "help": "vcmi.systemOptions.audioMuteFocus", "callback": "audioMuteFocusChanged" + }, + { + "name": "enableSubtitleCheckbox", + "help": "core.help.363", + "callback": "enableSubtitleChanged" } ] },