Allow a few replays coming with the game

This commit is contained in:
Benau 2016-04-22 09:49:46 +08:00
parent 790cd807a3
commit f6ce065cee
6 changed files with 2632 additions and 10 deletions

File diff suppressed because it is too large Load Diff

View File

@ -123,6 +123,7 @@ FileManager::FileManager()
m_subdir_name[LIBRARY ] = "library";
m_subdir_name[MODEL ] = "models";
m_subdir_name[MUSIC ] = "music";
m_subdir_name[REPLAY ] = "replay";
m_subdir_name[SCRIPT ] = "tracks";
m_subdir_name[SFX ] = "sfx";
m_subdir_name[SKIN ] = "skins";

View File

@ -48,7 +48,7 @@ public:
* The last entry ASSET_COUNT specifies the number of entries. */
enum AssetType {ASSET_MIN,
CHALLENGE=ASSET_MIN,
GFX, GRANDPRIX, GUI, LIBRARY, MODEL, MUSIC,
GFX, GRANDPRIX, GUI, LIBRARY, MODEL, MUSIC, REPLAY,
SCRIPT, SFX, SHADER, SKIN, TEXTURE, TTF,
TRANSLATION, ASSET_MAX = TRANSLATION,
ASSET_COUNT};
@ -138,7 +138,13 @@ public:
bool abort_on_error=false) const;
std::string getAsset(AssetType type, const std::string &name) const;
std::string getAsset(const std::string &name) const;
// ------------------------------------------------------------------------
/** Returns the directory of an asset. */
std::string getAssetDirectory(AssetType type) const
{
return m_subdir_name[type];
}
// ------------------------------------------------------------------------
std::string searchMusic(const std::string& file_name) const;
std::string searchTexture(const std::string& fname) const;
std::string getUserConfigFile(const std::string& fname) const;

View File

@ -40,7 +40,6 @@ ReplayPlay *ReplayPlay::m_replay_play = NULL;
ReplayPlay::ReplayPlay()
{
m_current_replay_file = 0;
m_custom_replay_file = false;
} // ReplayPlay
//-----------------------------------------------------------------------------
@ -64,6 +63,22 @@ void ReplayPlay::reset()
void ReplayPlay::loadAllReplayFile()
{
m_replay_file_list.clear();
// Load stock replay first
std::set<std::string> pre_record;
file_manager->listFiles(pre_record, file_manager
->getAssetDirectory(FileManager::REPLAY), /*is_full_path*/ true);
for (std::set<std::string>::iterator i = pre_record.begin();
i != pre_record.end(); ++i)
{
if (!addReplayFile(*i, /*custom_replay*/ true))
{
// Skip invalid replay file
continue;
}
}
// Now user recorded replay
std::set<std::string> files;
file_manager->listFiles(files, file_manager->getReplayDir(),
/*is_full_path*/ false);
@ -77,13 +92,12 @@ void ReplayPlay::loadAllReplayFile()
continue;
}
}
} // loadAllReplayFile
//-----------------------------------------------------------------------------
bool ReplayPlay::addReplayFile(const std::string& fn, bool custom_replay)
{
// custom_replay is true when full path of filename is given
m_custom_replay_file = custom_replay;
char s[1024], s1[1024];
if (StringUtils::getExtension(fn) != "replay") return false;
@ -92,6 +106,8 @@ bool ReplayPlay::addReplayFile(const std::string& fn, bool custom_replay)
if (fd == NULL) return false;
ReplayData rd;
// custom_replay is true when full path of filename is given
rd.m_custom_replay_file = custom_replay;
rd.m_filename = fn;
fgets(s, 1023, fd);
@ -196,7 +212,8 @@ void ReplayPlay::load()
m_ghost_karts.clearAndDeleteAll();
char s[1024];
FILE *fd = openReplayFile(/*writeable*/false, m_custom_replay_file);
FILE *fd = openReplayFile(/*writeable*/false,
m_replay_file_list.at(m_current_replay_file).m_custom_replay_file);
if(!fd)
{
Log::error("Replay", "Can't read '%s', ghost replay disabled.",

View File

@ -55,6 +55,7 @@ public:
std::string m_track_name;
std::vector<std::string> m_kart_list;
bool m_reverse;
bool m_custom_replay_file;
unsigned int m_difficulty;
unsigned int m_laps;
float m_min_time;
@ -93,8 +94,6 @@ private:
unsigned int m_current_replay_file;
bool m_custom_replay_file;
std::vector<ReplayData> m_replay_file_list;
/** All ghost karts. */

View File

@ -39,10 +39,15 @@ GhostReplayInfoDialog::GhostReplayInfoDialog(unsigned int replay_id)
LabelWidget *name = getWidget<LabelWidget>("name");
assert(name);
name->setText(stringw((m_rd.m_filename).c_str()), false);
name->setText(stringw((m_rd.m_custom_replay_file ? StringUtils::getBasename
(m_rd.m_filename) : m_rd.m_filename).c_str()), false);
m_back_widget = getWidget<IconButtonWidget>("back");
m_back_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
// Non-deletable for custom (standard) replay file
getWidget<IconButtonWidget>("remove")->setActive(!m_rd.m_custom_replay_file);
m_action_widget = getWidget<RibbonWidget>("actions");
m_record_widget = getWidget<CheckBoxWidget>("record-race");
m_watch_widget = getWidget<CheckBoxWidget>("watch-only");
@ -77,7 +82,7 @@ GUIEngine::EventPropagation
if(selection == "start")
{
bool reverse = m_rd.m_reverse;
std::string track_name = m_rd.m_track_name;
std::string track_name = m_rd.m_track_name;
int laps = m_rd.m_laps;
int replay_id = m_replay_id;