Beispiel #1
0
static int menu_lakka_iterate(unsigned action)
{
   menu_category_t *active_category = NULL;
   menu_item_t *active_item         = NULL;
   menu_subitem_t * active_subitem  = NULL;

   if (!driver.menu)
   {
      RARCH_ERR("Cannot iterate menu, menu handle is not initialized.\n");
      return 0;
   }

   if (action == MENU_ACTION_TOGGLE &&
         g_extern.main_is_init && !g_extern.libretro_dummy)
   {
      rarch_main_command(RARCH_CMD_RESUME);
      return -1;
   }

   active_category = (menu_category_t*)&categories[menu_active_category];

   if (active_category)
      active_item = (menu_item_t*)
         &active_category->items[active_category->active_item];

   if (active_item)
      active_subitem = (menu_subitem_t*)
         &active_item->subitems[active_item->active_subitem];

   if (!active_category || !active_item)
      return 0;

   if (driver.video_data && driver.menu_ctx && driver.menu_ctx->set_texture)
      driver.menu_ctx->set_texture(driver.menu);

   if (action && depth == 1 && menu_active_category == 0 
      && active_subitem->setting)
   {
      rarch_setting_t *setting = (rarch_setting_t*)
         active_subitem->setting;

      switch (action)
      {
         case MENU_ACTION_OK:
            if (setting->cmd_trigger.idx != RARCH_CMD_NONE)
               setting->cmd_trigger.triggered = true;
            /* fall-through */
         case MENU_ACTION_LEFT:
         case MENU_ACTION_RIGHT:
         case MENU_ACTION_START:
            if (setting->type == ST_BOOL)
               menu_action_setting_boolean(setting, action);
            else if (setting->type == ST_UINT)
               menu_action_setting_unsigned_integer(setting, 0, action);
            else if (setting->type == ST_FLOAT)
               menu_action_setting_fraction(setting, action);
            else if (setting->type == ST_STRING)
               menu_action_setting_driver(setting, action);
            break;
         default:
            break;
      }
   }

   switch (action)
   {
      case MENU_ACTION_LEFT:
         if (depth == 0 && menu_active_category > 0)
         {
            menu_active_category--;
            lakka_switch_categories();
         }
         else if (depth == 1 && menu_active_category > 0 
            && (active_item->active_subitem == 1 
            || active_item->active_subitem == 2)
            && g_settings.state_slot > -1)
         {
            g_settings.state_slot--;
         }
         break;

      case MENU_ACTION_RIGHT:
         if (depth == 0 && menu_active_category < num_categories-1)
         {
            menu_active_category++;
            lakka_switch_categories();
         }
         else if (depth == 1 && menu_active_category > 0 
            && (active_item->active_subitem == 1
            || active_item->active_subitem == 2)
            && g_settings.state_slot < 255)
         {
            g_settings.state_slot++;
         }
         break;

      case MENU_ACTION_DOWN:
         if (depth == 0 
               && (active_category->active_item < 
                  (active_category->num_items - 1)))
         {
            active_category->active_item++;
            lakka_switch_items();
         }

         /* If we are on subitems level, and we do not
          * exceed the number of subitems, and we
          * are in settings or content is launched. */
         if (depth == 1
               && (active_item->active_subitem < 
                  (active_item->num_subitems -1))
               && (menu_active_category == 0 
                  || ((active_item->active_subitem < 
                        (active_item->num_subitems - 1))
                     &&
                     (g_extern.main_is_init && !g_extern.libretro_dummy)
                     && (!strcmp(g_extern.fullpath, active_item->rom)))))
         {
            active_item->active_subitem++;
            lakka_switch_subitems();
         }
         break;

      case MENU_ACTION_UP:
         if (depth == 0 && active_category->active_item > 0)
         {
            active_category->active_item--;
            lakka_switch_items();
         }
         if (depth == 1 && active_item->active_subitem > 0)
         {
            active_item->active_subitem--;
            lakka_switch_subitems();
         }
         break;

      case MENU_ACTION_OK:
         if (depth == 1 && menu_active_category > 0)
         {
            switch (active_item->active_subitem)
            {
               case 0:
                  global_alpha = 0.0;
                  if (g_extern.main_is_init && !g_extern.libretro_dummy
                        && (!strcmp(g_extern.fullpath, active_item->rom)))
                  {
                     rarch_main_command(RARCH_CMD_RESUME);
                  }
                  else
                  {
                     strlcpy(g_extern.fullpath,
                           active_item->rom, sizeof(g_extern.fullpath));
                     strlcpy(g_settings.libretro,
                           active_category->libretro,
                           sizeof(g_settings.libretro));

#ifdef HAVE_DYNAMIC
                     rarch_main_command(RARCH_CMD_LOAD_CORE);
                     rarch_main_set_state(RARCH_ACTION_STATE_LOAD_CONTENT);
#endif
                  }
                  return -1;
                  break;
               case 1:
                  global_alpha = 0.0;
                  rarch_main_command(RARCH_CMD_SAVE_STATE);
                  return -1;
                  break;
               case 2:
                  global_alpha = 0.0;
                  rarch_main_command(RARCH_CMD_LOAD_STATE);
                  return -1;
                  break;
               case 3:
                  rarch_main_command(RARCH_CMD_TAKE_SCREENSHOT);
                  break;
               case 4:
                  global_alpha = 0.0;
                  rarch_main_command(RARCH_CMD_RESET);
                  return -1;
                  break;
            }
         }
         else if (depth == 0 && active_item->num_subitems)
         {
            lakka_open_submenu();
            depth = 1;
         }
         else if (depth == 0 && 
               (menu_active_category == 0 &&
                (active_category->active_item == 
                 (active_category->num_items - 1))))
         {
            add_tween(LAKKA_DELAY, 1.0, &global_alpha, &inOutQuad, NULL);
            rarch_main_command(RARCH_CMD_QUIT_RETROARCH);
            return -1;
         }
         break;

      case MENU_ACTION_CANCEL:
         if (depth == 1)
         {
            lakka_close_submenu();
            depth = 0;
         }
         break;
      default:
         break;
   }

   if (driver.menu_ctx && driver.menu_ctx->iterate)
      driver.menu_ctx->iterate(driver.menu, action);

   if (driver.video_data && driver.menu_ctx && driver.menu_ctx->render)
      driver.menu_ctx->render();

   return 0;
}
static int menu_lakka_iterate(unsigned action)
{
   menu_category_t *active_category;
   menu_item_t *active_item;

   if (!driver.menu)
   {
      RARCH_ERR("Cannot iterate menu, menu handle is not initialized.\n");
      return 0;
   }

   active_category = NULL;
   active_item = NULL;

   active_category = (menu_category_t*)&categories[menu_active_category];

   if (active_category)
      active_item = (menu_item_t*)&active_category->items[active_category->active_item];

   if (!active_category || !active_item)
      return 0;

   if (driver.video_data && driver.menu_ctx && driver.menu_ctx->set_texture)
      driver.menu_ctx->set_texture(driver.menu);

   switch (action)
   {
      case MENU_ACTION_LEFT:
         if (depth == 0 && menu_active_category > 0)
         {
            menu_active_category--;
            lakka_switch_categories();
         }
         break;

      case MENU_ACTION_RIGHT:
         if (depth == 0 && menu_active_category < num_categories-1)
         {
            menu_active_category++;
            lakka_switch_categories();
         }
         break;

      case MENU_ACTION_DOWN:
         if (depth == 0 && active_category->active_item < active_category->num_items - 1)
         {
            active_category->active_item++;
            lakka_switch_items();
         }
         if (depth == 1 // if we are on subitems level
         && active_item->active_subitem < active_item->num_subitems -1 // and we do not exceed the number of subitems
         && (menu_active_category == 0 // and we are in settings or a rom is launched
         || ((active_item->active_subitem < active_item->num_subitems -1) && (g_extern.main_is_init && !g_extern.libretro_dummy) && strcmp(g_extern.fullpath, &active_item->rom) == 0)))
         {
            active_item->active_subitem++;
            lakka_switch_subitems();
         }
         break;

      case MENU_ACTION_UP:
         if (depth == 0 && active_category->active_item > 0)
         {
            active_category->active_item--;
            lakka_switch_items();
         }
         if (depth == 1 && active_item->active_subitem > 0)
         {
            active_item->active_subitem--;
            lakka_switch_subitems();
         }
         break;

      case MENU_ACTION_OK:
         if (depth == 1)
         {
            switch (active_item->active_subitem)
            {
               case 0:
                  global_alpha = 0.0;
                  if (g_extern.main_is_init && !g_extern.libretro_dummy
                        && strcmp(g_extern.fullpath, active_item->rom) == 0)
                     g_extern.lifecycle_state |= (1ULL << MODE_GAME);
                  else
                  {
                     strlcpy(g_extern.fullpath, active_item->rom, sizeof(g_extern.fullpath));
                     strlcpy(g_settings.libretro, active_category->libretro, sizeof(g_settings.libretro));

#ifdef HAVE_DYNAMIC
                     menu_update_system_info(driver.menu, &driver.menu->load_no_rom);
                     g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME);
#else
                     rarch_environment_cb(RETRO_ENVIRONMENT_SET_LIBRETRO_PATH, (void*)g_settings.libretro);
                     rarch_environment_cb(RETRO_ENVIRONMENT_EXEC, (void*)g_extern.fullpath);
#endif
                  }
                  return -1;
                  break;
               case 1:
                  global_alpha = 0.0;
                  rarch_save_state();
                  g_extern.lifecycle_state |= (1ULL << MODE_GAME);
                  return -1;
                  break;
               case 2:
                  global_alpha = 0.0;
                  rarch_load_state();
                  g_extern.lifecycle_state |= (1ULL << MODE_GAME);
                  return -1;
                  break;
               case 3:
                  rarch_take_screenshot();
                  break;
               case 4:
                  global_alpha = 0.0;
                  rarch_game_reset();
                  g_extern.lifecycle_state |= (1ULL << MODE_GAME);
                  return -1;
                  break;
            }
         }
         else if (depth == 0 && active_item->num_subitems)
         {
            lakka_open_submenu();
            depth = 1;
         }
         else if (depth == 0 && menu_active_category == 0 && active_item->active_subitem == 1) // Hardcoded "Quit" item index
         {
            printf("EXIT\n");
         }
         break;

      case MENU_ACTION_CANCEL:
         if (depth == 1)
         {
            lakka_close_submenu();
            depth = 0;
         }
         break;
      default:
         break;
   }

   if (driver.menu_ctx && driver.menu_ctx->iterate)
      driver.menu_ctx->iterate(driver.menu, action);

   if (driver.video_data && driver.menu_ctx && driver.menu_ctx->render)
      driver.menu_ctx->render();

   return 0;
}