LevelCategory enum

master
krzys-h 2015-07-18 18:52:37 +02:00
parent 59a68892c6
commit ea9361fbb4
14 changed files with 255 additions and 140 deletions

View File

@ -153,6 +153,7 @@ set(BASE_SOURCES
object/level/parserexceptions.cpp
object/level/parserline.cpp
object/level/parserparam.cpp
object/level_category.cpp
object/mainmovie.cpp
object/motion/motion.cpp
object/motion/motionant.cpp

View File

@ -142,7 +142,7 @@ CApplication::CApplication()
m_mouseMode = MOUSE_SYSTEM;
m_runSceneName = "";
m_runSceneCategory = LevelCategory::Max;
m_runSceneRank = 0;
m_sceneTest = false;
@ -282,9 +282,18 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
case OPT_RUNSCENE:
{
std::string file = optarg;
m_runSceneName = file.substr(0, file.size()-3);
std::string cat = file.substr(0, file.size()-3);
m_runSceneCategory = GetLevelCategoryFromDir(cat);
m_runSceneRank = StrUtils::FromString<int>(file.substr(file.size()-3, 3));
GetLogger()->Info("Running scene '%s%d' on start\n", m_runSceneName.c_str(), m_runSceneRank);
if(m_runSceneCategory == LevelCategory::Max)
{
GetLogger()->Info("Running scene '%s%d' on start\n", cat.c_str(), m_runSceneRank);
}
else
{
GetLogger()->Error("Requested to run scene from unknown category '%s'\n", cat.c_str());
return PARSE_ARGS_FAIL;
}
break;
}
case OPT_SCENETEST:
@ -573,13 +582,13 @@ bool CApplication::Create()
// Create the robot application.
m_controller = MakeUnique<CController>(this, !defaultValues);
if (m_runSceneName.empty())
if (m_runSceneCategory == LevelCategory::Max)
m_controller->StartApp();
else
{
m_controller->GetRobotMain()->ChangePhase(PHASE_USER); // To load userlevel list - TODO: this is ugly
m_controller->GetRobotMain()->SetExitAfterMission(true);
m_controller->StartGame(m_runSceneName, m_runSceneRank/100, m_runSceneRank%100);
m_controller->StartGame(m_runSceneCategory, m_runSceneRank/100, m_runSceneRank%100);
}
return true;

View File

@ -32,6 +32,8 @@
#include "graphics/core/device.h"
#include "graphics/engine/engine.h"
#include "object/level_category.h"
#include <string>
#include <vector>
@ -433,7 +435,7 @@ protected:
//@{
//! Scene to run on startup
std::string m_runSceneName;
LevelCategory m_runSceneCategory;
int m_runSceneRank;
//@}
@ -452,4 +454,3 @@ protected:
//! Headles mode
bool m_headless;
};

View File

@ -63,10 +63,10 @@ void CController::StartApp()
m_main->ChangePhase(PHASE_WELCOME1);
}
void CController::StartGame(std::string cat, int chap, int lvl)
void CController::StartGame(LevelCategory cat, int chap, int lvl)
{
m_dialog->SetSceneName(cat.c_str());
m_dialog->SetSceneRank(chap*100+lvl);
m_dialog->SetLevelCategory(cat);
m_dialog->SetLevelRank(chap*100+lvl);
m_main->ChangePhase(PHASE_LOADING);
}

View File

@ -24,6 +24,8 @@
#pragma once
#include "object/level_category.h"
#include <memory>
#include <string>
@ -57,7 +59,7 @@ public:
//! Start the application
void StartApp();
//! Starts the simulation, loading the given scene
void StartGame(std::string cat, int chap, int lvl);
void StartGame(LevelCategory cat, int chap, int lvl);
private:
CApplication* m_app;

View File

@ -172,27 +172,27 @@ void CPathManager::LoadModsFromDir(const std::string &dir)
std::string CPathManager::InjectLevelDir(std::string path, const std::string& defaultDir)
{
std::string newPath = path;
std::string lvlDir = CLevelParser::BuildScenePath(CRobotMain::GetInstancePointer()->GetSceneName(), CRobotMain::GetInstancePointer()->GetSceneRank()/100, CRobotMain::GetInstancePointer()->GetSceneRank()%100, false);
std::string lvlDir = CLevelParser::BuildScenePath(CRobotMain::GetInstancePointer()->GetLevelCategory(), CRobotMain::GetInstancePointer()->GetLevelRank()/100, CRobotMain::GetInstancePointer()->GetLevelRank()%100, false);
boost::replace_all(newPath, "%lvl%", lvlDir);
std::string chapDir = CLevelParser::BuildScenePath(CRobotMain::GetInstancePointer()->GetSceneName(), CRobotMain::GetInstancePointer()->GetSceneRank()/100, 0, false);
std::string chapDir = CLevelParser::BuildScenePath(CRobotMain::GetInstancePointer()->GetLevelCategory(), CRobotMain::GetInstancePointer()->GetLevelRank()/100, 0, false);
boost::replace_all(newPath, "%chap%", chapDir);
std::string catDir = CLevelParser::BuildCategoryPath(CRobotMain::GetInstancePointer()->GetSceneName());
std::string catDir = CLevelParser::BuildCategoryPath(CRobotMain::GetInstancePointer()->GetLevelCategory());
boost::replace_all(newPath, "%cat%", catDir);
if(newPath == path && !path.empty())
{
newPath = defaultDir + (!defaultDir.empty() ? "/" : "") + newPath;
}
std::string langPath = newPath;
std::string langStr(1, CApplication::GetInstancePointer()->GetLanguageChar());
boost::replace_all(langPath, "%lng%", langStr);
if(CResourceManager::Exists(langPath))
return langPath;
// Fallback to English if file doesn't exist
boost::replace_all(newPath, "%lng%", "E");
if(CResourceManager::Exists(newPath))
return newPath;
return langPath; // Return current language file if none of the files exist
}
}

View File

@ -56,6 +56,10 @@ CLevelParser::CLevelParser(std::string category, int chapter, int rank)
m_filename = BuildScenePath(category, chapter, rank);
}
CLevelParser::CLevelParser(LevelCategory category, int chapter, int rank)
: CLevelParser(GetLevelCategoryDir(category), chapter, rank)
{}
std::string CLevelParser::BuildCategoryPath(std::string category)
{
std::ostringstream outstream;
@ -71,13 +75,18 @@ std::string CLevelParser::BuildCategoryPath(std::string category)
return outstream.str();
}
std::string CLevelParser::BuildCategoryPath(LevelCategory category)
{
return BuildCategoryPath(GetLevelCategoryDir(category));
}
std::string CLevelParser::BuildScenePath(std::string category, int chapter, int rank, bool sceneFile)
{
std::ostringstream outstream;
outstream << BuildCategoryPath(category);
if (category == "custom")
{
outstream << CRobotMain::GetInstancePointer()->GetUserLevelName(chapter);
outstream << CRobotMain::GetInstancePointer()->GetCustomLevelName(chapter);
if (rank == 000)
{
if (sceneFile)
@ -124,6 +133,11 @@ std::string CLevelParser::BuildScenePath(std::string category, int chapter, int
return outstream.str();
}
std::string CLevelParser::BuildScenePath(LevelCategory category, int chapter, int rank, bool sceneFile)
{
return BuildScenePath(GetLevelCategoryDir(category), chapter, rank, sceneFile);
}
bool CLevelParser::Exists()
{
return CResourceManager::Exists(m_filename);

View File

@ -28,6 +28,8 @@
#include "object/level/parserparam.h"
#include "object/level/parserexceptions.h"
#include "object/level_category.h"
#include <string>
#include <vector>
#include <memory>
@ -40,12 +42,21 @@ public:
//! Load level from file
CLevelParser(std::string filename);
//! Load given level
//@{
CLevelParser(LevelCategory category, int chapter, int rank);
CLevelParser(std::string category, int chapter, int rank);
//@}
//! Build category path
//@{
static std::string BuildCategoryPath(LevelCategory category);
static std::string BuildCategoryPath(std::string category);
//@}
//! Build level filename
//@{
static std::string BuildScenePath(LevelCategory category, int chapter, int rank, bool sceneFile = true);
static std::string BuildScenePath(std::string category, int chapter, int rank, bool sceneFile = true);
//@}
//! Check if level file exists
bool Exists();

View File

@ -0,0 +1,50 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "object/level_category.h"
#include <map>
const std::map<LevelCategory, std::string> category_dir_map = {
{ LevelCategory::Missions, "missions" },
{ LevelCategory::FreeGame, "freemissions" },
{ LevelCategory::Exercises, "exercises" },
{ LevelCategory::Challenges, "challenges" },
{ LevelCategory::CustomLevels, "custom" },
{ LevelCategory::Win, "win" },
{ LevelCategory::Lost, "lost" },
{ LevelCategory::Perso, "perso" },
};
std::string GetLevelCategoryDir(LevelCategory category)
{
return category_dir_map.at(category);
}
LevelCategory GetLevelCategoryFromDir(std::string dir)
{
for(auto it = category_dir_map.begin(); it != category_dir_map.end(); ++it)
{
if(it->second == dir)
{
return it->first;
}
}
return LevelCategory::Max;
}

View File

@ -0,0 +1,39 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include <string>
enum class LevelCategory
{
Exercises = 0,
Challenges = 1,
Missions = 2,
FreeGame = 3,
CustomLevels = 4,
Max,
// These are custom types not runnable by the user
Win,
Lost,
Perso,
};
std::string GetLevelCategoryDir(LevelCategory category);
LevelCategory GetLevelCategoryFromDir(std::string dir);

View File

@ -442,7 +442,7 @@ void CRobotMain::ChangePhase(Phase phase)
if (m_gameTime > 10.0f) // did you play at least 10 seconds?
{
int rank = m_dialog->GetSceneRank();
int rank = m_dialog->GetLevelRank();
int numTry = m_dialog->GetGamerInfoTry(rank);
m_dialog->SetGamerInfoTry(rank, numTry+1);
m_dialog->WriteGamerInfo();
@ -451,7 +451,7 @@ void CRobotMain::ChangePhase(Phase phase)
if (phase == PHASE_WIN) // wins a simulation?
{
int rank = m_dialog->GetSceneRank();
int rank = m_dialog->GetLevelRank();
m_dialog->SetGamerInfoPassed(rank, true);
m_dialog->NextMission(); // passes to the next mission
m_dialog->WriteGamerInfo();
@ -591,9 +591,8 @@ void CRobotMain::ChangePhase(Phase phase)
else
{
m_winTerminate = (m_endingWinRank == 904);
m_dialog->SetSceneName("win");
m_dialog->SetSceneRank(m_endingWinRank);
m_dialog->SetLevelCategory(LevelCategory::Win);
m_dialog->SetLevelRank(m_endingWinRank);
try
{
CreateScene(false, true, false); // sets scene
@ -639,8 +638,8 @@ void CRobotMain::ChangePhase(Phase phase)
else
{
m_winTerminate = false;
m_dialog->SetSceneName("lost");
m_dialog->SetSceneRank(m_endingLostRank);
m_dialog->SetLevelCategory(LevelCategory::Lost);
m_dialog->SetLevelRank(m_endingLostRank);
try
{
CreateScene(false, true, false); // sets scene
@ -2578,8 +2577,10 @@ bool CRobotMain::EventFrame(const Event &event)
if (m_pause->GetPause() == PAUSE_NONE && m_autosave && m_gameTimeAbsolute >= m_autosaveLast+(m_autosaveInterval*60) && m_phase == PHASE_SIMUL)
{
std::string base = m_dialog->GetSceneName();
if (base == "missions" || base == "freemissions" || base == "custom")
LevelCategory cat = m_dialog->GetLevelCategory();
if (cat == LevelCategory::Missions ||
cat == LevelCategory::FreeGame ||
cat == LevelCategory::CustomLevels )
{
m_autosaveLast = m_gameTimeAbsolute;
Autosave();
@ -2830,8 +2831,8 @@ void CRobotMain::ScenePerso()
ChangeColor();
m_dialog->SetSceneName("perso");
m_dialog->SetSceneRank(0);
m_dialog->SetLevelCategory(LevelCategory::Perso);
m_dialog->SetLevelRank(0);
try
{
CreateScene(false, true, false); // sets scene
@ -2858,8 +2859,8 @@ void CRobotMain::ScenePerso()
//! Creates the whole scene
void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
{
char* base = m_dialog->GetSceneName();
int rank = m_dialog->GetSceneRank();
LevelCategory category = m_dialog->GetLevelCategory();
int rank = m_dialog->GetLevelRank();
const char* read = m_dialog->GetSceneRead().c_str();
const char* stack = m_dialog->GetStackRead().c_str();
@ -2937,8 +2938,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
m_engine->SetSecondTexture("");
m_engine->SetForegroundName("");
m_dialog->BuildResumeName(m_title, base, rank);
m_dialog->BuildResumeName(m_resume, base, rank);
m_dialog->BuildResumeName(m_title, GetLevelCategoryDir(category), rank);
m_dialog->BuildResumeName(m_resume, GetLevelCategoryDir(category), rank);
std::string scriptNameStr;
GetResource(RES_TEXT, RT_SCRIPT_NEW, scriptNameStr);
strcpy(m_scriptName, scriptNameStr.c_str());
@ -2960,7 +2961,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
try
{
CLevelParser levelParser(base, rank/100, rank%100);
CLevelParser levelParser(category, rank/100, rank%100);
levelParser.Load();
int rankObj = 0;
@ -3896,10 +3897,10 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (read[0] == 0)
CompileScript(soluce); // compiles all scripts
if (strcmp(base, "missions") == 0 && !resetObject) // mission?
if (category == LevelCategory::Missions && !resetObject) // mission?
WriteFreeParam();
if (strcmp(base, "freemissions") == 0 && !resetObject) // free play?
if (category == LevelCategory::FreeGame && !resetObject) // free play?
{
m_researchDone[0] = m_freeResearch;
@ -4602,8 +4603,8 @@ void CRobotMain::LoadOneScript(CObject *obj, int &nbError)
int objRank = obj->GetDefRank();
if (objRank == -1) return;
char* name = m_dialog->GetSceneName();
int rank = m_dialog->GetSceneRank();
char categoryChar = GetLevelCategoryDir(m_dialog->GetLevelCategory())[0];
int rank = m_dialog->GetLevelRank();
for (unsigned int i = 0; i <= 999; i++)
{
@ -4611,7 +4612,7 @@ void CRobotMain::LoadOneScript(CObject *obj, int &nbError)
char filename[MAX_FNAME];
sprintf(filename, "%s/%s/%c%.3d%.3d%.3d.txt",
GetSavegameDir(), m_gamerName.c_str(), name[0], rank, objRank, i);
GetSavegameDir(), m_gamerName.c_str(), categoryChar, rank, objRank, i);
if (CResourceManager::Exists(filename))
{
@ -4676,8 +4677,8 @@ void CRobotMain::SaveOneScript(CObject *obj)
int objRank = obj->GetDefRank();
if (objRank == -1) return;
char* name = m_dialog->GetSceneName();
int rank = m_dialog->GetSceneRank();
char categoryChar = GetLevelCategoryDir(m_dialog->GetLevelCategory())[0];
int rank = m_dialog->GetLevelRank();
auto& programs = brain->GetPrograms();
// TODO: Find a better way to do that
@ -4685,7 +4686,7 @@ void CRobotMain::SaveOneScript(CObject *obj)
{
char filename[MAX_FNAME];
sprintf(filename, "%s/%s/%c%.3d%.3d%.3d.txt",
GetSavegameDir(), m_gamerName.c_str(), name[0], rank, objRank, i);
GetSavegameDir(), m_gamerName.c_str(), categoryChar, rank, objRank, i);
if (i < programs.size())
{
brain->WriteProgram(programs[i].get(), filename);
@ -5741,14 +5742,14 @@ float CRobotMain::GetPersoAngle()
return m_dialog->GetPersoAngle();
}
char* CRobotMain::GetSceneName()
LevelCategory CRobotMain::GetLevelCategory()
{
return m_dialog->GetSceneName();
return m_dialog->GetLevelCategory();
}
int CRobotMain::GetSceneRank()
int CRobotMain::GetLevelRank()
{
return m_dialog->GetSceneRank();
return m_dialog->GetLevelRank();
}
@ -5968,9 +5969,9 @@ void CRobotMain::DisplayError(Error err, Math::Vector goal, float height, float
m_displayText->DisplayError(err, goal, height, dist, time);
}
std::string& CRobotMain::GetUserLevelName(int id)
std::string& CRobotMain::GetCustomLevelName(int id)
{
return m_dialog->GetUserLevelName(id);
return m_dialog->GetCustomLevelName(id);
}
void CRobotMain::StartMissionTimer()

View File

@ -30,6 +30,7 @@
#include "graphics/engine/particle.h"
#include "object/level_category.h"
#include "object/object_type.h"
#include "object/drive_type.h"
#include "object/tool_type.h"
@ -263,8 +264,8 @@ public:
int GetGamerGlasses();
bool GetGamerOnlyHead();
float GetPersoAngle();
char* GetSceneName();
int GetSceneRank();
LevelCategory GetLevelCategory();
int GetLevelRank();
void StartMusic();
void StartPauseMusic(PauseType pause);
@ -312,7 +313,7 @@ public:
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);
std::string& GetUserLevelName(int id);
std::string& GetCustomLevelName(int id);
void StartMissionTimer();

View File

@ -130,7 +130,6 @@ CMainDialog::CMainDialog()
m_phaseTerm = PHASE_TRAINER;
m_sceneRead[0] = 0;
m_stackRead[0] = 0;
m_sceneName[0] = 0;
m_sceneRank = 0;
m_bSceneSoluce = false;
m_bSimulSetup = false;
@ -141,12 +140,13 @@ CMainDialog::CMainDialog()
m_bDeleteGamer = true;
for (int i = 0; i < 10; i++)
for(int i = 0; i < static_cast<int>(LevelCategory::Max); i++)
{
m_chap[i] = 0;
m_sel[i] = 0;
m_chap[static_cast<LevelCategory>(i)] = 0;
m_sel[static_cast<LevelCategory>(i)] = 0;
}
m_index = 0;
m_category = LevelCategory::Exercises;
m_maxList = 0;
memset(&m_perso, 0, sizeof(GamerPerso));
@ -731,24 +731,22 @@ void CMainDialog::ChangePhase(Phase phase)
m_phase == PHASE_FREE ||
m_phase == PHASE_USER )
{
if ( m_phase == PHASE_TRAINER ) m_index = 0;
if ( m_phase == PHASE_DEFI ) m_index = 1;
if ( m_phase == PHASE_MISSION ) m_index = 2;
if ( m_phase == PHASE_FREE ) m_index = 3;
if ( m_phase == PHASE_USER ) m_index = 4;
if ( m_phase == PHASE_TRAINER ) m_category = LevelCategory::Exercises;
if ( m_phase == PHASE_DEFI ) m_category = LevelCategory::Challenges;
if ( m_phase == PHASE_MISSION ) m_category = LevelCategory::Missions;
if ( m_phase == PHASE_FREE ) m_category = LevelCategory::FreeGame;
if ( m_phase == PHASE_USER ) m_category = LevelCategory::CustomLevels;
if ( m_phase == PHASE_FREE )
{
strcpy(m_sceneName, "missions");
LevelCategory temp = m_category;
m_category = LevelCategory::Missions;
ReadGamerInfo();
m_accessChap = GetChapPassed();
}
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, "custom");
m_category = temp;
}
ReadGamerInfo();
@ -796,7 +794,7 @@ void CMainDialog::ChangePhase(Phase phase)
ddim.x = dim.x*6.5f;
pli = pw->CreateList(pos, ddim, 0, EVENT_INTERFACE_CHAP);
pli->SetState(STATE_SHADOW);
UpdateSceneChap(m_chap[m_index]);
UpdateSceneChap(m_chap[m_category]);
if ( m_phase != PHASE_USER ) pli->SetState(STATE_EXTEND);
// Displays a list of missions:
@ -818,7 +816,7 @@ void CMainDialog::ChangePhase(Phase phase)
ddim.x = dim.x*6.5f;
pli = pw->CreateList(pos, ddim, 0, EVENT_INTERFACE_LIST);
pli->SetState(STATE_SHADOW);
UpdateSceneList(m_chap[m_index], m_sel[m_index]);
UpdateSceneList(m_chap[m_category], m_sel[m_category]);
if ( m_phase != PHASE_USER ) pli->SetState(STATE_EXTEND);
pos = pli->GetPos();
ddim = pli->GetDim();
@ -856,7 +854,7 @@ void CMainDialog::ChangePhase(Phase phase)
}
m_bSceneSoluce = false;
UpdateSceneResume((m_chap[m_index]+1)*100+(m_sel[m_index]+1));
UpdateSceneResume((m_chap[m_category]+1)*100+(m_sel[m_category]+1));
if ( m_phase == PHASE_MISSION ||
m_phase == PHASE_FREE ||
@ -2245,16 +2243,16 @@ bool CMainDialog::EventProcess(const Event &event)
case EVENT_INTERFACE_CHAP:
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_CHAP));
if ( pl == 0 ) break;
m_chap[m_index] = pl->GetSelect();
UpdateSceneList(m_chap[m_index], m_sel[m_index]);
UpdateSceneResume((m_chap[m_index]+1)*100+(m_sel[m_index]+1));
m_chap[m_category] = pl->GetSelect();
UpdateSceneList(m_chap[m_category], m_sel[m_category]);
UpdateSceneResume((m_chap[m_category]+1)*100+(m_sel[m_category]+1));
break;
case EVENT_INTERFACE_LIST:
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_LIST));
if ( pl == 0 ) break;
m_sel[m_index] = pl->GetSelect();
UpdateSceneResume((m_chap[m_index]+1)*100+(m_sel[m_index]+1));
m_sel[m_category] = pl->GetSelect();
UpdateSceneResume((m_chap[m_category]+1)*100+(m_sel[m_category]+1));
break;
case EVENT_INTERFACE_SOLUCE:
@ -2265,7 +2263,7 @@ bool CMainDialog::EventProcess(const Event &event)
break;
case EVENT_INTERFACE_PLAY:
m_sceneRank = (m_chap[m_index]+1)*100+(m_sel[m_index]+1);
m_sceneRank = (m_chap[m_category]+1)*100+(m_sel[m_category]+1);
m_phaseTerm = m_phase;
m_main->ChangePhase(PHASE_LOADING);
break;
@ -3353,22 +3351,11 @@ void CMainDialog::NiceParticle(Math::Point mouse, bool bPress)
// Builds the file name of a mission.
void CMainDialog::BuildScenePath(std::string &filename, char *base, int rank, bool sceneFile)
{
//TODO: Support for more than 9 chapters
int chapter = rank/100;
int new_rank = rank%100;
filename = CLevelParser::BuildScenePath(std::string(base), chapter, new_rank, sceneFile);
}
// Built the default descriptive name of a mission.
void CMainDialog::BuildResumeName(char *filename, char *base, int rank)
void CMainDialog::BuildResumeName(char *filename, std::string base, int rank)
{
sprintf(filename, "Scene %s %d", base, rank);
sprintf(filename, "Scene %s %d", base.c_str(), rank);
}
// Returns the name of the file or save the files.
@ -3993,9 +3980,9 @@ void CMainDialog::IOReadName()
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_IONAME));
if ( pe == nullptr ) return;
resume = std::string(m_sceneName) + " " + boost::lexical_cast<std::string>(m_chap[m_index]+1);
resume = std::string(GetLevelCategoryDir(m_category)) + " " + boost::lexical_cast<std::string>(m_chap[m_category]+1);
CLevelParser levelParser(m_sceneName, m_chap[m_index]+1, 0);
CLevelParser levelParser(m_category, m_chap[m_category]+1, 0);
try
{
levelParser.Load();
@ -4008,7 +3995,7 @@ void CMainDialog::IOReadName()
time(&now);
TimeToAsciiClean(now, line);
sprintf(name, "%s - %s %d", line, resume.c_str(), m_sel[m_index]+1);
sprintf(name, "%s - %s %d", line, resume.c_str(), m_sel[m_category]+1);
pe->SetText(name);
pe->SetCursor(strlen(name), 0);
@ -4246,10 +4233,10 @@ bool CMainDialog::IOReadScene()
levelParser.Load();
CLevelParserLine* line = levelParser.Get("Mission");
strcpy(m_sceneName, line->GetParam("base")->AsString().c_str());
m_category = GetLevelCategoryFromDir(line->GetParam("base")->AsString());
m_sceneRank = line->GetParam("rank")->AsInt();
if (std::string(m_sceneName) == "custom")
if (m_category == LevelCategory::CustomLevels)
{
m_sceneRank = m_sceneRank%100;
@ -4268,8 +4255,8 @@ bool CMainDialog::IOReadScene()
}
}
m_chap[m_index] = (m_sceneRank / 100)-1;
m_sel[m_index] = (m_sceneRank % 100)-1;
m_chap[m_category] = (m_sceneRank / 100)-1;
m_sel[m_category] = (m_sceneRank % 100)-1;
m_sceneRead = fileName;
m_stackRead = fileCbot;
@ -4305,8 +4292,8 @@ void CMainDialog::AllMissionUpdate()
m_phase == PHASE_FREE ||
m_phase == PHASE_USER )
{
UpdateSceneChap(m_chap[m_index]);
UpdateSceneList(m_chap[m_index], m_sel[m_index]);
UpdateSceneChap(m_chap[m_category]);
UpdateSceneList(m_chap[m_category], m_sel[m_category]);
}
}
@ -4359,7 +4346,7 @@ void CMainDialog::UpdateSceneChap(int &chap)
{
for ( j=0 ; j<9 ; j++ )
{
CLevelParser levelParser(m_sceneName, j+1, 0);
CLevelParser levelParser(m_category, j+1, 0);
if (!levelParser.Exists())
break;
try
@ -4422,7 +4409,7 @@ void CMainDialog::UpdateSceneList(int chap, int &sel)
bool readAll = true;
for ( j=0 ; j<99 ; j++ )
{
CLevelParser levelParser(m_sceneName, chap+1, j+1);
CLevelParser levelParser(m_category, chap+1, j+1);
if (!levelParser.Exists())
{
readAll = true;
@ -4546,7 +4533,7 @@ void CMainDialog::UpdateSceneResume(int rank)
try
{
CLevelParser levelParser(m_sceneName, rank/100, rank%100);
CLevelParser levelParser(m_category, rank/100, rank%100);
levelParser.Load();
pe->SetText(levelParser.Get("Resume")->GetParam("text")->AsString().c_str());
}
@ -5469,9 +5456,9 @@ void CMainDialog::StartAbort()
GetResource(RES_TEXT, RT_DIALOG_NO, name);
pb->SetName(name);
if ( m_index == 2 || // missions ?
m_index == 3 || // free games?
m_index == 4 ) // user ?
if ( m_category == LevelCategory::Missions || // missions ?
m_category == LevelCategory::FreeGame || // free games?
m_category == LevelCategory::CustomLevels ) // user ?
{
pos.y = 0.62f;
pb = pw->CreateButton(pos, dim, -1, EVENT_INTERFACE_WRITE);
@ -5913,35 +5900,35 @@ std::string & CMainDialog::GetStackRead()
// Specifies the name of the chosen to play scene.
void CMainDialog::SetSceneName(const char* name)
void CMainDialog::SetLevelCategory(LevelCategory category)
{
strcpy(m_sceneName, name);
m_category = category;
}
// Returns the name of the chosen to play scene.
char* CMainDialog::GetSceneName()
LevelCategory CMainDialog::GetLevelCategory()
{
return m_sceneName;
return m_category;
}
// Specifies the rank of the chosen to play scene.
void CMainDialog::SetSceneRank(int rank)
void CMainDialog::SetLevelRank(int rank)
{
m_sceneRank = rank;
}
// Returns the rank of the chosen to play scene.
int CMainDialog::GetSceneRank()
int CMainDialog::GetLevelRank()
{
return m_sceneRank;
}
// Returns folder name of the scene that user selected to play.
const char* CMainDialog::GetSceneDir()
const char* CMainDialog::GetCustomLevelDir()
{
int i;
@ -6136,11 +6123,11 @@ bool CMainDialog::ReadGamerInfo()
m_sceneInfo[i].bPassed = false;
}
if (!CResourceManager::Exists(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam"))
if (!CResourceManager::Exists(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+GetLevelCategoryDir(m_category)+".gam"))
return false;
CInputStream file;
file.open(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam");
file.open(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+GetLevelCategoryDir(m_category)+".gam");
if (!file.is_open())
{
GetLogger()->Error("Unable to read list of finished missions\n");
@ -6149,8 +6136,8 @@ bool CMainDialog::ReadGamerInfo()
std::getline(file, line);
sscanf(line.c_str(), "CurrentChapter=%d CurrentSel=%d\n", &chap, &i);
m_chap[m_index] = chap-1;
m_sel[m_index] = i-1;
m_chap[m_category] = chap-1;
m_sel[m_category] = i-1;
while (!file.eof())
{
@ -6183,14 +6170,14 @@ bool CMainDialog::WriteGamerInfo()
int i;
COutputStream file;
file.open(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+m_sceneName+".gam");
file.open(GetSavegameDir()+"/"+m_main->GetGamerName()+"/"+GetLevelCategoryDir(m_category)+".gam");
if (!file.is_open())
{
GetLogger()->Error("Unable to read list of finished missions\n");
return false;
}
file << "CurrentChapter=" << m_chap[m_index]+1 << " CurrentSel=" << m_sel[m_index]+1 << "\n";
file << "CurrentChapter=" << m_chap[m_category]+1 << " CurrentSel=" << m_sel[m_category]+1 << "\n";
for ( i=0 ; i<MAXSCENE ; i++ )
{
@ -6248,22 +6235,21 @@ bool CMainDialog::GetGamerInfoPassed(int rank)
bool CMainDialog::NextMission()
{
m_sel[m_index] ++; // next mission
m_sel[m_category] ++; // next mission
if ( m_sel[m_index] >= m_maxList ) // last mission of the chapter?
if ( m_sel[m_category] >= m_maxList ) // last mission of the chapter?
{
m_chap[m_index] ++; // next chapter
m_sel[m_index] = 0; // first mission
m_chap[m_category] ++; // next chapter
m_sel[m_category] = 0; // first mission
}
return true;
}
std::string& CMainDialog::GetUserLevelName(int id)
std::string& CMainDialog::GetCustomLevelName(int id)
{
return m_userList[id-1];
}
} // namespace Ui

View File

@ -25,6 +25,7 @@
#include "graphics/core/color.h"
#include "graphics/engine/camera.h"
#include "object/level_category.h"
#include "object/robotmain.h"
#include "app/pausemanager.h"
@ -80,14 +81,16 @@ public:
void ChangePhase(Phase phase);
void SetSceneRead(const char* name);
void SetStackRead(const char* name);
void SetSceneName(const char* name);
void SetSceneRank(int rank);
std::string & GetSceneRead();
void SetStackRead(const char* name);
std::string & GetStackRead();
char* GetSceneName();
int GetSceneRank();
const char* GetSceneDir();
void SetLevelCategory(LevelCategory category);
LevelCategory GetLevelCategory();
void SetLevelRank(int rank);
int GetLevelRank();
const char* GetCustomLevelDir();
bool GetSceneSoluce();
std::string & GetSavegameDir();
std::string & GetPublicDir();
@ -99,8 +102,7 @@ public:
bool GetNiceReset();
bool GetHimselfDamage();
void BuildScenePath(std::string &filename, char *base, int rank, bool sceneFile = true);
void BuildResumeName(char *filename, char *base, int rank);
void BuildResumeName(char *filename, std::string base, int rank);
std::string & GetFilesDir();
void StartAbort();
@ -141,7 +143,7 @@ public:
void AllMissionUpdate();
void ShowSoluceUpdate();
std::string& GetUserLevelName(int id);
std::string& GetCustomLevelName(int id);
void MakeSaveScreenshot(const std::string& name);
@ -200,21 +202,20 @@ protected:
GamerPerso m_perso; // perso: description
GamerPerso m_persoCopy; // perso: copy for cancellation
int m_persoTab; // perso: tab selected
int m_persoTab; // perso: tab selected
float m_persoAngle; // perso: angle of presentation
std::string m_savegameDir; // savegame folder
std::string m_publicDir; // program folder
std::string m_filesDir; // case files
int m_index; // 0..4
int m_chap[10]; // selected chapter (0..8)
int m_sel[10]; // chosen mission (0..98)
LevelCategory m_category; // 0..4
std::map<LevelCategory, int> m_chap; // selected chapter (0..8)
std::map<LevelCategory, int> m_sel; // chosen mission (0..98)
int m_maxList;
int m_accessChap;
std::string m_sceneRead; // name of the scene to read
std::string m_stackRead; // name of the scene to read
char m_sceneName[20]; // name of the scene to play
int m_sceneRank; // rank of the scene to play
bool m_bSceneSoluce; // shows the solution
bool m_bSimulSetup; // adjustment during the game
@ -272,4 +273,3 @@ protected:
};
} // namespace Ui