From 6333d2d38e9801f67925cae194b07abcf8f1260e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 4 May 2013 11:56:03 +0200 Subject: Removed most of "No such node" messages --- src/app/app.cpp | 9 ++++++++- src/common/profile.cpp | 37 +++++++++++++++++++++---------------- src/common/profile.h | 5 +++++ src/object/robotmain.cpp | 48 +++++++++++++++++++++++++++++++----------------- src/object/robotmain.h | 2 +- src/ui/maindialog.cpp | 3 +++ 6 files changed, 69 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/app/app.cpp b/src/app/app.cpp index 79c00c9..616caf9 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -364,6 +364,8 @@ bool CApplication::Create() return false; } + GetProfile().SetLocalProfileString("Resources", "Data", m_dataPath); + SetLanguage(m_language); //Create the sound instance. @@ -377,6 +379,11 @@ bool CApplication::Create() m_sound->Create(true); // Cache sound files + if (defaultValues) { + GetProfile().SetLocalProfileString("Resources", "Sound", GetDataSubdirPath(DIR_SOUND)); + GetProfile().SetLocalProfileString("Resources", "Music", GetDataSubdirPath(DIR_MUSIC)); + } + if (GetProfile().GetLocalProfileString("Resources", "Sound", path)) { m_sound->CacheAll(path); } else { @@ -485,7 +492,7 @@ bool CApplication::Create() m_modelManager = new Gfx::CModelManager(m_engine); // Create the robot application. - m_robotMain = new CRobotMain(this); + m_robotMain = new CRobotMain(this, !defaultValues); if (defaultValues) m_robotMain->CreateIni(); diff --git a/src/common/profile.cpp b/src/common/profile.cpp index f165119..0bc40cf 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -39,21 +39,7 @@ CProfile::CProfile() : CProfile::~CProfile() { - if (m_profileNeedSave) - { - try - { - #ifdef NDEBUG - bp::ini_parser::write_ini(GetSystemUtils()->profileFileLocation(), m_propertyTree); - #else - bp::ini_parser::write_ini("colobot.ini", m_propertyTree); - #endif - } - catch (std::exception & e) - { - GetLogger()->Error("Error on storing profile: %s\n", e.what()); - } - } + SaveCurrentDirectory(); } @@ -75,7 +61,26 @@ bool CProfile::InitCurrentDirectory() return true; } - +bool CProfile::SaveCurrentDirectory() +{ + if (m_profileNeedSave) + { + try + { + #ifdef NDEBUG + bp::ini_parser::write_ini(GetSystemUtils()->profileFileLocation(), m_propertyTree); + #else + bp::ini_parser::write_ini("colobot.ini", m_propertyTree); + #endif + } + catch (std::exception & e) + { + GetLogger()->Error("Error on storing profile: %s\n", e.what()); + return false; + } + } + return true; +} bool CProfile::SetLocalProfileString(std::string section, std::string key, std::string value) { diff --git a/src/common/profile.h b/src/common/profile.h index 7f99d81..ba797e9 100644 --- a/src/common/profile.h +++ b/src/common/profile.h @@ -50,6 +50,11 @@ class CProfile : public CSingleton */ bool InitCurrentDirectory(); + /** Saves colobot.ini to current directory + * \return return true on success + */ + bool SaveCurrentDirectory(); + /** Sets string value in section under specified key * \param section * \param key diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 1ca9e82..d291397 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -606,7 +606,7 @@ bool rPoint(CBotVar* pThis, CBotVar* var, CBotVar* pResult, int& Exception) //! Constructor of robot application -CRobotMain::CRobotMain(CApplication* app) +CRobotMain::CRobotMain(CApplication* app, bool loadProfile) { m_app = app; @@ -709,22 +709,26 @@ CRobotMain::CRobotMain(CApplication* app) float fValue; int iValue; - if (GetProfile().GetLocalProfileFloat("Edit", "FontSize", fValue)) m_fontSize = fValue; - if (GetProfile().GetLocalProfileFloat("Edit", "WindowPosX", fValue)) m_windowPos.x = fValue; - if (GetProfile().GetLocalProfileFloat("Edit", "WindowPosY", fValue)) m_windowPos.y = fValue; - if (GetProfile().GetLocalProfileFloat("Edit", "WindowDimX", fValue)) m_windowDim.x = fValue; - if (GetProfile().GetLocalProfileFloat("Edit", "WindowDimY", fValue)) m_windowDim.y = fValue; + if (loadProfile) { + if (GetProfile().GetLocalProfileFloat("Edit", "FontSize", fValue)) m_fontSize = fValue; + if (GetProfile().GetLocalProfileFloat("Edit", "WindowPosX", fValue)) m_windowPos.x = fValue; + if (GetProfile().GetLocalProfileFloat("Edit", "WindowPosY", fValue)) m_windowPos.y = fValue; + if (GetProfile().GetLocalProfileFloat("Edit", "WindowDimX", fValue)) m_windowDim.x = fValue; + if (GetProfile().GetLocalProfileFloat("Edit", "WindowDimY", fValue)) m_windowDim.y = fValue; + } m_IOPublic = false; m_IODim = Math::Point(320.0f/640.0f, (121.0f+18.0f*8)/480.0f); m_IOPos.x = (1.0f-m_IODim.x)/2.0f; // in the middle m_IOPos.y = (1.0f-m_IODim.y)/2.0f; - if (GetProfile().GetLocalProfileInt ("Edit", "IOPublic", iValue)) m_IOPublic = iValue; - if (GetProfile().GetLocalProfileFloat("Edit", "IOPosX", fValue)) m_IOPos.x = fValue; - if (GetProfile().GetLocalProfileFloat("Edit", "IOPosY", fValue)) m_IOPos.y = fValue; - if (GetProfile().GetLocalProfileFloat("Edit", "IODimX", fValue)) m_IODim.x = fValue; - if (GetProfile().GetLocalProfileFloat("Edit", "IODimY", fValue)) m_IODim.y = fValue; + if (loadProfile) { + if (GetProfile().GetLocalProfileInt ("Edit", "IOPublic", iValue)) m_IOPublic = iValue; + if (GetProfile().GetLocalProfileFloat("Edit", "IOPosX", fValue)) m_IOPos.x = fValue; + if (GetProfile().GetLocalProfileFloat("Edit", "IOPosY", fValue)) m_IOPos.y = fValue; + if (GetProfile().GetLocalProfileFloat("Edit", "IODimX", fValue)) m_IODim.x = fValue; + if (GetProfile().GetLocalProfileFloat("Edit", "IODimY", fValue)) m_IODim.y = fValue; + } m_short->FlushShortcuts(); InitEye(); @@ -741,10 +745,10 @@ CRobotMain::CRobotMain(CApplication* app) g_unit = UNIT; m_gamerName = ""; - GetProfile().GetLocalProfileString("Gamer", "LastName", m_gamerName); + if (loadProfile) GetProfile().GetLocalProfileString("Gamer", "LastName", m_gamerName); SetGlobalGamerName(m_gamerName); ReadFreeParam(); - m_dialog->SetupRecall(); + if (loadProfile) m_dialog->SetupRecall(); for (int i = 0; i < MAXSHOWLIMIT; i++) { @@ -904,10 +908,20 @@ Ui::CDisplayText* CRobotMain::GetDisplayText() //! Creates the file colobot.ini at the first time void CRobotMain::CreateIni() { - int iValue; - // colobot.ini doesn't exist? - if (!GetProfile().GetLocalProfileInt("Setup", "TotoMode", iValue)) - m_dialog->SetupMemorize(); + m_dialog->SetupMemorize(); + + GetProfile().SetLocalProfileFloat("Edit", "FontSize", m_fontSize); + GetProfile().SetLocalProfileFloat("Edit", "WindowPosX", m_windowPos.x); + GetProfile().SetLocalProfileFloat("Edit", "WindowPosY", m_windowPos.y); + GetProfile().SetLocalProfileFloat("Edit", "WindowDimX", m_windowDim.x); + GetProfile().SetLocalProfileFloat("Edit", "WindowDimY", m_windowDim.y); + GetProfile().SetLocalProfileInt("Edit", "IOPublic", m_IOPublic); + GetProfile().SetLocalProfileFloat("Edit", "IOPosX", m_IOPos.x); + GetProfile().SetLocalProfileFloat("Edit", "IOPosY", m_IOPos.y); + GetProfile().SetLocalProfileFloat("Edit", "IODimX", m_IODim.x); + GetProfile().SetLocalProfileFloat("Edit", "IODimY", m_IODim.y); + + GetProfile().SaveCurrentDirectory(); } void CRobotMain::SetDefaultInputBindings() diff --git a/src/object/robotmain.h b/src/object/robotmain.h index adabf64..a459a59 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -191,7 +191,7 @@ const int AXIS_INVALID = -1; class CRobotMain : public CSingleton { public: - CRobotMain(CApplication* app); + CRobotMain(CApplication* app, bool loadProfile); ~CRobotMain(); Gfx::CCamera* GetCamera(); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 0b0b848..1b87a04 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -5509,6 +5509,7 @@ void CMainDialog::SetupMemorize() GetProfile().SetLocalProfileInt("Setup", "HimselfDamage", m_bHimselfDamage); GetProfile().SetLocalProfileInt("Setup", "CameraScroll", m_bCameraScroll); GetProfile().SetLocalProfileInt("Setup", "CameraInvertX", m_bCameraInvertX); + GetProfile().SetLocalProfileInt("Setup", "CameraInvertY", m_bCameraInvertY); GetProfile().SetLocalProfileInt("Setup", "InterfaceEffect", m_bEffect); GetProfile().SetLocalProfileInt("Setup", "GroundShadow", m_engine->GetShadow()); GetProfile().SetLocalProfileInt("Setup", "GroundSpot", m_engine->GetGroundSpot()); @@ -5544,6 +5545,8 @@ void CMainDialog::SetupMemorize() if ( pl != 0 ) { GetProfile().SetLocalProfileInt("Setup", "Resolution", pl->GetSelect()); } + } else { + // TODO: Default value } std::stringstream key; -- cgit v1.2.3-1-g7c22