示例#1
0
/**
 * Returns the menu items that can be shown for the given location.
 * Should be used with a wmi_pager to limit the number of items displayed at once.
 * @param[out] items        Pointers to applicable menu items will be pushed onto @a items.
 * @param[out] descriptions Menu item text will be pushed onto @descriptions (in the same order as @a items).
 */
std::vector<std::pair<boost::shared_ptr<const wml_menu_item>, std::string> > wmi_container::get_items(const map_location& hex,
	game_data & gamedata, filter_context & fc, unit_map & units, const_iterator start, const_iterator finish) const
{
	std::vector<std::pair<boost::shared_ptr<const wml_menu_item>, std::string> > ret;
	if ( empty() ) {
		// Nothing to do (skip setting game variables).
		return ret;
	}
	// Prepare for can show().
	gamedata.get_variable("x1") = hex.x + 1;
	gamedata.get_variable("y1") = hex.y + 1;
	scoped_xy_unit highlighted_unit("unit", hex.x, hex.y, units);

	// Check each menu item.
	BOOST_FOREACH( const item_ptr & item, std::make_pair (start, finish) )
	{
		// Can this item be shown?
		if ( item->use_wml_menu() && (!item->is_synced() || resources::controller->can_use_synced_wml_menu()) && item->can_show(hex, gamedata, fc) )
		{
			// Include this item.
			ret.push_back(std::make_pair(item, item->menu_text()));
		}
	}
	return ret;
}
示例#2
0
/**
 * Returns the menu items that can be shown for the given location.
 * The number of items returned is limited by MAX_WML_COMMANDS.
 * @param[out] items        Pointers to applicable menu items will be pushed onto @a items.
 * @param[out] descriptions Menu item text will be pushed onto @descriptions (in the same order as @a items).
 */
void wmi_container::get_items(const map_location& hex,
                              std::vector<boost::shared_ptr<const wml_menu_item> > & items,
                              std::vector<std::string> & descriptions) const
{
	size_t item_count = 0;

	if ( empty() )
		// Nothing to do (skip setting game variables).
		return;

	// Prepare for can show().
	resources::gamedata->get_variable("x1") = hex.x + 1;
	resources::gamedata->get_variable("y1") = hex.y + 1;
	scoped_xy_unit highlighted_unit("unit", hex.x, hex.y, *resources::units);

	// Check each menu item.
	BOOST_FOREACH( const item_ptr & item, *this )
	{
		// Can this item be shown?
		if ( item->use_wml_menu() && item->can_show(hex) )
		{
			// Include this item.
			items.push_back(item);
			descriptions.push_back(item->menu_text());

			// Limit how many items can be returned.
			if ( ++item_count >= MAX_WML_COMMANDS )
				return;
		}
	}
}
示例#3
0
/**
 * Fires the menu item with the given @a id.
 * @returns true if a matching item was found (even if it could not be fired).
 * NOTE: The return value could be altered if it is decided that
 * play_controller::execute_command() needs something different.
 */
bool wmi_container::fire_item(const std::string & id, const map_location & hex) const
{
	// Does this item exist?
	const_iterator iter = find(id);
	if ( iter == end() )
		return false;
	const wml_menu_item & wmi = **iter;

	// Prepare for can show().
	resources::gamedata->get_variable("x1") = hex.x + 1;
	resources::gamedata->get_variable("y1") = hex.y + 1;
	scoped_xy_unit highlighted_unit("unit", hex.x, hex.y, *resources::units);

	// Can this item be shown?
	if ( wmi.can_show(hex) )
		wmi.fire_event(hex);

	return true;
}
示例#4
0
/**
 * Fires the menu item with the given @a id.
 * @returns true if a matching item was found (even if it could not be fired).
 * NOTE: The return value could be altered if it is decided that
 * play_controller::execute_command() needs something different.
 */
bool wmi_container::fire_item(const std::string & id, const map_location & hex, game_data & gamedata, filter_context & fc, unit_map & units) const
{
	// Does this item exist?
	const_iterator iter = find(id);
	if ( iter == end() ) {
		return false;
	}
	const wml_menu_item & wmi = **iter;

	// Prepare for can show().
	gamedata.get_variable("x1") = hex.x + 1;
	gamedata.get_variable("y1") = hex.y + 1;
	scoped_xy_unit highlighted_unit("unit", hex.x, hex.y, units);

	// Can this item be shown?
	if ( wmi.can_show(hex, gamedata, fc) ) {
		wmi.fire_event(hex, gamedata);
	}
	return true;
}