small updates and api changes
[carveJwlIkooP6JGAAIwe30JlM.git] / menu.h
diff --git a/menu.h b/menu.h
index 71b3570d06190c70a133d386719f92369267be5d..2071440c365c2bd24a89ab102deb59a94e819e57 100644 (file)
--- a/menu.h
+++ b/menu.h
@@ -18,7 +18,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,
@@ -50,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; i<mdl_arrcount(&menu.items); i++ ){
       ent_menuitem *item = mdl_arritm( &menu.items, i );
@@ -94,6 +100,28 @@ static void menu_link(void)
          item->pvoid = 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; i<mdl_arrcount(&menu.items); i++ ){
+      ent_menuitem *item = mdl_arritm( &menu.items, i );
+
+      if( MDL_CONST_PSTREQ( &menu.model, item->visual.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){
@@ -136,8 +164,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)
-{
+static void menu_back_page(void){
    vg_info( "menu_back_page()\n" );
    menu.page_depth --;
    if( menu.page_depth == 0 ){
@@ -156,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" );
 
@@ -203,8 +229,7 @@ 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;
 
@@ -247,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 ){
@@ -264,6 +288,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
  */
@@ -512,6 +542,26 @@ 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? */
+   }
 }
 
 /*
@@ -541,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;
@@ -615,6 +665,7 @@ VG_STATIC void menu_render(void){
    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_disabled ) continue;
       if(   item->type == k_ent_menuitem_type_page ) continue;
       if( !(item->groups & (0x1 << menu.page)) ) continue;