(50c0271)
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_route.c
1 #include "ent_route.h"
2 #include "input.h"
3 #include "gui.h"
4
5 struct global_ent_route global_ent_route;
6
7 entity_call_result ent_route_call( world_instance *world, ent_call *call )
8 {
9 u32 index = mdl_entity_id_id( call->id );
10 ent_route *route = mdl_arritm( &world->ent_route, index );
11
12 if( call->function == 0 )
13 { /* view() */
14 if( localplayer.subsystem == k_player_subsystem_walk )
15 {
16 world_entity_set_focus( call->id );
17 world_entity_focus_modal();
18
19 gui_helper_clear();
20 vg_str text;
21
22 if( (global_ent_route.helper_weekly =
23 gui_new_helper( input_button_list[k_srbind_mleft], &text )))
24 vg_strcat( &text, "weekly" );
25
26 if( (global_ent_route.helper_alltime =
27 gui_new_helper( input_button_list[k_srbind_mright], &text )))
28 vg_strcat( &text, "all time" );
29
30 if( gui_new_helper( input_button_list[k_srbind_mback], &text ) )
31 vg_strcat( &text, "exit" );
32 }
33
34 return k_entity_call_result_OK;
35 }
36
37 return k_entity_call_result_unhandled;
38 }
39
40 /* TODO: these should recieve the world instance */
41 void ent_route_preupdate( ent_route *route, int active )
42 {
43 if( !active ) return;
44
45 world_instance *world = world_current_instance();
46 u32 cam_id = 0;
47
48 if( __builtin_expect( world->meta.info.version >= 103, 1 ) )
49 cam_id = route->id_camera;
50
51 world_entity_focus_camera( world, cam_id );
52
53 if( button_down( k_srbind_mleft ) ){
54 world_sfd.view_weekly = 1;
55 world_sfd_compile_active_scores();
56 }
57
58 if( button_down( k_srbind_mright ) ){
59 world_sfd.view_weekly = 0;
60 world_sfd_compile_active_scores();
61 }
62
63 global_ent_route.helper_alltime->greyed =!world_sfd.view_weekly;
64 global_ent_route.helper_weekly->greyed = world_sfd.view_weekly;
65
66 if( button_down( k_srbind_mback ) )
67 {
68 world_entity_exit_modal();
69 world_entity_clear_focus();
70 gui_helper_clear();
71 return;
72 }
73 }