summaryrefslogtreecommitdiffstats
path: root/src/ui/maindialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/maindialog.cpp')
-rw-r--r--src/ui/maindialog.cpp221
1 files changed, 134 insertions, 87 deletions
diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp
index 696c156..dfc2d52 100644
--- a/src/ui/maindialog.cpp
+++ b/src/ui/maindialog.cpp
@@ -174,8 +174,10 @@ CMainDialog::CMainDialog()
m_sceneDir = "levels";
+
+ // TODO: replace NDEBUG with something like BUILD_TYPE == "DEBUG"/"RELEASE"
#ifdef NDEBUG
- m_savegameDir = GetSystemUtils()->savegameDirectoryLocation();
+ m_savegameDir = GetSystemUtils()->GetSavegameDirectoryLocation();
#else
m_savegameDir = "savegame";
#endif
@@ -756,7 +758,8 @@ pb->SetState(STATE_SHADOW);
m_phase != PHASE_SETUPcs &&
m_phase != PHASE_SETUPss )
{
- if (!m_sound->IsPlayingMusic()) {
+ if (!m_sound->IsPlayingMusic())
+ {
m_sound->PlayMusic("Intro1.ogg", false);
}
}
@@ -1623,7 +1626,7 @@ pos.y -= 0.048f;
}
if ( m_phase == PHASE_READ ||
- m_phase == PHASE_READs )
+ m_phase == PHASE_READs )
{
pos.x = 0.10f;
pos.y = 0.10f;
@@ -2029,14 +2032,15 @@ bool CMainDialog::EventProcess(const Event &event)
m_phase != PHASE_SETUPcs &&
m_phase != PHASE_SETUPss )
{
- if (!m_sound->IsPlayingMusic()) {
+ if (!m_sound->IsPlayingMusic())
+ {
m_sound->PlayMusic("Intro2.ogg", true);
}
}
if ( m_phase == PHASE_WELCOME1 ||
- m_phase == PHASE_WELCOME2 ||
- m_phase == PHASE_WELCOME3 )
+ m_phase == PHASE_WELCOME2 ||
+ m_phase == PHASE_WELCOME3 )
{
float intensity;
int mode = Gfx::ENG_RSTATE_TCOLOR_WHITE;
@@ -2627,15 +2631,18 @@ bool CMainDialog::EventProcess(const Event &event)
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) break;
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_INTERFACE_FULL));
- if ( pc == 0 ) break;
-
- if ( pc->TestState(STATE_CHECK) ) {
- m_setupFull = false;
- pc->ClearState(STATE_CHECK);
- } else {
- m_setupFull = true;
- pc->SetState(STATE_CHECK);
- }
+ if ( pc == 0 ) break;
+
+ if ( pc->TestState(STATE_CHECK) )
+ {
+ m_setupFull = false;
+ pc->ClearState(STATE_CHECK);
+ }
+ else
+ {
+ m_setupFull = true;
+ pc->SetState(STATE_CHECK);
+ }
UpdateApply();
break;
@@ -2647,7 +2654,7 @@ bool CMainDialog::EventProcess(const Event &event)
if ( pb == 0 ) break;
pb->ClearState(STATE_PRESS);
pb->ClearState(STATE_HILIGHT);
- // TODO: uncomment when changing display is implemented
+ // TODO: uncomment when changing display is implemented
//ChangeDisplay();
UpdateApply();
break;
@@ -4297,16 +4304,19 @@ 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)) {
- for( fs::directory_iterator dir_iter(saveDir) ; dir_iter != end_iter ; ++dir_iter) {
- if ( fs::is_directory(dir_iter->status()) && fs::exists(dir_iter->path() / "data.sav") ) {
+ if (fs::exists(saveDir) && fs::is_directory(saveDir))
+ {
+ for( fs::directory_iterator dir_iter(saveDir) ; dir_iter != end_iter ; ++dir_iter)
+ {
+ if ( fs::is_directory(dir_iter->status()) && fs::exists(dir_iter->path() / "data.sav") )
+ {
return true;
}
}
}
-
+
return false;
}
@@ -4390,27 +4400,34 @@ void CMainDialog::IOReadList()
if ( pl == 0 ) return;
pl->Flush();
-
+
fs::path saveDir(m_savegameDir + "/" + m_main->GetGamerName());
m_saveList.clear();
-
- if (fs::exists(saveDir) && fs::is_directory(saveDir)) {
- for( fs::directory_iterator dir_iter(saveDir) ; dir_iter != end_iter ; ++dir_iter) {
- if ( fs::is_directory(dir_iter->status()) && fs::exists(dir_iter->path() / "data.sav") ) {
-
+
+ if (fs::exists(saveDir) && fs::is_directory(saveDir))
+ {
+ for( fs::directory_iterator dir_iter(saveDir) ; dir_iter != end_iter ; ++dir_iter)
+ {
+ if ( fs::is_directory(dir_iter->status()) && fs::exists(dir_iter->path() / "data.sav") )
+ {
+
file = fopen((dir_iter->path() / "data.sav").make_preferred().string().c_str(), "r");
if ( file == NULL ) continue;
- while ( fgets(line, 500, file) != NULL ) {
- for ( i=0 ; i<500 ; i++ ) {
+ 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] == '/' ) {
+ if ( line[i] == '/' && line[i+1] == '/' )
+ {
line[i] = 0;
break;
}
}
- if ( Cmd(line, "Title") ) {
+ if ( Cmd(line, "Title") )
+ {
OpString(line, "text", name);
break;
}
@@ -4422,9 +4439,10 @@ void CMainDialog::IOReadList()
}
}
}
-
- // zly indeks
- if ( m_phase == PHASE_WRITE || m_phase == PHASE_WRITEs ) {
+
+ // invalid index
+ if ( m_phase == PHASE_WRITE || m_phase == PHASE_WRITEs )
+ {
GetResource(RES_TEXT, RT_IO_NEW, name);
pl->SetItemName(m_saveList.size(), name);
}
@@ -4453,22 +4471,24 @@ void CMainDialog::IOUpdateList()
sel = pl->GetSelect();
max = pl->GetTotal();
- if (m_saveList.size() <= static_cast<unsigned int>(sel)) {
+ if (m_saveList.size() <= static_cast<unsigned int>(sel))
return;
- }
-
+
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 ) {
+ if ( sel < max-1 )
+ {
pi->SetFilenameImage(filename.c_str());
}
- else {
+ else
+ {
pi->SetFilenameImage("");
}
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_IODELETE));
- if ( pb != nullptr ) {
+ if ( pb != nullptr )
+ {
pb->SetState(STATE_ENABLE, sel < max-1);
}
}
@@ -4500,11 +4520,13 @@ void CMainDialog::IODeleteScene()
try
{
- if (fs::exists(m_saveList.at(sel)) && fs::is_directory(m_saveList.at(sel))) {
+ 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) {
+ catch (std::exception & e)
+ {
GetLogger()->Error("Error removing save %s : %s\n", pl->GetItemName(sel), e.what());
}
@@ -4516,8 +4538,10 @@ std::string clearName(char *name)
{
std::string ret;
int len = strlen(name);
- for (int i = 0; i < len; i++) {
- if (isalnum(name[i])) {
+ for (int i = 0; i < len; i++)
+ {
+ if (isalnum(name[i]))
+ {
ret += name[i];
}
}
@@ -4542,19 +4566,24 @@ bool CMainDialog::IOWriteScene()
if ( pe == nullptr ) return false;
sel = pl->GetSelect();
- if ( sel == -1 ) {
+ if ( sel == -1 )
+ {
return false;
}
-
+
fs::path dir;
pe->GetText(info, 100);
- if (static_cast<unsigned int>(sel) >= m_saveList.size()) {
+ if (static_cast<unsigned int>(sel) >= m_saveList.size())
+ {
dir = fs::path(m_savegameDir) / m_main->GetGamerName() / ("save" + clearName(info));
- } else {
+ }
+ else
+ {
dir = m_saveList.at(sel);
- }
-
- if (!fs::exists(dir)) {
+ }
+
+ if (!fs::exists(dir))
+ {
fs::create_directories(dir);
}
@@ -4585,7 +4614,8 @@ bool CMainDialog::IOReadScene()
if ( pl == nullptr ) return false;
sel = pl->GetSelect();
- if ( sel == -1 || m_saveList.size() <= static_cast<unsigned int>(sel) ) {
+ if ( sel == -1 || m_saveList.size() <= static_cast<unsigned int>(sel) )
+ {
return false;
}
@@ -4593,33 +4623,42 @@ bool CMainDialog::IOReadScene()
std::string fileCbot = (m_saveList.at(sel) / "cbot.run").make_preferred().string();
file = fopen(fileName.c_str(), "r");
- if ( file == NULL ) {
+ if ( file == NULL )
+ {
return false;
}
- while ( fgets(line, 500, file) != NULL ) {
- for ( i=0 ; i<500 ; i++ ) {
+ 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] == '/' ) {
+ if ( line[i] == '/' && line[i+1] == '/' )
+ {
line[i] = 0;
break;
}
}
- if ( Cmd(line, "Mission") ) {
+ if ( Cmd(line, "Mission") )
+ {
OpString(line, "base", m_sceneName);
m_sceneRank = OpInt(line, "rank", 0);
- if ( strcmp(m_sceneName, "user") == 0 ) {
+ if ( strcmp(m_sceneName, "user") == 0 )
+ {
m_sceneRank = m_sceneRank%100;
OpString(line, "dir", dir);
- for ( i=0 ; i<m_userTotal ; i++ ) {
- if ( strcmp(m_userList[i].c_str(), dir) == 0 ) {
+ for ( i=0 ; i<m_userTotal ; i++ )
+ {
+ if ( strcmp(m_userList[i].c_str(), dir) == 0 )
+ {
m_sceneRank += (i+1)*100;
break;
}
}
- if ( m_sceneRank/100 == 0 ) {
+ if ( m_sceneRank/100 == 0 )
+ {
fclose(file);
return false;
}
@@ -5126,10 +5165,11 @@ void CMainDialog::UpdateDisplayMode()
m_app->GetVideoResolutionList(modes, true, true);
int i = 0;
std::stringstream mode_text;
- for (Math::IntPoint mode : modes) {
- mode_text.str("");
- mode_text << mode.x << "x" << mode.y;
- pl->SetItemName(i++, mode_text.str().c_str());
+ for (Math::IntPoint mode : modes)
+ {
+ mode_text.str("");
+ mode_text << mode.x << "x" << mode.y;
+ pl->SetItemName(i++, mode_text.str().c_str());
}
pl->SetSelect(m_setupSelMode);
@@ -5535,25 +5575,29 @@ void CMainDialog::SetupMemorize()
GetProfile().SetLocalProfileInt("Setup", "Sound3D", m_sound->GetSound3D());
GetProfile().SetLocalProfileInt("Setup", "EditIndentMode", m_engine->GetEditIndentMode());
GetProfile().SetLocalProfileInt("Setup", "EditIndentValue", m_engine->GetEditIndentValue());
-
+
/* screen setup */
if (m_setupFull)
- GetProfile().SetLocalProfileInt("Setup", "Fullscreen", 1);
+ GetProfile().SetLocalProfileInt("Setup", "Fullscreen", 1);
else
- GetProfile().SetLocalProfileInt("Setup", "Fullscreen", 0);
-
+ GetProfile().SetLocalProfileInt("Setup", "Fullscreen", 0);
+
CList *pl;
CWindow *pw;
pw = static_cast<CWindow *>(m_interface->SearchControl(EVENT_WINDOW5));
- if ( pw != 0 ) {
- pl = static_cast<CList *>(pw->SearchControl(EVENT_LIST2));
- if ( pl != 0 ) {
- GetProfile().SetLocalProfileInt("Setup", "Resolution", pl->GetSelect());
- }
- } else {
+ if ( pw != 0 )
+ {
+ pl = static_cast<CList *>(pw->SearchControl(EVENT_LIST2));
+ if ( pl != 0 )
+ {
+ GetProfile().SetLocalProfileInt("Setup", "Resolution", pl->GetSelect());
+ }
+ }
+ else
+ {
// TODO: Default value
}
-
+
std::stringstream key;
for (int i = 0; i < INPUT_SLOT_MAX; i++)
{
@@ -5765,7 +5809,7 @@ void CMainDialog::SetupRecall()
{
m_sound->SetMusicVolume(iValue);
}
-
+
if ( GetProfile().GetLocalProfileInt("Setup", "Sound3D", iValue) )
{
m_sound->SetSound3D(iValue == 1);
@@ -5813,13 +5857,15 @@ void CMainDialog::SetupRecall()
{
m_bDeleteGamer = iValue;
}
-
- if ( GetProfile().GetLocalProfileInt("Setup", "Resolution", iValue) ) {
- m_setupSelMode = iValue;
+
+ if ( GetProfile().GetLocalProfileInt("Setup", "Resolution", iValue) )
+ {
+ m_setupSelMode = iValue;
}
-
- if ( GetProfile().GetLocalProfileInt("Setup", "Fullscreen", iValue) ) {
- m_setupFull = (iValue == 1);
+
+ if ( GetProfile().GetLocalProfileInt("Setup", "Fullscreen", iValue) )
+ {
+ m_setupFull = (iValue == 1);
}
}
@@ -6584,7 +6630,7 @@ void CMainDialog::WriteGamerPerso(char *gamer)
if ( file == NULL ) return;
m_main->SetNumericLocale();
-
+
sprintf(line, "Head face=%d glasses=%d hair=%.2f;%.2f;%.2f;%.2f\n",
m_perso.face, m_perso.glasses,
m_perso.colorHair.r, m_perso.colorHair.g, m_perso.colorHair.b, m_perso.colorHair.a);
@@ -6596,7 +6642,7 @@ void CMainDialog::WriteGamerPerso(char *gamer)
fputs(line, file);
fclose(file);
-
+
m_main->RestoreNumericLocale();
}
@@ -6615,7 +6661,7 @@ void CMainDialog::ReadGamerPerso(char *gamer)
sprintf(filename, "%s/%s/face.gam", m_savegameDir.c_str(), gamer);
file = fopen(filename, "r");
if ( file == NULL ) return;
-
+
m_main->SetNumericLocale();
while ( fgets(line, 100, file) != NULL )
@@ -6649,7 +6695,7 @@ void CMainDialog::ReadGamerPerso(char *gamer)
}
fclose(file);
-
+
m_main->RestoreNumericLocale();
}
@@ -6836,3 +6882,4 @@ bool CMainDialog::NextMission()
} // namespace Ui
+