pokemon_menu.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #include "pokemon_pins.h"
  14. static void scene_change_from_main_cb(void* context, uint32_t index) {
  15. PokemonFap* pokemon_fap = (PokemonFap*)context;
  16. /* Set scene state to the current index so we can have that element highlighted when
  17. * we return.
  18. */
  19. scene_manager_set_scene_state(pokemon_fap->scene_manager, MainMenuScene, index);
  20. scene_manager_next_scene(pokemon_fap->scene_manager, index);
  21. }
  22. bool main_menu_back_event_callback(void* context) {
  23. furi_assert(context);
  24. PokemonFap* pokemon_fap = context;
  25. return scene_manager_handle_back_event(pokemon_fap->scene_manager);
  26. }
  27. void main_menu_scene_on_enter(void* context) {
  28. char buf[32];
  29. char name_buf[11]; // All name buffers are 11 bytes at most, including term
  30. PokemonFap* pokemon_fap = (PokemonFap*)context;
  31. /* Clear the scene state of the Move scene since that is used to set the
  32. * highlighted meny item.
  33. */
  34. scene_manager_set_scene_state(pokemon_fap->scene_manager, SelectMoveScene, 0);
  35. /* HACK: Since we may have come from trade view, we cannot assume that
  36. * pokemon_fap->curr_pokemon is correct.
  37. * The proper way to do this would be to instead of tracking curr_pokemon
  38. * separately, have it always be derived fro the current trade_block.
  39. */
  40. pokemon_fap->curr_pokemon = pokemon_table_get_num_from_index(
  41. pokemon_fap->pokemon_table, pokemon_fap->trade_block->party_members[0]);
  42. submenu_reset(pokemon_fap->submenu);
  43. snprintf(
  44. buf,
  45. sizeof(buf),
  46. "Pokemon: %s",
  47. pokemon_fap->pokemon_table[pokemon_fap->curr_pokemon].name);
  48. submenu_add_item(
  49. pokemon_fap->submenu, buf, SelectPokemonScene, scene_change_from_main_cb, pokemon_fap);
  50. pokemon_encoded_array_to_str(
  51. name_buf, (uint8_t*)pokemon_fap->trade_block->nickname, sizeof(name_buf));
  52. snprintf(buf, sizeof(buf), "Nickname: %s", name_buf);
  53. submenu_add_item(
  54. pokemon_fap->submenu, buf, SelectNicknameScene, scene_change_from_main_cb, pokemon_fap);
  55. snprintf(buf, sizeof(buf), "Level: %d", pokemon_fap->trade_block->party[0].level);
  56. submenu_add_item(
  57. pokemon_fap->submenu, buf, SelectLevelScene, scene_change_from_main_cb, pokemon_fap);
  58. submenu_add_item(
  59. pokemon_fap->submenu,
  60. "Select Moves",
  61. SelectMoveScene,
  62. scene_change_from_main_cb,
  63. pokemon_fap);
  64. submenu_add_item(
  65. pokemon_fap->submenu,
  66. "Select Types",
  67. SelectTypeScene,
  68. scene_change_from_main_cb,
  69. pokemon_fap);
  70. submenu_add_item(
  71. pokemon_fap->submenu,
  72. stats_text[pokemon_fap->curr_stats],
  73. SelectStatsScene,
  74. scene_change_from_main_cb,
  75. pokemon_fap);
  76. snprintf(
  77. buf,
  78. sizeof(buf),
  79. "OT ID#: %05d",
  80. __builtin_bswap16(pokemon_fap->trade_block->party[0].ot_id));
  81. submenu_add_item(
  82. pokemon_fap->submenu, buf, SelectOTIDScene, scene_change_from_main_cb, pokemon_fap);
  83. pokemon_encoded_array_to_str(
  84. name_buf, (uint8_t*)pokemon_fap->trade_block->ot_name, sizeof(name_buf));
  85. snprintf(buf, sizeof(buf), "OT Name: %s", name_buf);
  86. submenu_add_item(
  87. pokemon_fap->submenu, buf, SelectOTNameScene, scene_change_from_main_cb, pokemon_fap);
  88. submenu_add_item(
  89. pokemon_fap->submenu, "Trade PKMN", TradeScene, scene_change_from_main_cb, pokemon_fap);
  90. submenu_add_item(
  91. pokemon_fap->submenu,
  92. "Select Pinout",
  93. SelectPinsScene,
  94. scene_change_from_main_cb,
  95. pokemon_fap);
  96. submenu_set_selected_item(
  97. pokemon_fap->submenu,
  98. scene_manager_get_scene_state(pokemon_fap->scene_manager, MainMenuScene));
  99. view_dispatcher_set_navigation_event_callback(
  100. pokemon_fap->view_dispatcher, main_menu_back_event_callback);
  101. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewMainMenu);
  102. }
  103. bool null_scene_on_event(void* context, SceneManagerEvent event) {
  104. UNUSED(context);
  105. UNUSED(event);
  106. return false;
  107. }
  108. void null_scene_on_exit(void* context) {
  109. UNUSED(context);
  110. }
  111. void (*const pokemon_scene_on_enter_handlers[])(void*) = {
  112. main_menu_scene_on_enter,
  113. select_pokemon_scene_on_enter,
  114. select_nickname_scene_on_enter,
  115. select_level_scene_on_enter,
  116. select_move_scene_on_enter,
  117. select_move_index_scene_on_enter,
  118. select_move_set_scene_on_enter,
  119. select_type_scene_on_enter,
  120. select_stats_scene_on_enter,
  121. select_ot_id_scene_on_enter,
  122. select_ot_name_scene_on_enter,
  123. trade_scene_on_enter,
  124. select_pins_scene_on_enter,
  125. };
  126. void (*const pokemon_scene_on_exit_handlers[])(void*) = {
  127. null_scene_on_exit,
  128. select_pokemon_scene_on_exit,
  129. select_nickname_scene_on_exit,
  130. select_level_scene_on_exit,
  131. null_scene_on_exit,
  132. null_scene_on_exit,
  133. null_scene_on_exit,
  134. select_type_scene_on_exit,
  135. null_scene_on_exit,
  136. select_ot_id_scene_on_exit,
  137. select_ot_name_scene_on_exit,
  138. null_scene_on_exit,
  139. select_pins_scene_on_exit,
  140. };
  141. bool (*const pokemon_scene_on_event_handlers[])(void*, SceneManagerEvent) = {
  142. null_scene_on_event,
  143. null_scene_on_event,
  144. null_scene_on_event,
  145. null_scene_on_event,
  146. null_scene_on_event,
  147. null_scene_on_event,
  148. null_scene_on_event,
  149. null_scene_on_event,
  150. null_scene_on_event,
  151. null_scene_on_event,
  152. null_scene_on_event,
  153. null_scene_on_event,
  154. null_scene_on_event,
  155. };
  156. const SceneManagerHandlers pokemon_scene_manager_handlers = {
  157. .on_enter_handlers = pokemon_scene_on_enter_handlers,
  158. .on_exit_handlers = pokemon_scene_on_exit_handlers,
  159. .on_event_handlers = pokemon_scene_on_event_handlers,
  160. .scene_num = SceneCount,
  161. };