X-Git-Url: http://git.shiar.net/netris.git/blobdiff_plain/01aff5930cdf4448ad3fbdb8821d6708402faedd..HEAD:/curses.c diff --git a/curses.c b/curses.c index 57bfee7..d24a110 100644 --- a/curses.c +++ b/curses.c @@ -403,62 +403,43 @@ static void block_draw_2(int y, int x, unsigned char type) else { #ifdef HAVE_NCURSES if (Sets.standout) { - if (haveColor) attrset(COLOR_PAIR(type & 15)); - else attrset(A_REVERSE); + attrset(haveColor ? COLOR_PAIR(type & 15) : A_REVERSE); } #endif switch (Sets.drawstyle) { - case 2: - switch (type & 192) { - case 64: //right neighbour + case 2: // ascii horizontally grouped + switch (type & 0xC0) { + case 0x40: // right neighbour addstr("[["); break; - case 128: //left + case 0x80: // left addstr("]]"); break; - default: //both/none + default: // both/none addstr("[]"); break; - } //horizontal stickiness - break; //ascii horizontally grouped - case 3: - switch (type & 240) { - case 48: - addstr("||"); break; //middle - case 64: case 80: case 96: - addstr("[="); break; //left end - case 112: - addstr("|="); break; - case 128: case 144: case 160: - addstr("=]"); break; //right end - case 176: - addstr("=|"); break; - case 192: case 208: case 224: - addstr("=="); break; - default: - addstr("[]"); break; //top/bottom/mid - } //neighbours - break; //ascii semi-grouped - case 7: - switch (type & 240) { - case 16: addch(ACS_ULCORNER); addch(ACS_URCORNER); break;//top end - case 32: addch(ACS_LLCORNER); addch(ACS_LRCORNER); break;//bottom end - case 48: addch(ACS_VLINE); addch(ACS_VLINE); break; //vertical middle - case 64: addch('['); addch(ACS_HLINE); break; //left end - case 80: addch(ACS_ULCORNER); addch(ACS_TTEE); break; //top left corner - case 96: addch(ACS_LLCORNER); addch(ACS_BTEE); break; //bottom left corner - case 112: addch(ACS_LTEE); addch(ACS_PLUS); break; //vertical+right - case 128: addch(ACS_HLINE); addch(']'); break; //right end - case 144: addch(ACS_TTEE); addch(ACS_URCORNER); break; //top right corner - case 160: addch(ACS_BTEE); addch(ACS_LRCORNER); break; //bottom right corner - case 176: addch(ACS_PLUS); addch(ACS_RTEE); break; //vertical+left - case 192: addch(ACS_HLINE); addch(ACS_HLINE); break; //horizontal middle - case 208: addch(ACS_TTEE); addch(ACS_TTEE); break; //horizontal+down - case 224: addch(ACS_BTEE); addch(ACS_BTEE); break; //horizontal+up - default: addstr("[]"); break; - } //neighbours - break; //curses grouped - default: + } // horizontal stickiness + break; + case 3: // curses grouped + switch (type & 0xF0) { + case 0x10: addch(ACS_ULCORNER); addch(ACS_URCORNER); break; // top end + case 0x20: addch(ACS_LLCORNER); addch(ACS_LRCORNER); break; // bottom end + case 0x30: addch(ACS_VLINE); addch(ACS_VLINE); break; // vertical middle + case 0x40: addch('['); addch(ACS_HLINE); break; // left end + case 0x50: addch(ACS_ULCORNER); addch(ACS_TTEE); break; // top left corner + case 0x60: addch(ACS_LLCORNER); addch(ACS_BTEE); break; // bottom left corner + case 0x70: addch(ACS_LTEE); addch(ACS_PLUS); break; // vertical+right + case 0x80: addch(ACS_HLINE); addch(']'); break; // right end + case 0x90: addch(ACS_TTEE); addch(ACS_URCORNER); break; // top right corner + case 0xA0: addch(ACS_BTEE); addch(ACS_LRCORNER); break; // bottom right corner + case 0xB0: addch(ACS_PLUS); addch(ACS_RTEE); break; // vertical+left + case 0xC0: addch(ACS_HLINE); addch(ACS_HLINE); break; // horizontal middle + case 0xD0: addch(ACS_TTEE); addch(ACS_TTEE); break; // horizontal+down + case 0xE0: addch(ACS_BTEE); addch(ACS_BTEE); break; // horizontal+up + default: addstr("[]"); break; // all/none + } // neighbours + break; + default: // non-grouped addstr("[]"); - break; //ascii non-grouped - } //draw block + break; + } #ifdef HAVE_NCURSES if (Sets.standout) standend(); #endif @@ -471,16 +452,14 @@ static void block_draw_1(int y, int x, unsigned char type) if (type == BT_none) addch(' '); else if (type == BT_shadow) addch(':'); else { - if (Sets.standout) { #ifdef HAVE_NCURSES - if (haveColor) - attrset(COLOR_PAIR(type & 15)); - else attrset(A_REVERSE); -#endif + if (Sets.standout) { + attrset(haveColor ? COLOR_PAIR(type & 15) : A_REVERSE); } - if ((type & 192) == 64) +#endif + if ((type & 0xC0) == 0x40) addch('['); - else if ((type & 192) == 128) + else if ((type & 0xC0) == 0x80) addch(']'); else addch('|'); @@ -536,11 +515,13 @@ void window_msg(int player, char *message) { //put a message over player's field if (!window[player].shown) return; if (message) { - char s[MAX_BOARD_WIDTH+1]; - memset(s, ' ', MAX_BOARD_WIDTH); - memcpy(&s[(window[player].size * Players[player].boardWidth / 2) - (strlen(message) / 2)], - message, strlen(message)); - s[window[player].size * Players[player].boardWidth] = 0; + const int fieldsize = Players[player].boardWidth * window[player].size; + const int centered = (fieldsize - strlen(message)) / 2; + char s[fieldsize + 1]; + + memset(s, ' ', fieldsize); + memcpy(&s[centered], message, strlen(message)); + s[fieldsize] = 0; #ifdef HAVE_NCURSES attrset(A_REVERSE); #else @@ -597,24 +578,24 @@ void window_msg_status(int player) if (Players[player].alive > 0) if (Players[player].flags & SCF_paused) if (Game.started > 1) - window_msg_wide(player, "PAUSED"); + window_msg_wide(player, MSG_PLAYER_PAUSE); else - window_msg_wide(player, "NOT READY"); + window_msg_wide(player, MSG_PLAYER_JOIN); else if (Game.started > 1) window_msg(player, NULL); else - window_msg_wide(player, "READY"); + window_msg_wide(player, MSG_PLAYER_START); else if (!Players[player].alive) - window_msg_wide(player, "GAME OVER"); + window_msg_wide(player, MSG_PLAYER_STOP); else - window_msg_wide(player, "EMPTY"); + window_msg_wide(player, MSG_PLAYER_PART); } void status_tick(void) { //display timer - mvprintw(statusYPos, statusXPos, "timer %7.0f ", CurTimeval() / 1e6); + mvprintw(statusYPos, statusXPos, MSG_TIME, CurTimeval() / 1e6); } void ScheduleFullRedraw(void)