stuff
[carveJwlIkooP6JGAAIwe30JlM.git] / menu.h
diff --git a/menu.h b/menu.h
index 02ab25242a74c75837f862f20eb51fb6a230bf7b..f22789e0b1540c932da5c12c4c4c94e2af6cc996 100644 (file)
--- a/menu.h
+++ b/menu.h
@@ -7,6 +7,7 @@
 #include "player.h"
 
 #include "shaders/menu.h"
+#include "vg/vg_steam_friends.h"
 
 VG_STATIC mdl_context menu_model;
 VG_STATIC glmesh      menu_glmesh;
@@ -16,15 +17,23 @@ 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         menu_loc = 1,
-                   menu_loc_last = 1;
+VG_STATIC int         menu_loc = 0xb,
+                      menu_loc_last = 1;
 VG_STATIC u32         menu_page     = 0;
 
 VG_STATIC int         cl_menu         = 0,
-                   cl_menu_go_away = 0;
+                      cl_menu_go_away = 0;
 
 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;
+
 VG_STATIC void menu_btn_paused( int event );
 VG_STATIC void menu_btn_quit( int event );
 VG_STATIC void menu_btn_skater( int event );
@@ -33,6 +42,7 @@ VG_STATIC void menu_btn_map_a( int event );
 VG_STATIC void menu_btn_map_b( int event );
 VG_STATIC void menu_btn_map_c( int event );
 VG_STATIC void menu_btn_fuckoff( int event );
+VG_STATIC void menu_btn_reset( int event );
 
 struct menu_button
 {
@@ -48,19 +58,17 @@ struct menu_button
 VG_STATIC menu_buttons[] = 
 {
 /*0*/{"text_paused",     1, menu_btn_paused },
-/*1*/{"text_quit",       9, menu_btn_quit,    {3,-1,4,2}},
-/*2*/{"text_skater",     3, menu_btn_skater,  {3,1,4,-1}},
-/*3*/{"text_map",        5, menu_btn_map, {-1,-1,2,-1}},
+/*1*/{"text_quit",       9, menu_btn_quit,    {3,-1,4,0xb}},
+/*2*/{"text_skater",     3, menu_btn_skater,  {3,0xb,4,-1}},
+/*3*/{"text_map",        5, NULL, {-1,-1,2,-1}},
 /*4*/{"text_about_game", 1, NULL, {2,-1,-1,-1}},
 /*5*/{"skater_left",     2, NULL, {-1,-1,-1,-1}},
 /*6*/{"skater_right",    2, NULL, {-1,-1,-1,-1}},
-/*7*/{"map_a",           4, menu_btn_map_a,{8, -1, 9, 9 }},
-/*8*/{"map_b",           4, menu_btn_map_b,{-1,7,7,-1}},
-/*9*/{"map_c",           4, menu_btn_map_c,{7,7,-1,8}},
-/*a*/{"g_map",           5, NULL },
-/*b*/{"g_controls",      1, NULL },
-/*c*/{"text_quitty",     8, NULL },
-/*d*/{"text_yes",        8, menu_btn_fuckoff,{-1,-1,-1,-1} },
+/*7*/{"g_map",           5, NULL },
+/*8*/{"g_controls",      1, NULL },
+/*9*/{"text_quitty",     8, NULL },
+/*a*/{"text_yes",        8, menu_btn_fuckoff,{-1,-1,-1,-1} },
+/*b*/{"text_reset",      1, menu_btn_reset,{3,1,4,2} },
 };
 
 VG_STATIC void menu_btn_map_a( int event ){}
@@ -72,6 +80,15 @@ VG_STATIC void menu_btn_paused( int event )
 
 }
 
+VG_STATIC void menu_btn_reset( int event )
+{
+   reset_player(0,NULL);
+   world_routes_clear();
+
+   cl_menu_go_away = 1;
+   menu_page = 0;
+}
+
 VG_STATIC void menu_btn_fuckoff( int event )
 {
    glfwSetWindowShouldClose( vg.window, 1 );
@@ -80,7 +97,7 @@ VG_STATIC void menu_btn_fuckoff( int event )
 VG_STATIC void menu_btn_quit( int event )
 {
    menu_page = 0x8;
-   menu_loc = 0xd;
+   menu_loc = 0xa;
 }
 
 VG_STATIC void menu_btn_map( int event )
@@ -94,8 +111,38 @@ VG_STATIC void menu_btn_skater( int event )
    menu_page = 0x2;
 }
 
+
+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;
+      menu_page = 1;
+   }
+}
+
 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_apply_bind_str( &input_menu_h, "", "gp-ls-h" );
+   vg_apply_bind_str( &input_menu_h, "+", "d" );
+   vg_apply_bind_str( &input_menu_h, "-", "a" );
+   vg_apply_bind_str( &input_menu_v, "", "gp-ls-v" );
+   vg_apply_bind_str( &input_menu_v, "+", "w" );
+   vg_apply_bind_str( &input_menu_v, "-", "s" );
+   vg_apply_bind_str( &input_menu_press, "", "gp-a" );
+   vg_apply_bind_str( &input_menu_back, "", "gp-b" );
+   vg_apply_bind_str( &input_menu_toggle, "", "\2escape" );
+   vg_apply_bind_str( &input_menu_toggle, "", "\2gp-menu" );
+
    vg_linear_clear( vg_mem.scratch );
 
    mdl_open( &menu_model, "models/rs_menu.mdl" );
@@ -104,7 +151,10 @@ VG_STATIC void menu_init(void)
    mdl_close( &menu_model );
 
    vg_acquire_thread_sync();
-   mdl_unpack_glmesh( &menu_model, &menu_glmesh );
+   {
+      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++ )
@@ -117,13 +167,17 @@ VG_STATIC void menu_init(void)
    }
 
    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[ menu_loc ];
 
-   if( vg_get_button_down( "jump" ) )
+   if( vg_input_button_down( &input_menu_press ) )
    {
       if( btn->fn_press )
       {
@@ -138,7 +192,8 @@ VG_STATIC void menu_run_directional(void)
 
    if( menu_input_cooldown <= 0.0f )
    {
-      v2f dir = { vg_get_axis( "lookh" ), vg_get_axis( "lookv" ) };
+      v2f dir = { input_menu_h.axis.value,
+                  input_menu_v.axis.value };
 
       if( v2_length2( dir ) > 0.8f*0.8f )
       {
@@ -169,7 +224,7 @@ VG_STATIC void menu_run_directional(void)
 
 VG_STATIC int menu_page_should_backout(void)
 {
-   return vg_get_button_down( "break" );
+   return vg_input_button_down( &input_menu_back );
 }
 
 VG_STATIC void menu_close(void)
@@ -216,7 +271,7 @@ VG_STATIC void menu_page_quit(void)
 
 VG_STATIC void menu_page_skater(void)
 {
-   float h = vg_get_axis( "lookh" );
+   float h = input_menu_h.axis.value;
    menu_fov_target = 97.0f;
 
    if( menu_page_should_backout() )
@@ -228,6 +283,10 @@ VG_STATIC void menu_page_skater(void)
 
    if( (fabsf(h) > 0.7f) && (menu_input_cooldown <= 0.0f) )
    {
+      audio_lock();
+      audio_play_oneshot( &audio_rewind[4], 1.0f );
+      audio_unlock();
+
       if( h < 0.0f )
       {
          cl_playermdl_id --;
@@ -255,7 +314,13 @@ VG_STATIC void menu_page_skater(void)
 
 VG_STATIC void menu_update(void)
 {
-   if( vg_get_button_down( "menu" ) )
+   vg_input_update( 1, &input_menu_h );
+   vg_input_update( 1, &input_menu_v );
+   vg_input_update( 1, &input_menu_back );
+   vg_input_update( 1, &input_menu_press );
+   vg_input_update( 1, &input_menu_toggle );
+
+   if( vg_input_button_down( &input_menu_toggle ) )
    {
       if( cl_menu )
       {
@@ -386,7 +451,7 @@ VG_STATIC void menu_render( m4x4f projection )
    shader_menu_use();
    shader_menu_uColour( (v4f){ 1.0f,1.0f,1.0f,1.0f} );
    shader_menu_uTexMain( 1 );
-   vg_tex2d_bind( &tex_graffiti, 1 );
+   vg_tex2d_bind( &tex_menu, 1 );
 
    shader_menu_uPv( projection );
    mesh_bind( &menu_glmesh );