From 2260f6bf4feb62929e32a1bea9cd3f403aa034b1 Mon Sep 17 00:00:00 2001 From: Krzysztof Dermont Date: Fri, 20 Jun 2014 23:41:38 +0200 Subject: Big part of PhysFS support * removed -mod argument * removed -datadir argument * removed -lang argument * removed some dead ui code * added resource manager and file loaders (stream and SDL) * changed interface textures location to match new directory structure * removed CGameData for mod support * added PhysFS support --- src/ui/maindialog.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src/ui/maindialog.cpp') diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 1964531..9afad80 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -18,7 +18,6 @@ #include "ui/maindialog.h" #include "app/app.h" -#include "app/gamedata.h" #include "app/system.h" #include "common/config.h" @@ -182,7 +181,7 @@ CMainDialog::CMainDialog() #if DEV_BUILD m_savegameDir = "savegame"; #else - m_savegameDir = GetSystemUtils()->GetSavegameDirectoryLocation(); + m_savegameDir = "savegame"; #endif m_publicDir = "program"; @@ -389,7 +388,7 @@ pb->SetState(STATE_SHADOW); pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontSize(Gfx::FONT_SIZE_SMALL); - m_engine->SetBackground("interface.png", + m_engine->SetBackground("textures/interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -509,7 +508,7 @@ pb->SetState(STATE_SHADOW); UpdateNameControl(); UpdateNameFace(); - m_engine->SetBackground("interface.png", + m_engine->SetBackground("textures/interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -973,7 +972,7 @@ pb->SetState(STATE_SHADOW); pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_BACK); pb->SetState(STATE_SHADOW); - m_engine->SetBackground("interface.png", + m_engine->SetBackground("textures/interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1172,7 +1171,7 @@ pb->SetState(STATE_SHADOW); if ( !m_bSimulSetup ) { - m_engine->SetBackground("interface.png", + m_engine->SetBackground("textures/interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1690,7 +1689,7 @@ pos.y -= 0.048f; if ( m_phase == PHASE_READ ) { - m_engine->SetBackground("interface.png", + m_engine->SetBackground("textures/interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1740,7 +1739,7 @@ pos.y -= 0.048f; pl->SetFontSize(12.0f); pl->SetTextAlign(Gfx::TEXT_ALIGN_CENTER); - m_engine->SetBackground("interface.png", + m_engine->SetBackground("textures/interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1762,7 +1761,7 @@ pos.y -= 0.048f; m_engine->SetOverColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f), Gfx::ENG_RSTATE_TCOLOR_BLACK); // TODO: color ok? m_engine->SetOverFront(true); - m_engine->SetBackground("ppc.png", + m_engine->SetBackground("textures/interface/ppc.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1781,7 +1780,7 @@ pos.y -= 0.048f; m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::ENG_RSTATE_TCOLOR_WHITE); // TODO: color ok? m_engine->SetOverFront(true); - m_engine->SetBackground("colobot.png", + m_engine->SetBackground("textures/interface/colobot.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1800,7 +1799,7 @@ pos.y -= 0.048f; m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::ENG_RSTATE_TCOLOR_WHITE); // TODO: color ok? m_engine->SetOverFront(true); - m_engine->SetBackground("epsitec.png", + m_engine->SetBackground("textures/interface/epsitec.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1925,7 +1924,7 @@ pos.y -= 0.048f; pb->SetState(STATE_SHADOW); // #endif - m_engine->SetBackground("generico.png", + m_engine->SetBackground("textures/interface/generico.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -3589,7 +3588,6 @@ void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank) { rankStream << std::setfill('0') << std::setw(3) << rank; filename = base + rankStream.str() + ".txt"; - filename = CGameData::GetInstancePointer()->GetFilePath(DIR_LEVEL, filename); } } -- cgit v1.2.3-1-g7c22 From aa190bb59b5047bcaaa4e50df59b3c51cd6be21f Mon Sep 17 00:00:00 2001 From: Krzysztof Dermont Date: Mon, 30 Jun 2014 17:40:40 +0200 Subject: Last changes --- src/ui/maindialog.cpp | 87 +++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 48 deletions(-) (limited to 'src/ui/maindialog.cpp') diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 9afad80..54b8702 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -29,6 +29,10 @@ #include "common/restext.h" #include "common/stringutils.h" +#include "common/resources/resourcemanager.h" +#include "common/resources/inputstream.h" +#include "common/resources/outputstream.h" + #include "object/robotmain.h" #include "script/cmdtoken.h" @@ -48,6 +52,7 @@ #include "ui/window.h" #include "ui/edit.h" #include "ui/editvalue.h" +#include #include #include @@ -175,9 +180,6 @@ CMainDialog::CMainDialog() m_partiTime[i] = 0.0f; } - - m_sceneDir = "levels"; - #if DEV_BUILD m_savegameDir = "savegame"; #else @@ -762,7 +764,7 @@ pb->SetState(STATE_SHADOW); { if (!m_sound->IsPlayingMusic()) { - m_sound->PlayMusic("Intro1.ogg", false); + m_sound->PlayMusic("music/Intro1.ogg", false); } } @@ -782,15 +784,15 @@ pb->SetState(STATE_SHADOW); if ( m_phase == PHASE_FREE ) { - strcpy(m_sceneName, "scene"); + strcpy(m_sceneName, "levels/missions/"); ReadGamerInfo(); m_accessChap = GetChapPassed(); } - if ( m_phase == PHASE_TRAINER ) strcpy(m_sceneName, "train"); - if ( m_phase == PHASE_DEFI ) strcpy(m_sceneName, "defi" ); - if ( m_phase == PHASE_MISSION ) strcpy(m_sceneName, "scene"); - if ( m_phase == PHASE_FREE ) strcpy(m_sceneName, "free"); + if ( m_phase == PHASE_TRAINER ) strcpy(m_sceneName, "levels/exercises/"); + if ( m_phase == PHASE_DEFI ) strcpy(m_sceneName, "levels/challenges/" ); + if ( m_phase == PHASE_MISSION ) strcpy(m_sceneName, "levels/missions/"); + if ( m_phase == PHASE_FREE ) strcpy(m_sceneName, "levels/freemissions/"); if ( m_phase == PHASE_TEEN ) strcpy(m_sceneName, "teen"); if ( m_phase == PHASE_USER ) strcpy(m_sceneName, "user"); @@ -2011,7 +2013,7 @@ bool CMainDialog::EventProcess(const Event &event) { if (!m_sound->IsPlayingMusic()) { - m_sound->PlayMusic("Intro2.ogg", true); + m_sound->PlayMusic("music/Intro2.ogg", true); } } @@ -3584,10 +3586,22 @@ void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank) rankStream << std::setfill('0') << std::setw(2) << rank%100; filename = m_userDir + "/" + m_userList[rank/100-1] + "/" + rankStream.str() + ".txt"; } + else if ( strcmp(base, "perso") == 0 ) + { + filename = "levels/other/perso.txt"; + } else { - rankStream << std::setfill('0') << std::setw(3) << rank; - filename = base + rankStream.str() + ".txt"; + rankStream << "chapter" << std::setfill('0') << std::setw(3) << (rank / 100); + if (rank % 100 == 0) + { + rankStream << "/chaptertitle.txt"; + } + else + { + rankStream << "/level" << std::setfill('0') << std::setw(3) << (rank % 100) << "/scene.txt"; + } + filename = base + rankStream.str(); } } @@ -4282,7 +4296,6 @@ bool CMainDialog::IsIOReadScene() void CMainDialog::IOReadName() { - FILE* file; CWindow* pw; CEdit* pe; std::string filename; @@ -4304,10 +4317,12 @@ void CMainDialog::IOReadName() sprintf(op, "Title.E"); sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar() ); - file = fopen(filename.c_str(), "r"); - if ( file != NULL ) + CInputStream stream; + stream.open(filename); + + if (stream.is_open()) { - while ( fgets(line, 500, file) != NULL ) + while (stream.getline(line, 500)) { for ( i=0 ; i<500 ; i++ ) { @@ -4329,7 +4344,7 @@ void CMainDialog::IOReadName() break; } } - fclose(file); + stream.close(); } time(&now); @@ -4675,10 +4690,10 @@ void CMainDialog::AllMissionUpdate() void CMainDialog::UpdateSceneChap(int &chap) { - FILE* file = NULL; CWindow* pw; CList* pl; - //struct _finddata_t fileBuffer; + FILE *file; + std::string fileName; char op[100]; char op_i18n[100]; @@ -4762,26 +4777,16 @@ void CMainDialog::UpdateSceneChap(int &chap) { for ( j=0 ; j<9 ; j++ ) { -/* TODO: #if _SCHOOL - if ( m_phase == PHASE_MISSION ) break; - if ( m_phase == PHASE_FREE ) break; -#if _CEEBOTDEMO - if ( m_phase == PHASE_TRAINER && j >= 2 ) break; -#endif -#endif -#if _DEMO - if ( m_phase == PHASE_MISSION && j >= 4 ) break; - if ( m_phase == PHASE_TRAINER && j >= 1 ) break; -#endif */ BuildSceneName(fileName, m_sceneName, (j+1)*100); - file = fopen(fileName.c_str(), "r"); - if ( file == NULL ) break; + 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 ( fgets(line, 500, file) != NULL ) + while (stream.getline(line, 500)) { for ( i=0 ; i<500 ; i++ ) { @@ -4803,7 +4808,7 @@ void CMainDialog::UpdateSceneChap(int &chap) break; } } - fclose(file); + stream.close(); bPassed = GetGamerInfoPassed((j+1)*100); sprintf(line, "%d: %s", j+1, name); @@ -4817,14 +4822,6 @@ void CMainDialog::UpdateSceneChap(int &chap) break; } -/* TODO: #if _TEEN - if ( m_phase == PHASE_TRAINER && !m_main->GetShowAll() && !bPassed ) - { - j ++; - break; - } -#endif*/ - if ( m_phase == PHASE_FREE && j == m_accessChap ) { j ++; @@ -5493,7 +5490,6 @@ void CMainDialog::ChangeSetupButtons() void CMainDialog::SetupMemorize() { - GetProfile().SetLocalProfileString("Directory", "scene", m_sceneDir); GetProfile().SetLocalProfileString("Directory", "savegame", m_savegameDir); GetProfile().SetLocalProfileString("Directory", "public", m_publicDir); GetProfile().SetLocalProfileString("Directory", "user", m_userDir); @@ -5586,11 +5582,6 @@ void CMainDialog::SetupRecall() int iValue; std::string key; - if ( GetProfile().GetLocalProfileString("Directory", "scene", key) ) - { - m_sceneDir = key; - } - if ( GetProfile().GetLocalProfileString("Directory", "savegame", key) ) { m_savegameDir = key; -- cgit v1.2.3-1-g7c22 From 1ee0c0e8fe2b4f0cba35b65b2c17deaa9f1dc8e8 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 10 Jul 2014 15:27:43 +0200 Subject: Fixed level list --- src/ui/maindialog.cpp | 57 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 21 deletions(-) (limited to 'src/ui/maindialog.cpp') diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 54b8702..c6322b6 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -784,15 +784,15 @@ pb->SetState(STATE_SHADOW); if ( m_phase == PHASE_FREE ) { - strcpy(m_sceneName, "levels/missions/"); + strcpy(m_sceneName, "missions"); ReadGamerInfo(); m_accessChap = GetChapPassed(); } - if ( m_phase == PHASE_TRAINER ) strcpy(m_sceneName, "levels/exercises/"); - if ( m_phase == PHASE_DEFI ) strcpy(m_sceneName, "levels/challenges/" ); - if ( m_phase == PHASE_MISSION ) strcpy(m_sceneName, "levels/missions/"); - if ( m_phase == PHASE_FREE ) strcpy(m_sceneName, "levels/freemissions/"); + if ( m_phase == PHASE_TRAINER ) strcpy(m_sceneName, "exercises"); + if ( m_phase == PHASE_DEFI ) strcpy(m_sceneName, "challenges" ); + if ( m_phase == PHASE_MISSION ) strcpy(m_sceneName, "missions"); + if ( m_phase == PHASE_FREE ) strcpy(m_sceneName, "freemissions"); if ( m_phase == PHASE_TEEN ) strcpy(m_sceneName, "teen"); if ( m_phase == PHASE_USER ) strcpy(m_sceneName, "user"); @@ -3579,29 +3579,42 @@ void CMainDialog::SetUserDir(char *base, int rank) void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank) { - std::ostringstream rankStream; + //TODO: Support for more than 100 + int chapter = rank/100; + int new_rank = rank%100; + + std::ostringstream outstream; if ( strcmp(base, "user") == 0 ) { //TODO: Change this to point user dir according to operating system - rankStream << std::setfill('0') << std::setw(2) << rank%100; - filename = m_userDir + "/" + m_userList[rank/100-1] + "/" + rankStream.str() + ".txt"; + /*rankStream << std::setfill('0') << std::setw(2) << rank%100; + filename = m_userDir + "/" + m_userList[rank/100-1] + "/" + rankStream.str() + ".txt";*/ + assert(false); //TODO: Userlevel support } else if ( strcmp(base, "perso") == 0 ) { filename = "levels/other/perso.txt"; } + else if( strcmp(base, "win") == 0 || strcmp(base, "lost") == 0 ) + { + outstream << "levels/other/"; + outstream << base << std::setfill('0') << std::setw(3) << chapter << "/"; + outstream << "scene.txt"; + std::cout << outstream.str() << std::endl; + filename = outstream.str(); + } else { - rankStream << "chapter" << std::setfill('0') << std::setw(3) << (rank / 100); - if (rank % 100 == 0) - { - rankStream << "/chaptertitle.txt"; - } - else - { - rankStream << "/level" << std::setfill('0') << std::setw(3) << (rank % 100) << "/scene.txt"; + outstream << "levels/" << base << "/"; + outstream << "chapter" << std::setfill('0') << std::setw(3) << chapter << "/"; + if(new_rank == 000) { + outstream << "chaptertitle.txt"; + } else { + outstream << "level" << std::setfill('0') << std::setw(3) << new_rank << "/"; + outstream << "scene.txt"; } - filename = base + rankStream.str(); + filename = outstream.str(); + std::cout << filename.c_str() << std::endl; } } @@ -4881,14 +4894,16 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) if ( m_phase == PHASE_TRAINER && j >= 5 ) break; #endif */ BuildSceneName(fileName, m_sceneName, (chap+1)*100+(j+1)); - file = fopen(fileName.c_str(), "r"); - if ( file == NULL ) break; + + 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 ( fgets(line, 500, file) != NULL ) + while (stream.getline(line, 500)) { for ( i=0 ; i<500 ; i++ ) { @@ -4910,7 +4925,7 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) break; } } - fclose(file); + stream.close(); bPassed = GetGamerInfoPassed((chap+1)*100+(j+1)); sprintf(line, "%d: %s", j+1, name); -- cgit v1.2.3-1-g7c22 From 7b04f673580f0c24aecc103a25c4c4b82da1380f Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 10 Jul 2014 15:38:37 +0200 Subject: Fixed music loading --- src/ui/maindialog.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/ui/maindialog.cpp') diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index c6322b6..2699b46 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -764,7 +764,7 @@ pb->SetState(STATE_SHADOW); { if (!m_sound->IsPlayingMusic()) { - m_sound->PlayMusic("music/Intro1.ogg", false); + m_sound->PlayMusic("Intro1.ogg", false); } } @@ -2013,7 +2013,7 @@ bool CMainDialog::EventProcess(const Event &event) { if (!m_sound->IsPlayingMusic()) { - m_sound->PlayMusic("music/Intro2.ogg", true); + m_sound->PlayMusic("Intro2.ogg", true); } } @@ -3579,7 +3579,7 @@ void CMainDialog::SetUserDir(char *base, int rank) void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank) { - //TODO: Support for more than 100 + //TODO: Support for more than 9 chapters int chapter = rank/100; int new_rank = rank%100; @@ -3614,7 +3614,6 @@ void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank) outstream << "scene.txt"; } filename = outstream.str(); - std::cout << filename.c_str() << std::endl; } } -- cgit v1.2.3-1-g7c22 From 106ec014b812c6f5eb93ea30c04b3bba333542dd Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 10 Jul 2014 16:25:40 +0200 Subject: Fixed texture and script loading --- src/ui/maindialog.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/ui/maindialog.cpp') diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 2699b46..ed5edb4 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -390,7 +390,7 @@ pb->SetState(STATE_SHADOW); pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontSize(Gfx::FONT_SIZE_SMALL); - m_engine->SetBackground("textures/interface/interface.png", + m_engine->SetBackground("interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -510,7 +510,7 @@ pb->SetState(STATE_SHADOW); UpdateNameControl(); UpdateNameFace(); - m_engine->SetBackground("textures/interface/interface.png", + m_engine->SetBackground("interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -974,7 +974,7 @@ pb->SetState(STATE_SHADOW); pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_BACK); pb->SetState(STATE_SHADOW); - m_engine->SetBackground("textures/interface/interface.png", + m_engine->SetBackground("interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1173,7 +1173,7 @@ pb->SetState(STATE_SHADOW); if ( !m_bSimulSetup ) { - m_engine->SetBackground("textures/interface/interface.png", + m_engine->SetBackground("interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1691,7 +1691,7 @@ pos.y -= 0.048f; if ( m_phase == PHASE_READ ) { - m_engine->SetBackground("textures/interface/interface.png", + m_engine->SetBackground("interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1741,7 +1741,7 @@ pos.y -= 0.048f; pl->SetFontSize(12.0f); pl->SetTextAlign(Gfx::TEXT_ALIGN_CENTER); - m_engine->SetBackground("textures/interface/interface.png", + m_engine->SetBackground("interface/interface.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1763,7 +1763,7 @@ pos.y -= 0.048f; m_engine->SetOverColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f), Gfx::ENG_RSTATE_TCOLOR_BLACK); // TODO: color ok? m_engine->SetOverFront(true); - m_engine->SetBackground("textures/interface/ppc.png", + m_engine->SetBackground("interface/ppc.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1782,7 +1782,7 @@ pos.y -= 0.048f; m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::ENG_RSTATE_TCOLOR_WHITE); // TODO: color ok? m_engine->SetOverFront(true); - m_engine->SetBackground("textures/interface/colobot.png", + m_engine->SetBackground("interface/colobot.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1801,7 +1801,7 @@ pos.y -= 0.048f; m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::ENG_RSTATE_TCOLOR_WHITE); // TODO: color ok? m_engine->SetOverFront(true); - m_engine->SetBackground("textures/interface/epsitec.png", + m_engine->SetBackground("interface/epsitec.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), @@ -1926,7 +1926,7 @@ pos.y -= 0.048f; pb->SetState(STATE_SHADOW); // #endif - m_engine->SetBackground("textures/interface/generico.png", + m_engine->SetBackground("interface/generico.png", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), -- cgit v1.2.3-1-g7c22 From 5223ef1fb116780298495a4d2f63e6c2c39fdfbd Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 10 Jul 2014 16:36:00 +0200 Subject: Fixed mission description loading --- src/ui/maindialog.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/ui/maindialog.cpp') diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index ed5edb4..dffa424 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -4852,7 +4852,6 @@ void CMainDialog::UpdateSceneChap(int &chap) void CMainDialog::UpdateSceneList(int chap, int &sel) { - FILE* file = NULL; CWindow* pw; CList* pl; std::string fileName; @@ -4947,6 +4946,7 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) #endif*/ } + /* TODO: ????? BuildSceneName(fileName, m_sceneName, (chap+1)*100+(j+1)); file = fopen(fileName.c_str(), "r"); if ( file == NULL ) @@ -4957,7 +4957,8 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) { m_maxList = j+1; // this is not the last! fclose(file); - } + }*/ + m_maxList = j; if ( sel > j-1 ) sel = j-1; @@ -5008,7 +5009,6 @@ void CMainDialog::ShowSoluceUpdate() void CMainDialog::UpdateSceneResume(int rank) { - FILE* file = NULL; CWindow* pw; CEdit* pe; CCheck* pc; @@ -5048,11 +5048,12 @@ void CMainDialog::UpdateSceneResume(int rank) sprintf(op, "Resume.E"); sprintf(op_i18n, "Resume.%c", m_app->GetLanguageChar()); - file = fopen(fileName.c_str(), "r"); - if ( file == NULL ) return; + CInputStream stream; + stream.open(fileName); + if (!stream.is_open()) return; name[0] = 0; - while ( fgets(line, 500, file) != NULL ) + while ( stream.getline(line, 500) ) { for ( i=0 ; i<500 ; i++ ) { @@ -5077,7 +5078,7 @@ void CMainDialog::UpdateSceneResume(int rank) break; } } - fclose(file); + stream.close(); pe->SetText(name); } -- cgit v1.2.3-1-g7c22 From 02ba358a892b9977250ea345c42f8226f89ba250 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 11 Jul 2014 16:40:07 +0200 Subject: Help file loading --- src/ui/maindialog.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/ui/maindialog.cpp') diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index fd6cd2e..068732d 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -3290,7 +3290,7 @@ void CMainDialog::SetUserDir(char *base, int rank) // 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 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 ) { outstream << "levels/other/"; - outstream << base << std::setfill('0') << std::setw(3) << chapter << "/"; - outstream << "scene.txt"; - std::cout << outstream.str() << std::endl; + outstream << base << std::setfill('0') << std::setw(3) << rank << ".txt"; filename = outstream.str(); } else { outstream << "levels/" << base << "/"; outstream << "chapter" << std::setfill('0') << std::setw(3) << chapter << "/"; - if(new_rank == 000) { - outstream << "chaptertitle.txt"; - } else { + if(new_rank == 000) + { + if(sceneFile) + { + outstream << "chaptertitle.txt"; + } + } + else + { outstream << "level" << std::setfill('0') << std::setw(3) << new_rank << "/"; - outstream << "scene.txt"; + if(sceneFile) + { + outstream << "scene.txt"; + } } filename = outstream.str(); } -- cgit v1.2.3-1-g7c22 From 2b86e6e9d9be5cecc17eb509ee6fb1e2e73b184d Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 7 Sep 2014 22:07:48 +0200 Subject: Rewrite CMainDialog to use physfs --- src/ui/maindialog.cpp | 248 +++++++++++++++----------------------------------- 1 file changed, 72 insertions(+), 176 deletions(-) (limited to 'src/ui/maindialog.cpp') diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 068732d..ba8da9e 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -52,15 +52,12 @@ #include "ui/window.h" #include "ui/edit.h" #include "ui/editvalue.h" -#include #include #include #include #include #include -#include -#include //TODO Get rid of all sprintf's @@ -111,8 +108,6 @@ static int perso_color[3*10*3] = 0, 0, 0, // }; -namespace fs = boost::filesystem; - // Constructor of robot application. CMainDialog::CMainDialog() @@ -177,12 +172,7 @@ CMainDialog::CMainDialog() m_partiTime[i] = 0.0f; } - #if DEV_BUILD - m_savegameDir = "savegame"; - #else m_savegameDir = "savegame"; - #endif - m_publicDir = "program"; m_userDir = "user"; m_filesDir = m_savegameDir; @@ -3356,50 +3346,16 @@ std::string & CMainDialog::GetFilesDir() void CMainDialog::ReadNameList() { - CWindow* pw; - CList* pl; - //struct _finddata_t fBuffer; - char dir[MAX_FNAME]; - // char filenames[MAX_FNAME][100]; - std::vector fileNames; - - pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); - if ( pw == 0 ) return; - pl = static_cast(pw->SearchControl(EVENT_INTERFACE_NLIST)); - if ( pl == 0 ) return; + CWindow* pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); + if (pw == nullptr) return; + CList* pl = static_cast(pw->SearchControl(EVENT_INTERFACE_NLIST)); + if (pl == nullptr) return; pl->Flush(); - - try + auto userSaveDirs = CResourceManager::ListDirectories(m_savegameDir); + for (int i = 0; i < static_cast(userSaveDirs.size()); ++i) { - if (! fs::exists(m_savegameDir) && fs::is_directory(m_savegameDir)) - { - GetLogger()->Error("Savegame dir does not exist %s\n",dir); - } - else - { - fs::directory_iterator dirIt(m_savegameDir), dirEndIt; - - for (; dirIt != dirEndIt; ++dirIt) - { - const fs::path& p = *dirIt; - if (fs::is_directory(p)) - { - fileNames.push_back(p.leaf().string()); - } - } - } - } - catch (std::exception & e) - { - GetLogger()->Error("Error on listing savegame directory : %s\n", e.what()); - return; - } - - - for (size_t i=0 ; iSetItemName(i, fileNames.at(i).c_str()); + pl->SetItemName(i, userSaveDirs.at(i).c_str()); } } @@ -3582,7 +3538,6 @@ void CMainDialog::NameCreate() CWindow* pw; CEdit* pe; char name[100]; - std::string dir; char c; int len, i, j; @@ -3623,13 +3578,10 @@ void CMainDialog::NameCreate() return; } - // TODO: _mkdir(m_savegameDir); // if does not exist yet! - - - dir = m_savegameDir + "/" + name; - if (!fs::exists(dir)) + std::string userSaveDir = m_savegameDir + "/" + name; + if (!CResourceManager::DirectoryExists(userSaveDir)) { - fs::create_directories(dir); + CResourceManager::CreateDirectory(userSaveDir); } else { @@ -3646,58 +3598,26 @@ void CMainDialog::NameCreate() m_main->ChangePhase(PHASE_INIT); } -// Deletes a folder and all its offspring. - -bool RemoveDir(char *dirName) -{ - try - { - - if (!fs::exists(dirName) && fs::is_directory(dirName)) - { - GetLogger()->Error("Directory does not exist %s\n",dirName); - return false; - } - else - { - fs::remove_all(dirName); - } - - } - catch (std::exception & e) - { - GetLogger()->Error("Error on removing directory %s : %s\n", dirName, e.what()); - return false; - } - return true; -} - // Removes a player. void CMainDialog::NameDelete() { - CWindow* pw; - CList* pl; - int sel; - char* gamer; - char dir[100]; - - pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); - if ( pw == 0 ) return; - pl = static_cast(pw->SearchControl(EVENT_INTERFACE_NLIST)); - if ( pl == 0 ) return; + CWindow* pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); + if (pw == nullptr) return; + CList* pl = static_cast(pw->SearchControl(EVENT_INTERFACE_NLIST)); + if (pl == nullptr) return; - sel = pl->GetSelect(); - if ( sel == -1 ) + int sel = pl->GetSelect(); + if (sel == -1) { m_sound->Play(SOUND_TZOING); return; } - gamer = pl->GetItemName(sel); - // Deletes all the contents of the file. - sprintf(dir, "%s/%s", m_savegameDir.c_str(), gamer); - if ( !RemoveDir(dir) ) + char* gamer = pl->GetItemName(sel); + + std::string userSaveDir = m_savegameDir + "/" + gamer; + if (!CResourceManager::RemoveDirectory(userSaveDir)) { m_sound->Play(SOUND_TZOING); return; @@ -4007,17 +3927,13 @@ void CMainDialog::DefPerso() bool CMainDialog::IsIOReadScene() { - fs::directory_iterator end_iter; - - fs::path saveDir(m_savegameDir + "/" + m_main->GetGamerName()); - if (fs::exists(saveDir) && fs::is_directory(saveDir)) + std::string userSaveDir = m_savegameDir + "/" + m_main->GetGamerName(); + auto saveDirs = CResourceManager::ListDirectories(userSaveDir); + for (auto dir : saveDirs) { - for( fs::directory_iterator dir_iter(saveDir) ; dir_iter != end_iter ; ++dir_iter) + if (CResourceManager::Exists(userSaveDir + "/" + dir + "/" + "data.sav")) { - if ( fs::is_directory(dir_iter->status()) && fs::exists(dir_iter->path() / "data.sav") ) - { - return true; - } + return true; } } @@ -4091,59 +4007,53 @@ void CMainDialog::IOReadName() void CMainDialog::IOReadList() { - FILE* file = NULL; - CWindow* pw; - CList* pl; - char line[500]; - char name[100]; - int i; - std::vector v; - - pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); - if ( pw == 0 ) return; - pl = static_cast(pw->SearchControl(EVENT_INTERFACE_IOLIST)); - if ( pl == 0 ) return; + CWindow* pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); + if (pw == nullptr) return; + CList* pl = static_cast(pw->SearchControl(EVENT_INTERFACE_IOLIST)); + if (pl == nullptr) return; pl->Flush(); - fs::path saveDir(m_savegameDir + "/" + m_main->GetGamerName()); m_saveList.clear(); - if (fs::exists(saveDir) && fs::is_directory(saveDir)) + std::string userSaveDir = m_savegameDir + "/" + m_main->GetGamerName(); + + auto saveDirs = CResourceManager::ListDirectories(userSaveDir); + std::sort(saveDirs.begin(), saveDirs.end()); + + for (auto dir : saveDirs) { - copy(fs::directory_iterator(saveDir), fs::directory_iterator(), back_inserter(v)); - std::sort(v.begin(), v.end()); - for( std::vector::iterator iter = v.begin(); iter != v.end(); ++iter) + std::string savegameFile = userSaveDir + "/" + dir + "/" + "data.sav"; + if (CResourceManager::Exists(savegameFile)) { - if ( fs::is_directory(*iter) && fs::exists(*iter / "data.sav") ) - { + char line[500]; + char name[100]; - file = fopen((*iter / "data.sav").make_preferred().string().c_str(), "r"); - if ( file == NULL ) continue; + FILE* file = fopen(savegameFile.c_str(), "r"); + if ( file == NULL ) continue; - while ( fgets(line, 500, file) != NULL ) + while ( fgets(line, 500, file) != NULL ) + { + for (int i=0 ; i<500 ; i++ ) { - 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, "Title") ) + if ( line[i] == '\t' ) line[i] = ' '; // replaces tab by space + if ( line[i] == '/' && line[i+1] == '/' ) { - OpString(line, "text", name); + line[i] = 0; break; } } - fclose(file); - pl->SetItemName(m_saveList.size(), name); - m_saveList.push_back(*iter); + if ( Cmd(line, "Title") ) + { + OpString(line, "text", name); + break; + } } + fclose(file); + + pl->SetItemName(m_saveList.size(), name); + m_saveList.push_back(userSaveDir + "/" + dir); } } @@ -4182,7 +4092,7 @@ void CMainDialog::IOUpdateList() if (m_saveList.size() <= static_cast(sel)) return; - std::string filename = (m_saveList.at(sel) / "screen.png").make_preferred().string(); + std::string filename = m_saveList.at(sel) + "/" + "screen.png"; if ( m_phase == PHASE_WRITE || m_phase == PHASE_WRITEs ) { if ( sel < max-1 ) @@ -4226,16 +4136,9 @@ void CMainDialog::IODeleteScene() return; } - try - { - if (fs::exists(m_saveList.at(sel)) && fs::is_directory(m_saveList.at(sel))) - { - fs::remove_all(m_saveList.at(sel)); - } - } - catch (std::exception & e) + if (CResourceManager::DirectoryExists(m_saveList.at(sel))) { - GetLogger()->Error("Error removing save %s : %s\n", pl->GetItemName(sel), e.what()); + CResourceManager::RemoveDirectory(m_saveList.at(sel)); } IOReadList(); @@ -4279,28 +4182,28 @@ bool CMainDialog::IOWriteScene() return false; } - fs::path dir; + std::string dir; pe->GetText(info, 100); if (static_cast(sel) >= m_saveList.size()) { - dir = fs::path(m_savegameDir) / m_main->GetGamerName() / ("save" + clearName(info)); + dir = m_savegameDir + "/" + m_main->GetGamerName() + "/" + "save" + clearName(info); } else { dir = m_saveList.at(sel); } - if (!fs::exists(dir)) + if (!CResourceManager::DirectoryExists(dir)) { - fs::create_directories(dir); + CResourceManager::CreateDirectory(dir); } - std::string fileName = (dir / "data.sav").make_preferred().string(); - std::string fileCBot = (dir / "cbot.run").make_preferred().string(); - m_main->IOWriteScene(fileName.c_str(), fileCBot.c_str(), info); + std::string savegameFileName = dir + "/" + "data.sav"; + std::string fileCBot = dir + "/" + "cbot.run"; + m_main->IOWriteScene(savegameFileName.c_str(), fileCBot.c_str(), info); m_shotDelay = 3; - m_shotName = (dir / "screen.png").make_preferred().string(); + m_shotName = dir + "/" + "screen.png"; return true; } @@ -4327,8 +4230,8 @@ bool CMainDialog::IOReadScene() return false; } - std::string fileName = (m_saveList.at(sel) / "data.sav").make_preferred().string(); - std::string fileCbot = (m_saveList.at(sel) / "cbot.run").make_preferred().string(); + std::string fileName = m_saveList.at(sel) + "/" + "data.sav"; + std::string fileCbot = m_saveList.at(sel) + "/" + "cbot.run"; file = fopen(fileName.c_str(), "r"); if ( file == NULL ) @@ -4448,17 +4351,10 @@ void CMainDialog::UpdateSceneChap(int &chap) if ( m_phase == PHASE_USER ) { j = 0; - fs::directory_iterator dirIt(m_savegameDir), dirEndIt; - m_userList.clear(); - for (; dirIt != dirEndIt; ++dirIt) - { - const fs::path& p = *dirIt; - if (fs::is_directory(p)) - { - m_userList.push_back(p.leaf().string()); - } - } + auto userSaveDirs = CResourceManager::ListDirectories(m_savegameDir); + std::sort(userSaveDirs.begin(), userSaveDirs.end()); + m_userList = userSaveDirs; m_userTotal = m_userList.size(); for ( j=0 ; j Date: Fri, 26 Sep 2014 19:48:53 +0200 Subject: Don't use physfs in saving code for now This requires too much refactoring and we want to release 0.1.5 soon. We'll need to rewrite saving/loading code to fully implement new level parser anyway. --- src/ui/maindialog.cpp | 248 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 176 insertions(+), 72 deletions(-) (limited to 'src/ui/maindialog.cpp') diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index ba8da9e..068732d 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -52,12 +52,15 @@ #include "ui/window.h" #include "ui/edit.h" #include "ui/editvalue.h" +#include #include #include #include #include #include +#include +#include //TODO Get rid of all sprintf's @@ -108,6 +111,8 @@ static int perso_color[3*10*3] = 0, 0, 0, // }; +namespace fs = boost::filesystem; + // Constructor of robot application. CMainDialog::CMainDialog() @@ -172,7 +177,12 @@ CMainDialog::CMainDialog() m_partiTime[i] = 0.0f; } + #if DEV_BUILD + m_savegameDir = "savegame"; + #else m_savegameDir = "savegame"; + #endif + m_publicDir = "program"; m_userDir = "user"; m_filesDir = m_savegameDir; @@ -3346,16 +3356,50 @@ std::string & CMainDialog::GetFilesDir() void CMainDialog::ReadNameList() { - CWindow* pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); - if (pw == nullptr) return; - CList* pl = static_cast(pw->SearchControl(EVENT_INTERFACE_NLIST)); - if (pl == nullptr) return; + CWindow* pw; + CList* pl; + //struct _finddata_t fBuffer; + char dir[MAX_FNAME]; + // char filenames[MAX_FNAME][100]; + std::vector fileNames; + + pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); + if ( pw == 0 ) return; + pl = static_cast(pw->SearchControl(EVENT_INTERFACE_NLIST)); + if ( pl == 0 ) return; pl->Flush(); - auto userSaveDirs = CResourceManager::ListDirectories(m_savegameDir); - for (int i = 0; i < static_cast(userSaveDirs.size()); ++i) + + try { - pl->SetItemName(i, userSaveDirs.at(i).c_str()); + if (! fs::exists(m_savegameDir) && fs::is_directory(m_savegameDir)) + { + GetLogger()->Error("Savegame dir does not exist %s\n",dir); + } + else + { + fs::directory_iterator dirIt(m_savegameDir), dirEndIt; + + for (; dirIt != dirEndIt; ++dirIt) + { + const fs::path& p = *dirIt; + if (fs::is_directory(p)) + { + fileNames.push_back(p.leaf().string()); + } + } + } + } + catch (std::exception & e) + { + GetLogger()->Error("Error on listing savegame directory : %s\n", e.what()); + return; + } + + + for (size_t i=0 ; iSetItemName(i, fileNames.at(i).c_str()); } } @@ -3538,6 +3582,7 @@ void CMainDialog::NameCreate() CWindow* pw; CEdit* pe; char name[100]; + std::string dir; char c; int len, i, j; @@ -3578,10 +3623,13 @@ void CMainDialog::NameCreate() return; } - std::string userSaveDir = m_savegameDir + "/" + name; - if (!CResourceManager::DirectoryExists(userSaveDir)) + // TODO: _mkdir(m_savegameDir); // if does not exist yet! + + + dir = m_savegameDir + "/" + name; + if (!fs::exists(dir)) { - CResourceManager::CreateDirectory(userSaveDir); + fs::create_directories(dir); } else { @@ -3598,26 +3646,58 @@ void CMainDialog::NameCreate() m_main->ChangePhase(PHASE_INIT); } +// Deletes a folder and all its offspring. + +bool RemoveDir(char *dirName) +{ + try + { + + if (!fs::exists(dirName) && fs::is_directory(dirName)) + { + GetLogger()->Error("Directory does not exist %s\n",dirName); + return false; + } + else + { + fs::remove_all(dirName); + } + + } + catch (std::exception & e) + { + GetLogger()->Error("Error on removing directory %s : %s\n", dirName, e.what()); + return false; + } + return true; +} + // Removes a player. void CMainDialog::NameDelete() { - CWindow* pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); - if (pw == nullptr) return; - CList* pl = static_cast(pw->SearchControl(EVENT_INTERFACE_NLIST)); - if (pl == nullptr) return; + CWindow* pw; + CList* pl; + int sel; + char* gamer; + char dir[100]; + + pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); + if ( pw == 0 ) return; + pl = static_cast(pw->SearchControl(EVENT_INTERFACE_NLIST)); + if ( pl == 0 ) return; - int sel = pl->GetSelect(); - if (sel == -1) + sel = pl->GetSelect(); + if ( sel == -1 ) { m_sound->Play(SOUND_TZOING); return; } + gamer = pl->GetItemName(sel); - char* gamer = pl->GetItemName(sel); - - std::string userSaveDir = m_savegameDir + "/" + gamer; - if (!CResourceManager::RemoveDirectory(userSaveDir)) + // Deletes all the contents of the file. + sprintf(dir, "%s/%s", m_savegameDir.c_str(), gamer); + if ( !RemoveDir(dir) ) { m_sound->Play(SOUND_TZOING); return; @@ -3927,13 +4007,17 @@ void CMainDialog::DefPerso() bool CMainDialog::IsIOReadScene() { - std::string userSaveDir = m_savegameDir + "/" + m_main->GetGamerName(); - auto saveDirs = CResourceManager::ListDirectories(userSaveDir); - for (auto dir : saveDirs) + fs::directory_iterator end_iter; + + fs::path saveDir(m_savegameDir + "/" + m_main->GetGamerName()); + if (fs::exists(saveDir) && fs::is_directory(saveDir)) { - if (CResourceManager::Exists(userSaveDir + "/" + dir + "/" + "data.sav")) + for( fs::directory_iterator dir_iter(saveDir) ; dir_iter != end_iter ; ++dir_iter) { - return true; + if ( fs::is_directory(dir_iter->status()) && fs::exists(dir_iter->path() / "data.sav") ) + { + return true; + } } } @@ -4007,53 +4091,59 @@ void CMainDialog::IOReadName() void CMainDialog::IOReadList() { - CWindow* pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); - if (pw == nullptr) return; - CList* pl = static_cast(pw->SearchControl(EVENT_INTERFACE_IOLIST)); - if (pl == nullptr) return; + FILE* file = NULL; + CWindow* pw; + CList* pl; + char line[500]; + char name[100]; + int i; + std::vector v; + + pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); + if ( pw == 0 ) return; + pl = static_cast(pw->SearchControl(EVENT_INTERFACE_IOLIST)); + if ( pl == 0 ) return; pl->Flush(); + fs::path saveDir(m_savegameDir + "/" + m_main->GetGamerName()); m_saveList.clear(); - std::string userSaveDir = m_savegameDir + "/" + m_main->GetGamerName(); - - auto saveDirs = CResourceManager::ListDirectories(userSaveDir); - std::sort(saveDirs.begin(), saveDirs.end()); - - for (auto dir : saveDirs) + if (fs::exists(saveDir) && fs::is_directory(saveDir)) { - std::string savegameFile = userSaveDir + "/" + dir + "/" + "data.sav"; - if (CResourceManager::Exists(savegameFile)) + copy(fs::directory_iterator(saveDir), fs::directory_iterator(), back_inserter(v)); + std::sort(v.begin(), v.end()); + for( std::vector::iterator iter = v.begin(); iter != v.end(); ++iter) { - char line[500]; - char name[100]; + if ( fs::is_directory(*iter) && fs::exists(*iter / "data.sav") ) + { - FILE* file = fopen(savegameFile.c_str(), "r"); - if ( file == NULL ) continue; + file = fopen((*iter / "data.sav").make_preferred().string().c_str(), "r"); + if ( file == NULL ) continue; - while ( fgets(line, 500, file) != NULL ) - { - for (int i=0 ; i<500 ; i++ ) + while ( fgets(line, 500, file) != NULL ) { - if ( line[i] == '\t' ) line[i] = ' '; // replaces tab by space - if ( line[i] == '/' && line[i+1] == '/' ) + for ( i=0 ; i<500 ; i++ ) { - line[i] = 0; + if ( line[i] == '\t' ) line[i] = ' '; // replaces tab by space + if ( line[i] == '/' && line[i+1] == '/' ) + { + line[i] = 0; + break; + } + } + + if ( Cmd(line, "Title") ) + { + OpString(line, "text", name); break; } } + fclose(file); - if ( Cmd(line, "Title") ) - { - OpString(line, "text", name); - break; - } + pl->SetItemName(m_saveList.size(), name); + m_saveList.push_back(*iter); } - fclose(file); - - pl->SetItemName(m_saveList.size(), name); - m_saveList.push_back(userSaveDir + "/" + dir); } } @@ -4092,7 +4182,7 @@ void CMainDialog::IOUpdateList() if (m_saveList.size() <= static_cast(sel)) return; - std::string filename = m_saveList.at(sel) + "/" + "screen.png"; + std::string filename = (m_saveList.at(sel) / "screen.png").make_preferred().string(); if ( m_phase == PHASE_WRITE || m_phase == PHASE_WRITEs ) { if ( sel < max-1 ) @@ -4136,9 +4226,16 @@ void CMainDialog::IODeleteScene() return; } - if (CResourceManager::DirectoryExists(m_saveList.at(sel))) + try + { + if (fs::exists(m_saveList.at(sel)) && fs::is_directory(m_saveList.at(sel))) + { + fs::remove_all(m_saveList.at(sel)); + } + } + catch (std::exception & e) { - CResourceManager::RemoveDirectory(m_saveList.at(sel)); + GetLogger()->Error("Error removing save %s : %s\n", pl->GetItemName(sel), e.what()); } IOReadList(); @@ -4182,28 +4279,28 @@ bool CMainDialog::IOWriteScene() return false; } - std::string dir; + fs::path dir; pe->GetText(info, 100); if (static_cast(sel) >= m_saveList.size()) { - dir = m_savegameDir + "/" + m_main->GetGamerName() + "/" + "save" + clearName(info); + dir = fs::path(m_savegameDir) / m_main->GetGamerName() / ("save" + clearName(info)); } else { dir = m_saveList.at(sel); } - if (!CResourceManager::DirectoryExists(dir)) + if (!fs::exists(dir)) { - CResourceManager::CreateDirectory(dir); + fs::create_directories(dir); } - std::string savegameFileName = dir + "/" + "data.sav"; - std::string fileCBot = dir + "/" + "cbot.run"; - m_main->IOWriteScene(savegameFileName.c_str(), fileCBot.c_str(), info); + std::string fileName = (dir / "data.sav").make_preferred().string(); + std::string fileCBot = (dir / "cbot.run").make_preferred().string(); + m_main->IOWriteScene(fileName.c_str(), fileCBot.c_str(), info); m_shotDelay = 3; - m_shotName = dir + "/" + "screen.png"; + m_shotName = (dir / "screen.png").make_preferred().string(); return true; } @@ -4230,8 +4327,8 @@ bool CMainDialog::IOReadScene() return false; } - std::string fileName = m_saveList.at(sel) + "/" + "data.sav"; - std::string fileCbot = m_saveList.at(sel) + "/" + "cbot.run"; + std::string fileName = (m_saveList.at(sel) / "data.sav").make_preferred().string(); + std::string fileCbot = (m_saveList.at(sel) / "cbot.run").make_preferred().string(); file = fopen(fileName.c_str(), "r"); if ( file == NULL ) @@ -4351,10 +4448,17 @@ void CMainDialog::UpdateSceneChap(int &chap) if ( m_phase == PHASE_USER ) { j = 0; + fs::directory_iterator dirIt(m_savegameDir), dirEndIt; + m_userList.clear(); - auto userSaveDirs = CResourceManager::ListDirectories(m_savegameDir); - std::sort(userSaveDirs.begin(), userSaveDirs.end()); - m_userList = userSaveDirs; + for (; dirIt != dirEndIt; ++dirIt) + { + const fs::path& p = *dirIt; + if (fs::is_directory(p)) + { + m_userList.push_back(p.leaf().string()); + } + } m_userTotal = m_userList.size(); for ( j=0 ; j Date: Fri, 26 Sep 2014 20:53:11 +0200 Subject: Userlevel listing --- src/ui/maindialog.cpp | 189 +++++++++----------------------------------------- 1 file changed, 33 insertions(+), 156 deletions(-) (limited to 'src/ui/maindialog.cpp') diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 068732d..3acf1dd 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -33,6 +33,8 @@ #include "common/resources/inputstream.h" #include "common/resources/outputstream.h" +#include "object/level/parser.h" + #include "object/robotmain.h" #include "script/cmdtoken.h" @@ -52,7 +54,6 @@ #include "ui/window.h" #include "ui/edit.h" #include "ui/editvalue.h" -#include #include #include @@ -177,14 +178,8 @@ CMainDialog::CMainDialog() m_partiTime[i] = 0.0f; } - #if DEV_BUILD - m_savegameDir = "savegame"; - #else m_savegameDir = "savegame"; - #endif - m_publicDir = "program"; - m_userDir = "user"; m_filesDir = m_savegameDir; m_setupFull = m_app->GetVideoConfig().fullScreen; @@ -316,7 +311,6 @@ void CMainDialog::ChangePhase(Phase phase) pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_QUIT); pb->SetState(STATE_SHADOW); - #if DEV_BUILD if ( m_accessEnable && m_accessUser ) { pos.x = 447.0f/640.0f; @@ -325,7 +319,6 @@ void CMainDialog::ChangePhase(Phase phase) pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_USER); pb->SetState(STATE_SHADOW); } - #endif /*pos.x = 139.0f/640.0f; pos.y = 313.0f/480.0f; @@ -723,7 +716,7 @@ void CMainDialog::ChangePhase(Phase phase) if ( m_phase == PHASE_DEFI ) strcpy(m_sceneName, "challenges" ); if ( m_phase == PHASE_MISSION ) strcpy(m_sceneName, "missions"); if ( m_phase == PHASE_FREE ) strcpy(m_sceneName, "freemissions"); - if ( m_phase == PHASE_USER ) strcpy(m_sceneName, "user"); + if ( m_phase == PHASE_USER ) strcpy(m_sceneName, "custom"); ReadGamerInfo(); @@ -3271,23 +3264,6 @@ void CMainDialog::NiceParticle(Math::Point mouse, bool bPress) -// Specifies the special user folder if needed. - -void CMainDialog::SetUserDir(char *base, int rank) -{ - std::string dir; - - if ( strcmp(base, "user") == 0 && rank >= 100 ) - { - dir = m_userDir + "/" + m_userList.at(rank/100-1); - GetProfile().SetUserDir(dir); - } - else - { - GetProfile().SetUserDir(""); - } -} - // Builds the file name of a mission. void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank, bool sceneFile) @@ -3296,45 +3272,7 @@ void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank, bo int chapter = rank/100; int new_rank = rank%100; - std::ostringstream outstream; - if ( strcmp(base, "user") == 0 ) - { - //TODO: Change this to point user dir according to operating system - /*rankStream << std::setfill('0') << std::setw(2) << rank%100; - filename = m_userDir + "/" + m_userList[rank/100-1] + "/" + rankStream.str() + ".txt";*/ - assert(false); //TODO: Userlevel support - } - else if ( strcmp(base, "perso") == 0 ) - { - filename = "levels/other/perso.txt"; - } - else if( strcmp(base, "win") == 0 || strcmp(base, "lost") == 0 ) - { - outstream << "levels/other/"; - outstream << base << std::setfill('0') << std::setw(3) << rank << ".txt"; - filename = outstream.str(); - } - else - { - outstream << "levels/" << base << "/"; - outstream << "chapter" << std::setfill('0') << std::setw(3) << chapter << "/"; - if(new_rank == 000) - { - if(sceneFile) - { - outstream << "chaptertitle.txt"; - } - } - else - { - outstream << "level" << std::setfill('0') << std::setw(3) << new_rank << "/"; - if(sceneFile) - { - outstream << "scene.txt"; - } - } - filename = outstream.str(); - } + filename = CLevelParser::BuildSceneName(std::string(base), chapter, new_rank, sceneFile); } // Built the default descriptive name of a mission. @@ -4423,7 +4361,6 @@ void CMainDialog::UpdateSceneChap(int &chap) { CWindow* pw; CList* pl; - FILE *file; std::string fileName; char op[100]; @@ -4448,60 +4385,25 @@ void CMainDialog::UpdateSceneChap(int &chap) if ( m_phase == PHASE_USER ) { j = 0; - fs::directory_iterator dirIt(m_savegameDir), dirEndIt; - m_userList.clear(); - - for (; dirIt != dirEndIt; ++dirIt) - { - const fs::path& p = *dirIt; - if (fs::is_directory(p)) - { - m_userList.push_back(p.leaf().string()); - } - } + auto userLevelDirs = CResourceManager::ListDirectories("levels/custom/"); + std::sort(userLevelDirs.begin(), userLevelDirs.end()); + m_userList = userLevelDirs; m_userTotal = m_userList.size(); for ( j=0 ; jLoad(); + pl->SetItemName(j, level->Get("Title")->GetParam("text")->AsString().c_str()); + pl->SetEnable(j, true); + delete level; } - else + catch(CLevelParserException& e) { - BuildResumeName(name, m_sceneName, j+1); // default name - sprintf(op, "Title.E"); - sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar()); - - while ( fgets(line, 500, file) != NULL ) - { - 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; - } - } - fclose(file); + pl->SetItemName(j, (std::string("[ERROR]: ")+e.what()).c_str()); + pl->SetEnable(j, false); } - - pl->SetItemName(j, name); - pl->SetEnable(j, true); } } else @@ -4592,6 +4494,8 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) if ( pl == 0 ) return; pl->Flush(); + + if(chap < 0) return; for ( j=0 ; j<99 ; j++ ) { @@ -4738,44 +4642,18 @@ void CMainDialog::UpdateSceneResume(int rank) m_bSceneSoluce = false; } } - - BuildSceneName(fileName, m_sceneName, rank); - sprintf(op, "Resume.E"); - sprintf(op_i18n, "Resume.%c", m_app->GetLanguageChar()); - - CInputStream stream; - stream.open(fileName); - if (!stream.is_open()) return; - - name[0] = 0; - while ( stream.getline(line, 500) ) + + if(rank<100) return; + + try { + CLevelParser* level = new CLevelParser(m_sceneName, rank/100, rank%100); + level->Load(); + pe->SetText(level->Get("Resume")->GetParam("text")->AsString().c_str()); + } + catch(CLevelParserException& e) { - for ( i=0 ; i<500 ; i++ ) - { - if (line[i] == 0) - break; - - 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; - } + pe->SetText((std::string("[ERROR]: ")+e.what()).c_str()); } - stream.close(); - - pe->SetText(name); } // Updates the list of devices. @@ -5202,7 +5080,6 @@ void CMainDialog::SetupMemorize() { GetProfile().SetLocalProfileString("Directory", "savegame", m_savegameDir); GetProfile().SetLocalProfileString("Directory", "public", m_publicDir); - GetProfile().SetLocalProfileString("Directory", "user", m_userDir); GetProfile().SetLocalProfileString("Directory", "files", m_filesDir); GetProfile().SetLocalProfileInt("Setup", "Tooltips", m_bTooltip); GetProfile().SetLocalProfileInt("Setup", "InterfaceGlint", m_bGlint); @@ -5288,11 +5165,6 @@ void CMainDialog::SetupRecall() m_publicDir = key; } - if ( GetProfile().GetLocalProfileString("Directory", "user", key) ) - { - m_userDir = key; - } - if ( GetProfile().GetLocalProfileString("Directory", "files", key) ) { m_filesDir = key; @@ -6487,6 +6359,11 @@ bool CMainDialog::NextMission() return true; } +std::string& CMainDialog::GetUserLevelName(int id) +{ + return m_userList[id-1]; +} + } // namespace Ui -- cgit v1.2.3-1-g7c22 From c29ef4ec41cc062c4dbc14af8736c5e1c7c25f02 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 27 Sep 2014 16:49:00 +0200 Subject: Fixed some warnings Removed unused variables and fixed signed/unsigned comparation warnings --- src/ui/maindialog.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/ui/maindialog.cpp') diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 3acf1dd..b886691 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -4612,11 +4612,7 @@ void CMainDialog::UpdateSceneResume(int rank) CEdit* pe; CCheck* pc; std::string fileName; - char op[100]; - char op_i18n[100]; - char line[500]; - char name[500]; - int i, numTry; + int numTry; bool bPassed, bVisible; pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); @@ -5889,7 +5885,6 @@ void CMainDialog::FrameDialog(float rTime) void CMainDialog::StopDialog() { CWindow* pw; - CButton* pb; pw = static_cast(m_interface->SearchControl(EVENT_WINDOW0)); if ( pw != 0 ) pw->SetState(STATE_ENABLE); -- cgit v1.2.3-1-g7c22 From 83abb8ca8e74176d64944e9681d74aa11ef6cdf9 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 19 Oct 2014 13:18:31 +0200 Subject: Fixed program saving --- src/ui/maindialog.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/ui/maindialog.cpp') diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 482d00b..7d1da0a 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -3527,7 +3527,7 @@ void CMainDialog::NameCreate() char c; int len, i, j; - GetLogger()->Debug("Creating new player\n"); + GetLogger()->Info("Creating new player\n"); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); if ( pw == 0 ) return; pe = static_cast(pw->SearchControl(EVENT_INTERFACE_NEDIT)); @@ -3564,13 +3564,16 @@ void CMainDialog::NameCreate() return; } - // TODO: _mkdir(m_savegameDir); // if does not exist yet! - + if(!CResourceManager::DirectoryExists(m_savegameDir)) + CResourceManager::CreateDirectory(m_savegameDir); + dir = m_savegameDir + "/" + name; if (!fs::exists(dir)) { fs::create_directories(dir); + if(!CResourceManager::DirectoryExists(dir)) + CResourceManager::CreateDirectory(dir); } else { -- cgit v1.2.3-1-g7c22