pokemon_menu.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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,
  50. buf,
  51. SelectLevelScene,
  52. scene_change_from_main_cb,
  53. pokemon_fap);
  54. submenu_add_item(
  55. pokemon_fap->submenu,
  56. "Select Moves",
  57. SelectMoveScene,
  58. scene_change_from_main_cb,
  59. pokemon_fap);
  60. submenu_add_item(
  61. pokemon_fap->submenu,
  62. "Select Types",
  63. SelectTypeScene,
  64. scene_change_from_main_cb,
  65. pokemon_fap);
  66. submenu_add_item(
  67. pokemon_fap->submenu,
  68. stats_text[pokemon_fap->curr_stats],
  69. SelectStatsScene,
  70. scene_change_from_main_cb,
  71. pokemon_fap);
  72. snprintf(
  73. buf,
  74. sizeof(buf),
  75. "OT ID#: %05d",
  76. __builtin_bswap16(pokemon_fap->trade_block->party[0].ot_id));
  77. submenu_add_item(
  78. pokemon_fap->submenu, buf, SelectOTIDScene, scene_change_from_main_cb, pokemon_fap);
  79. pokemon_encoded_array_to_str(
  80. name_buf, (uint8_t*)pokemon_fap->trade_block->ot_name, sizeof(name_buf));
  81. snprintf(buf, sizeof(buf), "OT Name: %s", name_buf);
  82. submenu_add_item(
  83. pokemon_fap->submenu, buf, SelectOTNameScene, scene_change_from_main_cb, pokemon_fap);
  84. submenu_add_item(
  85. pokemon_fap->submenu, "Trade PKMN", TradeScene, scene_change_from_main_cb, pokemon_fap);
  86. submenu_set_selected_item(
  87. pokemon_fap->submenu,
  88. scene_manager_get_scene_state(pokemon_fap->scene_manager, MainMenuScene));
  89. view_dispatcher_set_navigation_event_callback(
  90. pokemon_fap->view_dispatcher, main_menu_back_event_callback);
  91. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewMainMenu);
  92. }
  93. bool null_scene_on_event(void* context, SceneManagerEvent event) {
  94. UNUSED(context);
  95. UNUSED(event);
  96. return false;
  97. }
  98. void null_scene_on_exit(void* context) {
  99. UNUSED(context);
  100. }
  101. void (*const pokemon_scene_on_enter_handlers[])(void*) = {
  102. main_menu_scene_on_enter,
  103. select_pokemon_scene_on_enter,
  104. select_nickname_scene_on_enter,
  105. select_level_scene_on_enter,
  106. select_move_scene_on_enter,
  107. select_move_index_scene_on_enter,
  108. select_move_set_scene_on_enter,
  109. select_type_scene_on_enter,
  110. select_stats_scene_on_enter,
  111. select_ot_id_scene_on_enter,
  112. select_ot_name_scene_on_enter,
  113. trade_scene_on_enter,
  114. };
  115. void (*const pokemon_scene_on_exit_handlers[])(void*) = {
  116. null_scene_on_exit,
  117. select_pokemon_scene_on_exit,
  118. select_nickname_scene_on_exit,
  119. select_level_scene_on_exit,
  120. null_scene_on_exit,
  121. null_scene_on_exit,
  122. null_scene_on_exit,
  123. select_type_scene_on_exit,
  124. null_scene_on_exit,
  125. select_ot_id_scene_on_exit,
  126. select_ot_name_scene_on_exit,
  127. null_scene_on_exit,
  128. };
  129. bool (*const pokemon_scene_on_event_handlers[])(void*, SceneManagerEvent) = {
  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. null_scene_on_event,
  139. null_scene_on_event,
  140. null_scene_on_event,
  141. null_scene_on_event,
  142. };
  143. const SceneManagerHandlers pokemon_scene_manager_handlers = {
  144. .on_enter_handlers = pokemon_scene_on_enter_handlers,
  145. .on_exit_handlers = pokemon_scene_on_exit_handlers,
  146. .on_event_handlers = pokemon_scene_on_event_handlers,
  147. .scene_num = SceneCount,
  148. };