説明なし

pokedex.c 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. #include <agb_debug.h>
  2. #include <constants/pkmns.h>
  3. #include <pokeagb/pokeagb.h>
  4. #include <pokedex/pdexArrow.h>
  5. #include <pokedex/pdexBall.h>
  6. #include <pokedex/pdexBg.h>
  7. #include <pokedex/pdexScrollBar.h>
  8. #include <pokedex/pdexSelectHalf.h>
  9. //testing ci, no hate plz
  10. #include "pokedex_common.h"
  11. #define TB_TITLE 0
  12. #define TB_PKMN 1
  13. #define TB_SEEN 2
  14. #define TB_CAUGHT 3
  15. #define TB_MAIN 4
  16. #define TB_SEEN_Y (6)
  17. #define TB_CAUGHT_Y 3
  18. #define DEX_SCROLL_MIN 23
  19. #define DEX_SCROLL_MAX 146
  20. #define SCROLL_SPEED_MAX 6
  21. void pdex_load(void);
  22. void pdex_vblank_handler(void);
  23. void pdex_loop(u8 tid);
  24. void pdex_cb_handler(void);
  25. extern const pchar pdex_str_title[];
  26. extern const pchar pdex_str_seen[];
  27. extern const pchar pdex_str_caught[];
  28. extern const pchar pdex_str_empty[];
  29. static const u8 pdex_y_offset[] = {19, 35, 51, 67, 83, 99, 115, 131};
  30. static const u16 scroll_speed_delays[] = {20, 20, 20, 20, 10, 5, 0};
  31. struct TextboxTemplate pdex_boxes[] = {
  32. {.bg_id = 0, .x = 11, .y = 0, .width = 10, .height = 2, .pal_id = 15, .charbase = 1},
  33. {.bg_id = 0, .x = 2, .y = 2, .width = 10, .height = 2, .pal_id = 15, .charbase = 21},
  34. {.bg_id = 0, .x = 3, .y = 13, .width = 9, .height = 3, .pal_id = 15, .charbase = 41},
  35. {.bg_id = 0, .x = 3, .y = 16, .width = 9, .height = 2, .pal_id = 15, .charbase = 59},
  36. {.bg_id = 1, .x = 16, .y = 0, .width = 11, .height = 32, .pal_id = 15, .charbase = 77},
  37. {.bg_id = 0xFF},
  38. };
  39. s16 pdex_get_y_offset(s8 n) {
  40. s8 modOffset = n + pokedex_context->hardware_scroll_amount;
  41. if (modOffset < -1) {
  42. modOffset += 16;
  43. }
  44. if (modOffset > 14) {
  45. modOffset -= 16;
  46. }
  47. return (19 + (16 * modOffset));
  48. }
  49. void pdex_main_box_species_fill(s8 n, u16 species, bool seen, bool caught) {
  50. seen = true;
  51. s16 y = pdex_get_y_offset(n);
  52. rboxid_fill_rectangle(TB_MAIN, 0, 0, y, 11 * 8, 16);
  53. const pchar *stringToPrint = (seen || caught) ? &pokemon_names[species][0] : &pdex_str_empty[0];
  54. const pchar stringWhitespace[] = {0x0, 0xFF};
  55. fmt_int_10(string_buffer, pokedex_context->cursor_position_top + n, 2, 3);
  56. pstrcat(string_buffer, &stringWhitespace[0]);
  57. pstrcat(string_buffer, stringToPrint);
  58. rboxid_print(TB_MAIN, FONT_DEX_STD, 4, y, &pdex_text_color, 0, string_buffer);
  59. }
  60. void pdex_update_balls(void) {
  61. for (u8 i = 0; i < 8; ++i) {
  62. if (pdex_lazy_lookup_entry(i + pokedex_context->cursor_position_top)->caught)
  63. OBJID_SHOW(pokedex_context->ball_oams[i]);
  64. else
  65. OBJID_HIDE(pokedex_context->ball_oams[i]);
  66. }
  67. }
  68. void pdex_update_page_full() {
  69. rboxid_clear_pixels(TB_MAIN, 0);
  70. for (u16 i = pokedex_context->cursor_position_top; i < pokedex_context->cursor_position_top + 8; ++i) {
  71. pdex_main_box_species_fill(i - pokedex_context->cursor_position_top, pdex_lazy_lookup_entry(i)->species,
  72. pdex_lazy_lookup_entry(i)->seen, pdex_lazy_lookup_entry(i)->caught);
  73. }
  74. pdex_update_balls();
  75. rboxid_update_tilemap_and_tileset(TB_MAIN);
  76. }
  77. void pdex_load_sc(void) {
  78. rboxid_clear_pixels(TB_SEEN, 0);
  79. rboxid_clear_pixels(TB_CAUGHT, 0);
  80. u32 seen = pokedex_count(false) + 10;
  81. u32 caught = pokedex_count(true);
  82. pchar seenBuffer[4];
  83. pchar caughtBuffer[4];
  84. fmt_int_10(seenBuffer, seen, 0, MAX3_COUNT_DIGITS(seen));
  85. fmt_int_10(caughtBuffer, caught, 0, MAX3_COUNT_DIGITS(caught));
  86. u32 twidthSeen = font_get_width_of_string(FONT_DEX_STD, seenBuffer, 0x0000);
  87. u32 twidthCaught = font_get_width_of_string(FONT_DEX_STD, caughtBuffer, 0x0000);
  88. rboxid_print(TB_SEEN, FONT_DEX_STD, 0, TB_SEEN_Y, &pdex_text_color, 0, &pdex_str_seen[0]);
  89. rboxid_print(TB_CAUGHT, FONT_DEX_STD, 0, TB_CAUGHT_Y, &pdex_text_color, 0, &pdex_str_caught[0]);
  90. rboxid_print(TB_SEEN, FONT_DEX_STD, TB_STD_RIGHT(twidthSeen, TB_BOT_LEN_PX), TB_SEEN_Y + 1, &pdex_text_color, 0,
  91. seenBuffer);
  92. rboxid_print(TB_CAUGHT, FONT_DEX_STD, TB_STD_RIGHT(twidthCaught, TB_BOT_LEN_PX), TB_CAUGHT_Y + 1, &pdex_text_color,
  93. 0, caughtBuffer);
  94. rboxid_update_tilemap_and_tileset(TB_SEEN);
  95. rboxid_update_tilemap_and_tileset(TB_CAUGHT);
  96. }
  97. void pdex_pokemon_oam_update(u16 species, s8 objid) {
  98. gpu_pal_apply_compressed(pokemon_palette_normal[species].data, 16 * (objects[objid].final_oam.palette_num + 16),
  99. 32);
  100. lz77UnCompVram(pokemon_graphics_front[species].data,
  101. ((void *)(objects[objid].final_oam.tile_num * 32) + ADDR_VRAM + 0x10000));
  102. }
  103. s8 pdex_pokemon_oam_load(u16 species, u16 tag) {
  104. struct SpriteTiles pkmnTiles = {pokemon_graphics_front[species].data, 2048, tag};
  105. struct SpritePalette pkmnPal = {pokemon_palette_normal[species].data, tag};
  106. const struct Template pkmnTemplate = {
  107. .tiles_tag = tag,
  108. .pal_tag = tag,
  109. .oam = &pdex_oam_pkmn,
  110. .animation = &anim_image_empty,
  111. .graphics = &pkmnTiles,
  112. .rotscale = &rotscale_empty,
  113. .callback = oac_nullsub,
  114. };
  115. gpu_tile_obj_decompress_alloc_tag_and_upload(&pkmnTiles);
  116. gpu_pal_decompress_alloc_tag_and_upload(&pkmnPal);
  117. s8 objid = (s8)template_instanciate_forward_search(&pkmnTemplate, 10, 10, 0);
  118. objects[objid].pos1.x = 55;
  119. objects[objid].pos1.y = 76;
  120. OBJID_HIDE(objid);
  121. return objid;
  122. }
  123. void pdex_pokemon_load(u16 species) {
  124. /* this is very temporary */
  125. rboxid_clear_pixels(TB_PKMN, 0);
  126. u32 twidth = font_get_width_of_string(FONT_DEX_STD, &pokemon_names[species][0], 0x0000);
  127. rboxid_print(TB_PKMN, FONT_DEX_STD, TB_STD_CENTER(twidth, TB_STD_LEN_PX), 3, &pdex_text_color, 0,
  128. &pokemon_names[species][0]);
  129. // pokedex_context->pokemon_oam = pdex_pokemon_oam_load(species, pokedex_context->pokemon_oam);
  130. rboxid_update_tilemap_and_tileset(TB_PKMN);
  131. }
  132. struct SpriteTiles pdex_ball_tiles = {pdexBallTiles, 128, DEX_BALL_TAG};
  133. struct SpritePalette pdex_ball_pal = {pdexBallPal, DEX_BALL_TAG};
  134. const struct OamData pdex_ball_oam = {
  135. .affine_mode = 0,
  136. .obj_mode = 0,
  137. .mosaic = false,
  138. .shape = 0,
  139. .size = 1,
  140. };
  141. const struct Template pdex_ball_template = {
  142. .tiles_tag = DEX_BALL_TAG,
  143. .pal_tag = DEX_BALL_TAG,
  144. .oam = &pdex_ball_oam,
  145. .animation = &anim_image_empty,
  146. .graphics = &pdex_ball_tiles,
  147. .rotscale = &rotscale_empty,
  148. .callback = oac_nullsub,
  149. };
  150. void pdex_pokeballs_init(void) {
  151. gpu_tile_obj_decompress_alloc_tag_and_upload(&pdex_ball_tiles);
  152. gpu_pal_obj_alloc_tag_and_apply(&pdex_ball_pal);
  153. for (u8 i = 0; i < 8; ++i) {
  154. pokedex_context->ball_oams[i] =
  155. template_instanciate_forward_search(&pdex_ball_template, 124, 8 + pdex_y_offset[i], 1);
  156. }
  157. }
  158. void pdex_oac_cursor_follow(struct Object *obj) { obj->pos1.y = objects[pokedex_context->cursor_main_oam].pos1.y; }
  159. void pdex_oac_cursor_main(struct Object *obj) {
  160. obj->pos1.y = 13 + pdex_y_offset[pokedex_context->cursor_position_internal];
  161. }
  162. struct SpriteTiles pdex_cursor_tiles = {pdexSelectHalfTiles, 1024, DEX_CURSOR_TAG};
  163. struct SpritePalette pdex_cursor_pal = {pdexSelectHalfPal, DEX_CURSOR_TAG};
  164. const struct OamData pdex_cursor_oam = {
  165. .affine_mode = 0,
  166. .obj_mode = 0,
  167. .mosaic = false,
  168. .shape = 1,
  169. .size = 3,
  170. };
  171. const struct Template pdex_ball_main_template = {
  172. .tiles_tag = DEX_CURSOR_TAG,
  173. .pal_tag = DEX_CURSOR_TAG,
  174. .oam = &pdex_cursor_oam,
  175. .animation = &anim_image_empty,
  176. .graphics = &pdex_cursor_tiles,
  177. .rotscale = &rotscale_empty,
  178. .callback = pdex_oac_cursor_main,
  179. };
  180. const struct Template pdex_ball_follow_template = {
  181. .tiles_tag = DEX_CURSOR_TAG,
  182. .pal_tag = DEX_CURSOR_TAG,
  183. .oam = &pdex_cursor_oam,
  184. .animation = &anim_image_empty,
  185. .graphics = &pdex_cursor_tiles,
  186. .rotscale = &rotscale_empty,
  187. .callback = pdex_oac_cursor_follow,
  188. };
  189. void pdex_cursor_init(void) {
  190. gpu_tile_obj_decompress_alloc_tag_and_upload(&pdex_cursor_tiles);
  191. gpu_pal_obj_alloc_tag_and_apply(&pdex_cursor_pal);
  192. pokedex_context->cursor_main_oam = template_instanciate_forward_search(&pdex_ball_main_template, 144, 32, 0);
  193. pokedex_context->cursor_follow_oam =
  194. template_instanciate_forward_search(&pdex_ball_follow_template, 144 + 48, 32, 0);
  195. objects[pokedex_context->cursor_follow_oam].final_oam.h_flip = true;
  196. }
  197. void pdex_oac_scroll_bar(struct Object *obj) {
  198. obj->pos1.y = 23 + (((pokedex_context->cursor_position_top + pokedex_context->cursor_position_internal) * 123) /
  199. PDEX_LAST_SHOWN);
  200. }
  201. void pdex_oac_arrow(struct Object *obj) {
  202. if (obj->priv[0]) {
  203. // this is the down facing arrow
  204. if (pokedex_context->cursor_position_top + 8 > PDEX_LAST_SHOWN) {
  205. obj->final_oam.palette_num = obj->priv[2];
  206. } else {
  207. obj->final_oam.palette_num = obj->priv[1];
  208. }
  209. } else {
  210. // this is the up facing arrow
  211. if (pokedex_context->cursor_position_top == pokedex_context->first_seen) {
  212. obj->final_oam.palette_num = obj->priv[2];
  213. } else {
  214. obj->final_oam.palette_num = obj->priv[1];
  215. }
  216. }
  217. }
  218. struct SpriteTiles pdex_scroll_bar_tiles = {pdexScrollBarTiles, 32, DEX_SCROLL_TAG};
  219. struct SpritePalette pdex_scroll_bar_pal = {pdexScrollBarPal, DEX_SCROLL_TAG};
  220. struct SpriteTiles pdex_arrow_tiles = {pdexArrowTiles, 128, DEX_ARROW_TAG};
  221. struct SpritePalette pdex_arrow_pal = {pdexArrowPal, DEX_ARROW_TAG};
  222. struct SpritePalette pdex_arrow_pal_gray = {pdexArrowPal, DEX_ARROW_TAG_EPAL};
  223. const struct OamData pdex_scroll_bar_oam = {
  224. .affine_mode = 0,
  225. .obj_mode = 0,
  226. .mosaic = false,
  227. .shape = 0,
  228. .size = 0,
  229. };
  230. const struct OamData pdex_arrow_oam = {
  231. .affine_mode = 0,
  232. .obj_mode = 0,
  233. .mosaic = false,
  234. .shape = 0,
  235. .size = 1,
  236. };
  237. const struct Template pdex_scroll_bar_template = {
  238. .tiles_tag = DEX_SCROLL_TAG,
  239. .pal_tag = DEX_SCROLL_TAG,
  240. .oam = &pdex_scroll_bar_oam,
  241. .animation = &anim_image_empty,
  242. .graphics = &pdex_scroll_bar_tiles,
  243. .rotscale = &rotscale_empty,
  244. .callback = pdex_oac_scroll_bar,
  245. };
  246. const struct Template pdex_arrow_template = {
  247. .tiles_tag = DEX_ARROW_TAG,
  248. .pal_tag = DEX_ARROW_TAG,
  249. .oam = &pdex_arrow_oam,
  250. .animation = &anim_image_empty,
  251. .graphics = &pdex_arrow_tiles,
  252. .rotscale = &rotscale_empty,
  253. .callback = pdex_oac_arrow,
  254. };
  255. void pdex_load_scroll_ui(void) {
  256. gpu_tile_obj_decompress_alloc_tag_and_upload(&pdex_scroll_bar_tiles);
  257. gpu_tile_obj_decompress_alloc_tag_and_upload(&pdex_arrow_tiles);
  258. gpu_pal_obj_alloc_tag_and_apply(&pdex_scroll_bar_pal);
  259. u8 normalPal = gpu_pal_obj_alloc_tag_and_apply(&pdex_arrow_pal);
  260. u8 grayPal = gpu_pal_obj_alloc_tag_and_apply(&pdex_arrow_pal_gray);
  261. tint_palette_gray(&palette_bg_unfaded[16 * (16 + grayPal)], 16);
  262. (void)template_instanciate_forward_search(&pdex_scroll_bar_template, 233, 23, 0);
  263. u8 upArrow = template_instanciate_forward_search(&pdex_arrow_template, 232, 19, 0);
  264. u8 downArrow = template_instanciate_forward_search(&pdex_arrow_template, 232, 150, 0);
  265. objects[downArrow].priv[0] = true;
  266. objects[downArrow].final_oam.v_flip = true;
  267. objects[upArrow].priv[1] = normalPal;
  268. objects[downArrow].priv[1] = normalPal;
  269. objects[upArrow].priv[2] = grayPal;
  270. objects[downArrow].priv[2] = grayPal;
  271. }
  272. void pdex_data_setup(void) { pokedex_context->first_seen = 1; }
  273. void pdex_hardware_scroll(bool up) {
  274. if (up) {
  275. if (pokedex_context->hardware_scroll_amount > -15) {
  276. bgid_mod_y_offset(1, -(16 << 8), 1);
  277. pokedex_context->hardware_scroll_amount--;
  278. } else {
  279. pokedex_context->hardware_scroll_amount = 0;
  280. bgid_mod_y_offset(1, 0, 0);
  281. }
  282. } else {
  283. if (pokedex_context->hardware_scroll_amount < 15) {
  284. bgid_mod_y_offset(1, 16 << 8, 1);
  285. pokedex_context->hardware_scroll_amount++;
  286. } else {
  287. pokedex_context->hardware_scroll_amount = 0;
  288. bgid_mod_y_offset(1, 0, 0);
  289. }
  290. }
  291. }
  292. void pdex_fill_previous_slot(void) {
  293. u16 pIndex = pokedex_context->cursor_position_top - 1;
  294. pdex_main_box_species_fill(-1, pdex_lazy_lookup_entry(pIndex)->species, pdex_lazy_lookup_entry(pIndex)->seen,
  295. pdex_lazy_lookup_entry(pIndex)->caught);
  296. }
  297. void pdex_fill_next_slot(void) {
  298. u16 pIndex = pokedex_context->cursor_position_top + 8;
  299. pdex_main_box_species_fill(8, pdex_lazy_lookup_entry(pIndex)->species, pdex_lazy_lookup_entry(pIndex)->seen,
  300. pdex_lazy_lookup_entry(pIndex)->caught);
  301. }
  302. void pdex_try_advance(u8 reverse) {
  303. if (reverse) {
  304. if (pokedex_context->cursor_position_internal > 0) {
  305. pokedex_context->cursor_position_internal--;
  306. m4aSongNumStart(600);
  307. } else if ((pokedex_context->cursor_position_top) > (pokedex_context->first_seen)) {
  308. pdex_fill_previous_slot();
  309. pokedex_context->cursor_position_top--;
  310. pdex_hardware_scroll(true);
  311. m4aSongNumStart(600);
  312. } else {
  313. return;
  314. }
  315. } else {
  316. if (pokedex_context->cursor_position_internal < 7) {
  317. pokedex_context->cursor_position_internal++;
  318. m4aSongNumStart(600);
  319. } else if (pokedex_context->cursor_position_top < (PDEX_LAST_SHOWN - 7)) {
  320. pdex_fill_next_slot();
  321. pokedex_context->cursor_position_top++;
  322. pdex_hardware_scroll(false);
  323. m4aSongNumStart(600);
  324. } else {
  325. return;
  326. }
  327. }
  328. u16 pkIndexToLoad = pokedex_context->cursor_position_internal + pokedex_context->cursor_position_top;
  329. u16 speciesToLoad = (pdex_lazy_lookup_entry(pkIndexToLoad)->seen || pdex_lazy_lookup_entry(pkIndexToLoad)->caught)
  330. ? pdex_lazy_lookup_entry(pkIndexToLoad)->species
  331. : pdex_lazy_lookup_entry(pkIndexToLoad)->species; /* debug, just display the mofo */
  332. pdex_pokemon_load(speciesToLoad);
  333. if (reverse) {
  334. s8 oam = pokedex_context->pokemon_oam; // current oam id
  335. OBJID_HIDE(oam);
  336. pokedex_context->pokemon_oam = pokedex_context->prev_pokemon_oam;
  337. OBJID_SHOW(pokedex_context->pokemon_oam);
  338. pokedex_context->prev_pokemon_oam = pokedex_context->next_pokemon_oam;
  339. pokedex_context->next_pokemon_oam = oam;
  340. pdex_pokemon_oam_update(pdex_lazy_lookup_entry(pkIndexToLoad - 1)->species, pokedex_context->prev_pokemon_oam);
  341. } else {
  342. s8 oam = pokedex_context->pokemon_oam;
  343. OBJID_HIDE(oam);
  344. pokedex_context->pokemon_oam = pokedex_context->next_pokemon_oam;
  345. OBJID_SHOW(pokedex_context->pokemon_oam);
  346. pokedex_context->next_pokemon_oam = pokedex_context->prev_pokemon_oam;
  347. pokedex_context->prev_pokemon_oam = oam;
  348. pdex_pokemon_oam_update(pdex_lazy_lookup_entry(pkIndexToLoad + 1)->species, pokedex_context->next_pokemon_oam);
  349. }
  350. pdex_update_balls();
  351. }
  352. void pdex_loop(u8 tid) {
  353. switch (pokedex_context->state) {
  354. case 0:
  355. pokedex_context->state++;
  356. break;
  357. case 1:
  358. for (u8 i = 0; i < 4; ++i)
  359. bgid_send_tilemap(i);
  360. rboxid_clear_pixels(TB_TITLE, 0);
  361. rboxid_print(TB_TITLE, FONT_DEX_STD, 0, 0, &pdex_text_color, 0, &pdex_str_title[0]);
  362. rboxid_update_tilemap_and_tileset(TB_TITLE);
  363. pdex_data_setup();
  364. pdex_cursor_init();
  365. pdex_pokeballs_init();
  366. pdex_load_scroll_ui();
  367. u16 currentIndex = pokedex_context->cursor_position_top + pokedex_context->cursor_position_internal;
  368. pdex_pokemon_load(pdex_lazy_lookup_entry(currentIndex)->species);
  369. pokedex_context->pokemon_oam =
  370. pdex_pokemon_oam_load(pdex_lazy_lookup_entry(currentIndex)->species, DEX_PKMN_TAG_ONE);
  371. OBJID_SHOW(pokedex_context->pokemon_oam);
  372. pokedex_context->next_pokemon_oam =
  373. pdex_pokemon_oam_load(pdex_lazy_lookup_entry(currentIndex + 1)->species, DEX_PKMN_TAG_TWO);
  374. if (currentIndex != pokedex_context->first_seen) {
  375. pokedex_context->prev_pokemon_oam =
  376. pdex_pokemon_oam_load(pdex_lazy_lookup_entry(currentIndex - 1)->species, DEX_PKMN_TAG_THREE);
  377. } else {
  378. pokedex_context->prev_pokemon_oam = pdex_pokemon_oam_load(0, DEX_PKMN_TAG_THREE);
  379. }
  380. pdex_load_sc();
  381. pdex_update_page_full();
  382. palette_bg_faded_fill_black();
  383. pokedex_context->state++;
  384. break;
  385. case 2:
  386. gpu_sync_bg_show(0);
  387. gpu_sync_bg_show(1);
  388. gpu_sync_bg_hide(3);
  389. gpu_sync_bg_show(2);
  390. fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 16, 0, 0x0000);
  391. pokedex_context->state++;
  392. break;
  393. case 3:
  394. if (!pal_fade_control.active)
  395. pokedex_context->state++;
  396. break;
  397. case 4:
  398. /* main control */
  399. if (super.buttons_new & KEY_A) {
  400. pokedex_context->state = 15;
  401. m4aSongNumStart(5);
  402. }
  403. if (super.buttons_new & KEY_B) {
  404. pokedex_context->state = 10;
  405. m4aSongNumStart(601);
  406. }
  407. if ((super.buttons_new & KEY_DOWN)) {
  408. pdex_try_advance(false);
  409. pokedex_context->scroll_speed = 0;
  410. pokedex_context->delay_count = 0;
  411. } else if (super.buttons_held & KEY_DOWN) {
  412. if (pokedex_context->scroll_speed < SCROLL_SPEED_MAX) {
  413. if (pokedex_context->delay_count >= scroll_speed_delays[pokedex_context->scroll_speed]) {
  414. pdex_try_advance(false);
  415. pokedex_context->delay_count = 0;
  416. pokedex_context->scroll_speed++;
  417. } else {
  418. pokedex_context->delay_count++;
  419. }
  420. } else {
  421. pdex_try_advance(false);
  422. }
  423. }
  424. if ((super.buttons_new & KEY_UP)) {
  425. pdex_try_advance(true);
  426. pokedex_context->scroll_speed = 0;
  427. pokedex_context->delay_count = 0;
  428. } else if (super.buttons_held & KEY_UP) {
  429. if (pokedex_context->scroll_speed < SCROLL_SPEED_MAX) {
  430. if (pokedex_context->delay_count >= scroll_speed_delays[pokedex_context->scroll_speed]) {
  431. pdex_try_advance(true);
  432. pokedex_context->delay_count = 0;
  433. pokedex_context->scroll_speed++;
  434. } else {
  435. pokedex_context->delay_count++;
  436. }
  437. } else {
  438. pdex_try_advance(true);
  439. }
  440. }
  441. break;
  442. case 10:
  443. /* control flow exit */
  444. fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 0, 16, 0x000);
  445. pokedex_context->state++;
  446. break;
  447. case 11:
  448. if (!pal_fade_control.active) {
  449. task_del(tid);
  450. pdex_vram_free_bgmaps();
  451. pdex_free_memory();
  452. void region_select_load(void);
  453. set_callback2(region_select_load);
  454. }
  455. break;
  456. case 15:
  457. /* load the detail screen */
  458. fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 0, 16, 0x0000);
  459. pokedex_context->state++;
  460. break;
  461. case 16:
  462. if (!pal_fade_control.active) {
  463. pdex_vram_free_bgmaps();
  464. task_del(tid);
  465. void dexdetail_load(void);
  466. set_callback2(dexdetail_load);
  467. }
  468. default:
  469. break;
  470. }
  471. }
  472. void pdex_load_gfx(void) {
  473. /*TODO: setup text boxes here */
  474. rbox_init_from_templates(&pdex_boxes[0]);
  475. lz77UnCompVram(pdexBgTiles, (void *)0x0600C000);
  476. LZ77UnCompWram(pdexBgMap, bgid_get_tilemap(2));
  477. gpu_pal_apply_compressed(pdexBgPal, 0, 32);
  478. gpu_pal_apply(pdex_text_pal, 15 * 16, 32);
  479. /*setup window*/
  480. lcd_io_set(REG_ID_WIN0H, (128 << 8) | (216));
  481. lcd_io_set(REG_ID_WIN0V, ((20 << 8) | (148)));
  482. lcd_io_set(REG_ID_WININ, WIN_BG0 | WIN_BG1 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
  483. lcd_io_set(REG_ID_WINOUT, WIN_BG0 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
  484. bgid_mark_for_sync(0);
  485. }
  486. void pdex_load(void) {
  487. pdex_vram_setup();
  488. pdex_load_gfx();
  489. pokedex_context->pokemon_oam = -1;
  490. pokedex_context->state = 0;
  491. pokedex_context->hardware_scroll_amount = 0;
  492. task_add(pdex_loop, 0);
  493. set_callback2(pdex_cb_handler);
  494. }