1 /* Tetrinet for Linux, by Andrew Church <achurch@achurch.org>
2 * This program is public domain.
4 * Text terminal I/O routines.
20 /*************************************************************************/
22 #define MY_HLINE (fancy ? ACS_HLINE : '-')
23 #define MY_VLINE (fancy ? ACS_VLINE : '|')
24 #define MY_ULCORNER (fancy ? ACS_ULCORNER : '+')
25 #define MY_URCORNER (fancy ? ACS_URCORNER : '+')
26 #define MY_LLCORNER (fancy ? ACS_LLCORNER : '+')
27 #define MY_LRCORNER (fancy ? ACS_LRCORNER : '+')
29 #define MY_HLINE2 (fancy ? (ACS_HLINE | A_BOLD) : '=')
30 #define MY_BOLD (fancy ? A_BOLD : 0)
32 /*************************************************************************/
33 /******************************* Input stuff *****************************/
34 /*************************************************************************/
36 /* Return either an ASCII code 0-255, a K_* value, or -1 if server input is
37 * waiting. Return -2 if we run out of time with no input.
40 static int wait_for_input(int msec
)
45 static int escape
= 0;
49 FD_SET(server_sock
, &fds
);
50 tv
.tv_sec
= msec
/1000;
51 tv
.tv_usec
= (msec
*1000) % 1000000;
52 while (select(server_sock
+1, &fds
, NULL
, NULL
, msec
<0 ? NULL
: &tv
) < 0) {
54 perror("Warning: select() failed");
56 if (FD_ISSET(0, &fds
)) {
58 if (!escape
&& c
== 27) { /* Escape */
60 c
= wait_for_input(1000);
69 else if (c
== KEY_DOWN
)
71 else if (c
== KEY_LEFT
)
73 else if (c
== KEY_RIGHT
)
75 else if (c
== KEY_F(1) || c
== ('1'|0x80) || (escape
&& c
== '1'))
77 else if (c
== KEY_F(2) || c
== ('2'|0x80) || (escape
&& c
== '2'))
79 else if (c
== KEY_F(3) || c
== ('3'|0x80) || (escape
&& c
== '3'))
81 else if (c
== KEY_F(4) || c
== ('4'|0x80) || (escape
&& c
== '4'))
83 else if (c
== KEY_F(5) || c
== ('5'|0x80) || (escape
&& c
== '5'))
85 else if (c
== KEY_F(6) || c
== ('6'|0x80) || (escape
&& c
== '6'))
87 else if (c
== KEY_F(7) || c
== ('7'|0x80) || (escape
&& c
== '7'))
89 else if (c
== KEY_F(8) || c
== ('8'|0x80) || (escape
&& c
== '8'))
91 else if (c
== KEY_F(9) || c
== ('9'|0x80) || (escape
&& c
== '9'))
93 else if (c
== KEY_F(10) || c
== ('0'|0x80) || (escape
&& c
== '0'))
95 else if (c
== KEY_F(11))
97 else if (c
== KEY_F(12))
99 else if (c
== KEY_BACKSPACE
)
101 else if (c
>= 0x0100)
103 else if (c
== 7) /* ^G */
104 return 27; /* Escape */
107 } /* if (FD_ISSET(0, &fds)) */
108 else if (FD_ISSET(server_sock
, &fds
))
111 return -2; /* out of time */
114 /*************************************************************************/
115 /****************************** Output stuff *****************************/
116 /*************************************************************************/
118 /* Size of the screen */
119 static int scrwidth
, scrheight
;
121 /* Is color available? */
122 static int has_color
;
124 /*************************************************************************/
129 int x
, y
, width
, height
;
131 WINDOW
*win
; /* NULL if not currently displayed */
135 static TextBuffer plinebuf
, gmsgbuf
, attdefbuf
;
137 /*************************************************************************/
139 /* Window for typing in-game text, and its coordinates: */
141 static WINDOW
*gmsg_inputwin
;
142 static int gmsg_inputpos
, gmsg_inputheight
;
144 /*************************************************************************/
145 /*************************************************************************/
147 /* Clean up the screen on exit. */
149 static void screen_cleanup()
151 wmove(stdscr
, scrheight
-1, 0);
157 /*************************************************************************/
159 /* Little signal handler that just does an exit(1) (thereby getting our
160 * cleanup routine called), except for TSTP, which does a clean suspend.
163 static void (*old_tstp
)(int sig
);
165 static void sighandler(int sig
)
167 if (sig
!= SIGTSTP
) {
170 fprintf(stderr
, "%s\n", strsignal(sig
));
174 signal(SIGTSTP
, old_tstp
);
177 signal(SIGTSTP
, sighandler
);
180 /*************************************************************************/
181 /*************************************************************************/
183 #define MAXCOLORS 256
185 static int colors
[MAXCOLORS
][2] = { {-1,-1} };
187 /* Return a color attribute value. */
189 static long getcolor(int fg
, int bg
)
193 if (colors
[0][0] < 0) {
195 memset(colors
, -1, sizeof(colors
));
196 colors
[0][0] = COLOR_WHITE
;
197 colors
[0][1] = COLOR_BLACK
;
199 if (fg
== COLOR_WHITE
&& bg
== COLOR_BLACK
)
200 return COLOR_PAIR(0);
201 for (i
= 1; i
< MAXCOLORS
; i
++) {
202 if (colors
[i
][0] == fg
&& colors
[i
][1] == bg
)
203 return COLOR_PAIR(i
);
205 for (i
= 1; i
< MAXCOLORS
; i
++) {
206 if (colors
[i
][0] < 0) {
207 if (init_pair(i
, fg
, bg
) == ERR
)
211 return COLOR_PAIR(i
);
217 /*************************************************************************/
218 /*************************************************************************/
220 /* Set up the screen stuff. */
222 static void screen_setup(void)
224 /* Avoid messy keyfield signals while we're setting up */
225 signal(SIGINT
, SIG_IGN
);
226 signal(SIGQUIT
, SIG_IGN
);
227 signal(SIGTSTP
, SIG_IGN
);
232 nodelay(stdscr
, TRUE
);
233 keypad(stdscr
, TRUE
);
234 leaveok(stdscr
, TRUE
);
235 if ((has_color
= has_colors()))
237 getmaxyx(stdscr
, scrheight
, scrwidth
);
238 scrwidth
--; /* Don't draw in last column--this can cause scroll */
240 /* Cancel all this when we exit. */
241 atexit(screen_cleanup
);
243 /* Catch signals so we can exit cleanly. */
244 signal(SIGINT
, sighandler
);
245 signal(SIGQUIT
, sighandler
);
246 signal(SIGTERM
, sighandler
);
247 signal(SIGHUP
, sighandler
);
248 signal(SIGSEGV
, sighandler
);
249 signal(SIGABRT
, sighandler
);
250 signal(SIGIOT
, sighandler
);
251 signal(SIGTRAP
, sighandler
);
252 signal(SIGBUS
, sighandler
);
253 signal(SIGFPE
, sighandler
);
254 signal(SIGUSR1
, sighandler
);
255 signal(SIGUSR2
, sighandler
);
256 signal(SIGALRM
, sighandler
);
258 signal(SIGSTKFLT
, sighandler
);
260 signal(SIGTSTP
, sighandler
);
261 signal(SIGXCPU
, sighandler
);
262 signal(SIGXFSZ
, sighandler
);
263 signal(SIGVTALRM
, sighandler
);
265 /* Broken pipes don't want to bother us at all. */
266 signal(SIGPIPE
, SIG_IGN
);
269 /*************************************************************************/
271 /* Redraw everything on the screen. */
273 static void screen_refresh(void)
276 touchline(stdscr
, gmsg_inputpos
, gmsg_inputheight
);
278 touchline(stdscr
, plinebuf
.y
, plinebuf
.height
);
280 touchline(stdscr
, gmsgbuf
.y
, gmsgbuf
.height
);
282 touchline(stdscr
, attdefbuf
.y
, attdefbuf
.height
);
283 wnoutrefresh(stdscr
);
287 /*************************************************************************/
289 /* Like screen_refresh(), but clear the screen first. */
291 static void screen_redraw(void)
293 clearok(stdscr
, TRUE
);
297 /*************************************************************************/
298 /************************* Text buffer routines **************************/
299 /*************************************************************************/
301 /* Put a line of text in a text buffer. */
303 static void outline(TextBuffer
*buf
, const char *s
)
305 if (buf
->line
== buf
->height
) {
308 memmove(buf
->text
, buf
->text
+1, (buf
->height
-1) * sizeof(char *));
312 mvwaddstr(buf
->win
, buf
->line
, 0, s
);
313 if (s
!= buf
->text
[buf
->line
]) /* check for restoring display */
314 buf
->text
[buf
->line
] = strdup(s
);
318 static void draw_text(int bufnum
, const char *s
)
320 char str
[1024]; /* hopefully scrwidth < 1024 */
327 case BUFFER_PLINE
: buf
= &plinebuf
; break;
328 case BUFFER_GMSG
: buf
= &gmsgbuf
; break;
329 case BUFFER_ATTDEF
: buf
= &attdefbuf
; break;
336 attrset(getcolor(COLOR_WHITE
, COLOR_BLACK
));
338 while (*s
&& isspace(*s
))
340 while (strlen(s
) > buf
->width
- indent
) {
341 t
= s
+ buf
->width
- indent
;
342 while (t
>= s
&& !isspace(*t
))
344 while (t
>= s
&& isspace(*t
))
348 t
= s
+ buf
->width
- indent
;
350 sprintf(str
, "%*s", indent
, "");
351 strncpy(str
+indent
, s
, t
-s
);
360 sprintf(str
, "%*s", indent
, "");
361 strcpy(str
+indent
, s
);
369 /*************************************************************************/
371 /* Clear the contents of a text buffer. */
373 static void clear_text(int bufnum
)
379 case BUFFER_PLINE
: buf
= &plinebuf
; break;
380 case BUFFER_GMSG
: buf
= &gmsgbuf
; break;
381 case BUFFER_ATTDEF
: buf
= &attdefbuf
; break;
385 for (i
= 0; i
< buf
->height
; i
++) {
399 /*************************************************************************/
401 /* Restore the contents of the given text buffer. */
403 static void restore_text(TextBuffer
*buf
)
406 while (buf
->line
< buf
->height
&& buf
->text
[buf
->line
])
407 outline(buf
, buf
->text
[buf
->line
]);
410 /*************************************************************************/
412 /* Open a window for the given text buffer. */
414 static void open_textwin(TextBuffer
*buf
)
416 if (buf
->height
<= 0 || buf
->width
<= 0) {
418 move(scrheight
-1, 0);
419 snprintf(str
, sizeof(str
), "ERROR: bad textwin size (%d,%d)",
420 buf
->width
, buf
->height
);
425 buf
->win
= subwin(stdscr
, buf
->height
, buf
->width
, buf
->y
, buf
->x
);
426 scrollok(buf
->win
, TRUE
);
429 buf
->text
= calloc(buf
->height
, sizeof(char *));
434 /*************************************************************************/
436 /* Close the window for the given text buffer, if it's open. */
438 static void close_textwin(TextBuffer
*buf
)
446 /*************************************************************************/
447 /************************ Field drawing routines *************************/
448 /*************************************************************************/
450 /* Are we on a wide screen (>=92 columns)? */
451 static int wide_screen
= 0;
453 /* Field display X/Y coordinates. */
454 static const int own_coord
[2] = {0,0};
455 static int other_coord
[5][2] = /* Recomputed based on screen width */
456 { {30,0}, {47,0}, {64,0}, {47,24}, {64,24} };
458 /* Position of the status window. */
459 static const int status_coord
[2] = {28,25};
460 static const int next_coord
[2] = {40,24};
461 static const int alt_status_coord
[2] = {28,2};
462 static const int alt_next_coord
[2] = {29,8};
464 /* Position of the attacks/defenses window. */
465 static const int attdef_coord
[2] = {28,28};
466 static const int alt_attdef_coord
[2] = {28,24};
468 /* Position of the text window. X coordinate is ignored. */
469 static const int field_text_coord
[2] = {0,47};
471 /* Information for drawing blocks. Color attributes are added to blocks in
472 * the setup_fields() routine. */
473 static int tile_chars
[15] =
474 { ' ','#','#','#','#','#','a','c','n','r','s','b','g','q','o' };
476 static int attdef_size
;
477 static int attdef_line
;
478 static char **attdef_text
;
480 /* Are we redrawing the entire display? */
481 static int field_redraw
= 0;
483 /*************************************************************************/
484 /*************************************************************************/
486 /* Set up the field display. */
488 static void draw_own_field(void);
489 static void draw_other_field(int player
);
490 static void draw_status(void);
491 static void draw_specials(void);
492 static void draw_gmsg_input(const char *s
, int pos
);
494 static void setup_fields(void)
496 int i
, j
, x
, y
, base
, delta
, attdefbot
;
499 if (!(tile_chars
[0] & A_ATTRIBUTES
)) {
500 for (i
= 1; i
< 15; i
++)
501 tile_chars
[i
] |= A_BOLD
;
502 tile_chars
[1] |= getcolor(COLOR_BLUE
, COLOR_BLACK
);
503 tile_chars
[2] |= getcolor(COLOR_YELLOW
, COLOR_BLACK
);
504 tile_chars
[3] |= getcolor(COLOR_GREEN
, COLOR_BLACK
);
505 tile_chars
[4] |= getcolor(COLOR_MAGENTA
, COLOR_BLACK
);
506 tile_chars
[5] |= getcolor(COLOR_RED
, COLOR_BLACK
);
510 leaveok(stdscr
, TRUE
);
511 close_textwin(&plinebuf
);
513 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
515 if (scrwidth
>= 92) {
521 delta
= (scrwidth
- base
) / 3;
522 base
+= 2 + (delta
- (FIELD_WIDTH
+5)) / 2;
523 other_coord
[0][0] = base
;
524 other_coord
[1][0] = base
+ delta
;
525 other_coord
[2][0] = base
+ delta
*2;
526 other_coord
[3][0] = base
+ delta
;
527 other_coord
[4][0] = base
+ delta
*2;
529 attdefbot
= field_text_coord
[1] - 1;
530 if (scrheight
- field_text_coord
[1] > 3) {
531 move(field_text_coord
[1], 0);
532 hline(MY_HLINE2
, scrwidth
);
534 if (scrheight
- field_text_coord
[1] > 5) {
535 move(scrheight
-2, 0);
536 hline(MY_HLINE2
, scrwidth
);
538 move(scrheight
-1, 0);
539 addstr("F1=Show Fields F2=Partyline F3=Winlist");
540 move(scrheight
-1, scrwidth
-8);
543 gmsgbuf
.y
= field_text_coord
[1]+1;
544 gmsgbuf
.height
= scrheight
- field_text_coord
[1] - 3;
546 gmsgbuf
.y
= field_text_coord
[1]+1;
547 gmsgbuf
.height
= scrheight
- field_text_coord
[1] - 1;
550 gmsgbuf
.y
= field_text_coord
[1];
551 gmsgbuf
.height
= scrheight
- field_text_coord
[1];
553 gmsgbuf
.x
= field_text_coord
[0];
554 gmsgbuf
.width
= scrwidth
;
555 open_textwin(&gmsgbuf
);
559 sprintf(buf
, "%d", my_playernum
);
560 mvaddstr(y
, x
+FIELD_WIDTH
*2+2, buf
);
561 for (i
= 2; i
< FIELD_HEIGHT
*2 && players
[my_playernum
-1][i
-2]; i
++)
562 mvaddch(y
+i
, x
+FIELD_WIDTH
*2+2, players
[my_playernum
-1][i
-2]);
564 vline(MY_VLINE
, FIELD_HEIGHT
*2);
565 move(y
, x
+FIELD_WIDTH
*2+1);
566 vline(MY_VLINE
, FIELD_HEIGHT
*2);
567 move(y
+FIELD_HEIGHT
*2, x
);
569 hline(MY_HLINE
, FIELD_WIDTH
*2);
570 move(y
+FIELD_HEIGHT
*2, x
+FIELD_WIDTH
*2+1);
572 mvaddstr(y
+FIELD_HEIGHT
*2+2, x
, "Specials:");
576 for (j
= 0; j
< 5; j
++) {
577 x
= other_coord
[j
][0];
578 y
= other_coord
[j
][1];
580 vline(MY_VLINE
, FIELD_HEIGHT
);
581 move(y
, x
+FIELD_WIDTH
+1);
582 vline(MY_VLINE
, FIELD_HEIGHT
);
583 move(y
+FIELD_HEIGHT
, x
);
585 hline(MY_HLINE
, FIELD_WIDTH
);
586 move(y
+FIELD_HEIGHT
, x
+FIELD_WIDTH
+1);
588 if (j
+1 >= my_playernum
) {
589 sprintf(buf
, "%d", j
+2);
590 mvaddstr(y
, x
+FIELD_WIDTH
+2, buf
);
592 for (i
= 0; i
< FIELD_HEIGHT
-2 && players
[j
+1][i
]; i
++)
593 mvaddch(y
+i
+2, x
+FIELD_WIDTH
+2, players
[j
+1][i
]);
595 draw_other_field(j
+2);
597 sprintf(buf
, "%d", j
+1);
598 mvaddstr(y
, x
+FIELD_WIDTH
+2, buf
);
600 for (i
= 0; i
< FIELD_HEIGHT
-2 && players
[j
][i
]; i
++)
601 mvaddch(y
+i
+2, x
+FIELD_WIDTH
+2, players
[j
][i
]);
603 draw_other_field(j
+1);
608 x
= alt_status_coord
[0];
609 y
= alt_status_coord
[1];
610 mvaddstr(y
, x
, "Lines:");
611 mvaddstr(y
+1, x
, "Level:");
612 x
= alt_next_coord
[0];
613 y
= alt_next_coord
[1];
614 mvaddstr(y
-2, x
-1, "Next piece:");
618 mvaddch(y
-1, x
+8, MY_URCORNER
);
626 mvaddch(y
+8, x
+8, MY_LRCORNER
);
630 mvaddstr(y
-1, x
, "Next piece:");
631 mvaddstr(y
, x
, "Lines:");
632 mvaddstr(y
+1, x
, "Level:");
637 attdefbuf
.x
= wide_screen
? alt_attdef_coord
[0] : attdef_coord
[0];
638 attdefbuf
.y
= wide_screen
? alt_attdef_coord
[1] : attdef_coord
[1];
639 attdefbuf
.width
= (other_coord
[3][0]-1) - attdefbuf
.x
;
640 attdefbuf
.height
= (attdefbot
+1) - attdefbuf
.y
;
641 open_textwin(&attdefbuf
);
644 delwin(gmsg_inputwin
);
645 gmsg_inputwin
= NULL
;
646 draw_gmsg_input(NULL
, -1);
653 /*************************************************************************/
655 /* Display the player's own field. */
657 static void draw_own_field(void)
660 Field
*f
= &fields
[my_playernum
-1];
662 if (dispmode
!= MODE_FIELDS
)
666 for (y
= 0; y
< 22; y
++) {
667 for (x
= 0; x
< 12; x
++) {
668 int c
= tile_chars
[(*f
)[y
][x
]];
669 mvaddch(y0
+y
*2, x0
+x
*2, c
);
671 mvaddch(y0
+y
*2+1, x0
+x
*2, c
);
676 delwin(gmsg_inputwin
);
677 gmsg_inputwin
= NULL
;
678 draw_gmsg_input(NULL
, -1);
684 /*************************************************************************/
686 /* Display another player's field. */
688 static void draw_other_field(int player
)
693 if (dispmode
!= MODE_FIELDS
)
695 f
= &fields
[player
-1];
696 if (player
> my_playernum
)
699 x0
= other_coord
[player
][0]+1;
700 y0
= other_coord
[player
][1];
701 for (y
= 0; y
< 22; y
++) {
703 for (x
= 0; x
< 12; x
++)
704 addch(tile_chars
[(*f
)[y
][x
]]);
707 delwin(gmsg_inputwin
);
708 gmsg_inputwin
= NULL
;
709 draw_gmsg_input(NULL
, -1);
715 /*************************************************************************/
717 /* Display the current game status (level, lines, next piece). */
719 static void draw_status(void)
722 char buf
[32], shape
[4][4];
724 x
= wide_screen
? alt_status_coord
[0] : status_coord
[0];
725 y
= wide_screen
? alt_status_coord
[1] : status_coord
[1];
726 sprintf(buf
, "%d", lines
>99999 ? 99999 : lines
);
727 mvaddstr(y
, x
+7, buf
);
728 sprintf(buf
, "%d", levels
[my_playernum
]);
729 mvaddstr(y
+1, x
+7, buf
);
730 x
= wide_screen
? alt_next_coord
[0] : next_coord
[0];
731 y
= wide_screen
? alt_next_coord
[1] : next_coord
[1];
732 if (get_shape(next_piece
, 0, shape
) == 0) {
733 for (j
= 0; j
< 4; j
++) {
736 for (i
= 0; i
< 4; i
++) {
739 addch(tile_chars
[shape
[j
][i
]]);
740 addch(tile_chars
[shape
[j
][i
]]);
741 move(y
+j
*2+1, x
+i
*2);
742 addch(tile_chars
[shape
[j
][i
]]);
743 addch(tile_chars
[shape
[j
][i
]]);
745 addch(tile_chars
[shape
[j
][i
]]);
751 /*************************************************************************/
753 /* Display the special inventory and description of the current special. */
755 static const char *descs
[] = {
760 "Clear Random Blocks ",
762 "Clear Special Blocks",
768 static void draw_specials(void)
772 if (dispmode
!= MODE_FIELDS
)
776 mvaddstr(y
, x
, descs
[specials
[0]+1]);
779 while (i
< special_capacity
&& specials
[i
] >= 0 && x
< attdef_coord
[0]-1) {
780 addch(tile_chars
[specials
[i
]+6]);
784 while (x
< attdef_coord
[0]-1) {
785 addch(tile_chars
[0]);
792 /*************************************************************************/
794 /* Display an attack/defense message. */
796 static const char *msgs
[][2] = {
797 { "cs1", "1 Line Added to All" },
798 { "cs2", "2 Lines Added to All" },
799 { "cs4", "4 Lines Added to All" },
801 { "c", "Clear Line" },
802 { "n", "Nuke Field" },
803 { "r", "Clear Random Blocks" },
804 { "s", "Switch Fields" },
805 { "b", "Clear Special Blocks" },
806 { "g", "Block Gravity" },
807 { "q", "Blockquake" },
808 { "o", "Block Bomb" },
812 static void draw_attdef(const char *type
, int from
, int to
)
817 width
= other_coord
[4][0] - attdef_coord
[0] - 1;
818 for (i
= 0; msgs
[i
][0]; i
++) {
819 if (strcmp(type
, msgs
[i
][0]) == 0)
824 strcpy(buf
, msgs
[i
][1]);
826 sprintf(buf
+strlen(buf
), " on %s", players
[to
-1]);
828 sprintf(buf
+strlen(buf
), " by Server");
830 sprintf(buf
+strlen(buf
), " by %s", players
[from
-1]);
831 draw_text(BUFFER_ATTDEF
, buf
);
834 /*************************************************************************/
836 /* Display the in-game text window. */
838 static void draw_gmsg_input(const char *s
, int pos
)
840 static int start
= 0; /* Start of displayed part of input line */
841 static const char *last_s
;
853 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
855 if (!gmsg_inputwin
) {
856 gmsg_inputpos
= scrheight
/2 - 1;
857 gmsg_inputheight
= 3;
859 subwin(stdscr
, gmsg_inputheight
, scrwidth
, gmsg_inputpos
, 0);
860 werase(gmsg_inputwin
);
861 leaveok(gmsg_inputwin
, FALSE
);
862 leaveok(stdscr
, FALSE
);
863 mvwaddstr(gmsg_inputwin
, 1, 0, "Text>");
866 if (strlen(s
) < scrwidth
-7) {
868 mvwaddstr(gmsg_inputwin
, 1, 6, s
);
869 wmove(gmsg_inputwin
, 1, 6+strlen(s
));
870 move(gmsg_inputpos
+1, 6+strlen(s
));
871 wclrtoeol(gmsg_inputwin
);
872 wmove(gmsg_inputwin
, 1, 6+pos
);
873 move(gmsg_inputpos
+1, 6+pos
);
879 } else if (pos
> start
+ scrwidth
-15) {
880 start
= pos
- (scrwidth
-15);
881 if (start
> strlen(s
) - (scrwidth
-7))
882 start
= strlen(s
) - (scrwidth
-7);
884 mvwaddnstr(gmsg_inputwin
, 1, 6, s
+start
, scrwidth
-6);
885 wmove(gmsg_inputwin
, 1, 6 + (pos
-start
));
886 move(gmsg_inputpos
+1, 6 + (pos
-start
));
891 /*************************************************************************/
893 /* Clear the in-game text window. */
895 static void clear_gmsg_input(void)
898 delwin(gmsg_inputwin
);
899 gmsg_inputwin
= NULL
;
900 leaveok(stdscr
, TRUE
);
901 touchline(stdscr
, gmsg_inputpos
, gmsg_inputheight
);
907 /*************************************************************************/
908 /*************************** Partyline display ***************************/
909 /*************************************************************************/
911 static void setup_partyline(void)
915 close_textwin(&gmsgbuf
);
916 close_textwin(&attdefbuf
);
919 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
921 plinebuf
.x
= plinebuf
.y
= 0;
922 plinebuf
.width
= scrwidth
;
923 plinebuf
.height
= scrheight
-4;
924 open_textwin(&plinebuf
);
926 move(scrheight
-4, 0);
927 hline(MY_HLINE
, scrwidth
);
928 move(scrheight
-3, 0);
931 move(scrheight
-2, 0);
932 hline(MY_HLINE2
, scrwidth
);
934 move(scrheight
-1, 0);
935 addstr("F1=Show Fields F2=Partyline F3=Winlist");
936 move(scrheight
-1, scrwidth
-8);
940 move(scrheight
-3, 2);
941 leaveok(stdscr
, FALSE
);
945 /*************************************************************************/
947 static void draw_partyline_input(const char *s
, int pos
)
949 static int start
= 0; /* Start of displayed part of input line */
951 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
952 if (strlen(s
) < scrwidth
-3) {
954 mvaddstr(scrheight
-3, 2, s
);
955 move(scrheight
-3, 2+strlen(s
));
957 move(scrheight
-3, 2+pos
);
963 } else if (pos
> start
+ scrwidth
-11) {
964 start
= pos
- (scrwidth
-11);
965 if (start
> strlen(s
) - (scrwidth
-3))
966 start
= strlen(s
) - (scrwidth
-3);
968 mvaddnstr(scrheight
-3, 2, s
+start
, scrwidth
-2);
969 move(scrheight
-3, 2 + (pos
-start
));
974 /*************************************************************************/
975 /**************************** Winlist display ****************************/
976 /*************************************************************************/
978 static void setup_winlist(void)
983 leaveok(stdscr
, TRUE
);
984 close_textwin(&plinebuf
);
986 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
988 for (i
= 0; i
< MAXWINLIST
&& *winlist
[i
].name
; i
++) {
989 x
= scrwidth
/2 - strlen(winlist
[i
].name
);
992 if (winlist
[i
].team
) {
995 mvaddstr(i
*2, x
-4, "<T>");
997 mvaddstr(i
*2, x
, winlist
[i
].name
);
998 snprintf(buf
, sizeof(buf
), "%4d", winlist
[i
].points
);
999 if (winlist
[i
].games
) {
1000 int avg100
= winlist
[i
].points
*100 / winlist
[i
].games
;
1001 snprintf(buf
+strlen(buf
), sizeof(buf
)-strlen(buf
),
1002 " %d.%02d",avg100
/100, avg100
%100);
1004 x
+= strlen(winlist
[i
].name
) + 2;
1005 if (x
> scrwidth
- strlen(buf
))
1006 x
= scrwidth
- strlen(buf
);
1007 mvaddstr(i
*2, x
, buf
);
1010 move(scrheight
-2, 0);
1011 hline(MY_HLINE2
, scrwidth
);
1013 move(scrheight
-1, 0);
1014 addstr("F1=Show Fields F2=Partyline F3=Winlist");
1015 move(scrheight
-1, scrwidth
-8);
1022 /*************************************************************************/
1023 /************************** Interface declaration ************************/
1024 /*************************************************************************/
1026 Interface tty_interface
= {
1047 draw_partyline_input
,
1052 /*************************************************************************/