Update spawn map to new UI
authorhgn <hgodden00@gmail.com>
Mon, 15 Apr 2024 20:51:52 +0000 (21:51 +0100)
committerhgn <hgodden00@gmail.com>
Mon, 15 Apr 2024 20:51:52 +0000 (21:51 +0100)
13 files changed:
.gitignore
ent_miniworld.c
gui.h
input.h
menu.c
menu.h
models_src/rs_icons.mdl
player.c
skaterift.c
skaterift.h
world_map.c
world_map.h
world_render.c

index 5955d4ec74199147e17f2e1e4d99dbacd3510d7e..db0406a6910105213da81c53d139a5561729a7dc 100755 (executable)
@@ -6,6 +6,7 @@
 *.bin
 *.swp
 *.c0
+*.gc
 
 # soft links
 steamworks_sdk
index 2fed03137313e7549a36cfee7939cd716ca2491c..40fac190fc72e5f0633979b75230639ecfcbb5a2 100644 (file)
@@ -171,12 +171,13 @@ void ent_miniworld_preupdate(void)
       return;
    }
 
-   if( button_down( k_srbind_miniworld_resume ) ){
-      if( skaterift.demo_mode ){
-         if( world_static.instance_addons[1]->flags & ADDON_REG_PREMIUM ){
-            skaterift.activity = k_skaterift_menu;
-            menu.page = 0xffffffff;
-            menu_open_page( "Premium", k_ent_menuitem_stack_append );
+   if( button_down( k_srbind_miniworld_resume ) )
+   {
+      if( skaterift.demo_mode )
+      {
+         if( world_static.instance_addons[1]->flags & ADDON_REG_PREMIUM )
+         {
+            menu_open( k_menu_page_premium );
             return;
          }
       }
diff --git a/gui.h b/gui.h
index c60c51be00b975e6f001509b3bb01b8faf4f6f9f..c1ce8d71a41ea81120b6c0767e56664c41a10441 100644 (file)
--- a/gui.h
+++ b/gui.h
@@ -4,6 +4,12 @@
 #include "player.h"
 #include "vg/vg_imgui.h"
 
+#define GUI_COL_DARK   ui_opacity( 0x00000000, 0.7f )
+#define GUI_COL_NORM   ui_opacity( 0x00101010, 0.7f )
+#define GUI_COL_ACTIVE ui_opacity( 0x00444444, 0.7f )
+#define GUI_COL_CLICK  ui_opacity( 0x00858585, 0.7f )
+#define GUI_COL_HI     ui_opacity( 0x00ffffff, 0.8f )
+
 enum gui_icon {
    k_gui_icon_tick    = 0,
    k_gui_icon_tick_2d,
@@ -19,6 +25,8 @@ enum gui_icon {
    k_gui_icon_rift_run_gold,
    k_gui_icon_rift_run_silver,
    k_gui_icon_glider,
+   k_gui_icon_spawn,
+   k_gui_icon_spawn_select,
 
    k_gui_icon_count,
 };
@@ -42,7 +50,7 @@ struct{
       v4f colour;
       int colour_changed;
    }
-   icon_draw_buffer[32];
+   icon_draw_buffer[64];
    u32 icon_draw_count;
    v4f cur_icon_colour;
    int colour_changed;
@@ -147,11 +155,6 @@ static void gui_draw(void)
    ui_px height = vg_ui.font->ch + 16;
    ui_rect lwr = { 0, vg.window_y - height, vg.window_x, height };
 
-   if( gui.factive > 0.01f )
-   {
-      //ui_fill( lwr, ui_opacity( 0xff000000, gui.factive*0.8f ) );
-   }
-
    ui_px x = 0;
    for( u32 i=0; i<gui.helper_count; i++ )
    {
@@ -172,7 +175,7 @@ static void gui_draw(void)
          opacity = 0.1f;
       }
 
-      struct ui_vert *bg = ui_fill( box, ui_opacity( 0x00000000, opacity ) );
+      struct ui_vert *bg = ui_fill( box, ui_opacity( GUI_COL_DARK, opacity ) );
 
       u32 w;
       box[0] += 16;
@@ -183,7 +186,7 @@ static void gui_draw(void)
       x += w + 32;
 
       box[0] = x;
-      bg = ui_fill( box, ui_opacity( 0x00101010, opacity*0.7f ) );
+      bg = ui_fill( box, ui_opacity( GUI_COL_NORM, opacity*0.7f ) );
       box[0] += 8;
       w = ui_text( box, helper->text, 1, k_ui_align_middle_left, fg );
       w *= vg_ui.font->sx;
@@ -204,7 +207,7 @@ static void gui_draw(void)
           o = 1.0f-t*t*(2.0f-t);
 
       ui_rect box = { 0, (vg.window_y*2)/3 - height/2, vg.window_x, height };
-      ui_fill( box, ui_opacity( 0x00101010, 0.5f ) );
+      ui_fill( box, ui_opacity( GUI_COL_NORM, 0.5f ) );
       ui_text( box, gui.location, 1, k_ui_align_middle_center, 0 );
 
       vg_ui.colour[3] = o;
@@ -327,6 +330,8 @@ static void gui_init(void){
    gui.icons[ k_gui_icon_friend ] = gui_find_icon( "icon_friend" );
    gui.icons[ k_gui_icon_player ] = gui_find_icon( "icon_player" );
    gui.icons[ k_gui_icon_glider ] = gui_find_icon( "icon_glider" );
+   gui.icons[ k_gui_icon_spawn ] = gui_find_icon( "icon_spawn" );
+   gui.icons[ k_gui_icon_spawn_select ] = gui_find_icon( "icon_spawn_select" );
    gui.icons[ k_gui_icon_rift_run_gold ] =
       gui_find_icon("icon_rift_run_medal_gold");
    gui.icons[ k_gui_icon_rift_run_silver]=
diff --git a/input.h b/input.h
index e66a8600f65911474af95465819d7b685d5203a0..2d4f30ea2c300b4a0b67eea1c9d03ea764de1bc7 100644 (file)
--- a/input.h
+++ b/input.h
@@ -5,7 +5,8 @@
 #include "vg/vg_m.h"
 #include "font.h"
 
-enum sr_bind{
+enum sr_bind
+{
    k_srbind_jump = 0,
    k_srbind_push,
    k_srbind_skid,
@@ -185,8 +186,7 @@ struct {
 static srinput;
 
 static int input_filter_generic(void){
-   if( srinput.state != k_input_state_enabled || 
-       vg_ui.wants_mouse || vg_console.enabled || vg.settings_open )
+   if( srinput.state != k_input_state_enabled || vg_console.enabled )
       return 1;
    else 
       return 0;
diff --git a/menu.c b/menu.c
index ed69945eaebd64cb9ba8b8f85122fcec967a043e..9df54fbc45fbdf991813f9b294927e4907e4bdca 100644 (file)
--- a/menu.c
+++ b/menu.c
 
 struct global_menu menu = { .skip_starter = 0 };
 
-/*
- * Attaches memory locations to the various items in the menu
- */
-void menu_link(void)
+void menu_at_begin(void)
 {
-   /* link data locations */
-   for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
-      ent_menuitem *item = mdl_arritm( &menu.items, i );
-      
-      if( item->type == k_ent_menuitem_type_toggle ||
-          item->type == k_ent_menuitem_type_slider ){
-         
-         const char *name;
-
-         if( item->type == k_ent_menuitem_type_slider )
-            name = mdl_pstr( &menu.model, item->slider.pstr_data );
-         else
-            name = mdl_pstr( &menu.model, item->checkmark.pstr_data );
-         vg_var *var = vg_console_match_var( name );
-
-         if( var ){
-            if( ( item->type == k_ent_menuitem_type_slider && 
-                  var->data_type != k_var_dtype_f32
-                ) ||
-                ( item->type == k_ent_menuitem_type_toggle &&!
-                  ( var->data_type == k_var_dtype_i32 ||
-                    var->data_type == k_var_dtype_u32 
-                  )
-               )
-            ){
-               vg_error( "Cannot hook to data %s(%p), because it is type %d.\n",
-                           name, var, var->data_type );
-               item->pvoid = NULL;
-            }
-            else{
-               item->pvoid = var->data;
-            }
-         }
-         else{
-            vg_error( "No data named %s\n", name );
-            item->pvoid = NULL;
-         }
-      }
-      else{
-         item->pvoid = NULL;
-      }
-   }
-
-   /* link controllers */
-   menu.ctr_deck = NULL;
-   menu.ctr_kbm = NULL;
-   menu.ctr_ps = NULL;
-   menu.ctr_steam = NULL;
-   menu.ctr_xbox = NULL;
-
-   for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
-      ent_menuitem *item = mdl_arritm( &menu.items, i );
-
-      if( MDL_CONST_PSTREQ( &menu.model, item->visual.pstr_name, "deck" ) )
-         menu.ctr_deck = item;
-      if( MDL_CONST_PSTREQ( &menu.model, item->visual.pstr_name, "kbm" ) )
-         menu.ctr_kbm = item;
-      if( MDL_CONST_PSTREQ( &menu.model, item->visual.pstr_name, "ps" ) )
-         menu.ctr_ps = item;
-      if( MDL_CONST_PSTREQ( &menu.model, item->visual.pstr_name, "steam" ) )
-         menu.ctr_steam = item;
-      if( MDL_CONST_PSTREQ( &menu.model, item->visual.pstr_name, "xbox" ) )
-         menu.ctr_xbox = item;
-   }
-}
+   if( menu.skip_starter ) return;
 
-void menu_close(void)
-{
-   skaterift.activity = k_skaterift_default;
-   menu.page_depth = 0;
-   menu.page = 0xffffffff;
-   srinput.state = k_input_state_resume;
+   skaterift.activity = k_skaterift_menu;
+   menu.page = k_menu_page_starter;
 }
 
 void menu_init(void)
 {
-   void *alloc = vg_mem.rtmemory;
-
-   mdl_open( &menu.model, "models/rs_menu.mdl", alloc );
-   mdl_load_metadata_block( &menu.model, alloc );
-
-   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 );
-
-   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;
-
-   mdl_async_load_glmesh( &menu.model, &menu.mesh, NULL );
-
-   for( u32 i=0; i<count; i ++ ){
-      vg_linear_clear( vg_mem.scratch );
-      menu.textures[i+1] = vg.tex_missing;
-
-      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 );
-
    vg_console_reg_var( "skip_starter_menu", &menu.skip_starter,
                        k_var_dtype_i32, VG_VAR_PERSISTENT );
 }
 
-void menu_at_begin(void)
+void menu_open( enum menu_page page )
 {
-   if( menu.skip_starter ) return;
-
    skaterift.activity = k_skaterift_menu;
-   menu.page = 0xffffffff;
-   menu_open_page( "Starter", k_ent_menuitem_stack_append );
-}
-
-/*
- * Drop back a page until we're at the bottom which then we jus quit
- */
-static void menu_back_page(void){
-   menu.page_depth --;
-   if( menu.page_depth == 0 ){
-      menu_close();
-   }
-   else{
-      menu.page = menu.page_stack[ menu.page_depth ].page;
-      menu.cam = menu.page_stack[ menu.page_depth ].cam;
-
-      if( menu.input_mode == k_menu_input_mode_keys )
-         menu.loc = menu.page_stack[ menu.page_depth ].loc;
-      else menu.loc = NULL;
-   }
-}
-
-/*
- * Open page to the string identifier
- */
-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" );
-   }
-   else{
-      if( menu.page_depth == 0 )
-         vg_fatal_error( "Stack underflow\n" );
-   }
-
-   u32 hash = vg_strdjb2( name );
-   for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
-      ent_menuitem *item = mdl_arritm( &menu.items, i );
-      
-      if( item->type == k_ent_menuitem_type_page ){
-         if( mdl_pstreq( &menu.model, item->page.pstr_name, name, hash ) ){
-            u32 new_page = __builtin_ctz( item->groups );
-
-            if( new_page == menu.page ){
-               if( stackmode != k_ent_menuitem_stack_replace )
-                  menu_back_page();
-            }
-            else{
-               menu.page_stack[ menu.page_depth ].page = menu.page;
-               menu.page_stack[ menu.page_depth ].cam = menu.cam;
-               menu.page_stack[ menu.page_depth ].loc = menu.loc;
-               
-               if( stackmode == k_ent_menuitem_stack_append )
-                  menu.page_depth ++;
-
-               menu.page = __builtin_ctz( item->groups );
 
-               if( menu.input_mode == k_menu_input_mode_keys ){
-                  if( item->page.id_entrypoint ){
-                     u32 id = mdl_entity_id_id( item->page.id_entrypoint );
-                     menu.loc = mdl_arritm( &menu.items, id );
-                  }
-               }
-
-               if( item->page.id_viewpoint ){
-                  u32 id = mdl_entity_id_id( item->page.id_viewpoint );
-                  menu.cam = mdl_arritm( &menu.cameras, id );
-               }
-            }
-            return;
-         }
-      }
-   }
-}
-
-/*
- * activate a pressable type
- */
-static void menu_trigger_item( ent_menuitem *item )
-{
-   audio_lock();
-   audio_oneshot( &audio_ui[0], 1.0f, 0.0f );
-   audio_unlock();
-
-   if     ( item->type == k_ent_menuitem_type_event_button )
+   if( page != k_menu_page_any )
    {
-      u32 q = item->button.pstr;
-
-      if( MDL_CONST_PSTREQ( &menu.model, q, "quit" ) )
-      {
-         vg.window_should_close = 1;
-      }
-      else if( MDL_CONST_PSTREQ( &menu.model, q, "map" ) ){
-         menu_close();
-         world_map_enter();
-      }
-      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( MDL_CONST_PSTREQ( &menu.model, q, "starter_enter" ) )
-      {
-         if( network_client.auto_connect )
-            network_client.user_intent = k_server_intent_online;
-
-         menu_close();
-      }
-   }
-   else if( item->type == k_ent_menuitem_type_page_button )
-   {
-      menu_open_page( mdl_pstr( &menu.model, item->button.pstr ),
-                      item->button.stack_behaviour );
-   }
-   else if( item->type == k_ent_menuitem_type_toggle )
-   {
-      if( item->pi32 ){
-         *item->pi32 = *item->pi32 ^ 0x1;
-      }
+      menu.page = page;
    }
 }
 
-static f32 menu_slider_snap( f32 value, f32 old, f32 notch ){
-   f32 const k_epsilon = 0.0125f;
-
-   if( fabsf(notch-value) < k_epsilon ){
-      if( fabsf(notch-old) > k_epsilon ){
-         audio_lock();
-         audio_oneshot( &audio_ui[0], 1.0f, 0.0f );
-         audio_unlock();
-      }
-
-      return notch;
-   }
-   else
-      return value;
-}
-
-static void menu_setitem_type( ent_menuitem *item, 
-                               enum ent_menuitem_type type ){
-   if( !item ) return;
-   item->type = type;
+bool menu_viewing_map(void)
+{
+   return (skaterift.activity == k_skaterift_menu) && 
+          (menu.page == k_menu_page_main) &&
+          (menu.main_index == 0);
 }
 
-/* 
- * Run from vg_gui every frame
- */
-void menu_update(void)
+void menu_gui(void)
 {
-   static f32 repeater = 0.0f;
-   if( repeater > 0.0f )
-      repeater -= vg.time_frame_delta;
-
-   if( workshop_form.page != k_workshop_form_hidden ){
-      return;
-   }
-
-   bool escape = 0;
-                          
-   if( menu.credits_open || vg.settings_open )
+   if( button_down( k_srbind_mopen ) )
    {
-      vg_exec_input_program( k_vg_input_type_button_u8, 
-                             input_button_list[k_srbind_mback], &escape );
-      if( escape )
+      if( skaterift.activity == k_skaterift_default )
       {
-         menu.credits_open = 0;
-
-         if( vg.settings_open )
-            vg_settings_close();
-
-         srinput.state = k_input_state_resume;
-      }
-      return;
-   }
-   escape = button_down( k_srbind_mback );
-
-   if( button_down( k_srbind_mopen ) ){
-      if( skaterift.activity == k_skaterift_default ){
-         skaterift.activity = k_skaterift_menu;
-         menu.page = 0xffffffff;
-         menu_open_page( "Main Menu", k_ent_menuitem_stack_append );
+         menu_open( k_menu_page_main );
          return;
       }
    }
 
-   if( skaterift.activity != k_skaterift_menu ) return;
-   enum menu_input_mode prev_mode = menu.input_mode;
+   if( skaterift.activity != k_skaterift_menu ) 
+      return;
 
    /* get buttons inputs
     * -------------------------------------------------------------------*/
@@ -353,505 +68,154 @@ void menu_update(void)
        mv = mu-md,
        enter = button_down( k_srbind_maccept );
 
-   if( mh||mv||enter ){
+   if( mh||mv||enter )
+   {
       menu.input_mode = k_menu_input_mode_keys;
    }
 
    /* get mouse inputs 
     * --------------------------------------------------------------------*/
    menu.mouse_dist += v2_length( vg.mouse_delta ); /* TODO: Move to UI */
-   menu.mouse_track += vg.time_frame_delta;
-   if( menu.mouse_track > 0.1f ){
-      menu.mouse_track = fmodf( menu.mouse_track, 0.1f );
-      if( menu.mouse_dist > 10.0f ){
-         menu.input_mode = k_menu_input_mode_mouse;
-         menu.mouse_dist = 0.0f;
-      }
+   if( menu.mouse_dist > 10.0f )
+   {
+      menu.input_mode = k_menu_input_mode_mouse;
+      menu.mouse_dist = 0.0f;
    }
 
-   if( ui_clicking(UI_MOUSE_LEFT) || ui_clicking(UI_MOUSE_RIGHT) ){
+   if( ui_clicking(UI_MOUSE_LEFT) || ui_clicking(UI_MOUSE_RIGHT) )
+   {
       menu.input_mode = k_menu_input_mode_mouse;
    }
 
-   if( menu.input_mode == k_menu_input_mode_mouse ){
+   if( menu.input_mode == k_menu_input_mode_mouse )
+   {
       /* 
        * handle mouse input
        * ------------------------------------------------------------*/
       vg_ui.wants_mouse = 1;
-
-      /* 
-       * this raycasting is super cumbersome because all the functions were 
-       * designed for other purposes. we dont care though.
-       */
-      m4x4f inverse;
-      m4x4_inv( menu.view.mtx.p, inverse );
-      v4f coords;
-      coords[0] = vg_ui.mouse[0];
-      coords[1] = vg.window_y - vg_ui.mouse[1];
-      v2_div( coords, (v2f){ vg.window_x, vg.window_y }, coords );
-      v2_muls( coords, 2.0f, coords );
-      v2_add( coords, (v2f){-1.0f,-1.0f}, coords );
-      coords[2] = 1.0f;
-      coords[3] = 1.0f;
-      m4x4_mulv( inverse, coords, coords );
-      v3f ray;
-      m3x3_mulv( menu.view.transform, coords, ray );
-      v3_normalize( ray );
-
-      if( menu.loc && (menu.loc->type == k_ent_menuitem_type_slider) &&
-          ui_clicking(UI_MOUSE_LEFT) && menu.loc->pf32 ){
-
-         u32 il = mdl_entity_id_id( menu.loc->slider.id_min ),
-             ir = mdl_entity_id_id( menu.loc->slider.id_max );
-         ent_marker *ml = mdl_arritm( &menu.markers, il ),
-                    *mr = mdl_arritm( &menu.markers, ir );
-
-         v3f q2;
-         v3_muladds( menu.view.pos, ray, 100.0f, q2 );
-
-         f32 s,t;
-         v3f c1, c2;
-         v3f p1, q1, v0;
-         v3_sub( mr->transform.co, ml->transform.co, v0 );
-         v3_muladds( ml->transform.co, v0, -1.0f, p1 );
-         v3_muladds( mr->transform.co, v0,  1.0f, q1 );
-         closest_segment_segment( p1, q1, menu.view.pos, q2, &s,&t, c1,c2 );
-
-         s-=(1.0f/3.0f);
-         s/=(1.0f/3.0f);
-
-         if( ui_click_down(UI_MOUSE_LEFT) ){
-            menu.slider_offset = *menu.loc->pf32 - s;
-         }
-
-         f32 newvalue = vg_clampf( s+menu.slider_offset, 0.0f, 1.0f );
-
-         newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 0.00f );
-         newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 1.00f );
-         newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 0.25f );
-         newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 0.50f );
-         newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 0.75f );
-
-         *menu.loc->pf32 = newvalue;
-         return;
-      }
-
-      ent_menuitem *hit_item = NULL;
-
-      for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
-         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) ||
-             (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;
-
-         ent_menuitem *ray_item = item;
-
-         if( item->type == k_ent_menuitem_type_slider ){
-            u32 subtarget = mdl_entity_id_id( item->slider.id_handle );
-            ray_item = mdl_arritm( &menu.items, subtarget );
-         }
-         
-         v3f local_ray,
-             local_co;
-
-         m4x3f inverse_mtx;
-         mdl_transform_m4x3( &ray_item->transform, inverse_mtx );
-         m4x3_invert_full( inverse_mtx, inverse_mtx );
-         
-         m4x3_mulv( inverse_mtx, menu.view.transform[3], local_co );
-         m3x3_mulv( inverse_mtx, ray, local_ray );
-         v3_normalize( local_ray );
-         
-         local_ray[0] = 1.0f/local_ray[0];
-         local_ray[1] = 1.0f/local_ray[1];
-         local_ray[2] = 1.0f/local_ray[2];
-
-         for( u32 j=0; j<ray_item->submesh_count; j++ ){
-            mdl_submesh *sm = mdl_arritm( &menu.model.submeshs, 
-                                           ray_item->submesh_start + j );
-            if( ray_aabb1( sm->bbx, local_co, local_ray, 1000.0f ) ){
-               hit_item = item;
-               break;
-            }
-         }
-      }
-
-      if( hit_item != menu.loc ){
-         menu.loc = hit_item;
-      }
-
-      if( escape ){
-         menu_back_page();
-      }
-      else if( menu.loc ){
-         if( ui_click_down( UI_MOUSE_LEFT ) )
-         {
-            menu_trigger_item( menu.loc );
-         }
-      }
    }
-   else if( menu.input_mode == k_menu_input_mode_keys ){
-      /* 
-       * handle button input
-       * ------------------------------------------------------------*/
-      if( (prev_mode != k_menu_input_mode_keys) && !menu.loc ){
-         for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
-            ent_menuitem *item = mdl_arritm( &menu.items, i );
-            
-            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;
-            }
-         }
-      }
-
-      if( !menu.loc ) vg_fatal_error( "No location\n" );
 
-      if( menu.loc->type == k_ent_menuitem_type_slider && menu.loc->pf32 ){
-         f32 move = 0.0f;
-
-         if( vg_input.display_input_method == k_input_method_controller ){
-            move += button_press( k_srbind_mright );
-            move -= button_press( k_srbind_mleft );
-         }
-         else{
-            move += axis_state( k_sraxis_mbrowse_h );
-         }
-
-         move *= vg.time_frame_delta;
-         *menu.loc->pf32 = vg_clampf( *menu.loc->pf32 + move, 0.0f, 1.0f );
-
-         mh = 0;
-      }
-      
-      if( escape )
-      {
-         menu_back_page();
-         audio_lock();
-         audio_oneshot( &audio_ui[3], 1.0f, 0.0f );
-         audio_unlock();
-      }
-      else if( enter )
-      {
-         menu_trigger_item( menu.loc );
-      }
-      else if( mh||mv ){
-         v3f opt; 
-         v3_zero( opt );
-         f32 best = 0.5f;
-         ent_menuitem *nextpos = NULL;
-
-         opt[0] += mh;
-         opt[2] += mv;
-         mdl_transform_vector( &menu.cam->transform, opt, opt );
-
-         for( u32 i=0; i<4; i++ ){
-            u32 id = menu.loc->id_links[i];
-            if( !id ) continue;
-            u32 index = mdl_entity_id_id( id );
-
-            ent_menuitem *other = mdl_arritm( &menu.items, index );
-            v3f delta;
-            v3_sub( menu.loc->transform.co, other->transform.co, delta );
-            v3_normalize( delta );
-
-            f32 score = v3_dot( delta, opt );
-            if( score > best ){
-               best = score;
-               nextpos = other;
-            }
-         }
+   if( skaterift.activity != k_skaterift_menu ) return;
 
-         if( nextpos && (repeater <= 0.0f) )
-         {
-            menu.loc = nextpos;
-            audio_lock();
-            audio_oneshot( &audio_ui[3], 1.0f, 0.0f );
-            audio_unlock();
-            repeater += 0.1f;
-         }
-      }
+   /* top bar */
+   ui_font_face( &vgf_default_title );
+   ui_px height = vg_ui.font->ch + 16;
+   ui_rect topbar = { 0, 0, vg.window_x, height };
+
+   const char *opts[] = {
+      "Map", "Online", "Settings", "Video"
+   };
+
+   /* TAB CONTROL */
+   u8 lb_down = 0, rb_down = 0;
+   vg_exec_input_program( k_vg_input_type_button_u8, 
+         (vg_input_op[]){
+            vg_joy_button, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, vg_end 
+         }, &rb_down );
+   vg_exec_input_program( k_vg_input_type_button_u8, 
+         (vg_input_op[]){
+            vg_joy_button, SDL_CONTROLLER_BUTTON_LEFTSHOULDER, vg_end 
+         }, &lb_down );
+
+   if( menu.repeater > 0.0f )
+   {
+      menu.repeater -= vg_minf( vg.time_frame_delta, 0.5f );
    }
+   else
+   {
+      if( lb_down != rb_down )
+      {
+         menu.main_index += rb_down;
+         menu.main_index -= lb_down;
+         menu.repeater += 0.2f;
 
-   menu_setitem_type( menu.ctr_deck, k_ent_menuitem_type_disabled );
-   menu_setitem_type( menu.ctr_ps, k_ent_menuitem_type_disabled );
-   menu_setitem_type( menu.ctr_kbm, k_ent_menuitem_type_disabled );
-   menu_setitem_type( menu.ctr_xbox, k_ent_menuitem_type_disabled );
-   menu_setitem_type( menu.ctr_steam, k_ent_menuitem_type_disabled );
+         if( menu.main_index == -1 )
+            menu.main_index ++;
 
-   if( vg_input.display_input_method == k_input_method_kbm )
-      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_nocol );
-      }
-      else {
-         menu_setitem_type( menu.ctr_xbox, k_ent_menuitem_type_visual_nocol );
+         if( menu.main_index == vg_list_size(opts) )
+            menu.main_index --;
       }
-      /* FIXME: Steam/Deck controller detection? */
    }
-}
-
-static void menu_binding_string( char buf[128], u32 pstr );
-
-/*
- * Run from vg_gui when active
- */
-void menu_render(void)
-{
-   glEnable(GL_BLEND);
-   glDisable(GL_DEPTH_TEST);
-   glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
-   glBlendEquation(GL_FUNC_ADD);
-
-   shader_blitcolour_use();
-   v4f colour;
-   ui_hex_to_norm( ui_colour( k_ui_bg+3 ), colour );
-   colour[3] = 0.5f;
-
-   shader_blitcolour_uColour( colour );
-   render_fsquad();
-
-   if( (workshop_form.page != k_workshop_form_hidden) ||
-       (vg_ui.focused_control_type != k_ui_control_none) ){
-      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 };
-      ui_rect_center( screen, panel );
-      ui_fill( panel, ui_colour(k_ui_bg) );
-      ui_outline( panel, 1, ui_colour(k_ui_fg), 0 );
-      ui_rect_pad( panel, (ui_px[]){8,8} );
-
-      ui_rect title;
-      ui_split( panel, k_ui_axis_h, 28*2, 0, title, panel );
-      ui_text( title, "Skate Rift - Credits", 2, k_ui_align_middle_center, 0 );
-      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*2, 0, title, panel );
-      ui_text( title, "Free Software", 2, k_ui_align_middle_center, 0 );
-
-      ui_split( panel, k_ui_axis_h, 8, 0, title, panel );
-      ui_text( panel, 
-            "Sam Lantinga       - SDL2 - libsdl.org\n"
-            "Hunter WB          - Anyascii\n"
-            "David Herberth     - GLAD\n"
-            "Dominic Szablewski - QOI - qoiformat.org\n"
-            "Sean Barrett       - stb_image,stb_vorbis,stb_include\n"
-            "Khronos Group      - OpenGL\n"
-            , 1, k_ui_align_left, 0 );
-      return;
-   }
-
-   glEnable( GL_DEPTH_TEST );
-   glDisable( GL_BLEND );
-
-   f32 rate = vg.time_frame_delta * 12.0f;
-
-   if( menu.cam ){
-      vg_camera target;
-
-      target.fov = menu.cam->fov;
-      v3_copy( menu.cam->transform.co, target.pos );
-
-      v3f v0;
-      mdl_transform_vector( &menu.cam->transform, (v3f){0.0f,-1.0f,0.0f}, v0 );
-      v3_angles( v0, target.angles );
-
-      vg_camera_lerp( &menu.view, &target, rate, &menu.view );
 
-      menu.view.farz = 150.0f;
-      menu.view.nearz = 0.01f;
-
-      vg_camera_update_transform( &menu.view );
-      vg_camera_update_view( &menu.view );
-      vg_camera_update_projection( &menu.view );
-      vg_camera_finalize( &menu.view );
-   }
-   else return;
-
-   shader_model_menu_use();
-   shader_model_menu_uTexMain( 1 );
-   shader_model_menu_uPv( menu.view.mtx.pv );
-   shader_model_menu_uPvmPrev( menu.view.mtx_prev.pv );
-
-   mesh_bind( &menu.mesh );
-
-   v4f white, blue;
-
-   ui_hex_to_norm( ui_colour( k_ui_fg ), white );
-   ui_hex_to_norm( ui_colour( k_ui_orange+k_ui_brighter ), blue );
-
-   ent_menuitem *text_list[ 8 ];
-   u32 text_count = 0;
-
-   u32 current_mat = 0xffffffff;
-
-   for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
-      ent_menuitem *item = mdl_arritm( &menu.items, i );
-
-      if(   item->type == k_ent_menuitem_type_disabled ) continue;
-      if(   item->type == k_ent_menuitem_type_page ) continue;
-      if( !(item->groups & (0x1 << menu.page)) ) continue;
-
-      if(   item->type == k_ent_menuitem_type_binding ){
-         if( text_count < vg_list_size(text_list) )
-            text_list[ text_count ++ ] = item;
-         else
-            vg_fatal_error( "Text list overflow" );
-
-         continue;  
-      }
-
-      int selected = 0;
-      
-      if( menu.loc ){
-         if( menu.loc->type == k_ent_menuitem_type_slider ){
-            u32 subid = menu.loc->slider.id_handle;
-            if( item == mdl_arritm( &menu.items, mdl_entity_id_id(subid) ))
-               selected = 1;
-         }
-         else{
-            if( item == menu.loc )
-               selected = 1;
-         }
-      }
-
-      if( item->type == k_ent_menuitem_type_visual_nocol ){
-         shader_model_menu_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
-      }
-      else{
-         v4f colour;
-         item->factive = vg_lerpf( item->factive, selected, rate );
-         v4_lerp( white, blue, item->factive, colour );
-         shader_model_menu_uColour( colour );
-      }
-
-      f32 scale = 1.0f+item->factive*0.1f;
-
-      m4x3f mmdl;
-      mdl_transform transform = item->transform;
-      v3_muls( transform.s, scale, transform.s );
-      mdl_transform_m4x3( &transform, mmdl );
-
-      if( item->type == k_ent_menuitem_type_toggle && item->pi32 ){
-         u32 subid = mdl_entity_id_id( item->checkmark.id_check );
-         ent_menuitem *subitem = mdl_arritm( &menu.items, subid );
-
-         v3_muladds( item->transform.co, item->checkmark.offset, scale,
-                     subitem->transform.co );
-
-         subitem->fvisible = vg_lerpf( subitem->fvisible, *item->pi32, rate );
-         v3_fill( subitem->transform.s, subitem->fvisible );
-      }
-      else if( item->type == k_ent_menuitem_type_slider && item->pf32 ){
-         u32 il = mdl_entity_id_id( item->slider.id_min ),
-             ir = mdl_entity_id_id( item->slider.id_max ),
-             ih = mdl_entity_id_id( item->slider.id_handle );
-         ent_marker *ml = mdl_arritm( &menu.markers, il ),
-                    *mr = mdl_arritm( &menu.markers, ir );
-         ent_menuitem *handle = mdl_arritm( &menu.items, ih );
-
-         v3_lerp( ml->transform.co, mr->transform.co, *item->pf32,
-                  handle->transform.co );
+   ui_px x = 0,
+         spacer = 8;
+   for( u32 draw=0; draw<2; draw ++ )
+   {
+      if( draw )
+      {
+         ui_rect inf_lb = { x, 0, 32, height };
+         ui_fill( inf_lb, lb_down? GUI_COL_NORM: GUI_COL_NORM );
+         ui_text( inf_lb, "\x91", 1, k_ui_align_middle_center, 0 );
       }
+      x += 32 + spacer;
 
-      shader_model_menu_uMdl( mmdl );
-
-      for( u32 j=0; j<item->submesh_count; j++ )
+      for( i32 i=0; i<vg_list_size(opts); i ++ )
       {
-         u32 index = item->submesh_start + j;
-         mdl_submesh *sm = mdl_arritm( &menu.model.submeshs, index );
+         ui_rect box = { x, 0, ui_text_line_width(opts[i]) + 32, height };
 
-         if( sm->material_id != current_mat )
+         if( draw )
          {
-            mdl_material *mat = mdl_arritm( &menu.model.materials, 
-                                            sm->material_id-1 );
-            glActiveTexture( GL_TEXTURE1 );
-
-            if( mat->shader == k_shader_standard ) 
+            enum ui_button_state state = ui_button_base( box );
+            if( state == k_ui_button_click )
             {
-               struct shader_props_standard *props = mat->props.compiled;
-
-               /* FIXME: why does menu have its own texture array?? */
-               glBindTexture( GL_TEXTURE_2D, 
-                              menu.textures[ props->tex_diffuse ] );
+               ui_fill( box, GUI_COL_DARK );
+               menu.main_index = i;
+            }
+            else if( state == k_ui_button_holding_inside )
+            {
+               ui_fill( box, GUI_COL_DARK );
+            }
+            else if( state == k_ui_button_holding_outside )
+            {
+               ui_fill( box, GUI_COL_DARK );
+               ui_outline( box, 1, GUI_COL_CLICK, 0 );
             }
-            else
+            else if( state == k_ui_button_hover )
             {
-               glBindTexture( GL_TEXTURE_2D, vg.tex_missing );
+               ui_fill( box, GUI_COL_NORM );
+               ui_outline( box, 1, GUI_COL_ACTIVE, 0 );
             }
+            else 
+               ui_fill( box, i==menu.main_index? GUI_COL_ACTIVE: GUI_COL_NORM );
 
-            current_mat = sm->material_id;
+            ui_text( box, opts[i], 1, k_ui_align_middle_center, 0 );
          }
 
-         mdl_draw_submesh( sm );
+         x += box[2] + spacer;
       }
-   }
-
-   if( !text_count ) return;
-
-   char buf[ 128 ];
 
-   m4x3f local;
-   m4x3_identity( local );
-
-   font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &menu.view );
-   for( u32 i=0; i<text_count; i++ ){
-      ent_menuitem *item = text_list[ i ];
-      m4x3f transform;
-      mdl_transform_m4x3( &item->transform, transform );
-
-      u32 variant = item->binding.font_variant;
-      menu_binding_string( buf, item->binding.pstr_bind );
-      f32 offset = font3d_string_width( variant, buf );
-
-      local[3][0] = -0.5f * offset;
-      m4x3_mul( transform, local, transform );
+      if( draw )
+      {
+         ui_rect inf_rb = { x, 0, 32, height };
+         ui_fill( inf_rb, rb_down? GUI_COL_NORM: GUI_COL_NORM );
+         ui_text( inf_rb, "\x92", 1, k_ui_align_middle_center, 0 );
+      }
+      x += 32;
 
-      font3d_simple_draw( variant, buf, &menu.view, transform );
+      if( draw )
+         ui_fill( (ui_rect){ x+8,0, vg.window_x-(x+8),height }, GUI_COL_NORM );
+      else
+      {
+         x = vg.window_x/2 - x/2;
+         ui_fill( (ui_rect){ 0, 0, x-8, height }, GUI_COL_NORM );
+      }
    }
-}
-
-static void menu_binding_string( char buf[128], u32 pstr ){
-   vg_str str;
-   vg_strnull( &str, buf, 128 );
 
-   if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_jump" ) ){
-      vg_input_string( &str, input_button_list[k_srbind_jump], 1 );
-   }
-   else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_trick0" ) ){
-      vg_strcat( &str, "SHUVIT " );
-      vg_input_string( &str, input_button_list[k_srbind_trick0], 1 );
-   }
-   else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_trick1" ) ){
-      vg_strcat( &str, "KICKFLIP " );
-      vg_input_string( &str, input_button_list[k_srbind_trick1], 1 );
-   }
-   else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_trick2" ) ){
-      vg_strcat( &str, "TREFLIP " );
-      vg_input_string( &str, input_button_list[k_srbind_trick2], 1 );
-   }
-   else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_grab" ) ){
-      vg_input_string( &str, input_axis_list[k_sraxis_grab], 1 );
-   }
-   else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_grab_mod" ) ){
-      vg_input_string( &str, input_joy_list[k_srjoystick_grab], 1 );
+   if( menu.main_index == 0 )
+   {
    }
    else
-      vg_strcat( &str, "error" );
+   {
+      if( button_down( k_srbind_mback ) )
+      {
+         skaterift.activity = k_skaterift_default;
+         return;
+      }
+   }
+
+   vg_ui.frosting = gui.factive*0.015f;
+   ui_flush( k_ui_shader_colour, vg.window_x, vg.window_y );
+   vg_ui.frosting = 0.0f;
+
+   ui_font_face( &vgf_default_small );
 }
diff --git a/menu.h b/menu.h
index dd9f08e236687ba58cba08029f682f009b4d765f..8e658dcabc73847ac767e57c0c1857251fa7e544 100644 (file)
--- a/menu.h
+++ b/menu.h
@@ -1,4 +1,45 @@
 #pragma once
+
+#define MENU_STACK_SIZE 8
+
+#include "vg/vg_engine.h"
+#include "entity.h"
+
+enum menu_page
+{
+   k_menu_page_any,
+   k_menu_page_starter,
+   k_menu_page_premium,
+   k_menu_page_main
+};
+
+struct global_menu
+{
+   int disable_open;
+   i32 skip_starter;
+   enum menu_page page;
+
+   i32 main_index;
+
+   enum menu_input_mode
+   {
+      k_menu_input_mode_keys,
+      k_menu_input_mode_mouse
+   }
+   input_mode;
+   f32 mouse_dist;  /* used for waking up mouse */
+
+   f32 repeater;
+}
+extern menu;
+
+void menu_init(void);
+void menu_at_begin(void);
+void menu_gui(void);
+void menu_open( enum menu_page page );
+bool menu_viewing_map(void);
+
+#if 0
 #define MENU_STACK_SIZE 8
 
 #include "vg/vg_engine.h"
@@ -19,13 +60,6 @@ struct global_menu
                 *ctr_ps,
                 *ctr_steam,
                 *ctr_xbox;
-
-   enum menu_input_mode{
-      k_menu_input_mode_keys,
-      k_menu_input_mode_mouse
-   }
-   input_mode;
-   f32 mouse_track, mouse_dist;  /* used for waking up mouse */
    f32 slider_offset;
 
    struct page_stack_frame {
@@ -47,10 +81,8 @@ struct global_menu
 }
 extern menu;
 void menu_close(void);
-void menu_init(void);
 void menu_open_page( const char *name, 
                      enum ent_menuitem_stack_behaviour stackmode );
 void menu_link(void);
-void menu_update(void);
 void menu_render(void);
-void menu_at_begin(void);
+#endif
index 7dec1221f5716be7830cc5e05801cbd1ec261b34..4d303ddbfd273c5e2ceac60387fff8848ee7450f 100644 (file)
Binary files a/models_src/rs_icons.mdl and b/models_src/rs_icons.mdl differ
index a60c8c2613aae02452ee8aae98bd0be3724847ab..9ac4849bb77794128dfabe3b9c8fefe36127f6b1 100644 (file)
--- a/player.c
+++ b/player.c
@@ -270,7 +270,6 @@ void player__im_gui(void)
                                        [k_skaterift_replay]    = "replay",
                                        [k_skaterift_ent_focus] = "ent_focus",
                                        [k_skaterift_default]   = "default",
-                                       [k_skaterift_world_map] = "world map"
                      } [skaterift.activity] );
    player__debugtext( 1, "time_rate: %.4f", skaterift.time_rate );
 
index d661fbf90501a2d1d7329df8bd418fc4b602bd02..dd040152a60962e00f1561201b2f8503338d4687 100644 (file)
@@ -261,7 +261,6 @@ void vg_load(void)
    vg_async_stall();
 
    vg_console_load_autos();
-   menu_link();
 
    addon_mount_content_folder( k_addon_type_player, 
                                "playermodels", ".mdl" );
@@ -310,8 +309,7 @@ void vg_pre_update(void)
 
    /* time rate */
    f32 target = 1;
-   if( skaterift.activity & (k_skaterift_replay|k_skaterift_menu|
-                             k_skaterift_world_map) )
+   if( skaterift.activity & (k_skaterift_replay|k_skaterift_menu) )
    {
       target = 0;
    }
@@ -426,7 +424,7 @@ static void present_view_with_post_processing(void){
       shader_blitblur_uGlitchStrength( glitch_strength );
 
       v2f override;
-      if( skaterift.activity == k_skaterift_menu )
+      if( (skaterift.activity == k_skaterift_menu) && !menu_viewing_map() )
          v2_muls( (v2f){ 0.04f, 0.001f }, 1.0f-skaterift.time_rate, override );
       else 
          v2_zero( override );
@@ -473,17 +471,21 @@ static world_instance *get_view_world(void){
    return view_world;
 }
 
-static void render_scene(void){
+static void render_scene(void)
+{
    /* Draw world */
    glEnable( GL_DEPTH_TEST );
 
-   for( u32 i=0; i<vg_list_size(world_static.instances); i++ ){
-      if( world_static.instances[i].status == k_world_status_loaded ){
+   for( u32 i=0; i<vg_list_size(world_static.instances); i++ )
+   {
+      if( world_static.instances[i].status == k_world_status_loaded )
+      {
          world_prerender( &world_static.instances[i] );
       }
    }
 
-   if( skaterift.activity == k_skaterift_world_map ){
+   if( menu_viewing_map() )
+   {
       world_instance *world = world_current_instance();
       glDrawBuffers( 1, (GLenum[]){ GL_COLOR_ATTACHMENT0 } );
       
@@ -506,7 +508,7 @@ static void render_scene(void){
       m4x3f identity;
       m4x3_identity( identity );
       render_world_override( world, world, identity, &skaterift.cam, 
-                             world_map.spawn, 
+                             world_map.close_spawn, 
                              (v4f){world->tar_min, world->tar_max, 1.0f, 0.0f});
       render_world_routes( world, world, identity, &skaterift.cam, 0, 1 );
       return;
@@ -587,7 +589,8 @@ static void skaterift_composite_maincamera(void)
    skaterift.cam.nearz = 0.1f;
    skaterift.cam.farz  = 2100.0f;
 
-   if( skaterift.activity == k_skaterift_world_map ){
+   if( menu_viewing_map() )
+   {
       vg_camera_copy( &world_map.cam, &skaterift.cam );
       skaterift.cam.nearz = 4.0f;
       skaterift.cam.farz = 3100.0f;
@@ -626,7 +629,8 @@ static void render_main_game(void){
    skaterift_composite_maincamera();
 
    /* --------------------------------------------------------------------- */
-   if( skaterift.activity != k_skaterift_world_map ){
+   if( menu_viewing_map() )
+   {
       world_instance *world = world_current_instance();
       render_world_cubemaps( world );
 
@@ -652,8 +656,8 @@ static void render_main_game(void){
                                    portals */
 
    /* continue with variable rate */
-   if( !global_miniworld.transition && 
-         (skaterift.activity != k_skaterift_world_map) ){
+   if( !global_miniworld.transition && !menu_viewing_map() )
+   {
       render_fb_bind( gpipeline.fb_main, 1 );
       render_world_gates( get_view_world(), &skaterift.cam );
    }
@@ -727,12 +731,7 @@ void vg_gui(void)
    vg_ui.tex_bg = gpipeline.fb_main->attachments[0].id;
    render_fb_inverse_ratio( gpipeline.fb_main, vg_ui.bg_inverse_ratio );
 
-   menu_update();
-   if( skaterift.activity == k_skaterift_menu ){
-      glClear( GL_DEPTH_BUFFER_BIT );
-      menu_render();
-   }
-
+   menu_gui();
    player__im_gui();
    world_instance *world = world_current_instance();
 
@@ -742,11 +741,13 @@ void vg_gui(void)
    render_view_framebuffer_ui();
    remote_player_network_imgui( vg.pv );
 
-   if( skaterift.activity == k_skaterift_world_map ){
+   if( menu_viewing_map() )
+   {
       remote_players_imgui_world( world_current_instance(), vg.pv, 2000.0f, 0 );
       remote_players_imgui_lobby();
    }
-   else {
+   else 
+   {
       remote_players_chat_imgui(); /* TODO: conditional */
       remote_players_imgui_world( world_current_instance(), vg.pv, 100.0f, 1 );
    }
index 4ea1b888edacf43d1030594219f907cb07976bff..85eb8554055f892f4b28d19beaaaf70c37e36ba0 100644 (file)
@@ -27,7 +27,6 @@ struct skaterift_globals
       k_skaterift_replay     = 0x01,
       k_skaterift_ent_focus  = 0x02,
       k_skaterift_menu       = 0x04,
-      k_skaterift_world_map  = 0x08,
    }
    activity;
    GLuint rt_textures[k_skaterift_rt_max];
index 3465776c7bd6a5d44efba6752d19354f4489d90d..13de85cb735a09abf66eb6702952bfd2ae84dc4f 100644 (file)
@@ -8,7 +8,8 @@
 
 struct world_map world_map;
 
-static void world_map_get_dir( v3f dir ){
+static void world_map_get_dir( v3f dir )
+{
    /* idk */
    dir[0] = -sqrtf(0.5f);
    dir[2] =  sqrtf(0.5f);
@@ -16,7 +17,8 @@ static void world_map_get_dir( v3f dir ){
    v3_normalize(dir);
 }
 
-static void world_map_get_plane( v4f plane ){
+static void world_map_get_plane( v4f plane )
+{
    world_instance *world = &world_static.instances[ world_map.world_id ];
    f32 h = localplayer.rb.co[1];
    if( world_map.world_id != world_static.active_instance )
@@ -25,7 +27,8 @@ static void world_map_get_plane( v4f plane ){
    v4_copy( (v4f){0.0f,1.0f,0.0f,h}, plane );
 }
 
-static void respawn_world_to_plane_pos( v3f pos, v2f plane_pos ){
+static void respawn_world_to_plane_pos( v3f pos, v2f plane_pos )
+{
    v3f dir;
    world_map_get_dir( dir );
    v3_negate(dir,dir);
@@ -40,37 +43,79 @@ static void respawn_world_to_plane_pos( v3f pos, v2f plane_pos ){
 }
 
 static void respawn_map_draw_icon( vg_camera *cam, 
-                                   enum gui_icon icon, v3f pos ){
+                                   enum gui_icon icon, v3f pos, f32 size )
+{
    v4f v;
    v3_copy( pos, v );
    v[3] = 1.0f;
    m4x4_mulv( cam->mtx.pv, v, v );
    v2_divs( v, v[3], v );
 
-   gui_draw_icon( icon, (v2f){ v[0]*0.5f+0.5f,v[1]*0.5f+0.5f }, 1.0f );
+   gui_draw_icon( icon, (v2f){ v[0]*0.5f+0.5f,v[1]*0.5f+0.5f }, size );
 }
 
-void world_map_pre_update(void)
+static void world_map_select_close(void)
 {
-   if( skaterift.activity != k_skaterift_world_map ) return;
-
-   if( button_down( k_srbind_mback ) ){
-      gui_helper_clear();
-      srinput.state = k_input_state_resume;
-      skaterift.activity = k_skaterift_menu;
-      menu.page = 0xffffffff;
-      menu_open_page( "Main Menu", k_ent_menuitem_stack_append );
-      return;
-   }
+   world_map.sel_spawn = world_map.close_spawn;
+   gui_helper_clear();
+
+   vg_str text;
+   if( gui_new_helper( input_button_list[k_srbind_maccept], &text ) )
+      vg_strcat( &text, "Spawn Here" );
+   if( gui_new_helper( input_button_list[k_srbind_mback], &text ) )
+      vg_strcat( &text, "Back" );
+}
 
-   if( button_down( k_srbind_maccept ) ){
-      skaterift.activity = k_skaterift_default;
-      srinput.state = k_input_state_resume;
+void world_map_click(void)
+{
+   world_map_select_close();
+}
 
-      if( world_map.spawn ){
-         world_static.active_instance = world_map.world_id;
-         player__spawn( world_map.spawn );
+static void world_map_help_normal(void)
+{
+   gui_helper_clear();
+
+   vg_str text;
+   if( gui_new_helper( input_joy_list[k_srjoystick_steer], &text ) )
+      vg_strcat( &text, "Move" );
+
+   if( gui_new_helper( input_button_list[k_srbind_maccept], &text ) )
+      vg_strcat( &text, "Select" );
+
+   if( gui_new_helper( input_button_list[k_srbind_mback], &text ) )
+      vg_strcat( &text, "Exit" );
+}
+
+void world_map_pre_update(void)
+{
+   if( menu_viewing_map() )
+   {
+      if( !world_map.view_ready )
+      {
+         world_map.world_id = world_static.active_instance;
+
+         world_instance *world = &world_static.instances[ world_map.world_id ];
+         v3f *bbx = world->scene_geo.bbx;
+
+         v3_copy( localplayer.rb.co, world->player_co );
+         respawn_world_to_plane_pos( localplayer.rb.co, world_map.plane_pos );
+         world_map.boom_dist = 400.0f;
+         world_map.home_select = 0;
+         world_map.view_ready = 1;
+         world_map.sel_spawn = NULL;
+         world_map.close_spawn = NULL;
+
+         world_map_help_normal();
       }
+   }
+   else
+   {
+      if( world_map.view_ready )
+      {
+         gui_helper_clear();
+         world_map.view_ready = 0;
+      }
+
       return;
    }
 
@@ -82,11 +127,28 @@ void world_map_pre_update(void)
    joystick_state( k_srjoystick_steer, steer );
    v2_normalize_clamp( steer );
 
-   m2x2f rm;
-   m2x2_create_rotation( rm, -0.25f*VG_PIf );
-   m2x2_mulv( rm, steer, steer );
+   if( !world_map.sel_spawn )
+   {
+      f32 *pos = world_map.plane_pos;
+      m2x2f rm;
+      m2x2_create_rotation( rm, -0.25f*VG_PIf );
+      m2x2_mulv( rm, steer, steer );
+      v2_muladds( pos, steer, vg.time_frame_delta * 200.0f, pos );
+   }
+
+   f32 bd_target = 400.0f,
+       interp = vg.time_frame_delta*2.0f;
+
+   if( world_map.sel_spawn )
+   {
+      v2f pp;
+      respawn_world_to_plane_pos( world_map.sel_spawn->transform.co, pp );
+      v2_lerp( pos, pp, interp, pos );
+
+      bd_target = 200.0f;
+   }
+   world_map.boom_dist = vg_lerpf( world_map.boom_dist, bd_target, interp );
 
-   v2_muladds( pos, steer, vg.time_frame_delta * 200.0f, pos );
    v2_minv( (v2f){ bbx[1][0], bbx[1][2] }, pos, pos );
    v2_maxv( (v2f){ bbx[0][0], bbx[0][2] }, pos, pos );
 
@@ -115,10 +177,11 @@ void world_map_pre_update(void)
    vg_camera_finalize( cam );
 
    /* pick spawn */
-   world_map.spawn = NULL;
    f32 closest2 = INFINITY;
+   v2f centroid = { 0, 0 };
 
-   for( u32 i=0; i<mdl_arrcount(&world->ent_spawn); i++ ){
+   for( u32 i=0; i<mdl_arrcount(&world->ent_spawn); i++ )
+   {
       ent_spawn *spawn = mdl_arritm(&world->ent_spawn,i);
 
       v4f v;
@@ -127,43 +190,97 @@ void world_map_pre_update(void)
       m4x4_mulv( cam->mtx.pv, v, v );
       v2_divs( v, v[3], v );
 
-      f32 d2 = v2_length2(v);
-      if( d2 < closest2 ){
-         world_map.spawn = spawn;
+      f32 d2 = v2_dist2(v, centroid);
+      if( d2 < closest2 )
+      {
+         world_map.close_spawn = spawn;
          closest2 = d2;
       }
+      spawn->transform.s[0] = d2;
+   }
+
+   if( button_down( k_srbind_maccept ) )
+   {
+      if( world_map.sel_spawn )
+      {
+         skaterift.activity = k_skaterift_default;
+         world_static.active_instance = world_map.world_id;
+         srinput.state = k_input_state_resume;
+         player__spawn( world_map.sel_spawn );
+         return;
+      }
+      else
+      {
+         world_map_select_close();
+      }
+   }
+
+   if( button_down( k_srbind_mback ) )
+   {
+      if( world_map.sel_spawn )
+      {
+         world_map.sel_spawn = NULL;
+         world_map_help_normal();
+      }
+      else
+      {
+         srinput.state = k_input_state_resume;
+         skaterift.activity = k_skaterift_default;
+         return;
+      }
    }
 
    /* icons
     * ---------------------*/
-   for( u32 i=0; i<mdl_arrcount(&world->ent_challenge); i++ ){
+   for( u32 i=0; i<mdl_arrcount(&world->ent_challenge); i++ )
+   {
       ent_challenge *challenge = mdl_arritm( &world->ent_challenge, i );
 
       enum gui_icon icon = k_gui_icon_exclaim_2d;
       if( challenge->status )
          icon = k_gui_icon_tick_2d;
 
-      respawn_map_draw_icon( cam, icon, challenge->transform.co );
+      respawn_map_draw_icon( cam, icon, challenge->transform.co, 1.0f );
    }
 
-   for( u32 i=0; i<mdl_arrcount(&world->ent_skateshop); i++ ){
+   for( u32 i=0; i<mdl_arrcount(&world->ent_spawn); i ++ )
+   {
+      ent_spawn *spawn = mdl_arritm( &world->ent_spawn, i );
+
+      if( spawn->transform.s[0] > 0.3f )
+         continue;
+
+      f32 s = 1.0f-(spawn->transform.s[0] / 0.3f);
+      respawn_map_draw_icon( cam, 
+            spawn==world_map.sel_spawn? 
+               k_gui_icon_spawn_select: k_gui_icon_spawn,
+            spawn->transform.co, s );
+   }
+
+   for( u32 i=0; i<mdl_arrcount(&world->ent_skateshop); i++ )
+   {
       ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, i );
-      if( shop->type == k_skateshop_type_boardshop ){
-         respawn_map_draw_icon( cam, k_gui_icon_board, shop->transform.co );
+      if( shop->type == k_skateshop_type_boardshop )
+      {
+         respawn_map_draw_icon( cam, k_gui_icon_board, shop->transform.co, 1 );
       }
-      else if( shop->type == k_skateshop_type_worldshop ){
-         respawn_map_draw_icon( cam, k_gui_icon_world, shop->transform.co );
+      else if( shop->type == k_skateshop_type_worldshop )
+      {
+         respawn_map_draw_icon( cam, k_gui_icon_world, shop->transform.co, 1 );
       }
    }
 
-   for( u32 i=0; i<mdl_arrcount(&world->ent_gate); i++ ){
+   for( u32 i=0; i<mdl_arrcount(&world->ent_gate); i++ )
+   {
       ent_gate *gate = mdl_arritm( &world->ent_gate, i );
-      if( gate->flags & k_ent_gate_nonlocal ){
-         respawn_map_draw_icon( cam, k_gui_icon_rift, gate->co[0] );
+      if( gate->flags & k_ent_gate_nonlocal )
+      {
+         respawn_map_draw_icon( cam, k_gui_icon_rift, gate->co[0], 1 );
       }
    }
 
-   for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
+   for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ )
+   {
       ent_route *route = mdl_arritm( &world->ent_route, i );
 
       v4f colour;
@@ -171,10 +288,11 @@ void world_map_pre_update(void)
       v3_muls( colour, 1.6666f, colour );
       gui_icon_setcolour( colour );
       respawn_map_draw_icon( cam, k_gui_icon_rift_run_2d, 
-                             route->board_transform[3] );
+                             route->board_transform[3], 1 );
    }
 
-   for( u32 i=0; i<mdl_arrcount(&world->ent_glider); i ++ ){
+   for( u32 i=0; i<mdl_arrcount(&world->ent_glider); i ++ )
+   {
       ent_glider *glider = mdl_arritm( &world->ent_glider, i );
 
       v4f colour = { 1,1,1,1 };
@@ -183,31 +301,6 @@ void world_map_pre_update(void)
          v3_muls( colour, 0.5f, colour );
       gui_icon_setcolour( colour );
 
-      respawn_map_draw_icon( cam, k_gui_icon_glider, glider->transform.co );
+      respawn_map_draw_icon( cam, k_gui_icon_glider, glider->transform.co, 1 );
    }
 }
-
-void world_map_enter(void)
-{
-   skaterift.activity = k_skaterift_world_map;
-   world_map.world_id = world_static.active_instance;
-
-   world_instance *world = &world_static.instances[ world_map.world_id ];
-   v3f *bbx = world->scene_geo.bbx;
-
-   respawn_world_to_plane_pos( localplayer.rb.co, world_map.plane_pos );
-   world_map.boom_dist = 400.0f;
-   world_map.home_select = 0;
-
-   gui_helper_clear();
-
-   vg_str text;
-   if( gui_new_helper( input_joy_list[k_srjoystick_steer], &text ) )
-      vg_strcat( &text, "Move" );
-
-   if( gui_new_helper( input_button_list[k_srbind_maccept], &text ) )
-      vg_strcat( &text, "Spawn" );
-
-   if( gui_new_helper( input_button_list[k_srbind_mback], &text ) )
-      vg_strcat( &text, "Exit" );
-}
index d4be3b55cb1c2f1ae6741e48156a8dd60b4b491a..3899363ff1c7dbf3483cd6d9013b73d76e20f1f8 100644 (file)
@@ -10,9 +10,10 @@ struct world_map
    u32 world_id;
    u32 home_select;
 
-   ent_spawn *spawn;
+   ent_spawn *sel_spawn, *close_spawn;
    vg_camera cam;
+
+   bool view_ready;
 }
 extern world_map;
-void world_map_enter(void);
 void world_map_pre_update(void);
index 4b6568b2651f3247dd3bc0d638bf9418790e3d82..ea582356c4cee9d70199e4b94ac9739cd18fcc73 100644 (file)
@@ -1201,7 +1201,6 @@ void render_world_override( world_instance *world,
    v4f uPlayerPos, uSpawnPos;
    v4_zero( uPlayerPos );
    v4_zero( uSpawnPos );
-
    v3_copy( world->player_co, uPlayerPos );
    
    if( dest_spawn && (v3_dist2(dest_spawn->transform.co,uPlayerPos) > 0.1f) )