2
* typespeed - measures your typing speed
3
* Copyright (C) 1999-2003 Jani Ollikainen <bestis@iki.fi>
4
* & Jaakko Manelius <jman@iki.fi>
5
* Copyright (C) 2006-2007 Tobias Stoeckmann <tobias@bugol.de>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
* menu.c - menu & misc drawing functions
28
#endif /* HAVE_CONFIG_H */
30
#ifdef HAVE_SYS_PARAM_H
31
#include <sys/param.h>
32
#endif /* HAVE_SYS_PARAM_H */
40
#endif /* HAVE_STDLIB_H */
44
#endif /* HAVE_STRING_H */
47
#include "typespeed.h"
49
#define _(string) gettext(string)
51
extern int chooseruleset(void);
52
extern int choosewordfile(int);
53
extern void closenetwork(void);
54
extern unsigned long cstrl(char *);
55
extern void xerrx(int, const char *, ...);
56
extern int initnetwork(char *, int);
57
extern unsigned short level(int);
58
extern void liima_mvgetnstr(int, int, char *, int);
59
extern void multipmenu(void);
60
extern void xcolor_set(short);
62
static int dochange(int);
64
void drawscreen(void);
65
void drawstatus(unsigned);
66
int fileselmenu(int, struct finfo *, const char *);
67
static int getnum(const char *, unsigned long, unsigned long);
68
void initstatus(char *);
69
void multipmenu(void);
70
void nowordlist(void);
71
void optionmenu(void);
72
void pressanykey(int, int);
74
void showhighscores(void);
78
extern char *rankki[11];
88
/* Switches "number" from 1 to 0 or any other value to 1. */
92
return (number == 1) ? 0 : 1;
95
/* Draws main menu onto screen. */
101
mvaddstr( 3, 30, "Typespeed ");
104
mvaddstr( 5, 30, _("1. Test Your Speed"));
106
mvaddstr( 6, 30, _("2. Close Connection"));
108
mvaddstr( 6, 30, _("2. Network Head2Head"));
109
mvaddstr( 7, 30, _("3. Story/Credits/RTFM!"));
110
mvaddstr( 8, 30, _("4. Show Highscores"));
111
mvaddstr( 9, 30, _("5. Options"));
112
mvaddstr(10, 30, _("6. Game Rules"));
113
mvaddstr(11, 30, _("7. Quit"));
115
mvaddstr(13, 30, _("Choose: "));
118
/* Clears screen and draws status bar. */
126
hline(ACS_HLINE, 80);
128
mvaddch(23, 21, '<');
132
_("Rank: %------- Score: %--- WPM: %-- CPS: %---- Misses: %-"));
134
/* sets color to 2: NET, CHE need this */
139
mvaddstr(22, 70, "H2H");
142
mvaddstr(22, 70, "NET");
149
mvaddstr(22, 73, "CHE");
155
* Prints status values - no descriptions though!
156
* Cursor will be put into "inputpos" (y = 21, x = 2 + inputpos).
159
drawstatus(unsigned inputpos)
161
mvprintw(23, pos.rank, "%-9s", rankki[level(now.score)]);
164
mvprintw(23, pos.score, "%4lu", now.score);
165
mvprintw(23, pos.wpm, "%3lu", now.wpm);
166
mvprintw(23, pos.speed, now.speed < 10.0f ? " %2.2f" : "%2.2f",
168
mvprintw(23, pos.misses, "%2lu", misses);
171
move(23, 2 + inputpos);
174
/* Prints file selection menu. */
176
fileselmenu(int tot, struct finfo *thingie, const char *title)
182
mvprintw(2, 5, _("Choose a %s (UP/DOWN/ENTER):"), title);
184
for (k = 0; k < 17; k++)
185
mvaddstr(k + 4, 5, thingie[k].descr);
187
for (k = 0; k < tot; k++)
188
mvaddstr(k + 4, 5, thingie[k].descr);
191
mvaddstr(4, 1, "->");
195
* And thanks for xmunkki, he made my day and
196
* "solved" this, what i didn't get right (or did
197
* but i used 2 extra variables. :)
216
mvaddstr(4, 5, thingie[k].descr);
223
if (cpos < 16 && cpos < tot - 1) {
231
mvaddstr(20, 5, thingie[k].descr);
240
mvaddstr(cpos + 3, 1, " ");
241
mvaddstr(cpos + 5, 1, " ");
242
mvaddstr(cpos + 4, 1, "->");
249
* Asks player about a specific value named by "string". If the entered
250
* value is smaller or equal min, or larger or equal max, 0 is returned.
251
* If a string (and not a number) has been entered, 0 is returned, too.
253
* Sets rules.hightype to 0, so a customized rule set cannot reach top10.
256
getnum(const char *string, unsigned long min, unsigned long max)
262
memset(clr, ' ', sizeof(clr));
263
clr[sizeof(clr) - 1] = '\0';
265
mvaddstr(17, 0, clr);
266
mvaddstr(17, 30, string);
267
liima_mvgetnstr(17, 31 + strlen(string), entr, sizeof(entr) - 1);
268
entr[sizeof(entr) - 1] = '\0';
270
if (!(res = cstrl(entr)) && errno)
272
if (res > min && res < max) {
280
* Note places where rank, score, wpm, cps, and misses have to
281
* be printed, so translators have a much easier job.
283
* "Rank: %------- Score: %--- WPM: %-- CPS: %---- Misses: %-"
286
initstatus(char *str)
291
for (field = 0, p = str; *p != '\0'; p++) {
297
pos.rank = p - str + 23;
300
pos.score = p - str + 23;
303
pos.wpm = p - str + 23;
306
pos.speed = p - str + 23;
309
pos.misses = p - str + 23;
312
xerrx(1, "1wrong status format");
319
xerrx(1, "2wrong status format");
322
/* Draws multiplayer menu. */
327
char port[6], serv[MAXHOSTNAMELEN];
334
mvaddstr(3, 30, "Typespeed ");
337
mvaddstr( 5, 30, _("1. Server"));
338
mvaddstr( 6, 30, _("2. Client"));
339
mvaddstr( 7, 30, _("3. Port"));
340
mvaddstr( 8, 30, _("4. Player Name"));
341
mvaddstr( 9, 30, _("5. Return"));
344
mvprintw( 7, 50, "%d", opt.port);
345
mvprintw( 8, 50, "%s", opt.name);
346
mvaddstr(11, 30, _("Choose: "));
354
mvaddstr(11, 30, _("Enter Host:"));
355
liima_mvgetnstr(11, 31 +
356
strlen(_("Enter Host:")), serv,
358
serv[sizeof(serv) - 1] = '\0';
362
mvaddstr(11, 30, _("Enter Port:"));
363
liima_mvgetnstr(11, 31 + strlen(_("Enter Port:")), port,
365
port[sizeof(port) - 1] = '\0';
366
opt.port = strtol(port, NULL, 10);
367
if (opt.port <= 1024)
372
mvaddstr(11, 30, _("Enter Name:"));
373
liima_mvgetnstr(11, 31 +
374
strlen(_("Enter Name:")), opt.name,
375
sizeof(opt.name) - 1);
376
opt.name[sizeof(opt.name) - 1] = '\0';
389
mvaddstr(3, 30, "Typespeed ");
392
mvaddstr(5, 30, _("When you get connect, choose a word list and"));
393
mvaddstr(6, 30, _("then wait for the game start. The game starts as"));
394
mvaddstr(7, 30, _("soon as the other player has chosen a word list."));
397
initnetwork(serv, 1);
402
* Prints "No word lists found...".
403
* This function just exists to split all output out of file.c.
409
mvaddstr(1, 5, _("No word lists found..."));
413
/* Draws option menu. */
422
mvaddstr(3, 30, "Typespeed ");
425
mvaddstr(5, 30, _("1. Colors"));
426
mvaddstr(6, 30, _("2. Cheat"));
427
mvaddstr(7, 30, _("3. Return"));
431
mvaddstr(5, 44, _("ON"));
433
mvaddstr(6, 44, _("ON"));
437
mvaddstr(5, 44, _("OFF"));
439
mvaddstr(6, 44, _("OFF"));
442
mvaddstr(12, 30, _("Choose: "));
444
switch (wheretogo = getch()) {
446
opt.cheat = dochange(opt.cheat);
451
opt.usecolors = dochange(opt.usecolors);
456
} while (wheretogo != '3');
459
/* This function waits until a key has been pressed */
461
pressanykey(int y, int x)
465
mvaddstr(y, x, _("Press any key to continue..."));
469
/* Draws rules menu. */
479
mvaddstr( 3, 30, "Typespeed ");
482
mvaddstr( 5, 30, _("Current Rule Set:"));
484
mvaddstr( 7, 30, _("1. Load Another Rule Set"));
485
mvaddstr( 8, 30, _("2. Misses Limit:"));
486
mvaddstr( 9, 30, _("3. Word Length:"));
488
mvaddstr(10, 30, _("4. Words On Screen:"));
490
mvaddstr(11, 30, _(" High Score Enabled:"));
491
mvaddstr(12, 30, _("6. Speed Step:"));
492
mvaddstr(13, 30, _("7. Speed Range:"));
494
mvaddstr(14, 30, _("8. Smoothness:"));
495
mvaddstr(15, 30, _("9. Return"));
498
mvprintw( 5, 31 + strlen(_("Current Rule Set:")), "%s",
500
mvprintw( 8, 31 + strlen(_("2. Misses Limit:")), "%d",
502
mvprintw( 9, 31 + strlen(_("3. Word Length:")), "%2d",
504
mvprintw( 9, 36 + strlen(_("3. Word Length:")), "%2d",
506
mvprintw(10, 31 + strlen(_("4. Words On Screen:")), "%2d",
508
mvprintw(10, 36 + strlen(_("4. Words On Screen:")), "%2d",
511
mvaddstr(11, 31 + strlen(_(" High Score Enabled:")),
514
mvaddstr(11, 31 + strlen(_(" High Score Enabled:")),
516
mvprintw(12, 31 + strlen(_("6. Speed Step:")), "%3d",
518
mvprintw(13, 31 + strlen(_("7. Speed Range:")), "%2d",
521
mvprintw(13, 36 + strlen(_("7. Speed Range:")), "%2d",
524
mvaddstr(13, 37 + strlen(_("7. Speed Range:")),
527
mvaddstr(14, 31 + strlen(_("8. Smoothness:")),
530
mvaddstr(14, 31 + strlen(_("8. Smoothness:")), _("no"));
532
mvaddstr(17, 30, _("Choose: "));
534
switch (wheretogo = getch()) {
539
if ((tmp = getnum(_("Misses Limit:"), 0, 100)))
543
if ((tmp = getnum(_("Min Length:"), 0, 20)))
545
if ((tmp = getnum(_("Max Length:"), 0, 20)))
547
if (rules.minlen > rules.maxlen)
548
rules.maxlen = rules.minlen;
551
if ((tmp = getnum(_("Min Words:"), 0, 23)))
552
rules.minwords = tmp;
553
if ((tmp = getnum(_("Max Words:"), 0, 23)))
554
rules.maxwords = tmp;
555
if (rules.minwords > rules.maxwords)
556
rules.maxwords = rules.minwords;
559
if ((tmp = getnum(_("Speed Step:"), 0, 1000)))
563
if ((tmp = getnum(_("Min Speed:"), 0, 100)))
564
rules.minspeed = tmp;
565
rules.maxspeed = getnum(_("Max Speed:"), 0, 100);
566
if (rules.minspeed > rules.maxspeed)
570
rules.smooth = dochange(rules.smooth);
576
} while (wheretogo != '9');
579
/* Shows high scores. */
586
/* Draws credits onto screen. */
592
mvaddstr( 3, 2, "Typespeed ");
595
_("Typespeed is made by Jani Ollikainen <bestis@iki.fi>"));
597
_(" & Jaakko Manelius <jman@iki.fi>"));
599
_("Current maintainer is Tobias Stoeckmann <tobias@bugol.de>"));
602
_("Typespeed's idea is ripped from ztspeed (a dos game made"));
604
_("by Zorlim). Typespeed doesn't give scores that can be"));
606
_("compared with ztspeed anymore. We wanted to use our way."));
608
_("Idea of the game should be clear to anyone, just type and"));
610
_("type it fast, or be a lewser."));
612
_("Bugs/Ideas/Comments to <tobias@bugol.de>"));