+ /* edit controls */
+ u32 drag_colour = ui_opacity( ui_colour(ctx, k_ui_bg+2), 0.5f );
+ if( i == player_replay.active_keyframe )
+ {
+ ui_outline( ctx, tag, 2, ui_colour(ctx, k_ui_fg), 0 );
+
+ ui_rect tray = { tag[0]+8-32, tag[1]+16+2, 64, 16 };
+ ui_rect dragbar = { tray[0]+16, tray[1], 32, 16 };
+
+ bool pos_correct = 0;
+
+ if( ui_inside_rect( dragbar, ctx->mouse_click ) )
+ {
+ if( ui_clicking( ctx, UI_MOUSE_LEFT ) )
+ {
+ drag_colour = ui_opacity( ui_colour(ctx,k_ui_fg), 0.5f );
+ pos_correct = 1;
+ replay_seek( &player_replay.local, mouse_t );
+ }
+ else if( ui_click_up( ctx, UI_MOUSE_LEFT ) )
+ {
+ pos_correct = 1;
+ kf->time = mouse_t;
+ replay_keyframe_sort();
+
+ for( u32 j=0; j<player_replay.keyframe_count; j ++ )
+ {
+ if( player_replay.keyframes[j].time == mouse_t )
+ {
+ player_replay.active_keyframe = j;
+ break;
+ }
+ }
+ }
+
+ if( pos_correct )
+ {
+ tag[0] = ctx->mouse[0]-8;
+ tray[0] = tag[0]+8-32;
+ dragbar[0] = tray[0]+16;
+ }
+ }
+
+ if( ui_inside_rect( dragbar, ctx->mouse ) )
+ {
+ ctx->cursor = k_ui_cursor_hand;
+ }
+
+ if( !pos_correct )
+ {
+ ui_fill( ctx, tray,
+ ui_opacity( ui_colour( ctx, k_ui_bg+2 ), 0.5f ) );
+ }
+
+ ui_fill( ctx, dragbar, drag_colour );
+ ui_text( ctx, dragbar, ":::", 1, k_ui_align_middle_center, 0 );
+
+ if( !pos_correct )
+ {
+ ui_rect btn = { tray[0], tray[1], 16, 16 };
+ if( ui_button_text( ctx, btn, "X", 1 ) == k_ui_button_click )
+ {
+ for( u32 j=i; j<player_replay.keyframe_count-1; j ++ )
+ player_replay.keyframes[j] = player_replay.keyframes[j+1];
+
+ player_replay.keyframe_count --;
+ player_replay.active_keyframe = -1;
+ }
+
+ ui_rect btn1 = { tray[0]+48, tray[1], 16, 16 };
+
+ enum ui_button_state mask_using =
+ k_ui_button_holding_inside |
+ k_ui_button_holding_outside |
+ k_ui_button_click;
+
+ if( ui_button_text( ctx, btn1, "E", 1 ) & mask_using )
+ {
+ replay_fly_edit_keyframe( ctx, kf );
+ vg_ui_set_mouse_pos( btn1[0]+8, btn1[1]+8 );
+ }
+ }
+ }
+
+ ui_fill( ctx, tag, ui_colour( ctx, k_ui_blue ) );
+ lx = x;
+ }
+
+ /* adding keyframes */
+ if( ui_inside_rect( script, ctx->mouse ) )
+ {
+ ctx->cursor = k_ui_cursor_hand;
+
+ ui_rect cursor = { ctx->mouse[0], script[1], 4, 16 };
+ ui_fill( ctx, cursor, ui_colour( ctx, k_ui_fg ) );
+
+ if( !absorb_by_keyframe && ui_click_down( ctx, UI_MOUSE_LEFT ) )
+ {
+ u32 max = vg_list_size( player_replay.keyframes );
+ if( player_replay.keyframe_count == max )
+ {
+ ui_start_modal( ctx, "Maximum keyframes reached", UI_MODAL_BAD );
+ }
+ else
+ {
+ replay_keyframe *kf =
+ &player_replay.keyframes[player_replay.keyframe_count++];
+
+ kf->time = mouse_t;
+ v3_copy( g_render.cam.pos, kf->cam.pos );
+ v3_copy( g_render.cam.angles, kf->cam.angles );
+ kf->cam.fov = g_render.cam.fov;
+
+ replay_keyframe_sort();
+ }
+ }
+ }
+
+ /* timeline scrub */
+ bool start_in_timeline =
+ ui_clicking(ctx, UI_MOUSE_LEFT) &&
+ ui_inside_rect(timeline, ctx->mouse_click);
+ if( (ui_inside_rect( timeline, ctx->mouse )) || start_in_timeline )
+ {
+ ui_rect cursor = { ctx->mouse[0], timeline[1], 4, timeline[3] };
+ ui_fill( ctx, cursor, ui_colour( ctx, k_ui_fg ) );
+ ctx->cursor = k_ui_cursor_ibeam;
+
+ if( ui_clicking( ctx, UI_MOUSE_LEFT ) && start_in_timeline )
+ {
+ replay_seek( &player_replay.local, mouse_t );
+ player_replay.active_keyframe = -1;
+ }
+ }
+
+ if( ui_button( ctx, panel, "Clear keyframes" ) == k_ui_button_click )
+ {
+ player_replay.keyframe_count = 0;
+ }
+
+ if( (ui_button( ctx, panel, "Hide UI (F2)" ) == k_ui_button_click) )
+ {
+ player_replay.show_ui ^= 0x1;
+ }
+
+ if( player_replay.active_keyframe != -1 )
+ {
+ replay_keyframe *kf =
+ &player_replay.keyframes[ player_replay.active_keyframe ];
+
+ enum ui_button_state mask_using =
+ k_ui_button_holding_inside |
+ k_ui_button_holding_outside |
+ k_ui_button_click;
+
+ if( ui_button( ctx, panel, "Edit cam" ) & mask_using )
+ {
+ replay_fly_edit_keyframe( ctx, kf );
+ }
+ }
+
+ ui_info( ctx, panel, "World settings" );
+ f32 new_time = world_current_instance()->time;
+ if( ui_slider( ctx, panel, "Time of day", 0, 1, &new_time ) )
+ {
+ world_current_instance()->time = new_time;
+ }
+
+ ui_info( ctx, panel, "" );
+ if( ui_button( ctx, panel, "Exit editor (F1)" ) == k_ui_button_click )
+ {
+ player_replay.editor_mode = 0;
+ replay_show_helpers();
+ }
+
+ /* TODO: Add Q/E scrub here too.
+ * Add replay trimming
+ */
+}