1 #ifndef _SaveFileDialog_h_ 2 #define _SaveFileDialog_h_ 3 4 #include <set> 5 #include <string> 6 #include <GG/DropDownList.h> 7 #include <GG/ListBox.h> 8 #include <GG/Layout.h> 9 10 #include "CUIWnd.h" 11 12 #include <boost/filesystem/path.hpp> 13 14 class SaveFileRow; 15 class SaveFileListBox; 16 struct PreviewInformation; 17 18 /** A dialog for choosing save files. 19 * Shows some additional infoormation in the listing and more 20 * in a preview section to the side. 21 */ 22 class SaveFileDialog : public CUIWnd { 23 public: 24 enum class Purpose {Save, Load}; 25 enum class SaveType {SinglePlayer, MultiPlayer}; 26 27 /** \name Structors */ //@{ 28 SaveFileDialog(const Purpose purpose = Purpose::Load, const SaveType type = SaveType::SinglePlayer); 29 30 void CompleteConstruction() override; 31 ~SaveFileDialog(); 32 //@} 33 34 /** \name Mutators */ //@{ 35 void ModalInit() override; 36 37 void KeyPress(GG::Key key, std::uint32_t key_code_point, GG::Flags<GG::ModKey> mod_keys) override; 38 39 /** Update the previews with \p preview_info*/ 40 void SetPreviewList(const PreviewInformation& preview_info); 41 //@} 42 43 /// Get the chosen save files full path 44 std::string Result() const; 45 46 protected: 47 GG::Rect CalculatePosition() const override; 48 49 private: 50 void Init(); 51 52 void Confirm(); //!< when m_save_btn button is pressed 53 void AskDelete(); //!< when a file is trying to be deleted 54 void DoubleClickRow(GG::ListBox::iterator row, const GG::Pt& pt, const GG::Flags<GG::ModKey>& mod); 55 void Cancel(); //!< when m_load_btn button is pressed 56 void SelectionChanged(const GG::ListBox::SelectionSet& files); //!< When file selection changes. 57 void UpdateDirectory(const std::string& newdir); //!< Change current directory 58 59 /** Either directly update from the local save directory, or request the 60 server for save preview information*/ 61 void UpdatePreviewList(); 62 /** Update the preview list from a local save directory*/ 63 void SetPreviewList(const boost::filesystem::path& path); 64 /** Update the previews with preview info set by \p setup_preview_info*/ 65 void SetPreviewListCore(const std::function<void ()>& setup_preview_info); 66 67 bool CheckChoiceValidity(); //!< Disables confirm if filename invalid. Returns false if not valid. 68 void FileNameEdited(const std::string& filename); //!< Called when the filename changes 69 void DirectoryEdited(const std::string& filename); //!< Called when the directory text changes 70 71 std::string GetDirPath() const; //!< Gets the current directory path string clean of display decorations 72 void SetDirPath(const std::string& path); //!< Sets the shown directory path, applying decorations if applicable 73 74 std::shared_ptr<GG::Layout> m_layout; //!< The layout of the dialog; 75 76 std::shared_ptr<SaveFileListBox> m_file_list; //!< The list of available saves 77 std::shared_ptr<GG::Edit> m_name_edit; //!< The file name edit control; 78 std::shared_ptr<GG::Edit> m_current_dir_edit; //!< The editor for the save directory; 79 std::shared_ptr<GG::Button> m_confirm_btn; //!< Button to confirm choice; 80 81 std::string m_loaded_dir; //!< The directory whose contents are currently shown 82 std::string m_extension; //!< The save game file name extension 83 bool m_load_only; //!< Whether we are loading 84 bool m_server_previews; //!< If true, get the previews from the server 85 86 /// Remove copy ctor, assign 87 SaveFileDialog(const SaveFileDialog&); 88 SaveFileDialog& operator=(const SaveFileDialog&); 89 }; 90 91 #endif // _SaveFileDialog_h_ 92