1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Merge pull request #2802 from Laserlicht/voice_camp

Voice for campaigns
This commit is contained in:
Nordsoft91
2023-09-11 18:15:23 +02:00
committed by GitHub
5 changed files with 22 additions and 9 deletions

View File

@@ -29,8 +29,12 @@ CPrologEpilogVideo::CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::f
CCS->videoh->open(spe.prologVideo);
CCS->musich->playMusic(spe.prologMusic, true, true);
// MPTODO: Custom campaign crashing on this?
// voiceSoundHandle = CCS->soundh->playSound(CCampaignHandler::prologVoiceName(spe.prologVideo));
voiceSoundHandle = CCS->soundh->playSound(spe.prologVoice);
auto onVoiceStop = [this]()
{
voiceStopped = true;
};
CCS->soundh->setCallback(voiceSoundHandle, onVoiceStop);
text = std::make_shared<CMultiLineLabel>(Rect(100, 500, 600, 100), EFonts::FONT_BIG, ETextAlignment::CENTER, Colors::METALLIC_GOLD, spe.prologText);
text->scrollTextTo(-100);
@@ -51,7 +55,7 @@ void CPrologEpilogVideo::show(Canvas & to)
else
text->showAll(to); // blit text over video, if needed
if(text->textSize.y + 100 < positionCounter / 5)
if(text->textSize.y + 100 < positionCounter / 5 && voiceStopped)
clickPressed(GH.getCursorPosition());
}

View File

@@ -23,6 +23,8 @@ class CPrologEpilogVideo : public CWindowObject
std::shared_ptr<CMultiLineLabel> text;
bool voiceStopped = false;
public:
CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::function<void()> callback);

View File

@@ -168,6 +168,7 @@ CampaignScenario CampaignHandler::readScenarioFromJson(JsonNode & reader)
{
ret.prologVideo = VideoPath::fromJson(identifier["video"]);
ret.prologMusic = AudioPath::fromJson(identifier["music"]);
ret.prologVoice = AudioPath::fromJson(identifier["voice"]);
ret.prologText = identifier["text"].String();
}
return ret;
@@ -403,8 +404,12 @@ CampaignScenario CampaignHandler::readScenarioFromMemory( CBinaryReader & reader
ret.hasPrologEpilog = reader.readUInt8();
if(ret.hasPrologEpilog)
{
ret.prologVideo = CampaignHandler::prologVideoName(reader.readUInt8());
bool isOriginalCampaign = boost::starts_with(header.getFilename(), "DATA/");
ui8 index = reader.readUInt8();
ret.prologVideo = CampaignHandler::prologVideoName(index);
ret.prologMusic = CampaignHandler::prologMusicName(reader.readUInt8());
ret.prologVoice = isOriginalCampaign ? CampaignHandler::prologVoiceName(index) : AudioPath();
ret.prologText = readLocalizedString(reader, header.filename, header.modName, header.encoding, identifier);
}
return ret;
@@ -605,13 +610,13 @@ AudioPath CampaignHandler::prologMusicName(ui8 index)
return AudioPath::builtinTODO(VLC->generaltexth->translate("core.cmpmusic." + std::to_string(static_cast<int>(index))));
}
std::string CampaignHandler::prologVoiceName(ui8 index)
AudioPath CampaignHandler::prologVoiceName(ui8 index)
{
JsonNode config(JsonPath::builtin("CONFIG/campaignMedia"));
auto audio = config["voice"].Vector();
if(index < audio.size())
return audio[index].String();
return "";
return AudioPath::fromJson(audio[index]);
return AudioPath();
}
VCMI_LIB_NAMESPACE_END

View File

@@ -35,7 +35,7 @@ class DLL_LINKAGE CampaignHandler
static VideoPath prologVideoName(ui8 index);
static AudioPath prologMusicName(ui8 index);
static std::string prologVoiceName(ui8 index);
static AudioPath prologVoiceName(ui8 index);
public:
static std::unique_ptr<Campaign> getHeader( const std::string & name); //name - name of appropriate file

View File

@@ -16,8 +16,9 @@ VCMI_LIB_NAMESPACE_BEGIN
struct DLL_LINKAGE CampaignScenarioPrologEpilog
{
bool hasPrologEpilog = false;
VideoPath prologVideo; // from CmpMovie.txt
VideoPath prologVideo;
AudioPath prologMusic; // from CmpMusic.txt
AudioPath prologVoice;
std::string prologText;
template <typename Handler> void serialize(Handler &h, const int formatVersion)
@@ -25,6 +26,7 @@ struct DLL_LINKAGE CampaignScenarioPrologEpilog
h & hasPrologEpilog;
h & prologVideo;
h & prologMusic;
h & prologVoice;
h & prologText;
}
};