Skip to content

Commit

Permalink
COMMS: allow 'y' to trigger crYpto button
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen M. Cameron <[email protected]>
  • Loading branch information
smcameron committed Oct 21, 2023
1 parent 1f6ed0b commit da4e375
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
60 changes: 32 additions & 28 deletions snis_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -4680,6 +4680,28 @@ static void comms_computer_button_pressed(__attribute__((unused)) void *x);
static void comms_eject_button_pressed(__attribute__((unused)) void *x);
static void comms_help_button_pressed(__attribute__((unused)) void *x);
static void comms_about_button_pressed(__attribute__((unused)) void *x);
static void comms_cryptanalysis_button_pressed(__attribute__((unused)) void *x);

static int maybe_trigger_comms_button(void (*button_press_func)(__attribute__((unused)) void *x), int grab_focus)
{
if (displaymode != DISPLAYMODE_COMMS)
return 0;

if (snis_text_input_box_has_focus(comms_ui.comms_input))
return 0;

struct snis_entity *o = find_my_ship();
if (!o)
return 0;

if (o->tsd.ship.comms_crypto_mode)
return 0;

button_press_func(NULL);
if (grab_focus)
snis_text_input_box_set_focus(comms_ui.comms_input, 1);
return 1;
}

static int key_press_cb(SDL_Window *window, SDL_Keysym *keysym, int key_repeat)
{
Expand Down Expand Up @@ -4774,46 +4796,28 @@ static int key_press_cb(SDL_Window *window, SDL_Keysym *keysym, int key_repeat)
current_quit_selection = QUIT_SELECTION_CONTINUE;
break;
case key_comms_hail:
if (!snis_text_input_box_has_focus(comms_ui.comms_input)) {
comms_hail_button_pressed(NULL);
snis_text_input_box_set_focus(comms_ui.comms_input, 1);
}
(void) maybe_trigger_comms_button(comms_hail_button_pressed, 1);
break;
case key_comms_channel:
if (!snis_text_input_box_has_focus(comms_ui.comms_input)) {
comms_channel_button_pressed(NULL);
snis_text_input_box_set_focus(comms_ui.comms_input, 1);
}
(void) maybe_trigger_comms_button(comms_channel_button_pressed, 1);
break;
case key_comms_manifest:
if (!snis_text_input_box_has_focus(comms_ui.comms_input)) {
comms_manifest_button_pressed(NULL);
/* don't set focus for manifest because there are no params to type */
}
(void) maybe_trigger_comms_button(comms_manifest_button_pressed, 0);
break;
case key_comms_computer:
if (!snis_text_input_box_has_focus(comms_ui.comms_input)) {
comms_computer_button_pressed(NULL);
snis_text_input_box_set_focus(comms_ui.comms_input, 1);
}
(void) maybe_trigger_comms_button(comms_computer_button_pressed, 1);
break;
case key_comms_eject:
if (!snis_text_input_box_has_focus(comms_ui.comms_input)) {
comms_eject_button_pressed(NULL);
snis_text_input_box_set_focus(comms_ui.comms_input, 1);
}
(void) maybe_trigger_comms_button(comms_eject_button_pressed, 1);
break;
case key_comms_help:
if (!snis_text_input_box_has_focus(comms_ui.comms_input)) {
comms_help_button_pressed(NULL);
/* don't set focus for help because there are no params to type */
}
(void) maybe_trigger_comms_button(comms_help_button_pressed, 0);
break;
case key_comms_about:
if (!snis_text_input_box_has_focus(comms_ui.comms_input)) {
comms_about_button_pressed(NULL);
/* don't set focus for about because there are no params to type */
}
(void) maybe_trigger_comms_button(comms_about_button_pressed, 0);
break;
case key_comms_crypto:
(void) maybe_trigger_comms_button(comms_cryptanalysis_button_pressed, 0);
break;
case keytorpedo:
fire_torpedo_button_pressed(NULL);
Expand Down
2 changes: 2 additions & 0 deletions snis_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ char *keyactionstring[] = {
"key_comms_eject",
"key_comms_help",
"key_comms_about",
"key_comms_crypto",
};

#ifdef DEBUG_KEYMAP
Expand Down Expand Up @@ -431,6 +432,7 @@ void init_keymap(void)
mapkey(comms, SDLK_e, key_comms_eject);
mapkey(comms, SDLK_SLASH, key_comms_help); /* uppercase slash key is question mark */
mapkey(comms, SDLK_a, key_comms_about);
mapkey(comms, SDLK_y, key_comms_crypto);

#ifdef DEBUG_KEYMAP
print_keymap("keymap", keymap);
Expand Down
3 changes: 2 additions & 1 deletion snis_keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ enum keyaction {
key_comms_eject = 92,
key_comms_help = 93,
key_comms_about = 94,
#define NKEYSTATES 95
key_comms_crypto = 95,
#define NKEYSTATES 96
};

struct keyboard_state {
Expand Down

0 comments on commit da4e375

Please sign in to comment.