From 926126d5adf457dbc5c92fd83c7231415ea22d04 Mon Sep 17 00:00:00 2001 From: erihel Date: Mon, 1 Apr 2013 18:24:12 +0200 Subject: * Changed loading of scene and player info (there's problem with locales using , as comma separator). Issue #137 * Changed way of saving files. Now it's not based on slot (from 000 to 999) but it uses save name as a base. * Changed way of displaying saved games. Listing directory instead of checking from 000 to 999. Issue #138 --- src/object/robotmain.cpp | 40 +++++++++++++++++++++++++++++++++------- src/object/robotmain.h | 6 ++++++ 2 files changed, 39 insertions(+), 7 deletions(-) (limited to 'src/object') diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 733bf6b..2c890a4 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -3873,12 +3873,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) int rankGadget = 0; CObject* sel = 0; - std::string oldLocale; - char *locale = setlocale(LC_NUMERIC, nullptr); - if (locale != nullptr) - oldLocale = locale; - - setlocale(LC_NUMERIC, "C"); + SetNumericLocale(); while (fgets(line, 500, file) != NULL) { @@ -4746,7 +4741,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_dialog->SetSceneRead(""); m_dialog->SetStackRead(""); - setlocale(LC_NUMERIC, oldLocale.c_str()); + RestoreNumericLocale(); } //! Creates an object of decoration mobile or stationary @@ -5953,6 +5948,8 @@ bool CRobotMain::IsBusy() void CRobotMain::IOWriteObject(FILE *file, CObject* obj, const char *cmd) { if (obj->GetType() == OBJECT_FIX) return; + + SetNumericLocale(); char line[3000]; char name[100]; @@ -6040,6 +6037,8 @@ void CRobotMain::IOWriteObject(FILE *file, CObject* obj, const char *cmd) strcat(line, "\n"); fputs(line, file); + + RestoreNumericLocale(); } //! Saves the current game @@ -6047,6 +6046,8 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char * { FILE* file = fopen(filename, "w"); if (file == NULL) return false; + + SetNumericLocale(); char line[500]; @@ -6109,6 +6110,8 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char * SaveFileScript(obj, filename, objRank++); } fclose(file); + + RestoreNumericLocale(); #if CBOT_STACK // Writes the file of stacks of execution. @@ -6154,6 +6157,8 @@ CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank) if (type == OBJECT_NULL) return nullptr; + SetNumericLocale(); + int trainer = OpInt(line, "trainer", 0); int toy = OpInt(line, "toy", 0); int option = OpInt(line, "option", 0); @@ -6219,6 +6224,8 @@ CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank) automat->Start(run); // starts the film } + RestoreNumericLocale(); + return obj; } @@ -6229,6 +6236,8 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) FILE* file = fopen(filename, "r"); if (file == NULL) return 0; + + SetNumericLocale(); CObject* fret = nullptr; CObject* power = nullptr; @@ -6351,6 +6360,8 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) } #endif + RestoreNumericLocale(); + return sel; } @@ -7047,3 +7058,18 @@ void CRobotMain::ClearInterface() HiliteClear(); // removes setting evidence m_tooltipName[0] = 0; // really removes the tooltip } + +void CRobotMain::SetNumericLocale() +{ + char *locale = setlocale(LC_NUMERIC, nullptr); + if (locale != nullptr) + m_oldLocale = locale; + + setlocale(LC_NUMERIC, "C"); +} + +void CRobotMain::RestoreNumericLocale() +{ + setlocale(LC_NUMERIC, m_oldLocale.c_str()); +} + \ No newline at end of file diff --git a/src/object/robotmain.h b/src/object/robotmain.h index fe5fbd5..fc62072 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -352,6 +352,9 @@ public: CObject* IOReadObject(char *line, const char* filename, int objRank); int CreateSpot(Math::Vector pos, Gfx::Color color); + + void SetNumericLocale(); + void RestoreNumericLocale(); protected: bool EventFrame(const Event &event); @@ -390,6 +393,7 @@ protected: void ExecuteCmd(char *cmd); bool TestGadgetQuantity(int rank); void UpdateSpeedLabel(); + protected: CApplication* m_app; @@ -540,5 +544,7 @@ protected: Gfx::Color m_colorRefWater; Gfx::Color m_colorNewWater; float m_colorShiftWater; + + std::string m_oldLocale; }; -- cgit v1.2.3-1-g7c22