X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=menu.h;h=d41017dd5074ba32ac3ae579d2f7b2990068df49;hb=e8a65239f85784e2e596d2622c2baddda9fb5fae;hp=f15b26b76836a105718893d5affc79ceb27ecf07;hpb=9d0ff08fef8507613586856de7ce25d43704db92;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/menu.h b/menu.h index f15b26b..d41017d 100644 --- a/menu.h +++ b/menu.h @@ -8,12 +8,16 @@ #include "conf.h" #include "shaders/model_menu.h" +#define MENU_STACK_SIZE 8 + struct { int active; f32 factive; int disable_open; - u32 page; /* current page index */ + u32 page, /* current page index */ + page_stack[ MENU_STACK_SIZE ], + page_depth; ent_menuitem *loc; ent_camera *cam; camera view; @@ -59,6 +63,8 @@ static void menu_init(void) static void menu_open_page( const char *name ) { + vg_info( "Try to open %s\n", name ); + u32 hash = vg_strdjb2( name ); for( u32 i=0; i 0.01f ){ } + + if( !menu.active ) return; + if( !menu.loc ) return; + if( !menu.cam ) return; + + 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 ), + mh = ml-mr, + mv = mu-md, + enter = button_down( k_srbind_maccept ), + escape = button_down( k_srbind_mback ); + + if( escape ){ + menu_back_page(); + } + else if( enter ){ + if ( menu.loc->type == k_ent_menuitem_type_event_button ){ + + } + else if( menu.loc->type == k_ent_menuitem_type_page_button ){ + menu_open_page( mdl_pstr( &menu.model, menu.loc->button.pstr ) ); + } + else if( menu.loc->type == k_ent_menuitem_type_toggle ){ + + } + } + 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; + } + } } -VG_STATIC void menu_render_bg(void) +VG_STATIC void menu_render(void) { glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); @@ -116,10 +187,7 @@ VG_STATIC void menu_render_bg(void) shader_blitcolour_use(); shader_blitcolour_uColour( (v4f){ 0.1f, 0.1f, 0.3f, menu.factive*0.5f } ); render_fsquad(); -} -VG_STATIC void menu_render_fg(void) -{ glEnable( GL_DEPTH_TEST ); glDisable( GL_BLEND ); @@ -140,7 +208,6 @@ VG_STATIC void menu_render_fg(void) else return; shader_model_menu_use(); - shader_model_menu_uColour( (v4f){ 1.0f,1.0f,1.0f,1.0f} ); shader_model_menu_uTexMain( 1 ); glActiveTexture( GL_TEXTURE1 ); glBindTexture( GL_TEXTURE_2D, menu.texture ); @@ -155,6 +222,13 @@ VG_STATIC void menu_render_fg(void) if( item->type == k_ent_menuitem_type_page ) continue; if( !(item->groups & (0x1 << menu.page)) ) continue; + if( item == menu.loc ){ + shader_model_menu_uColour( (v4f){ 0.1f,0.25f,0.9f,1.0f} ); + } + else{ + shader_model_menu_uColour( (v4f){ 1.0f,1.0f,1.0f,1.0f} ); + } + m4x3f mmdl; mdl_transform_m4x3( &item->transform, mmdl ); shader_model_menu_uMdl( mmdl );