X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=menu.h;h=2071440c365c2bd24a89ab102deb59a94e819e57;hb=f252ecb6f870260e0e944579ef732b94d1ed0ebe;hp=9f62242cc42de8589ea94d679bcca2260de0a7f3;hpb=9eb3de757a997becb8406417a4bf613f4cb04900;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/menu.h b/menu.h index 9f62242..2071440 100644 --- a/menu.h +++ b/menu.h @@ -9,15 +9,23 @@ #include "audio.h" #include "input.h" #include "workshop.h" +#include "respawn.h" #define MENU_STACK_SIZE 8 struct { - int active, credits_open; + int credits_open; 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 +57,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){ + skaterift.activity = k_skaterift_default; + menu.page_depth = 0; + menu.page = 0xffffffff; + srinput.enabled = 0; } -static void menu_init(void) -{ +static void menu_init(void){ void *alloc = vg_mem.rtmemory; mdl_open( &menu.model, "models/rs_menu.mdl", alloc ); @@ -129,13 +164,11 @@ 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) -{ +static void menu_back_page(void){ vg_info( "menu_back_page()\n" ); menu.page_depth --; if( menu.page_depth == 0 ){ - menu.active = 0; - menu.page = 0xffffffff; + menu_close(); } else{ menu.page = menu.page_stack[ menu.page_depth ].page; @@ -150,8 +183,7 @@ static void menu_back_page(void) /* * Open page to the string identifier */ -static void menu_open_page( const char *name ) -{ +static void menu_open_page( const char *name ){ if( menu.page_depth >= MENU_STACK_SIZE ) vg_fatal_error( "Stack overflow\n" ); @@ -197,31 +229,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.page_depth = 0; - menu.active = 0; - menu.page = 0xffffffff; + menu_close(); } + /* DEPRECATED? */ else if( MDL_CONST_PSTREQ( &menu.model, q, "reset_home" ) ){ - world_static.active_world = 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(); + } - menu.page_depth = 0; - menu.active = 0; - menu.page = 0xffffffff; + 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; } @@ -239,8 +272,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 ){ @@ -256,11 +288,16 @@ 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 */ -static void menu_update(void) -{ +static void menu_update(void){ if( workshop_form.page != k_workshop_form_hidden ){ return; } @@ -274,16 +311,15 @@ static void menu_update(void) } if( button_down( k_srbind_mopen ) ){ - if( !menu.active && !menu.disable_open ){ - menu.active = 1; + if( skaterift.activity == k_skaterift_default ){ + skaterift.activity = k_skaterift_menu; menu.page = 0xffffffff; menu_open_page( "Main Menu" ); return; } } - if( !menu.active ) return; - + if( skaterift.activity != k_skaterift_menu ) return; enum menu_input_mode prev_mode = menu.input_mode; /* get buttons inputs @@ -506,13 +542,32 @@ static void menu_update(void) } } } + + 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 ); + 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 ); + } + else { + menu_setitem_type( menu.ctr_xbox, k_ent_menuitem_type_visual ); + } + /* FIXME: Steam/Deck controller detection? */ + } } /* * Run from vg_gui when active */ -VG_STATIC void menu_render(void) -{ +VG_STATIC void menu_render(void){ glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); @@ -536,7 +591,7 @@ VG_STATIC void menu_render(void) 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) ); + ui_outline( panel, 1, ui_colour(k_ui_fg), 0 ); ui_rect_pad( panel, (ui_px[]){8,8} ); ui_rect title; @@ -610,6 +665,7 @@ VG_STATIC void menu_render(void) 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;