Browse Source

Add more menu improvements

- X button opens/closes menu
 - Wait for button release before resuming
master
Nathaniel Walizer 11 months ago
parent
commit
17956de7e4
2 changed files with 26 additions and 2 deletions
  1. +20
    -2
      src/menu.c
  2. +6
    -0
      src/sdl_input.c

+ 20
- 2
src/menu.c View File

@@ -33,6 +33,17 @@ static int wait_for_input(nes_Input_Reader* reader,
return status;
}

static int wait_for_input_quiet(nes_Input_Reader* reader,
nes_input* input) {
int status = 0;
while ( input_Result_Quit != status &&
input->controllers[0].buttons) {
time_sleep(US_PER_S / 60);
status = nes_input_update(reader, input);
}
return ( input_Result_Quit == status ?
input_Result_Quit : 0);
}

static int count_files(DIR* dir) {
int count = 0;
@@ -170,7 +181,8 @@ static int run_menu(menu_state* state, const file_list* files,
if (input_Result_Quit == special) {
status = special;

} else if (buttons & (1 << Button_B)) {
} else if ( input_Result_Menu == special ||
(buttons & (1 << Button_B))) {
status = input_Result_Cancel;

} else if (buttons & ( (1 << Button_A) |
@@ -277,10 +289,16 @@ int run_game_menu(menu_state* state, nes_Renderer* rend,
int status = run_menu(&menu, &options, 100,
rend, input, sys);

if (NULL != state) *state = menu;
if (input_Result_Menu == status) {
status = input_Result_Cancel;
}

if (0 == status) status = choices[menu.cursor];

wait_for_input_quiet(input, &sys->input);

if (NULL != state) *state = menu;

return status;
}



+ 6
- 0
src/sdl_input.c View File

@@ -68,6 +68,7 @@ static const int sdl_keycodes[nes_controller_num_buttons] = {
SDLK_RIGHT,
};

static const int sdl_menu_button = SDL_CONTROLLER_BUTTON_X;
static const int sdl_save_button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
static const int sdl_load_button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;

@@ -142,6 +143,11 @@ static int sdl_input_update(nes_Input_Reader* reader,
input->controllers[0].buttons &= ~mask;
}

} else if (sdl_menu_button == event.cbutton.button) {
if (SDL_CONTROLLERBUTTONDOWN == event.type) {
status = input_Result_Menu;
}

} else if (sdl_save_button == event.cbutton.button) {
if (SDL_CONTROLLERBUTTONDOWN == event.type) {
status = input_Result_Save;


Loading…
Cancel
Save