X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=menu.h;h=86f573620f5fa10ecabe789d0a8d09b5590bc3c3;hb=137d40d96fe923600d8378b8e138e3c276f27ff4;hp=44feffdf8cec1f2d5b219c61db681d149b591a9f;hpb=844527ec68c063d78d4993bd8e4053f9ddc47b78;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/menu.h b/menu.h index 44feffd..86f5736 100644 --- a/menu.h +++ b/menu.h @@ -9,6 +9,8 @@ #include "audio.h" #include "input.h" #include "workshop.h" +#include "respawn.h" +#include "gui.h" #define MENU_STACK_SIZE 8 @@ -17,7 +19,14 @@ struct { int disable_open; u32 page, /* current page index */ - page_depth; + page_depth, + controls_page_id; + + ent_menuitem *ctr_kbm, + *ctr_deck, + *ctr_ps, + *ctr_steam, + *ctr_xbox; enum menu_input_mode{ k_menu_input_mode_keys, @@ -49,8 +58,7 @@ static menu; /* * Attaches memory locations to the various items in the menu */ -static void menu_link(void) -{ +static void menu_link(void){ /* link data locations */ for( u32 i=0; ipvoid = NULL; } } + + /* 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; + } } static void menu_close(void){ @@ -135,9 +165,7 @@ static void menu_init(void){ /* * Drop back a page until we're at the bottom which then we jus quit */ -static void menu_back_page(void) -{ - vg_info( "menu_back_page()\n" ); +static void menu_back_page(void){ menu.page_depth --; if( menu.page_depth == 0 ){ menu_close(); @@ -155,12 +183,16 @@ static void menu_back_page(void) /* * Open page to the string identifier */ -static void menu_open_page( const char *name ) -{ - if( menu.page_depth >= MENU_STACK_SIZE ) - vg_fatal_error( "Stack overflow\n" ); - - vg_info( "Try to open %s\n", name ); +static void menu_open_page( const char *name, + enum ent_menuitem_stack_behaviour stackmode ){ + if( stackmode == k_ent_menuitem_stack_append ){ + if( menu.page_depth >= MENU_STACK_SIZE ) + vg_fatal_error( "Stack overflow\n" ); + } + else{ + if( menu.page_depth == 0 ) + vg_fatal_error( "Stack underflow\n" ); + } u32 hash = vg_strdjb2( name ); for( u32 i=0; igroups ); if( new_page == menu.page ){ - menu_back_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; + 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 ){ @@ -190,8 +227,6 @@ static void menu_open_page( const char *name ) u32 id = mdl_entity_id_id( item->page.id_viewpoint ); menu.cam = mdl_arritm( &menu.cameras, id ); } - vg_info( "menu page: %u (%p,%p)\n", - menu.page, menu.loc, menu.cam ); } return; } @@ -202,25 +237,32 @@ static void menu_open_page( const char *name ) /* * activate a pressable type */ -static void menu_trigger_item( ent_menuitem *item ) -{ +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; } + + /* DEPRECATED? */ else if( MDL_CONST_PSTREQ( &menu.model, q, "reset_nearest" ) ){ localplayer_cmd_respawn( 0, NULL ); menu_close(); } + /* DEPRECATED? */ else if( MDL_CONST_PSTREQ( &menu.model, q, "reset_home" ) ){ - world_static.active_instance = 0; - world_static.active_trigger_volume_count = 0; + world_set_active_instance( 0 ); localplayer.viewable_world = world_current_instance(); localplayer_cmd_respawn( 1, (const char *[]){"start"} ); menu_close(); } + + else if( MDL_CONST_PSTREQ( &menu.model, q, "reset" ) ){ + menu_close(); + respawn_begin_chooser(); + } + else if( MDL_CONST_PSTREQ( &menu.model, q, "credits" ) ){ menu.credits_open = 1; } @@ -229,7 +271,8 @@ static void menu_trigger_item( ent_menuitem *item ) } } else if( item->type == k_ent_menuitem_type_page_button ){ - menu_open_page( mdl_pstr( &menu.model, item->button.pstr ) ); + menu_open_page( mdl_pstr( &menu.model, item->button.pstr ), + item->button.stack_behaviour ); } else if( item->type == k_ent_menuitem_type_toggle ){ if( item->pi32 ){ @@ -238,8 +281,7 @@ static void menu_trigger_item( ent_menuitem *item ) } } -static f32 menu_slider_snap( f32 value, f32 old, f32 notch ) -{ +static f32 menu_slider_snap( f32 value, f32 old, f32 notch ){ f32 const k_epsilon = 0.0125f; if( fabsf(notch-value) < k_epsilon ){ @@ -255,6 +297,12 @@ static f32 menu_slider_snap( f32 value, f32 old, f32 notch ) return value; } +static void menu_setitem_type( ent_menuitem *item, + enum ent_menuitem_type type ){ + if( !item ) return; + item->type = type; +} + /* * Run from vg_gui every frame */ @@ -275,7 +323,7 @@ static void menu_update(void){ if( skaterift.activity == k_skaterift_default ){ skaterift.activity = k_skaterift_menu; menu.page = 0xffffffff; - menu_open_page( "Main Menu" ); + menu_open_page( "Main Menu", k_ent_menuitem_stack_append ); return; } } @@ -382,7 +430,9 @@ static void menu_update(void){ ent_menuitem *item = mdl_arritm( &menu.items, i ); if( item->type == k_ent_menuitem_type_page ) continue; - if( item->type == k_ent_menuitem_type_visual ) 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<type != 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_disabled ) continue; if( item->type == k_ent_menuitem_type_page ) continue; if( !(item->groups & (0x1 << menu.page)) ) continue; + 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" ); + + continue; + } + int selected = 0; if( menu.loc ){ @@ -623,10 +709,15 @@ VG_STATIC void menu_render(void){ } } - item->factive = vg_lerpf( item->factive, selected, rate ); - v4f colour; - v4_lerp( white, blue, item->factive, colour ); - shader_model_menu_uColour( colour ); + if( item->type == k_ent_menuitem_type_visual_nocol ){ + shader_model_menu_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} ); + } + else{ + v4f colour; + item->factive = vg_lerpf( item->factive, selected, rate ); + v4_lerp( white, blue, item->factive, colour ); + shader_model_menu_uColour( colour ); + } f32 scale = 1.0f+item->factive*0.1f; @@ -664,6 +755,64 @@ VG_STATIC void menu_render(void){ mdl_draw_submesh( mdl_arritm( &menu.model.submeshs, index )); } } + + if( !text_count ) return; + + char buf[ 128 ]; + + m4x3f local; + m4x3_identity( local ); + + font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &menu.view ); + for( u32 i=0; itransform, transform ); + + u32 variant = item->binding.font_variant; + menu_binding_string( buf, item->binding.pstr_bind ); + f32 offset = font3d_string_width( variant, buf ); + + local[3][0] = -0.5f * offset; + m4x3_mul( transform, local, transform ); + + font3d_simple_draw( variant, buf, &menu.view, transform ); + } +} + +static void menu_binding_string( char buf[128], u32 pstr ){ + vg_strncpy( "error", buf, 128, k_strncpy_allow_cutoff ); + + if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_jump" ) ){ + vg_strncpy( button_display_string(k_srbind_jump), buf, 128, + k_strncpy_allow_cutoff ); + } + else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_trick0" ) ){ + vg_str str; + vg_strnull( &str, buf, 128 ); + vg_strcat( &str, "SHUVIT " ); + vg_strcat( &str, button_display_string(k_srbind_trick0) ); + } + else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_trick1" ) ){ + vg_str str; + vg_strnull( &str, buf, 128 ); + vg_strcat( &str, "KICKFLIP " ); + vg_strcat( &str, button_display_string(k_srbind_trick1) ); + } + else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_trick2" ) ){ + vg_str str; + vg_strnull( &str, buf, 128 ); + vg_strcat( &str, "TREFLIP " ); + vg_strcat( &str, button_display_string(k_srbind_trick2) ); + } + else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_grab" ) ){ + vg_strncpy( axis_display_string(k_sraxis_grab), buf, 128, + k_strncpy_allow_cutoff ); + } + else if( MDL_CONST_PSTREQ( &menu.model, pstr, "bind_grab_mod" ) ){ + vg_strncpy( joystick_display_string(k_srjoystick_grab, 2), buf, 128, + k_strncpy_allow_cutoff ); + } } #endif /* MENU_H */