1 /*************************************************************************** 2 savegamedialog.h - The save/load game dialog 3 ------------------- 4 begin : 9/9/2005 5 copyright : (C) 2005 by Gabor Torok 6 email : cctorok@yahoo.com 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef SAVEGAME_DIALOG_H 19 #define SAVEGAME_DIALOG_H 20 #pragma once 21 22 #include <map> 23 #include <vector> 24 #include <set> 25 #include <sstream> 26 #include "gui/eventhandler.h" 27 28 class Scourge; 29 class Window; 30 class Label; 31 class ScrollingList; 32 class ScrollingLabel; 33 class Widget; 34 class Button; 35 class TextField; 36 class ConfirmDialog; 37 class Texture; 38 39 using namespace std; 40 41 #define MAX_SAVEGAME_COUNT 100 42 43 /// Information about a savegame. 44 class SavegameInfo { 45 public: 46 std::string path; 47 std::string title; 48 }; 49 50 /// The save/load game dialog. 51 class SavegameDialog : public EventHandler { 52 private: 53 Scourge *scourge; 54 Window *win; 55 ScrollingList *files; 56 Button *cancel, *save, *load, *newSave, *deleteSave; 57 std::vector<SavegameInfo*> fileInfos; 58 std::vector<std::string> filenames; 59 std::vector<Texture> screens; // owns the textures 60 ConfirmDialog *confirm; 61 62 bool matches_save_( std::string& match ); 63 64 public: 65 SavegameDialog( Scourge *scourge ); 66 ~SavegameDialog(); getWindow()67 inline Window *getWindow() { 68 return win; 69 } 70 bool handleEvent( Widget *widget, SDL_Event *event ); 71 void show( bool inSaveMode = true ); 72 73 bool createNewSaveGame(); 74 75 void deleteUnvisitedMaps( const string& dirName, std::set<std::string> *visitedMaps ); 76 77 bool quickSave( const string& dirName, const string& title ); 78 void quickLoad(); 79 80 protected: 81 bool findFiles(); 82 bool readFileDetails( const string& path ); 83 void makeDirectory( const string& path ); 84 void findFilesInDir( const string& path, vector<string> *fileNameList ); 85 bool checkIfFileExists( const string& filename ); 86 void saveScreenshot( const string& dirName ); 87 bool copyMaps( const string& fromDirName, const string& toDirName ); 88 bool copyFile( const string& fromDirName, const string& toDirName, const string& fileName ); 89 // unused: terror GLuint loadScreenshot( const string& path ); 90 bool saveGameInternal( SavegameInfo *info ); 91 bool createSaveGame( SavegameInfo *info ); 92 void loadGame( int n ); 93 void setSavegameInfoTitle( SavegameInfo *info ); 94 bool deleteDirectory( const string& path ); 95 void deleteUnreferencedMaps( const string& dirName ); 96 DECLARE_NOISY_OPENGL_SUPPORT(); 97 }; 98 99 #endif 100 101