summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkrzys-h <krzys_h@interia.pl>2014-10-25 12:01:21 +0200
committerkrzys-h <krzys_h@interia.pl>2014-10-25 12:01:21 +0200
commit7d28b9a6da319f4e102aedddbc2d6df64753146a (patch)
tree4bfebbe2b9cc7f01eefd7815c74f0a82780fc10c /src
parent4c865322f0142b2ebeb89c4354c7a2f529ea4a7f (diff)
downloadcolobot-7d28b9a6da319f4e102aedddbc2d6df64753146a.tar.gz
colobot-7d28b9a6da319f4e102aedddbc2d6df64753146a.tar.bz2
colobot-7d28b9a6da319f4e102aedddbc2d6df64753146a.zip
Fixed #340
Diffstat (limited to 'src')
-rw-r--r--src/object/level/parser.cpp6
-rw-r--r--src/object/level/parser.h2
-rw-r--r--src/ui/maindialog.cpp112
3 files changed, 34 insertions, 86 deletions
diff --git a/src/object/level/parser.cpp b/src/object/level/parser.cpp
index ab3e6bc..3a0449a 100644
--- a/src/object/level/parser.cpp
+++ b/src/object/level/parser.cpp
@@ -22,6 +22,7 @@
#include "app/app.h"
+#include "common/resources/resourcemanager.h"
#include "common/resources/inputstream.h"
#include "object/level/parserexceptions.h"
@@ -115,6 +116,11 @@ std::string CLevelParser::BuildSceneName(std::string category, int chapter, int
return outstream.str();
}
+bool CLevelParser::Exists()
+{
+ return CResourceManager::Exists(m_filename);
+}
+
void CLevelParser::Load()
{
CInputStream file;
diff --git a/src/object/level/parser.h b/src/object/level/parser.h
index 7e87e2d..ca2bf6f 100644
--- a/src/object/level/parser.h
+++ b/src/object/level/parser.h
@@ -46,6 +46,8 @@ public:
//! Build level filename
static std::string BuildSceneName(std::string category, int chapter, int rank, bool sceneFile = true);
+ //! Check if level file exists
+ bool Exists();
//! Load file
void Load();
//! Save file
diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp
index fe40609..f5b61c6 100644
--- a/src/ui/maindialog.cpp
+++ b/src/ui/maindialog.cpp
@@ -4378,17 +4378,11 @@ void CMainDialog::UpdateSceneChap(int &chap)
CList* pl;
std::string fileName;
- char op[100];
- char op_i18n[100];
char line[500];
- char name[100];
- int i, j;
+ int j;
bool bPassed;
- memset(op, 0, 100);
- memset(op_i18n, 0, 100);
memset(line, 0, 500);
- memset(name, 0, 100);
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
@@ -4425,41 +4419,19 @@ void CMainDialog::UpdateSceneChap(int &chap)
{
for ( j=0 ; j<9 ; j++ )
{
- BuildSceneName(fileName, m_sceneName, (j+1)*100);
- CInputStream stream;
- stream.open(fileName);
- if (!stream.is_open()) break;
-
- BuildResumeName(name, m_sceneName, j+1); // default name
- sprintf(op, "Title.E");
- sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar());
-
- while (stream.getline(line, 500))
- {
- for ( i=0 ; i<500 ; i++ )
- {
- if ( line[i] == '\t' ) line[i] = ' '; // replaces tab by space
- if ( line[i] == '/' && line[i+1] == '/' )
- {
- line[i] = 0;
- break;
- }
- }
-
- if ( Cmd(line, op) )
- {
- OpString(line, "text", name);
- }
- if ( Cmd(line, op_i18n) )
- {
- OpString(line, "text", name);
- break;
- }
+ CLevelParser* level = new CLevelParser(m_sceneName, j+1, 0);
+ if(!level->Exists())
+ break;
+ try {
+ level->Load();
+ sprintf(line, "%d: %s", j+1, level->Get("Title")->GetParam("text")->AsString().c_str());
}
- stream.close();
+ catch(CLevelParserException& e) {
+ sprintf(line, "%s", (std::string("[ERROR]: ")+e.what()).c_str());
+ }
+ delete level;
bPassed = GetGamerInfoPassed((j+1)*100);
- sprintf(line, "%d: %s", j+1, name);
pl->SetItemName(j, line);
pl->SetCheck(j, bPassed);
pl->SetEnable(j, true);
@@ -4491,17 +4463,11 @@ void CMainDialog::UpdateSceneList(int chap, int &sel)
CWindow* pw;
CList* pl;
std::string fileName;
- char op[100];
- char op_i18n[100];
char line[500];
- char name[100];
- int i, j;
+ int j;
bool bPassed;
- memset(op, 0, 100);
- memset(op_i18n, 0, 100);
memset(line, 0, 500);
- memset(name, 0, 100);
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
@@ -4512,44 +4478,22 @@ void CMainDialog::UpdateSceneList(int chap, int &sel)
if(chap < 0) return;
+ bool readAll = true;
for ( j=0 ; j<99 ; j++ )
{
- BuildSceneName(fileName, m_sceneName, (chap+1)*100+(j+1));
-
- CInputStream stream;
- stream.open(fileName);
- if (!stream.is_open()) break;
-
- BuildResumeName(name, m_sceneName, j+1); // default name
- sprintf(op, "Title.E");
- sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar());
-
- while (stream.getline(line, 500))
- {
- for ( i=0 ; i<500 ; i++ )
- {
- if ( line[i] == '\t' ) line[i] = ' '; // replaces tab by space
- if ( line[i] == '/' && line[i+1] == '/' )
- {
- line[i] = 0;
- break;
- }
- }
-
- if ( Cmd(line, op) )
- {
- OpString(line, "text", name);
- }
- if ( Cmd(line, op_i18n) )
- {
- OpString(line, "text", name);
- break;
- }
+ CLevelParser* level = new CLevelParser(m_sceneName, chap+1, j+1);
+ if(!level->Exists())
+ break;
+ try {
+ level->Load();
+ sprintf(line, "%d: %s", j+1, level->Get("Title")->GetParam("text")->AsString().c_str());
}
- stream.close();
+ catch(CLevelParserException& e) {
+ sprintf(line, "%s", (std::string("[ERROR]: ")+e.what()).c_str());
+ }
+ delete level;
bPassed = GetGamerInfoPassed((chap+1)*100+(j+1));
- sprintf(line, "%d: %s", j+1, name);
pl->SetItemName(j, line);
pl->SetCheck(j, bPassed);
pl->SetEnable(j, true);
@@ -4557,23 +4501,19 @@ void CMainDialog::UpdateSceneList(int chap, int &sel)
if ( m_phase == PHASE_MISSION && !m_main->GetShowAll() && !bPassed )
{
j ++;
+ readAll = false;
break;
}
}
- /* TODO: ?????
- BuildSceneName(fileName, m_sceneName, (chap+1)*100+(j+1));
- file = fopen(fileName.c_str(), "r");
- if ( file == NULL )
+ if(readAll)
{
m_maxList = j;
}
else
{
m_maxList = j+1; // this is not the last!
- fclose(file);
- }*/
- m_maxList = j;
+ }
if ( sel > j-1 ) sel = j-1;