diff options
| author | Mario Kilies <MarioKilies@GMX.net> | 2011-01-14 03:33:29 +0100 |
|---|---|---|
| committer | Mario Kilies <MarioKilies@GMX.net> | 2011-01-14 03:33:29 +0100 |
| commit | 0dfe9ff514cb6e3ffe9bfd394aebeb54445edc03 (patch) | |
| tree | 02771b64941987eb8beeb124f777ed47601f577f /src | |
| parent | cf073d5083edaa8249ad1a960db0b2ba7619e70e (diff) | |
Implemented ui_choose_card().
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 30 | ||||
| -rw-r--r-- | src/ui.c | 74 | ||||
| -rw-r--r-- | src/ui.h | 1 |
3 files changed, 77 insertions, 28 deletions
@@ -1,6 +1,4 @@ -#include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <curses.h> #include "ui.h" @@ -9,8 +7,34 @@ int main(int argc, char **argv) // Example data set for table cards window const tablestacks ts = {{1, 2, 3, 4, 101}, {6, 7, 53, 0, 0}, {11, 55, 0, 0, 0}, {17, 29, 36, 42, 0}}; + // The stack points window uses ts, too, so there is no separate data set + + // 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; + + // Example data set for hand cards window + const hand h = {12, 0, 22, 25, 27, 69, 77, 85, 100, 103}; + ui_init(); - ui_choose_stack(ts); + ui_display_wnd_table_cards(ts, false, 0); + ui_display_wnd_stack_points(ts, false, 0); + ui_display_wnd_current_state(pnoc, num_players, 2, score); + ui_display_wnd_hand_cards(h, false, 0); + + ui_choose_card(h); ui_fini(); return EXIT_SUCCESS; @@ -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); } /** @@ -12,6 +12,7 @@ void ui_display_wnd_table_cards(const tablestacks ts, const bool highlight, cons void ui_display_wnd_stack_points(const tablestacks ts, const bool highlight, const uint8_t highlighted_points); void ui_display_wnd_current_state(const player_name_open_card_tuple pnoc[], const uint8_t num_players, const uint8_t active_player, const uint32_t score); void ui_display_wnd_hand_cards(const hand h, const bool highlight, const uint8_t highlighted_card); +uint8_t ui_choose_card(const hand h); uint8_t ui_choose_stack(const tablestacks ts); void ui_init(void); void ui_fini(void); |
