X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=menu.c;h=f9b4c3ee59812004fcdc008b0a75d01a38986d04;hb=0ba0bbe2da453f17f56a88521057e6514ae30b8f;hp=b98f5d40e27ec991431890a7082d00f534b3d54e;hpb=5f6a4f9df6c8accc89f1920bfe9ace3cbac4c4b6;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/menu.c b/menu.c index b98f5d4..f9b4c3e 100644 --- a/menu.c +++ b/menu.c @@ -9,784 +9,1087 @@ #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; +struct global_menu menu = { .skip_starter = 0 }; -/* - * Attaches memory locations to the various items in the menu - */ -void menu_link(void) +void menu_at_begin(void) { - /* link data locations */ - for( u32 i=0; itype == k_ent_menuitem_type_toggle || - item->type == k_ent_menuitem_type_slider ){ - - const char *name; - - if( item->type == k_ent_menuitem_type_slider ) - name = mdl_pstr( &menu.model, item->slider.pstr_data ); - else - name = mdl_pstr( &menu.model, item->checkmark.pstr_data ); - vg_var *var = vg_console_match_var( name ); - - if( var ){ - if( ( item->type == k_ent_menuitem_type_slider && - var->data_type != k_var_dtype_f32 - ) || - ( item->type == k_ent_menuitem_type_toggle &&! - ( var->data_type == k_var_dtype_i32 || - var->data_type == k_var_dtype_u32 - ) - ) - ){ - vg_error( "Cannot hook to data %s(%p), because it is type %d.\n", - name, var, var->data_type ); - item->pvoid = NULL; - } - else{ - item->pvoid = var->data; - } - } - else{ - vg_error( "No data named %s\n", name ); - item->pvoid = NULL; - } - } - else{ - item->pvoid = NULL; - } - } + if( menu.skip_starter ) return; - /* link controllers */ - menu.ctr_deck = NULL; - menu.ctr_kbm = NULL; - menu.ctr_ps = NULL; - menu.ctr_steam = NULL; - menu.ctr_xbox = NULL; - - for( u32 i=0; ivisual.pstr_name, "deck" ) ) - menu.ctr_deck = item; - if( MDL_CONST_PSTREQ( &menu.model, item->visual.pstr_name, "kbm" ) ) - menu.ctr_kbm = item; - if( MDL_CONST_PSTREQ( &menu.model, item->visual.pstr_name, "ps" ) ) - menu.ctr_ps = item; - if( MDL_CONST_PSTREQ( &menu.model, item->visual.pstr_name, "steam" ) ) - menu.ctr_steam = item; - if( MDL_CONST_PSTREQ( &menu.model, item->visual.pstr_name, "xbox" ) ) - menu.ctr_xbox = item; - } + skaterift.activity = k_skaterift_menu; + menu.page = k_menu_page_starter; } -void menu_close(void) +void menu_init(void) { - skaterift.activity = k_skaterift_default; - menu.page_depth = 0; - menu.page = 0xffffffff; - srinput.state = k_input_state_resume; + vg_console_reg_var( "skip_starter_menu", &menu.skip_starter, + k_var_dtype_i32, VG_VAR_PERSISTENT ); + vg_tex2d_load_qoi_async_file( "textures/prem.qoi", + VG_TEX2D_CLAMP|VG_TEX2D_NOMIP|VG_TEX2D_NEAREST, + &menu.prem_tex ); } -void menu_init(void) +void menu_open( enum menu_page page ) { - void *alloc = vg_mem.rtmemory; + skaterift.activity = k_skaterift_menu; - mdl_open( &menu.model, "models/rs_menu.mdl", alloc ); - mdl_load_metadata_block( &menu.model, alloc ); + if( page != k_menu_page_any ) + { + menu.page = page; + } +} - vg_linear_clear( vg_mem.scratch ); +bool menu_viewing_map(void) +{ + return (skaterift.activity == k_skaterift_menu) && + (menu.page == k_menu_page_main) && + (menu.main_index == k_menu_main_map); +} - MDL_LOAD_ARRAY( &menu.model, &menu.items, ent_menuitem, alloc ); - MDL_LOAD_ARRAY( &menu.model, &menu.markers, ent_marker, alloc ); - MDL_LOAD_ARRAY( &menu.model, &menu.cameras, ent_camera, alloc ); +static void menu_decor_select( ui_context *ctx, ui_rect rect ) +{ + ui_px b = ctx->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 }; - u32 count = mdl_arrcount( &menu.model.textures ); - menu.textures = vg_linear_alloc(alloc,vg_align8(sizeof(GLuint)*(count+1))); - menu.textures[0] = vg.tex_missing; + ui_text( ctx, a0, "\x95", 1, k_ui_align_middle_center, 0 ); + ui_text( ctx, a1, "\x93", 1, k_ui_align_middle_center, 0 ); +} - mdl_async_load_glmesh( &menu.model, &menu.mesh, NULL ); +static void menu_standard_widget( ui_context *ctx, + ui_rect inout_panel, ui_rect rect, ui_px s ) +{ + ui_split( inout_panel, k_ui_axis_h, ctx->font->sy*s*2, + 8, rect, inout_panel ); +} - for( u32 i=0; i 0.5f ) + { + *value += m * vg.time_frame_delta * (1.0f/2.0f); + *value = vg_clampf( *value, 0, 1 ); + } - mdl_texture *tex = mdl_arritm( &menu.model.textures, i ); - void *data = vg_linear_alloc( vg_mem.scratch, tex->file.pack_size ); - mdl_fread_pack_file( &menu.model, &tex->file, data ); - vg_tex2d_load_qoi_async( data, tex->file.pack_size, - VG_TEX2D_LINEAR|VG_TEX2D_CLAMP, - &menu.textures[i+1] ); + menu_decor_select( ctx, rect ); + state |= k_ui_button_hover; + } + else + state = k_ui_button_none; } - mdl_close( &menu.model ); -} + ui_rect line = { box[0], box[1], t * (f32)box[2], box[3] }; + ui_fill( ctx, line, state&mask_brighter? GUI_COL_ACTIVE: GUI_COL_NORM ); + ui_fill( ctx, (ui_rect){ box[0]+line[2], box[1], box[2]-line[2], box[3] }, + GUI_COL_DARK ); -/* - * Drop back a page until we're at the bottom which then we jus quit - */ -static void menu_back_page(void){ - menu.page_depth --; - if( menu.page_depth == 0 ){ - menu_close(); - } - else{ - menu.page = menu.page_stack[ menu.page_depth ].page; - menu.cam = menu.page_stack[ menu.page_depth ].cam; + ui_outline( ctx, box, 1, state? GUI_COL_HI: GUI_COL_ACTIVE, 0 ); + ui_slider_text( ctx, box, + format, disp_min + (*value)*( disp_max-disp_min ) ); - if( menu.input_mode == k_menu_input_mode_keys ) - menu.loc = menu.page_stack[ menu.page_depth ].loc; - else menu.loc = NULL; - } + return (state & mask_using) && 1; } -/* - * Open page to the string identifier - */ -void menu_open_page( const char *name, - enum ent_menuitem_stack_behaviour stackmode ) +static bool menu_button( ui_context *ctx, + ui_rect inout_panel, bool select, const char *text ) { - srinput.state = k_input_state_resume; - if( stackmode == k_ent_menuitem_stack_append ){ - if( menu.page_depth >= MENU_STACK_SIZE ) - vg_fatal_error( "Stack overflow\n" ); + ui_rect rect; + menu_standard_widget( ctx, 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( ctx, rect ); + + if( button_down( k_srbind_maccept ) ) + state = k_ui_button_click; + } } - else{ - if( menu.page_depth == 0 ) - vg_fatal_error( "Stack underflow\n" ); + else + { + state = ui_button_base( ctx, rect ); + select = 0; } - u32 hash = vg_strdjb2( name ); - for( u32 i=0; itype == k_ent_menuitem_type_page ){ - if( mdl_pstreq( &menu.model, item->page.pstr_name, name, hash ) ){ - u32 new_page = __builtin_ctz( item->groups ); + if( state == k_ui_button_click ) + { + ui_fill( ctx, rect, GUI_COL_DARK ); + } + else if( state == k_ui_button_holding_inside ) + { + ui_fill( ctx, rect, GUI_COL_DARK ); + } + else if( state == k_ui_button_holding_outside ) + { + ui_fill( ctx, rect, GUI_COL_DARK ); + ui_outline( ctx, rect, 1, GUI_COL_CLICK, 0 ); + } + else if( state == k_ui_button_hover ) + { + ui_fill( ctx, rect, GUI_COL_ACTIVE ); + ui_outline( ctx, rect, 1, GUI_COL_CLICK, 0 ); + } + else + { + ui_fill( ctx, rect, select? GUI_COL_ACTIVE: GUI_COL_NORM ); + if( select ) + ui_outline( ctx, rect, 1, GUI_COL_HI, 0 ); + } - if( new_page == menu.page ){ - if( stackmode != k_ent_menuitem_stack_replace ) - menu_back_page(); - } - else{ - menu.page_stack[ menu.page_depth ].page = menu.page; - menu.page_stack[ menu.page_depth ].cam = menu.cam; - menu.page_stack[ menu.page_depth ].loc = menu.loc; - - if( stackmode == k_ent_menuitem_stack_append ) - menu.page_depth ++; - - menu.page = __builtin_ctz( item->groups ); - - if( menu.input_mode == k_menu_input_mode_keys ){ - if( item->page.id_entrypoint ){ - u32 id = mdl_entity_id_id( item->page.id_entrypoint ); - menu.loc = mdl_arritm( &menu.items, id ); - } - } + ui_text( ctx, rect, text, 1, k_ui_align_middle_center, 0 ); - if( item->page.id_viewpoint ){ - u32 id = mdl_entity_id_id( item->page.id_viewpoint ); - menu.cam = mdl_arritm( &menu.cameras, id ); - } - } - return; - } - } + if( state == k_ui_button_click ) + { + audio_lock(); + audio_oneshot( &audio_ui[0], 1.0f, 0.0f ); + audio_unlock(); + return 1; } + else return 0; } -/* - * activate a pressable type - */ -static void menu_trigger_item( ent_menuitem *item ){ - if ( item->type == k_ent_menuitem_type_event_button ){ - u32 q = item->button.pstr; - - if( MDL_CONST_PSTREQ( &menu.model, q, "quit" ) ){ - vg.window_should_close = 1; - } - else if( MDL_CONST_PSTREQ( &menu.model, q, "map" ) ){ - menu_close(); - world_map_enter(); - } - else if( MDL_CONST_PSTREQ( &menu.model, q, "hub" ) ){ - if( world_static.active_instance == k_world_purpose_client ){ - menu_close(); - ent_miniworld_goback(); +static bool menu_checkbox( ui_context *ctx, ui_rect inout_panel, bool select, + const char *str_label, i32 *data ) +{ + ui_rect rect, label, box; + menu_standard_widget( ctx, inout_panel, rect, 1 ); + + ui_split( rect, k_ui_axis_v, -rect[3], 0, label, box ); + ui_text( ctx, label, str_label, ctx->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( ctx, rect ); + + if( button_down( k_srbind_maccept ) ) + { + *data = (*data) ^ 0x1; + state = k_ui_button_click; } } - else if( MDL_CONST_PSTREQ( &menu.model, q, "credits" ) ){ - menu.credits_open = 1; - } - else if( MDL_CONST_PSTREQ( &menu.model, q, "workshop" ) ){ - workshop_submit_command(0,NULL); - } - else if( MDL_CONST_PSTREQ( &menu.model, q, "engine" ) ){ - vg_settings_open(); - } - else if( MDL_CONST_PSTREQ( &menu.model, q, "prem_store" ) ){ - if( steam_ready ) - SteamAPI_ISteamFriends_ActivateGameOverlayToStore( - SteamAPI_SteamFriends(), 2103940, k_EOverlayToStoreFlag_None); - } - else if( MDL_CONST_PSTREQ( &menu.model, q, "prem_nevermind" ) ){ - menu_close(); - } } - else if( item->type == k_ent_menuitem_type_page_button ){ - menu_open_page( mdl_pstr( &menu.model, item->button.pstr ), - item->button.stack_behaviour ); + else + { + state = ui_checkbox_base( ctx, box, data ); + select = 0; } - else if( item->type == k_ent_menuitem_type_toggle ){ - if( item->pi32 ){ - *item->pi32 = *item->pi32 ^ 0x1; - } + + if( state == k_ui_button_holding_inside ) + { + ui_fill( ctx, box, GUI_COL_ACTIVE ); + ui_outline( ctx, box, 1, GUI_COL_CLICK, 0 ); } + else if( state == k_ui_button_holding_outside ) + { + ui_fill( ctx, box, GUI_COL_DARK ); + ui_outline( ctx, box, 1, GUI_COL_CLICK, 0 ); + } + else if( state == k_ui_button_hover ) + { + ui_fill( ctx, box, GUI_COL_ACTIVE ); + ui_outline( ctx, box, 1, GUI_COL_HI, 0 ); + } + else + { + ui_fill( ctx, box, select? GUI_COL_ACTIVE: GUI_COL_DARK ); + ui_outline( ctx, box, 1, select? GUI_COL_HI: GUI_COL_NORM, 0 ); + } + + if( *data ) + { + ui_rect_pad( box, (ui_px[2]){8,8} ); + ui_fill( ctx, box, GUI_COL_HI ); + } + + if( state == k_ui_button_click ) + { + audio_lock(); + audio_oneshot( &audio_ui[0], 1.0f, 0.0f ); + audio_unlock(); + return 1; + } + else return 0; } -static f32 menu_slider_snap( f32 value, f32 old, f32 notch ){ - f32 const k_epsilon = 0.0125f; +static void menu_heading( ui_context *ctx, + ui_rect inout_panel, const char *label, u32 colour ) +{ + ui_rect rect; + menu_standard_widget( ctx, inout_panel, rect, 1 ); - if( fabsf(notch-value) < k_epsilon ){ - if( fabsf(notch-old) > k_epsilon ){ - audio_lock(); - audio_oneshot( &audio_ui[0], 1.0f, 0.0f ); - audio_unlock(); - } + rect[0] -= 8; + rect[2] += 16; - return notch; - } - else - return value; + u32 c0 = ui_opacity( GUI_COL_DARK, 0.36f ), + c1 = ui_opacity( GUI_COL_DARK, 0.5f ); + + struct ui_vert *vs = ui_fill( ctx, rect, c0 ); + + vs[0].colour = c1; + vs[1].colour = c1; + + rect[1] += 4; + ui_text( ctx, rect, label, 1, k_ui_align_middle_center, 1 ); + rect[0] += 1; + rect[1] -= 1; + ui_text( ctx, rect, label, 1, k_ui_align_middle_center, colour? colour: + ui_colour(ctx, k_ui_blue+k_ui_brighter) ); } -static void menu_setitem_type( ent_menuitem *item, - enum ent_menuitem_type type ){ - if( !item ) return; - item->type = type; +static u32 medal_colour( ui_context *ctx, u32 flags ) +{ + if( flags & k_ent_route_flag_achieve_gold ) + return ui_colour( ctx, k_ui_yellow ); + else if( flags & k_ent_route_flag_achieve_silver ) + return ui_colour( ctx, k_ui_fg ); + else return 0; } -/* - * Run from vg_gui every frame - */ -void menu_update(void) +static i32 menu_nav( i32 *p_row, int mv, i32 max ) { - if( workshop_form.page != k_workshop_form_hidden ){ - return; + i32 row_prev = *p_row; + + if( mv < 0 ) *p_row = vg_min( max, (*p_row) +1 ); + if( mv > 0 ) *p_row = vg_max( 0, (*p_row) -1 ); + + if( *p_row != row_prev ) + { + audio_lock(); + audio_oneshot( &audio_ui[3], 1.0f, 0.0f ); + audio_unlock(); } - int escape = button_down( k_srbind_mback ); - if( menu.credits_open || vg.settings_open ){ - if( escape ){ - menu.credits_open = 0; + return *p_row; +} - if( vg.settings_open ) - vg_settings_close(); +static void menu_try_find_cam( i32 id ) +{ + world_instance *world = &world_static.instances[0]; + for( u32 i=0; ient_npc); i ++ ) + { + ent_npc *fnpc = mdl_arritm( &world->ent_npc, i ); + if( (fnpc->id == 50) && (fnpc->context == id) ) + { + if( mdl_entity_id_type(fnpc->camera) == k_ent_camera ) + { + u32 index = mdl_entity_id_id( fnpc->camera ); + menu.bg_cam = mdl_arritm( &world->ent_camera, index ); + menu.bg_blur = 0; + } } - return; } +} + +static void menu_link_modal( const char *url ) +{ + menu.web_link = url; + + /* Only reset the choice of browser if 'No' was selected. */ + if( menu.web_choice == 2 ) + menu.web_choice = 0; +} - if( button_down( k_srbind_mopen ) ){ - if( skaterift.activity == k_skaterift_default ){ - skaterift.activity = k_skaterift_menu; - menu.page = 0xffffffff; - menu_open_page( "Main Menu", k_ent_menuitem_stack_append ); +void menu_gui( ui_context *ctx ) +{ + if( button_down( k_srbind_mopen ) ) + { + if( skaterift.activity == k_skaterift_default ) + { + menu_open( k_menu_page_main ); return; } } - if( skaterift.activity != k_skaterift_menu ) return; - enum menu_input_mode prev_mode = menu.input_mode; + if( skaterift.activity != k_skaterift_menu ) + return; + + menu.bg_blur = 1; + menu.bg_cam = NULL; /* get buttons inputs * -------------------------------------------------------------------*/ - int ml = button_down( k_srbind_mleft ), - mr = button_down( k_srbind_mright ), - mu = button_down( k_srbind_mup ), - md = button_down( k_srbind_mdown ), + int ml = button_press( k_srbind_mleft ), + mr = button_press( k_srbind_mright ), + mu = button_press( k_srbind_mup ), + md = button_press( k_srbind_mdown ), mh = ml-mr, mv = mu-md, enter = button_down( k_srbind_maccept ); - if( mh||mv||enter ){ - menu.input_mode = k_menu_input_mode_keys; + /* TAB CONTROL */ + u8 lb_down = 0, rb_down = 0; + vg_exec_input_program( k_vg_input_type_button_u8, + (vg_input_op[]){ + vg_joy_button, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, vg_end + }, &rb_down ); + vg_exec_input_program( k_vg_input_type_button_u8, + (vg_input_op[]){ + vg_joy_button, SDL_CONTROLLER_BUTTON_LEFTSHOULDER, vg_end + }, &lb_down ); + + int mtab = (i32)rb_down - (i32)lb_down; + + if( menu.repeater > 0.0f ) + { + menu.repeater -= vg_minf( vg.time_frame_delta, 0.5f ); + mv = 0; + mh = 0; + mtab = 0; } - - /* get mouse inputs - * --------------------------------------------------------------------*/ - menu.mouse_dist += v2_length( vg.mouse_delta ); /* TODO: Move to UI */ - menu.mouse_track += vg.time_frame_delta; - if( menu.mouse_track > 0.1f ){ - menu.mouse_track = fmodf( menu.mouse_track, 0.1f ); - if( menu.mouse_dist > 10.0f ){ - menu.input_mode = k_menu_input_mode_mouse; - menu.mouse_dist = 0.0f; - } + else + { + if( mv || mh || mtab ) + menu.repeater += 0.2f; } - if( ui_clicking(UI_MOUSE_LEFT) || ui_clicking(UI_MOUSE_RIGHT) ){ - menu.input_mode = k_menu_input_mode_mouse; - } - - if( menu.input_mode == k_menu_input_mode_mouse ){ - /* - * handle mouse input - * ------------------------------------------------------------*/ - vg_ui.wants_mouse = 1; - - /* - * this raycasting is super cumbersome because all the functions were - * designed for other purposes. we dont care though. - */ - m4x4f inverse; - m4x4_inv( menu.view.mtx.p, inverse ); - v4f coords; - coords[0] = vg_ui.mouse[0]; - coords[1] = vg.window_y - vg_ui.mouse[1]; - v2_div( coords, (v2f){ vg.window_x, vg.window_y }, coords ); - v2_muls( coords, 2.0f, coords ); - v2_add( coords, (v2f){-1.0f,-1.0f}, coords ); - coords[2] = 1.0f; - coords[3] = 1.0f; - m4x4_mulv( inverse, coords, coords ); - v3f ray; - m3x3_mulv( menu.view.transform, coords, ray ); - v3_normalize( ray ); - - if( menu.loc && (menu.loc->type == k_ent_menuitem_type_slider) && - ui_clicking(UI_MOUSE_LEFT) && menu.loc->pf32 ){ - - u32 il = mdl_entity_id_id( menu.loc->slider.id_min ), - ir = mdl_entity_id_id( menu.loc->slider.id_max ); - ent_marker *ml = mdl_arritm( &menu.markers, il ), - *mr = mdl_arritm( &menu.markers, ir ); - - v3f q2; - v3_muladds( menu.view.pos, ray, 100.0f, q2 ); - - f32 s,t; - v3f c1, c2; - v3f p1, q1, v0; - v3_sub( mr->transform.co, ml->transform.co, v0 ); - v3_muladds( ml->transform.co, v0, -1.0f, p1 ); - v3_muladds( mr->transform.co, v0, 1.0f, q1 ); - closest_segment_segment( p1, q1, menu.view.pos, q2, &s,&t, c1,c2 ); - - s-=(1.0f/3.0f); - s/=(1.0f/3.0f); - - if( ui_click_down(UI_MOUSE_LEFT) ){ - menu.slider_offset = *menu.loc->pf32 - s; - } + if( vg_input.display_input_method == k_input_method_kbm ) + { + ui_capture_mouse(ctx, 1); + } - f32 newvalue = vg_clampf( s+menu.slider_offset, 0.0f, 1.0f ); + if( skaterift.activity != k_skaterift_menu ) return; - newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 0.00f ); - newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 1.00f ); - newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 0.25f ); - newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 0.50f ); - newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 0.75f ); - *menu.loc->pf32 = newvalue; - return; - } + if( menu.web_link ) + { + menu_try_find_cam( 3 ); - ent_menuitem *hit_item = NULL; + ui_rect panel = { 0,0, 800, 200 }, + screen = { 0,0, vg.window_x,vg.window_y }; + ui_rect_center( screen, panel ); + ui_fill( ctx, panel, GUI_COL_DARK ); + ui_outline( ctx, panel, 1, GUI_COL_NORM, 0 ); + ui_rect_pad( panel, (ui_px[]){8,8} ); - for( u32 i=0; ifont = &vgf_default_title; + ui_text( ctx, title, "Open Link?", 1, k_ui_align_middle_center, 0 ); - if( item->type == k_ent_menuitem_type_page ) continue; - if( (item->type == k_ent_menuitem_type_visual) || - (item->type == k_ent_menuitem_type_visual_nocol) ) continue; - if( item->type == k_ent_menuitem_type_binding ) continue; - if( !(item->groups & (0x1<font = &vgf_default_large; + ui_text( ctx, title, menu.web_link, 1, k_ui_align_middle_center, 0 ); - ent_menuitem *ray_item = item; + ui_rect end = { panel[0], panel[1] + panel[3] - 48, panel[2], 48 }; - if( item->type == k_ent_menuitem_type_slider ){ - u32 subtarget = mdl_entity_id_id( item->slider.id_handle ); - ray_item = mdl_arritm( &menu.items, subtarget ); - } - - v3f local_ray, - local_co; - - m4x3f inverse_mtx; - mdl_transform_m4x3( &ray_item->transform, inverse_mtx ); - m4x3_invert_full( inverse_mtx, inverse_mtx ); - - m4x3_mulv( inverse_mtx, menu.view.transform[3], local_co ); - m3x3_mulv( inverse_mtx, ray, local_ray ); - v3_normalize( local_ray ); - - local_ray[0] = 1.0f/local_ray[0]; - local_ray[1] = 1.0f/local_ray[1]; - local_ray[2] = 1.0f/local_ray[2]; - - for( u32 j=0; jsubmesh_count; j++ ){ - mdl_submesh *sm = mdl_arritm( &menu.model.submeshs, - ray_item->submesh_start + j ); - if( ray_aabb1( sm->bbx, local_co, local_ray, 1000.0f ) ){ - hit_item = item; - break; - } - } - } + ui_rect a,b,c; + ui_split_ratio( end, k_ui_axis_v, 2.0/3.0, 2, a, c ); + ui_split_ratio( a, k_ui_axis_v, 1.0/2.0, 2, a, b ); - if( hit_item != menu.loc ){ - menu.loc = hit_item; - } + i32 R = menu_nav( &menu.web_choice, mh, 2 ); - if( escape ){ - menu_back_page(); - } - else if( menu.loc ){ - if( ui_click_down( UI_MOUSE_LEFT ) ){ - menu_trigger_item( menu.loc ); - } - } - } - else if( menu.input_mode == k_menu_input_mode_keys ){ - /* - * handle button input - * ------------------------------------------------------------*/ - if( (prev_mode != k_menu_input_mode_keys) && !menu.loc ){ - for( u32 i=0; itype != k_ent_menuitem_type_page) && - (item->type != k_ent_menuitem_type_visual) && - (item->type != k_ent_menuitem_type_visual_nocol) && - (item->groups & (0x1<type == k_ent_menuitem_type_slider && menu.loc->pf32 ){ - f32 move = 0.0f; - - if( vg_input.display_input_method == k_input_method_controller ){ - move += button_press( k_srbind_mright ); - move -= button_press( k_srbind_mleft ); - } - else{ - move += axis_state( k_sraxis_mbrowse_h ); - } - - move *= vg.time_frame_delta; - *menu.loc->pf32 = vg_clampf( *menu.loc->pf32 + move, 0.0f, 1.0f ); - - mh = 0; + if( menu_button( ctx, b, R==1, "Web Browser" ) ) + { + char buf[512]; + vg_str str; + vg_strnull( &str, buf, sizeof(buf) ); +#ifdef _WIN32 + vg_strcat( &str, "start " ); +#else + vg_strcat( &str, "xdg-open " ); +#endif + vg_strcat( &str, menu.web_link ); + + if( vg_strgood(&str) ) + system( buf ); + + menu.web_link = NULL; } - if( escape ){ - menu_back_page(); - } - else if( enter ){ - menu_trigger_item( menu.loc ); + if( menu_button( ctx, c, R==2, "No" ) || button_down( k_srbind_mback ) ) + { + audio_lock(); + audio_oneshot( &audio_ui[3], 1.0f, 0.0f ); + audio_unlock(); + menu.web_link = NULL; } - else if( mh||mv ){ - v3f opt; - v3_zero( opt ); - f32 best = 0.707f; - ent_menuitem *nextpos = NULL; - - opt[0] += mh; - opt[2] += mv; - mdl_transform_vector( &menu.cam->transform, opt, opt ); - - for( u32 i=0; i<4; i++ ){ - u32 id = menu.loc->id_links[i]; - if( !id ) continue; - u32 index = mdl_entity_id_id( id ); - - ent_menuitem *other = mdl_arritm( &menu.items, index ); - v3f delta; - v3_sub( menu.loc->transform.co, other->transform.co, delta ); - v3_normalize( delta ); - - f32 score = v3_dot( delta, opt ); - if( score > best ){ - best = score; - nextpos = other; - } - } - if( nextpos ){ - menu.loc = nextpos; - } - } + goto menu_draw; } - menu_setitem_type( menu.ctr_deck, k_ent_menuitem_type_disabled ); - menu_setitem_type( menu.ctr_ps, k_ent_menuitem_type_disabled ); - menu_setitem_type( menu.ctr_kbm, k_ent_menuitem_type_disabled ); - menu_setitem_type( menu.ctr_xbox, k_ent_menuitem_type_disabled ); - menu_setitem_type( menu.ctr_steam, k_ent_menuitem_type_disabled ); - if( vg_input.display_input_method == k_input_method_kbm ) - menu_setitem_type( menu.ctr_kbm, k_ent_menuitem_type_visual_nocol ); - else{ - if( vg_input.display_input_type == SDL_CONTROLLER_TYPE_PS3 || - vg_input.display_input_type == SDL_CONTROLLER_TYPE_PS4 || - vg_input.display_input_type == SDL_CONTROLLER_TYPE_PS5 ){ - menu_setitem_type( menu.ctr_ps, k_ent_menuitem_type_visual_nocol ); - } - else { - menu_setitem_type( menu.ctr_xbox, k_ent_menuitem_type_visual_nocol ); + if( vg.settings_open ) + { + if( button_down( k_srbind_mback ) ) + { + audio_lock(); + audio_oneshot( &audio_ui[3], 1.0f, 0.0f ); + audio_unlock(); + vg_settings_close(); + srinput.state = k_input_state_resume; } - /* FIXME: Steam/Deck controller detection? */ - } -} - -static void menu_binding_string( char buf[128], u32 pstr ); - -/* - * Run from vg_gui when active - */ -void menu_render(void) -{ - glEnable(GL_BLEND); - glDisable(GL_DEPTH_TEST); - glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - glBlendEquation(GL_FUNC_ADD); - shader_blitcolour_use(); - v4f colour; - ui_hex_to_norm( ui_colour( k_ui_bg+3 ), colour ); - colour[3] = 0.5f; - - shader_blitcolour_uColour( colour ); - render_fsquad(); - - if( (workshop_form.page != k_workshop_form_hidden) || - (vg_ui.focused_control_type != k_ui_control_none) ){ return; } - if( vg.settings_open ) - return; - - if( menu.credits_open ){ - ui_rect panel = { 0,0, 460, 400 }, + if( menu.page == k_menu_page_credits ) + { + ui_rect panel = { 0,0, 600, 400 }, screen = { 0,0, vg.window_x,vg.window_y }; ui_rect_center( screen, panel ); - ui_fill( panel, ui_colour(k_ui_bg) ); - ui_outline( panel, 1, ui_colour(k_ui_fg), 0 ); + ui_fill( ctx, panel, GUI_COL_DARK ); + ui_outline( ctx, 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_text( title, "Skate Rift - Credits", 2, k_ui_align_middle_center, 0 ); + ctx->font = &vgf_default_title; + ui_text( ctx, title, "Skate Rift - Credits", + 1, k_ui_align_middle_center, 0 ); + ui_split( panel, k_ui_axis_h, 28, 0, title, panel ); - ui_text( title, "Mt.Zero Software", 1, k_ui_align_middle_center, 0 ); + ctx->font = &vgf_default_large; + ui_text( ctx, title, + "Mt.Zero Software", 1, k_ui_align_middle_center, 0 ); ui_split( panel, k_ui_axis_h, 8, 0, title, panel ); ui_split( panel, k_ui_axis_h, 28*2, 0, title, panel ); - ui_text( title, "Free Software", 2, k_ui_align_middle_center, 0 ); + ctx->font = &vgf_default_title; + ui_text( ctx, title, "Free Software", 1, k_ui_align_middle_center, 0 ); ui_split( panel, k_ui_axis_h, 8, 0, title, panel ); - ui_text( panel, + ctx->font = &vgf_default_large; + ui_text( ctx, 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,stb_include\n" + "Sean Barrett - stb_image, stb_vorbis,\n" + " stb_include\n" "Khronos Group - OpenGL\n" , 1, k_ui_align_left, 0 ); - return; + + ui_rect end = { panel[0], panel[1] + panel[3] - 64, panel[2], 64 }; + + if( menu_button( ctx, end, 1, "Back" ) || button_down( k_srbind_mback ) ) + { + menu.page = k_menu_page_main; + } + + goto menu_draw; } + else if( menu.page == k_menu_page_starter ) + { + i32 R = menu_nav( &menu.intro_row, mv, 3 ); + ui_rect panel = { 0,0, 600, 400 }, + screen = { 0,0, vg.window_x,vg.window_y }; + ui_rect_center( screen, panel ); + ui_fill( ctx, panel, ui_opacity( GUI_COL_DARK, 0.35f ) ); + ui_outline( ctx, panel, 1, GUI_COL_NORM, 0 ); + ui_rect_pad( panel, (ui_px[]){8,8} ); - glEnable( GL_DEPTH_TEST ); - glDisable( GL_BLEND ); + ui_rect title; + ui_split( panel, k_ui_axis_h, 28*2, 0, title, panel ); + ctx->font = &vgf_default_title; + ui_text( ctx, title, + "Welcome to Skate Rift", 1, k_ui_align_middle_center, 0 ); - f32 rate = vg.time_frame_delta * 12.0f; + ui_split( panel, k_ui_axis_h, 28, 0, title, panel ); + ctx->font = &vgf_default_large; + + menu_checkbox( ctx, panel, R == 0, + "Show controls overlay (good for new players)", + &control_overlay.enabled ); + menu_checkbox( ctx, panel, R == 1, "Auto connect to global server", + &network_client.auto_connect ); + + ui_rect end = { panel[0], panel[1] + panel[3] - 100, panel[2], 100 }; + menu_checkbox( ctx, end, R == 2, + "Don't show this again", &menu.skip_starter ); + if( menu_button( ctx, end, R == 3, "OK" ) ) + { + menu.page = k_menu_page_main; + skaterift.activity = k_skaterift_default; + } - if( menu.cam ){ - vg_camera target; + menu_try_find_cam( 3 ); + goto menu_draw; + } + else if( menu.page == k_menu_page_premium ) + { + i32 R = menu_nav( &menu.prem_row, mh, 1 ); + ui_rect panel = { 0,0, 600, 400+240 }, + screen = { 0,0, vg.window_x,vg.window_y }; + ui_rect_center( screen, panel ); + ui_fill( ctx, panel, ui_opacity( GUI_COL_DARK, 0.35f ) ); + ui_outline( ctx, panel, 1, GUI_COL_NORM, 0 ); + ui_rect_pad( panel, (ui_px[]){8,8} ); - target.fov = menu.cam->fov; - v3_copy( menu.cam->transform.co, target.pos ); + ui_rect title; + ui_split( panel, k_ui_axis_h, 28*2, 0, title, panel ); + ctx->font = &vgf_default_title; + ui_text( ctx, title, "Content is in the full game.", + 1, k_ui_align_middle_center, 0 ); - v3f v0; - mdl_transform_vector( &menu.cam->transform, (v3f){0.0f,-1.0f,0.0f}, v0 ); - v3_angles( v0, target.angles ); + ui_split( panel, k_ui_axis_h, 28, 0, title, panel ); + ctx->font = &vgf_default_large; - vg_camera_lerp( &menu.view, &target, rate, &menu.view ); + ui_rect img; + ui_split( panel, k_ui_axis_h, 456, 0, img, panel ); + ui_image( ctx, img, &menu.prem_tex ); - menu.view.farz = 150.0f; - menu.view.nearz = 0.01f; + ui_rect end = { panel[0], panel[1] + panel[3] - 48, panel[2], 48 }, a,b; + ui_split_ratio( end, k_ui_axis_v, 0.5f, 2, a, b ); - vg_camera_update_transform( &menu.view ); - vg_camera_update_view( &menu.view ); - vg_camera_update_projection( &menu.view ); - vg_camera_finalize( &menu.view ); - } - else return; + if( menu_button( ctx, a, R == 0, "Store Page" ) ) + { + if( steam_ready ) + SteamAPI_ISteamFriends_ActivateGameOverlayToStore( + SteamAPI_SteamFriends(), 2103940, k_EOverlayToStoreFlag_None); + } - shader_model_menu_use(); - shader_model_menu_uTexMain( 1 ); - shader_model_menu_uPv( menu.view.mtx.pv ); - shader_model_menu_uPvmPrev( menu.view.mtx_prev.pv ); + if( menu_button( ctx, b, R == 1, "Nah" ) || button_down( k_srbind_mback ) ) + { + audio_lock(); + audio_oneshot( &audio_ui[3], 1.0f, 0.0f ); + audio_unlock(); + skaterift.activity = k_skaterift_default; + return; + } - mesh_bind( &menu.mesh ); + goto menu_draw; + } - v4f white, blue; + /* TOP BAR + * -------------------------------------------------------------------*/ - ui_hex_to_norm( ui_colour( k_ui_fg ), white ); - ui_hex_to_norm( ui_colour( k_ui_orange+k_ui_brighter ), blue ); + ctx->font = &vgf_default_title; + ui_px height = ctx->font->ch + 16; + ui_rect topbar = { 0, 0, vg.window_x, height }; - ent_menuitem *text_list[ 8 ]; - u32 text_count = 0; + const char *opts[] = { + [k_menu_main_main] = "Menu", + [k_menu_main_map] = "Map", + [k_menu_main_settings ] = "Settings", + [k_menu_main_guide ] = "Guides" + }; - u32 current_tex = 0xffffffff; + if( mtab ) + { + menu.main_index += mtab; - for( u32 i=0; itype == k_ent_menuitem_type_disabled ) continue; - if( item->type == k_ent_menuitem_type_page ) continue; - if( !(item->groups & (0x1 << menu.page)) ) continue; + if( menu.main_index == vg_list_size(opts) ) + menu.main_index --; - if( item->type == k_ent_menuitem_type_binding ){ - if( text_count < vg_list_size(text_list) ) - text_list[ text_count ++ ] = item; - else - vg_fatal_error( "Text list overflow" ); + audio_lock(); + audio_oneshot( &audio_ui[3], 1.0f, 0.0f ); + audio_unlock(); + } - continue; + ui_px x = 0, spacer = 8; + for( u32 draw=0; draw<2; draw ++ ) + { + if( vg_input.display_input_method == k_input_method_controller ) + { + if( draw ) + { + ui_rect inf_lb = { x, 0, 32, height }; + ui_fill( ctx, inf_lb, lb_down? GUI_COL_NORM: GUI_COL_NORM ); + ui_text( ctx, inf_lb, "\x91", 1, k_ui_align_middle_center, 0 ); + } + x += 32 + spacer; } - int selected = 0; - - if( menu.loc ){ - if( menu.loc->type == k_ent_menuitem_type_slider ){ - u32 subid = menu.loc->slider.id_handle; - if( item == mdl_arritm( &menu.items, mdl_entity_id_id(subid) )) - selected = 1; - } - else{ - if( item == menu.loc ) - selected = 1; + for( i32 i=0; itype == k_ent_menuitem_type_visual_nocol ){ - shader_model_menu_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} ); + x += box[2] + spacer; } - else{ - v4f colour; - item->factive = vg_lerpf( item->factive, selected, rate ); - v4_lerp( white, blue, item->factive, colour ); - shader_model_menu_uColour( colour ); + + if( vg_input.display_input_method == k_input_method_controller ) + { + if( draw ) + { + ui_rect inf_rb = { x, 0, 32, height }; + ui_fill( ctx, inf_rb, rb_down? GUI_COL_NORM: GUI_COL_NORM ); + ui_text( ctx, inf_rb, "\x92", 1, k_ui_align_middle_center, 0 ); + } + x += 32; } - f32 scale = 1.0f+item->factive*0.1f; + if( draw ) + ui_fill( ctx, + (ui_rect){ x+8,0, vg.window_x-(x+8),height }, GUI_COL_NORM ); + else + { + x = vg.window_x/2 - x/2; + ui_fill( ctx, + (ui_rect){ 0, 0, x-8, height }, GUI_COL_NORM ); + } + } - m4x3f mmdl; - mdl_transform transform = item->transform; - v3_muls( transform.s, scale, transform.s ); - mdl_transform_m4x3( &transform, mmdl ); + if( menu.main_index == k_menu_main_map ) + { + menu.bg_blur = 0; + ctx->font = &vgf_default_large; + ui_rect title = { vg.window_x/2- 512/2, height+8, 512, 64 }; - if( item->type == k_ent_menuitem_type_toggle && item->pi32 ){ - u32 subid = mdl_entity_id_id( item->checkmark.id_check ); - ent_menuitem *subitem = mdl_arritm( &menu.items, subid ); + ui_px x = 8, + y = height+8; - v3_muladds( item->transform.co, item->checkmark.offset, scale, - subitem->transform.co ); + struct ui_vert *vs = + ui_fill( ctx, (ui_rect){ x,y, 0,height }, + world_static.active_instance? GUI_COL_DARK: GUI_COL_ACTIVE ); - subitem->fvisible = vg_lerpf( subitem->fvisible, *item->pi32, rate ); - v3_fill( subitem->transform.s, subitem->fvisible ); + char buf[64]; + vg_str str; + vg_strnull( &str, buf, sizeof(buf) ); + vg_strcat( &str, "Hub World" ); + + if( world_static.active_instance ) + { + vg_strcat( &str, " (" ); + vg_input_string( &str, input_button_list[k_srbind_mhub], 1 ); + vg_strcatch( &str, '\x06' ); + vg_strcatch( &str, '\x00' ); + vg_strcat( &str, "\x1B[0m)" ); } - else if( item->type == k_ent_menuitem_type_slider && item->pf32 ){ - u32 il = mdl_entity_id_id( item->slider.id_min ), - ir = mdl_entity_id_id( item->slider.id_max ), - ih = mdl_entity_id_id( item->slider.id_handle ); - ent_marker *ml = mdl_arritm( &menu.markers, il ), - *mr = mdl_arritm( &menu.markers, ir ); - ent_menuitem *handle = mdl_arritm( &menu.items, ih ); - - v3_lerp( ml->transform.co, mr->transform.co, *item->pf32, - handle->transform.co ); + + ui_px w = ui_text( ctx, (ui_rect){ x+8, y, 1000, height }, buf, 1, + k_ui_align_middle_left, 0 ); + w *= ctx->font->sx; + x += w + 16; + + vs[1].co[0] = x + 8; + vs[2].co[0] = x; + + x += 2; + + world_instance *world = &world_static.instances[1]; + if( world->status == k_world_status_loaded ) + { + const char *world_name = + mdl_pstr( &world->meta, world->info.pstr_name ); + + vg_strnull( &str, buf, sizeof(buf) ); + vg_strcat( &str, world_name ); + + if( !world_static.active_instance && + (vg_input.display_input_method == k_input_method_controller) ) + { + vg_strcat( &str, " (" ); + vg_input_string( &str, input_button_list[k_srbind_mhub], 1 ); + vg_strcatch( &str, '\x06' ); + vg_strcatch( &str, '\x00' ); + vg_strcat( &str, "\x1B[0m)" ); + } + + vs = ui_fill( ctx, (ui_rect){ x,y, 1000,height }, + world_static.active_instance? GUI_COL_ACTIVE: GUI_COL_DARK ); + w = ui_text( ctx, (ui_rect){ x+16,y, 1000,height }, buf, + 1, k_ui_align_middle_left, 0 ); + + w = w*ctx->font->sx + 8*3; + x += w; + + if( button_down( k_srbind_mhub ) || + ui_button_base( ctx, (ui_rect){0,y,x,height} ) == k_ui_button_click ) + { + world_switch_instance( world_static.active_instance ^ 0x1 ); + skaterift.activity = k_skaterift_default; + world_map.view_ready = 0; + } + + vs[0].co[0] += 8; + vs[1].co[0] = x + 8; + vs[2].co[0] = x; } - shader_model_menu_uMdl( mmdl ); + 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( ctx, stat_panel, c0 ); + + ui_rect_pad( stat_panel, (ui_px[2]){8,0} ); + + for( u32 i=0; ient_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 ); + ctx->font = &vgf_default_large; + + ui_rect title_box; + menu_standard_widget( ctx, stat_panel, title_box, 1 ); + + stat_panel[0] += 16; + stat_panel[2] -= 16; + ctx->font = &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; jent_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, "(Race) " ); + 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( ctx, stat_panel, r, 1 ); + ui_text( ctx, r, buf, 1, k_ui_align_middle_left, + medal_colour( ctx, route->flags ) ); + } + + for( u32 j=0; jent_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( ctx, stat_panel, r, 1 ); + ui_text( ctx, r, buf, 1, + k_ui_align_middle_left, medal_colour( ctx, flags ) ); + } + + stat_panel[0] -= 16; + stat_panel[2] += 16; - for( u32 j=0; jsubmesh_count; j++ ){ - u32 index = item->submesh_start + j; - mdl_submesh *sm = mdl_arritm( &menu.model.submeshs, index ); - - mdl_material *mat = mdl_arritm( &menu.model.materials, - sm->material_id-1 ); + u32 title_col = 0; + if( combined & k_ent_route_flag_achieve_gold ) + title_col = ui_colour( ctx, k_ui_yellow ); + else if( combined & k_ent_route_flag_achieve_silver ) + title_col = ui_colour( ctx, k_ui_fg ); - if( mat->tex_diffuse != current_tex ){ - glActiveTexture( GL_TEXTURE1 ); - glBindTexture( GL_TEXTURE_2D, menu.textures[ mat->tex_diffuse ] ); - current_tex = mat->tex_diffuse; + menu_heading( ctx, title_box, title, title_col ); } - mdl_draw_submesh( sm ); + vs[2].co[1] = stat_panel[1]; + vs[3].co[1] = stat_panel[1]; } } + else + { + if( button_down( k_srbind_mback ) ) + { + audio_lock(); + audio_oneshot( &audio_ui[3], 1.0f, 0.0f ); + audio_unlock(); + skaterift.activity = k_skaterift_default; + return; + } - if( !text_count ) return; + 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} ); - char buf[ 128 ]; + /* MAIN / MAIN + * -------------------------------------------------------------------*/ - m4x3f local; - m4x3_identity( local ); + if( menu.main_index == k_menu_main_main ) + { + i32 R = menu_nav( &menu.main_row, mv, 2 ); - font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &menu.view ); - for( u32 i=0; itransform, transform ); + if( menu_button( ctx, list, R == 0, "Resume" ) ) + { + skaterift.activity = k_skaterift_default; + return; + } - u32 variant = item->binding.font_variant; - menu_binding_string( buf, item->binding.pstr_bind ); - f32 offset = font3d_string_width( variant, buf ); + if( menu_button( ctx, list, R == 1, "Credits" ) ) + { + menu.page = k_menu_page_credits; + } - local[3][0] = -0.5f * offset; - m4x3_mul( transform, local, transform ); + ui_rect end = { list[0], list[1]+list[3]-64, list[2], 72 }; + if( menu_button( ctx, end, R == 2, "Quit Game" ) ) + { + vg.window_should_close = 1; + } + } + else if( menu.main_index == k_menu_main_settings ) + { + ui_fill( ctx, list0, ui_opacity( GUI_COL_DARK, 0.36f ) ); + ui_outline( ctx, list0, 1, GUI_COL_NORM, 0 ); + i32 R = menu_nav( &menu.settings_row, mv, 8 ); + + ctx->font = &vgf_default_large; + list[1] -= 8; + menu_heading( ctx, list, "Game", 0 ); + menu_checkbox( ctx, list, R == 0, "Show controls overlay", + &control_overlay.enabled ); + menu_checkbox( ctx, list, R == 1, "Auto connect to global server", + &network_client.auto_connect ); + + menu_heading( ctx, list, "Audio/Video", 0 ); + menu_slider( ctx, list, R == 2, "Volume", 0, 100, + &vg_audio.external_global_volume, "%.f%%" ); + menu_slider( ctx, list, R == 3, "Resolution", 0, 100, + &k_render_scale, "%.f%%" ); + menu_checkbox( ctx, list, R == 4, "Motion Blur", &k_blur_effect ); + + menu_heading( ctx, list, "Camera", 0 ); + menu_slider( ctx, list, R == 5, "Fov", 97, 135, + &k_fov, "%.1f\xb0" ); + menu_slider( ctx, list, R == 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( ctx, list, R == 7, "Invert Y Axis", &k_invert_y ); + + + ui_rect end = { list[0], list[1]+list[3]-64, list[2], 72 }; + ctx->font = &vgf_default_small; + menu_heading( ctx, end, "Advanced", 0 ); + if( menu_button( ctx, end, R == 8, "Open Engine Settings" ) ) + { + vg_settings_open(); + } + } + else if( menu.main_index == k_menu_main_guide ) + { + list0[0] = 8; + list[0] = 16; + + ui_px w = 700, + marg = list0[0]+list0[2], + pw = vg.window_x - marg, + infx = pw/2 - w/2 + marg; + ui_rect inf = { infx, height +32, w, 800 }; + + struct ui_vert *vs = NULL; + + if( menu.guide_sel && (menu.guide_sel <= 3) ) + { + vs = ui_fill( ctx, inf, ui_opacity( GUI_COL_DARK, 0.20f ) ); + ui_rect_pad( inf, (ui_px[]){8,8} ); + } - font3d_simple_draw( variant, buf, &menu.view, transform ); - } -} + ui_fill( ctx, list0, ui_opacity( GUI_COL_DARK, 0.36f ) ); + ui_outline( ctx, list0, 1, GUI_COL_NORM, 0 ); + i32 R = menu_nav( &menu.guides_row, mv, 6 ); + + ctx->font = &vgf_default_large; + list[1] -= 8; + menu_heading( ctx, list, "Info", 0 ); + if( menu.guide_sel == 1 ) + { + menu_try_find_cam( 1 ); + + ui_rect title; + ui_split( inf, k_ui_axis_h, 28*2, 0, title, inf ); + ctx->font = &vgf_default_title; + ui_text( ctx, + title, "Where to go", 1, k_ui_align_middle_center, 0 ); + + ui_split( inf, k_ui_axis_h, 28, 0, title, inf ); + ctx->font = &vgf_default_large; + ui_text( ctx, inf, + "Visit the sandcastles built by John Cockroach to be\n" + "transported into the real location. Use the map in the\n" + "menu to return back this hub island.\n" + "\n" + "You can begin training at the Volcano Island, where you\n" + "can learn movement skills. Then travel to Mt.Zero Island\n" + "or Bort Downtown to test them out. Finally the most\n" + "challenging course can be taken on at the Valley.\n" + "\n" + "Also visit the Steam Workshop for community made\n" + "locations to skate!" + , 1, k_ui_align_left, 0 ); + + vs[2].co[1] = vs[0].co[1] + 84 + vgf_default_large.sy*11 + 16; + vs[3].co[1] = vs[2].co[1]; + } + if( menu_button( ctx, list, R == 0, "Where to go" ) ) + menu.guide_sel = 1; + + if( menu.guide_sel == 3 ) + { + menu_try_find_cam( 2 ); + + ui_rect title; + ui_split( inf, k_ui_axis_h, 28*2, 0, title, inf ); + ctx->font = &vgf_default_title; + ui_text( ctx, title, "Online", 1, k_ui_align_middle_center, 0 ); + + ui_split( inf, k_ui_axis_h, 28, 0, title, inf ); + ctx->font = &vgf_default_large; + ui_text( ctx, inf, + "Connection to the global server is managed by this radar\n" + "dish in the hub island. Come back here to turn the\n" + "connection on or off.\n" + "\n" + "You'll then see other players or your friends if you go\n" + "to the same location, and your highscores will be saved\n" + "onto the scoreboards." + , 1, k_ui_align_left, 0 ); + + vs[2].co[1] = vs[0].co[1] + 84 + vgf_default_large.sy*7 + 16; + vs[3].co[1] = vs[2].co[1]; + } + if( menu_button( ctx, list, R == 1, "Playing Online" ) ) + menu.guide_sel = 3; + + menu_heading( ctx, list, "Controls", 0 ); + if( menu_button( ctx, list, R == 2, "Skating \xb2" ) ) + { + menu.guide_sel = 0; + menu_link_modal( + "https://skaterift.com/index.php?page=movement" ); + } + if( menu.guide_sel == 0 || menu.guide_sel > 3 ) menu_try_find_cam( 3 ); -static void menu_binding_string( char buf[128], u32 pstr ){ - vg_str str; - vg_strnull( &str, buf, 128 ); + if( menu_button( ctx, list, R == 3, "Tricks \xb2" ) ) + { + menu.guide_sel = 0; + menu_link_modal( + "https://skaterift.com/index.php?page=tricks" ); + } - if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_jump" ) ){ - vg_input_string( &str, input_button_list[k_srbind_jump], 1 ); - } - else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_trick0" ) ){ - vg_strcat( &str, "SHUVIT " ); - vg_input_string( &str, input_button_list[k_srbind_trick0], 1 ); - } - else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_trick1" ) ){ - vg_strcat( &str, "KICKFLIP " ); - vg_input_string( &str, input_button_list[k_srbind_trick1], 1 ); - } - else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_trick2" ) ){ - vg_strcat( &str, "TREFLIP " ); - vg_input_string( &str, input_button_list[k_srbind_trick2], 1 ); - } - else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_grab" ) ){ - vg_input_string( &str, input_axis_list[k_sraxis_grab], 1 ); - } - else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_grab_mod" ) ){ - vg_input_string( &str, input_joy_list[k_srjoystick_grab], 1 ); + menu_heading( ctx, list, "Workshop", 0 ); + if( menu_button( ctx, list, R == 4, "Create a Board \xb2" ) ) + { + menu.guide_sel = 0; + menu_link_modal( + "https://skaterift.com/index.php?page=workshop_board" ); + } + if( menu_button( ctx, list, R == 5, "Create a World \xb2" ) ) + { + menu.guide_sel = 0; + menu_link_modal( + "https://skaterift.com/index.php?page=workshop_world" ); + } + if( menu_button( ctx, list, R == 6, "Create a Playermodel \xb2" ) ) + { + menu.guide_sel = 0; + menu_link_modal( + "https://skaterift.com/index.php?page=workshop_player" ); + } + } } - else - vg_strcat( &str, "error" ); + +menu_draw: + + vg_ui.frosting = 0.015f; + ui_flush( ctx, k_ui_shader_colour, NULL ); + vg_ui.frosting = 0.0f; + ctx->font = &vgf_default_small; }