void statistics_dialog::update_lists(window& window)
{
	//
	// Update primary stats list
	//
	listbox& stat_list = find_widget<listbox>(&window, "stats_list_main", false);

	stat_list.clear();
	main_stat_table_.clear();

	const statistics::stats& stats = current_stats();

	add_stat_row(window, _("Recruits"),     stats.recruits);
	add_stat_row(window, _("Recalls"),      stats.recalls);
	add_stat_row(window, _("Advancements"), stats.advanced_to, false);
	add_stat_row(window, _("Losses"),       stats.deaths);
	add_stat_row(window, _("Kills"),        stats.killed);

	// Update unit count list
	on_primary_list_select(window);

	//
	// Update damage stats list
	//
	const bool show_this_turn = use_campaign || scenario_index_ + 1 == scenarios_.size();

	listbox& damage_list = find_widget<listbox>(&window, "stats_list_damage", false);

	damage_list.clear();

	add_damage_row(window, _("Inflicted"),
		stats.damage_inflicted,
		stats.expected_damage_inflicted,
		stats.turn_damage_inflicted,
		stats.turn_expected_damage_inflicted,
		show_this_turn
	);

	add_damage_row(window, _("Taken"),
		stats.damage_taken,
		stats.expected_damage_taken,
		stats.turn_damage_taken,
		stats.turn_expected_damage_taken,
		show_this_turn
	);
}
Esempio n. 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);
	}
}
Esempio n. 3
0
/**
 * Fills in the text to be displayed in the dialog.
 * This also updates the scenario/campaign toggle button.
 *
 * @param[in]  campaign  Indicates whether or not the campaign stats are to
 *                       be displayed.
 */
void statistics_dialog::display_stats(bool campaign)
{
	// Record which stats we will display.
	use_campaign_ = campaign;
	const statistics::stats & stats = current_stats();
	const bool show_this_turn =
		use_campaign_ || scenario_index_ + 1 == scenarios_.size();

	int n, cost;
	std::vector<std::string> items;
	// The heading for the menu items:
	{
		std::stringstream str;
		str << HEADING_PREFIX
		    << COLUMN_SEPARATOR
		    << font::BOLD_TEXT << (use_campaign_ ? _("Campaign") : _("Scenario"));
		items.push_back(str.str());
	}
	// Prepare the menu items
	{
		std::stringstream str;
		n = statistics::sum_str_int_map(stats.recruits);
		cost = stats.recruit_cost;
		unit_count_[0] = n;
		str << _("Recruits") << COLUMN_SEPARATOR << n
		    << COLUMN_SEPARATOR
		    << COLUMN_SEPARATOR << IMAGE_PREFIX << "themes/gold.png"
		    << COLUMN_SEPARATOR << cost;
		items.push_back(str.str());
	}
	{
		std::stringstream str;
		n = statistics::sum_str_int_map(stats.recalls);
		cost = stats.recall_cost;
		unit_count_[1] = n;
		str << _("Recalls") << COLUMN_SEPARATOR << n
		    << COLUMN_SEPARATOR
		    << COLUMN_SEPARATOR << IMAGE_PREFIX << "themes/gold.png"
		    << COLUMN_SEPARATOR << cost;
		items.push_back(str.str());
	}
	{
		std::stringstream str;
		n = statistics::sum_str_int_map(stats.advanced_to);
		unit_count_[2] = n;
		str << _("Advancements") << COLUMN_SEPARATOR << n;
		items.push_back(str.str());
	}
	{
		std::stringstream str;
		n = statistics::sum_str_int_map(stats.deaths);
		unit_count_[3] = n;
		cost = statistics::sum_cost_str_int_map(stats.deaths);
		str << _("Losses") << COLUMN_SEPARATOR << n
		    << COLUMN_SEPARATOR
		    << COLUMN_SEPARATOR << IMAGE_PREFIX << "themes/gold.png"
		    << COLUMN_SEPARATOR << cost;
		items.push_back(str.str());
	}
	{
		std::stringstream str;
		n = statistics::sum_str_int_map(stats.killed);
		unit_count_[4] = n;
		cost = statistics::sum_cost_str_int_map(stats.killed);
		str << _("Kills") << COLUMN_SEPARATOR << n
		    << COLUMN_SEPARATOR
		    << COLUMN_SEPARATOR << IMAGE_PREFIX << "themes/gold.png"
		    << COLUMN_SEPARATOR << cost;
		items.push_back(str.str());
	}
	items.push_back("");
	{
		std::stringstream str;
		str << font::BOLD_TEXT << _("Damage")
		    << COLUMN_SEPARATOR << _("Overall");
		if ( show_this_turn ) {
			str << COLUMN_SEPARATOR
			    << COLUMN_SEPARATOR
			    << COLUMN_SEPARATOR << _("This Turn");
		}
		items.push_back(str.str());
	}

	make_damage_line(items, _("Inflicted"),
	                 stats.damage_inflicted, stats.expected_damage_inflicted,
	                 stats.turn_damage_inflicted, stats.turn_expected_damage_inflicted,
	                 show_this_turn);
	make_damage_line(items, _("Taken"),
	                 stats.damage_taken, stats.expected_damage_taken,
	                 stats.turn_damage_taken, stats.turn_expected_damage_taken,
	                 show_this_turn);

	set_menu_items(items, true);
	toggle_btn_->set_label(use_campaign_ ? _("Scenario") : _("Campaign"));
	scene_btn_->enable(!use_campaign_);
}