cleaned level selection
authorhgn <hgodden00@gmail.com>
Wed, 5 Jan 2022 11:59:16 +0000 (11:59 +0000)
committerhgn <hgodden00@gmail.com>
Wed, 5 Jan 2022 11:59:16 +0000 (11:59 +0000)
fishladder.c
fishladder_resources.h

index e671208e560f6c6558f04c061d84ee72ab7bf3b2..d663fd75927207502217807753fbe318c022601d 100644 (file)
@@ -14,10 +14,9 @@ enum world_button_mode
 struct world_button
 {
        v2i position;
-       v3f colour;
 
-       float light_target, light;
-       int state, click_grab;
+       float light_target, light, extra_light;
+       int state;
 
        enum world_button_mode mode;
 };
@@ -192,18 +191,9 @@ struct world_static
 world_static =
 {
        .buttons = {
-               {
-                       .colour = { 0.204f, 0.345f, 0.553f },
-                       .mode = k_world_button_mode_toggle
-               },
-               {
-                       .colour = { 0.204f, 0.345f, 0.553f },
-                       .mode = k_world_button_mode_toggle
-               },
-               {
-                       .colour = { 0.553f, 0.345f, 0.204f },
-                       .mode = k_world_button_mode_toggle
-               },
+               { .mode = k_world_button_mode_toggle },
+               { .mode = k_world_button_mode_toggle },
+               { .mode = k_world_button_mode_toggle },
                {
                        // TODO: Settings button and menu
                }
@@ -940,13 +930,21 @@ static int map_load( const char *str, const char *name )
                for( int i = 0; i < vg_list_size( career_packs ); i ++ )
                {
                        struct career_level_pack *grid = &career_packs[ i ];
-                       
+               
+                       int j = 0;
+
                        for( int y = 0; y < grid->dims[1]; y ++ )
                        {
                                for( int x = 0; x < grid->dims[0]; x ++ )
                                {
                                        u8 *px = &info_buffer[((y+16+grid->origin[1])*64+16+x+grid->origin[0])*4];
                                        px[0] = 0x10;
+
+                                       if( j < grid->count )
+                                       {
+                                               struct cmp_level *lvl = &grid->pack[ j ++ ];
+                                               v2i_add( grid->origin, (v2i){x,y}, lvl->btn.position );
+                                       }
                                }
                        }
                }
@@ -2206,10 +2204,22 @@ static void render_tiles( v2i start, v2i end, v4f const regular_colour, v4f cons
        }
 }
 
-static int world_button_exec( struct world_button *btn, v2f texture, enum world_button_status *status )
+static int world_button_exec( struct world_button *btn, v2f texture, v3f colour, enum world_button_status *status )
 {
+       static v2i click_grab = { -9999, -9999 };
+
+       // Reset click_grab
+       if( !btn )
+       {
+               click_grab[0] = -9999;
+               click_grab[1] = -9999;
+               return 0;
+       }
+
+       v2i click_tile = { world.tile_x, world.tile_y };
+
        int triggered = 0;
-       int is_hovering = v2i_eq( (v2i){ world.tile_x, world.tile_y }, btn->position );
+       int is_hovering = v2i_eq( click_tile, btn->position );
 
        // Set up light targets before logic runs
        if( btn->state )
@@ -2224,10 +2234,8 @@ static int world_button_exec( struct world_button *btn, v2f texture, enum world_
        if( is_hovering )
        {
                if( vg_get_button_down( "primary" ) && is_hovering )
-               {
-                       btn->click_grab = 1;
-               }
-               else if( btn->click_grab && vg_get_button_up( "primary" ) )
+                       v2i_copy( click_tile, click_grab );
+               else if( v2i_eq( click_grab, click_tile ) && vg_get_button_up( "primary" ) )
                {
                        // Click event
                        *status = btn->state? k_world_button_on_disable: k_world_button_on_enable;
@@ -2239,15 +2247,13 @@ static int world_button_exec( struct world_button *btn, v2f texture, enum world_
                        triggered = 1;
                }
        }
-       if( vg_get_button_up( "primary" ) )
-               btn->click_grab = 0;
 
        // Drawing stage
        v4f final_colour;
        
-       btn->light = vg_lerpf( btn->light, btn->light_target, vg_time_delta*26.0f );
+       btn->light = vg_lerpf( btn->light, btn->light_target + btn->extra_light, vg_time_delta*26.0f );
 
-       v3_copy( btn->colour, final_colour );
+       v3_copy( colour, final_colour );
        final_colour[3] = btn->light;
 
        glUniform4f( SHADER_UNIFORM( shader_buttons, "uOffset" ),
@@ -2402,84 +2408,34 @@ static void level_selection_buttons(void)
 {
        v3f tutorial_colour = { 0.204f, 0.345f, 0.553f };
        v3f locked_colour = { 0.2f, 0.2f, 0.2f };
-       
-       v4f final_colour = { 0.0f, 0.0f, 0.0f, 0.2f };
-       v2i button_pos;
-       static struct cmp_level *select_from = NULL;
+
        struct cmp_level *switch_level_to = NULL;
-       
-       if( vg_get_button_down( "primary" ) )
-               select_from = NULL;
-       
+
        for( int i = 0; i < vg_list_size( career_packs ); i ++ )
        {
                struct career_level_pack *grid = &career_packs[i];
                
-               int j = 0;
-               
-               for( int x = 0; x < grid->dims[0]; x ++ )
+               for( int j = 0; j < grid->count; j ++ )
                {
-                       for( int y = 0; y < grid->dims[1]; y ++ )
-                       {
-                               if( j < grid->count )
-                               {
-                                       struct cmp_level *lvl = &grid->pack[ j ];
-                                       
-                                       // Determine colour
-                                       if( lvl->unlocked )
-                                       {
-                                               if( lvl->is_tutorial )
-                                                       v3_copy( tutorial_colour, final_colour );
-                                               else
-                                                       v3_copy( grid->primary_colour, final_colour );
-                                                       
-                                               if( lvl->completed_score )
-                                                       final_colour[3] = 0.8f;
-                                               else
-                                                       final_colour[3] = 0.2f;
-                                       }
-                                       else 
-                                       {
-                                               v3_copy( locked_colour, final_colour );
-                                               final_colour[3] = 0.2f;
-                                       }
-                                       
-                                       v2i_add( grid->origin, (v2i){ x,y }, button_pos );
-                                       int is_hovering = v2i_eq( (v2i){world.tile_x, world.tile_y}, button_pos );
-                               
-                                       if( is_hovering )
-                                       {
-                                               final_colour[3] += 0.1f;
-                                               
-                                               // Up click
-                                               if( vg_get_button_up( "primary" ) )
-                                                       if( select_from == lvl && lvl->unlocked )
-                                                       {
-                                                               switch_level_to = lvl;
-                                                               sfx_set_play( &audio_clicks, &audio_system_ui, 1 );
-                                                       }
-                                               
-                                               // Start click
-                                               if( vg_get_button_down( "primary" ) )
-                                                       select_from = lvl;
-                                               
-                                               if( vg_get_button( "primary" ) )
-                                                       final_colour[3] += 0.2f;
-                                       }
-                                       
-                                       if( world.pCmpLevel == lvl )
-                                       {
-                                               final_colour[3] += 0.15f + fabsf(sinf( vg_time * 2.0f )) * 0.05f;
-                                               
-                                               if( lvl->completed_score )
-                                                       final_colour[3] += 0.1f;
-                                       }
-                                       
-                                       //wbutton_draw( (v2i){ grid->origin[0] + x, grid->origin[1] + y }, tex_coord, final_colour );
-                               }
-                               else break;
+                       struct cmp_level *lvl = &grid->pack[ j ];
                                
-                               j ++;
+                       if( world.pCmpLevel == lvl )
+                               lvl->btn.extra_light = 0.35f + fabsf(sinf( vg_time * 2.0f )) * 0.05f;   
+                       else lvl->btn.extra_light = 0.2f;
+                       
+                       if( lvl->completed_score )
+                               lvl->btn.extra_light += 0.8f;
+                       
+                       enum world_button_status status;
+                       if( world_button_exec( 
+                               &lvl->btn, 
+                               (v2f){0.0f,0.0f}, 
+                               lvl->unlocked? (lvl->is_tutorial? tutorial_colour: grid->primary_colour): locked_colour,
+                               &status 
+                       ))
+                       {
+                               if( status == k_world_button_on_enable && lvl->unlocked )
+                                       switch_level_to = lvl;
                        }
                }
        }
@@ -2702,7 +2658,10 @@ void vg_render(void)
 
        float sim_icon_x = world_paused? 3.0f: (world_running? 2.0f: 0.0f);
 
-       if( world_button_exec( &world_static.buttons[k_world_button_sim], (v2f){ sim_icon_x, 3.0f }, &stat ))
+       v3f btn_dark_blue = { 0.204f, 0.345f, 0.553f };
+       v3f btn_orange = { 0.553f, 0.345f, 0.204f };
+
+       if( world_button_exec( &world_static.buttons[k_world_button_sim], (v2f){ sim_icon_x, 3.0f }, btn_dark_blue, &stat ))
        {
                if( stat == k_world_button_on_enable )
                {
@@ -2726,7 +2685,7 @@ void vg_render(void)
                }
        }
        
-       if( world_button_exec( &world_static.buttons[k_world_button_pause], (v2f){ 1.0f, 3.0f }, &stat ))
+       if( world_button_exec( &world_static.buttons[k_world_button_pause], (v2f){ 1.0f, 3.0f }, btn_dark_blue, &stat ))
        {
                world.sim_internal_ref = world.sim_internal_time;
                world.sim_delta_ref = vg_time;
@@ -2740,7 +2699,7 @@ void vg_render(void)
                        world.pause_offset_target = 0.0f;
        }
 
-       if( world_button_exec( &world_static.buttons[k_world_button_speedy], (v2f){ 0.0f, 2.0f }, &stat ))
+       if( world_button_exec( &world_static.buttons[k_world_button_speedy], (v2f){ 0.0f, 2.0f }, btn_orange, &stat ))
        {
                world.sim_delta_speed = stat == k_world_button_on_enable? 10.0f: 2.5f;
                
@@ -2753,6 +2712,9 @@ void vg_render(void)
 
        level_selection_buttons();
        
+       if( vg_get_button_up( "primary" ) )
+               world_button_exec( NULL, NULL, NULL, NULL );
+
        // TEXT ELEMENTS
        // ========================================================================================================
        SHADER_USE( shader_sdf );
@@ -3393,7 +3355,7 @@ void vg_start(void)
        }
        
        resource_load_main();
-       
+
        // Create text buffers
        {
                // Work out the counts for each 'segment'
index ddc1f00926e05f19549a32aed40f8dd6c55dc413..c6ecc9a806d788a55bacad0784f738a8d5d8a5ed 100644 (file)
@@ -935,13 +935,13 @@ career_packs[] =
                .count = vg_list_size( cmp_levels_basic ),
                .primary_colour = { 0.304f, 0.245f, 0.553f },
                .origin = { -3, 0 },
-               .dims = { 3, 6 }
+               .dims = { 3, 5 }
        },
        {
                .pack = cmp_levels_grad,
                .count = vg_list_size( cmp_levels_grad ),
                .primary_colour = { 0.553f, 0.345f, 0.204f },
-               .origin = { -5, 7 },
+               .origin = { -5, 6 },
                .dims = { 4, 1 }
        }
 };