Help file loading
parent
96d49d84aa
commit
02ba358a89
|
@ -3843,11 +3843,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
const char* stack = m_dialog->GetStackRead().c_str();
|
const char* stack = m_dialog->GetStackRead().c_str();
|
||||||
m_dialog->SetUserDir(base, rank);
|
m_dialog->SetUserDir(base, rank);
|
||||||
|
|
||||||
/*
|
|
||||||
* TODO: original code relying on UserDir() was removed.
|
|
||||||
* A new way of providing custom data file paths will need to be devised.
|
|
||||||
*/
|
|
||||||
|
|
||||||
m_fixScene = fixScene;
|
m_fixScene = fixScene;
|
||||||
|
|
||||||
g_id = 0;
|
g_id = 0;
|
||||||
|
@ -4020,7 +4015,9 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
if (Cmd(line, "Instructions") && !resetObject)
|
if (Cmd(line, "Instructions") && !resetObject)
|
||||||
{
|
{
|
||||||
OpString(line, "name", name);
|
OpString(line, "name", name);
|
||||||
strcpy(m_infoFilename[SATCOM_HUSTON], name);
|
std::string path = name;
|
||||||
|
InjectLevelDir(path, "help/%lng%");
|
||||||
|
strcpy(m_infoFilename[SATCOM_HUSTON], path.c_str());
|
||||||
|
|
||||||
m_immediatSatCom = OpInt(line, "immediat", 0);
|
m_immediatSatCom = OpInt(line, "immediat", 0);
|
||||||
if (m_version >= 2) m_beginSatCom = m_lockedSatCom = OpInt(line, "lock", 0);
|
if (m_version >= 2) m_beginSatCom = m_lockedSatCom = OpInt(line, "lock", 0);
|
||||||
|
@ -4031,27 +4028,35 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
if (Cmd(line, "Satellite") && !resetObject)
|
if (Cmd(line, "Satellite") && !resetObject)
|
||||||
{
|
{
|
||||||
OpString(line, "name", name);
|
OpString(line, "name", name);
|
||||||
strcpy(m_infoFilename[SATCOM_SAT], name);
|
std::string path = name;
|
||||||
|
InjectLevelDir(path, "help/%lng%");
|
||||||
|
strcpy(m_infoFilename[SATCOM_SAT], path.c_str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Cmd(line, "Loading") && !resetObject)
|
if (Cmd(line, "Loading") && !resetObject)
|
||||||
{
|
{
|
||||||
OpString(line, "name", name);
|
OpString(line, "name", name);
|
||||||
strcpy(m_infoFilename[SATCOM_LOADING], name);
|
std::string path = name;
|
||||||
|
InjectLevelDir(path, "help/%lng%");
|
||||||
|
strcpy(m_infoFilename[SATCOM_LOADING], path.c_str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Cmd(line, "HelpFile") && !resetObject)
|
if (Cmd(line, "HelpFile") && !resetObject)
|
||||||
{
|
{
|
||||||
OpString(line, "name", name);
|
OpString(line, "name", name);
|
||||||
strcpy(m_infoFilename[SATCOM_PROG], name);
|
std::string path = name;
|
||||||
|
InjectLevelDir(path, "help/%lng%");
|
||||||
|
strcpy(m_infoFilename[SATCOM_PROG], path.c_str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Cmd(line, "SoluceFile") && !resetObject)
|
if (Cmd(line, "SoluceFile") && !resetObject)
|
||||||
{
|
{
|
||||||
OpString(line, "name", name);
|
OpString(line, "name", name);
|
||||||
strcpy(m_infoFilename[SATCOM_SOLUCE], name);
|
std::string path = name;
|
||||||
|
InjectLevelDir(path, "help/%lng%");
|
||||||
|
strcpy(m_infoFilename[SATCOM_SOLUCE], path.c_str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7001,6 +7006,21 @@ float CRobotMain::GetPersoAngle()
|
||||||
return m_dialog->GetPersoAngle();
|
return m_dialog->GetPersoAngle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* CRobotMain::GetSceneName()
|
||||||
|
{
|
||||||
|
return m_dialog->GetSceneName();
|
||||||
|
}
|
||||||
|
|
||||||
|
int CRobotMain::GetSceneRank()
|
||||||
|
{
|
||||||
|
return m_dialog->GetSceneRank();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRobotMain::BuildSceneName(std::string &filename, char *base, int rank, bool sceneFile)
|
||||||
|
{
|
||||||
|
m_dialog->BuildSceneName(filename, base, rank, sceneFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Changes on the pause mode
|
//! Changes on the pause mode
|
||||||
void CRobotMain::ChangePause(PauseType pause)
|
void CRobotMain::ChangePause(PauseType pause)
|
||||||
|
@ -7236,3 +7256,17 @@ void CRobotMain::DisplayError(Error err, Math::Vector goal, float height, float
|
||||||
{
|
{
|
||||||
m_displayText->DisplayError(err, goal, height, dist, time);
|
m_displayText->DisplayError(err, goal, height, dist, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CRobotMain::InjectLevelDir(std::string& path, const std::string defaultDir)
|
||||||
|
{
|
||||||
|
std::string oldPath = path;
|
||||||
|
std::string lvlDir;
|
||||||
|
CRobotMain::GetInstancePointer()->BuildSceneName(lvlDir, CRobotMain::GetInstancePointer()->GetSceneName(), CRobotMain::GetInstancePointer()->GetSceneRank(), false);
|
||||||
|
boost::replace_all(path, "%lvl%", lvlDir);
|
||||||
|
if(path == oldPath)
|
||||||
|
{
|
||||||
|
path = defaultDir + "/" + path;
|
||||||
|
}
|
||||||
|
std::string langStr(1, CApplication::GetInstancePointer()->GetLanguageChar());
|
||||||
|
boost::replace_all(path, "%lng%", langStr);
|
||||||
|
}
|
||||||
|
|
|
@ -337,6 +337,9 @@ public:
|
||||||
int GetGamerGlasses();
|
int GetGamerGlasses();
|
||||||
bool GetGamerOnlyHead();
|
bool GetGamerOnlyHead();
|
||||||
float GetPersoAngle();
|
float GetPersoAngle();
|
||||||
|
char* GetSceneName();
|
||||||
|
int GetSceneRank();
|
||||||
|
void BuildSceneName(std::string &filename, char *base, int rank, bool sceneFile = true);
|
||||||
|
|
||||||
void StartMusic();
|
void StartMusic();
|
||||||
void StartPauseMusic(PauseType pause);
|
void StartPauseMusic(PauseType pause);
|
||||||
|
@ -386,6 +389,8 @@ public:
|
||||||
|
|
||||||
void DisplayError(Error err, CObject* pObj, float time=10.0f);
|
void DisplayError(Error err, CObject* pObj, float time=10.0f);
|
||||||
void DisplayError(Error err, Math::Vector goal, float height=15.0f, float dist=60.0f, float time=10.0f);
|
void DisplayError(Error err, Math::Vector goal, float height=15.0f, float dist=60.0f, float time=10.0f);
|
||||||
|
|
||||||
|
static void InjectLevelDir(std::string& path, const std::string defaultDir = "");
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool EventFrame(const Event &event);
|
bool EventFrame(const Event &event);
|
||||||
|
|
|
@ -22,10 +22,13 @@
|
||||||
|
|
||||||
#include "clipboard/clipboard.h"
|
#include "clipboard/clipboard.h"
|
||||||
|
|
||||||
|
#include "object/robotmain.h"
|
||||||
|
|
||||||
#include "common/resources/inputstream.h"
|
#include "common/resources/inputstream.h"
|
||||||
#include "common/resources/outputstream.h"
|
#include "common/resources/outputstream.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
||||||
|
@ -784,14 +787,9 @@ void CEdit::HyperJump(std::string name, std::string marker)
|
||||||
|
|
||||||
sMarker = marker;
|
sMarker = marker;
|
||||||
|
|
||||||
if ( name[0] == '%' )
|
filename = name + std::string(".txt");
|
||||||
{
|
CRobotMain::InjectLevelDir(filename, "help/%lng%");
|
||||||
filename = GetProfile().GetUserBasedPath(name, "") + ".txt";
|
boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
filename = name + std::string(".txt");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ReadText(filename) )
|
if ( ReadText(filename) )
|
||||||
{
|
{
|
||||||
|
@ -1146,6 +1144,9 @@ void CEdit::DrawImage(Math::Point pos, std::string name, float width,
|
||||||
std::string filename;
|
std::string filename;
|
||||||
|
|
||||||
filename = name + ".png";
|
filename = name + ".png";
|
||||||
|
CRobotMain::InjectLevelDir(filename, "icons");
|
||||||
|
boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files
|
||||||
|
filename = "../" + filename;
|
||||||
|
|
||||||
m_engine->SetTexture(filename);
|
m_engine->SetTexture(filename);
|
||||||
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
|
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
|
||||||
|
@ -1434,7 +1435,9 @@ void CEdit::LoadImage(std::string name)
|
||||||
{
|
{
|
||||||
std::string filename;
|
std::string filename;
|
||||||
filename = name + ".png";
|
filename = name + ".png";
|
||||||
m_engine->LoadTexture(filename);
|
CRobotMain::InjectLevelDir(filename, "icons");
|
||||||
|
boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files
|
||||||
|
m_engine->LoadTexture("../"+filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read from a text file.
|
// Read from a text file.
|
||||||
|
@ -1449,13 +1452,14 @@ bool CEdit::ReadText(std::string filename, int addSize)
|
||||||
InputSlot slot;
|
InputSlot slot;
|
||||||
bool bInSoluce, bBOL;
|
bool bInSoluce, bBOL;
|
||||||
|
|
||||||
if ( filename[0] == 0 ) return false;
|
if ( filename == "" ) return false;
|
||||||
|
|
||||||
CInputStream stream;
|
CInputStream stream;
|
||||||
stream.open(filename);
|
stream.open(filename);
|
||||||
|
|
||||||
if (!stream.is_open())
|
if (!stream.is_open())
|
||||||
{
|
{
|
||||||
|
CLogger::GetInstancePointer()->Error("Failed to load text file %s\n", filename.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3290,7 +3290,7 @@ void CMainDialog::SetUserDir(char *base, int rank)
|
||||||
|
|
||||||
// Builds the file name of a mission.
|
// Builds the file name of a mission.
|
||||||
|
|
||||||
void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank)
|
void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank, bool sceneFile)
|
||||||
{
|
{
|
||||||
//TODO: Support for more than 9 chapters
|
//TODO: Support for more than 9 chapters
|
||||||
int chapter = rank/100;
|
int chapter = rank/100;
|
||||||
|
@ -3311,20 +3311,27 @@ void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank)
|
||||||
else if( strcmp(base, "win") == 0 || strcmp(base, "lost") == 0 )
|
else if( strcmp(base, "win") == 0 || strcmp(base, "lost") == 0 )
|
||||||
{
|
{
|
||||||
outstream << "levels/other/";
|
outstream << "levels/other/";
|
||||||
outstream << base << std::setfill('0') << std::setw(3) << chapter << "/";
|
outstream << base << std::setfill('0') << std::setw(3) << rank << ".txt";
|
||||||
outstream << "scene.txt";
|
|
||||||
std::cout << outstream.str() << std::endl;
|
|
||||||
filename = outstream.str();
|
filename = outstream.str();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
outstream << "levels/" << base << "/";
|
outstream << "levels/" << base << "/";
|
||||||
outstream << "chapter" << std::setfill('0') << std::setw(3) << chapter << "/";
|
outstream << "chapter" << std::setfill('0') << std::setw(3) << chapter << "/";
|
||||||
if(new_rank == 000) {
|
if(new_rank == 000)
|
||||||
outstream << "chaptertitle.txt";
|
{
|
||||||
} else {
|
if(sceneFile)
|
||||||
|
{
|
||||||
|
outstream << "chaptertitle.txt";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
outstream << "level" << std::setfill('0') << std::setw(3) << new_rank << "/";
|
outstream << "level" << std::setfill('0') << std::setw(3) << new_rank << "/";
|
||||||
outstream << "scene.txt";
|
if(sceneFile)
|
||||||
|
{
|
||||||
|
outstream << "scene.txt";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
filename = outstream.str();
|
filename = outstream.str();
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ public:
|
||||||
bool GetHimselfDamage();
|
bool GetHimselfDamage();
|
||||||
|
|
||||||
void SetUserDir(char *base, int rank);
|
void SetUserDir(char *base, int rank);
|
||||||
void BuildSceneName(std::string &filename, char *base, int rank);
|
void BuildSceneName(std::string &filename, char *base, int rank, bool sceneFile = true);
|
||||||
void BuildResumeName(char *filename, char *base, int rank);
|
void BuildResumeName(char *filename, char *base, int rank);
|
||||||
std::string & GetFilesDir();
|
std::string & GetFilesDir();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue