mirror of
https://git.zap.org.au/git/trader.git
synced 2025-02-02 15:08:13 -05:00
Continue to move text output to the new interfaces
This commit is contained in:
parent
5bb48fe35f
commit
746155078b
178
src/game.c
178
src/game.c
@ -110,14 +110,21 @@ void init_game (void)
|
|||||||
{
|
{
|
||||||
// Try to load an old game, if possible
|
// Try to load an old game, if possible
|
||||||
if (game_num != 0) {
|
if (game_num != 0) {
|
||||||
newtxwin(5, 30, 6, WCENTER, true, attr_status_window);
|
chtype *chbuf = xmalloc(BUFSIZE * sizeof(chtype));
|
||||||
center(curwin, 2, attr_status_window, "Loading game %d... ", game_num);
|
int lines, width;
|
||||||
|
|
||||||
|
lines = prepstr(chbuf, BUFSIZE, attr_status_window, 0, 0, 1,
|
||||||
|
WIN_COLS - 7, &width, 1,
|
||||||
|
"Loading game %d... ", game_num);
|
||||||
|
newtxwin(5, width + 5, 6, WCENTER, true, attr_status_window);
|
||||||
|
pr_center(curwin, 2, 0, chbuf, 1, &width);
|
||||||
wrefresh(curwin);
|
wrefresh(curwin);
|
||||||
|
|
||||||
game_loaded = load_game(game_num);
|
game_loaded = load_game(game_num);
|
||||||
|
|
||||||
deltxwin();
|
deltxwin();
|
||||||
txrefresh();
|
txrefresh();
|
||||||
|
free(chbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise game data, if not already loaded
|
// Initialise game data, if not already loaded
|
||||||
@ -134,18 +141,25 @@ void init_game (void)
|
|||||||
choice = ask_game_number();
|
choice = ask_game_number();
|
||||||
|
|
||||||
if (choice != ERR) {
|
if (choice != ERR) {
|
||||||
|
// Try to load the game, if possible
|
||||||
|
|
||||||
|
chtype *chbuf = xmalloc(BUFSIZE * sizeof(chtype));
|
||||||
|
int lines, width;
|
||||||
|
|
||||||
game_num = choice;
|
game_num = choice;
|
||||||
|
|
||||||
// Try to load the game, if possible
|
lines = prepstr(chbuf, BUFSIZE, attr_status_window,
|
||||||
newtxwin(5, 30, 9, WCENTER, true, attr_status_window);
|
0, 0, 1, WIN_COLS - 7, &width, 1,
|
||||||
center(curwin, 2, attr_status_window,
|
|
||||||
"Loading game %d... ", game_num);
|
"Loading game %d... ", game_num);
|
||||||
|
newtxwin(5, width + 5, 9, WCENTER, true, attr_status_window);
|
||||||
|
pr_center(curwin, 2, 0, chbuf, 1, &width);
|
||||||
wrefresh(curwin);
|
wrefresh(curwin);
|
||||||
|
|
||||||
game_loaded = load_game(game_num);
|
game_loaded = load_game(game_num);
|
||||||
|
|
||||||
deltxwin();
|
deltxwin();
|
||||||
txrefresh();
|
txrefresh();
|
||||||
|
free(chbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
deltxwin(); // "Enter game number" window
|
deltxwin(); // "Enter game number" window
|
||||||
@ -227,22 +241,24 @@ void init_game (void)
|
|||||||
|
|
||||||
static int ask_number_players (void)
|
static int ask_number_players (void)
|
||||||
{
|
{
|
||||||
|
chtype *chbuf;
|
||||||
|
int lines, maxwidth;
|
||||||
|
int widthbuf[2];
|
||||||
int key, ret;
|
int key, ret;
|
||||||
bool done;
|
bool done;
|
||||||
|
|
||||||
|
|
||||||
// Ask for the number of players
|
chbuf = xmalloc(BUFSIZE * sizeof(chtype));
|
||||||
newtxwin(5, 62, 3, WCENTER, true, attr_normal_window);
|
lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0,
|
||||||
|
sizeof(widthbuf) / sizeof(widthbuf[0]), WIN_COLS - 7,
|
||||||
|
widthbuf, sizeof(widthbuf) / sizeof(widthbuf[0]),
|
||||||
|
"Enter number of players [^{1^}-^{%d^}] "
|
||||||
|
"or ^{<C>^} to continue a game: ", MAX_PLAYERS);
|
||||||
|
maxwidth = MAX(widthbuf[0], widthbuf[1]) + 5;
|
||||||
|
|
||||||
mvwaddstr(curwin, 2, 2, "Enter number of players ");
|
newtxwin(lines + 4, maxwidth, 3, WCENTER, true, attr_normal_window);
|
||||||
waddstr(curwin, "[");
|
pr_left(curwin, 2, 2, chbuf, lines, widthbuf);
|
||||||
attrpr(curwin, attr_keycode, "1");
|
free(chbuf);
|
||||||
waddstr(curwin, "-");
|
|
||||||
attrpr(curwin, attr_keycode, "%d", MAX_PLAYERS);
|
|
||||||
waddstr(curwin, "]");
|
|
||||||
waddstr(curwin, " or ");
|
|
||||||
attrpr(curwin, attr_keycode, "<C>");
|
|
||||||
waddstr(curwin, " to continue a game: ");
|
|
||||||
|
|
||||||
curs_set(CURS_ON);
|
curs_set(CURS_ON);
|
||||||
wrefresh(curwin);
|
wrefresh(curwin);
|
||||||
@ -289,22 +305,24 @@ static int ask_number_players (void)
|
|||||||
|
|
||||||
int ask_game_number (void)
|
int ask_game_number (void)
|
||||||
{
|
{
|
||||||
|
chtype *chbuf;
|
||||||
|
int lines, maxwidth;
|
||||||
|
int widthbuf[2];
|
||||||
int key, ret;
|
int key, ret;
|
||||||
bool done;
|
bool done;
|
||||||
|
|
||||||
|
|
||||||
// Ask which game to load
|
chbuf = xmalloc(BUFSIZE * sizeof(chtype));
|
||||||
newtxwin(5, 54, 6, WCENTER, true, attr_normal_window);
|
lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0,
|
||||||
|
sizeof(widthbuf) / sizeof(widthbuf[0]), WIN_COLS - 7,
|
||||||
|
widthbuf, sizeof(widthbuf) / sizeof(widthbuf[0]),
|
||||||
|
"Enter game number [^{1^}-^{9^}] "
|
||||||
|
"or ^{<CTRL><C>^} to cancel: ");
|
||||||
|
maxwidth = MAX(widthbuf[0], widthbuf[1]) + 5;
|
||||||
|
|
||||||
mvwaddstr(curwin, 2, 2, "Enter game number ");
|
newtxwin(lines + 4, maxwidth, 6, WCENTER, true, attr_normal_window);
|
||||||
waddstr(curwin, "[");
|
pr_left(curwin, 2, 2, chbuf, lines, widthbuf);
|
||||||
attrpr(curwin, attr_keycode, "1");
|
free(chbuf);
|
||||||
waddstr(curwin, "-");
|
|
||||||
attrpr(curwin, attr_keycode, "9");
|
|
||||||
waddstr(curwin, "]");
|
|
||||||
waddstr(curwin, " or ");
|
|
||||||
attrpr(curwin, attr_keycode, "<CTRL><C>");
|
|
||||||
waddstr(curwin, " to cancel: ");
|
|
||||||
|
|
||||||
curs_set(CURS_ON);
|
curs_set(CURS_ON);
|
||||||
wrefresh(curwin);
|
wrefresh(curwin);
|
||||||
@ -349,7 +367,6 @@ void ask_player_names (void)
|
|||||||
// Ask for the player's name
|
// Ask for the player's name
|
||||||
|
|
||||||
newtxwin(5, WIN_COLS - 4, 9, WCENTER, true, attr_normal_window);
|
newtxwin(5, WIN_COLS - 4, 9, WCENTER, true, attr_normal_window);
|
||||||
|
|
||||||
mvwaddstr(curwin, 2, 2, "Please enter your name: ");
|
mvwaddstr(curwin, 2, 2, "Please enter your name: ");
|
||||||
|
|
||||||
int x = getcurx(curwin);
|
int x = getcurx(curwin);
|
||||||
@ -366,23 +383,35 @@ void ask_player_names (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newtxwin(5, 44, 6, WCENTER, true, attr_normal_window);
|
chtype *chbuf = xmalloc(BUFSIZE * sizeof(chtype));
|
||||||
mvwaddstr(curwin, 2, 2, "Do you need any instructions?");
|
int lines, width;
|
||||||
if (answer_yesno(curwin, attr_keycode)) {
|
|
||||||
|
lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0,
|
||||||
|
1, WIN_COLS - YESNO_COLS - 6, &width, 1,
|
||||||
|
"Do you need any instructions? [^{Y^}/^{N^}] ");
|
||||||
|
newtxwin(5, width + YESNO_COLS + 4, 6, WCENTER, true,
|
||||||
|
attr_normal_window);
|
||||||
|
pr_left(curwin, 2, 2, chbuf, lines, &width);
|
||||||
|
free(chbuf);
|
||||||
|
if (answer_yesno(curwin)) {
|
||||||
show_help();
|
show_help();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Ask for all of the player names
|
// Ask for all of the player names
|
||||||
|
|
||||||
|
chtype *chbuf = xmalloc(BUFSIZE * sizeof(chtype));
|
||||||
|
int lines, width;
|
||||||
|
|
||||||
bool entered[MAX_PLAYERS];
|
bool entered[MAX_PLAYERS];
|
||||||
bool done, modified;
|
bool done, modified;
|
||||||
int cur, len, i;
|
int cur, len, i;
|
||||||
|
|
||||||
newtxwin(number_players + 5, WIN_COLS - 4, 9, WCENTER,
|
newtxwin(number_players + 5, WIN_COLS - 4, 9, WCENTER,
|
||||||
true, attr_normal_window);
|
true, attr_normal_window);
|
||||||
|
lines = prepstr(chbuf, BUFSIZE, attr_title, 0, 0, 1, WIN_COLS - 8,
|
||||||
center(curwin, 1, attr_title, " Enter Player Names ");
|
&width, 1, " Enter Player Names ");
|
||||||
|
pr_center(curwin, 1, 0, chbuf, lines, &width);
|
||||||
|
|
||||||
for (i = 0; i < number_players; i++) {
|
for (i = 0; i < number_players; i++) {
|
||||||
player[i].name = NULL;
|
player[i].name = NULL;
|
||||||
@ -463,11 +492,17 @@ void ask_player_names (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newtxwin(5, 50, 6, WCENTER, true, attr_normal_window);
|
lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_keycode, 0,
|
||||||
mvwaddstr(curwin, 2, 2, "Does any player need instructions?");
|
1, WIN_COLS - YESNO_COLS - 6, &width, 1,
|
||||||
if (answer_yesno(curwin, attr_keycode)) {
|
"Does any player need instructions? [^{Y^}/^{N^}] ");
|
||||||
|
newtxwin(5, width + YESNO_COLS + 4, 6, WCENTER, true,
|
||||||
|
attr_normal_window);
|
||||||
|
pr_left(curwin, 2, 2, chbuf, lines, &width);
|
||||||
|
if (answer_yesno(curwin)) {
|
||||||
show_help();
|
show_help();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(chbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
deltxwin(); // "Need instructions?" window
|
deltxwin(); // "Need instructions?" window
|
||||||
@ -552,48 +587,30 @@ void end_game (void)
|
|||||||
|
|
||||||
void show_map (bool closewin)
|
void show_map (bool closewin)
|
||||||
{
|
{
|
||||||
int n, x, y;
|
chtype *chbuf = xmalloc(BUFSIZE * sizeof(chtype));
|
||||||
|
int lines, width;
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
|
||||||
newtxwin(MAX_Y + 4, WIN_COLS, 1, WCENTER, true, attr_map_window);
|
newtxwin(MAX_Y + 4, WIN_COLS, 1, WCENTER, true, attr_map_window);
|
||||||
|
|
||||||
// Draw various borders
|
// Draw various borders and highlights
|
||||||
mvwaddch(curwin, 2, 0, ACS_LTEE);
|
mvwaddch(curwin, 2, 0, ACS_LTEE);
|
||||||
whline(curwin, ACS_HLINE, getmaxx(curwin) - 2);
|
whline(curwin, ACS_HLINE, getmaxx(curwin) - 2);
|
||||||
mvwaddch(curwin, 2, getmaxx(curwin) - 1, ACS_RTEE);
|
mvwaddch(curwin, 2, getmaxx(curwin) - 1, ACS_RTEE);
|
||||||
|
mvwhline(curwin, 1, 2, ' ' | attr_mapwin_title, getmaxx(curwin) - 4);
|
||||||
|
|
||||||
// Display current player and turn number
|
// Display current player and turn number
|
||||||
wattrset(curwin, attr_mapwin_title);
|
lines = prepstr(chbuf, BUFSIZE, attr_mapwin_title, attr_mapwin_highlight,
|
||||||
mvwaddstr(curwin, 1, 2, " ");
|
0, 1, WIN_COLS - 4, &width, 1, " Player: ^{%s^} ",
|
||||||
waddstr(curwin, "Player: ");
|
player[current_player].name);
|
||||||
n = getmaxx(curwin) - getcurx(curwin) - 4;
|
pr_left(curwin, 1, 2, chbuf, lines, &width);
|
||||||
wattrset(curwin, attr_mapwin_highlight);
|
|
||||||
wprintw(curwin, "%-*.*s", n, n, player[current_player].name);
|
|
||||||
wattrset(curwin, attr_mapwin_title);
|
|
||||||
waddstr(curwin, " ");
|
|
||||||
|
|
||||||
if (turn_number != max_turn) {
|
lines = prepstr(chbuf, BUFSIZE, attr_mapwin_title, attr_mapwin_highlight,
|
||||||
const char *initial = "Turn: ";
|
attr_mapwin_blink, 1, WIN_COLS / 2, &width, 1,
|
||||||
char *buf = xmalloc(BUFSIZE);
|
(turn_number != max_turn) ? " Turn: ^{%d^} " :
|
||||||
|
" ^[*** Last Turn ***^] ", turn_number);
|
||||||
int len1 = strlen(initial);
|
pr_right(curwin, 1, WIN_COLS - 2, chbuf, lines, &width);
|
||||||
int len2 = snprintf(buf, BUFSIZE, "%d", turn_number);
|
|
||||||
|
|
||||||
mvwaddstr(curwin, 1, getmaxx(curwin) - (len1 + len2) - 6, " ");
|
|
||||||
waddstr(curwin, initial);
|
|
||||||
attrpr(curwin, attr_mapwin_highlight, "%s", buf);
|
|
||||||
waddstr(curwin, " ");
|
|
||||||
|
|
||||||
free(buf);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
const char *buf = "*** Last Turn ***";
|
|
||||||
int len = strlen(buf);
|
|
||||||
|
|
||||||
mvwaddstr(curwin, 1, getmaxx(curwin) - len - 6, " ");
|
|
||||||
attrpr(curwin, attr_mapwin_blink, "%s", buf);
|
|
||||||
waddstr(curwin, " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
wattrset(curwin, attr_map_window);
|
wattrset(curwin, attr_map_window);
|
||||||
|
|
||||||
@ -638,6 +655,8 @@ void show_map (bool closewin)
|
|||||||
deltxwin(); // Galaxy map window
|
deltxwin(); // Galaxy map window
|
||||||
txrefresh();
|
txrefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(chbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -646,6 +665,8 @@ void show_map (bool closewin)
|
|||||||
|
|
||||||
void show_status (int num)
|
void show_status (int num)
|
||||||
{
|
{
|
||||||
|
chtype *chbuf;
|
||||||
|
int lines, width;
|
||||||
double val;
|
double val;
|
||||||
int i, line;
|
int i, line;
|
||||||
|
|
||||||
@ -655,13 +676,22 @@ void show_status (int num)
|
|||||||
newtxwin(MAX_COMPANIES + 15, WIN_COLS, 1, WCENTER, true,
|
newtxwin(MAX_COMPANIES + 15, WIN_COLS, 1, WCENTER, true,
|
||||||
attr_normal_window);
|
attr_normal_window);
|
||||||
|
|
||||||
center(curwin, 1, attr_title, " Stock Portfolio ");
|
chbuf = xmalloc(BUFSIZE * sizeof(chtype));
|
||||||
center2(curwin, 2, attr_normal, attr_highlight, "Player: ", "%s",
|
lines = prepstr(chbuf, BUFSIZE, attr_title, 0, 0, 1, WIN_COLS - 4,
|
||||||
|
&width, 1, " Stock Portfolio ");
|
||||||
|
pr_center(curwin, 1, 0, chbuf, lines, &width);
|
||||||
|
|
||||||
|
lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_highlight, 0, 1,
|
||||||
|
WIN_COLS - 4, &width, 1, "Player: ^{%s^}",
|
||||||
player[num].name);
|
player[num].name);
|
||||||
|
pr_center(curwin, 2, 0, chbuf, lines, &width);
|
||||||
|
|
||||||
val = total_value(num);
|
val = total_value(num);
|
||||||
if (val == 0.0) {
|
if (val == 0.0) {
|
||||||
center(curwin, 11, attr_blink, "* * * B A N K R U P T * * *");
|
lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_highlight,
|
||||||
|
attr_blink, 1, WIN_COLS - 4, &width, 1,
|
||||||
|
"^[* * * B A N K R U P T * * *^]");
|
||||||
|
pr_center(curwin, 11, 0, chbuf, lines, &width);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
char *buf = xmalloc(BUFSIZE);
|
char *buf = xmalloc(BUFSIZE);
|
||||||
@ -676,7 +706,10 @@ void show_status (int num)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (none) {
|
if (none) {
|
||||||
center(curwin, 8, attr_normal, "No companies on the map");
|
lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_highlight, 0,
|
||||||
|
1, WIN_COLS - 4, &width, 1,
|
||||||
|
"No companies on the map");
|
||||||
|
pr_center(curwin, 8, 0, chbuf, lines, &width);
|
||||||
} else {
|
} else {
|
||||||
// Handle the locale's currency symbol
|
// Handle the locale's currency symbol
|
||||||
snprintf(buf, BUFSIZE, "share (%s)", lconvinfo.currency_symbol);
|
snprintf(buf, BUFSIZE, "share (%s)", lconvinfo.currency_symbol);
|
||||||
@ -726,6 +759,7 @@ void show_status (int num)
|
|||||||
wait_for_key(curwin, getmaxy(curwin) - 2, attr_waitforkey);
|
wait_for_key(curwin, getmaxy(curwin) - 2, attr_waitforkey);
|
||||||
deltxwin();
|
deltxwin();
|
||||||
txrefresh();
|
txrefresh();
|
||||||
|
free(chbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
53
src/help.c
53
src/help.c
@ -157,17 +157,45 @@ static const char *help_text[] = {
|
|||||||
|
|
||||||
void show_help (void)
|
void show_help (void)
|
||||||
{
|
{
|
||||||
|
chtype *chbuf = xmalloc(BUFSIZE * sizeof(chtype));
|
||||||
|
int lines, width;
|
||||||
|
|
||||||
int curpage = 0;
|
int curpage = 0;
|
||||||
int numpages;
|
int numpages;
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
|
||||||
|
chtype *ch_title; // Title string
|
||||||
|
chtype *ch_contfirst; // "Continue", first page
|
||||||
|
chtype *ch_contnext; // "Continue", following pages
|
||||||
|
int w_title, ln_title;
|
||||||
|
int w_contfirst, ln_contfirst;
|
||||||
|
int w_contnext, ln_contnext;
|
||||||
|
|
||||||
|
|
||||||
// Count how many pages appear in the help text
|
// Count how many pages appear in the help text
|
||||||
for (numpages = 0; help_text[numpages] != NULL; numpages++)
|
for (numpages = 0; help_text[numpages] != NULL; numpages++)
|
||||||
;
|
;
|
||||||
|
|
||||||
if (numpages == 0)
|
if (numpages == 0) {
|
||||||
|
free(chbuf);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare fixed-text strings
|
||||||
|
ln_title = prepstr(chbuf, BUFSIZE, attr_title, 0, 0, 1, WIN_COLS - 4,
|
||||||
|
&w_title, 1, " How to Play ");
|
||||||
|
ch_title = chbufdup(chbuf, BUFSIZE);
|
||||||
|
|
||||||
|
ln_contfirst = prepstr(chbuf, BUFSIZE, attr_waitforkey, 0, 0, 1,
|
||||||
|
WIN_COLS - 4, &w_contfirst, 1,
|
||||||
|
"[ Press <SPACE> to continue ] ");
|
||||||
|
ch_contfirst = chbufdup(chbuf, BUFSIZE);
|
||||||
|
|
||||||
|
ln_contnext = prepstr(chbuf, BUFSIZE, attr_waitforkey, 0, 0, 1,
|
||||||
|
WIN_COLS - 4, &w_contnext, 1,
|
||||||
|
"[ Press <SPACE> to continue or "
|
||||||
|
"<BACKSPACE> for the previous page ] ");
|
||||||
|
ch_contnext = chbufdup(chbuf, BUFSIZE);
|
||||||
|
|
||||||
newtxwin(WIN_LINES - 1, WIN_COLS, 1, WCENTER, false, 0);
|
newtxwin(WIN_LINES - 1, WIN_COLS, 1, WCENTER, false, 0);
|
||||||
|
|
||||||
@ -177,8 +205,12 @@ void show_help (void)
|
|||||||
werase(curwin);
|
werase(curwin);
|
||||||
wbkgd(curwin, attr_normal_window);
|
wbkgd(curwin, attr_normal_window);
|
||||||
box(curwin, 0, 0);
|
box(curwin, 0, 0);
|
||||||
center(curwin, 1, attr_title, " How to Play ");
|
pr_center(curwin, 1, 0, ch_title, ln_title, &w_title);
|
||||||
center(curwin, 2, attr_normal, "Page %d of %d", curpage + 1, numpages);
|
|
||||||
|
lines = prepstr(chbuf, BUFSIZE, attr_normal, attr_highlight, 0, 1,
|
||||||
|
WIN_COLS - 4, &width, 1, "Page %d of %d",
|
||||||
|
curpage + 1, numpages);
|
||||||
|
pr_center(curwin, 2, 0, chbuf, lines, &width);
|
||||||
wmove(curwin, 4, 2);
|
wmove(curwin, 4, 2);
|
||||||
|
|
||||||
// Process the help text string
|
// Process the help text string
|
||||||
@ -323,9 +355,13 @@ void show_help (void)
|
|||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
|
|
||||||
center(curwin, 21, attr_waitforkey, (curpage == 0) ?
|
if (curpage == 0) {
|
||||||
"[ Press <SPACE> to continue ] " :
|
pr_center(curwin, getmaxy(curwin) - 2, 0, ch_contfirst,
|
||||||
"[ Press <SPACE> to continue or <BACKSPACE> for the previous page ] ");
|
ln_contfirst, &w_contfirst);
|
||||||
|
} else {
|
||||||
|
pr_center(curwin, getmaxy(curwin) - 2, 0, ch_contnext,
|
||||||
|
ln_contnext, &w_contnext);
|
||||||
|
}
|
||||||
|
|
||||||
wrefresh(curwin);
|
wrefresh(curwin);
|
||||||
|
|
||||||
@ -363,4 +399,9 @@ void show_help (void)
|
|||||||
|
|
||||||
deltxwin();
|
deltxwin();
|
||||||
txrefresh();
|
txrefresh();
|
||||||
|
|
||||||
|
free(ch_title);
|
||||||
|
free(ch_contfirst);
|
||||||
|
free(ch_contnext);
|
||||||
|
free(chbuf);
|
||||||
}
|
}
|
||||||
|
@ -2352,7 +2352,7 @@ int gettxlong (WINDOW *win, long int *restrict result, long int min,
|
|||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
// answer_yesno: Wait for a Yes/No answer
|
// answer_yesno: Wait for a Yes/No answer
|
||||||
|
|
||||||
bool answer_yesno (WINDOW *win, chtype attr_keys)
|
bool answer_yesno (WINDOW *win)
|
||||||
{
|
{
|
||||||
int key;
|
int key;
|
||||||
bool done;
|
bool done;
|
||||||
@ -2365,12 +2365,6 @@ bool answer_yesno (WINDOW *win, chtype attr_keys)
|
|||||||
meta(win, true);
|
meta(win, true);
|
||||||
wtimeout(win, -1);
|
wtimeout(win, -1);
|
||||||
|
|
||||||
waddstr(curwin, " [");
|
|
||||||
attrpr(curwin, attr_keys, "Y");
|
|
||||||
waddstr(curwin, "/");
|
|
||||||
attrpr(curwin, attr_keys, "N");
|
|
||||||
waddstr(curwin, "] ");
|
|
||||||
|
|
||||||
curs_set(CURS_ON);
|
curs_set(CURS_ON);
|
||||||
|
|
||||||
done = false;
|
done = false;
|
||||||
|
16
src/intf.h
16
src/intf.h
@ -55,7 +55,8 @@
|
|||||||
|
|
||||||
#define WCENTER -1 // Centre the new window
|
#define WCENTER -1 // Centre the new window
|
||||||
|
|
||||||
#define MAX_DLG_LINES 10 // Default maximum lines in dialog box
|
#define MAX_DLG_LINES 10 // Default maximum lines of text in dialog box
|
||||||
|
#define YESNO_COLS 4 // Space to allow for "Yes" or "No" response
|
||||||
|
|
||||||
|
|
||||||
// Check if resizing events are supported
|
// Check if resizing events are supported
|
||||||
@ -728,17 +729,14 @@ extern int gettxlong (WINDOW *win, long int *restrict result, long int min,
|
|||||||
/*
|
/*
|
||||||
Function: answer_yesno - Wait for a Yes/No answer
|
Function: answer_yesno - Wait for a Yes/No answer
|
||||||
Parameters: win - Window to use (should be curwin)
|
Parameters: win - Window to use (should be curwin)
|
||||||
attr_keys - Window rendition to use for key choices
|
|
||||||
Returns: bool - True if Yes was selected, false if No
|
Returns: bool - True if Yes was selected, false if No
|
||||||
|
|
||||||
This function prompts the user by printing " [Y/N] " using appropriate
|
This function waits for the user to press either "Y" (for Yes) or "N"
|
||||||
character renditions ("Y" and "N" in attr_keys, the rest in the current
|
(for No) on the keyboard, then prints the answer using A_BOLD. True is
|
||||||
rendition), then waits for the user to press either "Y" (for Yes) or
|
returned if "Y" was selected, false if "N". Note that the cursor
|
||||||
"N" (for No) on the keyboard, then prints the answer using A_BOLD.
|
becomes invisible after calling this function.
|
||||||
True is returned if "Y" was selected, false if "N". Note that the
|
|
||||||
cursor becomes invisible after calling this function.
|
|
||||||
*/
|
*/
|
||||||
extern bool answer_yesno (WINDOW *win, chtype attr_keys);
|
extern bool answer_yesno (WINDOW *win);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
45
src/move.c
45
src/move.c
@ -207,7 +207,6 @@ void select_moves (void)
|
|||||||
|
|
||||||
selection_t get_move (void)
|
selection_t get_move (void)
|
||||||
{
|
{
|
||||||
int i, x, y;
|
|
||||||
selection_t selection = SEL_NONE;
|
selection_t selection = SEL_NONE;
|
||||||
|
|
||||||
|
|
||||||
@ -219,7 +218,7 @@ selection_t get_move (void)
|
|||||||
show_map(false);
|
show_map(false);
|
||||||
|
|
||||||
// Display current move choices on the galaxy map
|
// Display current move choices on the galaxy map
|
||||||
for (i = 0; i < NUMBER_MOVES; i++) {
|
for (int i = 0; i < NUMBER_MOVES; i++) {
|
||||||
mvwaddch(curwin, game_move[i].y + 3, game_move[i].x * 2 + 2,
|
mvwaddch(curwin, game_move[i].y + 3, game_move[i].x * 2 + 2,
|
||||||
MOVE_TO_KEY(i) | attr_map_choice);
|
MOVE_TO_KEY(i) | attr_map_choice);
|
||||||
}
|
}
|
||||||
@ -324,18 +323,20 @@ selection_t get_move (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear the menu choices (but not the prompt!)
|
// Clear the menu choices (but not the prompt!)
|
||||||
wattrset(curwin, attr_normal);
|
mvwhline(curwin, 2, 2, ' ' | attr_normal, getmaxx(curwin) - 4);
|
||||||
for (y = 2; y < 4; y++) {
|
mvwhline(curwin, 3, 2, ' ' | attr_normal, getmaxx(curwin) - 4);
|
||||||
wmove(curwin, y, 2);
|
|
||||||
for (x = 2; x < getmaxx(curwin) - 2; x++) {
|
|
||||||
waddch(curwin, ' ' | attr_normal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wrefresh(curwin);
|
|
||||||
|
|
||||||
// Ask the player to confirm their choice
|
// Ask the player to confirm their choice
|
||||||
|
wattrset(curwin, attr_normal);
|
||||||
mvwaddstr(curwin, 2, 22, "Are you sure? ");
|
mvwaddstr(curwin, 2, 22, "Are you sure? ");
|
||||||
if (! answer_yesno(curwin, attr_keycode)) {
|
waddstr(curwin, "[");
|
||||||
|
attrpr(curwin, attr_keycode, "Y");
|
||||||
|
waddstr(curwin, "/");
|
||||||
|
attrpr(curwin, attr_keycode, "N");
|
||||||
|
waddstr(curwin, "] ");
|
||||||
|
wrefresh(curwin);
|
||||||
|
|
||||||
|
if (! answer_yesno(curwin)) {
|
||||||
selection = SEL_NONE;
|
selection = SEL_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,15 +346,21 @@ selection_t get_move (void)
|
|||||||
|
|
||||||
if (game_loaded) {
|
if (game_loaded) {
|
||||||
// Save the game to the same game number
|
// Save the game to the same game number
|
||||||
newtxwin(5, 30, 7, WCENTER, true, attr_status_window);
|
chtype *chbuf = xmalloc(BUFSIZE * sizeof(chtype));
|
||||||
center(curwin, 2, attr_status_window,
|
int lines, width;
|
||||||
|
|
||||||
|
lines = prepstr(chbuf, BUFSIZE, attr_status_window, 0, 0, 1,
|
||||||
|
WIN_COLS - 7, &width, 1,
|
||||||
"Saving game %d... ", game_num);
|
"Saving game %d... ", game_num);
|
||||||
|
newtxwin(5, width + 5, 7, WCENTER, true, attr_status_window);
|
||||||
|
pr_center(curwin, 2, 0, chbuf, 1, &width);
|
||||||
wrefresh(curwin);
|
wrefresh(curwin);
|
||||||
|
|
||||||
saved = save_game(game_num);
|
saved = save_game(game_num);
|
||||||
|
|
||||||
deltxwin();
|
deltxwin();
|
||||||
txrefresh();
|
txrefresh();
|
||||||
|
free(chbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! saved) {
|
if (! saved) {
|
||||||
@ -405,18 +412,24 @@ selection_t get_move (void)
|
|||||||
curs_set(CURS_OFF);
|
curs_set(CURS_OFF);
|
||||||
|
|
||||||
if (key != KEY_CANCEL) {
|
if (key != KEY_CANCEL) {
|
||||||
|
// Try to save the game, if possible
|
||||||
|
chtype *chbuf = xmalloc(BUFSIZE * sizeof(chtype));
|
||||||
|
int lines, width;
|
||||||
|
|
||||||
game_num = key - '0';
|
game_num = key - '0';
|
||||||
|
|
||||||
// Try to save the game, if possible
|
lines = prepstr(chbuf, BUFSIZE, attr_status_window,
|
||||||
newtxwin(5, 30, 7, WCENTER, true, attr_status_window);
|
0, 0, 1, WIN_COLS - 7, &width, 1,
|
||||||
center(curwin, 2, attr_status_window,
|
|
||||||
"Saving game %d... ", game_num);
|
"Saving game %d... ", game_num);
|
||||||
|
newtxwin(5, width + 5, 7, WCENTER, true, attr_status_window);
|
||||||
|
pr_center(curwin, 2, 0, chbuf, 1, &width);
|
||||||
wrefresh(curwin);
|
wrefresh(curwin);
|
||||||
|
|
||||||
saved = save_game(game_num);
|
saved = save_game(game_num);
|
||||||
|
|
||||||
deltxwin();
|
deltxwin();
|
||||||
txrefresh();
|
txrefresh();
|
||||||
|
free(chbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
deltxwin(); // "Enter game number" window
|
deltxwin(); // "Enter game number" window
|
||||||
|
Loading…
Reference in New Issue
Block a user