pokemon_app.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. #include "pokemon_app.h"
  2. #include "views/trade.hpp"
  3. #include "views/select_pokemon.hpp"
  4. const PokemonTable pokemon_table[] = {
  5. {"Bulbasaur", &I_bulbasaur, 0x99},
  6. {"Ivysaur", &I_ivysaur, 0x09},
  7. {"Venusaur", &I_venusaur, 0x9A},
  8. {"Charmander", &I_charmander, 0xB0},
  9. {"Charmeleon", &I_charmeleon, 0xB2},
  10. {"Charizard", &I_charizard, 0xB4},
  11. {"Squirtle", &I_squirtle, 0xB1},
  12. {"Wartortle", &I_wartortle, 0xB3},
  13. {"Blastoise", &I_blastoise, 0x1C},
  14. {"Caterpie", &I_caterpie, 0x7B},
  15. {"Metapod", &I_metapod, 0x7C},
  16. {"Butterfree", &I_butterfree, 0x7D},
  17. {"Weedle", &I_weedle, 0x70},
  18. {"Kakuna", &I_kakuna, 0x71},
  19. {"Beedrill", &I_beedrill, 0x72},
  20. {"Pidgey", &I_pidgey, 0x24},
  21. {"Pidgeotto", &I_pidgeotto, 0x96},
  22. {"Pidgeot", &I_pidgeot, 0x97},
  23. {"Rattata", &I_rattata, 0xA5},
  24. {"Raticate", &I_raticate, 0xA6},
  25. {"Spearow", &I_spearow, 0x05},
  26. {"Fearow", &I_fearow, 0x23},
  27. {"Ekans", &I_ekans, 0x6C},
  28. {"Arbok", &I_arbok, 0x2D},
  29. {"Pikachu", &I_pikachu, 0x54},
  30. {"Raichu", &I_raichu, 0x55},
  31. {"Sandshrew", &I_sandshrew, 0x60},
  32. {"Sandslash", &I_sandslash, 0x61},
  33. {"Nidoran ♀", &I_nidoranf, 0x0F},
  34. {"Nidorina", &I_nidorina, 0xA8},
  35. {"Nidoqueen", &I_nidoqueen, 0x10},
  36. {"Nidoran ♂", &I_nidoranm, 0x03},
  37. {"Nidorino", &I_nidorino, 0xA7},
  38. {"Nidoking", &I_nidoking, 0x07},
  39. {"Clefairy", &I_clefairy, 0x04},
  40. {"Clefable", &I_clefable, 0x8E},
  41. {"Vulpix", &I_vulpix, 0x52},
  42. {"Ninetales", &I_ninetales, 0x53},
  43. {"Jigglypuff", &I_jigglypuff, 0x64},
  44. {"Wigglytuff", &I_wigglytuff, 0x65},
  45. {"Zubat", &I_zubat, 0x6B},
  46. {"Golbat", &I_golbat, 0x82},
  47. {"Oddish", &I_oddish, 0xB9},
  48. {"Gloom", &I_gloom, 0xBA},
  49. {"Vileplume", &I_vileplume, 0xBB},
  50. {"Paras", &I_paras, 0x6D},
  51. {"Parasect", &I_parasect, 0x2E},
  52. {"Venonat", &I_venonat, 0x41},
  53. {"Venomoth", &I_venomoth, 0x77},
  54. {"Diglett", &I_diglett, 0x3B},
  55. {"Dugtrio", &I_dugtrio, 0x76},
  56. {"Meowth", &I_meowth, 0x4D},
  57. {"Persian", &I_persian, 0x90},
  58. {"Psyduck", &I_psyduck, 0x2F},
  59. {"Golduck", &I_golduck, 0x80},
  60. {"Mankey", &I_mankey, 0x39},
  61. {"Primeape", &I_primeape, 0x75},
  62. {"Growlithe", &I_growlithe, 0x21},
  63. {"Arcanine", &I_arcanine, 0x14},
  64. {"Poliwag", &I_poliwag, 0x47},
  65. {"Poliwhirl", &I_poliwhirl, 0x6E},
  66. {"Poliwrath", &I_poliwrath, 0x6F},
  67. {"Abra", &I_abra, 0x94},
  68. {"Kadabra", &I_kadabra, 0x26},
  69. {"Alakazam", &I_alakazam, 0x95},
  70. {"Machop", &I_machop, 0x6A},
  71. {"Machoke", &I_machoke, 0x29},
  72. {"Machamp", &I_machamp, 0x7E},
  73. {"Bellsprout", &I_bellsprout, 0xBC},
  74. {"Weepinbell", &I_weepinbell, 0xBD},
  75. {"Victreebel", &I_victreebel, 0xBE},
  76. {"Tentacool", &I_tentacool, 0x18},
  77. {"Tentacruel", &I_tentacruel, 0x9B},
  78. {"Geodude", &I_geodude, 0xA9},
  79. {"Graveler", &I_graveler, 0x27},
  80. {"Golem", &I_golem, 0x31},
  81. {"Ponyta", &I_ponyta, 0xA3},
  82. {"Rapidash", &I_rapidash, 0xA4},
  83. {"Slowpoke", &I_slowpoke, 0x25},
  84. {"Slowbro", &I_slowbro, 0x08},
  85. {"Magnemite", &I_magnemite, 0xAD},
  86. {"Magneton", &I_magneton, 0x36},
  87. {"Farfetch'd", &I_farfetchd, 0x40},
  88. {"Doduo", &I_doduo, 0x46},
  89. {"Dodrio", &I_dodrio, 0x74},
  90. {"Seel", &I_seel, 0x3A},
  91. {"Dewgong", &I_dewgong, 0x78},
  92. {"Grimer", &I_grimer, 0x0D},
  93. {"Muk", &I_muk, 0x88},
  94. {"Shellder", &I_shellder, 0x17},
  95. {"Cloyster", &I_cloyster, 0x8B},
  96. {"Gastly", &I_gastly, 0x19},
  97. {"Haunter", &I_haunter, 0x93},
  98. {"Gengar", &I_gengar, 0x0E},
  99. {"Onix", &I_onix, 0x22},
  100. {"Drowzee", &I_drowzee, 0x30},
  101. {"Hypno", &I_hypno, 0x81},
  102. {"Krabby", &I_krabby, 0x4E},
  103. {"Kingler", &I_kingler, 0x8A},
  104. {"Voltorb", &I_voltorb, 0x06},
  105. {"Electrode", &I_electrode, 0x8D},
  106. {"Exeggcute", &I_exeggcute, 0x0C},
  107. {"Exeggutor", &I_exeggutor, 0x0A},
  108. {"Cubone", &I_cubone, 0x11},
  109. {"Marowak", &I_marowak, 0x91},
  110. {"Hitmonlee", &I_hitmonlee, 0x2B},
  111. {"Hitmonchan", &I_hitmonchan, 0x2C},
  112. {"Lickitung", &I_lickitung, 0x0B},
  113. {"Koffing", &I_koffing, 0x37},
  114. {"Weezing", &I_weezing, 0x8F},
  115. {"Rhyhorn", &I_rhyhorn, 0x12},
  116. {"Rhydon", &I_rhydon, 0x01},
  117. {"Chansey", &I_chansey, 0x28},
  118. {"Tangela", &I_tangela, 0x1E},
  119. {"Kangaskhan", &I_kangaskhan, 0x02},
  120. {"Horsea", &I_horsea, 0x5C},
  121. {"Seadra", &I_seadra, 0x5D},
  122. {"Goldeen", &I_goldeen, 0x9D},
  123. {"Seaking", &I_seaking, 0x9E},
  124. {"Staryu", &I_staryu, 0x1B},
  125. {"Starmie", &I_starmie, 0x98},
  126. {"Mr. Mime", &I_mr_mime, 0x2A},
  127. {"Scyther", &I_scyther, 0x1A},
  128. {"Jynx", &I_jynx, 0x48},
  129. {"Electabuzz", &I_electabuzz, 0x35},
  130. {"Magmar", &I_magmar, 0x33},
  131. {"Pinsir", &I_pinsir, 0x1D},
  132. {"Tauros", &I_tauros, 0x3C},
  133. {"Magikarp", &I_magikarp, 0x85},
  134. {"Gyarados", &I_gyarados, 0x16},
  135. {"Lapras", &I_lapras, 0x13},
  136. {"Ditto", &I_ditto, 0x4C},
  137. {"Eevee", &I_eevee, 0x66},
  138. {"Vaporeon", &I_vaporeon, 0x69},
  139. {"Jolteon", &I_jolteon, 0x68},
  140. {"Flareon", &I_flareon, 0x67},
  141. {"Porygon", &I_porygon, 0xAA},
  142. {"Omanyte", &I_omanyte, 0x62},
  143. {"Omastar", &I_omastar, 0x63},
  144. {"Kabuto", &I_kabuto, 0x5A},
  145. {"Kabutops", &I_kabutops, 0x5B},
  146. {"Aerodactyl", &I_aerodactyl, 0xAB},
  147. {"Snorlax", &I_snorlax, 0x84},
  148. {"Articuno", &I_articuno, 0x4A},
  149. {"Zapdos", &I_zapdos, 0x4B},
  150. {"Moltres", &I_moltres, 0x49},
  151. {"Dratini", &I_dratini, 0x58},
  152. {"Dragonair", &I_dragonair, 0x59},
  153. {"Dragonite", &I_dragonite, 0x42},
  154. {"Mewtwo", &I_mewtwo, 0x83},
  155. {"Mew", &I_mew, 0x15},
  156. {},
  157. };
  158. uint32_t pokemon_exit_confirm_view(void* context) {
  159. UNUSED(context);
  160. return AppViewExitConfirm;
  161. }
  162. PokemonFap* pokemon_alloc() {
  163. PokemonFap* pokemon_fap = (PokemonFap*)malloc(sizeof(PokemonFap));
  164. // View dispatcher
  165. pokemon_fap->view_dispatcher = view_dispatcher_alloc();
  166. view_dispatcher_enable_queue(pokemon_fap->view_dispatcher);
  167. view_dispatcher_set_event_callback_context(pokemon_fap->view_dispatcher, pokemon_fap);
  168. view_dispatcher_attach_to_gui(
  169. pokemon_fap->view_dispatcher,
  170. (Gui*)furi_record_open(RECORD_GUI),
  171. ViewDispatcherTypeFullscreen);
  172. // Start Index first pokemon
  173. pokemon_fap->curr_pokemon = 0;
  174. // Set up pointer to pokemon table
  175. pokemon_fap->pokemon_table = pokemon_table;
  176. // Select Pokemon View
  177. pokemon_fap->select_view = select_pokemon_alloc(pokemon_fap);
  178. view_set_previous_callback(select_pokemon_get_view(pokemon_fap), pokemon_exit_confirm_view);
  179. view_dispatcher_add_view(
  180. pokemon_fap->view_dispatcher, AppViewSelectPokemon, select_pokemon_get_view(pokemon_fap));
  181. // Trade View
  182. pokemon_fap->trade_view = trade_alloc(pokemon_fap);
  183. view_set_previous_callback(pokemon_fap->trade_view, pokemon_exit_confirm_view);
  184. view_dispatcher_add_view(pokemon_fap->view_dispatcher, AppViewTrade, pokemon_fap->trade_view);
  185. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewSelectPokemon);
  186. return pokemon_fap;
  187. }
  188. void free_app(PokemonFap* pokemon_fap) {
  189. furi_assert(pokemon_fap);
  190. // Free views
  191. view_dispatcher_remove_view(pokemon_fap->view_dispatcher, AppViewSelectPokemon);
  192. select_pokemon_free(pokemon_fap);
  193. view_dispatcher_remove_view(pokemon_fap->view_dispatcher, AppViewTrade);
  194. trade_free(pokemon_fap);
  195. // Close records
  196. furi_record_close(RECORD_GUI);
  197. // Free rest
  198. free(pokemon_fap);
  199. pokemon_fap = NULL;
  200. }
  201. extern "C" int32_t pokemon_app(void* p) {
  202. UNUSED(p);
  203. //App* app = (App*)pokemon_alloc();
  204. PokemonFap* pokemon_fap = pokemon_alloc();
  205. furi_hal_light_set(LightRed, 0x00);
  206. furi_hal_light_set(LightGreen, 0x00);
  207. furi_hal_light_set(LightBlue, 0x00);
  208. //switch view and run dispatcher
  209. view_dispatcher_run(pokemon_fap->view_dispatcher);
  210. // Free resources
  211. free_app(pokemon_fap);
  212. return 0;
  213. }