the pain is gone
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_skateshop.c
index b126abf3a3defee29929916521ff765378568bee..6cf47dc69cd1fb5192d23a291b65a3c301d545bc 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "world.h"
 #include "player.h"
+#include "gui.h"
 
 #define MAX_LOCAL_BOARDS 64
 #define BILL_TIN_BOARDS  1
 
 struct{
    v3f look_target;
-   mdl_transform rack_root,
-                 display_root,
-                 info_root;
-
-   enum camera_mode prev_camera_mode;
+   ent_skateshop *ptr_ent;
 
    int active;
    float factive;
@@ -326,8 +323,9 @@ next_file: tinydir_next( &dir );
 
 VG_STATIC void global_skateshop_exit(void)
 {
+   vg_info( "exit skateshop\n" );
+   localplayer.immobile = 0;
    global_skateshop.active = 0;
-   localplayer.camera_mode = global_skateshop.prev_camera_mode;
 }
 
 VG_STATIC void skateshop_request_viewpage( u32 page )
@@ -390,8 +388,6 @@ VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call )
       vg_info( "Entering skateshop\n" );
 
       localplayer.immobile = 1;
-      global_skateshop.prev_camera_mode = localplayer.camera_mode;
-      localplayer.camera_mode = k_cam_firstperson;
       global_skateshop.active = 1;
       global_skateshop.interface_loc = k_skateshop_loc_page__viewing;
 
@@ -399,32 +395,7 @@ VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call )
       v3_zero( localplayer.rb.w );
       localplayer._walk.move_speed = 0.0f;
 
-      struct{
-         mdl_transform *transform;
-         u32 id;
-      }
-      targets[] = {
-         { &global_skateshop.rack_root, shop->id_rack, },
-         { &global_skateshop.info_root, shop->id_info, },
-         { &global_skateshop.display_root, shop->id_display, },
-      };
-      
-      v3_copy( shop->transform.co, global_skateshop.look_target );
-
-      for( u32 i=0; i<vg_list_size(targets); i++ ){
-         
-         u32 type = mdl_entity_id_type( targets[i].id ),
-             index = mdl_entity_id_id( targets[i].id );
-
-         if( type == k_ent_marker ){
-            ent_marker *m = mdl_arritm( &world->ent_marker, index );
-
-            *targets[i].transform = m->transform;
-         }
-         else{
-            transform_identity( targets[i].transform );
-         }
-      }
+      global_skateshop.ptr_ent = shop;
 
       skateshop_request_viewpage(0);
       skateshop_loader_start( skateshop_scan_for_items );
@@ -437,69 +408,71 @@ VG_STATIC void global_skateshop_preupdate(void)
    global_skateshop.factive = vg_lerpf( global_skateshop.factive, 
                                         global_skateshop.active, rate );
 
-
    if( !global_skateshop.active ) return;
 
-   v3f delta;
-   v3_sub( global_skateshop.look_target, localplayer.cam.pos, delta );
-   v3_normalize( delta );
+   world_instance *world = get_active_world();
 
-   v3f target;
-   player_vector_angles( target, delta, 1.0f, 0.0f );
+   ent_skateshop *shop = global_skateshop.ptr_ent;
+   ent_camera *ref = mdl_arritm( &world->ent_camera, 
+                                 mdl_entity_id_id(shop->id_camera) );
+   ent_marker *display = mdl_arritm( &world->ent_marker,
+                                 mdl_entity_id_id(shop->id_display) );
+   
+   v3f dir = {0.0f,-1.0f,0.0f};
+   mdl_transform_vector( &ref->transform, dir, dir );
+   player_vector_angles( localplayer.cam_override_angles, dir, 1.0f, 0.0f );
+   
+   v3f lookat;
+   v3_sub( display->transform.co, localplayer.rb.co, lookat );
+   
+   q_axis_angle( localplayer.rb.q, (v3f){0.0f,1.0f,0.0f}, 
+                 atan2f(lookat[0],lookat[2]) );
 
-   camera_lerp_angles( localplayer.angles, target,
-                       global_skateshop.factive, localplayer.angles);
+   v3_copy( ref->transform.co, localplayer.cam_override_pos );
+   localplayer.cam_override_fov = ref->fov;
+
+   localplayer.cam_override_strength = global_skateshop.factive;
 
    if( global_skateshop.interaction_cooldown > 0.0f ){
       global_skateshop.interaction_cooldown -= vg.time_delta;
       return;
    }
 
-   float h = localplayer.input_js1h->axis.value;
-
    if( global_skateshop.interface_loc <= k_skateshop_loc_page__viewing ){
-      if( fabsf(h) > 0.25f ){
-         if( h < 0.0f ){
-            if( global_skateshop.selected_registry_id > 0 )
-               global_skateshop.selected_registry_id --;
+
+      gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" );
+      gui_helper_action( button_display_string( k_srbind_maccept ), "pick" );
+      gui_helper_action( button_display_string( k_srbind_mback ), "exit" );
+      
+      int moved = 0;
+
+      if( button_down( k_srbind_mleft ) ){
+         if( global_skateshop.selected_registry_id > 0 ){
+            global_skateshop.selected_registry_id --;
+            moved = 1;
          }
-         else{
-            if( global_skateshop.selected_registry_id < 
-                     global_skateshop.registry_count-1 )
-            {
-               global_skateshop.selected_registry_id ++;
-            }
+      }
+
+      if( button_down( k_srbind_mright ) ){
+         if( global_skateshop.selected_registry_id < 
+                  global_skateshop.registry_count-1 )
+         {
+            global_skateshop.selected_registry_id ++;
+            moved = 1;
          }
+      }
 
+      if( moved ){
          vg_info( "Select registry: %u\n", 
                   global_skateshop.selected_registry_id );
          global_skateshop.interaction_cooldown = 0.125f;
          return;
       }
 
-      if( vg_input_button_down( &input_menu_back ) ){
-         global_skateshop.active = 0;
-         return;
-      }
-   }
-   else if( global_skateshop.interface_loc <= k_skateshop_loc_page__selected ){
-      if( vg_input_button_down( &input_menu_back ) ){
-         global_skateshop.interface_loc = k_skateshop_loc_page__viewing;
+      if( button_down( k_srbind_mback ) ){
+         global_skateshop_exit();
          return;
       }
-
-      if( fabsf(h) > 0.25f ){
-         if( global_skateshop.interface_loc == k_skateshop_loc_select_use ){
-            global_skateshop.interface_loc = k_skateshop_loc_select_cancel;
-            return;
-         }
-      }
-      else{
-         if( global_skateshop.interface_loc == k_skateshop_loc_select_cancel ){
-            global_skateshop.interface_loc = k_skateshop_loc_select_use;
-            return;
-         }
-      }
    }
 }
 
@@ -534,6 +507,7 @@ VG_STATIC void skateshop_render(void)
 {
    if( !global_skateshop.active ) return;
       
+   ent_skateshop *shop = global_skateshop.ptr_ent;
    world_instance *world = get_active_world();
 
    u32 slot_count = vg_list_size(global_skateshop.shop_view_slots);
@@ -549,28 +523,29 @@ VG_STATIC void skateshop_render(void)
       if( slot->db->state != k_dynamic_board_state_loaded ) 
          goto set_fade_amt;
 
-      mdl_transform rack_xform;
-      transform_identity( &rack_xform );
+      mdl_transform xform;
+      transform_identity( &xform );
 
-      rack_xform.co[0] = -((float)i - ((float)slot_count)*0.5f)*0.45f;
+      xform.co[0] = -((float)i - ((float)slot_count)*0.5f)*0.45f;
 
-      mdl_transform_mul( &global_skateshop.rack_root, 
-                         &rack_xform, &rack_xform );
+      ent_marker *rack = mdl_arritm( &world->ent_marker, 
+                                     mdl_entity_id_id(shop->id_rack)),
+                 *display = mdl_arritm( &world->ent_marker,
+                                     mdl_entity_id_id(shop->id_display));
+
+      mdl_transform_mul( &rack->transform, &xform, &xform );
 
       if( slot->db->registry_id == global_skateshop.selected_registry_id ){
          selected = 1.0f;
       }
 
       float t = slot->view_blend;
-      v3_lerp( rack_xform.co, global_skateshop.display_root.co, 
-               t, rack_xform.co );
-      q_nlerp( rack_xform.q, global_skateshop.display_root.q, 
-               t, rack_xform.q );
-      v3_lerp( rack_xform.s, global_skateshop.display_root.s, 
-               t, rack_xform.s );
+      v3_lerp( xform.co, display->transform.co, t, xform.co );
+      q_nlerp( xform.q, display->transform.q, t, xform.q );
+      v3_lerp( xform.s, display->transform.s, t, xform.s );
 
       m4x3f mmdl;
-      mdl_transform_m4x3( &rack_xform, mmdl );
+      mdl_transform_m4x3( &xform, mmdl );
       render_board( &main_camera, world, &slot->db->board, mmdl,
                     k_board_shader_entity );
 
@@ -579,21 +554,38 @@ set_fade_amt:;
       slot->view_blend = vg_lerpf( slot->view_blend, selected, rate );
    }
 
+   ent_marker *info = mdl_arritm( &world->ent_marker, 
+                                  mdl_entity_id_id(shop->id_info));
    m4x3f mtext;
-   mdl_transform_m4x3( &global_skateshop.info_root, mtext );
+   mdl_transform_m4x3( &info->transform, mtext );
+
+   const char *text_title = "Fish - Title";
+   const char *text_author = "by Shaniqua";
 
-   m4x3f mlocal = {{0.2f,0.0f,0.0f},{0.0f,0.2f,0.0f},{0.0f,0.0f,0.03f},
-                   {-font3d_string_width( &world_global.font,0, 
-                        "Made by... Bob man 123" )*0.2f*0.5f,0.0f,0.0f}
-   };
+   m4x3f mlocal, mmdl;
+   m4x3_identity( mlocal );
 
-   m4x3_mul( mtext, mlocal, mtext );
+   float scale = 0.2f;
+
+   mlocal[0][0] = scale; mlocal[1][1] = scale;
+   mlocal[2][2] = 0.03f;
+   mlocal[3][0] = -font3d_string_width(&world_global.font,0,text_title);
+   mlocal[3][0] *= scale*0.5f;
+   mlocal[3][1] = 0.1f;
+   m4x3_mul( mtext, mlocal, mmdl );
 
    font3d_bind( &world_global.font, &main_camera );
 
-   shader_model_font_uColour( (v4f){1.0f,0.5f,0.1f,1.0f} );
-   font3d_simple_draw( &world_global.font, 0, "Made by... Bob man 123",
-                       &main_camera, mtext );
+   shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
+   font3d_simple_draw( &world_global.font, 0, text_title, &main_camera, mmdl );
+
+   scale *= 0.4f;
+   mlocal[0][0] = scale; mlocal[1][1] = scale;
+   mlocal[3][0] = -font3d_string_width(&world_global.font,0,text_author);
+   mlocal[3][0] *= scale*0.5f;
+   mlocal[3][1] = 0.0f;
+   m4x3_mul( mtext, mlocal, mmdl );
+   font3d_simple_draw( &world_global.font, 0, text_author, &main_camera, mmdl );
 }
 
 #endif /* ENT_SKATESHOP_C */