int launcher(){; char *rom = 0; char *dir = rc_getstr("romdir"); char version_str[80]; snprintf(version_str, sizeof(version_str)-1, "gnuboy %s", VERSION); gui_begin(); launcher: dialog_begin("OhBoy http://ohboy.googlecode.com/", version_str); dialog_text("Load ROM",NULL,FIELD_SELECTABLE); dialog_text("Options",NULL,FIELD_SELECTABLE); dialog_text("Controls",NULL,FIELD_SELECTABLE); dialog_text("About",NULL,FIELD_SELECTABLE); dialog_text("Quit","",FIELD_SELECTABLE); #ifdef DINGOO_NATIVE dialog_text(NULL, NULL, 0); /* blank line */ dialog_text("Menu:", NULL, 0); dialog_text(" Slide Power", NULL, 0); #endif /* DINGOO_NATIVE */ switch(dialog_end()){ case 1: rom = menu_requestfile(NULL,"Select Rom",dir,"gb;gbc;zip"); if(!rom) goto launcher; break; case 2: if(!menu_options()) goto launcher; break; case 3: if(!menu_controls()) goto launcher; break; case 4: if(!menu_about()) goto launcher; break; case 5: SDL_QuitSubSystem(SDL_INIT_EVERYTHING); SDL_Quit(); exit(0); default: goto launcher; } gui_end(); return rom; }
/** * @brief Opens the menu options from a button. */ static void menu_options_button( unsigned int wid, char *str ) { (void) wid; (void) str; menu_options(); }
int8_t rockpush_menu(Rock_Screen *screen_data) { SDL_Event event; SDL_Surface *menu; SDL_Surface *sprite_textures; SDL_Texture *font_surface; Rock_Sprite *rocco; Rock_Scroll_Map map; Mix_Music *music; TTF_Font *menu_font; bool done = false; Uint32 init_ms; char font_path[128]; int16_t offset; int8_t orientation, total_options, option; Sint32 event_option; SDL_Joystick *joystick = NULL; Sint16 joy_event = 0, joyy = 0; if (SDL_NumJoysticks() >= 1) { joystick = SDL_JoystickOpen(0); SDL_JoystickEventState(SDL_ENABLE); } if ((menu_font = TTF_OpenFont(MENU_TTF, 34)) == NULL) { printf("Error %s\n", TTF_GetError()); exit(EXIT_FAILURE); } gfx_check_gpu(screen_data->screen); if (gfx_get_low_gpu()) sprintf(font_path, "%s", TINY_FONT_PATH); else sprintf(font_path, "%s", FONT_PATH); if ((font_surface = IMG_LoadTexture(screen_data->screen, font_path)) == NULL) { printf("La fuente bitmap no encontrada %s\n", SDL_GetError()); exit(EXIT_FAILURE); } menu = screen_make_surface(SCREEN_WIDTH, SCREEN_HEIGHT); sprite_textures = screen_make_surface(screen_data->sprites_surface->w, screen_data->sprites_surface->h); map.view_height = MINI_HEIGHT * TILE_SIZE; map.view_width = MINI_WIDTH * TILE_SIZE; map.scroll_shift = SCROLL_SHIFT / 2; map.diamonds = 0; map.level = (rand() % 15); map.points = 0; map.lives = INIT_ROCCO_LIVE; map.update_score = false; map.refresh_rocco = false; rocco = set_level_rocco(&map); rocco->active = false; map.objects_map[rocco->x_map][rocco->y_map] = EMPTY; map.rockmap[rocco->x_map][rocco->y_map] = GRASS; sprites_set_tiles_textures(); //Se hace una copia de las texturas cargadas para convertirlas a B/N SDL_BlitSurface(screen_data->sprites_surface, NULL, sprite_textures, NULL); screen_greyscale(screen_data->sprites_surface); orientation = (rand() % 4) + 2; option = offset = 0; total_options = menu_options(option, map.view_width, menu, menu_font); gfx_init(); screen_data->blit_surface = true; SDL_SetRenderDrawColor(screen_data->screen, 0, 0, 0, 255); SDL_RenderClear(screen_data->screen); if (sfx_get_active()) { music = Mix_LoadMUS(MENU_MUSIC); Mix_PlayMusic(music, -1); } while (!done) { init_ms = SDL_GetTicks(); map_show(screen_data, &map, false); map_move(&map, orientation); SDL_BlitSurface(menu, NULL, screen_data->buffer_surface, NULL); //sprites_update(&map); screen_dump_buffer(screen_data, map.view_width, map.view_height); offset ++; if (offset > 240) { orientation = (rand() % 4) + 2; offset = 0; } /* Desplazamiento de texto */ gfx_text_move(screen_data->screen, font_surface); while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { option = 0; done = true; } if (SDL_JoystickGetAttached(joystick)) joy_event = SDL_JoystickGetAxis(joystick, 0) | SDL_JoystickGetAxis(joystick, 1); if (event.type == SDL_KEYDOWN || event.type == SDL_JOYBUTTONDOWN || joy_event) { event_option = event.key.keysym.sym; if (SDL_JoystickGetAttached(joystick)) { joyy = SDL_JoystickGetAxis(joystick, 1); joy_event = SDL_JoystickGetAxis(joystick, 0) | joyy; if (SDL_JoystickGetButton(joystick, 0)) event_option = SDLK_ESCAPE; if (SDL_JoystickGetButton(joystick, 1)) event_option = SDLK_RETURN; if (joyy < -10) event_option = SDLK_UP; if (joyy > 10) event_option = SDLK_DOWN; } switch (event_option) { case SDLK_UP: if (option > 0) option --; break; case SDLK_DOWN: if (option < total_options) option ++; break; case SDLK_ESCAPE: option = -1; case SDLK_RETURN: done = true; option ++; break; } menu_options(option, map.view_width, menu, menu_font); } } while ((SDL_GetTicks() - init_ms) < TICK_RATE); } //Restauramos la copia SDL_BlitSurface(sprite_textures, NULL, screen_data->sprites_surface, NULL); SDL_SetRenderDrawColor(screen_data->screen, 0, 0, 0, 255); SDL_RenderClear(screen_data->screen); screen_data->blit_surface = false; SDL_FreeSurface(sprite_textures); SDL_DestroyTexture(font_surface); SDL_FreeSurface(menu); TTF_CloseFont(menu_font); if (SDL_JoystickGetAttached(joystick)) SDL_JoystickClose(joystick); if (sfx_get_active()) { Mix_FadeOutMusic(SFX_FADE_OUT); while (Mix_PlayingMusic()) ; Mix_FreeMusic(music); } return option; }
int menu(){ char *dir; int mexit=0; static char *loadrom; int old_upscale = 0, new_upscale = 0; old_upscale = rc_getint("upscaler"); gui_begin(); while(!mexit){ dialog_begin(rom.name,"ohBoy"); dialog_text("Back to Game",NULL,FIELD_SELECTABLE); dialog_text("Load State",NULL,FIELD_SELECTABLE); dialog_text("Save State",NULL,FIELD_SELECTABLE); dialog_text("Reset Game",NULL,FIELD_SELECTABLE); dialog_text(NULL,NULL,0); dialog_text("Load ROM",NULL,FIELD_SELECTABLE); dialog_text("Options",NULL,FIELD_SELECTABLE); dialog_text("Controls",NULL,FIELD_SELECTABLE); dialog_text("About",NULL,FIELD_SELECTABLE); dialog_text("Quit","",FIELD_SELECTABLE); #ifdef DINGOO_NATIVE dialog_text(NULL, NULL, 0); /* blank line */ dialog_text("Menu:", NULL, 0); dialog_text(" Slide Power", NULL, 0); #endif /* DINGOO_NATIVE */ switch(dialog_end()){ case 2: if(menu_state(0)) mexit=1; break; case 3: if(menu_state(1)) mexit=1; break; case 4: rc_command("reset"); mexit=1; break; case 6: dir = rc_getstr("romdir"); if(loadrom = menu_requestfile(NULL,"Select Rom",dir,"gb;gbc;zip")) { loader_unload(); ohb_loadrom(loadrom); mexit=1; } break; case 7: if(menu_options()) mexit=1; break; case 8: if(menu_controls()) mexit=1; break; case 9: if(menu_about()) mexit=0; break; case 10: exit(0); break; default: mexit=1; break; } } new_upscale = rc_getint("upscaler"); if (old_upscale != new_upscale) scaler_init(new_upscale); gui_end(); return 0; }