diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/displayinfo.cpp | 2 | ||||
-rw-r--r-- | src/ui/edit.cpp | 136 | ||||
-rw-r--r-- | src/ui/edit.h | 29 | ||||
-rw-r--r-- | src/ui/maindialog.cpp | 25 | ||||
-rw-r--r-- | src/ui/maindialog.h | 6 | ||||
-rw-r--r-- | src/ui/studio.cpp | 36 | ||||
-rw-r--r-- | src/ui/studio.h | 5 |
7 files changed, 116 insertions, 123 deletions
diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 9a31956..5c41f65 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -671,7 +671,7 @@ void CDisplayInfo::ChangeIndexButton(int index) { filename = m_main->GetDisplayInfoName(m_index); edit->ReadText(filename); - edit->HyperHome(filename); + edit->HyperHome(std::string(filename)); SetPosition(m_main->GetDisplayInfoPosition(m_index)); } diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index c0b6446..a96d231 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -560,7 +560,7 @@ bool CEdit::IsLinkPos(Math::Point pos) if ( i == -1 ) return false; if ( i >= m_len ) return false; - if ( m_format.size() > i && ((m_format[i] & Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK)) return true; // TODO + if ( m_format.size() > static_cast<unsigned int>(i) && ((m_format[i] & Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK)) return true; // TODO return false; } @@ -760,7 +760,7 @@ void CEdit::HyperFlush() // Indicates which is the home page. -void CEdit::HyperHome(const char *filename) +void CEdit::HyperHome(std::string filename) { HyperFlush(); HyperAdd(filename, 0); @@ -768,10 +768,10 @@ void CEdit::HyperHome(const char *filename) // Performs a hyper jump through a link. -void CEdit::HyperJump(const char *name, const char *marker) +void CEdit::HyperJump(std::string name, std::string marker) { - char filename[100]; - char sMarker[100]; + std::string filename; + std:: string sMarker; int i, line, pos; if ( m_historyCurrent >= 0 ) @@ -779,18 +779,17 @@ void CEdit::HyperJump(const char *name, const char *marker) m_history[m_historyCurrent].firstLine = m_lineFirst; } - strcpy(sMarker, marker); + sMarker = marker; //? sprintf(filename, "help\\%s.txt", name); - if ( name[0] == '%' ) - { - UserDir(filename, name, ""); - strcat(filename, ".txt"); - } - else - { - sprintf(filename, "help\\%s.txt", name); + + if ( name[0] == '%' ) { + filename = GetProfile().GetUserBasedPath(name, "") + ".txt"; + } else { + std::string path = CApplication::GetInstancePointer()->GetDataDirPath() + "/help/" + name + ".txt"; + filename = fs::path(path).generic_string(); } + if ( ReadText(filename) ) { Justif(); @@ -798,7 +797,7 @@ void CEdit::HyperJump(const char *name, const char *marker) line = 0; for ( i=0 ; i<m_markerTotal ; i++ ) { - if ( strcmp(sMarker, m_marker[i].name) == 0 ) + if (sMarker == m_marker[i].name) { pos = m_marker[i].pos; for ( i=0 ; i<m_lineTotal ; i++ ) @@ -819,12 +818,12 @@ void CEdit::HyperJump(const char *name, const char *marker) // Adds text to the history of visited. -bool CEdit::HyperAdd(const char *filename, int firstLine) +bool CEdit::HyperAdd(std::string filename, int firstLine) { if ( m_historyCurrent >= EDITHISTORYMAX-1 ) return false; m_historyCurrent ++; - strcpy(m_history[m_historyCurrent].filename, filename); + m_history[m_historyCurrent].filename = filename; m_history[m_historyCurrent].firstLine = firstLine; m_historyTotal = m_historyCurrent+1; @@ -1136,16 +1135,14 @@ void CEdit::Draw() // Draw an image part. -void CEdit::DrawImage(Math::Point pos, const char *name, float width, +void CEdit::DrawImage(Math::Point pos, std::string name, float width, float offset, float height, int nbLine) { - Math::Point uv1, uv2, dim; - float dp; - char filename[100]; + Math::Point uv1, uv2, dim; + float dp; + std::string filename; -//? sprintf(filename, "diagram\\%s.png", name); - UserDir(filename, name, "diagram"); - strcat(filename, ".png"); + filename = GetProfile().GetUserBasedPath(name, "diagram") + ".png"; m_engine->SetTexture(filename); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); @@ -1389,77 +1386,64 @@ int CEdit::GetTextLength() // Returns a name in a command. // \x nom1 nom2 nom3; -void GetNameParam(const char *cmd, int rank, char *buffer) +std::string GetNameParam(std::string cmd, int rank) { - int i; - - for ( i=0 ; i<rank ; i++ ) - { - while ( *cmd != ' ' && *cmd != ';' ) - { - cmd ++; - } - if ( *cmd != ';' ) cmd ++; + std::vector<std::string> results; + boost::split(results, cmd, boost::is_any_of(" ;")); + + if (results.size() > static_cast<unsigned int>(rank)) { + return results.at(rank); } - while ( *cmd != ' ' && *cmd != ';' ) - { - *buffer++ = *cmd++; - } - *buffer = 0; + return ""; } // Returns a number of a command. // \x nom n1 n2; -int GetValueParam(const char *cmd, int rank) +int GetValueParam(std::string cmd, int rank) { - int n, i; - - for ( i=0 ; i<rank ; i++ ) - { - while ( *cmd != ' ' && *cmd != ';' ) - { - cmd ++; + std::vector<std::string> results; + boost::split(results, cmd, boost::is_any_of(" ;")); + int return_value = 0; + + if (results.size() > static_cast<unsigned int>(rank)) { + try { + return_value = std::stoi(results.at(rank)); + } catch (std::invalid_argument &e) { + GetLogger()->Error("Exception std::invalid_argument caught in GetValueParam function"); + } catch (std::out_of_range &e) { + GetLogger()->Error("Exception std::out_of_range caught in GetValueParam function"); } - if ( *cmd != ';' ) cmd ++; } - sscanf(cmd, "%d", &n); - return n; + return return_value; } // Frees all images. void CEdit::FreeImage() { - char filename[100]; - int i; + std::string filename; - for ( i=0 ; i<m_imageTotal ; i++ ) - { -//? sprintf(filename, "diagram\\%s.png", m_image[i].name); - UserDir(filename, m_image[i].name, "diagram"); - strcat(filename, ".png"); + for (int i = 0 ; i < m_imageTotal; i++ ) { + filename = GetProfile().GetUserBasedPath(m_image[i].name, "diagram") + ".png"; m_engine->DeleteTexture(filename); } } // Reads the texture of an image. -void CEdit::LoadImage(const char *name) +void CEdit::LoadImage(std::string name) { - char filename[100]; - -//? sprintf(filename, "diagram\\%s.png", name); - UserDir(filename, name, "diagram"); - strcat(filename, ".png"); + std::string filename; + filename = GetProfile().GetUserBasedPath(name, "diagram") + ".png"; m_engine->LoadTexture(filename); } // Read from a text file. -bool CEdit::ReadText(const char *filename, int addSize) +bool CEdit::ReadText(std::string filename, int addSize) { FILE *file = NULL; char *buffer; @@ -1471,7 +1455,7 @@ bool CEdit::ReadText(const char *filename, int addSize) bool bInSoluce, bBOL; if ( filename[0] == 0 ) return false; - file = fopen(filename, "rb"); + file = fopen(filename.c_str(), "rb"); if ( file == NULL ) return false; fseek(file, 0, SEEK_END); @@ -1605,8 +1589,8 @@ bool CEdit::ReadText(const char *filename, int addSize) { if ( iLink < EDITLINKMAX ) { - GetNameParam(buffer+i+3, 0, m_link[iLink].name); - GetNameParam(buffer+i+3, 1, m_link[iLink].marker); + m_link[iLink].name = GetNameParam(buffer+i+3, 0); + m_link[iLink].marker = GetNameParam(buffer+i+3, 1); iLink ++; } font &= ~Gfx::FONT_MASK_HIGHLIGHT; @@ -1622,7 +1606,7 @@ bool CEdit::ReadText(const char *filename, int addSize) { if ( m_markerTotal < EDITLINKMAX ) { - GetNameParam(buffer+i+3, 0, m_marker[m_markerTotal].name); + m_marker[m_markerTotal].name = GetNameParam(buffer+i+3, 0); m_marker[m_markerTotal].pos = j; m_markerTotal ++; } @@ -1640,21 +1624,19 @@ bool CEdit::ReadText(const char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { -#if _DEMO - strcpy(iName, "demo"); -#else - GetNameParam(buffer+i+7, 0, iName); -#endif + + strcpy(iName, GetNameParam(buffer+i+7, 0).c_str()); + //? iWidth = m_lineHeight*RetValueParam(buffer+i+7, 1); iWidth = static_cast<float>(GetValueParam(buffer+i+7, 1)); iWidth *= m_engine->GetText()->GetHeight(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL); iLines = GetValueParam(buffer+i+7, 2); - LoadImage(iName); + LoadImage(std::string(iName)); // A part of image per line of text. for ( iCount=0 ; iCount<iLines ; iCount++ ) { - strcpy(m_image[iIndex].name, iName); + m_image[iIndex].name = iName; m_image[iIndex].offset = static_cast<float>(iCount/iLines); m_image[iIndex].height = 1.0f/iLines; m_image[iIndex].width = iWidth*0.75f; @@ -1888,7 +1870,7 @@ bool CEdit::ReadText(const char *filename, int addSize) // Writes all the text in a file. -bool CEdit::WriteText(const char *filename) +bool CEdit::WriteText(std::string filename) { FILE* file; char buffer[1000+20]; @@ -1896,7 +1878,7 @@ bool CEdit::WriteText(const char *filename) float iDim; if ( filename[0] == 0 ) return false; - file = fopen(filename, "wb"); + file = fopen(filename.c_str(), "wb"); if ( file == NULL ) return false; if ( m_bAutoIndent ) diff --git a/src/ui/edit.h b/src/ui/edit.h index 8f46445..72423fa 100644 --- a/src/ui/edit.h +++ b/src/ui/edit.h @@ -35,7 +35,12 @@ #include "common/restext.h" #include <set> +#include <string> +#include <boost/filesystem.hpp> +#include <boost/algorithm/string.hpp> + +namespace fs = boost::filesystem; namespace Ui { @@ -84,7 +89,7 @@ enum OperUndo struct ImageLine { //! name of the image (without diagram \) - char name[40]; + std::string name; //! vertical offset (v texture) float offset; //! height of the part (dv texture) @@ -96,15 +101,15 @@ struct ImageLine struct HyperLink { //! text file name (without help \) - char name[40]; + std::string name; //! name of the marker - char marker[20]; + std::string marker; }; struct HyperMarker { //! name of the marker - char name[20]; + std::string name; //! position in the text int pos; }; @@ -112,7 +117,7 @@ struct HyperMarker struct HyperHistory { //! full file name text - char filename[50]; + std::string filename; //! rank of the first displayed line int firstLine; }; @@ -140,8 +145,8 @@ public: char* GetText(); int GetTextLength(); - bool ReadText(const char *filename, int addSize=0); - bool WriteText(const char *filename); + bool ReadText(std::string filename, int addSize=0); + bool WriteText(std::string filename); void SetMaxChar(int max); int GetMaxChar(); @@ -183,7 +188,7 @@ public: bool Undo(); void HyperFlush(); - void HyperHome(const char *filename); + void HyperHome(std::string filename); bool HyperTest(EventType event); bool HyperGo(EventType event); @@ -202,15 +207,15 @@ protected: int MouseDetect(Math::Point mouse); void MoveAdjust(); - void HyperJump(const char *name, const char *marker); - bool HyperAdd(const char *filename, int firstLine); + void HyperJump(std::string name, std::string marker); + bool HyperAdd(std::string filename, int firstLine); - void DrawImage(Math::Point pos, const char *name, float width, float offset, float height, int nbLine); + void DrawImage(Math::Point pos, std::string name, float width, float offset, float height, int nbLine); void DrawBack(Math::Point pos, Math::Point dim); void DrawPart(Math::Point pos, Math::Point dim, int icon); void FreeImage(); - void LoadImage(const char *name); + void LoadImage(std::string name); void Scroll(int pos, bool bAdjustCursor); void Scroll(); void MoveChar(int move, bool bWord, bool bSelect); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index a0b0e06..51d2dda 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -3559,11 +3559,11 @@ void CMainDialog::SetUserDir(char *base, int rank) if ( strcmp(base, "user") == 0 && rank >= 100 ) { dir = m_userDir + "/" + m_userList.at(rank/100-1); - UserDir(true, dir.c_str()); + GetProfile().SetUserDir(dir); } else { - UserDir(false, ""); + GetProfile().SetUserDir(""); } } @@ -4258,7 +4258,6 @@ bool CMainDialog::IsIOReadScene() FILE* file; std::string filename; - //TODO: Change this to point user dir acocrding to operating system filename = m_savegameDir + "/" + m_main->GetGamerName() + "/" + "save" + m_sceneName[0] + "000/data.sav"; file = fopen(filename.c_str(), "r"); if ( file == NULL ) return false; @@ -4354,7 +4353,7 @@ void CMainDialog::IOReadList() filename = m_savegameDir + "/" + m_main->GetGamerName() + "/save" + m_sceneName[0] + rankStream.str()+ "/data.sav"; // sprintf(filename, "%s\\%s\\save%c%.3d\\data.sav", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], j); - file = fopen(filename.c_str(), "r"); + file = fopen(fs::path(filename).native().c_str(), "r"); if ( file == NULL ) break; while ( fgets(line, 500, file) != NULL ) @@ -5046,8 +5045,8 @@ void CMainDialog::UpdateDisplayDevice() CWindow* pw; CList* pl; char bufDevices[1000]; - char bufModes[5000]; - int i, j, totalDevices, selectDevices, totalModes, selectModes; + //char bufModes[5000]; + int i, j; pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5)); if ( pw == 0 ) return; @@ -5055,7 +5054,7 @@ void CMainDialog::UpdateDisplayDevice() if ( pl == 0 ) return; pl->Flush(); - bufModes[0] = 0; + //bufModes[0] = 0; /* TODO: remove device choice m_engine->EnumDevices(bufDevices, 1000, bufModes, 5000, @@ -5070,10 +5069,10 @@ void CMainDialog::UpdateDisplayDevice() while ( bufDevices[i++] != 0 ); } - pl->SetSelect(selectDevices); + pl->SetSelect(0); pl->ShowSelect(false); - m_setupSelDevice = selectDevices; + m_setupSelDevice = 0; } // Updates the list of modes. @@ -5110,8 +5109,8 @@ void CMainDialog::ChangeDisplay() CWindow* pw; CList* pl; CCheck* pc; - char* device; - char* mode; + //char* device; + //char* mode; bool bFull; pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5)); @@ -5120,12 +5119,12 @@ void CMainDialog::ChangeDisplay() pl = static_cast<CList*>(pw->SearchControl(EVENT_LIST1)); if ( pl == 0 ) return; m_setupSelDevice = pl->GetSelect(); - device = pl->GetName(m_setupSelDevice); + //device = pl->GetName(m_setupSelDevice); pl = static_cast<CList*>(pw->SearchControl(EVENT_LIST2)); if ( pl == 0 ) return; m_setupSelMode = pl->GetSelect(); - mode = pl->GetName(m_setupSelMode); + //mode = pl->GetName(m_setupSelMode); pc = static_cast<CCheck*>(pw->SearchControl(EVENT_INTERFACE_FULL)); if ( pc == 0 ) return; diff --git a/src/ui/maindialog.h b/src/ui/maindialog.h index be61299..a79b95e 100644 --- a/src/ui/maindialog.h +++ b/src/ui/maindialog.h @@ -23,6 +23,12 @@ #include "object/robotmain.h" +#include <boost/filesystem.hpp> +#include <boost/algorithm/string.hpp> + +namespace fs = boost::filesystem; + + class CEventQueue; class CSoundInterface; diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index bf2ff33..a056026 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -1477,8 +1477,7 @@ void CStudio::UpdateDialogPublic() CCheck* pc; CLabel* pl; char name[100]; - char dir[MAX_FNAME]; - char text[MAX_FNAME+100]; + //char text[MAX_FNAME+100]; pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9)); if ( pw == nullptr ) return; @@ -1499,9 +1498,7 @@ void CStudio::UpdateDialogPublic() if ( pl != 0 ) { GetResource(RES_TEXT, RT_IO_LIST, name); - SearchDirectory(dir, false); - sprintf(text, name, dir); - pl->SetName(text, false); + pl->SetName(SearchDirectory(false).c_str(), false); } } @@ -1572,21 +1569,22 @@ void CStudio::UpdateDialogList() // Constructs the name of the folder or open/save. // If the folder does not exist, it will be created. -void CStudio::SearchDirectory(char *dir, bool bCreate) +std::string CStudio::SearchDirectory(bool bCreate) { - if ( m_main->GetIOPublic() ) - { - sprintf(dir, "%s\\", m_main->GetPublicDir()); + char dir[MAX_FNAME]; + if ( m_main->GetIOPublic() ) { + sprintf(dir, "%s/", m_main->GetPublicDir()); + } else { + sprintf(dir, "%s/%s/Program/", m_main->GetSavegameDir(), m_main->GetGamerName()); } - else - { - sprintf(dir, "%s\\%s\\Program\\", m_main->GetSavegameDir(), m_main->GetGamerName()); + + fs::path path = fs::path(dir); + + if ( bCreate ) { + fs::create_directory(path); } - if ( bCreate ) - {// TODO -// mkdir(dir,0777); // if does not exist yet! - } + return path.make_preferred().string(); } // Reads a new program. @@ -1612,7 +1610,7 @@ bool CStudio::ReadProgram() { strcat(filename, ".txt"); } - SearchDirectory(dir, true); + strcpy(dir, SearchDirectory(true).c_str()); strcat(dir, filename); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3)); @@ -1650,7 +1648,7 @@ bool CStudio::WriteProgram() { strcat(filename, ".txt"); } - SearchDirectory(dir, true); + strcpy(dir, SearchDirectory(true).c_str()); strcat(dir, filename); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3)); @@ -1658,7 +1656,7 @@ bool CStudio::WriteProgram() pe = static_cast< CEdit* >(pw->SearchControl(EVENT_STUDIO_EDIT)); if ( pe == nullptr ) return false; - if ( !pe->WriteText(dir) ) return false; + if ( !pe->WriteText(std::string(dir)) ) return false; m_script->SetFilename(filename); return true; diff --git a/src/ui/studio.h b/src/ui/studio.h index 7c2f652..1c14124 100644 --- a/src/ui/studio.h +++ b/src/ui/studio.h @@ -22,6 +22,9 @@ #include "graphics/engine/camera.h" +#include <boost/filesystem.hpp> + +namespace fs = boost::filesystem; #include <string> @@ -81,7 +84,7 @@ protected: void UpdateDialogAction(); void UpdateDialogPublic(); void UpdateDialogList(); - void SearchDirectory(char* dir, bool bCreate); + std::string SearchDirectory(bool bCreate); bool ReadProgram(); bool WriteProgram(); |