From 42bf5fdd5889679b13e5651c73db1b2f977cc419 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 7 Oct 2023 14:31:49 +0200 Subject: [PATCH] video fix --- client/CVideoHandler.h | 4 +++ client/battle/BattleInterfaceClasses.cpp | 41 ++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/client/CVideoHandler.h b/client/CVideoHandler.h index d447d64e6..cda410c44 100644 --- a/client/CVideoHandler.h +++ b/client/CVideoHandler.h @@ -23,6 +23,7 @@ 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; @@ -46,6 +47,7 @@ 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;}; @@ -106,6 +108,8 @@ 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 a9bc54bfe..d41dce25e 100644 --- a/client/battle/BattleInterfaceClasses.cpp +++ b/client/battle/BattleInterfaceClasses.cpp @@ -566,9 +566,16 @@ 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"); 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"); + } break; case EBattleResult::ESCAPE: text = 303; @@ -581,8 +588,8 @@ BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface break; } - CCS->musich->playMusic(AudioPath::builtin("Music/Win Battle"), false, true); - CCS->videoh->open(VideoPath::builtin("WIN3.BIK")); + 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(); @@ -603,6 +610,11 @@ BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface switch(br.result) { case EBattleResult::NORMAL: + if(owner.cb->getBattle(br.battleID)->battleGetDefendedTown() && !weAreAttacker) + { + musicName = AudioPath::builtin("Music/LoseCastle"); + videoName = VideoPath::builtin("LOSECSTL.BIK"); + } break; case EBattleResult::ESCAPE: musicName = AudioPath::builtin("Music/Retreat Battle"); @@ -634,7 +646,30 @@ void BattleResultWindow::activate() void BattleResultWindow::show(Canvas & to) { CIntObject::show(to); - CCS->videoh->update(pos.x + 107, pos.y + 70, to.getInternalSurface(), true, false); + 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")); + } + }); } void BattleResultWindow::buttonPressed(int button)