diff options
Diffstat (limited to 'src/ui.c')
| -rw-r--r-- | src/ui.c | 64 |
1 files changed, 63 insertions, 1 deletions
@@ -24,6 +24,8 @@ static WINDOW *w_current_state; static WINDOW *w_messages; static WINDOW *w_hand_cards; +static WINDOW *w_final_scores; + static void draw_card(WINDOW *w, const uint8_t row, const uint8_t col, const bool highlight, const card c) { assert(w != NULL); @@ -214,7 +216,7 @@ void ui_display_wnd_stack_points(const table_stacks_t *ts, const bool highlight, * @param[in] highlighted_player The player to highlight * @param[in] score The players score */ -void ui_display_wnd_current_state(const player_list_t *pl, const uint8_t num_players, const bool highlight, const uint8_t highlighted_player, const uint32_t score) +void ui_display_wnd_current_state(const player_list_t *pl, const uint8_t num_players, const bool highlight, const player_id_t highlighted_player, const uint32_t score) { assert(pl != NULL); uint8_t pos = 0; @@ -334,6 +336,62 @@ void ui_display_wnd_hand_cards(const hand_t *h, const bool highlight, const uint wnoutrefresh(w_hand_cards); } +/** + * Displays the final scores window and highlights the player. +*/ +void ui_display_wnd_final_scores(const player_list_t *pl, const uint8_t num_players, const player_id_t highlighted_player) +{ + uint8_t row = 4; + uint8_t place = 1; + + clear(); + refresh(); + + wattron(w_final_scores, A_BOLD); + mvwprintw(w_final_scores, 1, 7, "- Final standings -"); + mvwprintw(w_final_scores, 3, 2, "Pos: Player: Score:"); + wattroff(w_final_scores, A_BOLD); + + for (int i = 0; i < num_players; i++) + { + const player_list_entry_t *ple = &pl->players[i]; + + if (0 == ple->player_id) // Skip empty player list entries + continue; + + // If the previous player has the same score, we have the same place as he does + if (i > 0 && pl->players[i-1].score == ple->score) + place = place - 1; + + // Reward the glorious winners with an outstanding output of their scores + if (1 == place) + wattron(w_final_scores, A_BOLD); + + if (ple->player_id == highlighted_player || 1 == place) // Highlight the players score + { + wattron(w_final_scores, COLOR_PAIR(CP_YELLOW_ON_BLACK)); + mvwprintw(w_final_scores, row, 2, "%2d.", place); + mvwprintw(w_final_scores, row, 7, "%-s", ple->player_name); + mvwprintw(w_final_scores, row++, 25, "%3d", ple->score); + wattroff(w_final_scores, COLOR_PAIR(CP_YELLOW_ON_BLACK)); + } + else + { + mvwprintw(w_final_scores, row, 2, "%2d.", place); + mvwprintw(w_final_scores, row, 7, "%-s", ple->player_name); + mvwprintw(w_final_scores, row++, 25, "%3d", ple->score); + } + + if (1 == place) + wattroff(w_final_scores, A_BOLD); + + place++; + } + + wrefresh(w_final_scores); + while (KEY_RETURN != wgetch(w_final_scores)); +} + uint8_t ui_choose_card(hand_t *h) { assert(h != NULL); @@ -480,6 +538,9 @@ void ui_init(void) w_messages = newwin(2, 39, 7, 24); w_hand_cards = newwin(11, 39, 10, 24); + w_final_scores = newwin(15, 32, 2, 15); + box(w_final_scores, 0, 0); + // Set input settings for windows keypad(w_table_cards, true); // We get F1, F2 etc.. keypad(w_hand_cards, true); // We get F1, F2 etc.. @@ -499,5 +560,6 @@ void ui_fini(void) delwin(w_current_state); delwin(w_messages); delwin(w_hand_cards); + delwin(w_final_scores); endwin(); // End curses mode } |
