smooth block ui
authorhgn <hgodden00@gmail.com>
Sat, 25 Nov 2023 08:54:42 +0000 (08:54 +0000)
committerhgn <hgodden00@gmail.com>
Sat, 25 Nov 2023 08:54:42 +0000 (08:54 +0000)
entity.h
world_routes.c
world_routes_ui.c

index 13051d4f9b0eafd5fae78377ae4e2060f49ed1f3..bd487090c7ca30eb631c44d685432756a07a5360 100644 (file)
--- a/entity.h
+++ b/entity.h
@@ -207,6 +207,9 @@ struct ent_route{
    /* v104+, but always accessible */
    u32 flags;
    f64 best_laptime;
+   f32 ui_stopper, ui_residual;
+
+   ui_px ui_first_block_width, ui_residual_block_w;
 };
 
 struct ent_water{
index e0b5fa3f0498c211a108155c01743f960850a1fa..0bfdcac8bf92ac1406032a6f0c427f73e04ecad4 100644 (file)
@@ -135,6 +135,9 @@ static void world_routes_time_lap( world_instance *world, ent_route *route ){
 
    vg_info( "valid sections: %u\n", valid_sections );
    vg_info( "----------------------------\n" );
+
+   route->ui_residual = 1.0f;
+   route->ui_residual_block_w = route->ui_first_block_width;
 }
 
 /*
@@ -554,6 +557,8 @@ static void world_gen_routes_ent_init( world_instance *world ){
 
       route->flags = 0x00;
       route->best_laptime = 0.0;
+      route->ui_stopper = 0.0f;
+      route->ui_residual = 0.0f;
       
       if( mdl_arrcount(&world->ent_region) )
          route->flags |= k_ent_route_flag_out_of_zone;
index 319870a9f85658971ceaf5456de942ac0ac9aafb..4d39e9cce004542603187eaf9438adfe465bcee7 100644 (file)
@@ -62,12 +62,34 @@ static void ent_route_imgui( world_instance *world, ent_route *route,
    u32 colour = v4_rgba( route->colour ) | 0xff000000;
 
    ui_px x = 0,
-         h = route->factive * 16.0f;
+         h = route->factive * 16.0f,
+         base = inout_cursor[0];//(f32)vg.window_x*0.5f - route->ui_stopper;
+
+   if( route->ui_residual > 0.0f ){
+      ui_px w = route->ui_residual_block_w,
+            total = w + 4;
+
+      f32 t = vg_smoothstepf(1.0f-route->ui_residual);
+      
+      x -= (f32)total * t;
+
+      ui_rect rect = { base+x, inout_cursor[1], w, h };
+
+      v4f fadecolour;
+      v4_copy( route->colour, fadecolour );
+      fadecolour[3] *= route->ui_residual;
+
+      ui_fill( rect, v4_rgba(fadecolour) );
+
+      x += total;
+   }
+
+   int got_first = 0;
 
    for( u32 i=0; i<valid_sections; i ++ ){
       struct time_block *block = &blocks[ i ];
       ui_px w = 20 + (block->length * 6.0f);
-      ui_rect rect = { x, inout_cursor[1], w, h };
+      ui_rect rect = { base+x, inout_cursor[1], w, h };
       ui_fill( rect, colour );
    
       if( block->clean )
@@ -83,7 +105,7 @@ static void ent_route_imgui( world_instance *world, ent_route *route,
              s  = floorf( as ),
              ds = floorf( vg_fractf( as ) * 10.0f );
 
-         if( (block->best != 0.0f) && (fabsf(diff) > 0.02f) ){
+         if( (block->best != 0.0f) && (fabsf(diff) > 0.001f) ){
             if( diff > 0.0f )
                vg_strcatch( &str, '+' );
             else
@@ -98,22 +120,36 @@ static void ent_route_imgui( world_instance *world, ent_route *route,
       }
 
       x += w + 4;
+
+      if( !got_first ){
+         route->ui_first_block_width = w;
+         got_first = 1;
+      }
    }
 
    for( u32 i=0; i<route->checkpoints_count-valid_sections; i++ ){
       struct time_block *block = &blocks[ i ];
 
       ui_px w = 20;
-      ui_rect rect = { x, inout_cursor[1], w, h };
+      ui_rect rect = { base+x, inout_cursor[1], w, h };
       ui_outline( rect, -1, colour, 0 );
       x += w + 4;
+
+      if( !got_first ){
+         route->ui_first_block_width = w;
+         got_first = 1;
+      }
    }
 
    inout_cursor[1] += h + 4;
+
+   vg_slewf( &route->ui_residual, 0.0f, vg.time_frame_delta );
+   route->ui_stopper = vg_lerpf( route->ui_stopper, (f32)x*0.5f, 
+                                 vg.time_frame_delta );
 }
 
 static void world_routes_imgui( world_instance *world ){
-   ui_point cursor = { 0, 0 };
+   ui_point cursor = { 4, 4 };
    for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
       ent_route_imgui( world, mdl_arritm( &world->ent_route, i ), cursor );
    }