f5b51c5ec2ce520c74860ee04897d88ca214ef89
[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 void ent_route_preupdate( ent_focus_context *ctx )
41 {
42 if( !ctx->active )
43 return;
44
45 world_instance *world = ctx->world;
46 ent_route *route = mdl_arritm( &world->ent_route, ctx->index );
47
48 u32 cam_id = 0;
49
50 if( __builtin_expect( world->meta.info.version >= 103, 1 ) )
51 cam_id = route->id_camera;
52
53 world_entity_focus_camera( world, cam_id );
54
55 if( button_down( k_srbind_mleft ) ){
56 world_sfd.view_weekly = 1;
57 world_sfd_compile_active_scores();
58 }
59
60 if( button_down( k_srbind_mright ) ){
61 world_sfd.view_weekly = 0;
62 world_sfd_compile_active_scores();
63 }
64
65 global_ent_route.helper_alltime->greyed =!world_sfd.view_weekly;
66 global_ent_route.helper_weekly->greyed = world_sfd.view_weekly;
67
68 if( button_down( k_srbind_mback ) )
69 {
70 world_entity_exit_modal();
71 world_entity_clear_focus();
72 gui_helper_clear();
73 return;
74 }
75 }