pokemon_menu.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #include "../pokemon_app.h"
  2. #include "../pokemon_char_encode.h"
  3. #include "pokemon_menu.h"
  4. #include "pokemon_select.h"
  5. #include "pokemon_nickname.h"
  6. #include "pokemon_level.h"
  7. #include "pokemon_move.h"
  8. #include "pokemon_type.h"
  9. #include "pokemon_stats.h"
  10. #include "pokemon_ot_id.h"
  11. #include "pokemon_ot_name.h"
  12. #include "pokemon_trade.h"
  13. static void scene_change_from_main_cb(void* context, uint32_t index) {
  14. PokemonFap* pokemon_fap = (PokemonFap*)context;
  15. /* Set scene state to the current index so we can have that element highlighted when
  16. * we return.
  17. */
  18. scene_manager_set_scene_state(pokemon_fap->scene_manager, MainMenuScene, index);
  19. scene_manager_next_scene(pokemon_fap->scene_manager, index);
  20. }
  21. bool main_menu_back_event_callback(void* context) {
  22. furi_assert(context);
  23. PokemonFap* pokemon_fap = context;
  24. return scene_manager_handle_back_event(pokemon_fap->scene_manager);
  25. }
  26. void main_menu_scene_on_enter(void* context) {
  27. char buf[32];
  28. char name_buf[11]; // All name buffers are 11 bytes at most, including term
  29. PokemonFap* pokemon_fap = (PokemonFap*)context;
  30. /* Clear the scene state of the Move scene since that is used to set the
  31. * highlighted meny item.
  32. */
  33. scene_manager_set_scene_state(pokemon_fap->scene_manager, SelectMoveScene, 0);
  34. submenu_reset(pokemon_fap->submenu);
  35. snprintf(
  36. buf,
  37. sizeof(buf),
  38. "Pokemon: %s",
  39. pokemon_fap->pokemon_table[pokemon_fap->curr_pokemon].name);
  40. submenu_add_item(
  41. pokemon_fap->submenu, buf, SelectPokemonScene, scene_change_from_main_cb, pokemon_fap);
  42. pokemon_encoded_array_to_str(
  43. name_buf, (uint8_t*)pokemon_fap->trade_block->nickname, sizeof(name_buf));
  44. snprintf(buf, sizeof(buf), "Nickname: %s", name_buf);
  45. submenu_add_item(
  46. pokemon_fap->submenu, buf, SelectNicknameScene, scene_change_from_main_cb, pokemon_fap);
  47. snprintf(buf, sizeof(buf), "Level: %d", pokemon_fap->trade_block->party[0].level);
  48. submenu_add_item(
  49. pokemon_fap->submenu, buf, SelectLevelScene, scene_change_from_main_cb, pokemon_fap);
  50. submenu_add_item(
  51. pokemon_fap->submenu,
  52. "Select Moves",
  53. SelectMoveScene,
  54. scene_change_from_main_cb,
  55. pokemon_fap);
  56. submenu_add_item(
  57. pokemon_fap->submenu,
  58. "Select Types",
  59. SelectTypeScene,
  60. scene_change_from_main_cb,
  61. pokemon_fap);
  62. submenu_add_item(
  63. pokemon_fap->submenu,
  64. stats_text[pokemon_fap->curr_stats],
  65. SelectStatsScene,
  66. scene_change_from_main_cb,
  67. pokemon_fap);
  68. snprintf(
  69. buf,
  70. sizeof(buf),
  71. "OT ID#: %05d",
  72. __builtin_bswap16(pokemon_fap->trade_block->party[0].ot_id));
  73. submenu_add_item(
  74. pokemon_fap->submenu, buf, SelectOTIDScene, scene_change_from_main_cb, pokemon_fap);
  75. pokemon_encoded_array_to_str(
  76. name_buf, (uint8_t*)pokemon_fap->trade_block->ot_name, sizeof(name_buf));
  77. snprintf(buf, sizeof(buf), "OT Name: %s", name_buf);
  78. submenu_add_item(
  79. pokemon_fap->submenu, buf, SelectOTNameScene, scene_change_from_main_cb, pokemon_fap);
  80. submenu_add_item(
  81. pokemon_fap->submenu, "Trade PKMN", TradeScene, scene_change_from_main_cb, pokemon_fap);
  82. submenu_set_selected_item(
  83. pokemon_fap->submenu,
  84. scene_manager_get_scene_state(pokemon_fap->scene_manager, MainMenuScene));
  85. view_dispatcher_set_navigation_event_callback(
  86. pokemon_fap->view_dispatcher, main_menu_back_event_callback);
  87. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewMainMenu);
  88. }
  89. bool null_scene_on_event(void* context, SceneManagerEvent event) {
  90. UNUSED(context);
  91. UNUSED(event);
  92. return false;
  93. }
  94. void null_scene_on_exit(void* context) {
  95. UNUSED(context);
  96. }
  97. void (*const pokemon_scene_on_enter_handlers[])(void*) = {
  98. main_menu_scene_on_enter,
  99. select_pokemon_scene_on_enter,
  100. select_nickname_scene_on_enter,
  101. select_level_scene_on_enter,
  102. select_move_scene_on_enter,
  103. select_move_index_scene_on_enter,
  104. select_move_set_scene_on_enter,
  105. select_type_scene_on_enter,
  106. select_stats_scene_on_enter,
  107. select_ot_id_scene_on_enter,
  108. select_ot_name_scene_on_enter,
  109. trade_scene_on_enter,
  110. };
  111. void (*const pokemon_scene_on_exit_handlers[])(void*) = {
  112. null_scene_on_exit,
  113. select_pokemon_scene_on_exit,
  114. select_nickname_scene_on_exit,
  115. select_level_scene_on_exit,
  116. null_scene_on_exit,
  117. null_scene_on_exit,
  118. null_scene_on_exit,
  119. select_type_scene_on_exit,
  120. null_scene_on_exit,
  121. select_ot_id_scene_on_exit,
  122. select_ot_name_scene_on_exit,
  123. null_scene_on_exit,
  124. };
  125. bool (*const pokemon_scene_on_event_handlers[])(void*, SceneManagerEvent) = {
  126. null_scene_on_event,
  127. null_scene_on_event,
  128. null_scene_on_event,
  129. null_scene_on_event,
  130. null_scene_on_event,
  131. null_scene_on_event,
  132. null_scene_on_event,
  133. null_scene_on_event,
  134. null_scene_on_event,
  135. null_scene_on_event,
  136. null_scene_on_event,
  137. null_scene_on_event,
  138. };
  139. const SceneManagerHandlers pokemon_scene_manager_handlers = {
  140. .on_enter_handlers = pokemon_scene_on_enter_handlers,
  141. .on_exit_handlers = pokemon_scene_on_exit_handlers,
  142. .on_event_handlers = pokemon_scene_on_event_handlers,
  143. .scene_num = SceneCount,
  144. };