Author: jhinrichs
Date: Wed Apr 1 18:20:38 2009
New Revision: 34375
URL: http://svn.gna.org/viewcvs/wesnoth?rev=34375&view=rev
Log:
Savegame reorganization Step 1: Providing a simpler interface to saving and
loading.
Split menu_handler::save_game into menu_handler::save_game +
menu_handler::save_replay.
@nagbot: The changelog entry for this is already in, done with an earlier
commit ;-)
Modified:
trunk/src/menu_events.cpp
trunk/src/menu_events.hpp
trunk/src/play_controller.cpp
Modified: trunk/src/menu_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=34375&r1=34374&r2=34375&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Wed Apr 1 18:20:38 2009
@@ -584,18 +584,13 @@
}
void menu_handler::save_game(const std::string& message,
gui::DIALOG_TYPE dialog_type,
- const bool has_exit_button, const bool replay)
+ const bool has_exit_button)
{
std::stringstream stream;
const std::string ellipsed_name =
font::make_text_ellipsis(gamestate_.label,
font::SIZE_NORMAL, 200);
- if (replay) {
- stream << ellipsed_name << " " << _("replay");
- } else {
- stream << ellipsed_name << " " << _("Turn")
- << " " << status_.turn();
- }
+ stream << ellipsed_name << " " << _("Turn") << " " <<
status_.turn();
std::string label = stream.str();
if(dialog_type == gui::NULL_DIALOG && message != "") {
label = message;
@@ -609,15 +604,48 @@
if(res == 0) {
config snapshot;
- if (!replay){
- write_game_snapshot(snapshot);
- }
+ write_game_snapshot(snapshot);
gamestate_.replay_data = recorder.get_replay_data();
try {
- if (replay)
- ::save_replay(label, gamestate_);
- else
- ::save_game(label, snapshot,
gamestate_);
+ ::save_game(label, snapshot, gamestate_);
+
+ if(dialog_type != gui::NULL_DIALOG) {
+
gui::message_dialog(*gui_,_("Saved"),_("The game has been saved")).show();
+ }
+ } catch(game::save_game_failed&) {
+ gui::message_dialog
to_show(*gui_,_("Error"),_("The game could not be saved"));
+ to_show.show();
+ //do not bother retrying, since the user can
just try to save the game again
+ };
+ } else if(res == 2) {
+ throw end_level_exception(QUIT);
+ }
+ }
+
+ void menu_handler::save_replay(const std::string& message,
gui::DIALOG_TYPE dialog_type,
+ const bool has_exit_button)
+ {
+ std::stringstream stream;
+
+ const std::string ellipsed_name =
font::make_text_ellipsis(gamestate_.label,
+ font::SIZE_NORMAL, 200);
+ stream << ellipsed_name << " " << _("replay");
+ std::string label = stream.str();
+ if(dialog_type == gui::NULL_DIALOG && message != "") {
+ label = message;
+ }
+
+ label.erase(std::remove_if(label.begin(), label.end(),
+ dialogs::is_illegal_file_char), label.end());
+
+ const int res = dialog_type == gui::NULL_DIALOG ? 0
+ : dialogs::get_save_name(*gui_,message, _("Name: "),
&label,dialog_type, "", has_exit_button);
+
+ if(res == 0) {
+ config snapshot;
+ gamestate_.replay_data = recorder.get_replay_data();
+ try {
+ ::save_replay(label, gamestate_);
if(dialog_type != gui::NULL_DIALOG) {
gui::message_dialog(*gui_,_("Saved"),_("The game has been saved")).show();
Modified: trunk/src/menu_events.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.hpp?rev=34375&r1=34374&r2=34375&view=diff
==============================================================================
--- trunk/src/menu_events.hpp (original)
+++ trunk/src/menu_events.hpp Wed Apr 1 18:20:38 2009
@@ -69,7 +69,8 @@
void show_statistics(const unsigned int team_num);
void unit_list();
void status_table(int selected=0);
- void save_game(const std::string& message, gui::DIALOG_TYPE
dialog_type, const bool has_exit_button=false, const bool replay=false);
+ void save_replay(const std::string& message, gui::DIALOG_TYPE
dialog_type, const bool has_exit_button=false);
+ void save_game(const std::string& message, gui::DIALOG_TYPE
dialog_type, const bool has_exit_button=false);
void save_map();
void load_game();
void preferences();
Modified: trunk/src/play_controller.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/play_controller.cpp?rev=34375&r1=34374&r2=34375&view=diff
==============================================================================
--- trunk/src/play_controller.cpp (original)
+++ trunk/src/play_controller.cpp Wed Apr 1 18:20:38 2009
@@ -294,7 +294,7 @@
}
void play_controller::save_replay(){
- menu_handler_.save_game("", gui::OK_CANCEL, false, true);
+ menu_handler_.save_replay("", gui::OK_CANCEL, false);
}
void play_controller::save_map(){
@@ -437,6 +437,7 @@
// and the player should get income now.
// Healing/income happen if it's not the first turn of processing,
// or if we are loading a game, and this is not the player it started
with.
+ // FIXME: This does not work correct if loading a save of turn 1
(turn_refresh should be false but is true for every subsequent side)
const bool turn_refresh = status_.turn() > start_turn_ ||
(loading_game_ && team_index != (first_player_ - 1));
if(turn_refresh) {
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits