actually render trails
[carveJwlIkooP6JGAAIwe30JlM.git] / menu.h
diff --git a/menu.h b/menu.h
index 5218485c8574ca036b4906b6685369d37fd0ddc4..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;
@@ -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;
    }
@@ -600,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 };
@@ -614,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 );
@@ -648,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 );
 
@@ -664,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 );
 
@@ -679,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 );
 
@@ -752,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 );
       }
    }