summaryrefslogtreecommitdiff
path: root/src/ui.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui.c')
-rw-r--r--src/ui.c85
1 files changed, 70 insertions, 15 deletions
diff --git a/src/ui.c b/src/ui.c
index 6b80763..fedceed 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -8,6 +8,14 @@
#define CP_MAGENTA_ON_BLACK 4
#define CP_RED_ON_BLACK 5
+#define KEY_ESCAPE 27
+#define KEY_RETURN 10
+
+#define KEY_VI_LEFT 'h'
+#define KEY_VI_RIGHT 'l'
+#define KEY_VI_UP 'k'
+#define KEY_VI_DOWN 'j'
+
static bool colors = false;
static WINDOW *w_table_cards;
static WINDOW *w_stack_points;
@@ -129,13 +137,10 @@ void ui_display_wnd_table_cards(const tablestacks ts, const bool highlight, cons
for (uint8_t i = 0; i < NUM_TABLESTACKS; i++)
{
- if (highlight)
+ if (highlight && i == highlighted_stack)
{
- if (i == highlighted_stack)
- {
- draw_cardstack(w_table_cards, 1 + i*5, 0, true, ts[i]);
- continue;
- }
+ draw_cardstack(w_table_cards, 1 + i*5, 0, true, ts[i]);
+ continue;
}
draw_cardstack(w_table_cards, 1 + i*5, 0, false, ts[i]);
@@ -147,8 +152,10 @@ void ui_display_wnd_table_cards(const tablestacks ts, const bool highlight, cons
/**
* Displays the stack points window.
* @param[in] ts The table stacks used for calculation of stack points
+ * @param[in] highlight If true, stack poins will be highlighted
+ * @param[in] highlighted_points The stack points to highlight. Only used, if highlight is true
*/
-void ui_display_wnd_stack_points(const tablestacks ts)
+void ui_display_wnd_stack_points(const tablestacks ts, const bool highlight, const uint8_t highlighted_points)
{
wattron(w_stack_points, A_BOLD);
mvwprintw(w_stack_points, 0, 0, "Pts:");
@@ -156,6 +163,14 @@ void ui_display_wnd_stack_points(const tablestacks ts)
for (uint8_t i = 0; i < NUM_TABLESTACKS; i++)
{
+ if (highlight && i == highlighted_points)
+ {
+ wattron(w_stack_points, A_BOLD);
+ mvwprintw(w_stack_points, 3 + i*5, 1, "%2d", cardstack_get_points(ts[i]));
+ wattroff(w_stack_points, A_BOLD);
+ continue;
+ }
+
mvwprintw(w_stack_points, 3 + i*5, 1, "%2d", cardstack_get_points(ts[i]));
}
@@ -234,6 +249,51 @@ void ui_display_wnd_hand_cards(const hand h, const bool highlight, const uint8_t
wrefresh(w_hand_cards);
}
+uint8_t ui_choose_stack(const tablestacks ts)
+{
+ int key;
+ uint8_t chosen_stack_idx = 0;
+
+ 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)))
+ {
+ switch(key)
+ {
+ case KEY_VI_UP:
+ // Fall through
+ case KEY_LEFT:
+ // Fall through
+ case KEY_UP:
+ if (0 == chosen_stack_idx)
+ chosen_stack_idx = NUM_TABLESTACKS - 1;
+ else
+ chosen_stack_idx--;
+ break;
+
+ case KEY_VI_DOWN:
+ // Fall through
+ case KEY_RIGHT:
+ // Fall through
+ case KEY_DOWN:
+ if (NUM_TABLESTACKS - 1 == chosen_stack_idx)
+ chosen_stack_idx = 0;
+ else
+ chosen_stack_idx++;
+ break;
+ default:
+ // No default
+ break;
+ }
+
+ ui_display_wnd_table_cards(ts, true, chosen_stack_idx);
+ ui_display_wnd_stack_points(ts, true, chosen_stack_idx);
+ }
+
+ return chosen_stack_idx;
+}
+
/**
* Initializes ncurses.
*/
@@ -252,9 +312,8 @@ void ui_init(void)
init_pair(CP_RED_ON_BLACK, COLOR_RED, COLOR_BLACK);
bkgd(COLOR_PAIR(0));
}
+
raw(); // Line buffering disabled
- keypad(stdscr, true); // We get F1, F2 etc..
- nodelay(stdscr, true); // Non-blocking input
noecho(); // Don't echo() while we do getch
curs_set(0); // Make the cursor invisible
clear();
@@ -266,8 +325,8 @@ void ui_init(void)
w_current_state = newwin(10, 38, 0, 24);
w_hand_cards = newwin(11, 39, 10, 24);
- // 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}};
+ // 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
@@ -293,12 +352,8 @@ void ui_init(void)
// Draw user interface
mvvline(0, 22, ACS_VLINE, 21); // Vertical line
refresh();
- ui_display_wnd_table_cards(ts, true, 1);
- ui_display_wnd_stack_points(ts);
ui_display_wnd_current_state(pnoc, num_players, 2, score);
ui_display_wnd_hand_cards(h, true, 8);
-
- sleep(4);
}
/**