1
0
mirror of https://git.zap.org.au/git/trader.git synced 2024-12-04 14:46:45 -05:00

Move to the new left/center/right functions; add maxlines parameter

This commit is contained in:
John Zaitseff 2011-08-15 23:54:44 +10:00
parent 22677c0d89
commit 82647cf691
5 changed files with 177 additions and 120 deletions

View File

@ -368,7 +368,7 @@ 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);
left(curwin, 2, 2, attr_normal, 0, 0, "Please enter your name: "); left(curwin, 2, 2, attr_normal, 0, 0, 1, "Please enter your name: ");
int x = getcurx(curwin); int x = getcurx(curwin);
int w = getmaxx(curwin) - x - 2; int w = getmaxx(curwin) - x - 2;
@ -404,12 +404,12 @@ void ask_player_names (void)
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);
center(curwin, 1, 0, attr_title, 0, 0, " Enter Player Names "); center(curwin, 1, 0, attr_title, 0, 0, 1, " Enter Player Names ");
for (i = 0; i < number_players; i++) { for (i = 0; i < number_players; i++) {
player[i].name = NULL; player[i].name = NULL;
entered[i] = false; entered[i] = false;
left(curwin, i + 3, 2, attr_normal, 0, 0, "Player %d:", i + 1); left(curwin, i + 3, 2, attr_normal, 0, 0, 1, "Player %d:", i + 1);
} }
int x = getcurx(curwin) + 1; int x = getcurx(curwin) + 1;
@ -508,8 +508,9 @@ void ask_player_names (void)
void end_game (void) void end_game (void)
{ {
int i; chtype *chbuf;
char *buf; int lines;
int widthbuf[5];
if (abort_game) { if (abort_game) {
@ -517,14 +518,14 @@ void end_game (void)
return; return;
} }
buf = xmalloc(BUFSIZE); chbuf = xmalloc(BUFSIZE * sizeof(chtype));
txdlgbox(MAX_DLG_LINES, 50, 9, WCENTER, attr_error_window, txdlgbox(MAX_DLG_LINES, 50, 9, WCENTER, attr_error_window,
attr_error_title, attr_error_highlight, 0, 0, attr_error_title, attr_error_highlight, 0, 0,
attr_error_waitforkey, " Game Over ", attr_error_waitforkey, " Game Over ",
"The game is over after %d turns.", turn_number - 1); "The game is over after %d turns.", turn_number - 1);
for (i = 0; i < number_players; i++) { for (int i = 0; i < number_players; i++) {
show_status(i); show_status(i);
} }
@ -535,43 +536,45 @@ void end_game (void)
total_value(0)); total_value(0));
} else { } else {
// Sort players on the basis of total value // Sort players on the basis of total value
for (i = 0; i < number_players; i++) { for (int i = 0; i < number_players; i++) {
player[i].sort_value = total_value(i); player[i].sort_value = total_value(i);
} }
qsort(player, number_players, sizeof(player_info_t), cmp_player); qsort(player, number_players, sizeof(player_info_t), cmp_player);
newtxwin(number_players + 10, WIN_COLS - 4, 3, WCENTER, lines = mkchstr(chbuf, BUFSIZE, attr_normal, attr_highlight, attr_blink,
5, WIN_COLS - 8, widthbuf, 5, (player[0].sort_value == 0) ?
"The winner is ^{%s^}\n"
"who is ^[*** BANKRUPT ***^]" :
"The winner is ^{%s^}\n"
"with a value of ^{%N^}.", player[0].name,
player[0].sort_value);
newtxwin(number_players + lines + 8, WIN_COLS - 4, 3, WCENTER,
true, attr_normal_window); true, attr_normal_window);
center(curwin, 1, 0, attr_title, 0, 0, 1, " Game Winner ");
centerch(curwin, 3, 0, chbuf, lines, widthbuf);
old_center(curwin, 1, attr_title, " Game Winner "); mvwhline(curwin, lines + 4, 2, ' ' | attr_subtitle,
old_center2(curwin, 3, attr_normal, attr_highlight, "The winner is ", getmaxx(curwin) - 4);
"%s", player[0].name); left(curwin, lines + 4, ORDINAL_COLS + 4, attr_subtitle, 0, 0, 1,
if (player[0].sort_value == 0.0) { "Player");
old_center2(curwin, 4, attr_normal, attr_blink, "who is ", right(curwin, lines + 4, getmaxx(curwin) - 4, attr_subtitle, 0, 0, 1,
"*** BANKRUPT ***"); "Total Value (%s)", lconvinfo.currency_symbol);
} else {
l_strfmon(buf, BUFSIZE, "%1n", player[0].sort_value);
old_center2(curwin, 4, attr_normal, attr_highlight,
"with a value of ", "%s", buf);
}
int w = getmaxx(curwin) - 33; for (int i = 0; i < number_players; i++) {
wattrset(curwin, attr_subtitle); right(curwin, i + lines + 5, ORDINAL_COLS + 2, attr_normal, 0, 0,
snprintf(buf, BUFSIZE, "Total Value (%s)", lconvinfo.currency_symbol); 1, gettext(ordinal[i + 1]));
mvwprintw(curwin, 6, 2, "%5s %-*.*s %18s ", "", w, w, "Player", buf); left(curwin, i + lines + 5, ORDINAL_COLS + 4, attr_normal, 0, 0,
wattrset(curwin, attr_normal); 1, "%s", player[i].name);
right(curwin, i + lines + 5, getmaxx(curwin) - 2, attr_normal, 0,
for (i = 0; i < number_players; i++) { 0, 1, " %!N ", player[i].sort_value);
l_strfmon(buf, BUFSIZE, "%!18n", player[i].sort_value);
mvwprintw(curwin, i + 7, 2, "%5s %-*.*s %18s ",
gettext(ordinal[i + 1]), w, w, player[i].name, buf);
} }
wait_for_key(curwin, getmaxy(curwin) - 2, attr_waitforkey); wait_for_key(curwin, getmaxy(curwin) - 2, attr_waitforkey);
deltxwin(); deltxwin();
} }
free(buf); free(chbuf);
} }
@ -592,13 +595,12 @@ void show_map (bool closewin)
mvwhline(curwin, 1, 2, ' ' | attr_mapwin_title, getmaxx(curwin) - 4); mvwhline(curwin, 1, 2, ' ' | attr_mapwin_title, getmaxx(curwin) - 4);
// Display current player and turn number // Display current player and turn number
left(curwin, 1, 2, attr_mapwin_title, attr_mapwin_highlight, 0, left(curwin, 1, 2, attr_mapwin_title, attr_mapwin_highlight, 0, 1,
" Player: ^{%s^} ", player[current_player].name); " Player: ^{%s^} ", player[current_player].name);
right(curwin, 1, getmaxx(curwin) - 2, attr_mapwin_title, right(curwin, 1, getmaxx(curwin) - 2, attr_mapwin_title,
attr_mapwin_highlight, attr_mapwin_blink, (turn_number != max_turn) ? attr_mapwin_highlight, attr_mapwin_blink, 1,
" Turn: ^{%d^} " : " ^[*** Last Turn ***^] ", turn_number); (turn_number != max_turn) ? " Turn: ^{%d^} " :
" ^[*** Last Turn ***^] ", turn_number);
wattrset(curwin, attr_map_window);
// Display the actual map // Display the actual map
for (y = 0; y < MAX_Y; y++) { for (y = 0; y < MAX_Y; y++) {
@ -657,17 +659,15 @@ 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, 0, attr_title, 0, 0, " Stock Portfolio "); center(curwin, 1, 0, attr_title, 0, 0, 1, " Stock Portfolio ");
center(curwin, 2, 0, attr_normal, attr_highlight, 0, "Player: ^{%s^}", center(curwin, 2, 0, attr_normal, attr_highlight, 0, 1, "Player: ^{%s^}",
player[num].name); player[num].name);
val = total_value(num); val = total_value(num);
if (val == 0.0) { if (val == 0.0) {
center(curwin, 11, 0, attr_normal, attr_highlight, attr_blink, center(curwin, 11, 0, attr_normal, attr_highlight, attr_blink, 1,
"^[* * * B A N K R U P T * * *^]"); "^[* * * B A N K R U P T * * *^]");
} else { } else {
char *buf = xmalloc(BUFSIZE);
// Check to see if any companies are on the map // Check to see if any companies are on the map
bool none = true; bool none = true;
for (i = 0; i < MAX_COMPANIES; i++) { for (i = 0; i < MAX_COMPANIES; i++) {
@ -678,52 +678,83 @@ void show_status (int num)
} }
if (none) { if (none) {
center(curwin, 8, 0, attr_normal, attr_highlight, 0, center(curwin, 8, 0, attr_normal, attr_highlight, 0, 1,
"No companies on the map"); "No companies on the map");
} else { } else {
// Handle the locale's currency symbol mvwhline(curwin, 4, 2, ' ' | attr_subtitle, getmaxx(curwin) - 4);
snprintf(buf, BUFSIZE, "share (%s)", lconvinfo.currency_symbol); mvwhline(curwin, 5, 2, ' ' | attr_subtitle, getmaxx(curwin) - 4);
wattrset(curwin, attr_subtitle); left(curwin, 4, 4, attr_subtitle, 0, 0, 2, "\nCompany");
mvwprintw(curwin, 4, 2, " %-22s %12s %10s %10s %10s ", right(curwin, 4, getmaxx(curwin) - 4, attr_subtitle, 0, 0, 2,
"", "Price per", "", "Holdings", "Company"); "Ownership\n(%%)");
mvwprintw(curwin, 5, 2, " %-22s %12s %10s %10s %10s ", right(curwin, 4, getmaxx(curwin) - 6 - OWNERSHIP_COLS,
"Company", buf, "Return (%)", "(shares)", "owner (%)"); attr_subtitle, 0, 0, 2, "Holdings\n(shares)");
wattrset(curwin, attr_normal); right(curwin, 4, getmaxx(curwin) - 8 - OWNERSHIP_COLS
- STOCK_OWNED_COLS, attr_subtitle, 0, 0, 2,
"\nReturn (%%)");
right(curwin, 4, getmaxx(curwin) - 10 - OWNERSHIP_COLS
- STOCK_OWNED_COLS - SHARE_RETURN_COLS, attr_subtitle, 0, 0,
2, "Price per\nshare (%s)", lconvinfo.currency_symbol);
for (line = 6, i = 0; i < MAX_COMPANIES; i++) { for (line = 6, i = 0; i < MAX_COMPANIES; i++) {
if (company[i].on_map) { if (company[i].on_map) {
l_strfmon(buf, BUFSIZE, "%!12n", company[i].share_price); left(curwin, line, 4, attr_normal, 0, 0, 1, "%s",
mvwprintw(curwin, line, 2, company[i].name);
" %-22s %10s %10.2f %'10ld %10.2f ",
company[i].name, buf, right(curwin, line, getmaxx(curwin) - 2, attr_normal, 0, 0,
company[i].share_return * 100.0, 1, "%.2f ", (company[i].stock_issued == 0) ? 0.0 :
player[num].stock_owned[i],
(company[i].stock_issued == 0) ? 0.0 :
((double) player[num].stock_owned[i] * 100.0) ((double) player[num].stock_owned[i] * 100.0)
/ company[i].stock_issued); / company[i].stock_issued);
right(curwin, line, getmaxx(curwin) - 4 - OWNERSHIP_COLS,
attr_normal, 0, 0, 1, "%'ld ",
player[num].stock_owned[i]);
right(curwin, line, getmaxx(curwin) - 6 - OWNERSHIP_COLS
- STOCK_OWNED_COLS, attr_normal, 0, 0, 1, "%.2f ",
company[i].share_return * 100.0);
right(curwin, line, getmaxx(curwin) - 8 - OWNERSHIP_COLS
- STOCK_OWNED_COLS - SHARE_RETURN_COLS, attr_normal,
0, 0, 1, " %!N ", company[i].share_price);
line++; line++;
} }
} }
} }
line = 15; line = MAX_COMPANIES + 7;
l_strfmon(buf, BUFSIZE, "%18n", player[num].cash);
old_center2(curwin, line++, attr_normal, attr_highlight, "Current cash: ", chtype *chbuf = xmalloc(BUFSIZE * sizeof(chtype));
" %s ", buf); int width, x;
mkchstr(chbuf, BUFSIZE, attr_highlight, 0, 0, 1, getmaxx(curwin) / 2,
&width, 1, "Total value: ");
x = (getmaxx(curwin) + width - (TOTAL_VALUE_COLS + 2)) / 2;
right(curwin, line, x, attr_normal, attr_highlight, 0, 1,
"Current cash: ");
right(curwin, line, x + TOTAL_VALUE_COLS + 2, attr_normal,
attr_highlight, 0, 1, " ^{%N^} ", player[num].cash);
line++;
if (player[num].debt != 0.0) { if (player[num].debt != 0.0) {
l_strfmon(buf, BUFSIZE, "%18n", player[num].debt); right(curwin, line, x, attr_normal, attr_highlight, 0, 1,
old_center2(curwin, line++, attr_normal, attr_highlight, "Current debt: ");
"Current debt: ", " %s ", buf); right(curwin, line, x + TOTAL_VALUE_COLS + 2, attr_normal,
old_center2(curwin, line++, attr_normal, attr_highlight, attr_highlight, 0, 1, " ^{%N^} ", player[num].debt);
"Interest rate: ", " %17.2f%% ", interest_rate * 100.0); line++;
right(curwin, line, x, attr_normal, attr_highlight, 0, 1,
"Interest rate: ");
right(curwin, line, x + TOTAL_VALUE_COLS + 2, attr_normal,
attr_highlight, 0, 1, " ^{%.2f%%^} ", interest_rate * 100.0);
line++;
} }
l_strfmon(buf, BUFSIZE, "%18n", val); rightch(curwin, line + 1, x, chbuf, 1, &width);
old_center2(curwin, line + 1, attr_highlight, attr_title, whline(curwin, ' ' | attr_title, TOTAL_VALUE_COLS + 2);
"Total value: ", " %s ", buf); right(curwin, line + 1, x + TOTAL_VALUE_COLS + 2, attr_title, 0, 0, 1,
" %N ", val);
free(buf); free(chbuf);
} }
wait_for_key(curwin, getmaxy(curwin) - 2, attr_waitforkey); wait_for_key(curwin, getmaxy(curwin) - 2, attr_waitforkey);

View File

@ -178,8 +178,8 @@ void show_help (void)
wbkgd(curwin, attr_normal_window); wbkgd(curwin, attr_normal_window);
box(curwin, 0, 0); box(curwin, 0, 0);
center(curwin, 1, 0, attr_title, 0, 0, " How to Play "); center(curwin, 1, 0, attr_title, 0, 0, 1, " How to Play ");
center(curwin, 2, 0, attr_normal, attr_highlight, 0, center(curwin, 2, 0, attr_normal, attr_highlight, 0, 1,
"Page %d of %d", curpage + 1, numpages); "Page %d of %d", curpage + 1, numpages);
wmove(curwin, 4, 2); wmove(curwin, 4, 2);
@ -325,7 +325,7 @@ void show_help (void)
s++; s++;
} }
center(curwin, getmaxy(curwin) - 2, 0, attr_waitforkey, 0, 0, center(curwin, getmaxy(curwin) - 2, 0, attr_waitforkey, 0, 0, 1,
(curpage == 0) ? "[ Press <SPACE> to continue ] " : (curpage == 0) ? "[ Press <SPACE> to continue ] " :
"[ Press <SPACE> to continue or <BACKSPACE> " "[ Press <SPACE> to continue or <BACKSPACE> "
"for the previous page ] "); "for the previous page ] ");

View File

@ -409,7 +409,7 @@ void init_title (void)
clear(); clear();
mvwhline(stdscr, 0, 0, ' ' | attr_game_title, COLS); mvwhline(stdscr, 0, 0, ' ' | attr_game_title, COLS);
center(stdscr, 0, 0, attr_game_title, 0, 0, _("Star Traders")); center(stdscr, 0, 0, attr_game_title, 0, 0, 1, _("Star Traders"));
} }
@ -609,7 +609,7 @@ int txdlgbox (int maxlines, int ncols, int begin_y, int begin_x,
true, bkgd_attr); true, bkgd_attr);
if (usetitle) { if (usetitle) {
center(curwin, 1, 0, title_attr, 0, 0, boxtitle); center(curwin, 1, 0, title_attr, 0, 0, 1, boxtitle);
} }
centerch(curwin, usetitle ? 3 : 2, 0, chbuf, lines, widthbuf); centerch(curwin, usetitle ? 3 : 2, 0, chbuf, lines, widthbuf);
@ -1345,25 +1345,30 @@ int rightch (WINDOW *win, int y, int x, const chtype *restrict chstr,
// left: Print strings left-aligned // left: Print strings left-aligned
int left (WINDOW *win, int y, int x, chtype attr_norm, chtype attr_alt1, int left (WINDOW *win, int y, int x, chtype attr_norm, chtype attr_alt1,
chtype attr_alt2, const char *restrict format, ...) chtype attr_alt2, int maxlines, const char *restrict format, ...)
{ {
va_list args; va_list args;
chtype *chbuf = xmalloc(BUFSIZE * sizeof(chtype)); chtype *chbuf;
int widthbuf[MAX_DLG_LINES]; int *widthbuf;
int lines; int lines;
int ret; int ret;
assert(maxlines > 0);
chbuf = xmalloc(BUFSIZE * sizeof(chtype));
widthbuf = xmalloc(maxlines * sizeof(int));
va_start(args, format); va_start(args, format);
lines = vmkchstr(chbuf, BUFSIZE, attr_norm, attr_alt1, attr_alt2, lines = vmkchstr(chbuf, BUFSIZE, attr_norm, attr_alt1, attr_alt2, maxlines,
MAX_DLG_LINES, getmaxx(win) - x - 2, widthbuf, getmaxx(win) - x - 2, widthbuf, maxlines, format, args);
MAX_DLG_LINES, format, args);
ret = leftch(win, y, x, chbuf, lines, widthbuf); ret = leftch(win, y, x, chbuf, lines, widthbuf);
assert(ret == OK); assert(ret == OK);
va_end(args); va_end(args);
free(widthbuf);
free(chbuf); free(chbuf);
return ret; return lines;
} }
@ -1371,25 +1376,30 @@ int left (WINDOW *win, int y, int x, chtype attr_norm, chtype attr_alt1,
// center: Print strings centred in window // center: Print strings centred in window
int center (WINDOW *win, int y, int offset, chtype attr_norm, chtype attr_alt1, int center (WINDOW *win, int y, int offset, chtype attr_norm, chtype attr_alt1,
chtype attr_alt2, const char *restrict format, ...) chtype attr_alt2, int maxlines, const char *restrict format, ...)
{ {
va_list args; va_list args;
chtype *chbuf = xmalloc(BUFSIZE * sizeof(chtype)); chtype *chbuf;
int widthbuf[MAX_DLG_LINES]; int *widthbuf;
int lines; int lines;
int ret; int ret;
assert(maxlines > 0);
chbuf = xmalloc(BUFSIZE * sizeof(chtype));
widthbuf = xmalloc(maxlines * sizeof(int));
va_start(args, format); va_start(args, format);
lines = vmkchstr(chbuf, BUFSIZE, attr_norm, attr_alt1, attr_alt2, lines = vmkchstr(chbuf, BUFSIZE, attr_norm, attr_alt1, attr_alt2, maxlines,
MAX_DLG_LINES, getmaxx(win) - 4, widthbuf, getmaxx(win) - 4, widthbuf, maxlines, format, args);
MAX_DLG_LINES, format, args);
ret = centerch(win, y, offset, chbuf, lines, widthbuf); ret = centerch(win, y, offset, chbuf, lines, widthbuf);
assert(ret == OK); assert(ret == OK);
va_end(args); va_end(args);
free(widthbuf);
free(chbuf); free(chbuf);
return ret; return lines;
} }
@ -1397,25 +1407,30 @@ int center (WINDOW *win, int y, int offset, chtype attr_norm, chtype attr_alt1,
// right: Print strings right-aligned // right: Print strings right-aligned
int right (WINDOW *win, int y, int x, chtype attr_norm, chtype attr_alt1, int right (WINDOW *win, int y, int x, chtype attr_norm, chtype attr_alt1,
chtype attr_alt2, const char *restrict format, ...) chtype attr_alt2, int maxlines, const char *restrict format, ...)
{ {
va_list args; va_list args;
chtype *chbuf = xmalloc(BUFSIZE * sizeof(chtype)); chtype *chbuf;
int widthbuf[MAX_DLG_LINES]; int *widthbuf;
int lines; int lines;
int ret; int ret;
assert(maxlines > 0);
chbuf = xmalloc(BUFSIZE * sizeof(chtype));
widthbuf = xmalloc(maxlines * sizeof(int));
va_start(args, format); va_start(args, format);
lines = vmkchstr(chbuf, BUFSIZE, attr_norm, attr_alt1, attr_alt2, lines = vmkchstr(chbuf, BUFSIZE, attr_norm, attr_alt1, attr_alt2, maxlines,
MAX_DLG_LINES, x - 2, widthbuf, MAX_DLG_LINES, x - 2, widthbuf, maxlines, format, args);
format, args);
ret = rightch(win, y, x, chbuf, lines, widthbuf); ret = rightch(win, y, x, chbuf, lines, widthbuf);
assert(ret == OK); assert(ret == OK);
va_end(args); va_end(args);
free(widthbuf);
free(chbuf); free(chbuf);
return ret; return lines;
} }
@ -2554,7 +2569,7 @@ void wait_for_key (WINDOW *win, int y, chtype attr)
meta(win, true); meta(win, true);
wtimeout(win, -1); wtimeout(win, -1);
center(curwin, y, 0, attr, 0, 0, _("[ Press <SPACE> to continue ] ")); center(curwin, y, 0, attr, 0, 0, 1, _("[ Press <SPACE> to continue ] "));
wrefresh(win); wrefresh(win);
done = false; done = false;

View File

@ -57,6 +57,12 @@
#define MAX_DLG_LINES 10 // Default maximum lines of text 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 #define YESNO_COLS 4 // Space to allow for "Yes" or "No" response
#define ORDINAL_COLS 5 // Space for ordinals (1st, 2nd, etc)
#define TOTAL_VALUE_COLS 18 // Space for total value (monetary)
#define SHARE_PRICE_COLS 12 // Space for "Price per share"
#define SHARE_RETURN_COLS 10 // Space for "Return per share"
#define STOCK_OWNED_COLS 10 // Space for "Holdings (shares)"
#define OWNERSHIP_COLS 10 // Space for "Company ownership (%)"
// Check if resizing events are supported // Check if resizing events are supported
@ -470,9 +476,10 @@ extern int rightch (WINDOW *win, int y, int x, const chtype *restrict chstr,
attr_norm - Normal character rendition to use attr_norm - Normal character rendition to use
attr_alt1 - First alternate character rendition to use attr_alt1 - First alternate character rendition to use
attr_alt2 - Second alternate character rendition to use attr_alt2 - Second alternate character rendition to use
maxlines - Maximum number of screen lines to use
format - Format string as described for mkchstr() format - Format string as described for mkchstr()
... - Arguments for the format string ... - Arguments for the format string
Returns: int - Always returns OK Returns: int - Number of lines actually used
This shortcut function prepares a chtype string using mkchstr(), then This shortcut function prepares a chtype string using mkchstr(), then
prints the string using leftch(). At most MAX_DLG_LINES are printed, prints the string using leftch(). At most MAX_DLG_LINES are printed,
@ -480,7 +487,8 @@ extern int rightch (WINDOW *win, int y, int x, const chtype *restrict chstr,
for the right-hand border). for the right-hand border).
*/ */
extern int left (WINDOW *win, int y, int x, chtype attr_norm, chtype attr_alt1, extern int left (WINDOW *win, int y, int x, chtype attr_norm, chtype attr_alt1,
chtype attr_alt2, const char *restrict format, ...); chtype attr_alt2, int maxlines, const char *restrict format,
...);
/* /*
@ -491,16 +499,17 @@ extern int left (WINDOW *win, int y, int x, chtype attr_norm, chtype attr_alt1,
attr_norm - Normal character rendition to use attr_norm - Normal character rendition to use
attr_alt1 - First alternate character rendition to use attr_alt1 - First alternate character rendition to use
attr_alt2 - Second alternate character rendition to use attr_alt2 - Second alternate character rendition to use
maxlines - Maximum number of screen lines to use
format - Format string as described for mkchstr() format - Format string as described for mkchstr()
... - Arguments for the format string ... - Arguments for the format string
Returns: int - Always returns OK Returns: int - Number of lines actually used
This shortcut function prepares a chtype string using mkchstr(), then This shortcut function prepares a chtype string using mkchstr(), then
prints the string using centerch(). At most MAX_DLG_LINES are printed, prints the string using centerch(). At most MAX_DLG_LINES are printed,
with the maximum width being that of the window win - 4 (for borders). with the maximum width being that of the window win - 4 (for borders).
*/ */
extern int center (WINDOW *win, int y, int offset, chtype attr_norm, extern int center (WINDOW *win, int y, int offset, chtype attr_norm,
chtype attr_alt1, chtype attr_alt2, chtype attr_alt1, chtype attr_alt2, int maxlines,
const char *restrict format, ...); const char *restrict format, ...);
@ -512,9 +521,10 @@ extern int center (WINDOW *win, int y, int offset, chtype attr_norm,
attr_norm - Normal character rendition to use attr_norm - Normal character rendition to use
attr_alt1 - First alternate character rendition to use attr_alt1 - First alternate character rendition to use
attr_alt2 - Second alternate character rendition to use attr_alt2 - Second alternate character rendition to use
maxlines - Maximum number of screen lines to use
format - Format string as described for mkchstr() format - Format string as described for mkchstr()
... - Arguments for the format string ... - Arguments for the format string
Returns: int - Always returns OK Returns: int - Number of lines actually used
This shortcut function prepares a chtype string using mkchstr(), then This shortcut function prepares a chtype string using mkchstr(), then
prints the string using rightch(). At most MAX_DLG_LINES are printed, prints the string using rightch(). At most MAX_DLG_LINES are printed,
@ -522,7 +532,8 @@ extern int center (WINDOW *win, int y, int offset, chtype attr_norm,
left-hand border). left-hand border).
*/ */
extern int right (WINDOW *win, int y, int x, chtype attr_norm, chtype attr_alt1, extern int right (WINDOW *win, int y, int x, chtype attr_norm, chtype attr_alt1,
chtype attr_alt2, const char *restrict format, ...); chtype attr_alt2, int maxlines, const char *restrict format,
...);
/* /*

View File

@ -231,17 +231,17 @@ selection_t get_move (void)
werase(curwin); werase(curwin);
box(curwin, 0, 0); box(curwin, 0, 0);
left(curwin, 2, 2, attr_normal, attr_keycode, 0, left(curwin, 2, 2, attr_normal, attr_keycode, 0, 1,
"^{<1>^} Display stock portfolio"); "^{<1>^} Display stock portfolio");
left(curwin, 3, 2, attr_normal, attr_keycode, 0, left(curwin, 3, 2, attr_normal, attr_keycode, 0, 1,
"^{<2>^} Declare bankruptcy"); "^{<2>^} Declare bankruptcy");
left(curwin, 2, getmaxx(curwin) / 2, attr_normal, attr_keycode, 0, left(curwin, 2, getmaxx(curwin) / 2, attr_normal, attr_keycode, 0, 1,
"^{<3>^} Save and end the game"); "^{<3>^} Save and end the game");
left(curwin, 3, getmaxx(curwin) / 2, attr_normal, attr_keycode, 0, left(curwin, 3, getmaxx(curwin) / 2, attr_normal, attr_keycode, 0, 1,
"^{<CTRL><C>^} Quit the game"); "^{<CTRL><C>^} Quit the game");
right(curwin, 1, getmaxx(curwin) / 2, attr_normal, attr_keycode, right(curwin, 1, getmaxx(curwin) / 2, attr_normal, attr_keycode,
attr_choice, "Select move " attr_choice, 1, "Select move "
"[^[%c^]-^[%c^]/^{1^}-^{3^}/^{<CTRL><C>^}]: ", "[^[%c^]-^[%c^]/^{1^}-^{3^}/^{<CTRL><C>^}]: ",
MOVE_TO_KEY(0), MOVE_TO_KEY(NUMBER_MOVES - 1)); MOVE_TO_KEY(0), MOVE_TO_KEY(NUMBER_MOVES - 1));
@ -257,7 +257,7 @@ selection_t get_move (void)
curs_set(CURS_OFF); curs_set(CURS_OFF);
left(curwin, 1, getmaxx(curwin) / 2, attr_normal, attr_choice, left(curwin, 1, getmaxx(curwin) / 2, attr_normal, attr_choice,
0, "Move ^{%c^}", key); 0, 1, "Move ^{%c^}", key);
} else { } else {
switch (key) { switch (key) {
case '1': case '1':
@ -271,7 +271,7 @@ selection_t get_move (void)
curs_set(CURS_OFF); curs_set(CURS_OFF);
left(curwin, 1, getmaxx(curwin) / 2, attr_normal, left(curwin, 1, getmaxx(curwin) / 2, attr_normal,
attr_normal | A_BOLD, 0, attr_normal | A_BOLD, 0, 1,
"^{<2>^} (Declare bankruptcy)"); "^{<2>^} (Declare bankruptcy)");
break; break;
@ -280,7 +280,7 @@ selection_t get_move (void)
curs_set(CURS_OFF); curs_set(CURS_OFF);
left(curwin, 1, getmaxx(curwin) / 2, attr_normal, left(curwin, 1, getmaxx(curwin) / 2, attr_normal,
attr_normal | A_BOLD, 0, attr_normal | A_BOLD, 0, 1,
"^{<3>^} (Save and end the game)"); "^{<3>^} (Save and end the game)");
break; break;
@ -294,7 +294,7 @@ selection_t get_move (void)
curs_set(CURS_OFF); curs_set(CURS_OFF);
left(curwin, 1, getmaxx(curwin) / 2, attr_normal, left(curwin, 1, getmaxx(curwin) / 2, attr_normal,
attr_normal | A_BOLD, 0, attr_normal | A_BOLD, 0, 1,
"^{<CTRL><C>^} (Quit the game)"); "^{<CTRL><C>^} (Quit the game)");
break; break;
@ -309,7 +309,7 @@ selection_t get_move (void)
mvwhline(curwin, 3, 2, ' ' | attr_normal, getmaxx(curwin) - 4); mvwhline(curwin, 3, 2, ' ' | attr_normal, getmaxx(curwin) - 4);
// Ask the player to confirm their choice // Ask the player to confirm their choice
right(curwin, 2, getmaxx(curwin) / 2, attr_normal, attr_keycode, 0, right(curwin, 2, getmaxx(curwin) / 2, attr_normal, attr_keycode, 0, 1,
"Are you sure? [^{Y^}/^{N^}] "); "Are you sure? [^{Y^}/^{N^}] ");
wrefresh(curwin); wrefresh(curwin);