made the statistics dialog more user-friendly
slight improvements to some gui::dialog internal code
This commit is contained in:
parent
00ef9be014
commit
e51d5d32d6
2 changed files with 58 additions and 8 deletions
|
@ -629,16 +629,18 @@ int dialog::process(dialog_process_info &info)
|
|||
return (use_menu ? menu_->selection() : 0);
|
||||
}
|
||||
|
||||
if(!info.key_down && info.key[SDLK_ESCAPE] && type_ == MESSAGE) {
|
||||
return (ESCAPE_DIALOG);
|
||||
}
|
||||
|
||||
//escape quits from the dialog -- unless it's an "ok" dialog with a menu,
|
||||
//since such dialogs require a selection of some kind.
|
||||
if(!info.key_down && info.key[SDLK_ESCAPE] && (type_ != OK_ONLY || !use_menu)) {
|
||||
return ((type_ == OK_ONLY && use_menu) ? 1 : CLOSE_DIALOG);
|
||||
if(!info.key_down && info.key[SDLK_ESCAPE]) {
|
||||
if(type_ == MESSAGE) {
|
||||
//special return value for escaping game event messages
|
||||
return (ESCAPE_DIALOG);
|
||||
} else if(type_ != OK_ONLY || !use_menu) {
|
||||
return ((type_ == OK_ONLY && use_menu) ? 1 : CLOSE_DIALOG);
|
||||
}
|
||||
}
|
||||
|
||||
//inform preview panes when there is a new menu selection
|
||||
if((menu_->selection() != info.selection) || info.first_time) {
|
||||
info.selection = menu_->selection();
|
||||
int selection = info.selection;
|
||||
|
@ -658,6 +660,7 @@ int dialog::process(dialog_process_info &info)
|
|||
info.first_time = false;
|
||||
|
||||
if(use_menu) {
|
||||
//get any drop-down choice or context-menu click
|
||||
const int selection = menu_->process();
|
||||
if(selection != -1)
|
||||
{
|
||||
|
@ -671,6 +674,7 @@ int dialog::process(dialog_process_info &info)
|
|||
const SDL_Rect menu_rect = menu_->location();
|
||||
if(
|
||||
(
|
||||
//clicking outside of a drop-down or context-menu should close it
|
||||
standard_buttons_.empty() &&
|
||||
(
|
||||
(
|
||||
|
@ -681,6 +685,8 @@ int dialog::process(dialog_process_info &info)
|
|||
)
|
||||
)
|
||||
) || (
|
||||
//any keypress should close a dialog if it has one standard button (or less)
|
||||
//and no menu options.
|
||||
standard_buttons_.size() < 2 && new_key_down && !info.key_down && !use_menu
|
||||
)
|
||||
)
|
||||
|
@ -692,6 +698,7 @@ int dialog::process(dialog_process_info &info)
|
|||
info.right_button = new_right_button;
|
||||
info.key_down = new_key_down;
|
||||
|
||||
//now handle any button presses
|
||||
for(button_pool_iterator b = button_pool_.begin(); b != button_pool_.end(); ++b) {
|
||||
if(b->first->pressed()) {
|
||||
return b->first->action(info);
|
||||
|
|
|
@ -35,6 +35,45 @@
|
|||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
|
||||
class statistics_dialog : public gui::dialog
|
||||
{
|
||||
public:
|
||||
statistics_dialog(display &disp, const std::string& title="");
|
||||
~statistics_dialog();
|
||||
protected:
|
||||
void action(gui::dialog_process_info &dp_info);
|
||||
private:
|
||||
gui::dialog_button *detail_btn_;
|
||||
};
|
||||
|
||||
void statistics_dialog::action(gui::dialog_process_info &dp_info)
|
||||
{
|
||||
bool has_details = (get_menu().selection() < 5);
|
||||
detail_btn_->enable(has_details);
|
||||
if(dp_info.double_clicked && has_details) {
|
||||
set_result(get_menu().selection());
|
||||
} else if(dp_info.key_down) {
|
||||
set_result(gui::CLOSE_DIALOG);
|
||||
}
|
||||
}
|
||||
|
||||
statistics_dialog::statistics_dialog(display &disp, const std::string& title)
|
||||
: dialog(disp, title, "", gui::NULL_DIALOG)
|
||||
{
|
||||
detail_btn_ = new gui::standard_dialog_button(disp.video(), _("Detail"), 0 , false);
|
||||
add_button(detail_btn_, gui::dialog::BUTTON_EXTRA);
|
||||
add_button(new gui::standard_dialog_button(disp.video(), _("Close"), 1, true),
|
||||
gui::dialog::BUTTON_STANDARD);
|
||||
}
|
||||
|
||||
statistics_dialog::~statistics_dialog()
|
||||
{
|
||||
}
|
||||
|
||||
} //end anonymous namespace
|
||||
|
||||
namespace events{
|
||||
|
||||
class delete_recall_unit : public gui::dialog_button_action
|
||||
|
@ -190,11 +229,15 @@ namespace events{
|
|||
}
|
||||
str << ")";
|
||||
|
||||
const int res = gui::show_dialog2(*gui_, NULL, str.str(), "", gui::OK_CANCEL, &items);
|
||||
statistics_dialog stats_dialog(*gui_, str.str());
|
||||
stats_dialog.set_menu(items);
|
||||
const int res = stats_dialog.show();
|
||||
std::string title;
|
||||
std::vector<std::string> items_sub;
|
||||
|
||||
switch(res) {
|
||||
case gui::CLOSE_DIALOG:
|
||||
return;
|
||||
case 0:
|
||||
items_sub = create_unit_table(stats.recruits,gui_->viewing_team()+1);
|
||||
title = _("Recruits");
|
||||
|
@ -216,7 +259,7 @@ namespace events{
|
|||
title = _("Kills");
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
if (items_sub.empty() == false)
|
||||
|
|
Loading…
Add table
Reference in a new issue