Browse Source

update dex

SBird1337 6 years ago
parent
commit
0218dcd31f
3 changed files with 147 additions and 51 deletions
  1. 1
    1
      g3headers
  2. 1
    1
      sots-private
  3. 145
    49
      src/pokedex/pokedex.c

+ 1
- 1
g3headers

1
-Subproject commit 4e715b48868f0ffa22959c430c8decb5c7785bfc
1
+Subproject commit 84ca130548672a7ba031b0bc621510fd88176fc0

+ 1
- 1
sots-private

1
-Subproject commit ba7d2651d03ffc8749aed8ef8d1d77213e54bd81
1
+Subproject commit c2fbc6fcaf5babd6d49020cd6a70ec2a3a708266

+ 145
- 49
src/pokedex/pokedex.c View File

1
 #include <agb_debug.h>
1
 #include <agb_debug.h>
2
 #include <constants/pkmns.h>
2
 #include <constants/pkmns.h>
3
 #include <pokeagb/pokeagb.h>
3
 #include <pokeagb/pokeagb.h>
4
+#include <pokedex/pdexArrow.h>
4
 #include <pokedex/pdexBall.h>
5
 #include <pokedex/pdexBall.h>
5
 #include <pokedex/pdexBg.h>
6
 #include <pokedex/pdexBg.h>
7
+#include <pokedex/pdexScrollBar.h>
6
 #include <pokedex/pdexSelectHalf.h>
8
 #include <pokedex/pdexSelectHalf.h>
7
 
9
 
8
 #define PDEX_LAST_SHOWN PKMN_AMIGENTO
10
 #define PDEX_LAST_SHOWN PKMN_AMIGENTO
29
 #define TB_SEEN_Y (6)
31
 #define TB_SEEN_Y (6)
30
 #define TB_CAUGHT_Y 3
32
 #define TB_CAUGHT_Y 3
31
 
33
 
34
+#define DEX_SCROLL_MIN 23
35
+#define DEX_SCROLL_MAX 146
36
+
32
 #define DEX_PKMN_TAG 0x1300
37
 #define DEX_PKMN_TAG 0x1300
33
 #define DEX_BALL_TAG 0x1301
38
 #define DEX_BALL_TAG 0x1301
34
 #define DEX_CURSOR_TAG 0x1302
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
 #define MAX3_COUNT_DIGITS(n) (n >= 100 ? 3 : (n >= 10 ? 2 : 1))
44
 #define MAX3_COUNT_DIGITS(n) (n >= 100 ? 3 : (n >= 10 ? 2 : 1))
37
 
45
 
49
 extern const pchar pdex_str_caught[];
57
 extern const pchar pdex_str_caught[];
50
 extern const pchar pdex_str_empty[];
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
 const u16 pdex_text_pal[] = {rgb5(255, 0, 255), rgb5(255, 255, 255), rgb5(0, 0, 0),     rgb5(255, 0, 255),
62
 const u16 pdex_text_pal[] = {rgb5(255, 0, 255), rgb5(255, 255, 255), rgb5(0, 0, 0),     rgb5(255, 0, 255),
55
                              rgb5(255, 0, 255), rgb5(255, 0, 255),   rgb5(255, 0, 255), rgb5(255, 0, 255),
63
                              rgb5(255, 0, 255), rgb5(255, 0, 255),   rgb5(255, 0, 255), rgb5(255, 0, 255),
61
 struct TextboxTemplate pdex_boxes[] = {
69
 struct TextboxTemplate pdex_boxes[] = {
62
     {.bg_id = 0, .x = 11, .y = 0, .width = 10, .height = 2, .pal_id = 15, .charbase = 1},
70
     {.bg_id = 0, .x = 11, .y = 0, .width = 10, .height = 2, .pal_id = 15, .charbase = 1},
63
     {.bg_id = 0, .x = 2, .y = 2, .width = 10, .height = 2, .pal_id = 15, .charbase = 21},
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
     {.bg_id = 1, .x = 16, .y = 0, .width = 11, .height = 32, .pal_id = 15, .charbase = 77},
75
     {.bg_id = 1, .x = 16, .y = 0, .width = 11, .height = 32, .pal_id = 15, .charbase = 77},
68
 
76
 
114
 
122
 
115
 s16 pdex_get_y_offset(s8 n) {
123
 s16 pdex_get_y_offset(s8 n) {
116
     s8 modOffset = n + pokedex_context->hardware_scroll_amount;
124
     s8 modOffset = n + pokedex_context->hardware_scroll_amount;
117
-    s8 wrapOffset = 0;
118
     dprintf("mod_offset: %d\n", modOffset);
125
     dprintf("mod_offset: %d\n", modOffset);
119
     if (modOffset < -1) {
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
 void pdex_main_box_species_fill(s8 n, u16 species, bool seen, bool caught) {
136
 void pdex_main_box_species_fill(s8 n, u16 species, bool seen, bool caught) {
132
     s16 y = pdex_get_y_offset(n);
137
     s16 y = pdex_get_y_offset(n);
133
     dprintf("trying to print box to y: %d\n", y);
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
     const pchar *stringToPrint = (seen || caught) ? &pokemon_names[species][0] : &pdex_str_empty[0];
140
     const pchar *stringToPrint = (seen || caught) ? &pokemon_names[species][0] : &pdex_str_empty[0];
136
     const pchar stringWhitespace[] = {0x0, 0xFF};
141
     const pchar stringWhitespace[] = {0x0, 0xFF};
137
     fmt_int_10(string_buffer, pokedex_context->cursor_position_top + n, 2, 3);
142
     fmt_int_10(string_buffer, pokedex_context->cursor_position_top + n, 2, 3);
141
 }
146
 }
142
 
147
 
143
 void pdex_update_balls(void) {
148
 void pdex_update_balls(void) {
144
-    for (u8 i = 0; i < 9; ++i) {
149
+    for (u8 i = 0; i < 8; ++i) {
145
         if (pokedex_context->lookup[i + pokedex_context->cursor_position_top].caught)
150
         if (pokedex_context->lookup[i + pokedex_context->cursor_position_top].caught)
146
             OBJID_SHOW(pokedex_context->ball_oams[i]);
151
             OBJID_SHOW(pokedex_context->ball_oams[i]);
147
         else
152
         else
151
 
156
 
152
 void pdex_update_page_full() {
157
 void pdex_update_page_full() {
153
     rboxid_clear_pixels(TB_MAIN, 0);
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
         pdex_main_box_species_fill(i - pokedex_context->cursor_position_top, pokedex_context->lookup[i].species,
160
         pdex_main_box_species_fill(i - pokedex_context->cursor_position_top, pokedex_context->lookup[i].species,
156
                                    pokedex_context->lookup[i].seen, pokedex_context->lookup[i].caught);
161
                                    pokedex_context->lookup[i].seen, pokedex_context->lookup[i].caught);
157
     }
162
     }
219
         pokedex_context->pokemon_oam = (s8)template_instanciate_forward_search(&pkmnTemplate, 10, 10, 0);
224
         pokedex_context->pokemon_oam = (s8)template_instanciate_forward_search(&pkmnTemplate, 10, 10, 0);
220
 
225
 
221
         objects[pokedex_context->pokemon_oam].pos1.x = 55;
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
     rboxid_update_tilemap_and_tileset(TB_PKMN);
229
     rboxid_update_tilemap_and_tileset(TB_PKMN);
225
 }
230
 }
247
 void pdex_pokeballs_init(void) {
252
 void pdex_pokeballs_init(void) {
248
     gpu_tile_obj_decompress_alloc_tag_and_upload(&pdex_ball_tiles);
253
     gpu_tile_obj_decompress_alloc_tag_and_upload(&pdex_ball_tiles);
249
     gpu_pal_obj_alloc_tag_and_apply(&pdex_ball_pal);
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
         pokedex_context->ball_oams[i] =
256
         pokedex_context->ball_oams[i] =
252
             template_instanciate_forward_search(&pdex_ball_template, 124, 8 + pdex_y_offset[i], 1);
257
             template_instanciate_forward_search(&pdex_ball_template, 124, 8 + pdex_y_offset[i], 1);
253
     }
258
     }
298
     objects[pokedex_context->cursor_follow_oam].final_oam.h_flip = true;
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
 void pdex_data_setup(void) {
392
 void pdex_data_setup(void) {
302
     /* fill the LUT */
393
     /* fill the LUT */
303
     /* TODO: get data from various pokedex lists */
394
     /* TODO: get data from various pokedex lists */
318
 }
409
 }
319
 
410
 
320
 void pdex_hardware_scroll(bool up) {
411
 void pdex_hardware_scroll(bool up) {
321
-    /* somewhat hacky wraparound scrolling, works though */
322
-    /* TODO: Fix the one pixel off */
323
     if (up) {
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
             pokedex_context->hardware_scroll_amount--;
415
             pokedex_context->hardware_scroll_amount--;
327
         } else {
416
         } else {
328
             pokedex_context->hardware_scroll_amount = 0;
417
             pokedex_context->hardware_scroll_amount = 0;
329
-            // pokedex_context->overdo_amount++;
330
             bgid_mod_y_offset(1, 0, 0);
418
             bgid_mod_y_offset(1, 0, 0);
331
-            bgid_mod_y_offset(1, (256 * pokedex_context->overdo_amount), 1);
332
         }
419
         }
333
     } else {
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
             pokedex_context->hardware_scroll_amount++;
424
             pokedex_context->hardware_scroll_amount++;
338
         } else {
425
         } else {
339
             pokedex_context->hardware_scroll_amount = 0;
426
             pokedex_context->hardware_scroll_amount = 0;
340
-            // pokedex_context->overdo_amount--;
341
             bgid_mod_y_offset(1, 0, 0);
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
 }
436
 }
352
 
437
 
353
 void pdex_fill_next_slot(void) {
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
                                pokedex_context->lookup[pIndex].caught);
441
                                pokedex_context->lookup[pIndex].caught);
357
 }
442
 }
358
 
443
 
367
             pdex_hardware_scroll(true);
452
             pdex_hardware_scroll(true);
368
         }
453
         }
369
     } else {
454
     } else {
370
-        if (pokedex_context->cursor_position_internal < 8) {
455
+        if (pokedex_context->cursor_position_internal < 7) {
371
             pokedex_context->cursor_position_internal++;
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
             pdex_fill_next_slot();
458
             pdex_fill_next_slot();
374
             pokedex_context->cursor_position_top++;
459
             pokedex_context->cursor_position_top++;
375
             pdex_hardware_scroll(false);
460
             pdex_hardware_scroll(false);
385
 }
470
 }
386
 
471
 
387
 void pdex_loop(u8 tid) {
472
 void pdex_loop(u8 tid) {
388
-    (void)tid;
389
     switch (pokedex_context->state) {
473
     switch (pokedex_context->state) {
390
     case 0:
474
     case 0:
391
         pokedex_context->state++;
475
         pokedex_context->state++;
401
         pdex_cursor_init();
485
         pdex_cursor_init();
402
 
486
 
403
         pdex_pokeballs_init();
487
         pdex_pokeballs_init();
488
+        pdex_load_scroll_ui();
404
         pdex_pokemon_load(pokedex_context->lookup[pokedex_context->first_seen].species);
489
         pdex_pokemon_load(pokedex_context->lookup[pokedex_context->first_seen].species);
405
         pdex_load_sc();
490
         pdex_load_sc();
406
         pdex_update_page_full();
491
         pdex_update_page_full();
419
 
504
 
420
         break;
505
         break;
421
     case 3:
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
             pdex_try_advance(false);
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
             pdex_try_advance(true);
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
 bool sm_pdex_init(void) {
543
 bool sm_pdex_init(void) {
486
 
582
 
487
     /*setup window*/
583
     /*setup window*/
488
     lcd_io_set(REG_ID_WIN0H, (128 << 8) | (216));
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
     lcd_io_set(REG_ID_WININ, WIN_BG0 | WIN_BG1 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
586
     lcd_io_set(REG_ID_WININ, WIN_BG0 | WIN_BG1 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
491
     lcd_io_set(REG_ID_WINOUT, WIN_BG0 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
587
     lcd_io_set(REG_ID_WINOUT, WIN_BG0 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
492
 
588