Author: jhinrichs
Date: Fri May  1 12:04:19 2009
New Revision: 35365

URL: http://svn.gna.org/viewcvs/wesnoth?rev=35365&view=rev
Log:
Savegame reorganization Step 1: Providing a simpler interface to saving and 
loading.
Makes the interface more consistent by clearly separating between automatic and 
interactive saves.

Modified:
    trunk/src/menu_events.cpp
    trunk/src/playcampaign.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=35365&r1=35364&r2=35365&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Fri May  1 12:04:19 2009
@@ -2764,11 +2764,11 @@
        }
        void console_handler::do_save() {
                savegame save(menu_handler_.gamestate_, 
preferences::compress_saves());
-               save.save_game(&menu_handler_.gui_->video(), get_data());
+               save.save_game_automatic(menu_handler_.gui_->video(), true, 
get_data());
        }
        void console_handler::do_save_quit() {
                savegame save(menu_handler_.gamestate_, 
preferences::compress_saves());
-               save.save_game(&menu_handler_.gui_->video(), get_data());
+               save.save_game_automatic(menu_handler_.gui_->video(), true, 
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=35365&r1=35364&r2=35365&view=diff
==============================================================================
--- trunk/src/playcampaign.cpp (original)
+++ trunk/src/playcampaign.cpp Fri May  1 12:04:19 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);
+                               save.save_game_automatic(disp.video(), true);
                        }
                }
 
@@ -560,7 +560,7 @@
                                                gui::YES_NO)
                                }
 #else
-                               save.save_game();
+                               save.save_game_automatic(disp.video());
 #endif /* TINY_GUI */
                        }
 

Modified: trunk/src/savegame.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.cpp?rev=35365&r1=35364&r2=35365&view=diff
==============================================================================
--- trunk/src/savegame.cpp (original)
+++ trunk/src/savegame.cpp Fri May  1 12:04:19 2009
@@ -475,10 +475,31 @@
        , compress_saves_(compress_saves)
 {}
 
+bool savegame::save_game_automatic(CVideo& video, bool ask_for_overwrite, 
const std::string& filename)
+{
+       bool overwrite = true;
+
+       if (filename == "")
+               create_filename();
+       else
+               filename_ = filename;
+
+       if (ask_for_overwrite){
+               overwrite = check_overwrite(video);
+
+               if (!overwrite){
+                       show_confirmation_ = true;
+                       return save_game_interactive(video, "", gui::OK_CANCEL);
+               }
+       }
+
+       return save_game(&video);
+}
+
 bool savegame::save_game_interactive(CVideo& video, const std::string& message,
-                                                                        
gui::DIALOG_TYPE dialog_type, bool ask_for_filename)
-{
-       show_confirmation_ = ask_for_filename;
+                                                                        
gui::DIALOG_TYPE dialog_type)
+{
+       show_confirmation_ = true;
        create_filename();
 
        int res = gui2::twindow::OK;
@@ -486,18 +507,11 @@
 
        do{ 
                try{
-                       if (ask_for_filename){
-                               res = show_save_dialog(video, message, 
dialog_type);
-                               exit = true;
-                       }
+                       res = show_save_dialog(video, message, dialog_type);
+                       exit = true;
 
                        if (res == gui2::twindow::OK){
                                exit = check_overwrite(video);
-
-                               if (!exit){
-                                       ask_for_filename = true;
-                                       show_confirmation_ = true;
-                               }
                        }
                }
                catch (illegal_filename_exception){
@@ -592,7 +606,7 @@
                        filename_ = filename;
 
                before_save();
-               save_game_internal(filename_);
+               write_game_to_disk(filename_);
 
                end = SDL_GetTicks();
                LOG_SAVE << "Milliseconds to save " << filename_ << ": " << end 
- start << "\n";
@@ -612,7 +626,7 @@
        };
 }
 
-void savegame::save_game_internal(const std::string& filename)
+void savegame::write_game_to_disk(const std::string& filename)
 {
        LOG_SAVE << "savegame::save_game";
 
@@ -832,7 +846,6 @@
        : game_savegame(gamestate, level_cfg, gui, teams, units, gamestatus, 
map, compress_saves)
 {
        set_error_message(_("Could not auto save the game. Please save the game 
manually."));
-       create_filename();
 }
 
 void autosave_savegame::autosave(const bool disable_autosave, const int 
autosave_max, const int infinite_autosaves)
@@ -840,7 +853,7 @@
        if(disable_autosave)
                return;
 
-       save_game(&gui_.video());
+       save_game_automatic(gui_.video());
 
        savegame_manager::remove_old_auto_saves(autosave_max, 
infinite_autosaves);
 }

Modified: trunk/src/savegame.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.hpp?rev=35365&r1=35364&r2=35365&view=diff
==============================================================================
--- trunk/src/savegame.hpp (original)
+++ trunk/src/savegame.hpp Fri May  1 12:04:19 2009
@@ -138,22 +138,27 @@
                console_handler save actions. The return value denotes, if the 
save was successful or not. */
        //bool save_game(const std::string& filename);
 
+       /** Saves a game without user interaction, unless the file exists and 
it should be asked
+               to overwrite it. The return value denotes, if the save was 
successful or not. 
+               This is used by automatically generated replays, 
start-of-scenario saves and autosaves.
+       */
+       bool save_game_automatic(CVideo& video, bool ask_for_overwrite = false, 
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& video, const std::string& message,
+               gui::DIALOG_TYPE dialog_type);
+
+       const std::string& filename() const { return filename_; }
+
+protected:
        /** 
-               Save a game without any further user interaction. This is used 
by autosaves and
-               automatically generated replay saves. If you want notifying 
messages or error messages
-               to appear, you have to provide the gui parameter. 
+               Save a game without any further user interaction. If you want 
notifying messages 
+               or error messages 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, 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, 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);
@@ -184,7 +189,7 @@
 
        /** The actual method for saving the game to disk. All interactive 
filename choosing and
                data manipulation has to happen before calling this method. */
-       void save_game_internal(const std::string& filename);
+       void write_game_to_disk(const std::string& filename);
 
        /** Writing the savegame config to a file. */
        void write_game(config_writer &out) const;


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

Reply via email to