Beispiel #1
0
/**
 * Displays an option entry.
 */
static void option_toggle_display(struct menu *m, int oid, bool cursor,
		int row, int col, int width)
{
	byte attr = curs_attrs[CURS_KNOWN][cursor != 0];
	bool *options = menu_priv(m);

	c_prt(attr, format("%-45s: %s  (%s)", option_desc(oid),
			options[oid] ? "yes" : "no ", option_name(oid)), row, col);
}
Beispiel #2
0
/*
 * Write all current options to a user preference file.
 */
void option_dump(ang_file * fff)
{
	int i, j;

	/* Dump interface and gameplay options */
	for (i = 0; i < OPT_MAX; i++) {
		const char *name = option_name(i);
		int type = option_type(i);
		if ((type != OP_GAMEPLAY) && (type != OP_INTERFACE))
			continue;

		/* Comment */
		file_putf(fff, "# Option '%s'\n", option_desc(i));

		/* Dump the option */
		if (op_ptr->opt[i])
			file_putf(fff, "Y:%s\n", name);
		else
			file_putf(fff, "X:%s\n", name);

		/* Skip a line */
		file_putf(fff, "\n");
	}

	/* Dump window flags */
	for (i = 1; i < ANGBAND_TERM_MAX; i++) {
		/* Require a real window */
		if (!angband_term[i])
			continue;

		/* Check each flag */
		for (j = 0; j < (int) N_ELEMENTS(window_flag_desc); j++) {
			/* Require a real flag */
			if (!window_flag_desc[j])
				continue;

			/* Comment */
			file_putf(fff, "# Window '%s', Flag '%s'\n",
					  angband_term_name[i], window_flag_desc[j]);

			/* Dump the flag */
			if (op_ptr->window_flag[i] & (1L << j))
				file_putf(fff, "W:%d:%d:1\n", i, j);
			else
				file_putf(fff, "W:%d:%d:0\n", i, j);

			/* Skip a line */
			file_putf(fff, "\n");
		}
	}

	autoinsc_dump(fff);
	keymap_dump(fff);
}
Beispiel #3
0
/*
 * Write all current options to a user preference file.
 */
void option_dump(ang_file * fff)
{
	int i, j;

	/* Dump options (skip cheat, adult, score) */
	for (i = 0; i < OPT_CHEAT; i++) {
		const char *name = option_name(i);
		if (!name)
			continue;

		/* Comment */
		file_putf(fff, "# Option '%s'\n", option_desc(i));

		/* Dump the option */
		if (op_ptr->opt[i])
			file_putf(fff, "Y:%s\n", name);
		else
			file_putf(fff, "X:%s\n", name);

		/* Skip a line */
		file_putf(fff, "\n");
	}

	/* Dump window flags */
	for (i = 1; i < ANGBAND_TERM_MAX; i++) {
		/* Require a real window */
		if (!angband_term[i])
			continue;

		/* Check each flag */
		for (j = 0; j < (int) N_ELEMENTS(window_flag_desc); j++) {
			/* Require a real flag */
			if (!window_flag_desc[j])
				continue;

			/* Comment */
			file_putf(fff, "# Window '%s', Flag '%s'\n",
					  angband_term_name[i], window_flag_desc[j]);

			/* Dump the flag */
			if (op_ptr->window_flag[i] & (1L << j))
				file_putf(fff, "W:%d:%d:1\n", i, j);
			else
				file_putf(fff, "W:%d:%d:0\n", i, j);

			/* Skip a line */
			file_putf(fff, "\n");
		}
	}

	autoinsc_dump(fff);
	keymap_dump(fff);
}
Beispiel #4
0
void game::show_options()
{
 int iMaxX = (VIEWX < 12) ? 80 : (VIEWX*2)+56;
 int iMaxY = (VIEWY < 12) ? 25 : (VIEWY*2)+1;

 WINDOW* w_options_border = newwin(25, 80, (iMaxY > 25) ? (iMaxY-25)/2 : 0, (iMaxX > 80) ? (iMaxX-80)/2 : 0);
 WINDOW* w_options = newwin(23, 78, 1 + (int)((iMaxY > 25) ? (iMaxY-25)/2 : 0), 1 + (int)((iMaxX > 80) ? (iMaxX-80)/2 : 0));

 int offset = 1;
 int line = 0;
 char ch = ' ';
 bool changed_options = false;
 bool needs_refresh = true;
 do {
  wborder(w_options_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
                            LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX);
  mvwprintz(w_options_border, 0, 36, c_ltred, " OPTIONS ");
  wrefresh(w_options_border);

// TODO: change instructions
  if (needs_refresh) {
    werase(w_options);
    mvwprintz(w_options, 0, 40, c_white, "Use up/down keys to scroll through");
    mvwprintz(w_options, 1, 40, c_white, "available options.");
    mvwprintz(w_options, 2, 40, c_white, "Use left/right keys to toggle.");
    mvwprintz(w_options, 3, 40, c_white, "Press ESC or q to return.             ");
// highlight options for option descriptions
    std::string tmp = option_desc(option_key(offset + line));
    std::string out;
    size_t pos;
    int displayline = 5;
    do {
      pos = tmp.find_first_of('\n');
      out = tmp.substr(0, pos);
      mvwprintz(w_options, displayline, 40, c_white, out.c_str());
      tmp = tmp.substr(pos + 1);
      displayline++;
    } while (pos != std::string::npos && displayline < 12);
   needs_refresh = false;
  }

// Clear the lines
  for (int i = 0; i < 25; i++)
   mvwprintz(w_options, i, 0, c_black, "                                        ");
  int valid_option_count = 0;

// display options
  for (int i = 0; i < 25 && offset + i < NUM_OPTION_KEYS; i++)
  {
       valid_option_count++;
       mvwprintz(w_options, i, 0, c_white, "%s: ",
                option_name( option_key(offset + i) ).c_str());

      if (option_is_bool(option_key(offset + i)))
      {
        bool on = OPTIONS[ option_key(offset + i) ];
        if (i == line)
          mvwprintz(w_options, i, 30, hilite(c_ltcyan), (on ? "True" : "False"));
        else
          mvwprintz(w_options, i, 30, (on ? c_ltgreen : c_ltred), (on ? "True" : "False"));
      } else {
        char option_val = OPTIONS[ option_key(offset + i) ];
        if (i == line)
          mvwprintz(w_options, i, 30, hilite(c_ltcyan), "%d", option_val );
        else
          mvwprintz(w_options, i, 30, c_ltgreen, "%d", option_val );
      }
  }
  wrefresh(w_options);
  refresh();
  ch = input();
  needs_refresh = true;
  refresh();

 switch (ch) {
// move up and down
  case 'j':
   line++;
   if (line == NUM_OPTION_KEYS - 1)
    line = 0;
   break;
  case 'k':
   line--;
   if (line < 0)
    line = NUM_OPTION_KEYS - 2;
   break;
// toggle options with left/right keys
  case 'h':
      if (option_is_bool(option_key(offset + line)))
        OPTIONS[ option_key(offset + line) ] = !(OPTIONS[ option_key(offset + line) ]);
      else
      {
        OPTIONS[ option_key(offset + line) ]--;
        if ((OPTIONS[ option_key(offset + line) ]) < 0 )
          OPTIONS[ option_key(offset + line) ] = option_max_options(option_key(offset + line)) - 1;
      }
      changed_options = true;
  break;
  case 'l':
    if (option_is_bool(option_key(offset + line)))
      OPTIONS[ option_key(offset + line) ] = !(OPTIONS[ option_key(offset + line) ]);
    else
    {
      OPTIONS[ option_key(offset + line) ]++;
      if ((OPTIONS[ option_key(offset + line) ]) >= option_max_options(option_key(offset + line)))
        OPTIONS[ option_key(offset + line) ] = 0;
    }
    changed_options = true;
  break;
  }
 } while (ch != 'q' && ch != 'Q' && ch != KEY_ESCAPE);

 if (changed_options && query_yn(this->VIEWX, this->VIEWY, "Save changes?"))
  save_options();
 werase(w_options);
}
Beispiel #5
0
void game::show_options()
{
    WINDOW* w_options_border = newwin(25, 80, (TERMY > 25) ? (TERMY-25)/2 : 0, (TERMX > 80) ? (TERMX-80)/2 : 0);
    WINDOW* w_options = newwin(23, 78, 1 + ((TERMY > 25) ? (TERMY-25)/2 : 0), 1 + ((TERMX > 80) ? (TERMX-80)/2 : 0));

    int offset = 1;
    const int MAX_LINE = 22;
    int line = 0;
    char ch = ' ';
    bool changed_options = false;
    bool needs_refresh = true;
    wborder(w_options_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
            LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX);
    mvwprintz(w_options_border, 0, 36, c_ltred, " OPTIONS ");
    wrefresh(w_options_border);
    do {
// TODO: change instructions
        if(needs_refresh) {
            werase(w_options);
            mvwprintz(w_options, 0, 40, c_white, "Use up/down keys to scroll through");
            mvwprintz(w_options, 1, 40, c_white, "available options.");
            mvwprintz(w_options, 2, 40, c_white, "Use left/right keys to toggle.");
            mvwprintz(w_options, 3, 40, c_white, "Press ESC or q to return.             ");
// highlight options for option descriptions
            std::string tmp = option_desc(option_key(offset + line));
            std::string out;
            size_t pos;
            int displayline = 5;
            do {
                pos = tmp.find_first_of('\n');
                out = tmp.substr(0, pos);
                mvwprintz(w_options, displayline, 40, c_white, out.c_str());
                tmp = tmp.substr(pos + 1);
                displayline++;
            } while(pos != std::string::npos && displayline < 12);
            needs_refresh = false;
        }

// Clear the lines
        for(int i = 0; i < 25; i++) {
            mvwprintz(w_options, i, 0, c_black, "                                        ");
        }
        int valid_option_count = 0;

// display options
        for(int i = 0; i < 26 && offset + i < NUM_OPTION_KEYS; i++) {
            valid_option_count++;
            mvwprintz(w_options, i, 0, c_white, "%s: ",
                      option_name(option_key(offset + i)).c_str());

            if(option_is_bool(option_key(offset + i))) {
                bool on = OPTIONS[ option_key(offset + i) ];
                if(i == line) {
                    mvwprintz(w_options, i, 30, hilite(c_ltcyan), (on ? "True" : "False"));
                } else {
                    mvwprintz(w_options, i, 30, (on ? c_ltgreen : c_ltred), (on ? "True" : "False"));
                }
            } else {
                char option_val = OPTIONS[ option_key(offset + i) ];
                if(i == line) {
                    mvwprintz(w_options, i, 30, hilite(c_ltcyan), "%d", option_val);
                } else {
                    mvwprintz(w_options, i, 30, c_ltgreen, "%d", option_val);
                }
            }
        }
        wrefresh(w_options);
        ch = input();
        needs_refresh = true;

        switch(ch) {
// move up and down
        case 'j':
            line++;
            if(line > MAX_LINE/2 && offset + 1 < NUM_OPTION_KEYS - MAX_LINE) {
                ++offset;
                --line;
            }
            if(line > MAX_LINE) {
                line = 0;
                offset = 1;
            }
            break;
        case 'k':
            line--;
            if(line < MAX_LINE/2 && offset > 1) {
                --offset;
                ++line;
            }
            if(line < 0) {
                line = MAX_LINE;
                offset = NUM_OPTION_KEYS - MAX_LINE - 1;
            }
            break;
// toggle options with left/right keys
        case 'h':
            if(option_is_bool(option_key(offset + line))) {
                OPTIONS[ option_key(offset + line) ] = !(OPTIONS[ option_key(offset + line) ]);
            } else {
                OPTIONS[ option_key(offset + line) ]--;
                if((OPTIONS[ option_key(offset + line) ]) < option_min_options(option_key(offset + line))) {
                    OPTIONS[ option_key(offset + line) ] = option_max_options(option_key(offset + line)) - 1;
                }
            }
            changed_options = true;
            break;
        case 'l':
            if(option_is_bool(option_key(offset + line))) {
                OPTIONS[ option_key(offset + line) ] = !(OPTIONS[ option_key(offset + line) ]);
            } else {
                OPTIONS[ option_key(offset + line) ]++;
                if((OPTIONS[ option_key(offset + line) ]) >= option_max_options(option_key(offset + line))) {
                    OPTIONS[ option_key(offset + line) ] = option_min_options(option_key(offset + line));
                }
            }
            changed_options = true;
            break;
        }
        if(changed_options && OPTIONS[OPT_SEASON_LENGTH] < 1) { OPTIONS[OPT_SEASON_LENGTH]=option_max_options(OPT_SEASON_LENGTH)-1; }
    } while(ch != 'q' && ch != 'Q' && ch != KEY_ESCAPE);

    if(changed_options && query_yn("Save changes?")) {
        save_options();
        trigdist=(OPTIONS[OPT_CIRCLEDIST] ? true : false);
    }
    werase(w_options);
}
Beispiel #6
0
/**
 * Write a character dump
 */
void write_character_dump(ang_file *fff)
{
	int i, x, y;

	int a;
	wchar_t c;

	struct store *home = &stores[STORE_HOME];
	struct object **home_list = mem_zalloc(sizeof(struct object *) *
										   z_info->store_inven_max);
	char o_name[80];

	char buf[1024];
	char *p;

	/* Begin dump */
	file_putf(fff, "  [%s Character Dump]\n\n", buildid);

	/* Display player */
	display_player(0);

	/* Dump part of the screen */
	for (y = 1; y < 23; y++) {
		p = buf;
		/* Dump each row */
		for (x = 0; x < 79; x++) {
			/* Get the attr/char */
			(void)(Term_what(x, y, &a, &c));

			/* Dump it */
			p += wctomb(p, c);
		}

		/* Back up over spaces */
		while ((p > buf) && (p[-1] == ' ')) --p;

		/* Terminate */
		*p = '\0';

		/* End the row */
		file_putf(fff, "%s\n", buf);
	}

	/* Skip a line */
	file_putf(fff, "\n");

	/* Display player */
	display_player(1);

	/* Dump part of the screen */
	for (y = 11; y < 20; y++) {
		p = buf;
		/* Dump each row */
		for (x = 0; x < 39; x++) {
			/* Get the attr/char */
			(void)(Term_what(x, y, &a, &c));

			/* Dump it */
			p += wctomb(p, c);
		}

		/* Back up over spaces */
		while ((p > buf) && (p[-1] == ' ')) --p;

		/* Terminate */
		*p = '\0';

		/* End the row */
		file_putf(fff, "%s\n", buf);
	}

	/* Skip a line */
	file_putf(fff, "\n");

	/* Dump part of the screen */
	for (y = 11; y < 20; y++) {
		p = buf;
		/* Dump each row */
		for (x = 0; x < 39; x++) {
			/* Get the attr/char */
			(void)(Term_what(x + 40, y, &a, &c));

			/* Dump it */
			p += wctomb(p, c);
		}

		/* Back up over spaces */
		while ((p > buf) && (p[-1] == ' ')) --p;

		/* Terminate */
		*p = '\0';

		/* End the row */
		file_putf(fff, "%s\n", buf);
	}

	/* Skip some lines */
	file_putf(fff, "\n\n");


	/* If dead, dump last messages -- Prfnoff */
	if (player->is_dead) {
		i = messages_num();
		if (i > 15) i = 15;
		file_putf(fff, "  [Last Messages]\n\n");
		while (i-- > 0)
		{
			file_putf(fff, "> %s\n", message_str((s16b)i));
		}
		file_putf(fff, "\nKilled by %s.\n\n", player->died_from);
	}


	/* Dump the equipment */
	file_putf(fff, "  [Character Equipment]\n\n");
	for (i = 0; i < player->body.count; i++) {
		struct object *obj = slot_object(player, i);
		if (!obj) continue;

		object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL);
		file_putf(fff, "%c) %s\n", gear_to_label(obj), o_name);
		object_info_chardump(fff, obj, 5, 72);
	}
	file_putf(fff, "\n\n");

	/* Dump the inventory */
	file_putf(fff, "\n\n  [Character Inventory]\n\n");
	for (i = 0; i < z_info->pack_size; i++) {
		struct object *obj = player->upkeep->inven[i];
		if (!obj) break;

		object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL);
		file_putf(fff, "%c) %s\n", gear_to_label(obj), o_name);
		object_info_chardump(fff, obj, 5, 72);
	}
	file_putf(fff, "\n\n");

	/* Dump the quiver */
	file_putf(fff, "\n\n  [Character Quiver]\n\n");
	for (i = 0; i < z_info->quiver_size; i++) {
		struct object *obj = player->upkeep->quiver[i];
		if (!obj) continue;

		object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL);
		file_putf(fff, "%c) %s\n", gear_to_label(obj), o_name);
		object_info_chardump(fff, obj, 5, 72);
	}
	file_putf(fff, "\n\n");

	/* Dump the Home -- if anything there */
	store_stock_list(home, home_list, z_info->store_inven_max);
	if (home->stock_num) {
		/* Header */
		file_putf(fff, "  [Home Inventory]\n\n");

		/* Dump all available items */
		for (i = 0; i < z_info->store_inven_max; i++) {
			struct object *obj = home_list[i];
			if (!obj) break;
			object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL);
			file_putf(fff, "%c) %s\n", I2A(i), o_name);

			object_info_chardump(fff, obj, 5, 72);
		}

		/* Add an empty line */
		file_putf(fff, "\n\n");
	}

	/* Dump character history */
	dump_history(fff);
	file_putf(fff, "\n\n");

	/* Dump options */
	file_putf(fff, "  [Options]\n\n");

	/* Dump options */
	for (i = 0; i < OP_MAX; i++) {
		int opt;
		const char *title = "";
		switch (i) {
			case OP_INTERFACE: title = "User interface"; break;
			case OP_BIRTH: title = "Birth"; break;
		    default: continue;
		}

		file_putf(fff, "  [%s]\n\n", title);
		for (opt = 0; opt < OPT_MAX; opt++) {
			if (option_type(opt) != i) continue;

			file_putf(fff, "%-45s: %s (%s)\n",
			        option_desc(opt),
			        player->opts.opt[opt] ? "yes" : "no ",
			        option_name(opt));
		}

		/* Skip some lines */
		file_putf(fff, "\n");
	}

	mem_free(home_list);
}
Beispiel #7
0
/*
 * Hack -- Dump a character description file
 *
 * XXX XXX XXX Allow the "full" flag to dump additional info,
 * and trigger its usage from various places in the code.
 */
errr file_character(const char *path, bool full)
{
	int i, x, y;

	int a;
	wchar_t c;

	ang_file *fp;

	struct store *st_ptr = &stores[STORE_HOME];

	char o_name[80];

	char buf[1024];
	char *p;

	/* Unused parameter */
	(void)full;


	/* Open the file for writing */
	fp = file_open(path, MODE_WRITE, FTYPE_TEXT);
	if (!fp) return (-1);

	/* Begin dump */
	file_putf(fp, "  [%s Character Dump]\n\n", buildid);


	/* Display player */
	display_player(0);

	/* Dump part of the screen */
	for (y = 1; y < 23; y++)
	{
		p = buf;
		/* Dump each row */
		for (x = 0; x < 79; x++)
		{
			/* Get the attr/char */
			(void)(Term_what(x, y, &a, &c));

			/* Dump it */
			p += wctomb(p, c);
		}

		/* Back up over spaces */
		while ((p > buf) && (p[-1] == ' ')) --p;

		/* Terminate */
		*p = '\0';

		/* End the row */
		x_file_putf(fp, "%s\n", buf);
	}

	/* Skip a line */
	file_putf(fp, "\n");

	/* Display player */
	display_player(1);

	/* Dump part of the screen */
	for (y = 11; y < 20; y++)
	{
		p = buf;
		/* Dump each row */
		for (x = 0; x < 39; x++)
		{
			/* Get the attr/char */
			(void)(Term_what(x, y, &a, &c));

			/* Dump it */
			p += wctomb(p, c);
		}

		/* Back up over spaces */
		while ((p > buf) && (p[-1] == ' ')) --p;

		/* Terminate */
		*p = '\0';

		/* End the row */
		x_file_putf(fp, "%s\n", buf);
	}

	/* Skip a line */
	file_putf(fp, "\n");

	/* Dump part of the screen */
	for (y = 11; y < 20; y++)
	{
		p = buf;
		/* Dump each row */
		for (x = 0; x < 39; x++)
		{
			/* Get the attr/char */
			(void)(Term_what(x + 40, y, &a, &c));

			/* Dump it */
			p += wctomb(p, c);
		}

		/* Back up over spaces */
		while ((p > buf) && (p[-1] == ' ')) --p;

		/* Terminate */
		*p = '\0';

		/* End the row */
		x_file_putf(fp, "%s\n", buf);
	}

	/* Skip some lines */
	file_putf(fp, "\n\n");


	/* If dead, dump last messages -- Prfnoff */
	if (p_ptr->is_dead)
	{
		i = messages_num();
		if (i > 15) i = 15;
		file_putf(fp, "  [Last Messages]\n\n");
		while (i-- > 0)
		{
			x_file_putf(fp, "> %s\n", message_str((s16b)i));
		}
		x_file_putf(fp, "\nKilled by %s.\n\n", p_ptr->died_from);
	}


	/* Dump the equipment */
	file_putf(fp, "  [Character Equipment]\n\n");
	for (i = INVEN_WIELD; i < ALL_INVEN_TOTAL; i++)
	{
		if (i == INVEN_TOTAL)
		{
			file_putf(fp, "\n\n  [Character Quiver]\n\n");
			continue;
		}
		object_desc(o_name, sizeof(o_name), &p_ptr->inventory[i],
				ODESC_PREFIX | ODESC_FULL);

		x_file_putf(fp, "%c) %s\n", index_to_label(i), o_name);
		if (p_ptr->inventory[i].kind)
			object_info_chardump(fp, &p_ptr->inventory[i], 5, 72);
	}

	/* Dump the inventory */
	file_putf(fp, "\n\n  [Character Inventory]\n\n");
	for (i = 0; i < INVEN_PACK; i++)
	{
		if (!p_ptr->inventory[i].kind) break;

		object_desc(o_name, sizeof(o_name), &p_ptr->inventory[i],
					ODESC_PREFIX | ODESC_FULL);

		x_file_putf(fp, "%c) %s\n", index_to_label(i), o_name);
		object_info_chardump(fp, &p_ptr->inventory[i], 5, 72);
	}
	file_putf(fp, "\n\n");


	/* Dump the Home -- if anything there */
	if (st_ptr->stock_num)
	{
		/* Header */
		file_putf(fp, "  [Home Inventory]\n\n");

		/* Dump all available items */
		for (i = 0; i < st_ptr->stock_num; i++)
		{
			object_desc(o_name, sizeof(o_name), &st_ptr->stock[i],
						ODESC_PREFIX | ODESC_FULL);
			x_file_putf(fp, "%c) %s\n", I2A(i), o_name);

			object_info_chardump(fp, &st_ptr->stock[i], 5, 72);
		}

		/* Add an empty line */
		file_putf(fp, "\n\n");
	}

	/* Dump character history */
	dump_history(fp);
	file_putf(fp, "\n\n");

	/* Dump options */
	file_putf(fp, "  [Options]\n\n");

	/* Dump options */
	for (i = 0; i < OPT_PAGE_MAX - 1; i++) {
		int j;
		const char *title = "";
		switch (i) {
			case 0: title = "Interface"; break;
			case 1: title = "Warning"; break;
			case 2: title = "Birth"; break;
		}

		file_putf(fp, "  [%s]\n\n", title);
		for (j = 0; j < OPT_PAGE_PER; j++) {
			int opt = option_page[i][j];
			if (!option_name(opt)) continue;

			file_putf(fp, "%-45s: %s (%s)\n",
			        option_desc(opt),
			        op_ptr->opt[opt] ? "yes" : "no ",
			        option_name(opt));
		}

		/* Skip some lines */
		file_putf(fp, "\n");
	}

	file_close(fp);


	/* Success */
	return (0);
}
Beispiel #8
0
/*
 * Hack -- Dump a character description file
 *
 * XXX XXX XXX Allow the "full" flag to dump additional info,
 * and trigger its usage from various places in the code.
 */
errr file_character(const char *path, bool full)
{
	int i, x, y;

	byte a;
	char c;

	ang_file *fp;

	struct store *st_ptr = &stores[STORE_HOME];

	char o_name[80];

	byte (*old_xchar_hook)(byte c) = Term.xchar_hook;

	char buf[1024];

	/* We use either ascii or system-specific encoding */
 	int encoding = OPT(xchars_to_file) ? SYSTEM_SPECIFIC : ASCII;

	/* Unused parameter */
	(void)full;


	/* Open the file for writing */
	fp = file_open(path, MODE_WRITE, FTYPE_TEXT);
	if (!fp) return (-1);

	/* Display the requested encoding -- ASCII or system-specific */
 	if (!OPT(xchars_to_file)) Term.xchar_hook = null;

	/* Begin dump */
	file_putf(fp, "  [%s Character Dump]\n\n", buildid);


	/* Display player */
	display_player(0);

	/* Dump part of the screen */
	for (y = 1; y < 23; y++)
	{
		/* Dump each row */
		for (x = 0; x < 79; x++)
		{
			/* Get the attr/char */
			(void)(Term_what(x, y, &a, &c));

			/* Dump it */
			buf[x] = c;
		}

		/* Back up over spaces */
		while ((x > 0) && (buf[x-1] == ' ')) --x;

		/* Terminate */
		buf[x] = '\0';

		/* End the row */
		x_file_putf(fp, encoding, "%s\n", buf);
	}

	/* Skip a line */
	file_putf(fp, "\n");

	/* Display player */
	display_player(1);

	/* Dump part of the screen */
	for (y = 11; y < 20; y++)
	{
		/* Dump each row */
		for (x = 0; x < 39; x++)
		{
			/* Get the attr/char */
			(void)(Term_what(x, y, &a, &c));

			/* Dump it */
			buf[x] = c;
		}

		/* Back up over spaces */
		while ((x > 0) && (buf[x-1] == ' ')) --x;

		/* Terminate */
		buf[x] = '\0';

		/* End the row */
		x_file_putf(fp, encoding, "%s\n", buf);
	}

	/* Skip a line */
	file_putf(fp, "\n");

	/* Dump part of the screen */
	for (y = 11; y < 20; y++)
	{
		/* Dump each row */
		for (x = 0; x < 39; x++)
		{
			/* Get the attr/char */
			(void)(Term_what(x + 40, y, &a, &c));

			/* Dump it */
			buf[x] = c;
		}

		/* Back up over spaces */
		while ((x > 0) && (buf[x-1] == ' ')) --x;

		/* Terminate */
		buf[x] = '\0';

		/* End the row */
		x_file_putf(fp, encoding, "%s\n", buf);
	}

	/* Skip some lines */
	file_putf(fp, "\n\n");


	/* If dead, dump last messages -- Prfnoff */
	if (p_ptr.is_dead)
	{
		i = messages_num();
		if (i > 15) i = 15;
		file_putf(fp, "  [Last Messages]\n\n");
		while (i-- > 0)
		{
			x_file_putf(fp, encoding, "> %s\n", message_str((s16b)i));
		}
		x_file_putf(fp, encoding, "\nKilled by %s.\n\n", p_ptr.died_from);
	}


	/* Dump the equipment */
	file_putf(fp, "  [Character Equipment]\n\n");
	for (i = INVEN_WIELD; i < ALL_INVEN_TOTAL; i++)
	{
		if (i == INVEN_TOTAL)
		{
			file_putf(fp, "\n\n  [Character Quiver]\n\n");
			continue;
		}
		object_desc(o_name, sizeof(o_name), &p_ptr.inventory[i],
				ODESC_PREFIX | ODESC_FULL);

		x_file_putf(fp, encoding, "%c) %s\n", index_to_label(i), o_name);
		if (p_ptr.inventory[i].kind)
			object_info_chardump(fp, &p_ptr.inventory[i], 5, 72);
	}

	/* Dump the inventory */
	file_putf(fp, "\n\n  [Character Inventory]\n\n");
	for (i = 0; i < INVEN_PACK; i++)
	{
		if (!p_ptr.inventory[i].kind) break;

		object_desc(o_name, sizeof(o_name), &p_ptr.inventory[i],
					ODESC_PREFIX | ODESC_FULL);

		x_file_putf(fp, encoding, "%c) %s\n", index_to_label(i), o_name);
		object_info_chardump(fp, &p_ptr.inventory[i], 5, 72);
	}
	file_putf(fp, "\n\n");


	/* Dump the Home -- if anything there */
	if (st_ptr.stock_num)
	{
		/* Header */
		file_putf(fp, "  [Home Inventory]\n\n");

		/* Dump all available items */
		for (i = 0; i < st_ptr.stock_num; i++)
		{
			object_desc(o_name, sizeof(o_name), &st_ptr.stock[i],
						ODESC_PREFIX | ODESC_FULL);
			x_file_putf(fp, encoding, "%c) %s\n", I2A(i), o_name);

			object_info_chardump(fp, &st_ptr.stock[i], 5, 72);
		}

		/* Add an empty line */
		file_putf(fp, "\n\n");
	}

	/* Dump character history */
	dump_history(fp);
	file_putf(fp, "\n\n");

	/* Dump options */
	file_putf(fp, "  [Options]\n\n");

	/* Dump options */
	for (i = OPT_BIRTH; i < OPT_BIRTH + N_OPTS_BIRTH; i++)
	{
		if (option_name(i))
		{
			file_putf(fp, "%-45s: %s (%s)\n",
			        option_desc(i),
			        op_ptr.opt[i] ? "yes" : "no ",
			        option_name(i));
		}
	}

	/* Skip some lines */
	file_putf(fp, "\n\n");

	/* Return to standard display */
 	Term.xchar_hook = old_xchar_hook;

	file_close(fp);


	/* Success */
	return (0);
}
Beispiel #9
0
void game::show_options()
{
    // Remember what the options were originally so we can restore them if player cancels.
    option_table OPTIONS_OLD = OPTIONS;

    WINDOW* w_options_border = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH,
                                      (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 0,
                                      (TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 0);
    WINDOW* w_options = newwin(FULL_SCREEN_HEIGHT-2, FULL_SCREEN_WIDTH-2,
                               1 + ((TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 0),
                               1 + ((TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 0));

    int offset = 1;
    const int MAX_LINE = 22;
    int line = 0;
    char ch = ' ';
    bool changed_options = false;
    bool needs_refresh = true;
    wborder(w_options_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
            LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX);
    mvwprintz(w_options_border, 0, 36, c_ltred, _(" OPTIONS "));
    wrefresh(w_options_border);
    do {
// TODO: change instructions
        if(needs_refresh) {
            werase(w_options);
            // because those texts use their own \n, do not fold so use a large enough width like 999
            fold_and_print(w_options, 0, 40, 999, c_white, _("Use up/down keys to scroll through\navailable options.\nUse left/right keys to toggle.\nPress ESC or q to return."));
// highlight options for option descriptions
            fold_and_print(w_options, 5, 40, 999, c_white, option_desc(option_key(offset + line)).c_str());
            needs_refresh = false;
        }

// Clear the lines
        for(int i = 0; i < 25; i++) {
            mvwprintz(w_options, i, 0, c_black, "                                        ");
        }
        int valid_option_count = 0;

// display options
        for(int i = 0; i < 26 && offset + i < NUM_OPTION_KEYS; i++) {
            valid_option_count++;
            mvwprintz(w_options, i, 0, c_white, "%s: ",
                      option_name(option_key(offset + i)).c_str());

            if(option_is_bool(option_key(offset + i))) {
                bool on = OPTIONS[ option_key(offset + i) ];
                if(i == line) {
                    mvwprintz(w_options, i, 30, hilite(c_ltcyan), (on ? _("True") : _("False")));
                } else {
                    mvwprintz(w_options, i, 30, (on ? c_ltgreen : c_ltred), (on ? _("True") : _("False")));
                }
            } else {
                char option_val = OPTIONS[ option_key(offset + i) ];
                if(i == line) {
                    mvwprintz(w_options, i, 30, hilite(c_ltcyan), "%d", option_val);
                } else {
                    mvwprintz(w_options, i, 30, c_ltgreen, "%d", option_val);
                }
            }
        }
        wrefresh(w_options);
        ch = input();
        needs_refresh = true;

        switch(ch) {
// move up and down
        case 'j':
            line++;
            if(line > MAX_LINE/2 && offset + 1 < NUM_OPTION_KEYS - MAX_LINE) {
                ++offset;
                --line;
            }
            if(line > MAX_LINE) {
                line = 0;
                offset = 1;
            }
            break;
        case 'k':
            line--;
            if(line < MAX_LINE/2 && offset > 1) {
                --offset;
                ++line;
            }
            if(line < 0) {
                line = MAX_LINE;
                offset = NUM_OPTION_KEYS - MAX_LINE - 1;
            }
            break;
// toggle options with left/right keys
        case 'h':
            if(option_is_bool(option_key(offset + line))) {
                OPTIONS[ option_key(offset + line) ] = !(OPTIONS[ option_key(offset + line) ]);
            } else {
                OPTIONS[ option_key(offset + line) ]--;
                if((OPTIONS[ option_key(offset + line) ]) < option_min_options(option_key(offset + line))) {
                    OPTIONS[ option_key(offset + line) ] = option_max_options(option_key(offset + line)) - 1;
                }
            }
            changed_options = true;
            break;
        case 'l':
            if(option_is_bool(option_key(offset + line))) {
                OPTIONS[ option_key(offset + line) ] = !(OPTIONS[ option_key(offset + line) ]);
            } else {
                OPTIONS[ option_key(offset + line) ]++;
                if((OPTIONS[ option_key(offset + line) ]) >= option_max_options(option_key(offset + line))) {
                    OPTIONS[ option_key(offset + line) ] = option_min_options(option_key(offset + line));
                }
            }
            changed_options = true;
            break;
        }
        if(changed_options && OPTIONS[OPT_SEASON_LENGTH] < 1) { OPTIONS[OPT_SEASON_LENGTH]=option_max_options(OPT_SEASON_LENGTH)-1; }
    } while(ch != 'q' && ch != 'Q' && ch != KEY_ESCAPE);

    if(changed_options)
    {
        if(query_yn(_("Save changes?")))
        {
            save_options();
            trigdist=(OPTIONS[OPT_CIRCLEDIST] ? true : false);
        }
        else
        {
            // Player wants to keep the old options. Revert!
            OPTIONS = OPTIONS_OLD;
        }
    }
    werase(w_options);
}