summaryrefslogtreecommitdiff
path: root/web/web_prompt.c
diff options
context:
space:
mode:
Diffstat (limited to 'web/web_prompt.c')
-rw-r--r--web/web_prompt.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/web/web_prompt.c b/web/web_prompt.c
index 2ceb2d4..3b5bc68 100644
--- a/web/web_prompt.c
+++ b/web/web_prompt.c
@@ -13,8 +13,18 @@
int oi_timeout;
+enum prompt_mode {
+ PM_DARTBOARD,
+ PM_VISIT,
+ PM_NUM_DARTS,
+ PM_END_MATCH,
+ PM_SELECT_MODE
+};
enum prompt_mode pm;
+static char *list_optv[10];
+static int list_optc;
+
static struct {
bufstr msgl, msgr, input;
} bufs;
@@ -61,6 +71,42 @@ void prompt_flush()
dom_set_content("#prompt-input", bufstr_flush(&bufs.input));
}
+static void clear_list_opts()
+{
+ for (int i = 0; i < list_optc; ++i)
+ free(list_optv[i]);
+ list_optc = 0;
+}
+
+static void add_list_opt(char *str)
+{
+ list_optv[list_optc++] = strdup(str);
+}
+
+static void flush_list_opts()
+{
+ struct dom_elem **elemv = malloc(list_optc * sizeof(*elemv));
+
+ for (int i = 0; i < list_optc; ++i) {
+ struct dom_elem *e = dom_elem_init(NULL, "div", 2);
+ asprintf(&e->content, "[%d] %s", i + 1, list_optv[i]);
+ dom_elem_add_attr(e, "class", "key");
+
+ char buf[64];
+ sprintf(buf, "append:%d;submit", i + 1);
+ dom_elem_add_attr(e, "data-command", buf);
+
+ elemv[i] = e;
+ }
+
+ dom_set_content("#keypad-list", NULL);
+ dom_append_elemv("#keypad-list", list_optc, elemv);
+
+ for (int i = 0; i < list_optc; ++i)
+ dom_elem_free(elemv[i]);
+ free(elemv);
+}
+
void set_prompt_mode(enum prompt_mode mode)
{
pm = mode;
@@ -72,7 +118,7 @@ void set_prompt_mode(enum prompt_mode mode)
dom_set_uniq_class(
pm == PM_DARTBOARD ? "#keypad-dartboard" :
- pm == PM_SELECT_MODE ? "#keypad-select_mode" :
+ pm == PM_SELECT_MODE ? "#keypad-list" :
"#keypad-default",
"visible", ".keypad");
}
@@ -121,6 +167,11 @@ void prompt_select_mode()
clear_player_info(pn);
dom_set_content("#visits", NULL);
+ clear_list_opts();
+ add_list_opt("Play against bot");
+ add_list_opt("One-player scoreboard");
+ add_list_opt("Two-player scoreboard");
+ flush_list_opts();
set_prompt_mode(PM_SELECT_MODE);
prompt_set_msgl("Select match mode:");
prompt_set_msgr(NULL);