summaryrefslogtreecommitdiff
path: root/src/ui.c
diff options
context:
space:
mode:
authorMario Kilies <MarioKilies@GMX.net>2011-01-14 03:33:29 +0100
committerMario Kilies <MarioKilies@GMX.net>2011-01-14 03:33:29 +0100
commit0dfe9ff514cb6e3ffe9bfd394aebeb54445edc03 (patch)
tree02771b64941987eb8beeb124f777ed47601f577f /src/ui.c
parentcf073d5083edaa8249ad1a960db0b2ba7619e70e (diff)
Implemented ui_choose_card().
Diffstat (limited to 'src/ui.c')
-rw-r--r--src/ui.c74
1 files changed, 49 insertions, 25 deletions
diff --git a/src/ui.c b/src/ui.c
index fedceed..7c8f8f2 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -231,6 +231,10 @@ 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
@@ -249,6 +253,47 @@ 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)
+{
+ int key;
+ uint8_t chosen_card_idx = 0;
+
+ 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:
+ // Fall through
+ case KEY_LEFT:
+ i = (chosen_card_idx - 1 + MAX_HAND_CARDS) % MAX_HAND_CARDS;
+ while(0 == h[i])
+ i = (i - 1 + MAX_HAND_CARDS) % MAX_HAND_CARDS;
+ chosen_card_idx = i;
+ break;
+
+ case KEY_VI_RIGHT:
+ // Fall through
+ case KEY_RIGHT:
+ i = (chosen_card_idx + 1) % MAX_HAND_CARDS;
+ while(0 == h[i])
+ i = (i + 1) % MAX_HAND_CARDS;
+ chosen_card_idx = i;
+ break;
+
+ default:
+ // No default
+ break;
+ }
+
+ ui_display_wnd_hand_cards(h, true, chosen_card_idx);
+ }
+
+ return chosen_card_idx;
+}
+
uint8_t ui_choose_stack(const tablestacks ts)
{
int key;
@@ -257,9 +302,9 @@ uint8_t ui_choose_stack(const tablestacks ts)
ui_display_wnd_table_cards(ts, true, chosen_stack_idx);
ui_display_wnd_stack_points(ts, true, chosen_stack_idx);
- while(KEY_RETURN != (key = wgetch(w_table_cards)))
+ while (KEY_RETURN != (key = wgetch(w_table_cards)))
{
- switch(key)
+ switch (key)
{
case KEY_VI_UP:
// Fall through
@@ -282,6 +327,7 @@ uint8_t ui_choose_stack(const tablestacks ts)
else
chosen_stack_idx++;
break;
+
default:
// No default
break;
@@ -327,33 +373,11 @@ void ui_init(void)
// Set input settings for windows
keypad(w_table_cards, true); // We get F1, F2 etc..
-
- // The stack points window uses ts, too, so there is no separate data set
-
- // Example data set for hand cards window
- const hand h = {12, 13, 22, 25, 27, 69, 77, 85, 100, 103};
-
- // Example data set for current state window
- const player_name_open_card_tuple pnoc[10] = {
- {"$you", 10},
- {"1234567890", 23},
- {"baz", 38},
- {"foo_bar", 14},
- {"lolcat", 60},
- {"blablub123", 15},
- {"abcdefg", 103},
- {"hello", 98},
- {"hornoxe", 33},
- {"1337nick", 74}
- };
- const uint8_t num_players = 10;
- const uint32_t score = 10;
+ keypad(w_hand_cards, true); // We get F1, F2 etc..
// Draw user interface
mvvline(0, 22, ACS_VLINE, 21); // Vertical line
refresh();
- ui_display_wnd_current_state(pnoc, num_players, 2, score);
- ui_display_wnd_hand_cards(h, true, 8);
}
/**