1
0
mirror of https://git.zap.org.au/git/trader.git synced 2024-11-03 17:27:29 -05:00

Replace the WCENTER(x) macro with WCENTER; refactor newtxwin() to suit

This commit is contained in:
John Zaitseff 2011-07-23 10:16:03 +10:00
parent a5feeb2635
commit 961e989bd7
7 changed files with 58 additions and 54 deletions

View File

@ -83,7 +83,7 @@ void exchange_stock (void)
return;
}
newtxwin(17, WIN_COLS, 1, WCENTER(WIN_COLS), false, 0);
newtxwin(17, WIN_COLS, 1, WCENTER, false, 0);
while (selection != SEL_EXIT) {
selection = SEL_NONE;
@ -142,7 +142,7 @@ void exchange_stock (void)
wrefresh(curwin);
// Show menu of choices for the player
newtxwin(6, WIN_COLS, 18, WCENTER(WIN_COLS), true, attr_normal_window);
newtxwin(6, WIN_COLS, 18, WCENTER, true, attr_normal_window);
wmove(curwin, 3, 2);
attrpr(curwin, attr_keycode, "<1>");
@ -268,8 +268,7 @@ void visit_bank (void)
}
// Show the informational part of the Bank
newtxwin(10, WIN_COLS - 4, 5, WCENTER(WIN_COLS - 4), true,
attr_normal_window);
newtxwin(10, WIN_COLS - 4, 5, WCENTER, true, attr_normal_window);
center(curwin, 1, attr_title, " Interstellar Trading Bank ");
@ -291,8 +290,7 @@ void visit_bank (void)
wrefresh(curwin);
// Show menu of choices for the player
newtxwin(7, WIN_COLS - 4, 15, WCENTER(WIN_COLS - 4), true,
attr_normal_window);
newtxwin(7, WIN_COLS - 4, 15, WCENTER, true, attr_normal_window);
center2(curwin, 3, attr_keycode, attr_normal, "<1>", " Borrow money ");
center2(curwin, 4, attr_keycode, attr_normal, "<2>", " Repay debt ");
@ -340,7 +338,7 @@ void visit_bank (void)
case '1':
// Borrow money from the Bank
if (credit_limit == 0.0) {
newtxwin(7, 50, 8, WCENTER(50), true, attr_error_window);
newtxwin(7, 50, 8, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " Insufficient Credit Limit ");
center(curwin, 3, attr_error_highlight,
@ -392,7 +390,7 @@ void visit_bank (void)
case '2':
// Repay a debt
if (player[current_player].debt == 0.0) {
newtxwin(7, 50, 8, WCENTER(50), true, attr_error_window);
newtxwin(7, 50, 8, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " No Debt ");
center(curwin, 3, attr_error_highlight,
@ -402,7 +400,7 @@ void visit_bank (void)
deltxwin();
} else if (player[current_player].cash == 0.0) {
newtxwin(7, 60, 8, WCENTER(60), true, attr_error_window);
newtxwin(7, 60, 8, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " No Cash ");
center(curwin, 3, attr_error_highlight,
@ -497,8 +495,7 @@ void trade_shares (int num, bool *bid_used)
/ company[num].stock_issued);
// Show the informational part of the trade window
newtxwin(9, WIN_COLS - 4, 5, WCENTER(WIN_COLS - 4), true,
attr_normal_window);
newtxwin(9, WIN_COLS - 4, 5, WCENTER, true, attr_normal_window);
center(curwin, 1, attr_title, " Stock Transaction in %s ",
company[num].name);
@ -533,8 +530,7 @@ void trade_shares (int num, bool *bid_used)
wrefresh(curwin);
// Show menu of choices for the player
newtxwin(7, WIN_COLS - 4, 14, WCENTER(WIN_COLS - 4), true,
attr_normal_window);
newtxwin(7, WIN_COLS - 4, 14, WCENTER, true, attr_normal_window);
wmove(curwin, 3, 2);
attrpr(curwin, attr_keycode, "<1>");
@ -597,7 +593,7 @@ void trade_shares (int num, bool *bid_used)
maxshares = player[current_player].cash / company[num].share_price;
if (company[num].max_stock - company[num].stock_issued == 0) {
newtxwin(7, 50, 8, WCENTER(50), true, attr_error_window);
newtxwin(7, 50, 8, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " No Shares Available ");
center(curwin, 3, attr_error_highlight,
@ -607,7 +603,7 @@ void trade_shares (int num, bool *bid_used)
deltxwin();
} else if (maxshares <= 0) {
newtxwin(7, 50, 8, WCENTER(50), true, attr_error_window);
newtxwin(7, 50, 8, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " Insufficient Cash ");
center(curwin, 3, attr_error_highlight,
@ -645,7 +641,7 @@ void trade_shares (int num, bool *bid_used)
// Sell stock back to company
maxshares = player[current_player].stock_owned[num];
if (maxshares == 0) {
newtxwin(7, 50, 8, WCENTER(50), true, attr_error_window);
newtxwin(7, 50, 8, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " No Shares ");
center(curwin, 3, attr_error_highlight,
@ -687,7 +683,7 @@ void trade_shares (int num, bool *bid_used)
*bid_used = true;
if (maxshares == 0) {
newtxwin(8, 50, 8, WCENTER(50), true, attr_error_window);
newtxwin(8, 50, 8, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " No Shares Issued ");
center(curwin, 3, attr_error_highlight, "%s", company[num].name);
@ -697,7 +693,7 @@ void trade_shares (int num, bool *bid_used)
wait_for_key(curwin, 6, attr_error_waitforkey);
deltxwin();
} else {
newtxwin(8, 50, 8, WCENTER(50), true, attr_normal_window);
newtxwin(8, 50, 8, WCENTER, true, attr_normal_window);
center(curwin, 1, attr_title, " Shares Issued ");
center(curwin, 3, attr_highlight, "%s", company[num].name);

View File

@ -167,7 +167,7 @@ bool load_game (int num)
if (errno == ENOENT) {
// File not found
newtxwin(7, 40, 9, WCENTER(40), true, attr_error_window);
newtxwin(7, 40, 9, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " Game Not Found ");
center(curwin, 3, attr_error_highlight,
@ -179,7 +179,7 @@ bool load_game (int num)
// Some other file error
saved_errno = errno;
newtxwin(9, 70, 9, WCENTER(70), true, attr_error_window);
newtxwin(9, 70, 9, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " Game Not Loaded ");
center(curwin, 3, attr_error_highlight,
@ -334,7 +334,7 @@ bool save_game (int num)
} else {
// Data directory could not be created
newtxwin(9, 70, 7, WCENTER(70), true, attr_error_window);
newtxwin(9, 70, 7, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " Game Not Saved ");
center(curwin, 3, attr_error_highlight,
@ -359,7 +359,7 @@ bool save_game (int num)
// File could not be opened for writing
saved_errno = errno;
newtxwin(9, 70, 7, WCENTER(70), true, attr_error_window);
newtxwin(9, 70, 7, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " Game Not Saved ");
center(curwin, 3, attr_error_highlight,

View File

@ -110,7 +110,7 @@ void init_game (void)
{
// Try to load an old game, if possible
if (game_num != 0) {
newtxwin(5, 30, 6, WCENTER(30), true, attr_status_window);
newtxwin(5, 30, 6, WCENTER, true, attr_status_window);
center(curwin, 2, attr_status_window, "Loading game %d... ", game_num);
wrefresh(curwin);
@ -137,7 +137,7 @@ void init_game (void)
game_num = choice;
// Try to load the game, if possible
newtxwin(5, 30, 9, WCENTER(30), true, attr_status_window);
newtxwin(5, 30, 9, WCENTER, true, attr_status_window);
center(curwin, 2, attr_status_window,
"Loading game %d... ", game_num);
wrefresh(curwin);
@ -207,7 +207,7 @@ void init_game (void)
first_player = randi(number_players);
current_player = first_player;
newtxwin(7, 50, 8, WCENTER(50), true, attr_normal_window);
newtxwin(7, 50, 8, WCENTER, true, attr_normal_window);
center(curwin, 2, attr_normal, "The first player to go is");
center(curwin, 3, attr_highlight, "%s",
@ -235,7 +235,7 @@ static int ask_number_players (void)
// Ask for the number of players
newtxwin(5, 62, 3, WCENTER(62), true, attr_normal_window);
newtxwin(5, 62, 3, WCENTER, true, attr_normal_window);
mvwaddstr(curwin, 2, 2, "Enter number of players ");
waddstr(curwin, "[");
@ -297,7 +297,7 @@ int ask_game_number (void)
// Ask which game to load
newtxwin(5, 54, 6, WCENTER(54), true, attr_normal_window);
newtxwin(5, 54, 6, WCENTER, true, attr_normal_window);
mvwaddstr(curwin, 2, 2, "Enter game number ");
waddstr(curwin, "[");
@ -351,8 +351,7 @@ void ask_player_names (void)
if (number_players == 1) {
// Ask for the player's name
newtxwin(5, WIN_COLS - 4, 9, WCENTER(WIN_COLS - 4), true,
attr_normal_window);
newtxwin(5, WIN_COLS - 4, 9, WCENTER, true, attr_normal_window);
mvwaddstr(curwin, 2, 2, "Please enter your name: ");
@ -370,7 +369,7 @@ void ask_player_names (void)
}
}
newtxwin(5, 44, 6, WCENTER(44), true, attr_normal_window);
newtxwin(5, 44, 6, WCENTER, true, attr_normal_window);
mvwaddstr(curwin, 2, 2, "Do you need any instructions?");
if (answer_yesno(curwin, attr_keycode)) {
show_help();
@ -383,7 +382,7 @@ void ask_player_names (void)
bool done, modified;
int cur, len, i;
newtxwin(number_players + 5, WIN_COLS - 4, 9, WCENTER(WIN_COLS - 4),
newtxwin(number_players + 5, WIN_COLS - 4, 9, WCENTER,
true, attr_normal_window);
center(curwin, 1, attr_title, " Enter Player Names ");
@ -467,7 +466,7 @@ void ask_player_names (void)
}
}
newtxwin(5, 50, 6, WCENTER(50), true, attr_normal_window);
newtxwin(5, 50, 6, WCENTER, true, attr_normal_window);
mvwaddstr(curwin, 2, 2, "Does any player need instructions?");
if (answer_yesno(curwin, attr_keycode)) {
show_help();
@ -498,7 +497,7 @@ void end_game (void)
err_exit_nomem();
}
newtxwin(7, 40, 9, WCENTER(40), true, attr_error_window);
newtxwin(7, 40, 9, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " Game Over ");
center(curwin, 3, attr_error_highlight, "The game is over after %d turns",
@ -514,7 +513,7 @@ void end_game (void)
if (number_players == 1) {
l_strfmon(buf, BUFSIZE, "%1n", total_value(0));
newtxwin(9, 60, 8, WCENTER(60), true, attr_normal_window);
newtxwin(9, 60, 8, WCENTER, true, attr_normal_window);
center(curwin, 1, attr_title, " Total Value ");
center2(curwin, 4, attr_normal, attr_highlight,
@ -529,7 +528,7 @@ void end_game (void)
}
qsort(player, number_players, sizeof(player_info_t), cmp_player);
newtxwin(number_players + 10, WIN_COLS - 4, 3, WCENTER(WIN_COLS - 4),
newtxwin(number_players + 10, WIN_COLS - 4, 3, WCENTER,
true, attr_normal_window);
center(curwin, 1, attr_title, " Game Winner ");
@ -572,7 +571,7 @@ void show_map (bool closewin)
int n, x, y;
newtxwin(MAX_Y + 4, WIN_COLS, 1, WCENTER(WIN_COLS), true, attr_map_window);
newtxwin(MAX_Y + 4, WIN_COLS, 1, WCENTER, true, attr_map_window);
// Draw various borders
mvwaddch(curwin, 2, 0, ACS_LTEE);
@ -650,7 +649,7 @@ void show_map (bool closewin)
wrefresh(curwin);
newtxwin(WIN_LINES - MAX_Y - 5, WIN_COLS, MAX_Y + 5, WCENTER(WIN_COLS),
newtxwin(WIN_LINES - MAX_Y - 5, WIN_COLS, MAX_Y + 5, WCENTER,
true, attr_normal_window);
wait_for_key(curwin, 2, attr_waitforkey);
@ -673,7 +672,7 @@ void show_status (int num)
assert(num >= 0 && num < number_players);
newtxwin(MAX_COMPANIES + 15, WIN_COLS, 1, WCENTER(WIN_COLS), true,
newtxwin(MAX_COMPANIES + 15, WIN_COLS, 1, WCENTER, true,
attr_normal_window);
center(curwin, 1, attr_title, " Stock Portfolio ");

View File

@ -169,7 +169,7 @@ void show_help (void)
if (numpages == 0)
return;
newtxwin(WIN_LINES - 1, WIN_COLS, 1, WCENTER(WIN_COLS), false, 0);
newtxwin(WIN_LINES - 1, WIN_COLS, 1, WCENTER, false, 0);
while (! done) {
// Display a page of instructions

View File

@ -269,6 +269,14 @@ WINDOW *newtxwin (int nlines, int ncols, int begin_y, int begin_x,
txwin_t *nw;
// Centre the window, if required
if (begin_y == WCENTER) {
begin_y = (nlines == 0) ? 0 : (LINES - nlines) / 2;
}
if (begin_x == WCENTER) {
begin_x = (ncols == 0) ? 0 : (COLS - ncols) / 2;
}
// Create the new window
win = newwin(nlines, ncols, begin_y, begin_x);

View File

@ -54,7 +54,7 @@
#define WIN_LINES MIN_LINES // Number of lines in main window
#define WIN_COLS MIN_COLS // Number of columns in main window
#define WCENTER(x) ((COLS - (x)) / 2) // Centre the window
#define WCENTER -1 // Centre the new window
// Visibility of the cursor in Curses (for curs_set())
@ -201,9 +201,10 @@ extern void end_screen (void);
places it top-most in the stack of windows managed by this module. A
pointer to this new window is returned; the global variable curwin also
points to this new window. Note that begin_y and begin_x are zero-
based global coordinates. If dofill is true, bkgd_attr is used to fill
the background and box(curwin, 0, 0) is called. Note that wrefresh()
is NOT called on the new window.
based global coordinates; either (or both) can be WCENTER to centre
that dimension within the terminal screen. If dofill is true,
bkgd_attr is used to fill the background and box(curwin, 0, 0) is
called. Note that wrefresh() is NOT called on the new window.
If newtxwin() fails to create a new window due to insufficient memory,
this function does NOT return: it terminates the program with an "out

View File

@ -226,7 +226,7 @@ selection_t get_move (void)
wrefresh(curwin);
// Show menu of choices for the player
newtxwin(5, WIN_COLS, 19, WCENTER(WIN_COLS), false, 0);
newtxwin(5, WIN_COLS, 19, WCENTER, false, 0);
while (selection == SEL_NONE) {
wbkgd(curwin, attr_normal_window);
werase(curwin);
@ -345,7 +345,7 @@ selection_t get_move (void)
if (game_loaded) {
// Save the game to the same game number
newtxwin(5, 30, 7, WCENTER(30), true, attr_status_window);
newtxwin(5, 30, 7, WCENTER, true, attr_status_window);
center(curwin, 2, attr_status_window,
"Saving game %d... ", game_num);
wrefresh(curwin);
@ -361,7 +361,7 @@ selection_t get_move (void)
bool done;
// Ask which game to save
newtxwin(6, 54, 8, WCENTER(54), true, attr_normal_window);
newtxwin(6, 54, 8, WCENTER, true, attr_normal_window);
center(curwin, 1, attr_title, " Save Game ");
mvwaddstr(curwin, 3, 2, "Enter game number ");
@ -408,7 +408,7 @@ selection_t get_move (void)
game_num = key - '0';
// Try to save the game, if possible
newtxwin(5, 30, 7, WCENTER(30), true, attr_status_window);
newtxwin(5, 30, 7, WCENTER, true, attr_status_window);
center(curwin, 2, attr_status_window,
"Saving game %d... ", game_num);
wrefresh(curwin);
@ -641,9 +641,9 @@ void bankrupt_player (bool forced)
longname = (strlen(player[current_player].name) > 20);
if (forced) {
newtxwin(longname ? 9 : 8, 54, 7, WCENTER(54), true, attr_error_window);
newtxwin(longname ? 9 : 8, 54, 7, WCENTER, true, attr_error_window);
} else {
newtxwin(longname ? 8 : 7, 50, 7, WCENTER(50), true, attr_error_window);
newtxwin(longname ? 8 : 7, 50, 7, WCENTER, true, attr_error_window);
}
center(curwin, 1, attr_error_title, " Bankruptcy Court ");
@ -742,7 +742,7 @@ void try_start_new_company (int x, int y)
} else {
// Create the new company
newtxwin(8, 50, 7, WCENTER(50), true, attr_normal_window);
newtxwin(8, 50, 7, WCENTER, true, attr_normal_window);
center(curwin, 1, attr_title, " New Company ");
center(curwin, 3, attr_normal, "A new company has been formed!");
@ -807,7 +807,7 @@ void merge_companies (map_val_t a, map_val_t b)
// Display information about the merger
newtxwin(number_players + 14, WIN_COLS - 4, 9 - number_players,
WCENTER(WIN_COLS - 4), true, attr_normal_window);
WCENTER, true, attr_normal_window);
center(curwin, 1, attr_title, " Company Merger ");
center3(curwin, 3, attr_highlight, attr_highlight, attr_normal,
@ -958,7 +958,7 @@ void adjust_values (void)
if (company[which].on_map) {
if (randf() < ALL_ASSETS_TAKEN) {
newtxwin(10, 60, 6, WCENTER(60), true, attr_error_window);
newtxwin(10, 60, 6, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " Bankruptcy Court ");
center(curwin, 3, attr_error_highlight, "%s has been declared",
@ -988,7 +988,7 @@ void adjust_values (void)
}
}
newtxwin(14, 60, 4, WCENTER(60), true, attr_error_window);
newtxwin(14, 60, 4, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " Bankruptcy Court ");
center(curwin, 3, attr_error_highlight, "%s has been declared",
@ -1101,7 +1101,7 @@ void adjust_values (void)
impounded = MIN(player[current_player].cash,
player[current_player].debt);
newtxwin(8, 60, 7, WCENTER(60), true, attr_error_window);
newtxwin(8, 60, 7, WCENTER, true, attr_error_window);
center(curwin, 1, attr_error_title, " Interstellar Trading Bank ");
l_strfmon(buf, BUFSIZE, "%1n", player[current_player].debt);