mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Use ResourcePath for video accessing
This commit is contained in:
parent
6f0108e462
commit
97b7d44c88
@ -423,10 +423,10 @@ int main(int argc, char * argv[])
|
||||
//plays intro, ends when intro is over or button has been pressed (handles events)
|
||||
void playIntro()
|
||||
{
|
||||
if(CCS->videoh->openAndPlayVideo("3DOLOGO.SMK", 0, 1, true, true))
|
||||
if(CCS->videoh->openAndPlayVideo(VideoPath::builtin("3DOLOGO.SMK"), 0, 1, true, true))
|
||||
{
|
||||
if (CCS->videoh->openAndPlayVideo("NWCLOGO.SMK", 0, 1, true, true))
|
||||
CCS->videoh->openAndPlayVideo("H3INTRO.SMK", 0, 1, true, true);
|
||||
if (CCS->videoh->openAndPlayVideo(VideoPath::builtin("NWCLOGO.SMK"), 0, 1, true, true))
|
||||
CCS->videoh->openAndPlayVideo(VideoPath::builtin("H3INTRO.SMK"), 0, 1, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,30 +70,28 @@ CVideoPlayer::CVideoPlayer()
|
||||
, doLoop(false)
|
||||
{}
|
||||
|
||||
bool CVideoPlayer::open(std::string fname, bool scale)
|
||||
bool CVideoPlayer::open(const VideoPath & fname, bool scale)
|
||||
{
|
||||
return open(fname, true, false);
|
||||
}
|
||||
|
||||
// loop = to loop through the video
|
||||
// useOverlay = directly write to the screen.
|
||||
bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay, bool scale)
|
||||
bool CVideoPlayer::open(const VideoPath & fname, bool loop, bool useOverlay, bool scale)
|
||||
{
|
||||
close();
|
||||
|
||||
this->fname = fname;
|
||||
this->fname = fname.addPrefix("VIDEO/");
|
||||
doLoop = loop;
|
||||
frameTime = 0;
|
||||
|
||||
ResourcePath resource(std::string("Video/") + fname, EResType::VIDEO);
|
||||
|
||||
if (!CResourceHandler::get()->existsResource(resource))
|
||||
if (!CResourceHandler::get()->existsResource(fname))
|
||||
{
|
||||
logGlobal->error("Error: video %s was not found", resource.getName());
|
||||
logGlobal->error("Error: video %s was not found", fname.getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
data = CResourceHandler::get()->load(resource);
|
||||
data = CResourceHandler::get()->load(fname);
|
||||
|
||||
static const int BUFFER_SIZE = 4096;
|
||||
|
||||
@ -382,7 +380,8 @@ void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool forceRedraw, boo
|
||||
|
||||
void CVideoPlayer::close()
|
||||
{
|
||||
fname.clear();
|
||||
fname = VideoPath();
|
||||
|
||||
if (sws)
|
||||
{
|
||||
sws_freeContext(sws);
|
||||
@ -467,7 +466,7 @@ bool CVideoPlayer::playVideo(int x, int y, bool stopOnKey)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVideoPlayer::openAndPlayVideo(std::string name, int x, int y, bool stopOnKey, bool scale)
|
||||
bool CVideoPlayer::openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey, bool scale)
|
||||
{
|
||||
open(name, false, true, scale);
|
||||
bool ret = playVideo(x, y, stopOnKey);
|
||||
|
@ -10,6 +10,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../lib/Rect.h"
|
||||
#include "../lib/filesystem/ResourcePath.h"
|
||||
|
||||
struct SDL_Surface;
|
||||
struct SDL_Texture;
|
||||
@ -17,7 +18,7 @@ struct SDL_Texture;
|
||||
class IVideoPlayer
|
||||
{
|
||||
public:
|
||||
virtual bool open(std::string name, bool scale = false)=0; //true - succes
|
||||
virtual bool open(const VideoPath & name, bool scale = false)=0; //true - succes
|
||||
virtual void close()=0;
|
||||
virtual bool nextFrame()=0;
|
||||
virtual void show(int x, int y, SDL_Surface *dst, bool update = true)=0;
|
||||
@ -30,10 +31,10 @@ public:
|
||||
class IMainVideoPlayer : public IVideoPlayer
|
||||
{
|
||||
public:
|
||||
std::string fname; //name of current video file (empty if idle)
|
||||
VideoPath fname; //name of current video file (empty if idle)
|
||||
|
||||
virtual void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true){}
|
||||
virtual bool openAndPlayVideo(std::string name, int x, int y, bool stopOnKey = false, bool scale = false)
|
||||
virtual bool openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey = false, bool scale = false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -49,7 +50,7 @@ public:
|
||||
bool nextFrame() override {return false;};
|
||||
void close() override {};
|
||||
bool wait() override {return false;};
|
||||
bool open(std::string name, bool scale = false) override {return false;};
|
||||
bool open(const VideoPath & name, bool scale = false) override {return false;};
|
||||
};
|
||||
|
||||
#ifndef DISABLE_VIDEO
|
||||
@ -85,14 +86,14 @@ class CVideoPlayer : public IMainVideoPlayer
|
||||
bool doLoop; // loop through video
|
||||
|
||||
bool playVideo(int x, int y, bool stopOnKey);
|
||||
bool open(std::string fname, bool loop, bool useOverlay = false, bool scale = false);
|
||||
bool open(const VideoPath & fname, bool loop, bool useOverlay = false, bool scale = false);
|
||||
|
||||
public:
|
||||
CVideoPlayer();
|
||||
~CVideoPlayer();
|
||||
|
||||
bool init();
|
||||
bool open(std::string fname, bool scale = false) override;
|
||||
bool open(const VideoPath & fname, bool scale = false) override;
|
||||
void close() override;
|
||||
bool nextFrame() override; // display next frame
|
||||
|
||||
@ -101,7 +102,7 @@ public:
|
||||
void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true) override; //moves to next frame if appropriate, and blits it or blits only if redraw parameter is set true
|
||||
|
||||
// Opens video, calls playVideo, closes video; returns playVideo result (if whole video has been played)
|
||||
bool openAndPlayVideo(std::string 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;
|
||||
|
||||
//TODO:
|
||||
bool wait() override {return false;};
|
||||
|
@ -581,7 +581,7 @@ BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface
|
||||
}
|
||||
|
||||
CCS->musich->playMusic("Music/Win Battle", false, true);
|
||||
CCS->videoh->open("WIN3.BIK");
|
||||
CCS->videoh->open(VideoPath::builtin("WIN3.BIK"));
|
||||
std::string str = CGI->generaltexth->allTexts[text];
|
||||
|
||||
const CGHeroInstance * ourHero = owner.cb->battleGetMyHero();
|
||||
@ -598,19 +598,19 @@ BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface
|
||||
{
|
||||
int text = 311;
|
||||
std::string musicName = "Music/LoseCombat";
|
||||
std::string videoName = "LBSTART.BIK";
|
||||
VideoPath videoName = VideoPath::builtin("LBSTART.BIK");
|
||||
switch(br.result)
|
||||
{
|
||||
case EBattleResult::NORMAL:
|
||||
break;
|
||||
case EBattleResult::ESCAPE:
|
||||
musicName = "Music/Retreat Battle";
|
||||
videoName = "RTSTART.BIK";
|
||||
videoName = VideoPath::builtin("RTSTART.BIK");
|
||||
text = 310;
|
||||
break;
|
||||
case EBattleResult::SURRENDER:
|
||||
musicName = "Music/Surrender Battle";
|
||||
videoName = "SURRENDER.BIK";
|
||||
videoName = VideoPath::builtin("SURRENDER.BIK");
|
||||
text = 309;
|
||||
break;
|
||||
default:
|
||||
|
@ -99,7 +99,7 @@ CCampaignScreen::CCampaignButton::CCampaignButton(const JsonNode & config)
|
||||
pos.h = 116;
|
||||
|
||||
campFile = config["file"].String();
|
||||
video = config["video"].String();
|
||||
video = VideoPath::fromJson(config["video"]);
|
||||
|
||||
status = config["open"].Bool() ? CCampaignScreen::ENABLED : CCampaignScreen::DISABLED;
|
||||
|
||||
|
@ -37,7 +37,7 @@ private:
|
||||
CampaignStatus status;
|
||||
|
||||
std::string campFile; // the filename/resourcename of the campaign
|
||||
std::string video; // the resource name of the video
|
||||
VideoPath video; // the resource name of the video
|
||||
std::string hoverText;
|
||||
|
||||
void clickReleased(const Point & cursorPosition) override;
|
||||
|
@ -116,7 +116,7 @@ void CMenuScreen::activate()
|
||||
{
|
||||
CCS->musich->playMusic("Music/MainMenu", true, true);
|
||||
if(!config["video"].isNull())
|
||||
CCS->videoh->open(config["video"]["name"].String());
|
||||
CCS->videoh->open(VideoPath::fromJson(config["video"]["name"]));
|
||||
CIntObject::activate();
|
||||
}
|
||||
|
||||
|
@ -397,13 +397,13 @@ void CSpellWindow::setCurrentPage(int value)
|
||||
void CSpellWindow::turnPageLeft()
|
||||
{
|
||||
if(settings["video"]["spellbookAnimation"].Bool())
|
||||
CCS->videoh->openAndPlayVideo("PGTRNLFT.SMK", pos.x+13, pos.y+15);
|
||||
CCS->videoh->openAndPlayVideo(VideoPath::builtin("PGTRNLFT.SMK"), pos.x+13, pos.y+15);
|
||||
}
|
||||
|
||||
void CSpellWindow::turnPageRight()
|
||||
{
|
||||
if(settings["video"]["spellbookAnimation"].Bool())
|
||||
CCS->videoh->openAndPlayVideo("PGTRNRGH.SMK", pos.x+13, pos.y+15);
|
||||
CCS->videoh->openAndPlayVideo(VideoPath::builtin("PGTRNRGH.SMK"), pos.x+13, pos.y+15);
|
||||
}
|
||||
|
||||
void CSpellWindow::keyPressed(EShortcut key)
|
||||
|
@ -513,7 +513,7 @@ CTavernWindow::CTavernWindow(const CGObjectInstance * TavernObj)
|
||||
if(LOCPLINT->castleInt)
|
||||
CCS->videoh->open(LOCPLINT->castleInt->town->town->clientInfo.tavernVideo);
|
||||
else
|
||||
CCS->videoh->open("TAVERN.BIK");
|
||||
CCS->videoh->open(VideoPath::builtin("TAVERN.BIK"));
|
||||
}
|
||||
|
||||
void CTavernWindow::recruitb()
|
||||
|
@ -884,7 +884,7 @@ void CTownHandler::loadClientData(CTown &town, const JsonNode & source) const
|
||||
info.buildingsIcons = AnimationPath::fromJson(source["buildingsIcons"]);
|
||||
|
||||
info.guildBackground = ImagePath::fromJson(source["guildBackground"]);
|
||||
info.tavernVideo = source["tavernVideo"].String();
|
||||
info.tavernVideo = VideoPath::fromJson(source["tavernVideo"]);
|
||||
|
||||
loadTownHall(town, source["hallSlots"]);
|
||||
loadStructures(town, source["structures"]);
|
||||
|
@ -304,7 +304,7 @@ public:
|
||||
int icons[2][2];
|
||||
std::string iconSmall[2][2]; /// icon names used during loading
|
||||
std::string iconLarge[2][2];
|
||||
std::string tavernVideo;
|
||||
VideoPath tavernVideo;
|
||||
std::string musicTheme;
|
||||
ImagePath townBackground;
|
||||
ImagePath guildBackground;
|
||||
|
@ -166,7 +166,7 @@ CampaignScenario CampaignHandler::readScenarioFromJson(JsonNode & reader)
|
||||
ret.hasPrologEpilog = !identifier.isNull();
|
||||
if(ret.hasPrologEpilog)
|
||||
{
|
||||
ret.prologVideo = identifier["video"].String();
|
||||
ret.prologVideo = VideoPath::fromJson(identifier["video"]);
|
||||
ret.prologMusic = identifier["music"].String();
|
||||
ret.prologText = identifier["text"].String();
|
||||
}
|
||||
@ -590,13 +590,13 @@ std::vector< std::vector<ui8> > CampaignHandler::getFile(std::unique_ptr<CInputS
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string CampaignHandler::prologVideoName(ui8 index)
|
||||
VideoPath CampaignHandler::prologVideoName(ui8 index)
|
||||
{
|
||||
JsonNode config(JsonPath::builtin("CONFIG/campaignMedia"));
|
||||
auto vids = config["videos"].Vector();
|
||||
if(index < vids.size())
|
||||
return vids[index].String();
|
||||
return "";
|
||||
return VideoPath::fromJson(vids[index]);
|
||||
return VideoPath();
|
||||
}
|
||||
|
||||
std::string CampaignHandler::prologMusicName(ui8 index)
|
||||
|
@ -10,6 +10,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "CampaignState.h" // Convenience include - not required for build, but required for any user of CampaignHandler
|
||||
#include "../filesystem/ResourcePath.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
@ -32,7 +33,7 @@ class DLL_LINKAGE CampaignHandler
|
||||
/// headerOnly - only header will be decompressed, returned vector wont have any maps
|
||||
static std::vector<std::vector<ui8>> getFile(std::unique_ptr<CInputStream> file, bool headerOnly);
|
||||
|
||||
static std::string prologVideoName(ui8 index);
|
||||
static VideoPath prologVideoName(ui8 index);
|
||||
static std::string prologMusicName(ui8 index);
|
||||
static std::string prologVoiceName(ui8 index);
|
||||
|
||||
|
@ -9,12 +9,14 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "../filesystem/ResourcePath.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
struct DLL_LINKAGE CampaignScenarioPrologEpilog
|
||||
{
|
||||
bool hasPrologEpilog = false;
|
||||
std::string prologVideo; // from CmpMovie.txt
|
||||
VideoPath prologVideo; // from CmpMovie.txt
|
||||
std::string prologMusic; // from CmpMusic.txt
|
||||
std::string prologText;
|
||||
|
||||
|
@ -83,6 +83,11 @@ public:
|
||||
return name == other.name && type == other.type;
|
||||
}
|
||||
|
||||
inline bool operator!=(const ResourcePath & other) const
|
||||
{
|
||||
return name != other.name || type != other.type;
|
||||
}
|
||||
|
||||
inline bool operator<(const ResourcePath & other) const
|
||||
{
|
||||
if (type != other.type)
|
||||
@ -171,6 +176,7 @@ using AnimationPath = ResourcePathTempl<EResType::ANIMATION>;
|
||||
using ImagePath = ResourcePathTempl<EResType::IMAGE>;
|
||||
using TextPath = ResourcePathTempl<EResType::TEXT>;
|
||||
using JsonPath = ResourcePathTempl<EResType::JSON>;
|
||||
using VideoPath = ResourcePathTempl<EResType::VIDEO>;
|
||||
|
||||
namespace EResTypeHelper
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user