Пример #1
0
static int hiscore_congrats(const char **menu)
{
	char name[8] = "       ";
	int x = 9;
	int y = _HEIGHT_24L ? 7 : 3;
	setwcurs(0, 9, y);
	while (is_outside_screen(x+26, 0))
		x--;
	drawbox(x, y, 26, 9, "CONGRATULATIONS!");
	setcurs(x+2, y+2);
	printstr("You have a highscore!");  newln(x+2);
	printstr("Please enter your name");
entername:
	switch (hiscore_entername_menu(name, menu, x+4, y+4)) {
	case 0:
		return 0;
	case 1:
		if (savehiscore(name)) {
			if (x > 7)
				clearbox(33, y, 2, 9);
			return hiscorebox(menu, 9, y);
		}
		setcurs(x+2, y+2);
		printstr("ERROR! Could not save");  newln(x+2);
		printstr("score to file.        ");
		goto entername;
	case 2:
		clearbox(32, y, 0, 9);
		return 1;
	}
}
Пример #2
0
int startupmenu(int i)
{
	while (1) {
		drawbox(5, STARTUP_Y-2, 22, STARTUP_N+4, NULL);
		printmenuhelp(19);
		i = startup_menu(i-1, 8, STARTUP_Y);
# ifndef TTY_SOCKET
		if (!i)
			break;
# else
		if (i==2 && !select_2p_tty(24, STARTUP_Y+1))
			continue;
		if (!i) {
			setcurs(5, STARTUP_Y-2);
			wclrtobot(window);
			if ((i = menu_checkinvit(1, 7)) == -1) {
				refresh();
				setwcurs(0, 5, 7);
				i = 1;
				continue;
			}
			if (!i)
				break;
		}
		move(term_height-1, 0);
		clrtoeol();
		refresh();
# endif
		setcurs(5, STARTUP_Y-2);
		wclrtobot(window);
		break;
	}
	return i;
}
Пример #3
0
int handle_menuitem(const char **menu, int n, int *i, int x, int y,
		    menuhandler *handlers, int keypr)
{
	int j = *i;
	int m;
	keypr &= 0xFF;
	if (keypr == ESC)
		return 0;
	printmenuitem(menu[j], 1);
	if (handlers && handlers[j])
		switch (m = handlers[j](keypr, i)) {
		case 0:   break;
		case ESC: return 0;
		default:  return m;
		}
	switch (keypr) {
	case STARTBTN:
	case A_BTN:
		return 2;
	case B_BTN:
	case '\b':
		return 0;
	case 'q':
		exit(0);
	case MVUP:
		if (!j)
			return 1;
#if NO_MENU
		m = -1;
#else
		m = -1-(*menu[j-1]=='-');
#endif
		break;
	case '\t':
		if (j == n-1) {
			m = -j;
			break;
		}
	case MVDOWN:
		if (j < n-1) {
#if NO_MENU
			m = 1;
#else
			m = 1+(*menu[j+1]=='-');
#endif
			break;
		}
	default:
#ifndef NO_MENU
		if (m = find_firstletter(menu, n, j, keypr))
			break;
#endif
		return 1;
	}
	setcurs(x, y);
	printmenuitem(menu[j], 0);
	setcurs(x, y+m);
	printmenuitem(menu[*i+=m], 1);
	return 1;
}
Пример #4
0
static void tetrom_colors_menu(int x, int y)
{
	const char *menu[7] = {"I", "J", "L", "O", "S", "T", "Z"};
	menuhandler handlers[7] = {
		op_tcolor, op_tcolor, op_tcolor, op_tcolor,
		op_tcolor_gt4, op_tcolor_gt4, op_tcolor_gt4
	};
	int i = 0;
	if (y+6 >= term_height)
		y -= 7;
	drawbox(x, y, 19, 6, (char *) 0);
	x++;
	y++;
	drawmenu(menu, 4, 0, x, y, handlers);
	drawmenu(menu+4, 3, -1, x+9, y, handlers+4);
	autorep_a_b_btns = 1;
	while (1) {
		setcurs(x, y+i%4);
		refreshwin(-1);
		switch (handle_menuitem_2cols(menu, 7, &i, 4, x, y+i%4,
				handlers, getkeypress_block(SINGLE_PL))) {
		case 0:
		case 2:
			autorep_a_b_btns = 0;
			if (i >= 4)
				x -= 9;
			clearbox(x-1, y-1, 19, 6);
			return;
		case 3:
			x += i>=4 ? 9 : -9;
			setcurs(x, y+i%4);
			printmenuitem(menu[i], 1);
		}
	}
}
Пример #5
0
static int hiscore_entername_menu(char *name, const char **menu, int x, int y)
{
	int pos = 0;
	int i = 0;
	int k;
	while (1) {
		drawmenu(menu, 2, i-2, x, y+2, NULL);
textbox:	setcurs(x, y);
		printtextbox(name, pos);
		movefwd(3);
		printsavebutton(!i && pos==7);
		if (!i)
			x += pos;
		setcurs(x, y+i);
		refreshwin(-1);
		autorep_a_b_btns = 1;
		k = getkeypress_block(SINGLE_PL) & 0xFF;
		autorep_a_b_btns = 0;
		if (k == ESC)
			return 0;
		if (!i) {
			x -= pos;
			switch (k) {
			case STARTBTN:
				return 1;
			case '\t':
				if (pos < 7)
					break;
			case MVDOWN:
				i = 2;
				continue;
			}
			pos = hiscore_editname(name, pos, k);
			goto textbox;
		}
		switch (k) {
		case STARTBTN:
		case A_BTN:
			if (i==2)
				return 2;
		case 'q':
			exit(0);
		case MVUP:
			i = i==2 ? 0 : 2;
			break;
		case '\t':
			i = i==2 ? 3 : 0;
			break;
		case MVDOWN:
			if (i < 3)
				i++;
		}
		if (!i && pos==7) {
			pos = 6;
			while (pos && name[pos-1]==' ')
				pos--;
		}
	}
}
Пример #6
0
int dropdownlist(const char **items, int n, int i, int x, int y)
{
	int w = getdropdownwidth(items, n);
	int j;
	while (is_outside_screen(0, y+n+1))
		y--;
	setattr_standout();
	drawbox(x, y, w+2, n+2, NULL);
	x++;
	y++;
	setcurs(x, y);
	for (j = 0; j < n; j++) {
		printdropdownitem(items[j], i==j, w);
		newln(x);
	}
	while (1) {
		setcurs(x-1, y+i);
		refreshwin(-1);
		switch (getkeypress_block(SINGLE_PL) & 0xFF) {
		case STARTBTN:
		case A_BTN:
			goto out;
		case 'q':
			exit(0);
		case MVUP:
			if (!i)
				continue;
			j = -1;
			break;
		case '\t':
			if (i == n-1) {
				j = -i;
				break;
			}
		case MVDOWN:
			if (i < n-1) {
				j = 1;
				break;
			}
		case MVRIGHT:
			continue;
		default:
			i = -1;
			goto out;
		}
		setcurs(x, y+i);
		printdropdownitem(items[i], 0, w);
		i += j;
		setcurs(x, y+i);
		printdropdownitem(items[i], 1, w);
	}
out:	clearbox(x-1, y-1, w+2, n+2);
	return i+1;
}
Пример #7
0
static void printstat_1p()
{
	setattr_normal();
	if (!_WHITE_BG)
		setattr_bold();
	setcurs(1, 2);
	printlong(" %06ld ", player1.score % 1000000);
	setcurs(3, 6);
	printint(" %02d ", player1.level);
	setcurs(3, 10);
	printint(" %03d ", player1.lines);
}
Пример #8
0
static int op_handler(int k, int *pos)
{
	const struct termopt opt = {ASCII, "CP437 ASCII", "drawing"};
	int i = *pos-2;
	if (i < 0) {
		if (k) {
			clearbox(0, 16, 0, 4);
			inputsetup_box(k-1, 1, 7);
		}
		draw_options_box();
		return 1;
	}
	if (!i) {
		if (k == MVLEFT)
			i = 0;
		else if (k == MVRIGHT)
			i = 1;
		else {
			i = !getopt_int("", "fullscreen");
			if (k == A_BTN)
				i = !i;
			else if (k)
				return 0;
		}
		printmenuitem_options("yes no", i);
		if (k) {
			union val v;
			v.integ = !i;
			setoption("", "fullscreen", v, 0);
		}
		i = 1;
	} else if (i == 1) {
		if (!k) {
			get_xy(&k, &i);
			setcurs(2, i+5);
			putnchars(HLINE, 28);
			help_alt_enter();
			setcurs(k, i);
			k = 0;
		}
		i = term_optionhandler(k, &opt);
	}
#ifndef NO_BLOCKSTYLES
	else
		i = select_blockstyle(k);
#endif
	if (i == 3) {
		draw_tetris_logo(0, 0);
		draw_options_box();
	}
	return i;
}
Пример #9
0
int gamemenu()
{
	int i = 0;
#ifdef TWOPLAYER
	int y = 7;
	while (1) {
		if (!TWOPLAYER_MODE) {
			if (term_height >= 23)
				show_hiscorelist5(5, GAMEMENU_LENGTH+9, 0);
		} else if (term_height < 23) {
			setcurs(1, 4);
			cleartoeol();
			y = 5;
		}
		i = game_menu(0, 1, y);
		if (i != 4)
			break;
		wclrtobot(window);
		inputsetup_box(0, 1, 7);
	}
	if (!i) {
		setcurs(1, 4);
		wclrtobot(window);
		print_vitetris_ver(19, 4);
	}
#else
	while (1) {
		printmenuhelp(19);
		i = game_menu(i, 1, 7);
		if (!i)
			break;
		clearbox(0, 7, 0, GAMEMENU_LENGTH);
		if (i != 4 && i < GAMEMENU_LENGTH-1)
			break;
		wclrtobot(window);
		switch (i) {
		case 4:
			inputsetup_box(0, 1, 7);
			i = 0;
			continue;
		case GAMEMENU_LENGTH-1:
			optionsmenu();
			break;
		default:
			hiscorelist();
		}
		i--;
	}
#endif
	return i;
}
Пример #10
0
void drawboard(int pl)
{
	int x = board_x(pl, 0);
	int i;
	char tmp[30];
	if (_HEIGHT_24L) {
		//i = x+5;
		//setwcurs(0, i, 0);
		if (!_MONOCHROME) {
			setcolorpair(BOARD_FRAME_COLOR);
			setattr_bold();
		}
		//i = x-5;
		//setwcurs(0, i, 0);
		//sprintf(tmp, "lqNk\\x Nx\\| N|");
		//drawstr(tmp, 8, i, 0);

		i = x+5;
		setwcurs(0, i, 0);
		drawstr("lqNk\\x Nx\\2|_N|", 8, i, 0);

		setcolorpair(BOARD_FRAME_COLOR);
		setcurs(x, 3);
		printstr("_____");
		movefwd(10);
		printstr("_____");
		i = 4;
	} else
		i = 0;
	x--;
	setwcurs(0, x, i);
	setcolorpair(BOARD_FRAME_COLOR);
	for (i = 0; i < 20; i++) {
		putch(VLINE);
		movefwd(20);
		putch(VLINE);
		if (i < 19)
			newln(x);
	}
	if (term_height > 20 && term_height != 24) {
		newln(x);
		printstr_acs("m*Nj", 20);
	} else {
		setcurs(0, term_height-2);
		newln(0);
	}
#ifdef TWOPLAYER
	board_bottom_color[pl-1] = BOARD_FRAME_COLOR;
#endif
}
Пример #11
0
void show_hiscorelist5(int x, int y, int i)
{
	char s[20];
	const struct hiscore *hs, *end;
	int n;
	if (!hiscores[0].score && !readhiscores(NULL))
		return;
	setcurs(x, y);
	hs = hiscores;
	i -= 5;
	if (i < 0)
		i = 0;
	else
		hs += i;
	end = hs+5;
	while (hs->score && hs != end) {
		n = sprintf(s, "%2d. %s", i+1, gethiscorename(i, s+12));
		memset(s+n, ' ', 12-n);
		sprintf(s+12, "%7ld", (long) hs->score);
		printstr(s);
		newln(x);
		hs++;
		i++;
	}
}
Пример #12
0
void print_vitetris_ver(int x, int y)
{
	setcurs(x, y);
	setattr_bold();
	printstr(VITETRIS_VER);
	setattr_normal();
}
Пример #13
0
int selectitem(const char **items, int n, int *i, int k)
{
	int x, y;
	switch (k) {
	case 0:
		break;
	case MVLEFT:
		if (*i)
			*i -= 1;
		break;
	case MVRIGHT:
		if (*i < n-1)
			*i += 1;
		break;
	case STARTBTN:
	case A_BTN:
		get_xy(&x, &y);
		n = dropdownlist(items, n, *i, x, y);
		if (n)
			*i = n-1;
		setcurs(x, y);
		return 3;
	default:
		return 0;
	}
	putch('[');
	printstr(items[*i]);
	n = getdropdownwidth(items, n) - strlen(items[*i]);
	putnchars(' ', n);
	printstr("] ");
	return 1;
}
Пример #14
0
static void help_cmdline()
{
	if (term_height > 22) {
		setcurs(1, 20);
		printstr("-help for command-line options");
	}
}
Пример #15
0
static void printmenuhelp(int y)
{
	setcurs(0, y);
	printstr("Use the arrow keys or TAB to navigate,"); newln(0);
	printstr("ENTER to proceed, BACKSPACE or ESC to");  newln(0);
	printstr("go back.  Exit at once with Q.");
}
Пример #16
0
void inp_printkeys(int dev, int x, int y)
{
	const char *k;
	int i;
	x += 6;
	setcurs(x, y);
	for (i = 0; i < 11; i++) {
		k = getkeyfor_str(dev, inp_keypr(i));
		printstr(k);
		putnchars(' ', 6-strlen(k));
		if (i == 5) {
			x += 17;
			setcurs(x, y);
		} else
			newln(x);
	}
}
Пример #17
0
void setwcurs(int win, int x, int y)
{
	if (win != window) {
		getwin_xy(win, &win_x, &win_y);
		window = win;
	}
	setcurs(x, y);
}
Пример #18
0
static int inp_setcurs(int x, int y, int i)
{
	if (i >= 6) {
		x += 12;
		i -= 6;
	}
	setcurs(x, y+i);
	return x;
}
Пример #19
0
void optionsmenu()
{
	const char *items[2] = {"Term BG", "Line Drawing"};
	int n = 1+!(textgfx_flags & CYGWIN);
	draw_options_box();
	options_menu(items, n, op_handler, 3, 9);
	setcurs(0, 7);
	wclrtobot(window);
}
Пример #20
0
static void printmenuhelp(int y)
{
	if (term_height < y+5 || term_width < 48)
		return;
	setcurs(0, y);
	printstr("Use the arrow keys or TAB to navigate,"); newln(0);
	printstr("ENTER to proceed, BACKSPACE or ESC to");  newln(0);
	printstr("go back.  Exit at once with Q.");
}
Пример #21
0
void draw_2p_menu_decor(int pl, int x, int y)
{
	x++;
	drawstr("\\l\\x", 0, x, y-1);
	y += 2;
	setcurs(x-1, y);
	putch(pl+'0');
	drawstr("P\\x\\2m", 0, x, y);
}
Пример #22
0
void textgfx_init()
{
#ifdef UNIX
	strcpy(_xwin.application_name, "vitetris");
	strcpy(_xwin.application_class, "Vitetris");
#endif
	if (install_allegro(SYSTEM_AUTODETECT, &errno, NULL) != 0)
		exit(1);
#ifdef UNIX
	sigaction(SIGINT, NULL, &allegro_sigint_handler);
	signal(SIGINT, sigint_handler);
#endif
	load_pc8x16_font();
	set_window_title(VITETRIS_VER);
	set_close_button_callback(close_btn);
#ifndef UNIX
	/* Seems to cause seg fault later quite randomly on Linux  */
	int depth = desktop_color_depth();
	if (depth != 0)
		set_color_depth(depth);
#endif
	virt_screen = set_screen(getopt_int("", "fullscreen"));
	lang |= LATIN1;
	if (!font8x16) {
		font8x16 = font;
		textgfx_flags |= ASCII;
	}
	setattr_normal();
#if WIN32 && !ALLEGRO_USE_CONSOLE
	if (exists("stdout.tmp")) {
		FILE *fp;
		freopen("stdout2.tmp", "w", stdout);
		fp = fopen("stdout.tmp", "r");
		if (fp) {
			char line[80];
			int i;
			for (i=0; i < 25 && fgets(line, 80, fp); i++) {
				setcurs(0, i);
				i += printline(line);	
			}
			fclose(fp);
			if (i) {
				refreshscreen();
				if (!strncmp(line, "Press ", 6)) {
					install_keyboard();
					clear_keybuf();
					readkey();
					remove_keyboard();
				}
			}
		}
		freopen("stdout.tmp", "w", stdout);
		delete_file("stdout2.tmp");
	}
#endif
}
Пример #23
0
static int op_handler(int k, int *pos)
{
	const struct termopt opts[2] = {
		{ WHITE_BG, "black white", "bg" },
		{ ASCII, "VT100 ASCII", "drawing" }
	};
	int i = *pos-2;
	if (i < 0) {
		if (k) {
			setcurs(0, 16);
			wclrtobot(window);
			inputsetup_box(k-1, 1, 7);
		}
		draw_options_box();
		return 1;
	}
	if (!i && !k) {
		getyx(window, i, k);
		setcurs(2, i+5+!(textgfx_flags & CYGWIN));
		putnchars(HLINE, 28);
		help_cmdline();
		setcurs(k, i);
		i = k = 0;
	}
	if (i < 1+!(textgfx_flags & CYGWIN))
		i = term_optionhandler(k, opts+i);
#ifndef NO_BLOCKSTYLES
	else
		i = select_blockstyle(k);
#endif
	if (i == 3) {
		draw_tetris_logo(0, 0);
		if (!_MONOCHROME) {
			init_color_pairs();
			if (*pos == 2)
				clearok(window, TRUE);
		}
		draw_options_box();
	}
	return i;
}
Пример #24
0
void drawmenu(const char **menu, int n, int pos, int x, int y,
	      menuhandler *handlers)
{
	int i;
	setcurs(x, y);
	for (i = 0; i < n; i++) {
		printmenuitem(menu[i], (i==pos));
		if (handlers && handlers[i])
			handlers[i](0, &i);
		newln(x);
	}
}
Пример #25
0
void drawpanel_labels(const char *first, int x)
{
	const char *s = first;
	int i;
	setcolorpair(PANEL_LABEL_COLOR);
	for (i = 1; i <= 9; i += 4) {
		setcurs(x, i);
		putch(' ');
		printstr(s);
		putch(' ');
		s = s==first ? "Level" : "Lines";
	}
}
Пример #26
0
void drawnext(const struct player *p, const struct tetr *next)
{
	int win = WIN_NEXT+isplayer2(p);
	int bl;
	int x;
	if (TWOPLAYER_MODE && !_HEIGHT_24L && term_width < 76)
		return;
	clearwin(win);
	if (next && (bl = next->blocks)) {
		x = (bl!=TETR_I && bl!=TETR_O);
		while (!(bl & 15))
			bl >>= 4;
		setcurs(x, 0);
		drawbl(bl, next->color+10, x, 0);
	}
Пример #27
0
static void drawpanel_1p()
{
	int h24 = _HEIGHT_24L;
	int clr = (player1.level % 6)+1;
	int i;
	setwcurs(WIN_PANEL, 0, 0);
	setblockcolor(clr);
	printstr_acs("lqNu", 8);
	for (i = 0; i <= 8; i += 4)
		drawstr("\\xhNx\\3tqNu", 8, 0, i);
	if (h24) {
		setcurs(0, 12);
		putch(LOWLEFT);
		drawpanel_labels("Score", 1);
	} else {
		setcurs(0, 13);
		printstr_acs("xhNx", 8);
		drawpanel_labels("Score", 1);
		setcurs(2, 13);
		printstr(" Next ");
	}
	printstat_1p();
	drawpanel_bordercolor(clr);
	if (h24)
		drawstr("\\x\\6x", 6, 9, 12);
	else {
		drawstr("\\x Nx\\3mqNu", 8, 0, 13);
		drawstr("\\x\\x", 0, 9, 17);
	}
	i = 0;
	if (h24)
		i = 4;
	setwcurs(0, 0, i);
	drawpanel_bordercolor(clr);
	draw_vline(board_x(1, 10)+1, i, 20);
}
Пример #28
0
int gamemenu()
{
	int i = 1;
#ifdef TWOPLAYER
	int h;
	if (!TWOPLAYER_MODE || game->mode & MODE_NETWORK)
		h = GAMEMENU_LENGTH+4;
	else {
		h = 17;
		while (menuheight < h)
			newln(2);
	}
	while (1) {
		i = game_menu(0, 1, 4);
		if (i==4)
			inputsetup_box(0, 1, 4);
		else
			break;
	}
	if (!i)
		clearbox(0, 4, 0, h-4);
#else
	while (1) {
		i = game_menu(i-1, 1, 4);
		if (i==4) {
			setcurs(0, 13);
			printf("\033[K");
			inputsetup_box(0, 1, 4);
			i = 1;
		} else if (i < GAMEMENU_LENGTH-1)
			break;
		else {
			clearbox(0, 4, 0, GAMEMENU_LENGTH);
			if (i == GAMEMENU_LENGTH-1)
				optionsmenu();
			else
				hiscorelist();
		}
	}
#endif
	return i;
}
Пример #29
0
int openmenu(const char **menu, int n, int i, int x, int y,
	     menuhandler *handlers)
{
	drawmenu(menu, n, i, x, y, handlers);
	while (1) {
		setcurs(x, y+i);
		refreshwin(-1);		/* refresh active window */

		switch (handle_menuitem(menu, n, &i, x, y+i, handlers,
					getkeypress_block(SINGLE_PL))) {
		case 0:
			return 0;
		case 2:
			return i+1;
#if !NO_MENU
		case 3:
			return openmenu(menu, n, i, x, y, handlers);
#endif
		}
	}
}
Пример #30
0
void drawstr(const char *str, int n, int x, int y)
{
	char s[8];
	const char *p;
	int m;
	while (p = strchr(str, '\\')) {
		m = p-str;
		memcpy(s, str, m);
		s[m] = '\0';
		str += m+1;
		if (isdigit(p[1])) {
			str++;
			m = p[1]-'0';
		} else
			m = 1;
		do {
			printstr_acs(s, n);
			setcurs(x, ++y);
		} while (--m);
	}
	printstr_acs(str, n);
}