From 9c855d16f1a737ddd9bde72e0fc51f4fd0a1e042 Mon Sep 17 00:00:00 2001 From: Mario Kilies Date: Fri, 14 Jan 2011 04:32:35 +0100 Subject: Implemented hand_sort(). ui_choose_card() now pre-selects the card with lowest index, if at index 0 is no card. draw_card() now draws empty placeholder cards, to clear old screen content. --- src/ui.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src/ui.c') diff --git a/src/ui.c b/src/ui.c index 7c8f8f2..e7b7657 100644 --- a/src/ui.c +++ b/src/ui.c @@ -26,6 +26,17 @@ static void draw_card(WINDOW *w, const uint8_t row, const uint8_t col, const boo { 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. + if (0 == c) + { + mvwhline(w, row, col, ' ', 7); + mvwhline(w, row+1, col, ' ', 7); + mvwhline(w, row+2, col, ' ', 7); + mvwhline(w, row+3, col, ' ', 7); + mvwhline(w, row+4, col, ' ', 7); + return; + } + if (highlight) wattron(w, A_BOLD); @@ -231,10 +242,6 @@ void ui_display_wnd_hand_cards(const hand h, const bool highlight, const uint8_t for (uint8_t i = 0; i < MAX_HAND_CARDS; i++) { - // Skip empty card slots in hand - if (0 == h[i]) - continue; - if (highlight && i == highlighted_card) { if (i < 5) // Start with the first row of cards @@ -253,16 +260,27 @@ void ui_display_wnd_hand_cards(const hand h, const bool highlight, const uint8_t wrefresh(w_hand_cards); } -uint8_t ui_choose_card(const hand h) +uint8_t ui_choose_card(hand h) { int key; uint8_t chosen_card_idx = 0; + int8_t i; // Has to be signed for modulo calculation + + hand_sort(h); + + // Select card with lowest index as default + if (0 == h[chosen_card_idx]) + { + i = (chosen_card_idx + 1) % MAX_HAND_CARDS; + while(0 == h[i]) + i = (i + 1) % MAX_HAND_CARDS; + chosen_card_idx = i; + } ui_display_wnd_hand_cards(h, true, chosen_card_idx); while (KEY_RETURN != (key = wgetch(w_hand_cards))) { - int8_t i; // Has to be signed for modulo calculation switch (key) { case KEY_VI_LEFT: -- cgit v1.2.3