diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-09 23:39:12 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-09 23:39:12 -0700 |
commit | 90b5ca5e47f0fda21f8da6cb9857a35e0f4730a3 (patch) | |
tree | 05c3bae5829fcdcc5df2bebd36c504efea974494 /web/web_prompt.c | |
parent | 1def0d71449f95c1fb609053b84a92e8adbb0eb1 (diff) | |
download | dartboat-90b5ca5e47f0fda21f8da6cb9857a35e0f4730a3.tar.gz dartboat-90b5ca5e47f0fda21f8da6cb9857a35e0f4730a3.tar.xz |
web: allow selection of starting points and user to throw first
This new option selection code is a bit messy for now. It requires the
options and their order to be in sync between the prompt functions and
the corresponding submit functions. There's also a bit too much
repetition of generic code that's applicable to all options.
Diffstat (limited to 'web/web_prompt.c')
-rw-r--r-- | web/web_prompt.c | 136 |
1 files changed, 129 insertions, 7 deletions
diff --git a/web/web_prompt.c b/web/web_prompt.c index 3f5521a..9db4fdd 100644 --- a/web/web_prompt.c +++ b/web/web_prompt.c @@ -18,7 +18,10 @@ enum prompt_mode { PM_VISIT, PM_NUM_DARTS, PM_END_MATCH, - PM_SELECT_MODE + PM_SELECT_MODE, + PM_MATCH_OPTS, + PM_MATCH_OPT_START_PTS, + PM_MATCH_OPT_THROWS_FIRST }; enum prompt_mode pm; @@ -128,6 +131,9 @@ void set_prompt_mode(enum prompt_mode mode) dom_set_uniq_class( pm == PM_DARTBOARD ? "#keypad-dartboard" : pm == PM_SELECT_MODE ? "#keypad-list" : + pm == PM_MATCH_OPTS ? "#keypad-list" : + pm == PM_MATCH_OPT_START_PTS ? "#keypad-list" : + pm == PM_MATCH_OPT_THROWS_FIRST ? "#keypad-list" : "#keypad-default", "visible", ".keypad"); } @@ -137,6 +143,7 @@ void prompt_visit() set_prompt_mode(PM_VISIT); prompt_set_msgl("Enter points:"); prompt_set_msgr(NULL); + dom_set_content("#key-submit", "OK"); dom_set_content("#key-rem", "REMAINING"); } @@ -160,11 +167,13 @@ void prompt_num_darts() void prompt_end_match() { scoreboard_set_player_active(-1); // sets all inactive + set_prompt_mode(PM_END_MATCH); prompt_set_msgl( state->mode == M_PVC && state->legs[1]->rem <= 0 ? "Bot wins. :(" : "You win! :)"); prompt_set_msgr(NULL); + dom_set_content("#key-submit", "END MATCH"); dom_set_content("#key-rem", "REMATCH"); } @@ -176,14 +185,111 @@ void prompt_select_mode() clear_player_info(pn); dom_set_content("#visits", NULL); + set_prompt_mode(PM_SELECT_MODE); + prompt_set_msgl("Select match mode:"); + prompt_set_msgr(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:"); +} + +void prompt_match_opts() +{ + set_prompt_mode(PM_MATCH_OPTS); + prompt_set_msgl("Match options:"); prompt_set_msgr(NULL); + + char buf[64]; + clear_list_opts(); + add_list_opt("Start match"); + sprintf(buf, "Starting points: %d", match_opts->start_pts); + add_list_opt(buf); + sprintf(buf, "Throws first: %s", + match_opts->throws_first == 1 ? + match_opts->p1_name : + match_opts->p2_name); + add_list_opt(buf); + flush_list_opts(); +} + +void prompt_match_opt_start_pts() +{ + set_prompt_mode(PM_MATCH_OPT_START_PTS); + prompt_set_msgl("Starting points:"); + prompt_set_msgr(NULL); + prompt_flush(); + + clear_list_opts(); + add_list_opt("301"); + add_list_opt("501"); + add_list_opt("701"); + add_list_opt("901"); + flush_list_opts(); +} + +static void match_opt_start_pts_submit(int val) +{ + if (val < 1 || val > list_optc) { + oi(); + return; + } + + if (val == 1) + match_opts->start_pts = 301; + else if (val == 2) + match_opts->start_pts = 501; + else if (val == 3) + match_opts->start_pts = 701; + else if (val == 4) + match_opts->start_pts = 901; + + prompt_match_opts(); + prompt_flush(); +} + +void prompt_match_opt_throws_first() +{ + set_prompt_mode(PM_MATCH_OPT_THROWS_FIRST); + prompt_set_msgl("Throws first:"); + prompt_set_msgr(NULL); + prompt_flush(); + + clear_list_opts(); + add_list_opt(match_opts->p1_name); + if (match_opts->p2_name) + add_list_opt(match_opts->p2_name); + flush_list_opts(); +} + +static void match_opt_throws_first_submit(int val) +{ + if (val < 1 || val > list_optc) { + oi(); + return; + } + + match_opts->throws_first = val; + + prompt_match_opts(); + prompt_flush(); +} + +static void match_opts_submit(int val) +{ + if (val < 1 || val > list_optc) { + oi(); + return; + } + + if (val == 1) + start_match(); + else if (val == 2) + prompt_match_opt_start_pts(); + else if (val == 3) + prompt_match_opt_throws_first(); } bool key_is_active(char *k) @@ -244,7 +350,12 @@ void prompt_handle_on_change() void prompt_handle_append(char *data) { - if (pm != PM_SELECT_MODE && pm != PM_VISIT && pm != PM_NUM_DARTS) + if (pm != PM_MATCH_OPTS && + pm != PM_MATCH_OPT_START_PTS && + pm != PM_MATCH_OPT_THROWS_FIRST && + pm != PM_SELECT_MODE && + pm != PM_VISIT && + pm != PM_NUM_DARTS) return; char *str = prompt_get(); @@ -292,7 +403,12 @@ void prompt_handle_submit() return; } - if (pm != PM_VISIT && pm != PM_NUM_DARTS && pm != PM_SELECT_MODE) + if (pm != PM_VISIT && + pm != PM_NUM_DARTS && + pm != PM_SELECT_MODE && + pm != PM_MATCH_OPTS && + pm != PM_MATCH_OPT_START_PTS && + pm != PM_MATCH_OPT_THROWS_FIRST) return; char *str = prompt_get(); @@ -303,7 +419,13 @@ void prompt_handle_submit() else if (pm == PM_NUM_DARTS) user_num_darts(atoi(str)); else if (pm == PM_SELECT_MODE) - start_match(atoi(str)); + match_mode_selected(atoi(str)); + else if (pm == PM_MATCH_OPTS) + match_opts_submit(atoi(str)); + else if (pm == PM_MATCH_OPT_START_PTS) + match_opt_start_pts_submit(atoi(str)); + else if (pm == PM_MATCH_OPT_THROWS_FIRST) + match_opt_throws_first_submit(atoi(str)); } free(str); @@ -313,7 +435,7 @@ void prompt_handle_rem() { if (pm == PM_END_MATCH) { if (key_is_active("rem")) - start_match(state->mode); + start_match(); toggle_key("rem"); return; } |