コード例 #1
0
void scenario_settings_table(display& gui, int selected)
{
	std::stringstream heading;
	heading << HEADING_PREFIX << _("scenario settings^Leader") << COLUMN_SEPARATOR
			<< COLUMN_SEPARATOR
			<< _("scenario settings^Side")              << COLUMN_SEPARATOR
			<< _("scenario settings^Start\nGold")       << COLUMN_SEPARATOR
			<< _("scenario settings^Base\nIncome")      << COLUMN_SEPARATOR
			<< _("scenario settings^Gold Per\nVillage") << COLUMN_SEPARATOR
			<< _("scenario settings^Support Per\nVillage") << COLUMN_SEPARATOR
			<< _("scenario settings^Fog")               << COLUMN_SEPARATOR
			<< _("scenario settings^Shroud");

	gui::menu::basic_sorter sorter;
	sorter.set_redirect_sort(0,1).set_alpha_sort(1).set_numeric_sort(2)
		  .set_numeric_sort(3).set_numeric_sort(4).set_numeric_sort(5)
		  .set_numeric_sort(6).set_alpha_sort(7).set_alpha_sort(8);

	std::vector<std::string> items;
	std::vector<bool> leader_bools;
	items.push_back(heading.str());

	//const gamemap& map = gui.get_map();
	const unit_map& units = gui.get_units();
	const std::vector<team>& teams = gui.get_teams();

	const team& viewing_team = teams[gui.viewing_team()];
	bool settings_table_empty = true;
	bool fogged;

	for(size_t n = 0; n != teams.size(); ++n) {
		if(teams[n].hidden()) {
			continue;
		}
		settings_table_empty = false;

		std::stringstream str;
		unit_map::const_iterator leader = units.find_leader(n + 1);

		if(leader != units.end()) {
			// Add leader image. If it's fogged
			// show only a random leader image.
			fogged=viewing_team.fogged(leader->get_location());
			if (!fogged || viewing_team.knows_about_team(n, network::nconnections() > 0) || game_config::debug) {
				str << IMAGE_PREFIX << leader->absolute_image();
				leader_bools.push_back(true);
			} else {
				str << IMAGE_PREFIX << std::string("units/unknown-unit.png");
				leader_bools.push_back(false);
			}
#ifndef LOW_MEM
			str << "~RC(" << leader->team_color() << '>'
			    << team::get_side_color_index(n+1) << ")";
#endif
		} else {
			leader_bools.push_back(false);
		}

		str << COLUMN_SEPARATOR	<< team::get_side_highlight(n)
			<< teams[n].current_player() << COLUMN_SEPARATOR
			<< n + 1 << COLUMN_SEPARATOR
			<< teams[n].start_gold() << COLUMN_SEPARATOR
			<< teams[n].base_income() << COLUMN_SEPARATOR
			<< teams[n].village_gold() << COLUMN_SEPARATOR
			<< teams[n].village_support() << COLUMN_SEPARATOR
			<< (teams[n].uses_fog()    ? _("yes") : _("no")) << COLUMN_SEPARATOR
			<< (teams[n].uses_shroud() ? _("yes") : _("no")) << COLUMN_SEPARATOR;

		items.push_back(str.str());
	}

	if (settings_table_empty)
	{
		// no sides to show - display empty table
		std::stringstream str;
		for (int i=0;i<8;++i)
			str << " " << COLUMN_SEPARATOR;
		leader_bools.push_back(false);
		items.push_back(str.str());
	}
	int result = 0;
	{
		leader_scroll_dialog slist(gui, _("Scenario Settings"), leader_bools, selected, gui::DIALOG_BACK);
		slist.set_menu(items, &sorter);
		slist.get_menu().move_selection(selected);
		slist.add_button(new gui::dialog_button(gui.video(), _(" < Back"),
				gui::button::TYPE_PRESS, gui::DIALOG_BACK),
				gui::dialog::BUTTON_EXTRA_LEFT);
		result = slist.show();
		selected = slist.get_menu().selection();
	} // this will kill the dialog before scrolling

	if (result >= 0) {
		//TODO
		//gui_->scroll_to_leader(units_, selected+1);
	}
	else if (result == gui::DIALOG_BACK)
		status_table(gui, selected);
}
コード例 #2
0
void status_table(display& gui, int selected)
{
	std::stringstream heading;
	heading << HEADING_PREFIX << _("Leader") << COLUMN_SEPARATOR << ' ' << COLUMN_SEPARATOR
			<< _("Team")         << COLUMN_SEPARATOR
			<< _("Gold")         << COLUMN_SEPARATOR
			<< _("Villages")     << COLUMN_SEPARATOR
			<< _("status^Units") << COLUMN_SEPARATOR
			<< _("Upkeep")       << COLUMN_SEPARATOR
			<< _("Income");

	gui::menu::basic_sorter sorter;
	sorter.set_redirect_sort(0,1).set_alpha_sort(1).set_alpha_sort(2).set_numeric_sort(3)
		  .set_numeric_sort(4).set_numeric_sort(5).set_numeric_sort(6).set_numeric_sort(7);

	std::vector<std::string> items;
	std::vector<bool> leader_bools;
	items.push_back(heading.str());

	const gamemap& map = gui.get_map();
	const unit_map& units = gui.get_units();
	assert(&gui.get_teams() == resources::teams);
	const std::vector<team>& teams = gui.get_teams();

	const team& viewing_team = teams[gui.viewing_team()];

	unsigned total_villages = 0;
	// a variable to check if there are any teams to show in the table
	bool status_table_empty = true;

	//if the player is under shroud or fog, they don't get
	//to see details about the other sides, only their own
	//side, allied sides and a ??? is shown to demonstrate
	//lack of information about the other sides But he see
	//all names with in colors
	for(size_t n = 0; n != teams.size(); ++n) {
		if(teams[n].hidden()) {
			continue;
		}
		status_table_empty=false;

		const bool known = viewing_team.knows_about_team(n, network::nconnections() > 0);
		const bool enemy = viewing_team.is_enemy(n+1);

		std::stringstream str;

		const team_data data = gui.get_disp_context().calculate_team_data(teams[n],n+1);

		unit_map::const_iterator leader = units.find_leader(n + 1);
		std::string leader_name;
		//output the number of the side first, and this will
		//cause it to be displayed in the correct color
		if(leader != units.end()) {
			const bool fogged = viewing_team.fogged(leader->get_location());
			// Add leader image. If it's fogged
			// show only a random leader image.
			if (!fogged || known || game_config::debug) {
				str << IMAGE_PREFIX << leader->absolute_image();
				leader_bools.push_back(true);
				leader_name = leader->name();
			} else {
				str << IMAGE_PREFIX << std::string("units/unknown-unit.png");
				leader_bools.push_back(false);
				leader_name = "Unknown";
			}
	//	if (gamestate_.classification().campaign_type == game_classification::MULTIPLAYER)
	//			leader_name = teams[n].current_player();

#ifndef LOW_MEM
			str << leader->image_mods();
#endif
		} else {
			leader_bools.push_back(false);
		}
		str << COLUMN_SEPARATOR	<< team::get_side_highlight(n)
			<< leader_name << COLUMN_SEPARATOR
			<< (data.teamname.empty() ? teams[n].team_name() : data.teamname)
			<< COLUMN_SEPARATOR;

		if(!known && !game_config::debug) {
			// We don't spare more info (only name)
			// so let's go on next side ...
			items.push_back(str.str());
			continue;
		}

		if(game_config::debug) {
			str << utils::half_signed_value(data.gold) << COLUMN_SEPARATOR;
		} else if(enemy && viewing_team.uses_fog()) {
			str << ' ' << COLUMN_SEPARATOR;
		} else {
			str << utils::half_signed_value(data.gold) << COLUMN_SEPARATOR;
		}
		str << data.villages;
                if(!(viewing_team.uses_fog() || viewing_team.uses_shroud())) {
                        str << "/" << map.villages().size();
                }
		str << COLUMN_SEPARATOR
			<< data.units << COLUMN_SEPARATOR << data.upkeep << COLUMN_SEPARATOR
			<< (data.net_income < 0 ? font::BAD_TEXT : font::NULL_MARKUP) << utils::signed_value(data.net_income);
		total_villages += data.villages;
		items.push_back(str.str());
	}
	if (total_villages > map.villages().size()) {
		//TODO
//		ERR_NG << "Logic error: map has " << map.villages().size()
//				<< " villages but status table shows " << total_villages << " owned in total\n";
	}

	if (status_table_empty)
	{
		// no sides to show - display empty table
		std::stringstream str;
		str << " ";
		for (int i=0;i<7;++i)
			str << COLUMN_SEPARATOR << " ";
		leader_bools.push_back(false);
		items.push_back(str.str());
	}
	int result = 0;
	{
		leader_scroll_dialog slist(gui, _("Current Status"), leader_bools, selected, gui::DIALOG_FORWARD);
		slist.add_button(new gui::dialog_button(gui.video(), _("More >"),
												 gui::button::TYPE_PRESS, gui::DIALOG_FORWARD),
												 gui::dialog::BUTTON_EXTRA_LEFT);
		slist.set_menu(items, &sorter);
		slist.get_menu().move_selection(selected);
		result = slist.show();
		selected = slist.get_menu().selection();
	} // this will kill the dialog before scrolling

	if (result >= 0) {
		//TODO
	//	gui.scroll_to_leader(units_, selected+1);
	}
	else if (result == gui::DIALOG_FORWARD)
		scenario_settings_table(gui, selected);
}
コード例 #3
0
ファイル: dialogs.cpp プロジェクト: justinzane/wesnoth-ng
void show_unit_list(display& gui)
{
	const std::string heading = std::string(1,HEADING_PREFIX) +
			_("Type")          + COLUMN_SEPARATOR + // 0
			_("Name")          + COLUMN_SEPARATOR + // 1
			_("Moves")         + COLUMN_SEPARATOR + // 2
			_("Status")        + COLUMN_SEPARATOR + // 3
			_("HP")            + COLUMN_SEPARATOR + // 4
			_("Level^Lvl.")    + COLUMN_SEPARATOR + // 5
			_("XP")            + COLUMN_SEPARATOR + // 6
			_("unit list^Traits");                  // 7

	gui::menu::basic_sorter sorter;
	sorter.set_alpha_sort(0).set_alpha_sort(1).set_numeric_sort(2);
	sorter.set_alpha_sort(3).set_numeric_sort(4).set_level_sort(5, 6);
	sorter.set_xp_sort(6).set_alpha_sort(7);

	std::vector<std::string> items;
	items.push_back(heading);

	std::vector<map_location> locations_list;
	std::vector<unit> units_list;

	int selected = 0;

	const unit_map& units = gui.get_units();

	for(unit_map::const_iterator i = units.begin(); i != units.end(); ++i) {
		if (i->side() != gui.viewing_side())
			continue;

		std::stringstream row;
		// If a unit is already selected on the map, we do the same in the unit list dialog
		if (gui.selected_hex() == i->get_location()) {
			row << DEFAULT_ITEM;
			selected = units_list.size();
		}
		// If unit is leader, show name in special color, e.g. gold/silver
		/** @todo TODO: hero just has overlay "misc/hero-icon.png" - needs an ability to query */

		if (i->can_recruit() ) {
			row << "<205,173,0>";   // gold3
		}
		row << i->type_name() << COLUMN_SEPARATOR;
		if (i->can_recruit() ) {
			row << "<205,173,0>";   // gold3
		}
		row << i->name()   << COLUMN_SEPARATOR;

		// display move left (0=red, moved=yellow, not moved=green)
		if (i->movement_left() == 0) {
			row << font::RED_TEXT;
		} else if (i->movement_left() < i->total_movement() ) {
			row << "<255,255,0>";
		} else {
			row << font::GREEN_TEXT;
		}
		row << i->movement_left() << '/' << i->total_movement() << COLUMN_SEPARATOR;

		// show icons if unit is slowed, poisoned, petrified, invisible:
		if(i->get_state(unit::STATE_PETRIFIED))
			row << IMAGE_PREFIX << "misc/petrified.png"    << IMG_TEXT_SEPARATOR;
		if(i->get_state(unit::STATE_POISONED))
			row << IMAGE_PREFIX << "misc/poisoned.png" << IMG_TEXT_SEPARATOR;
		if(i->get_state(unit::STATE_SLOWED))
			row << IMAGE_PREFIX << "misc/slowed.png"   << IMG_TEXT_SEPARATOR;
		if(i->invisible(i->get_location(),false))
			row << IMAGE_PREFIX << "misc/invisible.png";
		row << COLUMN_SEPARATOR;

		// Display HP
		// see also unit_preview_pane in dialogs.cpp
		row << font::color2markup(i->hp_color());
		row << i->hitpoints()  << '/' << i->max_hitpoints() << COLUMN_SEPARATOR;

		// Show units of level (0=gray, 1 normal, 2 bold, 2+ bold&wbright)
		int level = i->level();
		if(level < 1) {
			row << "<150,150,150>";
		} else if(level == 1) {
			row << font::NORMAL_TEXT;
		} else if(level == 2) {
			row << font::BOLD_TEXT;
		} else if(level > 2 ) {
			row << font::BOLD_TEXT << "<255,255,255>";
		}
		row << level << COLUMN_SEPARATOR;

		// Display XP
		row << font::color2markup(i->xp_color());
		row << i->experience() << "/";
		if (i->can_advance()) {
			row << i->max_experience();
		} else {
			row << "-";
		}
		row << COLUMN_SEPARATOR;

		// TODO: show 'loyal' in green / xxx in red  //  how to handle translations ??
		row << utils::join(i->trait_names(), ", ");
		items.push_back(row.str());

		locations_list.push_back(i->get_location());
		units_list.push_back(*i);
	}

	{
		dialogs::units_list_preview_pane unit_preview(units_list);
		unit_preview.set_selection(selected);

		gui::dialog umenu(gui, _("Unit List"), "", gui::NULL_DIALOG);
		umenu.set_menu(items, &sorter);
		umenu.add_pane(&unit_preview);
		//sort by type name
		umenu.get_menu().sort_by(0);

		umenu.add_button(new gui::standard_dialog_button(gui.video(), _("Scroll To"), 0, false),
				gui::dialog::BUTTON_STANDARD);
		umenu.add_button(new gui::standard_dialog_button(gui.video(), _("Close"), 1, true),
				gui::dialog::BUTTON_STANDARD);
		umenu.set_basic_behavior(gui::OK_CANCEL);
		selected = umenu.show();
	} // this will kill the dialog before scrolling

	if(selected >= 0 && selected < int(locations_list.size())) {
		const map_location& loc = locations_list[selected];
		gui.scroll_to_tile(loc,game_display::WARP);
		gui.select_hex(loc);
	}
}