#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;
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<mdl_arrcount(&menu.items); i++ ){
ent_menuitem *item = mdl_arritm( &menu.items, i );
menu.cam = mdl_arritm( &menu.cameras, id );
}
+ menu.page_stack[ menu.page_depth ++ ] = menu.page;
return;
}
}
}
}
+static void menu_back_page(void)
+{
+ if( menu.page_depth == 0 ){
+ menu.active = 0;
+ }
+ else{
+ menu.page = menu.page_stack[ -- menu.page_depth ];
+ }
+}
+
static void menu_update(void)
{
if( button_down( k_srbind_mopen ) ){
- if( menu.active ){
- menu.active = 0;
- }
- else{
- if( !menu.disable_open ){
- menu.active = 1;
- menu_open_page( "Main Menu" );
- }
+ if( !menu.active && !menu.disable_open ){
+ menu.active = 1;
+ menu_open_page( "Main Menu" );
}
}
if( menu.factive > 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);
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 );
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 );
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 );