Quellcode durchsuchen

add another dex screen for region selection

SBird1337 vor 6 Jahren
Ursprung
Commit
4274cf7c3d

+ 2
- 2
data/pkmn_tables/icon_sprites.s Datei anzeigen

@@ -2,8 +2,8 @@
2 2
 .thumb
3 3
 .text
4 4
 
5
-.global icon_table
6
-icon_table:
5
+.global pokeicon_table
6
+pokeicon_table:
7 7
 
8 8
 .word icon_0000Tiles
9 9
 .word icon_0001Tiles

+ 2
- 2
data/pkmn_tables/icons_paletten.s Datei anzeigen

@@ -2,8 +2,8 @@
2 2
 .text
3 3
 .thumb
4 4
 
5
-.global icon_palette_table
6
-icon_palette_table:
5
+.global pokeicon_pal_indices
6
+pokeicon_pal_indices:
7 7
 
8 8
 .byte 0
9 9
 .byte 1

+ 1
- 1
g3headers

@@ -1 +1 @@
1
-Subproject commit 84ca130548672a7ba031b0bc621510fd88176fc0
1
+Subproject commit 51b88ad16c551b386614c2e6f7d41c1acd552d92

+ 14
- 14
patches/pokemon_data/pokemon_icons.asm Datei anzeigen

@@ -1,43 +1,43 @@
1 1
 .org 0x08000138
2
-.word icon_table
2
+.word pokeicon_table
3 3
 
4 4
 .org 0x08097050
5
-.word icon_table
5
+.word pokeicon_table
6 6
 
7 7
 .org 0x083D4050
8
-.word icon_table
8
+.word pokeicon_table
9 9
 
10 10
 .org 0x0800013C
11
-.word icon_palette_table
11
+.word pokeicon_pal_indices
12 12
 
13 13
 .org 0x08091390
14
-//.word icon_palette_table
14
+//.word pokeicon_pal_indices
15 15
 /* NOTE: this is referencing the icon template, overriding this will break stuff, for now we do not need to modify the template */
16 16
 
17 17
 
18 18
 .org 0x08096EC0
19
-.word icon_palette_table
19
+.word pokeicon_pal_indices
20 20
 
21 21
 .org 0x08096F50
22
-.word icon_palette_table
22
+.word pokeicon_pal_indices
23 23
 
24 24
 .org 0x080970D8
25
-.word icon_palette_table
25
+.word pokeicon_pal_indices
26 26
 
27 27
 .org 0x0809710C
28
-.word icon_palette_table
28
+.word pokeicon_pal_indices
29 29
 
30 30
 .org 0x08097160
31
-.word icon_palette_table
31
+.word pokeicon_pal_indices
32 32
 
33 33
 .org 0x08097184
34
-.word icon_palette_table
34
+.word pokeicon_pal_indices
35 35
 
36 36
 .org 0x080971F4
37
-.word icon_palette_table
37
+.word pokeicon_pal_indices
38 38
 
39 39
 .org 0x08097214
40
-.word icon_palette_table
40
+.word pokeicon_pal_indices
41 41
 
42 42
 .org 0x08097224
43
-.word icon_palette_table
43
+.word pokeicon_pal_indices

+ 1
- 1
sots-private

@@ -1 +1 @@
1
-Subproject commit c2fbc6fcaf5babd6d49020cd6a70ec2a3a708266
1
+Subproject commit 8ed8457f4c1b3028f890bd873cd2134e67d59574

+ 17
- 145
src/pokedex/pokedex.c Datei anzeigen

@@ -7,9 +7,9 @@
7 7
 #include <pokedex/pdexScrollBar.h>
8 8
 #include <pokedex/pdexSelectHalf.h>
9 9
 
10
-#define PDEX_LAST_SHOWN PKMN_AMIGENTO
10
+#include "pokedex_common.h"
11 11
 
12
-#define PDEX_FADEIN_SPD 1
12
+#define PDEX_LAST_SHOWN PKMN_AMIGENTO
13 13
 
14 14
 #define TB_TITLE 0
15 15
 #define TB_PKMN 1
@@ -17,16 +17,11 @@
17 17
 #define TB_CAUGHT 3
18 18
 #define TB_MAIN 4
19 19
 
20
-#define FONT_DEX_STD 1
20
+
21 21
 #define TB_STD_LEN 10
22 22
 #define TB_STD_LEN_PX (TB_STD_LEN * 8)
23 23
 #define TB_BOT_LEN 9
24 24
 #define TB_BOT_LEN_PX (TB_BOT_LEN * 8)
25
-#define TB_STD_CENTER(t) (((TB_STD_LEN_PX - t) >> 1) + 2)
26
-#define TB_STD_RIGHT(t) ((TB_BOT_LEN_PX - t))
27
-
28
-#define OBJID_HIDE(objid) objects[objid].final_oam.affine_mode = 2
29
-#define OBJID_SHOW(objid) objects[objid].final_oam.affine_mode = 0
30 25
 
31 26
 #define TB_SEEN_Y (6)
32 27
 #define TB_CAUGHT_Y 3
@@ -34,19 +29,6 @@
34 29
 #define DEX_SCROLL_MIN 23
35 30
 #define DEX_SCROLL_MAX 146
36 31
 
37
-#define DEX_PKMN_TAG 0x1300
38
-#define DEX_BALL_TAG 0x1301
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
43
-
44
-#define MAX3_COUNT_DIGITS(n) (n >= 100 ? 3 : (n >= 10 ? 2 : 1))
45
-
46
-#define CPUFSCPY 0
47
-#define CPUFSSET 1
48
-#define CPUModeFS(size, mode) ((size >> 2) | (mode << 24))
49
-
50 32
 void pdex_load(void);
51 33
 void pdex_vblank_handler(void);
52 34
 void pdex_loop(u8 tid);
@@ -59,13 +41,6 @@ extern const pchar pdex_str_empty[];
59 41
 
60 42
 static const u8 pdex_y_offset[] = {19, 35, 51, 67, 83, 99, 115, 131};
61 43
 
62
-const u16 pdex_text_pal[] = {rgb5(255, 0, 255), rgb5(255, 255, 255), rgb5(0, 0, 0),     rgb5(255, 0, 255),
63
-                             rgb5(255, 0, 255), rgb5(255, 0, 255),   rgb5(255, 0, 255), rgb5(255, 0, 255),
64
-                             rgb5(255, 0, 255), rgb5(255, 0, 255),   rgb5(255, 0, 255), rgb5(255, 0, 255),
65
-                             rgb5(255, 0, 255), rgb5(255, 0, 255),   rgb5(255, 0, 255), rgb5(255, 0, 255)};
66
-
67
-struct TextColor pdex_text_color = {0, 1, 2};
68
-
69 44
 struct TextboxTemplate pdex_boxes[] = {
70 45
     {.bg_id = 0, .x = 11, .y = 0, .width = 10, .height = 2, .pal_id = 15, .charbase = 1},
71 46
     {.bg_id = 0, .x = 2, .y = 2, .width = 10, .height = 2, .pal_id = 15, .charbase = 21},
@@ -77,48 +52,7 @@ struct TextboxTemplate pdex_boxes[] = {
77 52
     {.bg_id = 0xFF},
78 53
 };
79 54
 
80
-const struct BgConfig pdex_bg_config[4] = {
81
-    {
82
-        .padding = 0,
83
-        .b_padding = 0,
84
-        .priority = 0,
85
-        .palette = 0,
86
-        .size = 0,
87
-        .map_base = 29,
88
-        .character_base = 0,
89
-        .bgid = 0,
90
-    },
91
-    {
92
-        .padding = 0,
93
-        .b_padding = 0,
94
-        .priority = 1,
95
-        .palette = 0,
96
-        .size = 0,
97
-        .map_base = 28,
98
-        .character_base = 0,
99
-        .bgid = 1,
100
-    },
101
-    {
102
-        .padding = 0,
103
-        .b_padding = 0,
104
-        .priority = 2,
105
-        .palette = 0,
106
-        .size = 0,
107
-        .map_base = 30,
108
-        .character_base = 3,
109
-        .bgid = 2,
110
-    },
111
-    {
112
-        .padding = 0,
113
-        .b_padding = 0,
114
-        .priority = 3,
115
-        .palette = 0,
116
-        .size = 1,
117
-        .map_base = 31,
118
-        .character_base = 3,
119
-        .bgid = 3,
120
-    },
121
-};
55
+
122 56
 
123 57
 s16 pdex_get_y_offset(s8 n) {
124 58
     s8 modOffset = n + pokedex_context->hardware_scroll_amount;
@@ -304,7 +238,8 @@ void pdex_cursor_init(void) {
304 238
 }
305 239
 
306 240
 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);
241
+    obj->pos1.y = 23 + (((pokedex_context->cursor_position_top + pokedex_context->cursor_position_internal) * 123) /
242
+                        PDEX_LAST_SHOWN);
308 243
 }
309 244
 
310 245
 void pdex_oac_arrow(struct Object *obj) {
@@ -312,18 +247,14 @@ void pdex_oac_arrow(struct Object *obj) {
312 247
         // this is the down facing arrow
313 248
         if (pokedex_context->cursor_position_top + 8 > PDEX_LAST_SHOWN) {
314 249
             obj->final_oam.palette_num = obj->priv[2];
315
-        }
316
-        else
317
-        {
250
+        } else {
318 251
             obj->final_oam.palette_num = obj->priv[1];
319 252
         }
320 253
     } else {
321 254
         // this is the up facing arrow
322 255
         if (pokedex_context->cursor_position_top == pokedex_context->first_seen) {
323 256
             obj->final_oam.palette_num = obj->priv[2];
324
-        }
325
-        else
326
-        {
257
+        } else {
327 258
             obj->final_oam.palette_num = obj->priv[1];
328 259
         }
329 260
     }
@@ -392,6 +323,7 @@ void pdex_load_scroll_ui(void) {
392 323
 void pdex_data_setup(void) {
393 324
     /* fill the LUT */
394 325
     /* TODO: get data from various pokedex lists */
326
+    pokedex_context->lookup = malloc_and_clear((PDEX_LAST_SHOWN + 1) * sizeof(struct PdexLookup));
395 327
     bool first = false;
396 328
     for (u32 i = 0; i <= PDEX_LAST_SHOWN; ++i) {
397 329
         u16 species = pokedex_index_to_species(i);
@@ -512,12 +444,10 @@ void pdex_loop(u8 tid) {
512 444
         if (super.buttons_new & KEY_B) {
513 445
             pokedex_context->state = 10;
514 446
         }
515
-        if ((super.buttons_new & KEY_DOWN) || (super.buttons_held & KEY_DOWN))
516
-        {
447
+        if ((super.buttons_new & KEY_DOWN) || (super.buttons_held & KEY_DOWN)) {
517 448
             pdex_try_advance(false);
518 449
         }
519
-        if((super.buttons_new & KEY_UP) || (super.buttons_held & KEY_UP))
520
-        {
450
+        if ((super.buttons_new & KEY_UP) || (super.buttons_held & KEY_UP)) {
521 451
             pdex_try_advance(true);
522 452
         }
523 453
         break;
@@ -540,43 +470,12 @@ void pdex_loop(u8 tid) {
540 470
     }
541 471
 }
542 472
 
543
-bool sm_pdex_init(void) {
544
-    if (pal_fade_control.active)
545
-        return false;
546
-    audioDampenMaybe();
547
-    sav1_secure_increment(0x29); // this is something the original dex routine does, probably for statistics
548
-    /* maybe clean up safari stuff here if necessary */
549
-    overworld_free_bgmaps();
550
-    set_callback2(pdex_load);
551
-    return true;
552
-}
553
-
554
-void pdex_vram_setup(void) {
555
-    vblank_handler_set(NULL);
556
-    pal_fade_control_and_dead_struct_reset();
557
-    gpu_tile_bg_drop_all_sets(true);
558
-    obj_and_aux_reset_all();
559
-    gpu_tile_obj_tags_reset();
560
-    gpu_pal_allocator_reset();
561
-    rboxes_free();
562
-    malloc_init((void *)0x2000000, 0x1C000);
563
-    tasks_init();
564
-
565
-    bg_vram_setup(0, &pdex_bg_config[0], 4);
566
-
567
-    u8 *bgMap = malloc(0x800);
568
-    u8 *strMap = malloc(0x800);
569
-    bgid_set_tilemap(2, bgMap);
570
-    bgid_set_tilemap(0, strMap);
571
-    bgid_mark_for_sync(0);
572
-
473
+void pdex_load_gfx(void) {
573 474
     /*TODO: setup text boxes here */
574 475
     rbox_init_from_templates(&pdex_boxes[0]);
575
-    u32 set = 0;
576
-    CpuFastSet((void *)&set, (void *)0x06000000, CPUModeFS(0x10000, CPUFSSET));
577 476
 
578 477
     lz77UnCompVram(pdexBgTiles, (void *)0x0600C000);
579
-    LZ77UnCompWram(pdexBgMap, bgMap);
478
+    LZ77UnCompWram(pdexBgMap, bgid_get_tilemap(2));
580 479
     gpu_pal_apply_compressed(pdexBgPal, 0, 32);
581 480
     gpu_pal_apply(pdex_text_pal, 15 * 16, 32);
582 481
 
@@ -585,43 +484,16 @@ void pdex_vram_setup(void) {
585 484
     lcd_io_set(REG_ID_WIN0V, ((20 << 8) | (148)));
586 485
     lcd_io_set(REG_ID_WININ, WIN_BG0 | WIN_BG1 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
587 486
     lcd_io_set(REG_ID_WINOUT, WIN_BG0 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
588
-
589
-    vblank_handler_set(pdex_vblank_handler);
590
-    interrupts_enable(INTERRUPT_VBLANK);
591
-    bgid_mod_x_offset(0, 0, 0);
592
-    bgid_mod_y_offset(0, 0, 0);
593
-    bgid_mod_x_offset(1, 0, 0);
594
-    bgid_mod_y_offset(1, 0, 0);
595
-    bgid_mod_x_offset(2, 0, 0);
596
-    bgid_mod_y_offset(2, 0, 0);
597
-    bgid_mod_x_offset(3, 0, 0);
598
-    bgid_mod_y_offset(3, 0, 0);
487
+    bgid_mark_for_sync(0);
599 488
 }
600 489
 
601 490
 void pdex_load(void) {
602 491
 
603 492
     pdex_vram_setup();
604
-    pokedex_context = malloc_and_clear(sizeof(struct PdexCtx));
493
+    pdex_load_gfx();
494
+
605 495
     pokedex_context->pokemon_oam = -1;
606
-    pokedex_context->lookup = malloc_and_clear((PDEX_LAST_SHOWN + 1) * sizeof(struct PdexLookup));
496
+
607 497
     task_add(pdex_loop, 0);
608 498
     set_callback2(pdex_cb_handler);
609
-}
610
-
611
-void pdex_vblank_handler(void) {
612
-    gpu_sprites_upload();
613
-    copy_queue_process();
614
-    gpu_pal_upload();
615
-}
616
-
617
-void pdex_cb_handler(void) {
618
-    if (pal_fade_control.active)
619
-        process_palfade();
620
-    else {
621
-        task_exec();
622
-        objc_exec();
623
-        obj_sync_superstate();
624
-        tilemaps_sync();
625
-        remoboxes_upload_tilesets();
626
-    }
627 499
 }

+ 100
- 0
src/pokedex/pokedex_common.c Datei anzeigen

@@ -0,0 +1,100 @@
1
+#include <pokeagb/pokeagb.h>
2
+#include "pokedex_common.h"
3
+
4
+const u16 pdex_text_pal[] = {rgb5(255, 0, 255), rgb5(255, 255, 255), rgb5(0, 0, 0),     rgb5(255, 0, 255),
5
+                             rgb5(255, 0, 255), rgb5(255, 0, 255),   rgb5(255, 0, 255), rgb5(255, 0, 255),
6
+                             rgb5(255, 0, 255), rgb5(255, 0, 255),   rgb5(255, 0, 255), rgb5(255, 0, 255),
7
+                             rgb5(255, 0, 255), rgb5(255, 0, 255),   rgb5(255, 0, 255), rgb5(255, 0, 255)};
8
+
9
+const struct BgConfig pdex_bg_config[4] = {
10
+    {
11
+        .padding = 0,
12
+        .b_padding = 0,
13
+        .priority = 0,
14
+        .palette = 0,
15
+        .size = 0,
16
+        .map_base = 29,
17
+        .character_base = 0,
18
+        .bgid = 0,
19
+    },
20
+    {
21
+        .padding = 0,
22
+        .b_padding = 0,
23
+        .priority = 1,
24
+        .palette = 0,
25
+        .size = 0,
26
+        .map_base = 28,
27
+        .character_base = 0,
28
+        .bgid = 1,
29
+    },
30
+    {
31
+        .padding = 0,
32
+        .b_padding = 0,
33
+        .priority = 2,
34
+        .palette = 0,
35
+        .size = 0,
36
+        .map_base = 30,
37
+        .character_base = 3,
38
+        .bgid = 2,
39
+    },
40
+    {
41
+        .padding = 0,
42
+        .b_padding = 0,
43
+        .priority = 3,
44
+        .palette = 0,
45
+        .size = 1,
46
+        .map_base = 31,
47
+        .character_base = 3,
48
+        .bgid = 3,
49
+    },
50
+};
51
+
52
+struct TextColor pdex_text_color = {0, 1, 2};
53
+
54
+void pdex_vblank_handler(void) {
55
+    gpu_sprites_upload();
56
+    copy_queue_process();
57
+    gpu_pal_upload();
58
+}
59
+
60
+void pdex_cb_handler(void) {
61
+    if (pal_fade_control.active)
62
+        process_palfade();
63
+    else {
64
+        task_exec();
65
+        objc_exec();
66
+        obj_sync_superstate();
67
+        tilemaps_sync();
68
+        remoboxes_upload_tilesets();
69
+    }
70
+}
71
+
72
+void pdex_vram_setup(void) {
73
+    vblank_handler_set(NULL);
74
+    pal_fade_control_and_dead_struct_reset();
75
+    gpu_tile_bg_drop_all_sets(true);
76
+    obj_and_aux_reset_all();
77
+    gpu_tile_obj_tags_reset();
78
+    gpu_pal_allocator_reset();
79
+    rboxes_free();
80
+    tasks_init();
81
+    bg_vram_setup(0, &pdex_bg_config[0], 4);
82
+    u32 set = 0;
83
+    CpuFastSet((void *)&set, (void *)0x06000000, CPUModeFS(0x10000, CPUFSSET));
84
+
85
+    bgid_mod_x_offset(0, 0, 0);
86
+    bgid_mod_y_offset(0, 0, 0);
87
+    bgid_mod_x_offset(1, 0, 0);
88
+    bgid_mod_y_offset(1, 0, 0);
89
+    bgid_mod_x_offset(2, 0, 0);
90
+    bgid_mod_y_offset(2, 0, 0);
91
+    bgid_mod_x_offset(3, 0, 0);
92
+    bgid_mod_y_offset(3, 0, 0);
93
+
94
+    vblank_handler_set(pdex_vblank_handler);
95
+    interrupts_enable(INTERRUPT_VBLANK);
96
+
97
+    u8 *bgMap = malloc(0x800);
98
+    bgid_set_tilemap(2, bgMap);
99
+    
100
+}

+ 40
- 0
src/pokedex/pokedex_common.h Datei anzeigen

@@ -0,0 +1,40 @@
1
+#ifndef PDEX_C_H_
2
+#define PDEX_C_H_
3
+
4
+#include <pokeagb/pokeagb.h>
5
+
6
+#define CPUFSCPY 0
7
+#define CPUFSSET 1
8
+#define CPUModeFS(size, mode) ((size >> 2) | (mode << 24))
9
+#define MAX3_COUNT_DIGITS(n) (n >= 100 ? 3 : (n >= 10 ? 2 : 1))
10
+
11
+#define OBJID_HIDE(objid) objects[objid].final_oam.affine_mode = 2
12
+#define OBJID_SHOW(objid) objects[objid].final_oam.affine_mode = 0
13
+
14
+#define PDEX_FADEIN_SPD 1
15
+
16
+#define FONT_DEX_STD 1
17
+
18
+#define TB_STD_CENTER(t) (((TB_STD_LEN_PX - t) >> 1) + 2)
19
+#define TB_STD_RIGHT(t) ((TB_BOT_LEN_PX - t))
20
+
21
+#define DEX_PKMN_TAG 0x1300
22
+#define DEX_BALL_TAG 0x1301
23
+#define DEX_CURSOR_TAG 0x1302
24
+#define DEX_ARROW_TAG 0x1303
25
+#define DEX_ARROW_TAG_EPAL 0x1304
26
+#define DEX_SCROLL_TAG 0x1305
27
+#define DEX_REGION_SELECT 0x1306
28
+
29
+#define DEX_REGION_PAL(i) (0x1307 + i)
30
+#define DEX_REGION_ICON(i) (0x1307 + i)
31
+
32
+void pdex_cb_handler(void);
33
+void pdex_vblank_handler(void);
34
+void pdex_vram_setup(void);
35
+
36
+const u16 pdex_text_pal[16];
37
+const struct BgConfig pdex_bg_config[4];
38
+struct TextColor pdex_text_color;
39
+
40
+#endif

+ 194
- 0
src/pokedex/pokedex_region.c Datei anzeigen

@@ -0,0 +1,194 @@
1
+#include <agb_debug.h>
2
+#include <constants/pkmns.h>
3
+#include <pokeagb/pokeagb.h>
4
+#include <pokedex/pdexSelectBg.h>
5
+#include <pokedex/pdexSelectRegion.h>
6
+
7
+#include "pokedex_common.h"
8
+
9
+void region_select_load(void);
10
+extern const pchar *pdex_str_regions[];
11
+extern const pchar *pdex_str_empty;
12
+
13
+struct TextboxTemplate region_select_boxes[] = {
14
+    {.bg_id = 0, .x = 4, .y = 7, .width = 6, .height = 3, .pal_id = 15, .charbase = 1},
15
+    {.bg_id = 0, .x = 13, .y = 7, .width = 6, .height = 3, .pal_id = 15, .charbase = 19},
16
+    {.bg_id = 0, .x = 22, .y = 7, .width = 6, .height = 3, .pal_id = 15, .charbase = 38},
17
+
18
+    {.bg_id = 0, .x = 2, .y = 17, .width = 6, .height = 2, .pal_id = 15, .charbase = 57},
19
+    {.bg_id = 0, .x = 9, .y = 17, .width = 6, .height = 2, .pal_id = 15, .charbase = 69},
20
+    {.bg_id = 0, .x = 17, .y = 17, .width = 6, .height = 2, .pal_id = 15, .charbase = 81},
21
+    {.bg_id = 0, .x = 24, .y = 17, .width = 6, .height = 2, .pal_id = 15, .charbase = 93},
22
+
23
+    {.bg_id = 0xFF},
24
+};
25
+
26
+u8 region_text_x_offset[] = {2, 4, 2, 1, 5, 1, 4};
27
+u8 region_text_y_offset[] = {7, 7, 7, 2, 2, 2, 2};
28
+u8 region_select_x_offset[] = {54, 128, 198, 38, 97, 156, 215};
29
+u8 region_select_y_offset[] = {40, 40, 40, 115, 115, 115, 115};
30
+
31
+u16 region_icons[] = {PKMN_BISASAM,   PKMN_SCHIGGY,  PKMN_GLUMANDA, PKMN_ENDIVIE, PKMN_KARNIMANI, PKMN_FEURIGEL,
32
+                     PKMN_GECKARBOR, PKMN_HYDROPI, PKMN_FLEMMLI,  PKMN_CHELAST, PKMN_PLINFA,    PKMN_PANFLAM,
33
+                     PKMN_SERPIFEU,  PKMN_OTTARO,  PKMN_FLOINK,   PKMN_IGAMARO, PKMN_FROXY,     PKMN_FYNX,
34
+                     PKMN_BAUZ,      PKMN_ROBBALL, PKMN_FLAMIAU};
35
+
36
+u16 region_icons_x_offset[] = {37, 49, 58, 110, 122, 133, 183, 193, 206, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120};
37
+
38
+u16 region_icons_y_offset[] = {39,  17,  39, 39,  19,  39, 39,  19,  39, 100, 90,
39
+                              100, 100, 90, 100, 100, 90, 100, 100, 90, 100};
40
+
41
+bool sm_pdex_init(void) {
42
+    if (pal_fade_control.active)
43
+        return false;
44
+    audioDampenMaybe();
45
+    sav1_secure_increment(0x29); // this is something the original dex routine does, probably for statistics
46
+    /* maybe clean up safari stuff here if necessary */
47
+    overworld_free_bgmaps();
48
+
49
+    malloc_init((void *)0x2000000, 0x1C000);
50
+    set_callback2(region_select_load);
51
+    return true;
52
+}
53
+
54
+void region_select_load_gfx() {
55
+    rbox_init_from_templates(&region_select_boxes[0]);
56
+    lz77UnCompVram(pdexSelectBgTiles, (void *)0x0600C000);
57
+    LZ77UnCompWram(pdexSelectBgMap, bgid_get_tilemap(2));
58
+    gpu_pal_apply_compressed(pdexSelectBgPal, 0, 32);
59
+    gpu_pal_apply(pdex_text_pal, 15 * 16, 32);
60
+    bgid_mark_for_sync(0);
61
+}
62
+
63
+void region_oac_select(struct Object *obj) {
64
+    obj->pos1.x = region_select_x_offset[pokedex_context->region_selected];
65
+    obj->pos1.y = region_select_y_offset[pokedex_context->region_selected];
66
+}
67
+
68
+struct SpriteTiles region_select_tiles = {pdexSelectRegionTiles, 2048, DEX_REGION_SELECT};
69
+struct SpritePalette region_select_pal = {pdexSelectRegionPal, DEX_REGION_SELECT};
70
+
71
+const struct OamData region_select_oam = {
72
+    .affine_mode = 0,
73
+    .obj_mode = 0,
74
+    .mosaic = false,
75
+    .shape = 0,
76
+    .size = 3,
77
+};
78
+
79
+struct Template region_select_template = {
80
+    .tiles_tag = DEX_REGION_SELECT,
81
+    .pal_tag = DEX_REGION_SELECT,
82
+    .oam = &region_select_oam,
83
+    .animation = &anim_image_empty,
84
+    .graphics = &region_select_tiles,
85
+    .rotscale = &rotscale_empty,
86
+    .callback = region_oac_select,
87
+};
88
+
89
+void region_load_icon_palettes(void) {
90
+    for (u8 i = 0; i < 3; ++i) {
91
+        struct SpritePalette current = {pokeicon_pals[i], DEX_REGION_PAL(i)};
92
+        gpu_pal_obj_alloc_tag_and_apply(&current);
93
+    }
94
+}
95
+
96
+const struct OamData region_icon_oam = {
97
+    .affine_mode = 0,
98
+    .obj_mode = 0,
99
+    .mosaic = false,
100
+    .shape = 0,
101
+    .size = 2,
102
+};
103
+
104
+void region_load_icon(u8 i) {
105
+    struct SpriteTiles current = {pokeicon_table[region_icons[i]], 512, DEX_REGION_ICON(i)};
106
+    gpu_tile_obj_alloc_tag_and_upload(&current);
107
+    struct Template region_icon_template = {
108
+        .tiles_tag = DEX_REGION_ICON(i),
109
+        .pal_tag = DEX_REGION_PAL(pokeicon_pal_indices[region_icons[i]]),
110
+        .oam = &region_icon_oam,
111
+        .animation = &anim_image_empty,
112
+        .graphics = &current,
113
+        .rotscale = &rotscale_empty,
114
+        .callback = oac_nullsub,
115
+    };
116
+    template_instanciate_forward_search(&region_icon_template, region_icons_x_offset[i], region_icons_y_offset[i], 0);
117
+}
118
+
119
+void region_load_border() {
120
+    gpu_tile_obj_decompress_alloc_tag_and_upload(&region_select_tiles);
121
+    gpu_pal_obj_alloc_tag_and_apply(&region_select_pal);
122
+    (void)template_instanciate_forward_search(&region_select_template, 100, 100, 0);
123
+}
124
+
125
+void region_loop(u8 tid) {
126
+    (void)tid;
127
+    switch (pokedex_context->state) {
128
+    case 0:
129
+        bgid_send_tilemap(2);
130
+
131
+        for (u8 i = 0; i < 7; ++i) {
132
+            rboxid_clear_pixels(i, 0);
133
+            rboxid_print(i, FONT_DEX_STD, region_text_x_offset[i], region_text_y_offset[i], &pdex_text_color, 0,
134
+                         pdex_str_regions[i + 1]);
135
+            rboxid_update_tilemap_and_tileset(i);
136
+        }
137
+
138
+        region_load_border();
139
+        region_load_icon_palettes();
140
+        for(u8 i = 0; i < 21; ++i)
141
+            region_load_icon(i);
142
+        
143
+        palette_bg_faded_fill_black();
144
+        pokedex_context->state++;
145
+        break;
146
+    case 1:
147
+        gpu_sync_bg_show(0);
148
+        gpu_sync_bg_hide(1);
149
+        gpu_sync_bg_hide(3);
150
+
151
+        gpu_sync_bg_show(2);
152
+        fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 16, 0, 0x0000);
153
+        pokedex_context->state++;
154
+        break;
155
+    case 2:
156
+        if (!pal_fade_control.active)
157
+            pokedex_context->state++;
158
+        break;
159
+    case 3:
160
+        switch (super.buttons_new) {
161
+        case KEY_RIGHT:
162
+            if (pokedex_context->region_selected < 6)
163
+                pokedex_context->region_selected++;
164
+            break;
165
+        case KEY_DOWN:
166
+            if (pokedex_context->region_selected < 3)
167
+                pokedex_context->region_selected += 3;
168
+            break;
169
+        case KEY_LEFT:
170
+            if (pokedex_context->region_selected > 0)
171
+                pokedex_context->region_selected--;
172
+            break;
173
+        case KEY_UP:
174
+            if ((pokedex_context->region_selected > 2) && (pokedex_context->region_selected < 6))
175
+                pokedex_context->region_selected -= 3;
176
+            break;
177
+        default:
178
+            break;
179
+        }
180
+        break;
181
+    default:
182
+        break;
183
+    }
184
+}
185
+
186
+void region_select_load(void) {
187
+    pdex_vram_setup();
188
+
189
+    pokedex_context = malloc_and_clear(sizeof(struct PdexCtx));
190
+
191
+    region_select_load_gfx();
192
+    task_add(region_loop, 0);
193
+    set_callback2(pdex_cb_handler);
194
+}

+ 40
- 1
src/pokedex/pokedex_string.s Datei anzeigen

@@ -19,4 +19,43 @@ pdex_str_caught:
19 19
 .global pdex_str_empty
20 20
 pdex_str_empty:
21 21
     .string LAN_DE "----------"
22
-    .string LAN_EN "----------"
22
+    .string LAN_EN "----------"
23
+
24
+.global pdex_str_regions
25
+pdex_str_regions:
26
+.word pdex_str_empty
27
+.word pdex_str_kanto
28
+.word pdex_str_jotho
29
+.word pdex_str_hoeen
30
+.word pdex_str_sinnoh
31
+.word pdex_str_unova
32
+.word pdex_str_kalos
33
+.word pdex_str_alola
34
+
35
+pdex_str_kanto:
36
+    .string LAN_DE "Kanto"
37
+    .string LAN_EN "Kanto"
38
+
39
+pdex_str_jotho:
40
+    .string LAN_DE "Johto"
41
+    .string LAN_EN "Johto"
42
+
43
+pdex_str_hoeen:
44
+    .string LAN_DE "Hoenn"
45
+    .string LAN_EN "Hoenn"
46
+
47
+pdex_str_sinnoh:
48
+    .string LAN_DE "Sinnoh"
49
+    .string LAN_EN "Sinnoh"
50
+
51
+pdex_str_unova:
52
+    .string LAN_DE "Einall"
53
+    .string LAN_EN " Unova"
54
+
55
+pdex_str_kalos:
56
+    .string LAN_DE "Kalos"
57
+    .string LAN_EN "Kalos"
58
+
59
+pdex_str_alola:
60
+    .string LAN_DE "Alola"
61
+    .string LAN_EN "Alola"