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

new approach

This commit is contained in:
Laserlicht
2023-10-08 21:19:04 +02:00
committed by GitHub
parent 42bf5fdd58
commit 7ef9e91741
3 changed files with 93 additions and 45 deletions

View File

@@ -23,7 +23,6 @@ public:
virtual bool nextFrame()=0; virtual bool nextFrame()=0;
virtual void show(int x, int y, SDL_Surface *dst, bool update = true)=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 void redraw(int x, int y, SDL_Surface *dst, bool update = true)=0; //reblits buffer
virtual VideoPath videoName()=0;
virtual bool wait()=0; virtual bool wait()=0;
virtual int curFrame() const =0; virtual int curFrame() const =0;
virtual int frameCount() 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 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 {}; void show( int x, int y, SDL_Surface *dst, bool update = true ) override {};
bool nextFrame() override {return false;}; bool nextFrame() override {return false;};
VideoPath videoName() override {return VideoPath();};
void close() override {}; void close() override {};
bool wait() override {return false;}; bool wait() override {return false;};
bool open(const VideoPath & name, bool scale = false) 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) // 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; bool openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey = false, bool scale = false) override;
VideoPath videoName() override {return fname;};
//TODO: //TODO:
bool wait() override {return false;}; bool wait() override {return false;};
int curFrame() const override {return -1;}; int curFrame() const override {return -1;};

View File

@@ -459,7 +459,7 @@ HeroInfoWindow::HeroInfoWindow(const InfoAboutHero & hero, Point * position)
} }
BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface & _owner, bool allowReplay) BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface & _owner, bool allowReplay)
: owner(_owner) : owner(_owner), currentVideo(BattleResultVideo::NONE)
{ {
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); 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 if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won
{ {
int text = 304; int text = 304;
AudioPath musicName = AudioPath::builtin("Music/Win Battle"); currentVideo = BattleResultVideo::WIN;
VideoPath videoName = VideoPath::builtin("WIN3.BIK");
switch(br.result) switch(br.result)
{ {
case EBattleResult::NORMAL: case EBattleResult::NORMAL:
if(owner.cb->getBattle(br.battleID)->battleGetDefendedTown() && !weAreAttacker) if(owner.cb->getBattle(br.battleID)->battleGetDefendedTown() && !weAreAttacker)
{ currentVideo = BattleResultVideo::WIN_SIEGE;
musicName = AudioPath::builtin("Music/Defend Castle");
videoName = VideoPath::builtin("DEFENDALL.BIK");
}
break; break;
case EBattleResult::ESCAPE: case EBattleResult::ESCAPE:
text = 303; text = 303;
@@ -587,9 +583,8 @@ BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface
logGlobal->error("Invalid battle result code %d. Assumed normal.", static_cast<int>(br.result)); logGlobal->error("Invalid battle result code %d. Assumed normal.", static_cast<int>(br.result));
break; break;
} }
playVideo();
CCS->musich->playMusic(musicName, false, true);
CCS->videoh->open(videoName);
std::string str = CGI->generaltexth->allTexts[text]; std::string str = CGI->generaltexth->allTexts[text];
const CGHeroInstance * ourHero = owner.cb->getBattle(br.battleID)->battleGetMyHero(); const CGHeroInstance * ourHero = owner.cb->getBattle(br.battleID)->battleGetMyHero();
@@ -605,33 +600,26 @@ BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface
else // we lose else // we lose
{ {
int text = 311; int text = 311;
AudioPath musicName = AudioPath::builtin("Music/LoseCombat"); currentVideo = BattleResultVideo::DEFEAT;
VideoPath videoName = VideoPath::builtin("LBSTART.BIK");
switch(br.result) switch(br.result)
{ {
case EBattleResult::NORMAL: case EBattleResult::NORMAL:
if(owner.cb->getBattle(br.battleID)->battleGetDefendedTown() && !weAreAttacker) if(owner.cb->getBattle(br.battleID)->battleGetDefendedTown() && !weAreAttacker)
{ currentVideo = BattleResultVideo::DEFEAT_SIEGE;
musicName = AudioPath::builtin("Music/LoseCastle");
videoName = VideoPath::builtin("LOSECSTL.BIK");
}
break; break;
case EBattleResult::ESCAPE: case EBattleResult::ESCAPE:
musicName = AudioPath::builtin("Music/Retreat Battle"); currentVideo = BattleResultVideo::RETREAT;
videoName = VideoPath::builtin("RTSTART.BIK");
text = 310; text = 310;
break; break;
case EBattleResult::SURRENDER: case EBattleResult::SURRENDER:
musicName = AudioPath::builtin("Music/Surrender Battle"); currentVideo = BattleResultVideo::SURRENDER;
videoName = VideoPath::builtin("SURRENDER.BIK");
text = 309; text = 309;
break; break;
default: default:
logGlobal->error("Invalid battle result code %d. Assumed normal.", static_cast<int>(br.result)); logGlobal->error("Invalid battle result code %d. Assumed normal.", static_cast<int>(br.result));
break; break;
} }
CCS->musich->playMusic(musicName, false, true); playVideo();
CCS->videoh->open(videoName);
labels.push_back(std::make_shared<CLabel>(235, 235, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[text])); labels.push_back(std::make_shared<CLabel>(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, CCS->videoh->update(pos.x + 107, pos.y + 70, to.getInternalSurface(), true, false,
[&]() [&]()
{ {
if(CCS->videoh->videoName() == VideoPath::builtin("VIDEO/LBSTART")) playVideo(true);
{
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::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) void BattleResultWindow::buttonPressed(int button)
{ {
if (resultCallback) if (resultCallback)

View File

@@ -163,6 +163,24 @@ private:
std::vector<std::shared_ptr<CAnimImage>> icons; std::vector<std::shared_ptr<CAnimImage>> icons;
std::shared_ptr<CTextBox> description; std::shared_ptr<CTextBox> description;
CPlayerInterface & owner; 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 void buttonPressed(int button); //internal function for button callbacks
public: public: