8 #include "ent_miniworld.h"
12 #include "control_overlay.h"
14 #include "shaders/model_menu.h"
16 struct global_menu menu
= { .skip_starter
= 0 };
18 void menu_at_begin(void)
20 if( menu
.skip_starter
) return;
22 skaterift
.activity
= k_skaterift_menu
;
23 menu
.page
= k_menu_page_starter
;
28 vg_console_reg_var( "skip_starter_menu", &menu
.skip_starter
,
29 k_var_dtype_i32
, VG_VAR_PERSISTENT
);
32 void menu_open( enum menu_page page
)
34 skaterift
.activity
= k_skaterift_menu
;
36 if( page
!= k_menu_page_any
)
42 bool menu_viewing_map(void)
44 return (skaterift
.activity
== k_skaterift_menu
) &&
45 (menu
.page
== k_menu_page_main
) &&
46 (menu
.main_index
== k_menu_main_map
);
49 static void menu_decor_select( ui_rect rect
)
51 ui_px b
= vg_ui
.font
->sx
, hb
= b
/2;
52 ui_rect a0
= { rect
[0] - 20 - hb
, rect
[1] + rect
[3]/2 - hb
, b
,b
},
53 a1
= { rect
[0] + rect
[2] + 20 + hb
, rect
[1] + rect
[3]/2 - hb
, b
,b
};
55 ui_text( a0
, "\x95", 1, k_ui_align_middle_center
, 0 );
56 ui_text( a1
, "\x93", 1, k_ui_align_middle_center
, 0 );
59 static void menu_standard_widget( ui_rect inout_panel
, ui_rect rect
, ui_px s
)
61 ui_split( inout_panel
, k_ui_axis_h
, vg_ui
.font
->sy
*s
*2,
62 8, rect
, inout_panel
);
65 static bool menu_slider( ui_rect inout_panel
, bool select
, const char *label
,
66 const f32 disp_min
, const f32 disp_max
, f32
*value
,
70 menu_standard_widget( inout_panel
, rect
, 1 );
71 ui_label( rect
, label
, 1, 8, box
);
74 enum ui_button_state state
= ui_slider_base( box
, 0, 1, value
, &t
),
76 k_ui_button_holding_inside
|
77 k_ui_button_holding_outside
|
79 mask_brighter
= mask_using
| k_ui_button_hover
;
81 if( vg_input
.display_input_method
== k_input_method_controller
)
85 f32 m
= axis_state( k_sraxis_mbrowse_h
);
88 *value
+= m
* vg
.time_frame_delta
* (1.0f
/2.0f
);
89 *value
= vg_clampf( *value
, 0, 1 );
92 menu_decor_select( rect
);
93 state
|= k_ui_button_hover
;
97 ui_rect line
= { box
[0], box
[1], t
* (f32
)box
[2], box
[3] };
98 ui_fill( line
, state
&mask_brighter
? GUI_COL_ACTIVE
: GUI_COL_NORM
);
99 ui_fill( (ui_rect
){ box
[0]+line
[2], box
[1], box
[2]-line
[2], box
[3] },
102 ui_outline( box
, 1, state
? GUI_COL_HI
: GUI_COL_ACTIVE
, 0 );
103 ui_slider_text( box
, format
, disp_min
+ (*value
)*( disp_max
-disp_min
) );
105 return (state
& mask_using
) && 1;
108 static bool menu_button( ui_rect inout_panel
, bool select
, const char *text
)
111 menu_standard_widget( inout_panel
, rect
, 1 );
113 enum ui_button_state state
= k_ui_button_none
;
115 if( vg_input
.display_input_method
== k_input_method_controller
)
119 menu_decor_select( rect
);
121 if( button_down( k_srbind_maccept
) )
122 state
= k_ui_button_click
;
127 state
= ui_button_base( rect
);
131 if( state
== k_ui_button_click
)
133 ui_fill( rect
, GUI_COL_DARK
);
135 else if( state
== k_ui_button_holding_inside
)
137 ui_fill( rect
, GUI_COL_DARK
);
139 else if( state
== k_ui_button_holding_outside
)
141 ui_fill( rect
, GUI_COL_DARK
);
142 ui_outline( rect
, 1, GUI_COL_CLICK
, 0 );
144 else if( state
== k_ui_button_hover
)
146 ui_fill( rect
, GUI_COL_ACTIVE
);
147 ui_outline( rect
, 1, GUI_COL_CLICK
, 0 );
151 ui_fill( rect
, select
? GUI_COL_ACTIVE
: GUI_COL_NORM
);
153 ui_outline(rect
, 1, GUI_COL_HI
, 0 );
156 ui_text( rect
, text
, 1, k_ui_align_middle_center
, 0 );
157 return state
== k_ui_button_click
;
160 static bool menu_checkbox( ui_rect inout_panel
, bool select
,
161 const char *str_label
, i32
*data
)
163 ui_rect rect
, label
, box
;
164 menu_standard_widget( inout_panel
, rect
, 1 );
166 ui_split( rect
, k_ui_axis_v
, -rect
[3], 0, label
, box
);
167 ui_text( label
, str_label
, k_ui_scale
, k_ui_align_middle_left
, 0 );
169 enum ui_button_state state
= k_ui_button_none
;
171 if( vg_input
.display_input_method
== k_input_method_controller
)
175 menu_decor_select( rect
);
177 if( button_down( k_srbind_maccept
) )
179 *data
= (*data
) ^ 0x1;
180 state
= k_ui_button_click
;
186 state
= ui_checkbox_base( box
, data
);
190 if( state
== k_ui_button_holding_inside
)
192 ui_fill( box
, GUI_COL_ACTIVE
);
193 ui_outline( box
, 1, GUI_COL_CLICK
, 0 );
195 else if( state
== k_ui_button_holding_outside
)
197 ui_fill( box
, GUI_COL_DARK
);
198 ui_outline( box
, 1, GUI_COL_CLICK
, 0 );
200 else if( state
== k_ui_button_hover
)
202 ui_fill( box
, GUI_COL_ACTIVE
);
203 ui_outline( box
, 1, GUI_COL_HI
, 0 );
207 ui_fill( box
, select
? GUI_COL_ACTIVE
: GUI_COL_DARK
);
208 ui_outline( box
, 1, select
? GUI_COL_HI
: GUI_COL_NORM
, 0 );
211 bool changed
= (state
== k_ui_button_click
);
215 ui_rect_pad( box
, (ui_px
[2]){8,8} );
216 ui_fill( box
, GUI_COL_HI
);
222 static void menu_heading( ui_rect inout_panel
, const char *label
, u32 colour
)
225 menu_standard_widget( inout_panel
, rect
, 1 );
230 u32 c0
= ui_opacity( GUI_COL_DARK
, 0.36f
),
231 c1
= ui_opacity( GUI_COL_DARK
, 0.5f
);
233 struct ui_vert
*vs
= ui_fill( rect
, c0
);
239 ui_text( rect
, label
, 1, k_ui_align_middle_center
, 1 );
242 ui_text( rect
, label
, 1, k_ui_align_middle_center
, colour
? colour
:
243 ui_colour(k_ui_blue
+k_ui_brighter
) );
246 static u32
medal_colour( u32 flags
)
248 if( flags
& k_ent_route_flag_achieve_gold
)
249 return ui_colour( k_ui_yellow
);
250 else if( flags
& k_ent_route_flag_achieve_silver
)
251 return ui_colour( k_ui_fg
);
257 if( button_down( k_srbind_mopen
) )
259 if( skaterift
.activity
== k_skaterift_default
)
261 menu_open( k_menu_page_main
);
266 if( skaterift
.activity
!= k_skaterift_menu
)
269 /* get buttons inputs
270 * -------------------------------------------------------------------*/
271 int ml
= button_down( k_srbind_mleft
),
272 mr
= button_down( k_srbind_mright
),
273 mu
= button_down( k_srbind_mup
),
274 md
= button_down( k_srbind_mdown
),
277 enter
= button_down( k_srbind_maccept
);
279 if( vg_input
.display_input_method
== k_input_method_kbm
)
281 vg_ui
.wants_mouse
= 1;
284 if( skaterift
.activity
!= k_skaterift_menu
) return;
286 if( vg
.settings_open
)
288 if( button_down( k_srbind_mback
) )
291 srinput
.state
= k_input_state_resume
;
297 if( menu
.page
== k_menu_page_credits
)
299 ui_rect panel
= { 0,0, 600, 400 },
300 screen
= { 0,0, vg
.window_x
,vg
.window_y
};
301 ui_rect_center( screen
, panel
);
302 ui_fill( panel
, GUI_COL_DARK
);
303 ui_outline( panel
, 1, GUI_COL_NORM
, 0 );
304 ui_rect_pad( panel
, (ui_px
[]){8,8} );
307 ui_split( panel
, k_ui_axis_h
, 28*2, 0, title
, panel
);
308 ui_font_face( &vgf_default_title
);
309 ui_text( title
, "Skate Rift - Credits", 1, k_ui_align_middle_center
, 0 );
311 ui_split( panel
, k_ui_axis_h
, 28, 0, title
, panel
);
312 ui_font_face( &vgf_default_large
);
313 ui_text( title
, "Mt.Zero Software", 1, k_ui_align_middle_center
, 0 );
315 ui_split( panel
, k_ui_axis_h
, 8, 0, title
, panel
);
316 ui_split( panel
, k_ui_axis_h
, 28*2, 0, title
, panel
);
317 ui_font_face( &vgf_default_title
);
318 ui_text( title
, "Free Software", 1, k_ui_align_middle_center
, 0 );
320 ui_split( panel
, k_ui_axis_h
, 8, 0, title
, panel
);
321 ui_font_face( &vgf_default_large
);
323 "Sam Lantinga - SDL2 - libsdl.org\n"
324 "Hunter WB - Anyascii\n"
325 "David Herberth - GLAD\n"
326 "Dominic Szablewski - QOI - qoiformat.org\n"
327 "Sean Barrett - stb_image, stb_vorbis,\n"
329 "Khronos Group - OpenGL\n"
330 , 1, k_ui_align_left
, 0 );
332 ui_rect end
= { panel
[0], panel
[1] + panel
[3] - 64, panel
[2], 64 };
334 if( menu_button( end
, 1, "Back" ) || button_down( k_srbind_mback
) )
336 menu
.page
= k_menu_page_main
;
343 * -------------------------------------------------------------------*/
345 ui_font_face( &vgf_default_title
);
346 ui_px height
= vg_ui
.font
->ch
+ 16;
347 ui_rect topbar
= { 0, 0, vg
.window_x
, height
};
349 const char *opts
[] = {
350 [k_menu_main_main
] = "Menu",
351 [k_menu_main_map
] = "Map",
352 [k_menu_main_settings
] = "Settings",
353 [k_menu_main_guide
] = "Guides"
357 u8 lb_down
= 0, rb_down
= 0;
358 vg_exec_input_program( k_vg_input_type_button_u8
,
360 vg_joy_button
, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER
, vg_end
362 vg_exec_input_program( k_vg_input_type_button_u8
,
364 vg_joy_button
, SDL_CONTROLLER_BUTTON_LEFTSHOULDER
, vg_end
367 if( menu
.repeater
> 0.0f
)
369 menu
.repeater
-= vg_minf( vg
.time_frame_delta
, 0.5f
);
373 if( lb_down
!= rb_down
)
375 menu
.main_index
+= rb_down
;
376 menu
.main_index
-= lb_down
;
377 menu
.repeater
+= 0.2f
;
379 if( menu
.main_index
== -1 )
382 if( menu
.main_index
== vg_list_size(opts
) )
387 ui_px x
= 0, spacer
= 8;
388 for( u32 draw
=0; draw
<2; draw
++ )
390 if( vg_input
.display_input_method
== k_input_method_controller
)
394 ui_rect inf_lb
= { x
, 0, 32, height
};
395 ui_fill( inf_lb
, lb_down
? GUI_COL_NORM
: GUI_COL_NORM
);
396 ui_text( inf_lb
, "\x91", 1, k_ui_align_middle_center
, 0 );
401 for( i32 i
=0; i
<vg_list_size(opts
); i
++ )
403 ui_rect box
= { x
, 0, ui_text_line_width(opts
[i
]) + 32, height
};
407 enum ui_button_state state
= ui_button_base( box
);
408 if( state
== k_ui_button_click
)
410 ui_fill( box
, GUI_COL_DARK
);
413 else if( state
== k_ui_button_holding_inside
)
415 ui_fill( box
, GUI_COL_DARK
);
417 else if( state
== k_ui_button_holding_outside
)
419 ui_fill( box
, GUI_COL_DARK
);
420 ui_outline( box
, 1, GUI_COL_CLICK
, 0 );
422 else if( state
== k_ui_button_hover
)
424 ui_fill( box
, GUI_COL_NORM
);
425 ui_outline( box
, 1, GUI_COL_ACTIVE
, 0 );
428 ui_fill( box
, i
==menu
.main_index
? GUI_COL_ACTIVE
: GUI_COL_NORM
);
430 ui_text( box
, opts
[i
], 1, k_ui_align_middle_center
, 0 );
433 x
+= box
[2] + spacer
;
436 if( vg_input
.display_input_method
== k_input_method_controller
)
440 ui_rect inf_rb
= { x
, 0, 32, height
};
441 ui_fill( inf_rb
, rb_down
? GUI_COL_NORM
: GUI_COL_NORM
);
442 ui_text( inf_rb
, "\x92", 1, k_ui_align_middle_center
, 0 );
448 ui_fill( (ui_rect
){ x
+8,0, vg
.window_x
-(x
+8),height
}, GUI_COL_NORM
);
451 x
= vg
.window_x
/2 - x
/2;
452 ui_fill( (ui_rect
){ 0, 0, x
-8, height
}, GUI_COL_NORM
);
456 if( menu
.main_index
== k_menu_main_map
)
458 ui_font_face( &vgf_default_large
);
459 ui_rect title
= { vg
.window_x
/2 - 512/2, height
+8, 512, 64 };
465 ui_fill( (ui_rect
){ x
,y
, 0,height
},
466 world_static
.active_instance
? GUI_COL_DARK
: GUI_COL_ACTIVE
);
470 vg_strnull( &str
, buf
, sizeof(buf
) );
471 vg_strcat( &str
, "Hub World" );
473 if( world_static
.active_instance
)
475 vg_strcat( &str
, " (" );
476 vg_input_string( &str
, input_button_list
[k_srbind_mhub
], 1 );
477 vg_strcatch( &str
, '\x06' );
478 vg_strcatch( &str
, '\x00' );
479 vg_strcat( &str
, "\x1B[0m)" );
482 ui_px w
= ui_text( (ui_rect
){ x
+8, y
, 1000, height
}, buf
, 1,
483 k_ui_align_middle_left
, 0 );
492 world_instance
*world
= &world_static
.instances
[1];
493 if( world
->status
== k_world_status_loaded
)
495 const char *world_name
=
496 mdl_pstr( &world
->meta
, world
->info
.pstr_name
);
498 vg_strnull( &str
, buf
, sizeof(buf
) );
499 vg_strcat( &str
, world_name
);
501 if( !world_static
.active_instance
&&
502 (vg_input
.display_input_method
== k_input_method_controller
) )
504 vg_strcat( &str
, " (" );
505 vg_input_string( &str
, input_button_list
[k_srbind_mhub
], 1 );
506 vg_strcatch( &str
, '\x06' );
507 vg_strcatch( &str
, '\x00' );
508 vg_strcat( &str
, "\x1B[0m)" );
511 vs
= ui_fill( (ui_rect
){ x
,y
, 1000,height
},
512 world_static
.active_instance
? GUI_COL_ACTIVE
: GUI_COL_DARK
);
513 w
= ui_text( (ui_rect
){ x
+16,y
, 1000,height
}, buf
,
514 1, k_ui_align_middle_left
, 0 );
516 w
= w
*vg_ui
.font
->sx
+ 8*3;
519 if( button_down( k_srbind_mhub
) ||
520 ui_button_base( (ui_rect
){0,y
,x
,height
} ) == k_ui_button_click
)
522 world_switch_instance( world_static
.active_instance
^ 0x1 );
523 skaterift
.activity
= k_skaterift_default
;
524 world_map
.view_ready
= 0;
535 if( world_static
.active_instance
)
537 ui_rect stat_panel
= { x
,y
, 256,vg
.window_y
-y
};
538 u32 c0
= ui_opacity( GUI_COL_DARK
, 0.36f
);
539 struct ui_vert
*vs
= ui_fill( stat_panel
, c0
);
541 ui_rect_pad( stat_panel
, (ui_px
[2]){8,0} );
543 for( u32 i
=0; i
<mdl_arrcount( &world
->ent_region
); i
++ )
545 ent_region
*region
= mdl_arritm( &world
->ent_region
, i
);
547 if( !region
->zone_volume
)
550 const char *title
= mdl_pstr( &world
->meta
, region
->pstr_title
);
551 ui_font_face( &vgf_default_large
);
554 menu_standard_widget( stat_panel
, title_box
, 1 );
558 ui_font_face( &vgf_default_small
);
560 ent_volume
*volume
= mdl_arritm(&world
->ent_volume
,
561 mdl_entity_id_id(region
->zone_volume
));
563 u32 combined
= k_ent_route_flag_achieve_gold
|
564 k_ent_route_flag_achieve_silver
;
569 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_route
); j
++ )
571 ent_route
*route
= mdl_arritm(&world
->ent_route
, j
);
574 m4x3_mulv( volume
->to_local
, route
->board_transform
[3], local
);
575 if( !((fabsf(local
[0]) <= 1.0f
) &&
576 (fabsf(local
[1]) <= 1.0f
) &&
577 (fabsf(local
[2]) <= 1.0f
)) )
582 combined
&= route
->flags
;
584 vg_strnull( &str
, buf
, sizeof(buf
) );
585 vg_strcat( &str
, mdl_pstr(&world
->meta
, route
->pstr_name
));
587 if( route
->flags
& k_ent_route_flag_achieve_silver
)
588 vg_strcat( &str
, " \xb3");
589 if( route
->flags
& k_ent_route_flag_achieve_gold
)
590 vg_strcat( &str
, "\xb3");
593 ui_standard_widget( stat_panel
, r
, 1 );
594 ui_text( r
, buf
, 1, k_ui_align_middle_left
,
595 medal_colour(route
->flags
) );
598 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_challenge
); j
++ )
600 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, j
);
603 m4x3_mulv( volume
->to_local
, challenge
->transform
.co
, local
);
604 if( !((fabsf(local
[0]) <= 1.0f
) &&
605 (fabsf(local
[1]) <= 1.0f
) &&
606 (fabsf(local
[2]) <= 1.0f
)) )
611 vg_strnull( &str
, buf
, sizeof(buf
) );
612 vg_strcat( &str
, mdl_pstr(&world
->meta
, challenge
->pstr_alias
));
615 if( challenge
->status
)
617 flags
|= k_ent_route_flag_achieve_gold
;
618 flags
|= k_ent_route_flag_achieve_silver
;
619 vg_strcat( &str
, " \xb3\xb3" );
625 ui_standard_widget( stat_panel
, r
, 1 );
626 ui_text( r
, buf
, 1, k_ui_align_middle_left
, medal_colour(flags
) );
633 if( combined
& k_ent_route_flag_achieve_gold
)
634 title_col
= ui_colour( k_ui_yellow
);
635 else if( combined
& k_ent_route_flag_achieve_silver
)
636 title_col
= ui_colour( k_ui_fg
);
638 menu_heading( title_box
, title
, title_col
);
641 vs
[2].co
[1] = stat_panel
[1];
642 vs
[3].co
[1] = stat_panel
[1];
647 if( button_down( k_srbind_mback
) )
649 skaterift
.activity
= k_skaterift_default
;
653 ui_rect list0
= { vg
.window_x
/2 - 512/2, height
+32,
654 512, vg
.window_y
-height
-64 }, list
;
655 rect_copy( list0
, list
);
656 ui_rect_pad( list
, (ui_px
[2]){8,8} );
660 [k_menu_main_main
] = &menu
.main_row
,
661 [k_menu_main_settings
] = &menu
.settings_row
,
662 [k_menu_main_guide
] = &menu
.guides_row
666 if( mv
< 0 ) *row
= (*row
) +1;
667 if( mv
> 0 ) *row
= vg_max( 0, (*row
) -1 );
670 * -------------------------------------------------------------------*/
672 if( menu
.main_index
== k_menu_main_main
)
674 *row
= vg_min( 2, *row
);
676 if( menu_button( list
, *row
== 0, "Resume" ) )
678 skaterift
.activity
= k_skaterift_default
;
682 if( menu_button( list
, *row
== 1, "Credits" ) )
684 menu
.page
= k_menu_page_credits
;
687 ui_rect end
= { list
[0], list
[1]+list
[3]-64, list
[2], 72 };
688 if( menu_button( end
, *row
== 2, "Quit Game" ) )
690 vg
.window_should_close
= 1;
693 else if( menu
.main_index
== k_menu_main_settings
)
695 ui_fill( list0
, ui_opacity( GUI_COL_DARK
, 0.36f
) );
696 ui_outline( list0
, 1, GUI_COL_NORM
, 0 );
697 *row
= vg_min( 8, *row
);
699 ui_font_face( &vgf_default_large
);
701 menu_heading( list
, "Game", 0 );
702 menu_checkbox( list
, *row
== 0, "Show controls overlay",
703 &control_overlay
.enabled
);
704 menu_checkbox( list
, *row
== 1, "Auto connect to global server",
705 &network_client
.auto_connect
);
707 menu_heading( list
, "Audio/Video", 0 );
708 menu_slider( list
, *row
== 2, "Volume", 0, 100,
709 &vg_audio
.external_global_volume
, "%.f%%" );
710 menu_slider( list
, *row
== 3, "Resolution", 0, 100,
711 &k_render_scale
, "%.f%%" );
712 menu_checkbox( list
, *row
== 4, "Motion Blur", &k_blur_effect
);
714 menu_heading( list
, "Camera", 0 );
715 menu_slider( list
, *row
== 5, "Fov", 97, 135,
716 &k_fov
, "%.1f\xb0" );
717 menu_slider( list
, *row
== 6, "Cam Height", -0.4f
, +1.4f
,
718 &k_cam_height
, vg_lerpf(-0.4f
,1.4f
,k_cam_height
)>=0.0f
?
720 menu_checkbox( list
, *row
== 7, "Invert Y Axis", &k_invert_y
);
723 ui_rect end
= { list
[0], list
[1]+list
[3]-64, list
[2], 72 };
724 ui_font_face( &vgf_default_small
);
725 menu_heading( end
, "Advanced", 0 );
726 if( menu_button( end
, *row
== 8, "Open Engine Settings" ) )
731 else if( menu
.main_index
== k_menu_main_guide
)
733 ui_fill( list0
, ui_opacity( GUI_COL_DARK
, 0.36f
) );
734 ui_outline( list0
, 1, GUI_COL_NORM
, 0 );
735 *row
= vg_min( 4, *row
);
737 ui_font_face( &vgf_default_large
);
739 menu_heading( list
, "Controls", 0 );
740 if( menu_button( list
, *row
== 0, "Skating \xb2" ) )
743 if( menu_button( list
, *row
== 1, "Tricks \xb2" ) )
747 menu_heading( list
, "Workshop", 0 );
748 if( menu_button( list
, *row
== 2, "Create a Board \xb2" ) )
751 if( menu_button( list
, *row
== 3, "Create a World \xb2" ) )
754 if( menu_button( list
, *row
== 4, "Create a Playermodel \xb2" ) )
762 vg_ui
.frosting
= 0.015f
;
763 ui_flush( k_ui_shader_colour
, vg
.window_x
, vg
.window_y
);
764 vg_ui
.frosting
= 0.0f
;
766 ui_font_face( &vgf_default_small
);