diff options
Diffstat (limited to 'src/ui/maindialog.cpp')
-rw-r--r-- | src/ui/maindialog.cpp | 131 |
1 files changed, 77 insertions, 54 deletions
diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 39e7aa9..fd6cd2e 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" @@ -30,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" @@ -49,6 +52,7 @@ #include "ui/window.h" #include "ui/edit.h" #include "ui/editvalue.h" +#include <test/cbot/CBot_console/CClass.h> #include <stdio.h> #include <string.h> @@ -173,13 +177,10 @@ CMainDialog::CMainDialog() m_partiTime[i] = 0.0f; } - - m_sceneDir = "levels"; - #if DEV_BUILD m_savegameDir = "savegame"; #else - m_savegameDir = GetSystemUtils()->GetSavegameDirectoryLocation(); + m_savegameDir = "savegame"; #endif m_publicDir = "program"; @@ -343,7 +344,7 @@ void CMainDialog::ChangePhase(Phase phase) pl->SetFontType(Gfx::FONT_COURIER); pl->SetFontSize(Gfx::FONT_SIZE_SMALL); - m_engine->SetBackground("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), @@ -450,7 +451,7 @@ void CMainDialog::ChangePhase(Phase phase) UpdateNameControl(); UpdateNameFace(); - m_engine->SetBackground("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), @@ -713,15 +714,15 @@ void CMainDialog::ChangePhase(Phase phase) if ( m_phase == PHASE_FREE ) { - strcpy(m_sceneName, "scene"); + strcpy(m_sceneName, "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, "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_USER ) strcpy(m_sceneName, "user"); ReadGamerInfo(); @@ -875,7 +876,7 @@ void CMainDialog::ChangePhase(Phase phase) pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_BACK); pb->SetState(STATE_SHADOW); - m_engine->SetBackground("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), @@ -1000,7 +1001,7 @@ void CMainDialog::ChangePhase(Phase phase) if ( !m_bSimulSetup ) { - m_engine->SetBackground("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), @@ -1489,7 +1490,7 @@ void CMainDialog::ChangePhase(Phase phase) if ( m_phase == PHASE_READ ) { - m_engine->SetBackground("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), @@ -1536,7 +1537,7 @@ void CMainDialog::ChangePhase(Phase phase) pl->SetFontSize(12.0f); pl->SetTextAlign(Gfx::TEXT_ALIGN_CENTER); - m_engine->SetBackground("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), @@ -1558,7 +1559,7 @@ void CMainDialog::ChangePhase(Phase phase) 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("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), @@ -1577,7 +1578,7 @@ void CMainDialog::ChangePhase(Phase phase) 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("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), @@ -1596,7 +1597,7 @@ void CMainDialog::ChangePhase(Phase phase) 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("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), @@ -1662,7 +1663,7 @@ void CMainDialog::ChangePhase(Phase phase) pb = pw->CreateButton(pos, ddim, 49, EVENT_INTERFACE_ABORT); pb->SetState(STATE_SHADOW); - m_engine->SetBackground("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), @@ -3291,18 +3292,41 @@ 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 9 chapters + 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 << std::setfill('0') << std::setw(3) << rank; - filename = base + rankStream.str() + ".txt"; - filename = CGameData::GetInstancePointer()->GetFilePath(DIR_LEVEL, filename); + 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 = outstream.str(); } } @@ -3997,7 +4021,6 @@ bool CMainDialog::IsIOReadScene() void CMainDialog::IOReadName() { - FILE* file; CWindow* pw; CEdit* pe; std::string filename; @@ -4019,10 +4042,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++ ) { @@ -4044,7 +4069,7 @@ void CMainDialog::IOReadName() break; } } - fclose(file); + stream.close(); } time(&now); @@ -4389,10 +4414,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]; @@ -4477,14 +4502,15 @@ void CMainDialog::UpdateSceneChap(int &chap) for ( j=0 ; j<9 ; j++ ) { 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++ ) { @@ -4506,7 +4532,7 @@ void CMainDialog::UpdateSceneChap(int &chap) break; } } - fclose(file); + stream.close(); bPassed = GetGamerInfoPassed((j+1)*100); sprintf(line, "%d: %s", j+1, name); @@ -4538,7 +4564,6 @@ void CMainDialog::UpdateSceneChap(int &chap) void CMainDialog::UpdateSceneList(int chap, int &sel) { - FILE* file = NULL; CWindow* pw; CList* pl; std::string fileName; @@ -4564,14 +4589,16 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) for ( j=0 ; j<99 ; j++ ) { 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++ ) { @@ -4593,7 +4620,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); @@ -4608,6 +4635,7 @@ void CMainDialog::UpdateSceneList(int chap, int &sel) } } + /* TODO: ????? BuildSceneName(fileName, m_sceneName, (chap+1)*100+(j+1)); file = fopen(fileName.c_str(), "r"); if ( file == NULL ) @@ -4618,7 +4646,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; @@ -4668,7 +4697,6 @@ void CMainDialog::ShowSoluceUpdate() void CMainDialog::UpdateSceneResume(int rank) { - FILE* file = NULL; CWindow* pw; CEdit* pe; CCheck* pc; @@ -4708,11 +4736,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++ ) { @@ -4737,7 +4766,7 @@ void CMainDialog::UpdateSceneResume(int rank) break; } } - fclose(file); + stream.close(); pe->SetText(name); } @@ -5164,7 +5193,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); @@ -5243,11 +5271,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; |