Merge all features from glider feature branch
[carveJwlIkooP6JGAAIwe30JlM.git] / menu.h
diff --git a/menu.h b/menu.h
index 098570608e53248d174e42a745da54ba30bc41db..73e048f9b17ca1c0f251726a002e42651f5154ef 100644 (file)
--- a/menu.h
+++ b/menu.h
@@ -9,8 +9,9 @@
 #include "audio.h"
 #include "input.h"
 #include "workshop.h"
-#include "respawn.h"
+#include "world_map.h"
 #include "gui.h"
+#include "ent_miniworld.h"
 
 #define MENU_STACK_SIZE 8
 
@@ -48,7 +49,7 @@ struct {
    camera        view;
 
    mdl_context model;
-   GLuint texture;
+   GLuint *textures;
    glmesh mesh;
 
    mdl_array_ptr items, markers, cameras;
@@ -129,7 +130,7 @@ static void menu_close(void){
    skaterift.activity = k_skaterift_default;
    menu.page_depth = 0;
    menu.page = 0xffffffff;
-   srinput.enabled = 0;
+   srinput.state = k_input_state_resume;
 }
 
 static void menu_init(void){
@@ -140,23 +141,27 @@ static void menu_init(void){
 
    vg_linear_clear( vg_mem.scratch );
 
-   mdl_load_array( &menu.model, &menu.items,   "ent_menuitem", alloc );
-   mdl_load_array( &menu.model, &menu.markers, "ent_marker", alloc );
-   mdl_load_array( &menu.model, &menu.cameras, "ent_camera", alloc );
+   MDL_LOAD_ARRAY( &menu.model, &menu.items,   ent_menuitem, alloc );
+   MDL_LOAD_ARRAY( &menu.model, &menu.markers, ent_marker, alloc );
+   MDL_LOAD_ARRAY( &menu.model, &menu.cameras, ent_camera, alloc );
 
-   vg_linear_clear( vg_mem.scratch );
+   u32 count = mdl_arrcount( &menu.model.textures );
+   menu.textures = vg_linear_alloc(alloc,vg_align8(sizeof(GLuint)*(count+1)));
+   menu.textures[0] = vg.tex_missing;
 
-   if( !mdl_arrcount( &menu.model.textures ) )
-      vg_fatal_error( "No texture in menu file" );
+   mdl_async_load_glmesh( &menu.model, &menu.mesh, NULL );
 
-   mdl_texture *tex0 = mdl_arritm( &menu.model.textures, 0 );
-   void *data = vg_linear_alloc( vg_mem.scratch, tex0->file.pack_size );
-   mdl_fread_pack_file( &menu.model, &tex0->file, data );
+   for( u32 i=0; i<count; i ++ ){
+      vg_linear_clear( vg_mem.scratch );
+      menu.textures[i+1] = vg.tex_missing;
 
-   mdl_async_load_glmesh( &menu.model, &menu.mesh );
-   vg_tex2d_load_qoi_async( data, tex0->file.pack_size, 
-                            VG_TEX2D_LINEAR|VG_TEX2D_CLAMP,
-                            &menu.texture );
+      mdl_texture *tex = mdl_arritm( &menu.model.textures, i );
+      void *data = vg_linear_alloc( vg_mem.scratch, tex->file.pack_size );
+      mdl_fread_pack_file( &menu.model, &tex->file, data );
+      vg_tex2d_load_qoi_async( data, tex->file.pack_size, 
+                               VG_TEX2D_LINEAR|VG_TEX2D_CLAMP,
+                               &menu.textures[i+1] );
+   }
 
    mdl_close( &menu.model );
    shader_model_menu_register();
@@ -185,6 +190,7 @@ static void menu_back_page(void){
  */
 static void menu_open_page( const char *name, 
                             enum ent_menuitem_stack_behaviour stackmode ){
+   srinput.state = k_input_state_resume;
    if( stackmode == k_ent_menuitem_stack_append ){
       if( menu.page_depth >= MENU_STACK_SIZE )
          vg_fatal_error( "Stack overflow\n" );
@@ -244,31 +250,33 @@ static void menu_trigger_item( ent_menuitem *item ){
       if( MDL_CONST_PSTREQ( &menu.model, q, "quit" ) ){
          vg.window_should_close = 1;
       }
-
-      /* DEPRECATED? */
-      else if( MDL_CONST_PSTREQ( &menu.model, q, "reset_nearest" ) ){
-         localplayer_cmd_respawn( 0, NULL );
+      else if( MDL_CONST_PSTREQ( &menu.model, q, "map" ) ){
          menu_close();
+         world_map_enter();
       }
-      /* DEPRECATED? */
-      else if( MDL_CONST_PSTREQ( &menu.model, q, "reset_home" ) ){
-         world_set_active_instance( 0 );
-         localplayer.viewable_world = world_current_instance();
-         localplayer_cmd_respawn( 1, (const char *[]){"start"} );
-         menu_close();
-      }
-
-      else if( MDL_CONST_PSTREQ( &menu.model, q, "reset" ) ){
-         menu_close();
-         respawn_begin_chooser();
+      else if( MDL_CONST_PSTREQ( &menu.model, q, "hub" ) ){
+         if( world_static.active_instance == k_world_purpose_client ){
+            menu_close();
+            ent_miniworld_goback();
+         }
       }
-
       else if( MDL_CONST_PSTREQ( &menu.model, q, "credits" ) ){
          menu.credits_open = 1;
       }
       else if( MDL_CONST_PSTREQ( &menu.model, q, "workshop" ) ){
          workshop_submit_command(0,NULL);
       }
+      else if( MDL_CONST_PSTREQ( &menu.model, q, "engine" ) ){
+         vg_settings_open();
+      }
+      else if( MDL_CONST_PSTREQ( &menu.model, q, "prem_store" ) ){
+         if( steam_ready )
+            SteamAPI_ISteamFriends_ActivateGameOverlayToStore( 
+                  SteamAPI_SteamFriends(), 2103940, k_EOverlayToStoreFlag_None);
+      }
+      else if( MDL_CONST_PSTREQ( &menu.model, q, "prem_nevermind" ) ){
+         menu_close();
+      }
    }
    else if( item->type == k_ent_menuitem_type_page_button ){
       menu_open_page( mdl_pstr( &menu.model, item->button.pstr ),
@@ -312,9 +320,12 @@ static void menu_update(void){
    }
 
    int escape = button_down( k_srbind_mback );
-   if( menu.credits_open ){
+   if( menu.credits_open || vg.settings_open ){
       if( escape ){
          menu.credits_open = 0;
+
+         if( vg.settings_open )
+            vg_settings_close();
       }
       return;
    }
@@ -430,7 +441,8 @@ static void menu_update(void){
          ent_menuitem *item = mdl_arritm( &menu.items, i );
 
          if( item->type == k_ent_menuitem_type_page ) continue;
-         if( item->type == k_ent_menuitem_type_visual ) continue;
+         if( (item->type == k_ent_menuitem_type_visual) ||
+             (item->type == k_ent_menuitem_type_visual_nocol) ) continue;
          if( item->type == k_ent_menuitem_type_binding ) continue;
          if( !(item->groups & (0x1<<menu.page)) ) continue;
 
@@ -489,6 +501,7 @@ static void menu_update(void){
             
             if( (item->type != k_ent_menuitem_type_page) &&
                 (item->type != k_ent_menuitem_type_visual) &&
+                (item->type != k_ent_menuitem_type_visual_nocol) &&
                 (item->groups & (0x1<<menu.page)) ){
                menu.loc = item;
             }
@@ -560,15 +573,15 @@ static void menu_update(void){
    menu_setitem_type( menu.ctr_steam, k_ent_menuitem_type_disabled );
 
    if( vg_input.display_input_method == k_input_method_kbm )
-      menu_setitem_type( menu.ctr_kbm, k_ent_menuitem_type_visual );
+      menu_setitem_type( menu.ctr_kbm, k_ent_menuitem_type_visual_nocol );
    else{
       if( vg_input.display_input_type == SDL_CONTROLLER_TYPE_PS3 ||
           vg_input.display_input_type == SDL_CONTROLLER_TYPE_PS4 ||
           vg_input.display_input_type == SDL_CONTROLLER_TYPE_PS5 ){
-         menu_setitem_type( menu.ctr_ps, k_ent_menuitem_type_visual );
+         menu_setitem_type( menu.ctr_ps, k_ent_menuitem_type_visual_nocol );
       }
       else {
-         menu_setitem_type( menu.ctr_xbox, k_ent_menuitem_type_visual );
+         menu_setitem_type( menu.ctr_xbox, k_ent_menuitem_type_visual_nocol );
       }
       /* FIXME: Steam/Deck controller detection? */
    }
@@ -598,6 +611,9 @@ static void menu_render(void){
       return;
    }
 
+   if( vg.settings_open )
+      return;
+
    if( menu.credits_open ){
       ui_rect panel = { 0,0, 460, 400 },
               screen = { 0,0, vg.window_x,vg.window_y };
@@ -612,11 +628,6 @@ static void menu_render(void){
       ui_split( panel, k_ui_axis_h, 28, 0, title, panel );
       ui_text( title, "Mt.Zero Software", 1, k_ui_align_middle_center, 0 );
 
-      ui_split( panel, k_ui_axis_h, 8, 0, title, panel );
-      ui_split( panel, k_ui_axis_h, 28, 0, title, panel );
-      ui_text( title, "A game by Harry Godden", 1, 
-               k_ui_align_middle_center, 0 );
-
       ui_split( panel, k_ui_axis_h, 8, 0, title, panel );
       ui_split( panel, k_ui_axis_h, 28*2, 0, title, panel );
       ui_text( title, "Free Software", 2, k_ui_align_middle_center, 0 );
@@ -646,7 +657,7 @@ static void menu_render(void){
 
       v3f v0;
       mdl_transform_vector( &menu.cam->transform, (v3f){0.0f,-1.0f,0.0f}, v0 );
-      player_vector_angles( target.angles, v0, 1.0f, 0.0f );
+      v3_angles( v0, target.angles );
 
       camera_lerp( &menu.view, &target, rate, &menu.view );
 
@@ -662,8 +673,6 @@ static void menu_render(void){
 
    shader_model_menu_use();
    shader_model_menu_uTexMain( 1 );
-   glActiveTexture( GL_TEXTURE1 );
-   glBindTexture( GL_TEXTURE_2D, menu.texture );
    shader_model_menu_uPv( menu.view.mtx.pv );
    shader_model_menu_uPvmPrev( menu.view.mtx_prev.pv );
 
@@ -677,6 +686,8 @@ static void menu_render(void){
    ent_menuitem *text_list[ 8 ];
    u32 text_count = 0;
 
+   u32 current_tex = 0xffffffff;
+
    for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
       ent_menuitem *item = mdl_arritm( &menu.items, i );
 
@@ -707,7 +718,7 @@ static void menu_render(void){
          }
       }
 
-      if( item->type == k_ent_menuitem_type_visual ){
+      if( item->type == k_ent_menuitem_type_visual_nocol ){
          shader_model_menu_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
       }
       else{
@@ -750,7 +761,18 @@ static void menu_render(void){
 
       for( u32 j=0; j<item->submesh_count; j++ ){
          u32 index = item->submesh_start + j;
-         mdl_draw_submesh( mdl_arritm( &menu.model.submeshs, index ));
+         mdl_submesh *sm = mdl_arritm( &menu.model.submeshs, index );
+         
+         mdl_material *mat = mdl_arritm( &menu.model.materials, 
+                                         sm->material_id-1 );
+
+         if( mat->tex_diffuse != current_tex ){
+            glActiveTexture( GL_TEXTURE1 );
+            glBindTexture( GL_TEXTURE_2D, menu.textures[ mat->tex_diffuse ] );
+            current_tex = mat->tex_diffuse;
+         }
+
+         mdl_draw_submesh( sm );
       }
    }
 
@@ -779,38 +801,32 @@ static void menu_render(void){
 }
 
 static void menu_binding_string( char buf[128], u32 pstr ){
-   vg_strncpy( "error", buf, 128, k_strncpy_allow_cutoff );
+   vg_str str;
+   vg_strnull( &str, buf, 128 );
 
    if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_jump" ) ){
-      vg_strncpy( button_display_string(k_srbind_jump), buf, 128, 
-                  k_strncpy_allow_cutoff );
+      vg_input_string( &str, input_button_list[k_srbind_jump], 1 );
    }
    else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_trick0" ) ){
-      vg_str str;
-      vg_strnull( &str, buf, 128 );
       vg_strcat( &str, "SHUVIT " );
-      vg_strcat( &str, button_display_string(k_srbind_trick0) );
+      vg_input_string( &str, input_button_list[k_srbind_trick0], 1 );
    }
    else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_trick1" ) ){
-      vg_str str;
-      vg_strnull( &str, buf, 128 );
       vg_strcat( &str, "KICKFLIP " );
-      vg_strcat( &str, button_display_string(k_srbind_trick1) );
+      vg_input_string( &str, input_button_list[k_srbind_trick1], 1 );
    }
    else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_trick2" ) ){
-      vg_str str;
-      vg_strnull( &str, buf, 128 );
       vg_strcat( &str, "TREFLIP " );
-      vg_strcat( &str, button_display_string(k_srbind_trick2) );
+      vg_input_string( &str, input_button_list[k_srbind_trick2], 1 );
    }
    else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_grab" ) ){
-      vg_strncpy( axis_display_string(k_sraxis_grab), buf, 128,
-                  k_strncpy_allow_cutoff );
+      vg_input_string( &str, input_axis_list[k_sraxis_grab], 1 );
    }
    else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_grab_mod" ) ){
-      vg_strncpy( joystick_display_string(k_srjoystick_grab, 2), buf, 128,
-                  k_strncpy_allow_cutoff );
+      vg_input_string( &str, input_joy_list[k_srjoystick_grab], 1 );
    }
+   else
+      vg_strcat( &str, "error" );
 }
 
 #endif /* MENU_H */