pokemon_app.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include "pokemon_app.h"
  2. const char* pokemon_names[] = {
  3. "bulbasaur", "ivysaur", "venusaur", "charmander", "charmeleon", "charizard",
  4. "squirtle", "wartortle", "blastoise", "caterpie", "metapod", "butterfree",
  5. "weedle", "kakuna", "beedrill", "pidgey", "pidgeotto", "pidgeot",
  6. "rattata", "raticate", "spearow", "fearow", "ekans", "arbok",
  7. "pikachu", "raichu", "sandshrew", "sandslash", "nidoran ♀", "nidorina",
  8. "nidoqueen", "nidoran ♂", "nidorino", "nidoking", "clefairy", "clefable",
  9. "vulpix", "ninetales", "jigglypuff", "wigglytuff", "zubat", "golbat",
  10. "oddish", "gloom", "vileplume", "paras", "parasect", "venonat",
  11. "venomoth", "diglett", "dugtrio", "meowth", "persian", "psyduck",
  12. "golduck", "mankey", "primeape", "growlithe", "arcanine", "poliwag",
  13. "poliwhirl", "poliwrath", "abra", "kadabra", "alakazam", "machop",
  14. "machoke", "machamp", "bellsprout", "weepinbell", "victreebel", "tentacool",
  15. "tentacruel", "geodude", "graveler", "golem", "ponyta", "rapidash",
  16. "slowpoke", "slowbro", "magnemite", "magneton", "farfetchd", "doduo",
  17. "dodrio", "seel", "dewgong", "grimer", "muk", "shellder",
  18. "cloyster", "gastly", "haunter", "gengar", "onix", "drowzee",
  19. "hypno", "krabby", "kingler", "voltorb", "electrode", "exeggcute",
  20. "exeggutor", "cubone", "marowak", "hitmonlee", "hitmonchan", "lickitung",
  21. "koffing", "weezing", "rhyhorn", "rhydon", "chansey", "tangela",
  22. "kangaskhan", "horsea", "seadra", "goldeen", "seaking", "staryu",
  23. "starmie", "mr. mime", "scyther", "jynx", "electabuzz", "magmar",
  24. "pinsir", "tauros", "magikarp", "gyarados", "lapras", "ditto",
  25. "eevee", "vaporeon", "jolteon", "flareon", "porygon", "omanyte",
  26. "omastar", "kabuto", "kabutops", "aerodactyl", "snorlax", "articuno",
  27. "zapdos", "moltres", "dratini", "dragonair", "dragonite", "mewtwo",
  28. "mew"};
  29. const Icon* pokemon_icons[] = {
  30. &I_bulbasaur, &I_ivysaur, &I_venusaur, &I_charmander, &I_charmeleon, &I_charizard,
  31. &I_squirtle, &I_wartortle, &I_blastoise, &I_caterpie, &I_metapod, &I_butterfree,
  32. &I_weedle, &I_kakuna, &I_beedrill, &I_pidgey, &I_pidgeotto, &I_pidgeot,
  33. &I_rattata, &I_raticate, &I_spearow, &I_fearow, &I_ekans, &I_arbok,
  34. &I_pikachu, &I_raichu, &I_sandshrew, &I_sandslash, &I_nidoranf, &I_nidorina,
  35. &I_nidoqueen, &I_nidoranm, &I_nidorino, &I_nidoking, &I_clefairy, &I_clefable,
  36. &I_vulpix, &I_ninetales, &I_jigglypuff, &I_wigglytuff, &I_zubat, &I_golbat,
  37. &I_oddish, &I_gloom, &I_vileplume, &I_paras, &I_parasect, &I_venonat,
  38. &I_venomoth, &I_diglett, &I_dugtrio, &I_meowth, &I_persian, &I_psyduck,
  39. &I_golduck, &I_mankey, &I_primeape, &I_growlithe, &I_arcanine, &I_poliwag,
  40. &I_poliwhirl, &I_poliwrath, &I_abra, &I_kadabra, &I_alakazam, &I_machop,
  41. &I_machoke, &I_machamp, &I_bellsprout, &I_weepinbell, &I_victreebel, &I_tentacool,
  42. &I_tentacruel, &I_geodude, &I_graveler, &I_golem, &I_ponyta, &I_rapidash,
  43. &I_slowpoke, &I_slowbro, &I_magnemite, &I_magneton, &I_farfetchd, &I_doduo,
  44. &I_dodrio, &I_seel, &I_dewgong, &I_grimer, &I_muk, &I_shellder,
  45. &I_cloyster, &I_gastly, &I_haunter, &I_gengar, &I_onix, &I_drowzee,
  46. &I_hypno, &I_krabby, &I_kingler, &I_voltorb, &I_electrode, &I_exeggcute,
  47. &I_exeggutor, &I_cubone, &I_marowak, &I_hitmonlee, &I_hitmonchan, &I_lickitung,
  48. &I_koffing, &I_weezing, &I_rhyhorn, &I_rhydon, &I_chansey, &I_tangela,
  49. &I_kangaskhan, &I_horsea, &I_seadra, &I_goldeen, &I_seaking, &I_staryu,
  50. &I_starmie, &I_mr_mime, &I_scyther, &I_jynx, &I_electabuzz, &I_magmar,
  51. &I_pinsir, &I_tauros, &I_magikarp, &I_gyarados, &I_lapras, &I_ditto,
  52. &I_eevee, &I_vaporeon, &I_jolteon, &I_flareon, &I_porygon, &I_omanyte,
  53. &I_omastar, &I_kabuto, &I_kabutops, &I_aerodactyl, &I_snorlax, &I_articuno,
  54. &I_zapdos, &I_moltres, &I_dratini, &I_dragonair, &I_dragonite, &I_mewtwo,
  55. &I_mew};
  56. const unsigned char pokemon_hex_codes[] = {
  57. 0x99, 0x09, 0x9A, 0xB0, 0xB2, 0xB4, 0xB1, 0xB3, 0x1C, 0x7B, 0x7C, 0x7D, 0x70, 0x71, 0x72, 0x24,
  58. 0x96, 0x97, 0xA5, 0xA6, 0x05, 0x23, 0x6C, 0x2D, 0x54, 0x55, 0x60, 0x61, 0x0F, 0xA8, 0x10, 0x03,
  59. 0xA7, 0x07, 0x04, 0x8E, 0x52, 0x53, 0x64, 0x65, 0x6B, 0x82, 0xB9, 0xBA, 0xBB, 0x6D, 0x2E, 0x41,
  60. 0x77, 0x3B, 0x76, 0x4D, 0x90, 0x2F, 0x80, 0x39, 0x75, 0x21, 0x14, 0x47, 0x6E, 0x6F, 0x94, 0x26,
  61. 0x95, 0x6A, 0x29, 0x7E, 0xBC, 0xBD, 0xBE, 0x18, 0x9B, 0xA9, 0x27, 0x31, 0xA3, 0xA4, 0x25, 0x08,
  62. 0xAD, 0x36, 0x40, 0x46, 0x74, 0x3A, 0x78, 0x0D, 0x88, 0x17, 0x8B, 0x19, 0x93, 0x0E, 0x22, 0x30,
  63. 0x81, 0x4E, 0x8A, 0x06, 0x8D, 0x0C, 0x0A, 0x11, 0x91, 0x2B, 0x2C, 0x0B, 0x37, 0x8F, 0x12, 0x01,
  64. 0x28, 0x1E, 0x02, 0x5C, 0x5D, 0x9D, 0x9E, 0x1B, 0x98, 0x2A, 0x1A, 0x48, 0x35, 0x33, 0x1D, 0x3C,
  65. 0x85, 0x16, 0x13, 0x4C, 0x66, 0x69, 0x68, 0x67, 0xAA, 0x62, 0x63, 0x5A, 0x5B, 0xAB, 0x84, 0x4A,
  66. 0x4B, 0x49, 0x58, 0x59, 0x42, 0x83, 0x15};
  67. uint32_t pokemon_exit_confirm_view(void* context) {
  68. UNUSED(context);
  69. return AppViewExitConfirm;
  70. }
  71. App* pokemon_alloc() {
  72. App* app = (App*)malloc(sizeof(App));
  73. // Gui
  74. app->gui = (Gui*)furi_record_open(RECORD_GUI);
  75. // View dispatcher
  76. app->view_dispatcher = view_dispatcher_alloc();
  77. view_dispatcher_enable_queue(app->view_dispatcher);
  78. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  79. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  80. // Start Index first pokemon
  81. app->current_pokemon = 0;
  82. // Select Pokemon View
  83. app->select_pokemon = select_pokemon_alloc(app);
  84. view_set_previous_callback(select_pokemon_get_view(app), pokemon_exit_confirm_view);
  85. view_dispatcher_add_view(
  86. app->view_dispatcher, AppViewSelectPokemon, select_pokemon_get_view(app));
  87. // Trade View
  88. app->trade = trade_alloc(app);
  89. view_set_previous_callback(trade_get_view(app), pokemon_exit_confirm_view);
  90. view_dispatcher_add_view(app->view_dispatcher, AppViewTrade, trade_get_view(app));
  91. view_dispatcher_switch_to_view(app->view_dispatcher, AppViewSelectPokemon);
  92. return app;
  93. }
  94. void free_app(App* app) {
  95. furi_assert(app);
  96. // Free views
  97. view_dispatcher_remove_view(app->view_dispatcher, AppViewSelectPokemon);
  98. select_pokemon_free(app);
  99. view_dispatcher_remove_view(app->view_dispatcher, AppViewTrade);
  100. trade_free(app);
  101. // Close records
  102. furi_record_close(RECORD_GUI);
  103. app->gui = NULL;
  104. // Free rest
  105. free(app);
  106. }
  107. extern "C" int32_t pokemon_app(void* p) {
  108. UNUSED(p);
  109. //FURI_LOG_D(TAG, "init scene");
  110. App* app = (App*)pokemon_alloc();
  111. furi_hal_light_set(LightRed, 0x00);
  112. furi_hal_light_set(LightGreen, 0x00);
  113. furi_hal_light_set(LightBlue, 0x00);
  114. view_dispatcher_enable_queue(app->view_dispatcher);
  115. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  116. //switch view and run dispatcher
  117. view_dispatcher_switch_to_view(app->view_dispatcher, AppViewSelectPokemon);
  118. view_dispatcher_run(app->view_dispatcher);
  119. // Free resources
  120. free_app(app);
  121. furi_record_close(RECORD_GUI);
  122. return 0;
  123. }