Author: jhinrichs
Date: Thu Apr 30 20:04:23 2009
New Revision: 35352

URL: http://svn.gna.org/viewcvs/wesnoth?rev=35352&view=rev
Log:
Savegame reorganization Step 1: Providing a simpler interface to saving and 
loading.
Further refactoring savegame.cpp and slightly simplifying the interface.

Modified:
    trunk/src/menu_events.cpp
    trunk/src/playcampaign.cpp
    trunk/src/playmp_controller.cpp
    trunk/src/savegame.cpp
    trunk/src/savegame.hpp

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=35352&r1=35351&r2=35352&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Thu Apr 30 20:04:23 2009
@@ -2764,11 +2764,11 @@
        }
        void console_handler::do_save() {
                savegame save(menu_handler_.gamestate_, 
preferences::compress_saves());
-               save.save_game(get_data());
+               save.save_game(&menu_handler_.gui_->video(), get_data());
        }
        void console_handler::do_save_quit() {
                savegame save(menu_handler_.gamestate_, 
preferences::compress_saves());
-               save.save_game(get_data());
+               save.save_game(&menu_handler_.gui_->video(), get_data());
                throw end_level_exception(QUIT);
        }
        void console_handler::do_quit() {

Modified: trunk/src/playcampaign.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/playcampaign.cpp?rev=35352&r1=35351&r2=35352&view=diff
==============================================================================
--- trunk/src/playcampaign.cpp (original)
+++ trunk/src/playcampaign.cpp Thu Apr 30 20:04:23 2009
@@ -395,7 +395,7 @@
 
                        if (preferences::save_replays()) {
                                replay_savegame save(gamestate, 
preferences::compress_saves());
-                               save.save_game_interactive(disp.video(), "", 
gui::OK_CANCEL, false, false);
+                               save.save_game_interactive(disp.video(), "", 
gui::OK_CANCEL, false);
                        }
                }
 

Modified: trunk/src/playmp_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/playmp_controller.cpp?rev=35352&r1=35351&r2=35352&view=diff
==============================================================================
--- trunk/src/playmp_controller.cpp (original)
+++ trunk/src/playmp_controller.cpp Thu Apr 30 20:04:23 2009
@@ -538,8 +538,8 @@
                temp_buf << " \n";
        }
 
-       game_savegame save(gamestate_, level_, *gui_, teams_, units_, status_, 
map_, preferences::compress_saves());
-       save.save_game_interactive((*gui_).video(), temp_buf.str(), 
gui::YES_NO, true);
+       oos_savegame save(gamestate_, level_, *gui_, teams_, units_, status_, 
map_, preferences::compress_saves());
+       save.save_game_interactive((*gui_).video(), temp_buf.str(), 
gui::YES_NO);
 }
 
 void playmp_controller::handle_generic_event(const std::string& name){

Modified: trunk/src/savegame.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.cpp?rev=35352&r1=35351&r2=35352&view=diff
==============================================================================
--- trunk/src/savegame.cpp (original)
+++ trunk/src/savegame.cpp Thu Apr 30 20:04:23 2009
@@ -476,8 +476,7 @@
 {}
 
 bool savegame::save_game_interactive(CVideo& video, const std::string& message,
-                                                                        
gui::DIALOG_TYPE dialog_type, const bool has_exit_button,
-                                                                        bool 
ask_for_filename)
+                                                                        
gui::DIALOG_TYPE dialog_type, bool ask_for_filename)
 {
        show_confirmation_ = ask_for_filename;
        create_filename();
@@ -488,7 +487,7 @@
        do{ 
                try{
                        if (ask_for_filename){
-                               res = show_save_dialog(video, has_exit_button, 
message, dialog_type);
+                               res = show_save_dialog(video, message, 
dialog_type);
                                exit = true;
                        }
 
@@ -516,33 +515,23 @@
        return save_game(&video);
 }
 
-int savegame::show_save_dialog(CVideo& video, bool is_oos, const std::string& 
message, const gui::DIALOG_TYPE dialog_type)
-{
-       static bool ignore_all = false;
+int savegame::show_save_dialog(CVideo& video, const std::string& message, 
const gui::DIALOG_TYPE dialog_type)
+{
        int res = 0;
 
        std::string filename = filename_;
 
-       if (is_oos && (!ignore_all)){
-               gui2::tgame_save_oos dlg(title_, filename, message);
+       if (dialog_type == gui::OK_CANCEL){
+               gui2::tgame_save dlg(title_, filename);
                dlg.show(video);
                filename = dlg.filename();
-               ignore_all = dlg.ignore_all();
                res = dlg.get_retval();
        }
-       else{
-               if (dialog_type == gui::OK_CANCEL){
-                       gui2::tgame_save dlg(title_, filename);
-                       dlg.show(video);
-                       filename = dlg.filename();
-                       res = dlg.get_retval();
-               }
-               else if (dialog_type == gui::YES_NO){
-                       gui2::tgame_save_message dlg(title_, filename, message);
-                       dlg.show(video);
-                       filename = dlg.filename();
-                       res = dlg.get_retval();
-               }
+       else if (dialog_type == gui::YES_NO){
+               gui2::tgame_save_message dlg(title_, filename, message);
+               dlg.show(video);
+               filename = dlg.filename();
+               res = dlg.get_retval();
        }
 
        check_filename(filename, video);
@@ -593,17 +582,14 @@
        gamestate_.replay_data = recorder.get_replay_data();
 }
 
-bool savegame::save_game(const std::string& filename)
-{
-       filename_ = filename;
-       return save_game();
-}
-
-bool savegame::save_game(CVideo* video)
+bool savegame::save_game(CVideo* video, const std::string& filename)
 {
        try {
                Uint32 start, end;
                start = SDL_GetTicks();
+
+               if (filename_ == "")
+                       filename_ = filename;
 
                before_save();
                save_game_internal(filename_);
@@ -870,6 +856,34 @@
        set_filename(filename);
 }
 
+oos_savegame::oos_savegame(game_state &gamestate, const config& level_cfg,
+                                                        game_display& gui, 
const std::vector<team>& teams,
+                                                        const unit_map& units, 
const gamestatus& gamestatus,
+                                                        const gamemap& map, 
const bool compress_saves)
+       : game_savegame(gamestate, level_cfg, gui, teams, units, gamestatus, 
map, compress_saves)
+{}
+
+int oos_savegame::show_save_dialog(CVideo& video, const std::string& message, 
const gui::DIALOG_TYPE dialog_type)
+{
+       static bool ignore_all = false;
+       int res = 0;
+
+       std::string filename = this->filename();
+
+       if (!ignore_all){
+               gui2::tgame_save_oos dlg(title(), filename, message);
+               dlg.show(video);
+               filename = dlg.filename();
+               ignore_all = dlg.ignore_all();
+               res = dlg.get_retval();
+       }
+
+       check_filename(filename, video);
+       set_filename(filename);
+
+       return res;
+}
+
 game_savegame::game_savegame(game_state &gamestate, const config& level_cfg,
                                                         game_display& gui, 
const std::vector<team>& teams,
                                                         const unit_map& units, 
const gamestatus& gamestatus,

Modified: trunk/src/savegame.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.hpp?rev=35352&r1=35351&r2=35352&view=diff
==============================================================================
--- trunk/src/savegame.hpp (original)
+++ trunk/src/savegame.hpp Thu Apr 30 20:04:23 2009
@@ -136,7 +136,7 @@
 
        /** Save a game without any further user interaction. Atm, this is only 
used by the
                console_handler save actions. The return value denotes, if the 
save was successful or not. */
-       bool save_game(const std::string& filename);
+       //bool save_game(const std::string& filename);
 
        /** 
                Save a game without any further user interaction. This is used 
by autosaves and
@@ -144,24 +144,26 @@
                to appear, you have to provide the gui parameter. 
                The return value denotes, if the save was successful or not.
        */
-       bool save_game(CVideo* video = NULL);
+       bool save_game(CVideo* video = NULL, const std::string& filename = "");
 
        /** Save a game interactively through the savegame dialog. Used for 
manual midgame and replay
                saves. The return value denotes, if the save was successful or 
not. */
        bool save_game_interactive(CVideo& gui, const std::string& message,
-               gui::DIALOG_TYPE dialog_type, const bool has_exit_button = 
false,
-               bool ask_for_filename = true);
-
-       const std::string filename() const { return filename_; }
+               gui::DIALOG_TYPE dialog_type, bool ask_for_filename = true);
+
+       const std::string& filename() const { return filename_; }
 
 protected:
        /** Sets the filename and removes invalid characters. Don't set the 
filename directly but
                use this method instead. */
        void set_filename(std::string filename);
+       /** Check, if the filename contains illegal constructs like ".gz". */
+       void check_filename(const std::string& filename, CVideo& video);
 
        /** Customize the standard error message */
        void set_error_message(const std::string error_message) { 
error_message_ = error_message; }
 
+       const std::string& title() const { return title_; }
        game_state& gamestate() const { return gamestate_; }
        config& snapshot() { return snapshot_; }
 
@@ -175,10 +177,8 @@
        /** Build the filename according to the specific savegame's needs. 
Subclasses will have to
                override this to take effect. */
        virtual void create_filename() {}
-       /** Check, if the filename contains illegal constructs like ".gz". */
-       void check_filename(const std::string& filename, CVideo& video);
        /** Display the save game dialog. */
-       int show_save_dialog(CVideo& video, bool is_oos, const std::string& 
message, const gui::DIALOG_TYPE dialog_type);
+       virtual int show_save_dialog(CVideo& video, const std::string& message, 
const gui::DIALOG_TYPE dialog_type);
        /** Ask the user if an existing file should be overwritten. */
        bool check_overwrite(CVideo& video);
 
@@ -257,9 +257,9 @@
 {
 public:
        autosave_savegame(game_state &gamestate, const config& level_cfg,
-                                                        game_display& gui, 
const std::vector<team>& teams,
-                                                        const unit_map& units, 
const gamestatus& gamestatus,
-                                                        const gamemap& map, 
const bool compress_saves);
+                                        game_display& gui, const 
std::vector<team>& teams,
+                                        const unit_map& units, const 
gamestatus& gamestatus,
+                                        const gamemap& map, const bool 
compress_saves);
 
        void autosave(const bool disable_autosave, const int autosave_max, 
const int infinite_autosaves);
 private:
@@ -267,6 +267,19 @@
        virtual void create_filename();
 };
 
+class oos_savegame : public game_savegame
+{
+public:
+       oos_savegame(game_state &gamestate, const config& level_cfg,
+                                game_display& gui, const std::vector<team>& 
teams,
+                                const unit_map& units, const gamestatus& 
gamestatus,
+                                const gamemap& map, const bool compress_saves);
+
+private:
+       /** Display the save game dialog. */
+       virtual int show_save_dialog(CVideo& video, const std::string& message, 
const gui::DIALOG_TYPE dialog_type);
+};
+
 /** Class for start-of-scenario saves */
 class scenariostart_savegame : public savegame
 {


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to