Example #1
0
void play_controller::hotkey_handler::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& disp)
{
	if (context_menu)
	{
		last_context_menu_x_ = xloc;
		last_context_menu_y_ = yloc;
	}

	std::vector<std::string> items = items_arg;
	const hotkey::hotkey_command* cmd;
	std::vector<std::string>::iterator i = items.begin();
	while(i != items.end()) {
		if (*i == "AUTOSAVES") {
			// Autosave visibility is similar to LOAD_GAME hotkey
			cmd = &hotkey::hotkey_command::get_command_by_command(hotkey::HOTKEY_LOAD_GAME);
		} else {
			cmd = &hotkey::get_hotkey_command(*i);
		}
		// Remove commands that can't be executed or don't belong in this type of menu
		if(*i != "wml" && (!can_execute_command(*cmd) || (context_menu && !in_context_menu(cmd->id)))) {
			i = items.erase(i);
			continue;
		}
		++i;
	}

	// Add special non-hotkey items to the menu and remember their indices
	expand_autosaves(items);
	expand_wml_commands(items);

	if(items.empty())
		return;

	command_executor::show_menu(items, xloc, yloc, context_menu, disp);
}
void controller_base::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& disp)
{
	std::vector<std::string> items = items_arg;
	std::vector<std::string>::iterator i = items.begin();
	while(i != items.end()) {
		const hotkey::hotkey_command& command = hotkey::get_hotkey_command(*i);
		if(!can_execute_command(command)
			|| (context_menu && !in_context_menu(command.id))) {
			i = items.erase(i);
			continue;
		}
		++i;
	}
	if(items.empty())
		return;
	command_executor::show_menu(items, xloc, yloc, context_menu, disp);
}
Example #3
0
void play_controller::hotkey_handler::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& disp)
{
	if (context_menu)
	{
		last_context_menu_x_ = xloc;
		last_context_menu_y_ = yloc;
	}

	std::vector<std::string> items = items_arg;
	const hotkey::hotkey_command* cmd;
	std::vector<std::string>::iterator i = items.begin();
	while(i != items.end()) {
		if (*i == "AUTOSAVES") {
			// Autosave visibility is similar to LOAD_GAME hotkey
			cmd = &hotkey::hotkey_command::get_command_by_command(hotkey::HOTKEY_LOAD_GAME);
		} else {
			cmd = &hotkey::get_hotkey_command(*i);
		}
		// Remove WML commands if they would not be allowed here
		if(*i == "wml") {
			if(!context_menu || !viewing_team_is_playing()
			|| events::commands_disabled || !viewing_team().is_local_human()
			|| (linger() && !game_config::debug)){
				i = items.erase(i);
				continue;
			}
		// Remove commands that can't be executed or don't belong in this type of menu
		} else if(!can_execute_command(*cmd)
			|| (context_menu && !in_context_menu(cmd->id))) {
			i = items.erase(i);
			continue;
		}
		++i;
	}

	// Add special non-hotkey items to the menu and remember their indices
	expand_autosaves(items);
	expand_wml_commands(items);

	if(items.empty())
		return;

	command_executor::show_menu(items, xloc, yloc, context_menu, disp);
}