📄 manager.c
字号:
menu_add( _main, item_create_link ( "New Game", HINT_NEWGAME, game ) ); menu_add( _main, item_create_separator ( "" ) );#ifdef _1 menu_add( _main, item_create_link ( "Options", HINT_, options ) );#endif menu_add( _main, item_create_link ( "Controls", HINT_CTRLS, cont ) ); menu_add( _main, item_create_link ( "Graphics", HINT_GFX, gfx ) );#ifdef SOUND menu_add( _main, item_create_link ( "Audio", HINT_AUDIO, audio ) );#else menu_add( _main, item_create_separator ( "Audio" ) );#endif menu_add( _main, item_create_separator ( "" ) ); menu_add( _main, item_create_link ( "Advanced Options", HINT_ADV, adv ) ); menu_add( _main, item_create_separator ( "" ) ); menu_add( _main, item_create_action ( "Quit", HINT_QUIT, ACTION_QUIT ) );#ifdef _1 /* options */ menu_add( options, item_create_link( "Controls", HINT_, cont ) ); menu_add( options, item_create_link( "Graphics", HINT_, gfx ) ); menu_add( options, item_create_link( "Audio", HINT_, audio ) ); menu_add( options, item_create_separator( "Audio" ) ); menu_add( options, item_create_separator( "" ) ); menu_add( options, item_create_link( "Back", _main ) );#endif /* audio */#ifdef SOUND item = item_create_switch( "Sound:", HINT_, &config.sound, "Off", "On" ); item->callback = cb_sound; menu_add( audio, item ); item = item_create_range( "Volume:", HINT_, &config.volume, 1, 8, 1 ); item->callback = cb_volume; menu_add( audio, item ); menu_add( audio, item_create_separator( "" ) ); menu_add( audio, item_create_link( "Back", HINT_, _main ) );#endif /* gfx */ menu_add( gfx, item_create_switch( "Animations:", HINT_ANIM, &config.anim, "Off", "On" ) ); menu_add( gfx, item_create_switch( "Move:", HINT_SMOOTHHORI, &config.smooth_hori, "Tile By Tile", "Smooth" ) ); menu_add( gfx, item_create_switch( "Drop:", HINT_SMOOTHVERT, &config.block_by_block, "Smooth", "Tile By Tile" ) ); menu_add( gfx, item_create_switch( "Change Background:", HINT_BKGND, &config.keep_bkgnd, "Yes", "No" ) ); menu_add( gfx, item_create_separator( "" ) ); item = item_create_switch( "Display:", HINT_DISPLAY, &config.fullscreen, "Window", "Fullscreen" ); item->callback = cb_fullscreen; menu_add( gfx, item ); menu_add( gfx, item_create_switch_x( "Frame Rate:", HINT_FPS, &config.fps, str_fps, 4 ) ); menu_add( gfx, item_create_separator( "" ) ); menu_add( gfx, item_create_link( "Back", HINT_, _main ) ); /* game */ menu_add( game, item_create_action( "Start Game", HINT_START, ACTION_PLAY ) ); menu_add( game, item_create_separator( "" ) ); menu_add( game, item_create_edit( "1st Player:", HINT_NAME, config.player1.name, 12 ) ); menu_add( game, item_create_edit( "2nd Player:", HINT_NAME, config.player2.name, 12 ) ); menu_add( game, item_create_edit( "3rd Player:", HINT_NAME, config.player3.name, 12 ) ); menu_add( game, item_create_separator( "" ) ); menu_add( game, item_create_switch_x( "Game:", HINT_GAME, &config.gametype, gametype_names, 8 ) ); menu_add( game, item_create_range( "Starting Level:", HINT_STARTLEVEL, &config.starting_level, 0, 9, 1 ) ); menu_add( game, item_create_switch( "Preview:", HINT_PREVIEW, &config.preview, "Off", "On" ) ); menu_add( game, item_create_switch_x( "Help:", HINT_HELP, &config.help, str_help, 3 ) ); menu_add( game, item_create_switch( "Expert Mode:", HINT_EXPERT, &config.expert, "Off", "On" ) );#ifdef _1 menu_add( game, item_create_switch( "Slow:", HINT_, &config.slow, "Off", "On" ) );#endif //menu_add( game, item_create_separator( "" ) ); menu_add( game, item_create_link( "Multiplayer Options", HINT_MPMENU, twoplayer ) ); menu_add( game, item_create_separator( "" ) ); menu_add( game, item_create_link( "Back", HINT_, _main ) ); /* twoplayer options */ menu_add( twoplayer, item_create_switch( "Same Blocks For All:", HINT_SAME, &config.same_blocks_for_all, "Off", "On" ) ); menu_add( twoplayer, item_create_separator( "" ) ); menu_add( twoplayer, item_create_range( "Holes:", HINT_HOLES, &config.holes, 1, 9, 1 ) ); menu_add( twoplayer, item_create_switch( "Send All Lines:", HINT_SENDALL, &config.send_all, "Off", "On" ) ); menu_add( twoplayer, item_create_switch( "Always Send Tetris:", HINT_SENDTETRIS, &config.send_tetris, "Off", "On" ) ); menu_add( twoplayer, item_create_separator( "" ) ); menu_add( twoplayer, item_create_switch_x( "CPU Style:", HINT_CPUAGGR, &config.cpu_aggr, str_cpu_aggr, 4 ) ); menu_add( twoplayer, item_create_range( "CPU Drop Delay:", HINT_CPUDROP, &config.cpu_delay, 0, 2000, 100 ) ); menu_add( twoplayer, item_create_separator( "" ) ); menu_add( twoplayer, item_create_link( "Back", HINT_, game ) ); /* controls */ menu_add( cont, item_create_link( "Player1", HINT_CONTROLS, cont_player1 ) ); menu_add( cont, item_create_link( "Player2", HINT_CONTROLS, cont_player2 ) ); menu_add( cont, item_create_link( "Player3", HINT_CONTROLS, cont_player3 ) ); menu_add( cont, item_create_separator( "" ) ); menu_add( cont, item_create_range( "Horizontal Delay:", HINT_HORIDEL,&config.hori_delay, 0, 5, 1 ) ); menu_add( cont, item_create_separator( "" ) ); menu_add( cont, item_create_link( "Back", HINT_, _main ) ); /* all keys used */ keys[0][0] = item_create_key( "Left:", HINT_CONTROLS, &config.player1.controls.left, filter ); keys[0][1] = item_create_key( "Right:", HINT_CONTROLS, &config.player1.controls.right, filter ); keys[0][2] = item_create_key( "Rotate Left:", HINT_CONTROLS, &config.player1.controls.rot_left, filter ); keys[0][3] = item_create_key( "Rotate Right:", HINT_CONTROLS, &config.player1.controls.rot_right, filter ); keys[0][4] = item_create_key( "Down:", HINT_CONTROLS, &config.player1.controls.down, filter ); keys[0][5] = item_create_key( "Drop:", HINT_CONTROLS, &config.player1.controls.drop, filter ); keys[1][0] = item_create_key( "Left:", HINT_CONTROLS, &config.player2.controls.left, filter ); keys[1][1] = item_create_key( "Right:", HINT_CONTROLS, &config.player2.controls.right, filter ); keys[1][2] = item_create_key( "Rotate Left:", HINT_CONTROLS, &config.player2.controls.rot_left, filter ); keys[1][3] = item_create_key( "Rotate Right:", HINT_CONTROLS, &config.player2.controls.rot_right, filter ); keys[1][4] = item_create_key( "Down:", HINT_CONTROLS, &config.player2.controls.down, filter ); keys[1][5] = item_create_key( "Drop:", HINT_CONTROLS, &config.player2.controls.drop, filter ); keys[2][0] = item_create_key( "Left:", HINT_CONTROLS, &config.player3.controls.left, filter ); keys[2][1] = item_create_key( "Right:", HINT_CONTROLS, &config.player3.controls.right, filter ); keys[2][2] = item_create_key( "Rotate Left:", HINT_CONTROLS, &config.player3.controls.rot_left, filter ); keys[2][3] = item_create_key( "Rotate Right:", HINT_CONTROLS, &config.player3.controls.rot_right, filter ); keys[2][4] = item_create_key( "Down:", HINT_CONTROLS, &config.player3.controls.down, filter ); keys[2][5] = item_create_key( "Drop:", HINT_CONTROLS, &config.player3.controls.drop, filter ); /* for each key all others are restricted */ for ( k = 0; k < 3; k++ ) for ( l = 0; l < 6; l++ ) { /* restrict all other keys for key( k, l ) */ for ( i = 0; i < 3; i++ ) for ( j = 0; j < 6; j++ ) if ( k != i || l != j ) value_add_other_key( keys[k][l]->value, keys[i][j]->value ); } /* controls player 1 */ for ( k = 0; k < 6; k++ ) menu_add( cont_player1, keys[0][k] ); menu_add( cont_player1, item_create_separator( "" ) ); menu_add( cont_player1, item_create_link( "Back", HINT_,cont ) ); /* controls player 2 */ for ( k = 0; k < 6; k++ ) menu_add( cont_player2, keys[1][k] ); menu_add( cont_player2, item_create_separator( "" ) ); menu_add( cont_player2, item_create_link( "Back", HINT_, cont ) ); /* controls player 3 */ for ( k = 0; k < 6; k++ ) menu_add( cont_player3, keys[2][k] ); menu_add( cont_player3, item_create_separator( "" ) ); menu_add( cont_player3, item_create_link( "Back", HINT_, cont ) ); /* advanced options */ item = item_create_switch ( "Quick Help:", HINT_QHELP, &config.quick_help, "Off", "On" ); item->callback = cb_hints; menu_add( adv, item ); menu_add( adv, item_create_switch ( "Clear Keystate:", HINT_KEYSTATE, &config.clear_keystate, "Off", "On" ) ); menu_add( adv, item_create_switch ( "Center Preview:", HINT_CENTERPREVIEW, &config.center_preview, "Off", "On" ) ); menu_add( adv, item_create_switch ( "Collision Check:", HINT_COL_CHECK, &config.async_col_check, "Sync", "Async" ) );#ifdef DEVELOPMENT menu_add( adv, item_create_separator( "" ) ); menu_add( adv, item_create_action( "Test CPU Algorithm", HINT_CPUALG, ACTION_MAKE_STAT ) ); menu_add( adv, item_create_switch( "Visualization", HINT_VIS, &config.visualize, "Off", "On" ) );#endif menu_add( adv, item_create_separator( "" ) ); menu_add( adv, item_create_link( "Back", HINT_, _main ) ); /* adjust all menus */ menu_adjust( _main );#ifdef _1 menu_adjust( options );#endif menu_adjust( adv );#ifdef SOUND menu_adjust( audio );#endif menu_adjust( gfx ); menu_adjust( game ); menu_adjust( cont ); menu_adjust( cont_player1 ); menu_adjust( cont_player2 ); menu_adjust( cont_player3 ); menu_adjust( twoplayer ); /* set main menu as current */ menu_select( game );}void manager_delete(){ list_delete( menus ); free_surf( &mbkgnd ); free_font( &mfont ); free_font( &mhfont ); free_font( &mcfont );#ifdef SOUND if ( wav_menu_click ) sound_chunk_free( wav_menu_click ); wav_menu_click = 0; if ( wav_menu_motion ) sound_chunk_free( wav_menu_motion ); wav_menu_motion = 0;#endif}/*====================================================================Run menu until request sent====================================================================*/int manager_run(){ SDL_Event event; int event_polled = 0; /* event occured? */ int result = ACTION_NONE; int ms; /* draw highscores */ chart_show( chart_set_query_id( chart_id ), cx, cy, cw, ch ); /* loop */ reset_timer(); while ( result == ACTION_NONE && !term_game ) { if ( event_poll( &event ) ) event_polled = 1; if ( event_polled && event.type == SDL_QUIT ) { result = ACTION_QUIT; term_game = 1; } /* fullscreen if no item selected */ if ( event_polled ) { if ( cur_menu->cur_item == 0 || ( cur_menu->cur_item->type != ITEM_EDIT && cur_menu->cur_item->type != ITEM_KEY ) ) if ( event.type == SDL_KEYUP ) if ( event.key.keysym.sym == SDLK_f ) { config.fullscreen = !config.fullscreen; set_video_mode( std_video_mode( config.fullscreen ) ); FULL_DEST( sdl.screen ); FULL_SOURCE( mbkgnd ); blit_surf(); chart_show( chart_set_query_id( chart_id ), cx, cy, cw, ch ); refresh_screen( 0, 0 ,0, 0 ); } /* check if clicked on highscore */ if ( event.type == SDL_MOUSEBUTTONUP ) if ( event.button.x >= cx && event.button.y >= cy ) if ( event.button.x < cx + cw && event.button.y < cy + ch ) {#ifdef SOUND sound_play( wav_menu_click );#endif /* set chart id */ if ( event.button.button == LEFT_BUTTON ) { chart_id++; if ( chart_id == charts->count ) chart_id = 0; } else { chart_id--; if ( chart_id == -1 ) chart_id = charts->count - 1; } /* redraw */ FULL_DEST( sdl.screen ); FULL_SOURCE( mbkgnd ); blit_surf(); chart_show( chart_set_query_id( chart_id ), cx, cy, cw, ch ); refresh_screen( cx, cy, cw, ch ); } } ms = get_time(); menu_hide( cur_menu ); hint_hide(); if ( event_polled ) result = menu_update( cur_menu, &event, ms ); else result = menu_update( cur_menu, 0, ms ); hint_update( ms ); menu_show( cur_menu ); chart_show( chart_set_query_id( chart_id ), cx, cy, cw, ch ); hint_show(); refresh_rects(); event_polled = 0; SDL_Delay( 5 ); } return result;}/*====================================================================Fade in/out background of menu====================================================================*/void manager_fade( int type ){ if ( type == FADE_IN ) { FULL_DEST( sdl.screen ); FULL_SOURCE( mbkgnd ); blit_surf(); } fade_screen( type, FADE_DEF_TIME );}/*====================================================================Update screen without menu itself as this is shown next frame.====================================================================*/void manager_show(){ set_video_mode( std_video_mode( config.fullscreen ) ); FULL_DEST( sdl.screen ); FULL_SOURCE( mbkgnd ); blit_surf(); chart_show( chart_set_query_id( chart_id ), cx, cy, cw, ch ); add_refresh_rect( 0, 0, sdl.screen->w, sdl.screen->h );}/*====================================================================Update set list when creating a new file for editor.====================================================================*/void manager_update_set_list(){#ifdef _1 cb_adjust_set_list(); /* hacky but shiiiit how cares? */#endif }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -