-#include "shaders/menu.h"
-#include "vg_steam_friends.h"
-#include "submodules/tinydir/tinydir.h"
-
-VG_STATIC mdl_context menu_model;
-VG_STATIC glmesh menu_glmesh;
-VG_STATIC m4x3f menu_mdl_mtx;
-VG_STATIC float menu_opacity = 0.0f;
-VG_STATIC float menu_input_cooldown = 0.0f;
-VG_STATIC float menu_fov_target = 97.0f;
-VG_STATIC v2f menu_extra_angles;
-
-VG_STATIC int cl_menu = 0,
- cl_menu_go_away = 0;
-
-VG_STATIC int menu_enabled(void){ return cl_menu; }
-
-VG_STATIC const char *playermodels[] = { "ch_new", "ch_jordan", "ch_outlaw" };
-
-vg_tex2d tex_menu = { .path = "textures/menu.qoi",.flags = VG_TEXTURE_NEAREST };
-
-VG_STATIC struct input_binding input_menu_h,
- input_menu_v,
- input_menu_press,
- input_menu_back,
- input_menu_toggle,
- input_menu_toggle_kbm;
-
-VG_STATIC void menu_btn_quit( int event );
-VG_STATIC void menu_btn_skater( int event );
-VG_STATIC void menu_btn_blur( int event );
-VG_STATIC void menu_btn_fuckoff( int event );
-VG_STATIC void menu_btn_reset( int event );
-VG_STATIC void menu_btn_map( int event );
-VG_STATIC void menu_btn_settings( int event );
-
-VG_STATIC mdl_node *menu_pnode_fov_slider,
- *menu_pnode_fov_min,
- *menu_pnode_fov_max,
- *menu_pnode_vol_slider,
- *menu_pnode_vol_min,
- *menu_pnode_vol_max;
-
-struct
-{
- /* state */
- int loc;
- u32 page;
-
- /* map browser */
- struct menu_map_file
- {
- char name[ 64 ];
- }
- maps_list[ 16 ];
-
- int selected_map,
- map_count;
-}
-VG_STATIC game_menu;
-
-enum menu_page
-{
- k_menu_page_main = 0x1,
- k_menu_page_skater = 0x2,
- k_menu_page_quit = 0x4,
- k_menu_page_settings = 0x8,
- k_menu_page_map = 0x10
-};
-
-struct menu_btn_userdata
-{
- union
- {
- int i;
- void *ptr_generic;
- };
-};
-
-VG_STATIC int menu_settings_if( struct menu_btn_userdata ud )
-{
- if( game_menu.page & k_menu_page_settings )
- {
- int *ptr = ud.ptr_generic;
- return *ptr;
- }
- else
- return 0;
-}
-
-VG_STATIC int menu_vis( struct menu_btn_userdata ud )
-{
- if( ud.i & game_menu.page )
- return 1;
- else
- return 0;
-}
-
-VG_STATIC int menu_controller( struct menu_btn_userdata ud )
-{
- if( (game_menu.page & (k_menu_page_main|k_menu_page_settings))
- && (ud.i == menu_display_controller) )
- return 1;
- return 0;
-}
-
-VG_STATIC int menu_controller_inf( struct menu_btn_userdata ud )
-{
- if( (game_menu.page & k_menu_page_settings)
- && (ud.i == menu_display_controller) )
- return 1;
- return 0;
-}
-
-struct menu_button
-{
- const char *name;
-
- int (*fn_visibility)( struct menu_btn_userdata ud );
- struct menu_btn_userdata user;
-
- void (*fn_press)( int event );
-
- const char *ll,
- *lu,
- *lr,
- *ld;
-
- mdl_node *pnode;
- float falpha, fsize;
-}
-VG_STATIC menu_buttons[] =
-{
-{
- "text_quit", menu_vis, {.i=k_menu_page_main|k_menu_page_quit},
- .fn_press = menu_btn_quit,
- .ld="text_reset", .lr="text_settings", .ll="text_map"
-},
- {
- "text_quitty", menu_vis, {.i=k_menu_page_quit}
- },
- {
- "text_yes", menu_vis, {.i=k_menu_page_quit},
- .fn_press = menu_btn_fuckoff
- },
-{
- "text_reset", menu_vis, {.i=k_menu_page_main},
- .fn_press = menu_btn_reset,
- .lu="text_quit", .ld="text_skater", .ll="text_map", .lr="text_settings"
-},
-{
- "text_skater", menu_vis, {.i=k_menu_page_main|k_menu_page_skater},
- .fn_press = menu_btn_skater,
- .lu="text_reset", .ll="text_map", .lr="text_settings"
-},
-{
- "text_map", menu_vis, {.i=k_menu_page_main},
- .fn_press = menu_btn_map,
- .lr="text_reset"
-},
-{
- "text_settings", menu_vis, {.i=k_menu_page_main|k_menu_page_settings},
- .fn_press = menu_btn_settings,
- .ll="text_reset"
-},
-{
- "skater_left", menu_vis, {k_menu_page_skater}
-},
-{
- "skater_right", menu_vis, {k_menu_page_skater}
-},
-
-{
- "fov_slider", menu_vis, {k_menu_page_settings},
- .ld="text_blur"
-},
-{ "fov_info", menu_vis, {k_menu_page_settings} },
-
-{
- "vol_slider", menu_vis, {k_menu_page_settings},
- .lu="text_blur"
-},
-{ "vol_info", menu_vis, {k_menu_page_settings} },
-
-{
- "text_blur", menu_vis, {k_menu_page_settings},
- .fn_press = menu_btn_blur,
- .lu="fov_slider", .ld="vol_slider"
-},
-{
- "text_blur_check", menu_settings_if, {.ptr_generic=&cl_blur}
-},
-
-{ "ctr_xbox", menu_controller_inf, {k_menu_controller_type_xbox}},
-{ "ctr_xbox_text", menu_controller_inf, {k_menu_controller_type_xbox}},
-{ "ctr_steam", menu_controller_inf, {k_menu_controller_type_steam}},
-{ "ctr_steam_text", menu_controller_inf, {k_menu_controller_type_steam}},
-{ "ctr_deck", menu_controller_inf, {k_menu_controller_type_steam_deck}},
-{ "ctr_deck_text", menu_controller_inf, {k_menu_controller_type_steam_deck}},
-{ "ctr_ps", menu_controller_inf, {k_menu_controller_type_playstation}},
-{ "ctr_ps_text", menu_controller_inf, {k_menu_controller_type_playstation}},
-{ "ctr_kbm", menu_controller_inf, {k_menu_controller_type_keyboard}},
-{ "ctr_kbm_text", menu_controller_inf, {k_menu_controller_type_keyboard}},
-{
- "text_paused", menu_vis, {k_menu_page_main}
-},
-};
-
-VG_STATIC int menu_get_loc( const char *loc )
-{
- for( int i=0; i<vg_list_size(menu_buttons); i++ )
- if( !strcmp( menu_buttons[i].name, loc ) )
- return i;
-
- assert(0);
- return 0;
-}
-
-VG_STATIC void menu_btn_reset( int event )
-{
- reset_player(0,NULL);
- world_routes_clear();
-
- cl_menu_go_away = 1;
- game_menu.page = 0;
-}
-
-VG_STATIC void menu_btn_fuckoff( int event )
-{
- vg.window_should_close = 1;
-}
-
-VG_STATIC void menu_btn_quit( int event )
-{
- game_menu.page = k_menu_page_quit;
- game_menu.loc = menu_get_loc( "text_yes" );
-}
-
-VG_STATIC void menu_btn_settings( int event )
-{
- game_menu.page = k_menu_page_settings;
- game_menu.loc = menu_get_loc( "fov_slider" );
-}
-
-VG_STATIC void menu_btn_skater( int event )
-{
- game_menu.page = k_menu_page_skater;
-}
-
-VG_STATIC void menu_btn_blur( int event )
-{
- cl_blur ^= 0x1;
-}
-
-VG_STATIC void menu_btn_map( int event )
-{
- game_menu.page = k_menu_page_map;
- game_menu.map_count = 0;
- game_menu.selected_map = 0;
-
- tinydir_dir dir;
- tinydir_open( &dir, "maps" );
-
- while( dir.has_next )
- {
- tinydir_file file;
- tinydir_readfile( &dir, &file );
-
- if( file.is_reg )
- {
- struct menu_map_file *mf = &game_menu.maps_list[ game_menu.map_count ];
-
- vg_strncpy( file.name, mf->name,
- vg_list_size(game_menu.maps_list[0].name)-1 );
-
- game_menu.map_count ++;
- if( game_menu.map_count == vg_list_size(game_menu.maps_list) )
- break;
- }
-
- tinydir_next( &dir );
- }
-
- tinydir_close(&dir);
-}
-
-VG_STATIC void menu_crap_ui(void)
-{
- if( cl_menu && (game_menu.page == k_menu_page_map) )
- {
- ui_rect box;
- box[0] = vg.window_x/2 - 150;
- box[1] = vg.window_y/2 - 300;
- box[2] = 300;
- box[3] = 600;
-
- ui_fill_rect( box, 0xa0000000 );
-
- if( game_menu.map_count == 0 )
- {
- ui_text( (ui_rect){ vg.window_x/2, box[1]+8, 0,0 }, "No maps found", 1,
- k_text_align_center );
- }
- else
- {
- ui_rect_pad( box, 4 );
- box[3] = 16;
-
- for( int i=0; i<game_menu.map_count; i++ )
- {
- struct menu_map_file *mf = &game_menu.maps_list[ i ];
-
- ui_fill_rect( box, game_menu.selected_map == i? 0xa0ffffff:
- 0xa0808080 );
- ui_text( (ui_rect){ vg.window_x/2, box[1]+2, 0,0 },
- mf->name, 1, k_text_align_center );
- box[1] += 16+4;
- }
- }
- }
-}
-
-VG_STATIC void steam_on_game_overlay( CallbackMsg_t *msg )
-{
- GameOverlayActivated_t *inf = (GameOverlayActivated_t *)msg->m_pubParam;
- vg_info( "Steam game overlay activated; pausing\n" );
-
- if( inf->m_bActive )
- {
- cl_menu = 1;
- game_menu.page = k_menu_page_main;
- game_menu.loc = menu_get_loc( "text_skater" );
- }
-}
-
-VG_STATIC void menu_init(void)
-{
- vg_create_unnamed_input( &input_menu_h, k_input_type_axis );
- vg_create_unnamed_input( &input_menu_v, k_input_type_axis );
- vg_create_unnamed_input( &input_menu_back, k_input_type_button );
- vg_create_unnamed_input( &input_menu_press, k_input_type_button );
- vg_create_unnamed_input( &input_menu_toggle, k_input_type_button );
- vg_create_unnamed_input( &input_menu_toggle_kbm, k_input_type_button );
-
- vg_apply_bind_str( &input_menu_h, "", "gp-ls-h" );
- vg_apply_bind_str( &input_menu_h, "+", "right" );
- vg_apply_bind_str( &input_menu_h, "-", "left" );
- vg_apply_bind_str( &input_menu_v, "", "-gp-ls-v" );
- vg_apply_bind_str( &input_menu_v, "+", "up" );
- vg_apply_bind_str( &input_menu_v, "-", "down" );
- vg_apply_bind_str( &input_menu_press, "", "gp-a" );
- vg_apply_bind_str( &input_menu_press, "", "\2enter" );
- vg_apply_bind_str( &input_menu_back, "", "gp-b" );
- vg_apply_bind_str( &input_menu_back, "", "\2escape" );
- vg_apply_bind_str( &input_menu_toggle_kbm, "", "\2escape" );
- vg_apply_bind_str( &input_menu_toggle, "", "\2gp-menu" );
-
- vg_linear_clear( vg_mem.scratch );
-
- mdl_open( &menu_model, "models/rs_menu.mdl" );
- mdl_load_metadata( &menu_model, vg_mem.rtmemory );
- mdl_load_mesh_data( &menu_model, vg_mem.scratch );
- mdl_invert_uv_coordinates( &menu_model );
- mdl_close( &menu_model );
-
- vg_acquire_thread_sync();
- {
- mdl_unpack_glmesh( &menu_model, &menu_glmesh );
- vg_tex2d_init( (vg_tex2d *[]){ &tex_menu }, 1 );
- }
- vg_release_thread_sync();
-
- for( int i=0; i<vg_list_size(menu_buttons); i++ )
- {
- struct menu_button *btn = &menu_buttons[i];
- btn->pnode = mdl_node_from_name( &menu_model, btn->name );
-
- if( !btn->pnode )
- {
- vg_info( "info: %s\n", btn->name );
- vg_fatal_exit_loop( "Menu programming error" );
- }
- }
-
- menu_pnode_fov_max = mdl_node_from_name( &menu_model, "fov_slider_max" );
- menu_pnode_fov_min = mdl_node_from_name( &menu_model, "fov_slider_min" );
- menu_pnode_fov_slider = mdl_node_from_name( &menu_model, "fov_slider" );
- menu_pnode_vol_max = mdl_node_from_name( &menu_model, "vol_slider_max" );
- menu_pnode_vol_min = mdl_node_from_name( &menu_model, "vol_slider_min" );
- menu_pnode_vol_slider = mdl_node_from_name( &menu_model, "vol_slider" );
-
- shader_menu_register();
-
-#ifdef SR_NETWORKED
- steam_register_callback( k_iGameOverlayActivated, steam_on_game_overlay );
-#endif
-}
-
-VG_STATIC void menu_run_directional(void)
-{
- struct menu_button *btn = &menu_buttons[ game_menu.loc ];
-
- if( vg_input_button_down( &input_menu_press ) )
- {
- if( btn->fn_press )
- {
- audio_lock();
- audio_play_oneshot( &audio_ui[0], 1.0f );
- audio_unlock();
-
- btn->fn_press( 1 );
- return;
- }
- }
-
- if( menu_input_cooldown <= 0.0f )
- {
- v2f dir = { input_menu_h.axis.value,
- -input_menu_v.axis.value };
-
- if( v2_length2( dir ) > 0.8f*0.8f )
- {
- const char *link = NULL;
-
- if( fabsf(dir[0]) > fabsf(dir[1]) )
- {
- if( dir[0] > 0.0f ) link = btn->lr;
- else link = btn->ll;
- }
- else
- {
- if( dir[1] > 0.0f ) link = btn->ld;
- else link = btn->lu;
- }
-
- if( link )
- {
- game_menu.loc = menu_get_loc( link );
- menu_input_cooldown = 0.25f;
- }
- }
- }
-}
-
-VG_STATIC int menu_page_should_backout(void)