Exemplo n.º 1
0
/**
 * Display list of ego items to be ignored.
 */
static void ego_menu(const char *unused, int also_unused)
{
	int max_num = 0;
	struct ego_item *ego;
	struct ego_desc *choice;

	struct menu menu;
	menu_iter menu_f = { 0, 0, ego_display, ego_action, 0 };
	region area = { 1, 5, -1, -1 };
	int cursor = 0;

	int i;

	/* Create the array */
	choice = mem_zalloc(z_info->e_max * ITYPE_MAX * sizeof(struct ego_desc));

	/* Get the valid ego-items */
	for (i = 0; i < z_info->e_max; i++) {
		int itype;
		ego = &e_info[i];

		/* Only valid known ego-items allowed */
		if (!ego->name || !ego->everseen)
			continue;

		/* Find appropriate ignore types */
		for (itype = ITYPE_NONE + 1; itype < ITYPE_MAX; itype++)
			if (ego_has_ignore_type(ego, itype)) {

				/* Fill in the details */
				choice[max_num].e_idx = i;
				choice[max_num].itype = itype;
				choice[max_num].short_name = strip_ego_name(ego->name);

				++max_num;
			}
	}

	/* Quickly sort the array by ego-item name */
	qsort(choice, max_num, sizeof(choice[0]), ego_comp_func);

	/* Return here if there are no objects */
	if (!max_num) {
		mem_free(choice);
		return;
	}


	/* Save the screen and clear it */
	screen_save();
	clear_from(0);

	/* Help text */
	prt("Ego item ignore menu", 0, 0);

	/* Output to the screen */
	text_out_hook = text_out_to_screen;

	/* Indent output */
	text_out_indent = 1;
	text_out_wrap = 79;
	Term_gotoxy(1, 1);

	/* Display some helpful information */
	text_out_e(EGO_MENU_HELPTEXT);

	text_out_indent = 0;

	/* Set up the menu */
	memset(&menu, 0, sizeof(menu));
	menu_init(&menu, MN_SKIN_SCROLL, &menu_f);
	menu_setpriv(&menu, max_num, choice);
	menu_layout(&menu, &area);

	/* Select an entry */
	(void) menu_select(&menu, cursor, false);

	/* Free memory */
	mem_free(choice);

	/* Load screen */
	screen_load();

	return;
}
Exemplo n.º 2
0
/**
 * Display list of ego items to be ignored.
 */
static void ego_menu(const char *unused, int also_unused)
{
	int max_num = 0;
	ego_item_type *ego;
	ego_desc *choice;
	struct ego_poss_item *poss;

	struct menu menu;
	menu_iter menu_f = { 0, 0, ego_display, ego_action, 0 };
	region area = { 1, 5, -1, -1 };
	int cursor = 0;

	int i;

	/* Create the array */
	choice = mem_zalloc(z_info->e_max * sizeof(ego_desc));

	/* Get the valid ego-items */
	for (i = 0; i < z_info->e_max; i++) {
		int itype, tval;
		int tval_table[TV_MAX] = { 0 };
		ego = &e_info[i];

		/* Only valid known ego-items allowed */
		if (!ego->name || !ego->everseen)
			continue;

		/* Note the tvals which are possible for this ego */
		for (poss = ego->poss_items; poss; poss = poss->next) {
			object_kind *kind = &k_info[poss->kidx];
			tval_table[kind->tval]++;
		}

		/* Find appropriate ignore types */
		for (itype = ITYPE_NONE; itype < ITYPE_MAX; itype++)
			for (tval = 1; tval < TV_MAX; tval++) {
				/* Skip invalid types */
				if (!tval_table[tval]) continue;
				if (tval_has_ignore_type(tval, itype)) {

					/* Fill in the details */
					choice[max_num].e_idx = i;
					choice[max_num].itype = itype;
					choice[max_num].short_name = strip_ego_name(ego->name);

					++max_num;

					/* Done with this tval */
					break;
				}
			}
	}

	/* Quickly sort the array by ego-item name */
	qsort(choice, max_num, sizeof(choice[0]), ego_comp_func);

	/* Return here if there are no objects */
	if (!max_num) {
		mem_free(choice);
		return;
	}


	/* Save the screen and clear it */
	screen_save();
	clear_from(0);

	/* Help text */
	prt("Ego item ignore menu", 0, 0);

	/* Output to the screen */
	text_out_hook = text_out_to_screen;

	/* Indent output */
	text_out_indent = 1;
	text_out_wrap = 79;
	Term_gotoxy(1, 1);

	/* Display some helpful information */
	text_out_e(EGO_MENU_HELPTEXT);

	text_out_indent = 0;

	/* Set up the menu */
	memset(&menu, 0, sizeof(menu));
	menu_init(&menu, MN_SKIN_SCROLL, &menu_f);
	menu_setpriv(&menu, max_num, choice);
	menu_layout(&menu, &area);

	/* Select an entry */
	(void) menu_select(&menu, cursor, FALSE);

	/* Free memory */
	mem_free(choice);

	/* Load screen */
	screen_load();

	return;
}