diff options
Diffstat (limited to 'src/ui.c')
| -rw-r--r-- | src/ui.c | 50 |
1 files changed, 34 insertions, 16 deletions
@@ -1,5 +1,6 @@ #include "ui.h" -#include "cardstack.h" +#include <assert.h> +#include "card_stack.h" // Definition of ncurses color pair identifiers #define CP_WHITE_ON_BLACK 1 @@ -24,6 +25,8 @@ static WINDOW *w_hand_cards; static void draw_card(WINDOW *w, const uint8_t row, const uint8_t col, const bool highlight, const card c) { + assert(w != NULL); + unsigned color_pair = 0; // If card is 0, draw a placeholder (empty space) instead of a card. This is used to remove a card that does not longer exist but has visible remains on the screen. @@ -123,8 +126,11 @@ static void draw_card(WINDOW *w, const uint8_t row, const uint8_t col, const boo wattroff(w, A_BOLD); } -static void draw_cardstack(WINDOW *w, const uint8_t row, const uint8_t col, const bool highlight, const cardstack cs) +static void draw_card_stack(WINDOW *w, const uint8_t row, const uint8_t col, const bool highlight, const card_stack_t *cs) { + assert(w != NULL); + assert(cs != NULL); + // Clear old card stack first mvwhline(w, row, col, ' ', 15); mvwhline(w, row+1, col, ' ', 15); @@ -132,11 +138,11 @@ static void draw_cardstack(WINDOW *w, const uint8_t row, const uint8_t col, cons mvwhline(w, row+3, col, ' ', 15); mvwhline(w, row+4, col, ' ', 15); - for (uint8_t i = 0; i < MAX_CARDSTACK_SIZE; i++) + for (uint8_t i = 0; i < MAX_CARD_STACK_SIZE; i++) { - if (cs[i] != 0) + if (cs->cards[i] != 0) { - draw_card(w, row, i*2, highlight, cs[i]); + draw_card(w, row, i*2, highlight, cs->cards[i]); } } } @@ -147,21 +153,23 @@ static void draw_cardstack(WINDOW *w, const uint8_t row, const uint8_t col, cons * @param[in] highlight If true, a stack will be highlighted * @param[in] highlighted_stack The stack to highlight. Only used, if highlight is true */ -void ui_display_wnd_table_cards(const tablestacks ts, const bool highlight, const uint8_t highlighted_stack) +void ui_display_wnd_table_cards(const table_stacks_t *ts, const bool highlight, const uint8_t highlighted_stack) { + assert(ts != NULL); + wattron(w_table_cards, A_BOLD); mvwprintw(w_table_cards, 0, 2, "Table Cards:"); wattroff(w_table_cards, A_BOLD); - for (uint8_t i = 0; i < NUM_TABLESTACKS; i++) + for (uint8_t i = 0; i < NUM_TABLE_STACKS; i++) { if (highlight && i == highlighted_stack) { - draw_cardstack(w_table_cards, 1 + i*5, 0, true, ts[i]); + draw_card_stack(w_table_cards, 1 + i*5, 0, true, &ts->stacks[i]); continue; } - draw_cardstack(w_table_cards, 1 + i*5, 0, false, ts[i]); + draw_card_stack(w_table_cards, 1 + i*5, 0, false, &ts->stacks[i]); } wrefresh(w_table_cards); @@ -173,23 +181,25 @@ void ui_display_wnd_table_cards(const tablestacks ts, const bool highlight, cons * @param[in] highlight If true, stack poins will be highlighted * @param[in] highlighted_points The stack points to highlight. Only used, if highlight is true */ -void ui_display_wnd_stack_points(const tablestacks ts, const bool highlight, const uint8_t highlighted_points) +void ui_display_wnd_stack_points(const table_stacks_t *ts, const bool highlight, const uint8_t highlighted_points) { + assert(ts != NULL); + wattron(w_stack_points, A_BOLD); mvwprintw(w_stack_points, 0, 0, "Pts:"); wattroff(w_stack_points, A_BOLD); - for (uint8_t i = 0; i < NUM_TABLESTACKS; i++) + for (uint8_t i = 0; i < NUM_TABLE_STACKS; i++) { if (highlight && i == highlighted_points) { wattron(w_stack_points, A_BOLD); - mvwprintw(w_stack_points, 3 + i*5, 1, "%2d", cardstack_get_points(ts[i])); + mvwprintw(w_stack_points, 3 + i*5, 1, "%2d", card_stack_get_points(&ts->stacks[i])); wattroff(w_stack_points, A_BOLD); continue; } - mvwprintw(w_stack_points, 3 + i*5, 1, "%2d", cardstack_get_points(ts[i])); + mvwprintw(w_stack_points, 3 + i*5, 1, "%2d", card_stack_get_points(&ts->stacks[i])); } wrefresh(w_stack_points); @@ -204,6 +214,8 @@ void ui_display_wnd_stack_points(const tablestacks ts, const bool highlight, con */ void ui_display_wnd_current_state(const pnoc_t pnoc[], const uint8_t num_players, const uint8_t active_player, const uint32_t score) { + assert(pnoc != NULL); + wattron(w_current_state, A_BOLD); mvwprintw(w_current_state, 0, 0, "Current state:"); mvwprintw(w_current_state, 0, 22, "Your Score: %3d", score); @@ -243,6 +255,8 @@ void ui_display_wnd_current_state(const pnoc_t pnoc[], const uint8_t num_players */ void ui_display_wnd_hand_cards(const hand_t *h, const bool highlight, const uint8_t highlighted_card) { + assert(h != NULL); + uint8_t num_zero_cards = 0; wattron(w_hand_cards, A_BOLD); @@ -287,6 +301,8 @@ void ui_display_wnd_hand_cards(const hand_t *h, const bool highlight, const uint uint8_t ui_choose_card(hand_t *h) { + assert(h != NULL); + int key; uint8_t chosen_card_idx = 0; int8_t i; // Has to be signed for modulo calculation @@ -338,8 +354,10 @@ uint8_t ui_choose_card(hand_t *h) return chosen_card_idx; } -uint8_t ui_choose_stack(const tablestacks ts) +uint8_t ui_choose_stack(const table_stacks_t *ts) { + assert(ts != NULL); + int key; uint8_t chosen_stack_idx = 0; @@ -356,7 +374,7 @@ uint8_t ui_choose_stack(const tablestacks ts) // Fall through case KEY_UP: if (0 == chosen_stack_idx) - chosen_stack_idx = NUM_TABLESTACKS - 1; + chosen_stack_idx = NUM_TABLE_STACKS - 1; else chosen_stack_idx--; break; @@ -366,7 +384,7 @@ uint8_t ui_choose_stack(const tablestacks ts) case KEY_RIGHT: // Fall through case KEY_DOWN: - if (NUM_TABLESTACKS - 1 == chosen_stack_idx) + if (NUM_TABLE_STACKS - 1 == chosen_stack_idx) chosen_stack_idx = 0; else chosen_stack_idx++; |
