#include "model.h"
#include "world_render.h"
#include "player.h"
+#include "shaders/model_menu.h"
+#include "audio.h"
+#include "input.h"
+#include "workshop.h"
-#include "shaders/menu.h"
+#define MENU_STACK_SIZE 8
-static mdl_header *menu_model;
-static glmesh menu_glmesh;
-static v3f menu_cam_pos,
- menu_target_cam_pos;
-static v4f menu_cam_q = { 0.0f, 0.0f, 0.0f, 1.0f },
- menu_target_cam_q;
-static m4x3f menu_cam, menu_cam_inv;
-static float menu_opacity = 0.0f;
+struct {
+ int active, credits_open;
+ int disable_open;
+
+ u32 page, /* current page index */
+ page_depth;
+
+ enum menu_input_mode{
+ k_menu_input_mode_keys,
+ k_menu_input_mode_mouse
+ }
+ input_mode;
+ f32 mouse_track, mouse_dist; /* used for waking up mouse */
+ f32 slider_offset;
+
+ struct page_stack_frame {
+ u32 page;
+ ent_menuitem *loc;
+ ent_camera *cam;
+ }
+ page_stack[ MENU_STACK_SIZE ];
+
+ ent_menuitem *loc;
+ ent_camera *cam;
+ camera view;
+
+ mdl_context model;
+ GLuint texture;
+ glmesh mesh;
+
+ mdl_array_ptr items, markers, cameras;
+}
+static menu;
+
+/*
+ * Attaches memory locations to the various items in the menu
+ */
+static void menu_link(void)
+{
+ /* link data locations */
+ for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
+ ent_menuitem *item = mdl_arritm( &menu.items, i );
+
+ if( item->type == 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;
+ }
+ }
+}
static void menu_init(void)
{
- menu_model = mdl_load( "models/rs_menu.mdl" );
+ void *alloc = vg_mem.rtmemory;
+
+ mdl_open( &menu.model, "models/rs_menu.mdl", alloc );
+ mdl_load_metadata_block( &menu.model, alloc );
+
+ vg_linear_clear( vg_mem.scratch );
+
+ 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 );
+
+ vg_linear_clear( vg_mem.scratch );
+
+ if( !mdl_arrcount( &menu.model.textures ) )
+ vg_fatal_error( "No texture in menu file" );
+
+ mdl_texture *tex0 = mdl_arritm( &menu.model.textures, 0 );
+ void *data = vg_linear_alloc( vg_mem.scratch, tex0->file.pack_size );
+ mdl_fread_pack_file( &menu.model, &tex0->file, data );
+
+ mdl_async_load_glmesh( &menu.model, &menu.mesh );
+ vg_tex2d_load_qoi_async( data, tex0->file.pack_size,
+ VG_TEX2D_LINEAR|VG_TEX2D_CLAMP,
+ &menu.texture );
+
+ mdl_close( &menu.model );
+ shader_model_menu_register();
+}
+
+/*
+ * 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" );
+ menu.page_depth --;
+ if( menu.page_depth == 0 ){
+ menu.active = 0;
+ menu.page = 0xffffffff;
+ }
+ else{
+ menu.page = menu.page_stack[ menu.page_depth ].page;
+ menu.cam = menu.page_stack[ menu.page_depth ].cam;
+
+ if( menu.input_mode == k_menu_input_mode_keys )
+ menu.loc = menu.page_stack[ menu.page_depth ].loc;
+ else menu.loc = NULL;
+ }
+}
+
+/*
+ * 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 );
- if( !menu_model )
- vg_fatal_exit_loop( "No menu model" );
+ u32 hash = vg_strdjb2( name );
+ for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
+ ent_menuitem *item = mdl_arritm( &menu.items, i );
+
+ if( item->type == k_ent_menuitem_type_page ){
+ if( mdl_pstreq( &menu.model, item->page.pstr_name, name, hash ) ){
+ u32 new_page = __builtin_ctz( item->groups );
+
+ if( new_page == menu.page ){
+ 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 = __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 );
+ }
+ }
+
+ if( item->page.id_viewpoint ){
+ 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;
+ }
+ }
+ }
+}
+
+/*
+ * 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;
- vg_acquire_thread_sync();
- mdl_unpack_glmesh( menu_model, &menu_glmesh );
- vg_release_thread_sync();
+ if( MDL_CONST_PSTREQ( &menu.model, q, "quit" ) ){
+ vg.window_should_close = 1;
+ }
+ 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;
+ }
+ else if( MDL_CONST_PSTREQ( &menu.model, q, "reset_home" ) ){
+ world_static.active_world = 0;
+ world_static.active_trigger_volume_count = 0;
+ localplayer.viewable_world = world_current_instance();
+ localplayer_cmd_respawn( 1, (const char *[]){"start"} );
- shader_menu_register();
+ menu.page_depth = 0;
+ menu.active = 0;
+ menu.page = 0xffffffff;
+ }
+ 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( item->type == k_ent_menuitem_type_page_button ){
+ menu_open_page( mdl_pstr( &menu.model, item->button.pstr ) );
+ }
+ else if( item->type == k_ent_menuitem_type_toggle ){
+ if( item->pi32 ){
+ *item->pi32 = *item->pi32 ^ 0x1;
+ }
+ }
}
-static void menu_update( int enabled )
+static f32 menu_slider_snap( f32 value, f32 old, f32 notch )
{
- static int enabled_last = 0;
+ f32 const k_epsilon = 0.0125f;
- if( enabled && !enabled_last )
- {
- v3_copy( player.camera[3], menu_cam_pos );
- m3x3_q( player.camera, menu_cam_q );
+ 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();
+ }
- if( player.phys.on_board )
- {
- v4f r90;
- q_axis_angle( r90, player.phys.rb.up, VG_PIf*-0.5f );
- q_mul( r90, player.phys.rb.q, menu_target_cam_q );
- m4x3_mulv( player.phys.rb.to_world, (v3f){-1.0f,1.6f,0.0f},
- menu_target_cam_pos );
+ return notch;
+ }
+ else
+ return value;
+}
+
+/*
+ * Run from vg_gui every frame
+ */
+static void menu_update(void)
+{
+ if( workshop_form.page != k_workshop_form_hidden ){
+ return;
+ }
+
+ int escape = button_down( k_srbind_mback );
+ if( menu.credits_open ){
+ if( escape ){
+ menu.credits_open = 0;
}
- else
- {
- v4f r180;
- q_axis_angle( r180, player.phys.rb.up, VG_PIf );
- q_mul( r180, player.phys.rb.q, menu_target_cam_q );
- m4x3_mulv( player.phys.rb.to_world, (v3f){0.0f,1.6f,-1.0f},
- menu_target_cam_pos );
+ return;
+ }
+
+ if( button_down( k_srbind_mopen ) ){
+ if( !menu.active && !menu.disable_open ){
+ menu.active = 1;
+ menu.page = 0xffffffff;
+ menu_open_page( "Main Menu" );
+ return;
}
+ }
+
+ if( !menu.active ) return;
+
+ enum menu_input_mode prev_mode = menu.input_mode;
- q_normalize( menu_target_cam_q );
- q_normalize( menu_cam_q );
- menu_opacity = 0.0f;
+ /* 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 ),
+ mh = ml-mr,
+ mv = mu-md,
+ enter = button_down( k_srbind_maccept );
+
+ if( mh||mv||enter ){
+ menu.input_mode = k_menu_input_mode_keys;
}
- if( enabled_last && !enabled )
- {
- m3x3_q( player.camera, menu_target_cam_q );
- v3_copy( player.camera[3], menu_target_cam_pos );
+ /* 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;
+ }
}
- float dt = vg.time_delta * 6.0f;
+ 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 ){
- q_nlerp( menu_cam_q, menu_target_cam_q, dt, menu_cam_q );
- v3_lerp( menu_cam_pos, menu_target_cam_pos, dt, menu_cam_pos );
+ 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 );
- q_m3x3( menu_cam_q, menu_cam );
- v3_copy( menu_cam_pos, menu_cam[3] );
- m4x3_invert_affine( menu_cam, menu_cam_inv );
- menu_opacity = vg_lerpf( menu_opacity, enabled, dt );
+ v3f q2;
+ v3_muladds( menu.view.pos, ray, 100.0f, q2 );
- enabled_last = enabled;
+ 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;
+ }
+
+ f32 newvalue = vg_clampf( s+menu.slider_offset, 0.0f, 1.0f );
+
+ 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;
+ }
+
+ ent_menuitem *hit_item = NULL;
+
+ for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
+ 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->groups & (0x1<<menu.page)) ) continue;
+
+ ent_menuitem *ray_item = item;
+
+ 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; j<ray_item->submesh_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;
+ }
+ }
+ }
+
+ if( hit_item != menu.loc ){
+ menu.loc = hit_item;
+ }
+
+ 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; i<mdl_arrcount(&menu.items); i++ ){
+ ent_menuitem *item = mdl_arritm( &menu.items, i );
+
+ if( (item->type != k_ent_menuitem_type_page) &&
+ (item->type != k_ent_menuitem_type_visual) &&
+ (item->groups & (0x1<<menu.page)) ){
+ menu.loc = item;
+ }
+ }
+ }
+
+ if( !menu.loc ) vg_fatal_error( "No location\n" );
+
+ if( menu.loc->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( escape ){
+ menu_back_page();
+ }
+ else if( enter ){
+ menu_trigger_item( menu.loc );
+ }
+ 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;
+ }
+ }
+ }
}
-static void menu_render( m4x4f projection )
+/*
+ * Run from vg_gui when active
+ */
+VG_STATIC 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_fscolour_use();
- shader_fscolour_uColour( (v4f){ 0.1f, 0.1f, 0.3f, menu_opacity*0.5f } );
+ 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( menu.credits_open ){
+ ui_rect panel = { 0,0, 460, 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) );
+ 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 );
+ ui_split( panel, k_ui_axis_h, 28, 0, title, panel );
+ ui_text( 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, 0, title, panel );
+ ui_text( title, "A game by Harry Godden", 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 );
+
+ ui_split( panel, k_ui_axis_h, 8, 0, title, panel );
+ ui_text( 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"
+ "Khronos Group - OpenGL\n"
+ , 1, k_ui_align_left, 0 );
+ return;
+ }
+
glEnable( GL_DEPTH_TEST );
glDisable( GL_BLEND );
- m4x3f mtx;
-
- shader_menu_use();
- shader_menu_uColour( (v4f){ 1.0f,1.0f,1.0f,1.0f} );
- shader_menu_uTexMain( 1 );
- vg_tex2d_bind( &tex_graffiti, 1 );
+ f32 rate = vg.time_frame_delta * 12.0f;
+
+ if( menu.cam ){
+ camera target;
+
+ target.fov = menu.cam->fov;
+ v3_copy( menu.cam->transform.co, target.pos );
+
+ v3f v0;
+ mdl_transform_vector( &menu.cam->transform, (v3f){0.0f,-1.0f,0.0f}, v0 );
+ player_vector_angles( target.angles, v0, 1.0f, 0.0f );
+
+ camera_lerp( &menu.view, &target, rate, &menu.view );
+
+ menu.view.farz = 150.0f;
+ menu.view.nearz = 0.01f;
+
+ camera_update_transform( &menu.view );
+ camera_update_view( &menu.view );
+ camera_update_projection( &menu.view );
+ camera_finalize( &menu.view );
+ }
+ else return;
- shader_menu_uPv( projection );
- mesh_bind( &menu_glmesh );
+ shader_model_menu_use();
+ shader_model_menu_uTexMain( 1 );
+ glActiveTexture( GL_TEXTURE1 );
+ glBindTexture( GL_TEXTURE_2D, menu.texture );
+ shader_model_menu_uPv( menu.view.mtx.pv );
+ shader_model_menu_uPvmPrev( menu.view.mtx_prev.pv );
- m4x3_identity( mtx );
- shader_menu_uMdl( mtx );
- mesh_draw( &menu_glmesh );
+ mesh_bind( &menu.mesh );
- for( int i=0; i<menu_model->node_count; i++ )
- {
- mdl_node *pnode = mdl_node_from_id( menu_model, i );
+ v4f white, blue;
+
+ ui_hex_to_norm( ui_colour( k_ui_fg ), white );
+ ui_hex_to_norm( ui_colour( k_ui_orange+k_ui_brighter ), blue );
+
+ for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
+ ent_menuitem *item = mdl_arritm( &menu.items, i );
+
+ if( item->type == k_ent_menuitem_type_page ) continue;
+ if( !(item->groups & (0x1 << menu.page)) ) continue;
+
+ int selected = 0;
- for( int j=0; j<pnode->submesh_count; j++ )
- {
- mdl_submesh *sm =
- mdl_submesh_from_id( menu_model, pnode->submesh_start+j );
+ 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;
+ }
+ }
+
+ item->factive = vg_lerpf( item->factive, selected, rate );
+ v4f colour;
+ v4_lerp( white, blue, item->factive, colour );
+ shader_model_menu_uColour( colour );
+
+ f32 scale = 1.0f+item->factive*0.1f;
+
+ m4x3f mmdl;
+ mdl_transform transform = item->transform;
+ v3_muls( transform.s, scale, transform.s );
+ mdl_transform_m4x3( &transform, mmdl );
+
+ 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 );
- mdl_node_transform( pnode, mtx );
- m4x3_mul( player.phys.rb.to_world, mtx, mtx );
- shader_menu_uMdl( mtx );
+ v3_muladds( item->transform.co, item->checkmark.offset, scale,
+ subitem->transform.co );
- mdl_draw_submesh( sm );
+ subitem->fvisible = vg_lerpf( subitem->fvisible, *item->pi32, rate );
+ v3_fill( subitem->transform.s, subitem->fvisible );
}
- }
-}
+ 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 );
-static void menu_free(void *_)
-{
- mesh_free( &menu_glmesh );
+ v3_lerp( ml->transform.co, mr->transform.co, *item->pf32,
+ handle->transform.co );
+ }
+
+ shader_model_menu_uMdl( mmdl );
+
+ for( u32 j=0; j<item->submesh_count; j++ ){
+ u32 index = item->submesh_start + j;
+ mdl_draw_submesh( mdl_arritm( &menu.model.submeshs, index ));
+ }
+ }
}
#endif /* MENU_H */