|
@@ -1,8 +1,10 @@
|
1
|
1
|
#include <agb_debug.h>
|
2
|
2
|
#include <constants/pkmns.h>
|
3
|
3
|
#include <pokeagb/pokeagb.h>
|
|
4
|
+#include <pokedex/pdexArrow.h>
|
4
|
5
|
#include <pokedex/pdexBall.h>
|
5
|
6
|
#include <pokedex/pdexBg.h>
|
|
7
|
+#include <pokedex/pdexScrollBar.h>
|
6
|
8
|
#include <pokedex/pdexSelectHalf.h>
|
7
|
9
|
|
8
|
10
|
#define PDEX_LAST_SHOWN PKMN_AMIGENTO
|
|
@@ -29,9 +31,15 @@
|
29
|
31
|
#define TB_SEEN_Y (6)
|
30
|
32
|
#define TB_CAUGHT_Y 3
|
31
|
33
|
|
|
34
|
+#define DEX_SCROLL_MIN 23
|
|
35
|
+#define DEX_SCROLL_MAX 146
|
|
36
|
+
|
32
|
37
|
#define DEX_PKMN_TAG 0x1300
|
33
|
38
|
#define DEX_BALL_TAG 0x1301
|
34
|
39
|
#define DEX_CURSOR_TAG 0x1302
|
|
40
|
+#define DEX_ARROW_TAG 0x1303
|
|
41
|
+#define DEX_ARROW_TAG_EPAL 0x1304
|
|
42
|
+#define DEX_SCROLL_TAG 0x1305
|
35
|
43
|
|
36
|
44
|
#define MAX3_COUNT_DIGITS(n) (n >= 100 ? 3 : (n >= 10 ? 2 : 1))
|
37
|
45
|
|
|
@@ -49,7 +57,7 @@ extern const pchar pdex_str_seen[];
|
49
|
57
|
extern const pchar pdex_str_caught[];
|
50
|
58
|
extern const pchar pdex_str_empty[];
|
51
|
59
|
|
52
|
|
-static const u8 pdex_y_offset[] = {19, 34, 49, 64, 79, 94, 109, 124, 139};
|
|
60
|
+static const u8 pdex_y_offset[] = {19, 35, 51, 67, 83, 99, 115, 131};
|
53
|
61
|
|
54
|
62
|
const u16 pdex_text_pal[] = {rgb5(255, 0, 255), rgb5(255, 255, 255), rgb5(0, 0, 0), rgb5(255, 0, 255),
|
55
|
63
|
rgb5(255, 0, 255), rgb5(255, 0, 255), rgb5(255, 0, 255), rgb5(255, 0, 255),
|
|
@@ -61,8 +69,8 @@ struct TextColor pdex_text_color = {0, 1, 2};
|
61
|
69
|
struct TextboxTemplate pdex_boxes[] = {
|
62
|
70
|
{.bg_id = 0, .x = 11, .y = 0, .width = 10, .height = 2, .pal_id = 15, .charbase = 1},
|
63
|
71
|
{.bg_id = 0, .x = 2, .y = 2, .width = 10, .height = 2, .pal_id = 15, .charbase = 21},
|
64
|
|
- {.bg_id = 0, .x = 3, .y = 14, .width = 9, .height = 3, .pal_id = 15, .charbase = 41},
|
65
|
|
- {.bg_id = 0, .x = 3, .y = 17, .width = 9, .height = 2, .pal_id = 15, .charbase = 59},
|
|
72
|
+ {.bg_id = 0, .x = 3, .y = 13, .width = 9, .height = 3, .pal_id = 15, .charbase = 41},
|
|
73
|
+ {.bg_id = 0, .x = 3, .y = 16, .width = 9, .height = 2, .pal_id = 15, .charbase = 59},
|
66
|
74
|
|
67
|
75
|
{.bg_id = 1, .x = 16, .y = 0, .width = 11, .height = 32, .pal_id = 15, .charbase = 77},
|
68
|
76
|
|
|
@@ -114,24 +122,21 @@ const struct BgConfig pdex_bg_config[4] = {
|
114
|
122
|
|
115
|
123
|
s16 pdex_get_y_offset(s8 n) {
|
116
|
124
|
s8 modOffset = n + pokedex_context->hardware_scroll_amount;
|
117
|
|
- s8 wrapOffset = 0;
|
118
|
125
|
dprintf("mod_offset: %d\n", modOffset);
|
119
|
126
|
if (modOffset < -1) {
|
120
|
|
- modOffset += 17;
|
121
|
|
- wrapOffset = 1;
|
|
127
|
+ modOffset += 16;
|
122
|
128
|
}
|
123
|
129
|
|
124
|
|
- if (modOffset > 15) {
|
125
|
|
- wrapOffset = -1;
|
126
|
|
- modOffset -= 17;
|
|
130
|
+ if (modOffset > 14) {
|
|
131
|
+ modOffset -= 16;
|
127
|
132
|
}
|
128
|
|
- return (19 + (15 * modOffset)) + wrapOffset + (pokedex_context->overdo_amount);
|
|
133
|
+ return (19 + (16 * modOffset));
|
129
|
134
|
}
|
130
|
135
|
|
131
|
136
|
void pdex_main_box_species_fill(s8 n, u16 species, bool seen, bool caught) {
|
132
|
137
|
s16 y = pdex_get_y_offset(n);
|
133
|
138
|
dprintf("trying to print box to y: %d\n", y);
|
134
|
|
- rboxid_fill_rectangle(TB_MAIN, 0, 0, y, 11 * 8, 15);
|
|
139
|
+ rboxid_fill_rectangle(TB_MAIN, 0, 0, y, 11 * 8, 16);
|
135
|
140
|
const pchar *stringToPrint = (seen || caught) ? &pokemon_names[species][0] : &pdex_str_empty[0];
|
136
|
141
|
const pchar stringWhitespace[] = {0x0, 0xFF};
|
137
|
142
|
fmt_int_10(string_buffer, pokedex_context->cursor_position_top + n, 2, 3);
|
|
@@ -141,7 +146,7 @@ void pdex_main_box_species_fill(s8 n, u16 species, bool seen, bool caught) {
|
141
|
146
|
}
|
142
|
147
|
|
143
|
148
|
void pdex_update_balls(void) {
|
144
|
|
- for (u8 i = 0; i < 9; ++i) {
|
|
149
|
+ for (u8 i = 0; i < 8; ++i) {
|
145
|
150
|
if (pokedex_context->lookup[i + pokedex_context->cursor_position_top].caught)
|
146
|
151
|
OBJID_SHOW(pokedex_context->ball_oams[i]);
|
147
|
152
|
else
|
|
@@ -151,7 +156,7 @@ void pdex_update_balls(void) {
|
151
|
156
|
|
152
|
157
|
void pdex_update_page_full() {
|
153
|
158
|
rboxid_clear_pixels(TB_MAIN, 0);
|
154
|
|
- for (s8 i = pokedex_context->cursor_position_top; i < pokedex_context->cursor_position_top + 9; ++i) {
|
|
159
|
+ for (s8 i = pokedex_context->cursor_position_top; i < pokedex_context->cursor_position_top + 8; ++i) {
|
155
|
160
|
pdex_main_box_species_fill(i - pokedex_context->cursor_position_top, pokedex_context->lookup[i].species,
|
156
|
161
|
pokedex_context->lookup[i].seen, pokedex_context->lookup[i].caught);
|
157
|
162
|
}
|
|
@@ -219,7 +224,7 @@ void pdex_pokemon_load(u16 species) {
|
219
|
224
|
pokedex_context->pokemon_oam = (s8)template_instanciate_forward_search(&pkmnTemplate, 10, 10, 0);
|
220
|
225
|
|
221
|
226
|
objects[pokedex_context->pokemon_oam].pos1.x = 55;
|
222
|
|
- objects[pokedex_context->pokemon_oam].pos1.y = 80;
|
|
227
|
+ objects[pokedex_context->pokemon_oam].pos1.y = 76;
|
223
|
228
|
}
|
224
|
229
|
rboxid_update_tilemap_and_tileset(TB_PKMN);
|
225
|
230
|
}
|
|
@@ -247,7 +252,7 @@ const struct Template pdex_ball_template = {
|
247
|
252
|
void pdex_pokeballs_init(void) {
|
248
|
253
|
gpu_tile_obj_decompress_alloc_tag_and_upload(&pdex_ball_tiles);
|
249
|
254
|
gpu_pal_obj_alloc_tag_and_apply(&pdex_ball_pal);
|
250
|
|
- for (u8 i = 0; i < 9; ++i) {
|
|
255
|
+ for (u8 i = 0; i < 8; ++i) {
|
251
|
256
|
pokedex_context->ball_oams[i] =
|
252
|
257
|
template_instanciate_forward_search(&pdex_ball_template, 124, 8 + pdex_y_offset[i], 1);
|
253
|
258
|
}
|
|
@@ -298,6 +303,92 @@ void pdex_cursor_init(void) {
|
298
|
303
|
objects[pokedex_context->cursor_follow_oam].final_oam.h_flip = true;
|
299
|
304
|
}
|
300
|
305
|
|
|
306
|
+void pdex_oac_scroll_bar(struct Object *obj) {
|
|
307
|
+ obj->pos1.y = 23 + (((pokedex_context->cursor_position_top + pokedex_context->cursor_position_internal) * 123) / PDEX_LAST_SHOWN);
|
|
308
|
+}
|
|
309
|
+
|
|
310
|
+void pdex_oac_arrow(struct Object *obj) {
|
|
311
|
+ if (obj->priv[0]) {
|
|
312
|
+ // this is the down facing arrow
|
|
313
|
+ if (pokedex_context->cursor_position_top + 8 > PDEX_LAST_SHOWN) {
|
|
314
|
+ obj->final_oam.palette_num = obj->priv[2];
|
|
315
|
+ }
|
|
316
|
+ else
|
|
317
|
+ {
|
|
318
|
+ obj->final_oam.palette_num = obj->priv[1];
|
|
319
|
+ }
|
|
320
|
+ } else {
|
|
321
|
+ // this is the up facing arrow
|
|
322
|
+ if (pokedex_context->cursor_position_top == pokedex_context->first_seen) {
|
|
323
|
+ obj->final_oam.palette_num = obj->priv[2];
|
|
324
|
+ }
|
|
325
|
+ else
|
|
326
|
+ {
|
|
327
|
+ obj->final_oam.palette_num = obj->priv[1];
|
|
328
|
+ }
|
|
329
|
+ }
|
|
330
|
+}
|
|
331
|
+
|
|
332
|
+struct SpriteTiles pdex_scroll_bar_tiles = {pdexScrollBarTiles, 32, DEX_SCROLL_TAG};
|
|
333
|
+struct SpritePalette pdex_scroll_bar_pal = {pdexScrollBarPal, DEX_SCROLL_TAG};
|
|
334
|
+struct SpriteTiles pdex_arrow_tiles = {pdexArrowTiles, 128, DEX_ARROW_TAG};
|
|
335
|
+struct SpritePalette pdex_arrow_pal = {pdexArrowPal, DEX_ARROW_TAG};
|
|
336
|
+struct SpritePalette pdex_arrow_pal_gray = {pdexArrowPal, DEX_ARROW_TAG_EPAL};
|
|
337
|
+
|
|
338
|
+const struct OamData pdex_scroll_bar_oam = {
|
|
339
|
+ .affine_mode = 0,
|
|
340
|
+ .obj_mode = 0,
|
|
341
|
+ .mosaic = false,
|
|
342
|
+ .shape = 0,
|
|
343
|
+ .size = 0,
|
|
344
|
+};
|
|
345
|
+
|
|
346
|
+const struct OamData pdex_arrow_oam = {
|
|
347
|
+ .affine_mode = 0,
|
|
348
|
+ .obj_mode = 0,
|
|
349
|
+ .mosaic = false,
|
|
350
|
+ .shape = 0,
|
|
351
|
+ .size = 1,
|
|
352
|
+};
|
|
353
|
+
|
|
354
|
+const struct Template pdex_scroll_bar_template = {
|
|
355
|
+ .tiles_tag = DEX_SCROLL_TAG,
|
|
356
|
+ .pal_tag = DEX_SCROLL_TAG,
|
|
357
|
+ .oam = &pdex_scroll_bar_oam,
|
|
358
|
+ .animation = &anim_image_empty,
|
|
359
|
+ .graphics = &pdex_scroll_bar_tiles,
|
|
360
|
+ .rotscale = &rotscale_empty,
|
|
361
|
+ .callback = pdex_oac_scroll_bar,
|
|
362
|
+};
|
|
363
|
+
|
|
364
|
+const struct Template pdex_arrow_template = {
|
|
365
|
+ .tiles_tag = DEX_ARROW_TAG,
|
|
366
|
+ .pal_tag = DEX_ARROW_TAG,
|
|
367
|
+ .oam = &pdex_arrow_oam,
|
|
368
|
+ .animation = &anim_image_empty,
|
|
369
|
+ .graphics = &pdex_arrow_tiles,
|
|
370
|
+ .rotscale = &rotscale_empty,
|
|
371
|
+ .callback = pdex_oac_arrow,
|
|
372
|
+};
|
|
373
|
+
|
|
374
|
+void pdex_load_scroll_ui(void) {
|
|
375
|
+ gpu_tile_obj_decompress_alloc_tag_and_upload(&pdex_scroll_bar_tiles);
|
|
376
|
+ gpu_tile_obj_decompress_alloc_tag_and_upload(&pdex_arrow_tiles);
|
|
377
|
+ gpu_pal_obj_alloc_tag_and_apply(&pdex_scroll_bar_pal);
|
|
378
|
+ u8 normalPal = gpu_pal_obj_alloc_tag_and_apply(&pdex_arrow_pal);
|
|
379
|
+ u8 grayPal = gpu_pal_obj_alloc_tag_and_apply(&pdex_arrow_pal_gray);
|
|
380
|
+ tint_palette_gray(&palette_bg_unfaded[16 * (16 + grayPal)], 16);
|
|
381
|
+ (void)template_instanciate_forward_search(&pdex_scroll_bar_template, 233, 23, 0);
|
|
382
|
+ u8 upArrow = template_instanciate_forward_search(&pdex_arrow_template, 232, 19, 0);
|
|
383
|
+ u8 downArrow = template_instanciate_forward_search(&pdex_arrow_template, 232, 150, 0);
|
|
384
|
+ objects[downArrow].priv[0] = true;
|
|
385
|
+ objects[downArrow].final_oam.v_flip = true;
|
|
386
|
+ objects[upArrow].priv[1] = normalPal;
|
|
387
|
+ objects[downArrow].priv[1] = normalPal;
|
|
388
|
+ objects[upArrow].priv[2] = grayPal;
|
|
389
|
+ objects[downArrow].priv[2] = grayPal;
|
|
390
|
+}
|
|
391
|
+
|
301
|
392
|
void pdex_data_setup(void) {
|
302
|
393
|
/* fill the LUT */
|
303
|
394
|
/* TODO: get data from various pokedex lists */
|
|
@@ -318,28 +409,22 @@ void pdex_data_setup(void) {
|
318
|
409
|
}
|
319
|
410
|
|
320
|
411
|
void pdex_hardware_scroll(bool up) {
|
321
|
|
- /* somewhat hacky wraparound scrolling, works though */
|
322
|
|
- /* TODO: Fix the one pixel off */
|
323
|
412
|
if (up) {
|
324
|
|
- if (pokedex_context->hardware_scroll_amount > -16) {
|
325
|
|
- bgid_mod_y_offset(1, -(15 << 8), 1);
|
|
413
|
+ if (pokedex_context->hardware_scroll_amount > -15) {
|
|
414
|
+ bgid_mod_y_offset(1, -(16 << 8), 1);
|
326
|
415
|
pokedex_context->hardware_scroll_amount--;
|
327
|
416
|
} else {
|
328
|
417
|
pokedex_context->hardware_scroll_amount = 0;
|
329
|
|
- // pokedex_context->overdo_amount++;
|
330
|
418
|
bgid_mod_y_offset(1, 0, 0);
|
331
|
|
- bgid_mod_y_offset(1, (256 * pokedex_context->overdo_amount), 1);
|
332
|
419
|
}
|
333
|
420
|
} else {
|
334
|
421
|
|
335
|
|
- if (pokedex_context->hardware_scroll_amount < 16) {
|
336
|
|
- bgid_mod_y_offset(1, 15 << 8, 1);
|
|
422
|
+ if (pokedex_context->hardware_scroll_amount < 15) {
|
|
423
|
+ bgid_mod_y_offset(1, 16 << 8, 1);
|
337
|
424
|
pokedex_context->hardware_scroll_amount++;
|
338
|
425
|
} else {
|
339
|
426
|
pokedex_context->hardware_scroll_amount = 0;
|
340
|
|
- // pokedex_context->overdo_amount--;
|
341
|
427
|
bgid_mod_y_offset(1, 0, 0);
|
342
|
|
- bgid_mod_y_offset(1, (256 * pokedex_context->overdo_amount), 1);
|
343
|
428
|
}
|
344
|
429
|
}
|
345
|
430
|
}
|
|
@@ -351,8 +436,8 @@ void pdex_fill_previous_slot(void) {
|
351
|
436
|
}
|
352
|
437
|
|
353
|
438
|
void pdex_fill_next_slot(void) {
|
354
|
|
- u16 pIndex = pokedex_context->cursor_position_top + 9;
|
355
|
|
- pdex_main_box_species_fill(9, pokedex_context->lookup[pIndex].species, pokedex_context->lookup[pIndex].seen,
|
|
439
|
+ u16 pIndex = pokedex_context->cursor_position_top + 8;
|
|
440
|
+ pdex_main_box_species_fill(8, pokedex_context->lookup[pIndex].species, pokedex_context->lookup[pIndex].seen,
|
356
|
441
|
pokedex_context->lookup[pIndex].caught);
|
357
|
442
|
}
|
358
|
443
|
|
|
@@ -367,9 +452,9 @@ void pdex_try_advance(u8 reverse) {
|
367
|
452
|
pdex_hardware_scroll(true);
|
368
|
453
|
}
|
369
|
454
|
} else {
|
370
|
|
- if (pokedex_context->cursor_position_internal < 8) {
|
|
455
|
+ if (pokedex_context->cursor_position_internal < 7) {
|
371
|
456
|
pokedex_context->cursor_position_internal++;
|
372
|
|
- } else if (pokedex_context->cursor_position_top < (PDEX_LAST_SHOWN - 8)) {
|
|
457
|
+ } else if (pokedex_context->cursor_position_top < (PDEX_LAST_SHOWN - 7)) {
|
373
|
458
|
pdex_fill_next_slot();
|
374
|
459
|
pokedex_context->cursor_position_top++;
|
375
|
460
|
pdex_hardware_scroll(false);
|
|
@@ -385,7 +470,6 @@ void pdex_try_advance(u8 reverse) {
|
385
|
470
|
}
|
386
|
471
|
|
387
|
472
|
void pdex_loop(u8 tid) {
|
388
|
|
- (void)tid;
|
389
|
473
|
switch (pokedex_context->state) {
|
390
|
474
|
case 0:
|
391
|
475
|
pokedex_context->state++;
|
|
@@ -401,6 +485,7 @@ void pdex_loop(u8 tid) {
|
401
|
485
|
pdex_cursor_init();
|
402
|
486
|
|
403
|
487
|
pdex_pokeballs_init();
|
|
488
|
+ pdex_load_scroll_ui();
|
404
|
489
|
pdex_pokemon_load(pokedex_context->lookup[pokedex_context->first_seen].species);
|
405
|
490
|
pdex_load_sc();
|
406
|
491
|
pdex_update_page_full();
|
|
@@ -419,29 +504,40 @@ void pdex_loop(u8 tid) {
|
419
|
504
|
|
420
|
505
|
break;
|
421
|
506
|
case 3:
|
422
|
|
- if ((super.buttons_held & KEY_DOWN)) {
|
423
|
|
- pokedex_context->held_frames++;
|
424
|
|
- if (pokedex_context->held_frames == 10) {
|
|
507
|
+ if (!pal_fade_control.active)
|
|
508
|
+ pokedex_context->state++;
|
|
509
|
+ break;
|
|
510
|
+ case 4:
|
|
511
|
+ /* main control */
|
|
512
|
+ if (super.buttons_new & KEY_B) {
|
|
513
|
+ pokedex_context->state = 10;
|
|
514
|
+ }
|
|
515
|
+ if ((super.buttons_new & KEY_DOWN) || (super.buttons_held & KEY_DOWN))
|
|
516
|
+ {
|
425
|
517
|
pdex_try_advance(false);
|
426
|
|
- pokedex_context->held_frames = 0;
|
427
|
518
|
}
|
428
|
|
- } else if ((super.buttons_held & KEY_UP)) {
|
429
|
|
- pokedex_context->held_frames++;
|
430
|
|
- if (pokedex_context->held_frames == 10) {
|
|
519
|
+ if((super.buttons_new & KEY_UP) || (super.buttons_held & KEY_UP))
|
|
520
|
+ {
|
431
|
521
|
pdex_try_advance(true);
|
432
|
|
- pokedex_context->held_frames = 0;
|
433
|
522
|
}
|
434
|
|
- } else if ((super.buttons_new & KEY_DOWN)) {
|
435
|
|
- pokedex_context->held_frames = 0;
|
436
|
|
- pdex_try_advance(false);
|
437
|
|
- } else if ((super.buttons_new & KEY_UP)) {
|
438
|
|
- pokedex_context->held_frames = 0;
|
439
|
|
- pdex_try_advance(true);
|
|
523
|
+ break;
|
|
524
|
+ case 10:
|
|
525
|
+ /* control flow exit */
|
|
526
|
+ fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 0, 16, 0x000);
|
|
527
|
+ pokedex_context->state++;
|
|
528
|
+ break;
|
|
529
|
+ case 11:
|
|
530
|
+ if (!pal_fade_control.active) {
|
|
531
|
+ task_del(tid);
|
|
532
|
+ free(pokedex_context->lookup);
|
|
533
|
+ free(pokedex_context);
|
|
534
|
+ set_callback2(c2_overworld_switch_start_menu);
|
|
535
|
+ set_callback1(c1_overworld);
|
|
536
|
+ }
|
|
537
|
+ break;
|
|
538
|
+ default:
|
|
539
|
+ break;
|
440
|
540
|
}
|
441
|
|
- break;
|
442
|
|
-default:
|
443
|
|
- break;
|
444
|
|
-}
|
445
|
541
|
}
|
446
|
542
|
|
447
|
543
|
bool sm_pdex_init(void) {
|
|
@@ -486,7 +582,7 @@ void pdex_vram_setup(void) {
|
486
|
582
|
|
487
|
583
|
/*setup window*/
|
488
|
584
|
lcd_io_set(REG_ID_WIN0H, (128 << 8) | (216));
|
489
|
|
- lcd_io_set(REG_ID_WIN0V, ((20 << 8) | (152)));
|
|
585
|
+ lcd_io_set(REG_ID_WIN0V, ((20 << 8) | (148)));
|
490
|
586
|
lcd_io_set(REG_ID_WININ, WIN_BG0 | WIN_BG1 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
|
491
|
587
|
lcd_io_set(REG_ID_WINOUT, WIN_BG0 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
|
492
|
588
|
|