adds "Quit Game" button to OOS pop-up

This commit is contained in:
Patrick Parker 2006-07-31 22:37:26 +00:00
parent 9c381da3a6
commit d75e869251
5 changed files with 29 additions and 16 deletions

View file

@ -28,7 +28,7 @@
#include "minimap.hpp"
#include "preferences.hpp"
#include "replay.hpp"
#include "show_dialog.hpp"
#include "construct_dialog.hpp"
#include "util.hpp"
#include "video.hpp"
#include "wassert.hpp"
@ -185,18 +185,28 @@ void show_objectives(display& disp, const config& level, const std::string& obje
gui::OK_ONLY);
}
int get_save_name(display & disp,const std::string& caption, const std::string& message,
std::string* name, gui::DIALOG_TYPE dialog_type, const std::string& title)
int get_save_name(display & disp,const std::string& message, const std::string& txt_label,
std::string* fname, gui::DIALOG_TYPE dialog_type, const std::string& title,
const bool has_exit_button)
{
const std::string& title2 = (title.empty()) ? _("Save Game") : title;
const std::string& tmp_title = (title.empty()) ? _("Save Game") : title;
int overwrite=0;
int res=0;
do {
res = gui::show_dialog(disp,NULL,title2,caption,dialog_type,NULL,NULL,message,name);
if (res == 0 && save_game_exists(*name))
overwrite = gui::show_dialog(disp,NULL,_("Overwrite?"),
_("Save already exists. Do you want to overwrite it ?"),gui::YES_NO);
else overwrite = 0;
gui::dialog d(disp, tmp_title, message, dialog_type);
d.set_textbox(txt_label, *fname);
if(has_exit_button) {
d.add_button( new gui::dialog_button(disp.video(), _("Quit Game"),
gui::button::TYPE_PRESS, 2), gui::dialog::BUTTON_STANDARD);
}
res = d.show();
*fname = d.textbox_text();
if (res == 0 && save_game_exists(*fname)) {
overwrite = gui::show_dialog(disp,NULL,_("Overwrite?"),
_("Save already exists. Do you want to overwrite it ?"),gui::YES_NO);
} else {
overwrite = 0;
}
} while ((res==0)&&(overwrite!=0));
return res;
}

View file

@ -69,9 +69,9 @@ void show_objectives(display& disp, const config& level, const std::string& obje
// Ask user if I should really save the game and what name I should use
// returns 0 iff user wants to save the game
int get_save_name(display & disp, const std::string& caption,
const std::string& message, std::string* name,
gui::DIALOG_TYPE dialog_type=gui::YES_NO, const std::string& title="");
int get_save_name(display & disp,const std::string& message, const std::string& txt_label,
std::string* fname, gui::DIALOG_TYPE dialog_type=gui::YES_NO,
const std::string& title="", const bool has_exit_button=false);
//allow user to select the game they want to load. Returns the name
//of the save they want to load. Stores whether the user wants to show

View file

@ -366,7 +366,8 @@ namespace events{
NULL,"",NULL,0,NULL,NULL,-1,-1,NULL,NULL,"",&sorter);
}
void menu_handler::save_game(const std::string& message, gui::DIALOG_TYPE dialog_type)
void menu_handler::save_game(const std::string& message, gui::DIALOG_TYPE dialog_type,
const bool has_exit_button)
{
std::stringstream stream;
@ -381,7 +382,7 @@ namespace events{
label.erase(std::remove_if(label.begin(),label.end(),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);
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) {
@ -402,6 +403,8 @@ namespace events{
gui::show_dialog(*gui_,NULL,_("Error"),_("The game could not be saved"),gui::MESSAGE);
//do not bother retrying, since the user can just try to save the game again
};
} else if(res == 2) {
throw end_level_exception(QUIT);
}
}

View file

@ -71,7 +71,7 @@ public:
void show_statistics();
void unit_list();
void status_table();
void save_game(const std::string& message, gui::DIALOG_TYPE dialog_type);
void save_game(const std::string& message, gui::DIALOG_TYPE dialog_type, const bool has_exit_button=false);
void load_game();
void preferences();
void show_chat_log();

View file

@ -251,7 +251,7 @@ void playmp_controller::process_oos(const std::string& err_msg){
}
temp_buf << " \n";
}
menu_handler_.save_game(temp_buf.str(),gui::YES_NO);
menu_handler_.save_game(temp_buf.str(),gui::YES_NO, true);
}
void playmp_controller::handle_generic_event(const std::string& name){