pokemon_menu.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. /* HACK: Since we may have come from trade view, we cannot assume that
  35. * pokemon_fap->curr_pokemon is correct.
  36. * The proper way to do this would be to instead of tracking curr_pokemon
  37. * separately, have it always be derived fro the current trade_block.
  38. */
  39. pokemon_fap->curr_pokemon = pokemon_table_get_num_from_index(
  40. pokemon_fap->pokemon_table, pokemon_fap->trade_block->party_members[0]);
  41. submenu_reset(pokemon_fap->submenu);
  42. snprintf(
  43. buf,
  44. sizeof(buf),
  45. "Pokemon: %s",
  46. pokemon_fap->pokemon_table[pokemon_fap->curr_pokemon].name);
  47. submenu_add_item(
  48. pokemon_fap->submenu, buf, SelectPokemonScene, scene_change_from_main_cb, pokemon_fap);
  49. pokemon_encoded_array_to_str(
  50. name_buf, (uint8_t*)pokemon_fap->trade_block->nickname, sizeof(name_buf));
  51. snprintf(buf, sizeof(buf), "Nickname: %s", name_buf);
  52. submenu_add_item(
  53. pokemon_fap->submenu, buf, SelectNicknameScene, scene_change_from_main_cb, pokemon_fap);
  54. snprintf(buf, sizeof(buf), "Level: %d", pokemon_fap->trade_block->party[0].level);
  55. submenu_add_item(
  56. pokemon_fap->submenu, buf, SelectLevelScene, scene_change_from_main_cb, pokemon_fap);
  57. submenu_add_item(
  58. pokemon_fap->submenu,
  59. "Select Moves",
  60. SelectMoveScene,
  61. scene_change_from_main_cb,
  62. pokemon_fap);
  63. submenu_add_item(
  64. pokemon_fap->submenu,
  65. "Select Types",
  66. SelectTypeScene,
  67. scene_change_from_main_cb,
  68. pokemon_fap);
  69. submenu_add_item(
  70. pokemon_fap->submenu,
  71. stats_text[pokemon_fap->curr_stats],
  72. SelectStatsScene,
  73. scene_change_from_main_cb,
  74. pokemon_fap);
  75. snprintf(
  76. buf,
  77. sizeof(buf),
  78. "OT ID#: %05d",
  79. __builtin_bswap16(pokemon_fap->trade_block->party[0].ot_id));
  80. submenu_add_item(
  81. pokemon_fap->submenu, buf, SelectOTIDScene, scene_change_from_main_cb, pokemon_fap);
  82. pokemon_encoded_array_to_str(
  83. name_buf, (uint8_t*)pokemon_fap->trade_block->ot_name, sizeof(name_buf));
  84. snprintf(buf, sizeof(buf), "OT Name: %s", name_buf);
  85. submenu_add_item(
  86. pokemon_fap->submenu, buf, SelectOTNameScene, scene_change_from_main_cb, pokemon_fap);
  87. submenu_add_item(
  88. pokemon_fap->submenu, "Trade PKMN", TradeScene, scene_change_from_main_cb, pokemon_fap);
  89. submenu_set_selected_item(
  90. pokemon_fap->submenu,
  91. scene_manager_get_scene_state(pokemon_fap->scene_manager, MainMenuScene));
  92. view_dispatcher_set_navigation_event_callback(
  93. pokemon_fap->view_dispatcher, main_menu_back_event_callback);
  94. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewMainMenu);
  95. }
  96. bool null_scene_on_event(void* context, SceneManagerEvent event) {
  97. UNUSED(context);
  98. UNUSED(event);
  99. return false;
  100. }
  101. void null_scene_on_exit(void* context) {
  102. UNUSED(context);
  103. }
  104. void (*const pokemon_scene_on_enter_handlers[])(void*) = {
  105. main_menu_scene_on_enter,
  106. select_pokemon_scene_on_enter,
  107. select_nickname_scene_on_enter,
  108. select_level_scene_on_enter,
  109. select_move_scene_on_enter,
  110. select_move_index_scene_on_enter,
  111. select_move_set_scene_on_enter,
  112. select_type_scene_on_enter,
  113. select_stats_scene_on_enter,
  114. select_ot_id_scene_on_enter,
  115. select_ot_name_scene_on_enter,
  116. trade_scene_on_enter,
  117. };
  118. void (*const pokemon_scene_on_exit_handlers[])(void*) = {
  119. null_scene_on_exit,
  120. select_pokemon_scene_on_exit,
  121. select_nickname_scene_on_exit,
  122. select_level_scene_on_exit,
  123. null_scene_on_exit,
  124. null_scene_on_exit,
  125. null_scene_on_exit,
  126. select_type_scene_on_exit,
  127. null_scene_on_exit,
  128. select_ot_id_scene_on_exit,
  129. select_ot_name_scene_on_exit,
  130. null_scene_on_exit,
  131. };
  132. bool (*const pokemon_scene_on_event_handlers[])(void*, SceneManagerEvent) = {
  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. null_scene_on_event,
  143. null_scene_on_event,
  144. null_scene_on_event,
  145. };
  146. const SceneManagerHandlers pokemon_scene_manager_handlers = {
  147. .on_enter_handlers = pokemon_scene_on_enter_handlers,
  148. .on_exit_handlers = pokemon_scene_on_exit_handlers,
  149. .on_event_handlers = pokemon_scene_on_event_handlers,
  150. .scene_num = SceneCount,
  151. };