Нет описания

pokedex_detail.c 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #include <agb_debug.h>
  2. #include <pokeagb/pokeagb.h>
  3. #include <pokedex/pdexDetailBg.h>
  4. #include "pokedex_common.h"
  5. #define TB_PKNAME 0
  6. #define TB_PKSIZE 1
  7. #define TB_DESC 2
  8. #define TB_PKNAME_W 30
  9. #define TB_SW_W 12
  10. extern pchar pdex_entry_debug[];
  11. extern pchar pdex_str_size[];
  12. extern pchar pdex_str_weight[];
  13. extern pchar pdex_str_size_unit[];
  14. extern pchar pdex_str_weight_unit[];
  15. extern pchar pdex_str_comma[];
  16. struct TextboxTemplate dexdetail_boxes[] = {
  17. {.bg_id = 0, .x = 0, .y = 0, .width = TB_PKNAME_W, .height = 4, .pal_id = 15, .charbase = 1},
  18. {.bg_id = 0, .x = 17, .y = 5, .width = TB_SW_W, .height = 4, .pal_id = 15, .charbase = 121},
  19. {.bg_id = 1, .x = 1, .y = 0, .width = 28, .height = 20, .pal_id = 15, .charbase = 161},
  20. {.bg_id = 0xFF},
  21. };
  22. void dexdetail_load_pokemon(u16 dexindex) {
  23. u16 species = pokedex_context->lookup[dexindex].species;
  24. rboxid_clear_pixels(TB_PKNAME, 0);
  25. rboxid_clear_pixels(TB_PKSIZE, 0);
  26. rboxid_clear_pixels(TB_DESC, 0);
  27. u16 twidth = font_get_width_of_string(FONT_DEX_STD, &pokemon_names[species][0], 0x0000);
  28. rboxid_print(TB_PKNAME, FONT_DEX_STD, TB_STD_CENTER(twidth, 8 * TB_PKNAME_W), 0, &pdex_text_color, 0,
  29. &pokemon_names[species][0]);
  30. pchar *strType = &pokedex_data[dexindex].category_name[0];
  31. u16 typeTwidth = font_get_width_of_string(FONT_DEX_STD, strType, 0x0000);
  32. rboxid_print(TB_PKNAME, FONT_DEX_STD, TB_STD_CENTER(typeTwidth, 88) + 110, 14, &pdex_text_color, 0, strType);
  33. rboxid_print(TB_PKSIZE, FONT_DEX_STD, 4, 1, &pdex_text_color, 0, pdex_str_size);
  34. rboxid_print(TB_PKSIZE, FONT_DEX_STD, 4, 14, &pdex_text_color, 0, pdex_str_weight);
  35. u16 weightNumber = pokedex_data[dexindex].weight / 10;
  36. u16 weightDecimal = pokedex_data[dexindex].weight % 10;
  37. pchar buffer[20];
  38. fmt_int_10(string_buffer, weightNumber, 0, 3);
  39. fmt_int_10(&buffer[0], weightDecimal, 0, 1);
  40. pstrcat(string_buffer, pdex_str_comma);
  41. pstrcat(string_buffer, buffer);
  42. pstrcat(string_buffer, pdex_str_weight_unit);
  43. u16 weightTwidth = font_get_width_of_string(FONT_DEX_STD, string_buffer, 0x0000);
  44. rboxid_print(TB_PKSIZE, FONT_DEX_STD, TB_STD_RIGHT(weightTwidth, TB_SW_W * 8) - 6, 1, &pdex_text_color, 0,
  45. string_buffer);
  46. u16 sizeNumber = pokedex_data[dexindex].height / 10;
  47. u16 sizeDecimal = pokedex_data[dexindex].height % 10;
  48. fmt_int_10(string_buffer, sizeNumber, 0, 3);
  49. fmt_int_10(&buffer[0], sizeDecimal, 0, 1);
  50. pstrcat(string_buffer, pdex_str_comma);
  51. pstrcat(string_buffer, buffer);
  52. pstrcat(string_buffer, pdex_str_size_unit);
  53. rboxid_print(TB_PKSIZE, FONT_DEX_STD, TB_STD_RIGHT(weightTwidth, TB_SW_W * 8) - 6, 14, &pdex_text_color, 0,
  54. string_buffer);
  55. rboxid_print(TB_DESC, FONT_DEX_STD, 3, 2, &pdex_text_color, 0, pokedex_data[dexindex].description1);
  56. /* load the species sprite */
  57. if (pokedex_context->detail_pokemon_oam != -1) {
  58. } else {
  59. struct SpriteTiles pkmnTiles = {pokemon_graphics_front[species].data, 2048, DEX_PKMN_TAG};
  60. struct SpritePalette pkmnPal = {pokemon_palette_normal[species].data, DEX_PKMN_TAG};
  61. const struct Template pkmnTemplate = {
  62. .tiles_tag = DEX_PKMN_TAG,
  63. .pal_tag = DEX_PKMN_TAG,
  64. .oam = &pdex_oam_pkmn,
  65. .animation = &anim_image_empty,
  66. .graphics = &pkmnTiles,
  67. .rotscale = &rotscale_empty,
  68. .callback = oac_nullsub,
  69. };
  70. gpu_tile_obj_decompress_alloc_tag_and_upload(&pkmnTiles);
  71. gpu_pal_decompress_alloc_tag_and_upload(&pkmnPal);
  72. pokedex_context->detail_pokemon_oam = (s8)template_instanciate_forward_search(&pkmnTemplate, 10, 10, 0);
  73. objects[pokedex_context->detail_pokemon_oam].pos1.x = 55;
  74. objects[pokedex_context->detail_pokemon_oam].pos1.y = 55;
  75. }
  76. rboxid_update_tilemap_and_tileset(TB_DESC);
  77. rboxid_update_tilemap_and_tileset(TB_PKNAME);
  78. rboxid_update_tilemap_and_tileset(TB_PKSIZE);
  79. }
  80. void dexdetail_loop(u8 tid) {
  81. (void)tid;
  82. switch (pokedex_context->state) {
  83. case 0:
  84. bgid_send_tilemap(2);
  85. dexdetail_load_pokemon(pokedex_context->cursor_position_top + pokedex_context->cursor_position_internal);
  86. palette_bg_faded_fill_black();
  87. pokedex_context->state++;
  88. break;
  89. case 1:
  90. gpu_sync_bg_show(0);
  91. gpu_sync_bg_show(1);
  92. gpu_sync_bg_hide(3);
  93. gpu_sync_bg_show(2);
  94. fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 16, 0, 0x0000);
  95. pokedex_context->state++;
  96. break;
  97. default:
  98. break;
  99. }
  100. }
  101. void dexdetail_load_gfx(void) {
  102. rbox_init_from_templates(&dexdetail_boxes[0]);
  103. lz77UnCompVram(pdexDetailBgTiles, (void *)0x0600C000);
  104. LZ77UnCompWram(pdexDetailBgMap, bgid_get_tilemap(2));
  105. gpu_pal_apply_compressed(pdexDetailBgPal, 0, 32);
  106. gpu_pal_apply(pdex_text_pal, 15 * 16, 32);
  107. lcd_io_set(REG_ID_WIN0H, (8 << 8) | (232));
  108. lcd_io_set(REG_ID_WIN0V, ((100 << 8) | (160)));
  109. lcd_io_set(REG_ID_WININ, WIN_BG0 | WIN_BG1 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
  110. lcd_io_set(REG_ID_WINOUT, WIN_BG0 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
  111. bgid_mod_y_offset(1, -24576, 1);
  112. bgid_mark_for_sync(0);
  113. }
  114. void dexdetail_load(void) {
  115. pdex_vram_setup();
  116. dexdetail_load_gfx();
  117. pokedex_context->state = 0;
  118. pokedex_context->detail_pokemon_oam = -1;
  119. task_add(dexdetail_loop, 0);
  120. set_callback2(pdex_cb_handler);
  121. }