#include "audio.h"
#include "workshop.h"
#include "gui.h"
+#include "control_overlay.h"
+#include "network.h"
#include "shaders/model_menu.h"
struct global_menu menu = { .skip_starter = 0 };
(menu.main_index == k_menu_main_map);
}
+static void menu_decor_select( ui_rect rect )
+{
+ ui_px b = vg_ui.font->sx, hb = b/2;
+ ui_rect a0 = { rect[0] - 20 - hb, rect[1] + rect[3]/2 - hb, b,b },
+ a1 = { rect[0] + rect[2] + 20 + hb, rect[1] + rect[3]/2 - hb, b,b };
+
+ ui_text( a0, "\x95", 1, k_ui_align_middle_center, 0 );
+ ui_text( a1, "\x93", 1, k_ui_align_middle_center, 0 );
+}
+
+static void menu_standard_widget( ui_rect inout_panel, ui_rect rect, ui_px s )
+{
+ ui_split( inout_panel, k_ui_axis_h, vg_ui.font->sy*s*2,
+ 8, rect, inout_panel );
+}
+
+static bool menu_slider( ui_rect inout_panel, bool select, const char *label,
+ const f32 disp_min, const f32 disp_max, f32 *value,
+ const char *format )
+{
+ ui_rect rect, box;
+ menu_standard_widget( inout_panel, rect, 1 );
+ ui_label( rect, label, 1, 8, box );
+
+ f32 t;
+ enum ui_button_state state = ui_slider_base( box, 0, 1, value, &t ),
+ mask_using =
+ k_ui_button_holding_inside |
+ k_ui_button_holding_outside |
+ k_ui_button_click,
+ mask_brighter = mask_using | k_ui_button_hover;
+
+ if( vg_input.display_input_method == k_input_method_controller )
+ {
+ if( select )
+ {
+ f32 m = axis_state( k_sraxis_mbrowse_h );
+ if( fabsf(m) > 0.5f )
+ {
+ *value += m * vg.time_frame_delta * (1.0f/2.0f);
+ *value = vg_clampf( *value, 0, 1 );
+ }
+
+ menu_decor_select( rect );
+ state |= k_ui_button_hover;
+ }
+ }
+
+ ui_rect line = { box[0], box[1], t * (f32)box[2], box[3] };
+ ui_fill( line, state&mask_brighter? GUI_COL_ACTIVE: GUI_COL_NORM );
+ ui_fill( (ui_rect){ box[0]+line[2], box[1], box[2]-line[2], box[3] },
+ GUI_COL_DARK );
+
+ ui_outline( box, 1, state? GUI_COL_HI: GUI_COL_ACTIVE, 0 );
+ ui_slider_text( box, format, disp_min + (*value)*( disp_max-disp_min ) );
+
+ return (state & mask_using) && 1;
+}
+
+static bool menu_button( ui_rect inout_panel, bool select, const char *text )
+{
+ ui_rect rect;
+ menu_standard_widget( inout_panel, rect, 1 );
+
+ enum ui_button_state state = k_ui_button_none;
+
+ if( vg_input.display_input_method == k_input_method_controller )
+ {
+ if( select )
+ {
+ menu_decor_select( rect );
+
+ if( button_down( k_srbind_maccept ) )
+ state = k_ui_button_click;
+ }
+ }
+ else
+ {
+ state = ui_button_base( rect );
+ select = 0;
+ }
+
+ if( state == k_ui_button_click )
+ {
+ ui_fill( rect, GUI_COL_DARK );
+ }
+ else if( state == k_ui_button_holding_inside )
+ {
+ ui_fill( rect, GUI_COL_DARK );
+ }
+ else if( state == k_ui_button_holding_outside )
+ {
+ ui_fill( rect, GUI_COL_DARK );
+ ui_outline( rect, 1, GUI_COL_CLICK, 0 );
+ }
+ else if( state == k_ui_button_hover )
+ {
+ ui_fill( rect, GUI_COL_ACTIVE );
+ ui_outline( rect, 1, GUI_COL_CLICK, 0 );
+ }
+ else
+ {
+ ui_fill( rect, select? GUI_COL_ACTIVE: GUI_COL_NORM );
+ if( select )
+ ui_outline(rect, 1, GUI_COL_HI, 0 );
+ }
+
+ ui_text( rect, text, 1, k_ui_align_middle_center, 0 );
+ return state == k_ui_button_click;
+}
+
+static bool menu_checkbox( ui_rect inout_panel, bool select,
+ const char *str_label, i32 *data )
+{
+ ui_rect rect, label, box;
+ menu_standard_widget( inout_panel, rect, 1 );
+
+ ui_split( rect, k_ui_axis_v, -rect[3], 0, label, box );
+ ui_text( label, str_label, k_ui_scale, k_ui_align_middle_left, 0 );
+
+ enum ui_button_state state = k_ui_button_none;
+
+ if( vg_input.display_input_method == k_input_method_controller )
+ {
+ if( select )
+ {
+ menu_decor_select( rect );
+
+ if( button_down( k_srbind_maccept ) )
+ {
+ *data = (*data) ^ 0x1;
+ state = k_ui_button_click;
+ }
+ }
+ }
+ else
+ {
+ state = ui_checkbox_base( box, data );
+ select = 0;
+ }
+
+ if( state == k_ui_button_holding_inside )
+ {
+ ui_fill( box, GUI_COL_ACTIVE );
+ ui_outline( box, 1, GUI_COL_CLICK, 0 );
+ }
+ else if( state == k_ui_button_holding_outside )
+ {
+ ui_fill( box, GUI_COL_DARK );
+ ui_outline( box, 1, GUI_COL_CLICK, 0 );
+ }
+ else if( state == k_ui_button_hover )
+ {
+ ui_fill( box, GUI_COL_ACTIVE );
+ ui_outline( box, 1, GUI_COL_HI, 0 );
+ }
+ else
+ {
+ ui_fill( box, select? GUI_COL_ACTIVE: GUI_COL_DARK );
+ ui_outline( box, 1, select? GUI_COL_HI: GUI_COL_NORM, 0 );
+ }
+
+ bool changed = (state == k_ui_button_click);
+
+ if( *data )
+ {
+ ui_rect_pad( box, (ui_px[2]){8,8} );
+ ui_fill( box, GUI_COL_HI );
+ }
+
+ return changed;
+}
+
+static void menu_heading( ui_rect inout_panel, const char *label, u32 colour )
+{
+ ui_rect rect;
+ menu_standard_widget( inout_panel, rect, 1 );
+
+ rect[0] -= 8;
+ rect[2] += 16;
+
+ u32 c0 = ui_opacity( GUI_COL_DARK, 0.36f ),
+ c1 = ui_opacity( GUI_COL_DARK, 0.5f );
+
+ struct ui_vert *vs = ui_fill( rect, c0 );
+
+ vs[0].colour = c1;
+ vs[1].colour = c1;
+
+ rect[1] += 4;
+ ui_text( rect, label, 1, k_ui_align_middle_center, 1 );
+ rect[0] += 1;
+ rect[1] -= 1;
+ ui_text( rect, label, 1, k_ui_align_middle_center, colour? colour:
+ ui_colour(k_ui_blue+k_ui_brighter) );
+}
+
+static u32 medal_colour( u32 flags )
+{
+ if( flags & k_ent_route_flag_achieve_gold )
+ return ui_colour( k_ui_yellow );
+ else if( flags & k_ent_route_flag_achieve_silver )
+ return ui_colour( k_ui_fg );
+ else return 0;
+}
+
void menu_gui(void)
{
if( button_down( k_srbind_mopen ) )
mv = mu-md,
enter = button_down( k_srbind_maccept );
- if( mh||mv||enter )
+ if( vg_input.display_input_method == k_input_method_kbm )
{
- menu.input_mode = k_menu_input_mode_keys;
+ vg_ui.wants_mouse = 1;
}
- /* get mouse inputs
- * --------------------------------------------------------------------*/
- menu.mouse_dist += v2_length( vg.mouse_delta ); /* TODO: Move to UI */
- if( menu.mouse_dist > 10.0f )
- {
- menu.input_mode = k_menu_input_mode_mouse;
- menu.mouse_dist = 0.0f;
- }
+ if( skaterift.activity != k_skaterift_menu ) return;
- if( ui_clicking(UI_MOUSE_LEFT) || ui_clicking(UI_MOUSE_RIGHT) )
+ if( vg.settings_open )
{
- menu.input_mode = k_menu_input_mode_mouse;
+ if( button_down( k_srbind_mback ) )
+ {
+ vg_settings_close();
+ srinput.state = k_input_state_resume;
+ }
+
+ return;
}
- if( menu.input_mode == k_menu_input_mode_mouse )
+ if( menu.page == k_menu_page_credits )
{
- /*
- * handle mouse input
- * ------------------------------------------------------------*/
- vg_ui.wants_mouse = 1;
- }
+ ui_rect panel = { 0,0, 600, 400 },
+ screen = { 0,0, vg.window_x,vg.window_y };
+ ui_rect_center( screen, panel );
+ ui_fill( panel, GUI_COL_DARK );
+ ui_outline( panel, 1, GUI_COL_NORM, 0 );
+ ui_rect_pad( panel, (ui_px[]){8,8} );
+
+ ui_rect title;
+ ui_split( panel, k_ui_axis_h, 28*2, 0, title, panel );
+ ui_font_face( &vgf_default_title );
+ ui_text( title, "Skate Rift - Credits", 1, k_ui_align_middle_center, 0 );
+
+ ui_split( panel, k_ui_axis_h, 28, 0, title, panel );
+ ui_font_face( &vgf_default_large );
+ ui_text( title, "Mt.Zero Software", 1, k_ui_align_middle_center, 0 );
- if( skaterift.activity != k_skaterift_menu ) return;
+ ui_split( panel, k_ui_axis_h, 8, 0, title, panel );
+ ui_split( panel, k_ui_axis_h, 28*2, 0, title, panel );
+ ui_font_face( &vgf_default_title );
+ ui_text( title, "Free Software", 1, k_ui_align_middle_center, 0 );
+ ui_split( panel, k_ui_axis_h, 8, 0, title, panel );
+ ui_font_face( &vgf_default_large );
+ ui_text( panel,
+ "Sam Lantinga - SDL2 - libsdl.org\n"
+ "Hunter WB - Anyascii\n"
+ "David Herberth - GLAD\n"
+ "Dominic Szablewski - QOI - qoiformat.org\n"
+ "Sean Barrett - stb_image, stb_vorbis,\n"
+ " stb_include\n"
+ "Khronos Group - OpenGL\n"
+ , 1, k_ui_align_left, 0 );
+
+ ui_rect end = { panel[0], panel[1] + panel[3] - 64, panel[2], 64 };
+
+ if( menu_button( end, 1, "Back" ) || button_down( k_srbind_mback ) )
+ {
+ menu.page = k_menu_page_main;
+ }
+
+ goto menu_draw;
+ }
/* TOP BAR
* -------------------------------------------------------------------*/
const char *opts[] = {
[k_menu_main_main] = "Menu",
- [k_menu_main_map] = "Map"
+ [k_menu_main_map] = "Map",
+ [k_menu_main_settings ] = "Settings",
+ [k_menu_main_guide ] = "Guides"
};
/* TAB CONTROL */
}
}
- ui_px x = 0,
- spacer = 8;
+ ui_px x = 0, spacer = 8;
for( u32 draw=0; draw<2; draw ++ )
{
- if( draw )
+ if( vg_input.display_input_method == k_input_method_controller )
{
- ui_rect inf_lb = { x, 0, 32, height };
- ui_fill( inf_lb, lb_down? GUI_COL_NORM: GUI_COL_NORM );
- ui_text( inf_lb, "\x91", 1, k_ui_align_middle_center, 0 );
+ if( draw )
+ {
+ ui_rect inf_lb = { x, 0, 32, height };
+ ui_fill( inf_lb, lb_down? GUI_COL_NORM: GUI_COL_NORM );
+ ui_text( inf_lb, "\x91", 1, k_ui_align_middle_center, 0 );
+ }
+ x += 32 + spacer;
}
- x += 32 + spacer;
for( i32 i=0; i<vg_list_size(opts); i ++ )
{
x += box[2] + spacer;
}
- if( draw )
+ if( vg_input.display_input_method == k_input_method_controller )
{
- ui_rect inf_rb = { x, 0, 32, height };
- ui_fill( inf_rb, rb_down? GUI_COL_NORM: GUI_COL_NORM );
- ui_text( inf_rb, "\x92", 1, k_ui_align_middle_center, 0 );
+ if( draw )
+ {
+ ui_rect inf_rb = { x, 0, 32, height };
+ ui_fill( inf_rb, rb_down? GUI_COL_NORM: GUI_COL_NORM );
+ ui_text( inf_rb, "\x92", 1, k_ui_align_middle_center, 0 );
+ }
+ x += 32;
}
- x += 32;
if( draw )
ui_fill( (ui_rect){ x+8,0, vg.window_x-(x+8),height }, GUI_COL_NORM );
vg_strnull( &str, buf, sizeof(buf) );
vg_strcat( &str, "Hub World" );
- if( world_static.active_instance &&
- (vg_input.display_input_method == k_input_method_controller) )
+ if( world_static.active_instance )
{
vg_strcat( &str, " (" );
vg_input_string( &str, input_button_list[k_srbind_mhub], 1 );
- vg_strcat( &str, ")" );
+ vg_strcatch( &str, '\x06' );
+ vg_strcatch( &str, '\x00' );
+ vg_strcat( &str, "\x1B[0m)" );
}
ui_px w = ui_text( (ui_rect){ x+8, y, 1000, height }, buf, 1,
{
vg_strcat( &str, " (" );
vg_input_string( &str, input_button_list[k_srbind_mhub], 1 );
- vg_strcat( &str, ")" );
+ vg_strcatch( &str, '\x06' );
+ vg_strcatch( &str, '\x00' );
+ vg_strcat( &str, "\x1B[0m)" );
}
vs = ui_fill( (ui_rect){ x,y, 1000,height },
vs[1].co[0] = x + 8;
vs[2].co[0] = x;
}
+
+ x = 8;
+ y += 8 + height;
+
+ if( world_static.active_instance )
+ {
+ ui_rect stat_panel = { x,y, 256,vg.window_y-y };
+ u32 c0 = ui_opacity( GUI_COL_DARK, 0.36f );
+ struct ui_vert *vs = ui_fill( stat_panel, c0 );
+
+ ui_rect_pad( stat_panel, (ui_px[2]){8,0} );
+
+ for( u32 i=0; i<mdl_arrcount( &world->ent_region ); i ++ )
+ {
+ ent_region *region = mdl_arritm( &world->ent_region, i );
+
+ if( !region->zone_volume )
+ continue;
+
+ const char *title = mdl_pstr( &world->meta, region->pstr_title );
+ ui_font_face( &vgf_default_large );
+
+ ui_rect title_box;
+ menu_standard_widget( stat_panel, title_box, 1 );
+
+ stat_panel[0] += 16;
+ stat_panel[2] -= 16;
+ ui_font_face( &vgf_default_small );
+
+ ent_volume *volume = mdl_arritm(&world->ent_volume,
+ mdl_entity_id_id(region->zone_volume));
+
+ u32 combined = k_ent_route_flag_achieve_gold |
+ k_ent_route_flag_achieve_silver;
+
+ char buf[128];
+ vg_str str;
+
+ for( u32 j=0; j<mdl_arrcount(&world->ent_route); j ++ )
+ {
+ ent_route *route = mdl_arritm(&world->ent_route, j );
+
+ v3f local;
+ m4x3_mulv( volume->to_local, route->board_transform[3], local );
+ if( !((fabsf(local[0]) <= 1.0f) &&
+ (fabsf(local[1]) <= 1.0f) &&
+ (fabsf(local[2]) <= 1.0f)) )
+ {
+ continue;
+ }
+
+ combined &= route->flags;
+
+ vg_strnull( &str, buf, sizeof(buf) );
+ vg_strcat( &str, mdl_pstr(&world->meta, route->pstr_name));
+
+ if( route->flags & k_ent_route_flag_achieve_silver )
+ vg_strcat( &str, " \xb3");
+ if( route->flags & k_ent_route_flag_achieve_gold )
+ vg_strcat( &str, "\xb3");
+
+ ui_rect r;
+ ui_standard_widget( stat_panel, r, 1 );
+ ui_text( r, buf, 1, k_ui_align_middle_left,
+ medal_colour(route->flags) );
+ }
+
+ for( u32 j=0; j<mdl_arrcount(&world->ent_challenge); j ++ )
+ {
+ ent_challenge *challenge = mdl_arritm( &world->ent_challenge, j );
+
+ v3f local;
+ m4x3_mulv( volume->to_local, challenge->transform.co, local );
+ if( !((fabsf(local[0]) <= 1.0f) &&
+ (fabsf(local[1]) <= 1.0f) &&
+ (fabsf(local[2]) <= 1.0f)) )
+ {
+ continue;
+ }
+
+ vg_strnull( &str, buf, sizeof(buf) );
+ vg_strcat( &str, mdl_pstr(&world->meta, challenge->pstr_alias));
+
+ u32 flags = 0x00;
+ if( challenge->status )
+ {
+ flags |= k_ent_route_flag_achieve_gold;
+ flags |= k_ent_route_flag_achieve_silver;
+ vg_strcat( &str, " \xb3\xb3" );
+ }
+
+ combined &= flags;
+
+ ui_rect r;
+ ui_standard_widget( stat_panel, r, 1 );
+ ui_text( r, buf, 1, k_ui_align_middle_left, medal_colour(flags) );
+ }
+
+ stat_panel[0] -= 16;
+ stat_panel[2] += 16;
+
+ u32 title_col = 0;
+ if( combined & k_ent_route_flag_achieve_gold )
+ title_col = ui_colour( k_ui_yellow );
+ else if( combined & k_ent_route_flag_achieve_silver )
+ title_col = ui_colour( k_ui_fg );
+
+ menu_heading( title_box, title, title_col );
+ }
+
+ vs[2].co[1] = stat_panel[1];
+ vs[3].co[1] = stat_panel[1];
+ }
}
else
{
skaterift.activity = k_skaterift_default;
return;
}
- }
- /* MAIN / MAIN
- * -------------------------------------------------------------------*/
+ ui_rect list0 = { vg.window_x/2 - 512/2, height+32,
+ 512, vg.window_y-height-64 }, list;
+ rect_copy( list0, list );
+ ui_rect_pad( list, (ui_px[2]){8,8} );
- if( menu.main_index == k_menu_main_main )
- {
- ui_rect list = { vg.window_x/2 - 512/2, height+64,
- 512, vg.window_y-height-128 };
- ui_fill( list, GUI_COL_DARK );
+ i32 *row = (i32 *[])
+ {
+ [k_menu_main_main] = &menu.main_row,
+ [k_menu_main_settings] = &menu.settings_row,
+ [k_menu_main_guide] = &menu.guides_row
+ }
+ [ menu.main_index ];
+
+ if( mv < 0 ) *row = (*row) +1;
+ if( mv > 0 ) *row = vg_max( 0, (*row) -1 );
+
+ /* MAIN / MAIN
+ * -------------------------------------------------------------------*/
+
+ if( menu.main_index == k_menu_main_main )
+ {
+ *row = vg_min( 2, *row );
+
+ if( menu_button( list, *row == 0, "Resume" ) )
+ {
+ skaterift.activity = k_skaterift_default;
+ return;
+ }
+
+ if( menu_button( list, *row == 1, "Credits" ) )
+ {
+ menu.page = k_menu_page_credits;
+ }
+
+ ui_rect end = { list[0], list[1]+list[3]-64, list[2], 72 };
+ if( menu_button( end, *row == 2, "Quit Game" ) )
+ {
+ vg.window_should_close = 1;
+ }
+ }
+ else if( menu.main_index == k_menu_main_settings )
+ {
+ ui_fill( list0, ui_opacity( GUI_COL_DARK, 0.36f ) );
+ ui_outline( list0, 1, GUI_COL_NORM, 0 );
+ *row = vg_min( 8, *row );
+
+ ui_font_face( &vgf_default_large );
+ list[1] -= 8;
+ menu_heading( list, "Game", 0 );
+ menu_checkbox( list, *row == 0, "Show controls overlay",
+ &control_overlay.enabled );
+ menu_checkbox( list, *row == 1, "Auto connect to global server",
+ &network_client.auto_connect );
+
+ menu_heading( list, "Audio/Video", 0 );
+ menu_slider( list, *row == 2, "Volume", 0, 100,
+ &vg_audio.external_global_volume, "%.f%%" );
+ menu_slider( list, *row == 3, "Resolution", 0, 100,
+ &k_render_scale, "%.f%%" );
+ menu_checkbox( list, *row == 4, "Motion Blur", &k_blur_effect );
+
+ menu_heading( list, "Camera", 0 );
+ menu_slider( list, *row == 5, "Fov", 97, 135,
+ &k_fov, "%.1f\xb0" );
+ menu_slider( list, *row == 6, "Cam Height", -0.4f, +1.4f,
+ &k_cam_height, vg_lerpf(-0.4f,1.4f,k_cam_height)>=0.0f?
+ "+%.2fm": "%.2fm" );
+ menu_checkbox( list, *row == 7, "Invert Y Axis", &k_invert_y );
+
+
+ ui_rect end = { list[0], list[1]+list[3]-64, list[2], 72 };
+ ui_font_face( &vgf_default_small );
+ menu_heading( end, "Advanced", 0 );
+ if( menu_button( end, *row == 8, "Open Engine Settings" ) )
+ {
+ vg_settings_open();
+ }
+ }
+ else if( menu.main_index == k_menu_main_guide )
+ {
+ ui_fill( list0, ui_opacity( GUI_COL_DARK, 0.36f ) );
+ ui_outline( list0, 1, GUI_COL_NORM, 0 );
+ *row = vg_min( 4, *row );
+
+ ui_font_face( &vgf_default_large );
+ list[1] -= 8;
+ menu_heading( list, "Controls", 0 );
+ if( menu_button( list, *row == 0, "Skating \xb2" ) )
+ {
+ }
+ if( menu_button( list, *row == 1, "Tricks \xb2" ) )
+ {
+ }
+
+ menu_heading( list, "Workshop", 0 );
+ if( menu_button( list, *row == 2, "Create a Board \xb2" ) )
+ {
+ }
+ if( menu_button( list, *row == 3, "Create a World \xb2" ) )
+ {
+ }
+ if( menu_button( list, *row == 4, "Create a Playermodel \xb2" ) )
+ {
+ }
+ }
}
+menu_draw:
+
vg_ui.frosting = 0.015f;
ui_flush( k_ui_shader_colour, vg.window_x, vg.window_y );
vg_ui.frosting = 0.0f;