void statistics_dialog::action(gui::dialog_process_info &dp_info)
{
	int sel = get_menu().selection();
	bool has_details = sel < 5 && sel >= 0 && unit_count_[sel] > 0;
	detail_btn_->enable(has_details);
	if(dp_info.double_clicked && has_details) {
		set_result(sel);
	} else if(dp_info.new_key_down && !dp_info.key_down) {
		set_result(gui::CLOSE_DIALOG);
	}

	// Prepare the sub-dialog for Statistic Details
	std::string title;
	std::vector<std::string> items_sub;
	switch(result()) {
	case gui::CLOSE_DIALOG:
		break;
	case 0:
		items_sub = create_unit_table(stats_.recruits, team_num_);
		title = _("Recruits");
		break;
	case 1:
		items_sub = create_unit_table(stats_.recalls, team_num_);
		title = _("Recalls");
		break;
	case 2:
		items_sub = create_unit_table(stats_.advanced_to, team_num_);
		title = _("Advancements");
		break;
	case 3:
		items_sub = create_unit_table(stats_.deaths, team_num_);
		title = _("Losses");
		break;
	case 4:
		items_sub = create_unit_table(stats_.killed, team_num_);
		/** @todo FIXME? Perhaps killed units shouldn't have the same team-color as your own. */
		title = _("Kills");
		break;
	default:
		break;
	}
	if (items_sub.empty() == false) {
		gui::dialog d(get_display(), title + " (" + player_name_ + ")", "", gui::CLOSE_ONLY);
		d.set_menu(items_sub);
		d.show();
		dp_info.clear_buttons();
		set_result(gui::CONTINUE_DIALOG);
	}
}
Exemple #2
0
void statistics_dialog::action(gui::dialog_process_info &dp_info)
{
	int sel = get_menu().selection();
	bool has_details = sel < 5 && sel >= 0 && unit_count_[sel] > 0;
	detail_btn_->enable(has_details);
	if(dp_info.double_clicked && has_details) {
		set_result(sel);
	} else if(dp_info.new_key_down && !dp_info.key_down) {
		set_result(gui::CLOSE_DIALOG);
	}

	// Prepare the sub-dialog for Statistic Details
	std::string title;
	std::vector<std::string> items_sub;
	switch(result()) {
	case gui::CLOSE_DIALOG:
		break;
	case 0:
		items_sub = create_unit_table(current_stats().recruits, team_num_);
		title = _("Recruits");
		break;
	case 1:
		items_sub = create_unit_table(current_stats().recalls, team_num_);
		title = _("Recalls");
		break;
	case 2:
		items_sub = create_unit_table(current_stats().advanced_to, team_num_);
		title = _("Advancements");
		break;
	case 3:
		items_sub = create_unit_table(current_stats().deaths, team_num_);
		title = _("Losses");
		break;
	case 4:
		// Give kills a (probably) different team color.
		items_sub = create_unit_table(current_stats().killed, team_num_ == 1 ? 2 : 1);
		title = _("Kills");
		break;

	case BUTTON_SCENE:
		// Scenario selection.
		do_scene_selection();
		set_result(gui::CONTINUE_DIALOG);
		break;
	case BUTTON_TOGGLE:
		// Toggle between campaign and scenario stats.
		display_stats(!use_campaign_);
		set_result(gui::CONTINUE_DIALOG);
		break;

	default:
		break;
	}
	if (items_sub.empty() == false) {
		gui::dialog d(get_video(), title + " (" + player_name_ + ")", "", gui::CLOSE_ONLY);
		d.set_menu(items_sub);
		d.show();
		dp_info.clear_buttons();
		set_result(gui::CONTINUE_DIALOG);
	}
}
Exemple #3
0
void file_dialog::action(gui::dialog_process_info &dp_info) {
	if(result() == gui::CLOSE_DIALOG)
		return;

	//handle "delete item" requests
	if(result() == gui::DELETE_ITEM)
	{
		if(!chosen_file_.empty())
		{
			if(files_list_->delete_chosen_file() == -1) {
				gui2::show_transient_error_message(get_display().video()
						, _("Deletion of the file failed."));
				dp_info.clear_buttons();
			} else {
				dp_info.first_time = true;
			}
		}
		set_result(gui::CONTINUE_DIALOG);
	}
	//handle "create item" requests
	else if(result() == gui::CREATE_ITEM)
	{
		std::string new_dir_name = "";
		if(gui2::tfolder_create::execute(new_dir_name, get_display().video()))
		{
			if( !files_list_->make_directory(new_dir_name) ) {
				gui2::show_transient_error_message(get_display().video()
						, _("Creation of the directory failed."));
			} else {
				dp_info.first_time = true;
			}
		}
		dp_info.clear_buttons();
		set_result(gui::CONTINUE_DIALOG);
	}

	//update the chosen file
	if((dp_info.selection != last_selection_
		|| dp_info.first_time
		|| dp_info.double_clicked)
			&& (!files_list_->type_a_head()
				|| dp_info.new_left_button))
	{
		files_list_->reset_type_a_head();

		chosen_file_ = files_list_->get_choice();
		get_textbox().set_text(format_filename(chosen_file_));
		last_selection_ = (dp_info.double_clicked) ? -1 : dp_info.selection;
		last_textbox_text_ = textbox_text();
	}
	else if(textbox_text() != last_textbox_text_)
	{
		chosen_file_ = unformat_filename(textbox_text());
		last_textbox_text_ = textbox_text();

		// Do type-a-head search in listbox
        if (autocomplete_) {
		    files_list_->select_file(textbox_text());
        }
	}

	if(result() >=0) {
		//if a directory has been chosen, enter it
		if(files_list_->is_directory(chosen_file_))
		{
			files_list_->change_directory(chosen_file_);
			get_message().set_text(format_dirname(files_list_->get_directory()));

			//reset the chosen file
			chosen_file_ = "..";
			get_textbox().set_text(format_filename(chosen_file_));
			set_result(gui::CONTINUE_DIALOG);
		}
		//if a file has been chosen, return button index "Ok"
		else
		{
			set_result(0);
		}
	}
}