diff --git a/client/CVideoHandler.h b/client/CVideoHandler.h index cda410c44..d447d64e6 100644 --- a/client/CVideoHandler.h +++ b/client/CVideoHandler.h @@ -23,7 +23,6 @@ public: virtual bool nextFrame()=0; virtual void show(int x, int y, SDL_Surface *dst, bool update = true)=0; virtual void redraw(int x, int y, SDL_Surface *dst, bool update = true)=0; //reblits buffer - virtual VideoPath videoName()=0; virtual bool wait()=0; virtual int curFrame() const =0; virtual int frameCount() const =0; @@ -47,7 +46,6 @@ public: void redraw( int x, int y, SDL_Surface *dst, bool update = true ) override {}; void show( int x, int y, SDL_Surface *dst, bool update = true ) override {}; bool nextFrame() override {return false;}; - VideoPath videoName() override {return VideoPath();}; void close() override {}; bool wait() override {return false;}; bool open(const VideoPath & name, bool scale = false) override {return false;}; @@ -108,8 +106,6 @@ public: // Opens video, calls playVideo, closes video; returns playVideo result (if whole video has been played) bool openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey = false, bool scale = false) override; - VideoPath videoName() override {return fname;}; - //TODO: bool wait() override {return false;}; int curFrame() const override {return -1;}; diff --git a/client/battle/BattleInterfaceClasses.cpp b/client/battle/BattleInterfaceClasses.cpp index d41dce25e..feac0006b 100644 --- a/client/battle/BattleInterfaceClasses.cpp +++ b/client/battle/BattleInterfaceClasses.cpp @@ -459,7 +459,7 @@ HeroInfoWindow::HeroInfoWindow(const InfoAboutHero & hero, Point * position) } BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface & _owner, bool allowReplay) - : owner(_owner) + : owner(_owner), currentVideo(BattleResultVideo::NONE) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); @@ -566,16 +566,12 @@ BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won { int text = 304; - AudioPath musicName = AudioPath::builtin("Music/Win Battle"); - VideoPath videoName = VideoPath::builtin("WIN3.BIK"); + currentVideo = BattleResultVideo::WIN; switch(br.result) { case EBattleResult::NORMAL: if(owner.cb->getBattle(br.battleID)->battleGetDefendedTown() && !weAreAttacker) - { - musicName = AudioPath::builtin("Music/Defend Castle"); - videoName = VideoPath::builtin("DEFENDALL.BIK"); - } + currentVideo = BattleResultVideo::WIN_SIEGE; break; case EBattleResult::ESCAPE: text = 303; @@ -587,9 +583,8 @@ BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface logGlobal->error("Invalid battle result code %d. Assumed normal.", static_cast(br.result)); break; } + playVideo(); - CCS->musich->playMusic(musicName, false, true); - CCS->videoh->open(videoName); std::string str = CGI->generaltexth->allTexts[text]; const CGHeroInstance * ourHero = owner.cb->getBattle(br.battleID)->battleGetMyHero(); @@ -605,33 +600,26 @@ BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface else // we lose { int text = 311; - AudioPath musicName = AudioPath::builtin("Music/LoseCombat"); - VideoPath videoName = VideoPath::builtin("LBSTART.BIK"); + currentVideo = BattleResultVideo::DEFEAT; switch(br.result) { case EBattleResult::NORMAL: if(owner.cb->getBattle(br.battleID)->battleGetDefendedTown() && !weAreAttacker) - { - musicName = AudioPath::builtin("Music/LoseCastle"); - videoName = VideoPath::builtin("LOSECSTL.BIK"); - } + currentVideo = BattleResultVideo::DEFEAT_SIEGE; break; case EBattleResult::ESCAPE: - musicName = AudioPath::builtin("Music/Retreat Battle"); - videoName = VideoPath::builtin("RTSTART.BIK"); + currentVideo = BattleResultVideo::RETREAT; text = 310; break; case EBattleResult::SURRENDER: - musicName = AudioPath::builtin("Music/Surrender Battle"); - videoName = VideoPath::builtin("SURRENDER.BIK"); + currentVideo = BattleResultVideo::SURRENDER; text = 309; break; default: logGlobal->error("Invalid battle result code %d. Assumed normal.", static_cast(br.result)); break; } - CCS->musich->playMusic(musicName, false, true); - CCS->videoh->open(videoName); + playVideo(); labels.push_back(std::make_shared(235, 235, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[text])); } @@ -649,29 +637,75 @@ void BattleResultWindow::show(Canvas & to) CCS->videoh->update(pos.x + 107, pos.y + 70, to.getInternalSurface(), true, false, [&]() { - if(CCS->videoh->videoName() == VideoPath::builtin("VIDEO/LBSTART")) - { - CCS->videoh->close(); - CCS->videoh->open(VideoPath::builtin("VIDEO/LBLOOP")); - } - if(CCS->videoh->videoName() == VideoPath::builtin("VIDEO/RTSTART")) - { - CCS->videoh->close(); - CCS->videoh->open(VideoPath::builtin("VIDEO/RTLOOP")); - } - if(CCS->videoh->videoName() == VideoPath::builtin("VIDEO/LOSECSTL")) - { - CCS->videoh->close(); - CCS->videoh->open(VideoPath::builtin("VIDEO/LOSECSLP")); - } - if(CCS->videoh->videoName() == VideoPath::builtin("VIDEO/DEFENDALL")) - { - CCS->videoh->close(); - CCS->videoh->open(VideoPath::builtin("VIDEO/DEFENDLOOP")); - } + playVideo(true); }); } +void BattleResultWindow::playVideo(bool startLoop) +{ + AudioPath musicName = AudioPath(); + VideoPath videoName = VideoPath(); + + if(!startLoop) + { + switch(currentVideo) + { + case BattleResultVideo::WIN: + musicName = AudioPath::builtin("Music/Win Battle"); + videoName = VideoPath::builtin("WIN3.BIK"); + break; + case BattleResultVideo::SURRENDER: + musicName = AudioPath::builtin("Music/Surrender Battle"); + videoName = VideoPath::builtin("SURRENDER.BIK"); + break; + case BattleResultVideo::RETREAT: + musicName = AudioPath::builtin("Music/Retreat Battle"); + videoName = VideoPath::builtin("RTSTART.BIK"); + break; + case BattleResultVideo::DEFEAT: + musicName = AudioPath::builtin("Music/LoseCombat"); + videoName = VideoPath::builtin("LBSTART.BIK"); + break; + case BattleResultVideo::DEFEAT_SIEGE: + musicName = AudioPath::builtin("Music/LoseCastle"); + videoName = VideoPath::builtin("LOSECSTL.BIK"); + break; + case BattleResultVideo::WIN_SIEGE: + musicName = AudioPath::builtin("Music/Defend Castle"); + videoName = VideoPath::builtin("DEFENDALL.BIK"); + break; + } + } + else + { + switch(currentVideo) + { + case BattleResultVideo::RETREAT: + currentVideo = BattleResultVideo::RETREAT_LOOP; + videoName = VideoPath::builtin("RTLOOP.BIK"); + break; + case BattleResultVideo::DEFEAT: + currentVideo = BattleResultVideo::DEFEAT_LOOP; + videoName = VideoPath::builtin("LBLOOP.BIK"); + break; + case BattleResultVideo::DEFEAT_SIEGE: + currentVideo = BattleResultVideo::DEFEAT_SIEGE_LOOP; + videoName = VideoPath::builtin("LOSECSLP.BIK"); + break; + case BattleResultVideo::WIN_SIEGE: + currentVideo = BattleResultVideo::WIN_SIEGE_LOOP; + videoName = VideoPath::builtin("DEFENDLOOP.BIK"); + break; + } + } + + if(musicName != AudioPath()) + CCS->musich->playMusic(musicName, false, true); + + if(videoName != VideoPath()) + CCS->videoh->open(videoName); +} + void BattleResultWindow::buttonPressed(int button) { if (resultCallback) diff --git a/client/battle/BattleInterfaceClasses.h b/client/battle/BattleInterfaceClasses.h index c77f84782..2b395ed23 100644 --- a/client/battle/BattleInterfaceClasses.h +++ b/client/battle/BattleInterfaceClasses.h @@ -163,6 +163,24 @@ private: std::vector> icons; std::shared_ptr description; CPlayerInterface & owner; + + enum BattleResultVideo + { + NONE, + WIN, + SURRENDER, + RETREAT, + RETREAT_LOOP, + DEFEAT, + DEFEAT_LOOP, + DEFEAT_SIEGE, + DEFEAT_SIEGE_LOOP, + WIN_SIEGE, + WIN_SIEGE_LOOP, + }; + BattleResultVideo currentVideo; + + void playVideo(bool startLoop = false); void buttonPressed(int button); //internal function for button callbacks public: