|
@@ -1,10 +1,14 @@
|
1
|
1
|
#include <agb_debug.h>
|
|
2
|
+#include <constants/pkmns.h>
|
2
|
3
|
#include <pokeagb/pokeagb.h>
|
3
|
4
|
#include <pokedex/pdexBall.h>
|
4
|
5
|
#include <pokedex/pdexBg.h>
|
5
|
6
|
#include <pokedex/pdexSelectHalf.h>
|
6
|
7
|
|
|
8
|
+#define PDEX_LAST_SHOWN PKMN_AMIGENTO
|
|
9
|
+
|
7
|
10
|
#define PDEX_FADEIN_SPD 1
|
|
11
|
+
|
8
|
12
|
#define TB_TITLE 0
|
9
|
13
|
#define TB_PKMN 1
|
10
|
14
|
#define TB_SEEN 2
|
|
@@ -45,8 +49,7 @@ extern const pchar pdex_str_seen[];
|
45
|
49
|
extern const pchar pdex_str_caught[];
|
46
|
50
|
extern const pchar pdex_str_empty[];
|
47
|
51
|
|
48
|
|
-static const u8 pdex_y_offset[] = {3, 16 + 2, 2 * 16 + 1, 3 * 16, 4 * 16 - 1,
|
49
|
|
- 5 * 16 - 2, 6 * 16 - 3, 7 * 16 - 4, 8 * 16 - 5};
|
|
52
|
+static const u8 pdex_y_offset[] = {19, 34, 49, 64, 79, 94, 109, 124, 139};
|
50
|
53
|
|
51
|
54
|
const u16 pdex_text_pal[] = {rgb5(255, 0, 255), rgb5(255, 255, 255), rgb5(0, 0, 0), rgb5(255, 0, 255),
|
52
|
55
|
rgb5(255, 0, 255), rgb5(255, 0, 255), rgb5(255, 0, 255), rgb5(255, 0, 255),
|
|
@@ -61,7 +64,7 @@ struct TextboxTemplate pdex_boxes[] = {
|
61
|
64
|
{.bg_id = 0, .x = 3, .y = 14, .width = 9, .height = 3, .pal_id = 15, .charbase = 41},
|
62
|
65
|
{.bg_id = 0, .x = 3, .y = 17, .width = 9, .height = 2, .pal_id = 15, .charbase = 59},
|
63
|
66
|
|
64
|
|
- {.bg_id = 0, .x = 16, .y = 2, .width = 11, .height = 17, .pal_id = 15, .charbase = 77},
|
|
67
|
+ {.bg_id = 1, .x = 16, .y = 0, .width = 11, .height = 32, .pal_id = 15, .charbase = 77},
|
65
|
68
|
|
66
|
69
|
{.bg_id = 0xFF},
|
67
|
70
|
};
|
|
@@ -109,24 +112,37 @@ const struct BgConfig pdex_bg_config[4] = {
|
109
|
112
|
},
|
110
|
113
|
};
|
111
|
114
|
|
112
|
|
-void pdex_main_box_species_fill(u8 n, u16 species, bool seen, bool caught) {
|
113
|
|
- rboxid_fill_rectangle(TB_MAIN, 0, 0, pdex_y_offset[n], 11 * 8, 12);
|
|
115
|
+u16 pdex_get_y_offset(s8 n) {
|
|
116
|
+ s8 modOffset = n + pokedex_context->hardware_scroll_amount;
|
|
117
|
+ if (modOffset < -1)
|
|
118
|
+ modOffset += 8;
|
|
119
|
+ if (modOffset > 15)
|
|
120
|
+ modOffset -= 8;
|
|
121
|
+ return 19 + (15 * modOffset);
|
|
122
|
+}
|
|
123
|
+
|
|
124
|
+void pdex_main_box_species_fill(s8 n, u16 species, bool seen, bool caught) {
|
114
|
125
|
const pchar *stringToPrint = (seen || caught) ? &pokemon_names[species][0] : &pdex_str_empty[0];
|
115
|
126
|
const pchar stringWhitespace[] = {0x0, 0xFF};
|
116
|
|
- fmt_int_10(string_buffer, species, 2, 3);
|
|
127
|
+ fmt_int_10(string_buffer, pokedex_context->cursor_position_top + n, 2, 3);
|
117
|
128
|
pstrcat(string_buffer, &stringWhitespace[0]);
|
118
|
129
|
pstrcat(string_buffer, stringToPrint);
|
119
|
|
- rboxid_print(TB_MAIN, FONT_DEX_STD, 4, pdex_y_offset[n], &pdex_text_color, 0, string_buffer);
|
|
130
|
+ rboxid_print(TB_MAIN, FONT_DEX_STD, 4, pdex_get_y_offset(n), &pdex_text_color, 0, string_buffer);
|
120
|
131
|
// show the pokéball if necessary
|
121
|
132
|
}
|
122
|
133
|
|
123
|
|
-void pdex_init_dex_boxes(void) {
|
124
|
|
- /* fill with dummy data */
|
|
134
|
+void pdex_update_page_full() {
|
125
|
135
|
rboxid_clear_pixels(TB_MAIN, 0);
|
|
136
|
+ for (s8 i = pokedex_context->cursor_position_top - 1; i < pokedex_context->cursor_position_top + 9 + 7; ++i) {
|
|
137
|
+ pdex_main_box_species_fill(i - pokedex_context->cursor_position_top, pokedex_context->lookup[i].species,
|
|
138
|
+ pokedex_context->lookup[i].seen, pokedex_context->lookup[i].caught);
|
|
139
|
+ }
|
126
|
140
|
for (u8 i = 0; i < 9; ++i) {
|
127
|
|
- pdex_main_box_species_fill(i, i + 1, false, false);
|
|
141
|
+ if (pokedex_context->lookup[i + pokedex_context->cursor_position_top].caught)
|
|
142
|
+ OBJID_SHOW(pokedex_context->ball_oams[i]);
|
|
143
|
+ else
|
|
144
|
+ OBJID_HIDE(pokedex_context->ball_oams[i]);
|
128
|
145
|
}
|
129
|
|
- // rboxid_fill_rectangle(TB_MAIN, 1, 0,0, 10*8, 18*8);
|
130
|
146
|
rboxid_update_tilemap_and_tileset(TB_MAIN);
|
131
|
147
|
}
|
132
|
148
|
|
|
@@ -168,27 +184,30 @@ void pdex_pokemon_load(u16 species) {
|
168
|
184
|
u32 twidth = font_get_width_of_string(FONT_DEX_STD, &pokemon_names[species][0], 0x0000);
|
169
|
185
|
rboxid_print(TB_PKMN, FONT_DEX_STD, TB_STD_CENTER(twidth), 3, &pdex_text_color, 0, &pokemon_names[species][0]);
|
170
|
186
|
if (pokedex_context->pokemon_oam != -1) {
|
171
|
|
- obj_delete_and_free(&objects[pokedex_context->pokemon_oam]);
|
|
187
|
+ lz77UnCompVram(pokemon_graphics_front[species].data,
|
|
188
|
+ ((void *)(objects[pokedex_context->pokemon_oam].final_oam.tile_num * 32) + ADDR_VRAM + 0x10000));
|
|
189
|
+ gpu_pal_apply_compressed(pokemon_palette_normal[species].data,
|
|
190
|
+ 16 * (objects[pokedex_context->pokemon_oam].final_oam.palette_num + 16), 32);
|
|
191
|
+ } else {
|
|
192
|
+ struct SpriteTiles pkmnTiles = {pokemon_graphics_front[species].data, 2048, DEX_PKMN_TAG};
|
|
193
|
+ struct SpritePalette pkmnPal = {pokemon_palette_normal[species].data, DEX_PKMN_TAG};
|
|
194
|
+ const struct Template pkmnTemplate = {
|
|
195
|
+ .tiles_tag = DEX_PKMN_TAG,
|
|
196
|
+ .pal_tag = DEX_PKMN_TAG,
|
|
197
|
+ .oam = &pdex_oam_pkmn,
|
|
198
|
+ .animation = &anim_image_empty,
|
|
199
|
+ .graphics = &pkmnTiles,
|
|
200
|
+ .rotscale = &rotscale_empty,
|
|
201
|
+ .callback = oac_nullsub,
|
|
202
|
+ };
|
|
203
|
+ gpu_tile_obj_decompress_alloc_tag_and_upload(&pkmnTiles);
|
|
204
|
+
|
|
205
|
+ gpu_pal_decompress_alloc_tag_and_upload(&pkmnPal);
|
|
206
|
+ pokedex_context->pokemon_oam = (s8)template_instanciate_forward_search(&pkmnTemplate, 10, 10, 0);
|
|
207
|
+
|
|
208
|
+ objects[pokedex_context->pokemon_oam].pos1.x = 55;
|
|
209
|
+ objects[pokedex_context->pokemon_oam].pos1.y = 80;
|
172
|
210
|
}
|
173
|
|
- struct SpriteTiles pkmnTiles = {pokemon_graphics_front[species].data, 2048, DEX_PKMN_TAG};
|
174
|
|
- struct SpritePalette pkmnPal = {pokemon_palette_normal[species].data, DEX_PKMN_TAG};
|
175
|
|
- const struct Template pkmnTemplate = {
|
176
|
|
- .tiles_tag = DEX_PKMN_TAG,
|
177
|
|
- .pal_tag = DEX_PKMN_TAG,
|
178
|
|
- .oam = &pdex_oam_pkmn,
|
179
|
|
- .animation = &anim_image_empty,
|
180
|
|
- .graphics = &pkmnTiles,
|
181
|
|
- .rotscale = &rotscale_empty,
|
182
|
|
- .callback = oac_nullsub,
|
183
|
|
- };
|
184
|
|
- gpu_tile_obj_decompress_alloc_tag_and_upload(&pkmnTiles);
|
185
|
|
-
|
186
|
|
- gpu_pal_decompress_alloc_tag_and_upload(&pkmnPal);
|
187
|
|
- pokedex_context->pokemon_oam = (s8)template_instanciate_forward_search(&pkmnTemplate, 10, 10, 0);
|
188
|
|
-
|
189
|
|
- objects[pokedex_context->pokemon_oam].pos1.x = 55;
|
190
|
|
- objects[pokedex_context->pokemon_oam].pos1.y = 80;
|
191
|
|
-
|
192
|
211
|
rboxid_update_tilemap_and_tileset(TB_PKMN);
|
193
|
212
|
}
|
194
|
213
|
|
|
@@ -217,15 +236,14 @@ void pdex_pokeballs_init(void) {
|
217
|
236
|
gpu_pal_obj_alloc_tag_and_apply(&pdex_ball_pal);
|
218
|
237
|
for (u8 i = 0; i < 9; ++i) {
|
219
|
238
|
pokedex_context->ball_oams[i] =
|
220
|
|
- template_instanciate_forward_search(&pdex_ball_template, 124, 24 + pdex_y_offset[i], 0);
|
221
|
|
- OBJID_HIDE(pokedex_context->ball_oams[i]);
|
|
239
|
+ template_instanciate_forward_search(&pdex_ball_template, 124, 8 + pdex_y_offset[i], 1);
|
222
|
240
|
}
|
223
|
241
|
}
|
224
|
242
|
|
225
|
243
|
void pdex_oac_cursor_follow(struct Object *obj) { obj->pos1.y = objects[pokedex_context->cursor_main_oam].pos1.y; }
|
226
|
244
|
|
227
|
245
|
void pdex_oac_cursor_main(struct Object *obj) {
|
228
|
|
- obj->pos1.y = 29 + pdex_y_offset[pokedex_context->cursor_position_internal];
|
|
246
|
+ obj->pos1.y = 13 + pdex_y_offset[pokedex_context->cursor_position_internal];
|
229
|
247
|
}
|
230
|
248
|
|
231
|
249
|
struct SpriteTiles pdex_cursor_tiles = {pdexSelectHalfTiles, 1024, DEX_CURSOR_TAG};
|
|
@@ -267,6 +285,82 @@ void pdex_cursor_init(void) {
|
267
|
285
|
objects[pokedex_context->cursor_follow_oam].final_oam.h_flip = true;
|
268
|
286
|
}
|
269
|
287
|
|
|
288
|
+void pdex_data_setup(void) {
|
|
289
|
+ /* fill the LUT */
|
|
290
|
+ /* TODO: get data from various pokedex lists */
|
|
291
|
+ bool first = false;
|
|
292
|
+ for (u32 i = 0; i <= PDEX_LAST_SHOWN; ++i) {
|
|
293
|
+ u16 species = pokedex_index_to_species(i);
|
|
294
|
+ if (species > 0) {
|
|
295
|
+ pokedex_context->lookup[i].species = species;
|
|
296
|
+ pokedex_context->lookup[i].seen = dex_flag_pokedex_index(i, DEX_FLAG_CHECK_SEEN);
|
|
297
|
+ pokedex_context->lookup[i].caught = dex_flag_pokedex_index(i, DEX_FLAG_CHECK_CAUGHT);
|
|
298
|
+ if (!first && (pokedex_context->lookup[i].seen)) {
|
|
299
|
+ pokedex_context->first_seen = i;
|
|
300
|
+ pokedex_context->cursor_position_top = i;
|
|
301
|
+ first = true;
|
|
302
|
+ }
|
|
303
|
+ }
|
|
304
|
+ }
|
|
305
|
+}
|
|
306
|
+
|
|
307
|
+void pdex_hardware_scroll(bool up) {
|
|
308
|
+ /* somewhat hacky wraparound scrolling, works though */
|
|
309
|
+ if (up) {
|
|
310
|
+ if (pokedex_context->hardware_scroll_amount > -16) {
|
|
311
|
+ if (pokedex_context->hardware_scroll_amount != -8) {
|
|
312
|
+ bgid_mod_y_offset(1, -3840, 1);
|
|
313
|
+
|
|
314
|
+ } else {
|
|
315
|
+ bgid_mod_y_offset(1, -4096, 1);
|
|
316
|
+ }
|
|
317
|
+ pokedex_context->hardware_scroll_amount--;
|
|
318
|
+ } else {
|
|
319
|
+ pokedex_context->hardware_scroll_amount = 0;
|
|
320
|
+ bgid_mod_y_offset(1, 0, 0);
|
|
321
|
+ }
|
|
322
|
+ } else {
|
|
323
|
+ if (pokedex_context->hardware_scroll_amount < 16) {
|
|
324
|
+ if (pokedex_context->hardware_scroll_amount != 8) {
|
|
325
|
+ bgid_mod_y_offset(1, 3840, 1);
|
|
326
|
+ } else {
|
|
327
|
+ bgid_mod_y_offset(1, 4096, 1);
|
|
328
|
+ }
|
|
329
|
+ pokedex_context->hardware_scroll_amount++;
|
|
330
|
+ } else {
|
|
331
|
+ pokedex_context->hardware_scroll_amount = 0;
|
|
332
|
+ bgid_mod_y_offset(1, 0, 0);
|
|
333
|
+ }
|
|
334
|
+ }
|
|
335
|
+}
|
|
336
|
+
|
|
337
|
+void pdex_try_advance(u8 reverse) {
|
|
338
|
+ bool dirty = false;
|
|
339
|
+ if (reverse) {
|
|
340
|
+ if (pokedex_context->cursor_position_internal > 0) {
|
|
341
|
+ pokedex_context->cursor_position_internal--;
|
|
342
|
+ } else if ((pokedex_context->cursor_position_top) > (pokedex_context->first_seen)) {
|
|
343
|
+ pokedex_context->cursor_position_top--;
|
|
344
|
+ dirty = true;
|
|
345
|
+ }
|
|
346
|
+ } else {
|
|
347
|
+ if (pokedex_context->cursor_position_internal < 8) {
|
|
348
|
+ pokedex_context->cursor_position_internal++;
|
|
349
|
+ } else if (pokedex_context->cursor_position_top < (PDEX_LAST_SHOWN - 8)) {
|
|
350
|
+ pokedex_context->cursor_position_top++;
|
|
351
|
+ dirty = true;
|
|
352
|
+ }
|
|
353
|
+ }
|
|
354
|
+ if (dirty) {
|
|
355
|
+ pdex_update_page_full();
|
|
356
|
+ }
|
|
357
|
+ u16 pkIndexToLoad = pokedex_context->cursor_position_internal + pokedex_context->cursor_position_top;
|
|
358
|
+ if (pokedex_context->lookup[pkIndexToLoad].seen || pokedex_context->lookup[pkIndexToLoad].caught)
|
|
359
|
+ pdex_pokemon_load(pokedex_context->lookup[pkIndexToLoad].species);
|
|
360
|
+ else
|
|
361
|
+ pdex_pokemon_load(0);
|
|
362
|
+}
|
|
363
|
+
|
270
|
364
|
void pdex_loop(u8 tid) {
|
271
|
365
|
(void)tid;
|
272
|
366
|
switch (pokedex_context->state) {
|
|
@@ -280,37 +374,32 @@ void pdex_loop(u8 tid) {
|
280
|
374
|
rboxid_print(TB_TITLE, FONT_DEX_STD, 0, 0, &pdex_text_color, 0, &pdex_str_title[0]);
|
281
|
375
|
rboxid_update_tilemap_and_tileset(TB_TITLE);
|
282
|
376
|
|
283
|
|
- pdex_pokemon_load(0);
|
284
|
|
- pdex_load_sc();
|
285
|
|
- pdex_init_dex_boxes();
|
286
|
|
- pdex_pokeballs_init();
|
|
377
|
+ pdex_data_setup();
|
287
|
378
|
pdex_cursor_init();
|
|
379
|
+
|
|
380
|
+ pdex_pokeballs_init();
|
|
381
|
+ pdex_pokemon_load(pokedex_context->lookup[pokedex_context->first_seen].species);
|
|
382
|
+ pdex_load_sc();
|
|
383
|
+ pdex_update_page_full();
|
|
384
|
+
|
288
|
385
|
palette_bg_faded_fill_black();
|
289
|
386
|
pokedex_context->state++;
|
290
|
387
|
break;
|
291
|
388
|
case 2:
|
292
|
389
|
gpu_sync_bg_show(0);
|
293
|
|
- gpu_sync_bg_hide(1);
|
|
390
|
+ gpu_sync_bg_show(1);
|
294
|
391
|
gpu_sync_bg_hide(3);
|
295
|
392
|
|
296
|
393
|
gpu_sync_bg_show(2);
|
297
|
|
- if (pokedex_context->delay_count >= 5) {
|
298
|
|
- fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 16, 0, 0x0000);
|
299
|
|
- pokedex_context->state++;
|
300
|
|
- pokedex_context->delay_count = 0;
|
301
|
|
- } else {
|
302
|
|
- pokedex_context->delay_count++;
|
303
|
|
- }
|
|
394
|
+ fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 16, 0, 0x0000);
|
|
395
|
+ pokedex_context->state++;
|
304
|
396
|
|
305
|
397
|
break;
|
306
|
398
|
case 3:
|
307
|
399
|
if ((super.buttons_new & KEY_DOWN)) {
|
308
|
|
- if (pokedex_context->cursor_position_internal < 8) {
|
309
|
|
- pokedex_context->cursor_position_internal++;
|
310
|
|
- }
|
|
400
|
+ pdex_try_advance(false);
|
311
|
401
|
} else if ((super.buttons_new & KEY_UP)) {
|
312
|
|
- if (pokedex_context->cursor_position_internal > 0)
|
313
|
|
- pokedex_context->cursor_position_internal--;
|
|
402
|
+ pdex_try_advance(true);
|
314
|
403
|
}
|
315
|
404
|
break;
|
316
|
405
|
default:
|
|
@@ -332,11 +421,13 @@ bool sm_pdex_init(void) {
|
332
|
421
|
void pdex_vram_setup(void) {
|
333
|
422
|
vblank_handler_set(NULL);
|
334
|
423
|
pal_fade_control_and_dead_struct_reset();
|
|
424
|
+ gpu_tile_bg_drop_all_sets(true);
|
335
|
425
|
obj_and_aux_reset_all();
|
336
|
426
|
gpu_tile_obj_tags_reset();
|
|
427
|
+ gpu_pal_allocator_reset();
|
337
|
428
|
rboxes_free();
|
|
429
|
+ malloc_init((void *)0x2000000, 0x1C000);
|
338
|
430
|
tasks_init();
|
339
|
|
- gpu_tile_bg_drop_all_sets(true);
|
340
|
431
|
|
341
|
432
|
bg_vram_setup(0, &pdex_bg_config[0], 4);
|
342
|
433
|
|
|
@@ -356,6 +447,12 @@ void pdex_vram_setup(void) {
|
356
|
447
|
gpu_pal_apply_compressed(pdexBgPal, 0, 32);
|
357
|
448
|
gpu_pal_apply(pdex_text_pal, 15 * 16, 32);
|
358
|
449
|
|
|
450
|
+ /*setup window*/
|
|
451
|
+ lcd_io_set(REG_ID_WIN0H, (128 << 8) | (216));
|
|
452
|
+ lcd_io_set(REG_ID_WIN0V, ((20 << 8) | (152)));
|
|
453
|
+ lcd_io_set(REG_ID_WININ, WIN_BG0 | WIN_BG1 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
|
|
454
|
+ lcd_io_set(REG_ID_WINOUT, WIN_BG0 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
|
|
455
|
+
|
359
|
456
|
vblank_handler_set(pdex_vblank_handler);
|
360
|
457
|
interrupts_enable(INTERRUPT_VBLANK);
|
361
|
458
|
bgid_mod_x_offset(0, 0, 0);
|
|
@@ -369,11 +466,11 @@ void pdex_vram_setup(void) {
|
369
|
466
|
}
|
370
|
467
|
|
371
|
468
|
void pdex_load(void) {
|
|
469
|
+
|
372
|
470
|
pdex_vram_setup();
|
373
|
|
- pokedex_context = malloc(sizeof(struct PdexCtx));
|
374
|
|
- pokedex_context->state = 0;
|
|
471
|
+ pokedex_context = malloc_and_clear(sizeof(struct PdexCtx));
|
375
|
472
|
pokedex_context->pokemon_oam = -1;
|
376
|
|
- pokedex_context->delay_count = 0;
|
|
473
|
+ pokedex_context->lookup = malloc_and_clear((PDEX_LAST_SHOWN + 1) * sizeof(struct PdexLookup));
|
377
|
474
|
task_add(pdex_loop, 0);
|
378
|
475
|
set_callback2(pdex_cb_handler);
|
379
|
476
|
}
|