summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c1
-rw-r--r--src/ui.c32
2 files changed, 26 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index 388f34d..1861185 100644
--- a/src/main.c
+++ b/src/main.c
@@ -27,6 +27,7 @@ int main(int argc, char **argv)
// Example data set for hand cards window
hand h = {22, 0, 12, 85, 27, 69, 78, 0, 77, 0};
+ hand_sort(h);
ui_init();
ui_display_wnd_table_cards(ts, false, 0);
diff --git a/src/ui.c b/src/ui.c
index c9409df..3500f93 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -237,31 +237,49 @@ void ui_display_wnd_current_state(const player_name_open_card_tuple pnoc[], cons
/**
* Displays the hand cards window.
- * @param[in] h The hand that will be displayed. h must not contain 0
+ * @param[in] h The hand that will be displayed. h must be sorted in ascending order
* @param[in] highlight If true, a card will be highlighted
* @param[in] highlighted_card The card to highlight. Only used, if highlight is true
*/
void ui_display_wnd_hand_cards(const hand h, const bool highlight, const uint8_t highlighted_card)
{
+ uint8_t num_zero_cards = 0;
+
wattron(w_hand_cards, A_BOLD);
mvwprintw(w_hand_cards, 0, 0, "Hand Cards:");
wattroff(w_hand_cards, A_BOLD);
+ // Clear old cards from screen first
+ for (uint8_t i = 0; i < MAX_HAND_CARDS; i++)
+ {
+ if (i - num_zero_cards < 5) // Start with the first row of cards
+ draw_card(w_hand_cards, 1, (i - num_zero_cards) * 8, false, 0);
+ else // And then draw the second row
+ draw_card(w_hand_cards, 6, (i - num_zero_cards - 5) * 8, false, 0);
+ }
+
for (uint8_t i = 0; i < MAX_HAND_CARDS; i++)
{
+ // Cound all 0 cards and don't draw them
+ if (0 == h[i])
+ {
+ num_zero_cards++;
+ continue;
+ }
+
if (highlight && i == highlighted_card)
{
- if (i < 5) // Start with the first row of cards
- draw_card(w_hand_cards, 1, i*8, true, h[i]);
+ if (i - num_zero_cards < 5) // Start with the first row of cards
+ draw_card(w_hand_cards, 1, (i - num_zero_cards) * 8, true, h[i]);
else // And then draw the second row
- draw_card(w_hand_cards, 6, (i-5)*8, true, h[i]);
+ draw_card(w_hand_cards, 6, (i - num_zero_cards - 5) * 8, true, h[i]);
continue;
}
- if (i < 5) // Start with the first row of cards
- draw_card(w_hand_cards, 1, i*8, false, h[i]);
+ if (i - num_zero_cards < 5) // Start with the first row of cards
+ draw_card(w_hand_cards, 1, (i - num_zero_cards) * 8, false, h[i]);
else // And then draw the second row
- draw_card(w_hand_cards, 6, (i-5)*8, false, h[i]);
+ draw_card(w_hand_cards, 6, (i - num_zero_cards - 5) * 8, false, h[i]);
}
wrefresh(w_hand_cards);