浏览代码

first part of detail screen done, intercon restored, resolves #22

SBird1337 6 年前
父节点
当前提交
719d13d14b
共有 6 个文件被更改,包括 101 次插入10 次删除
  1. 1
    1
      g3headers
  2. 4
    4
      src/pokedex/pokedex.c
  3. 7
    0
      src/pokedex/pokedex_common.c
  4. 4
    0
      src/pokedex/pokedex_common.h
  5. 84
    1
      src/pokedex/pokedex_detail.c
  6. 1
    4
      src/pokedex/pokedex_region.c

+ 1
- 1
g3headers

@@ -1 +1 @@
1
-Subproject commit 6199a23e667a6645d3ebc0b76517ec869941246a
1
+Subproject commit ee7c8b28b58f61df864f7716c7ee9bbae82f5411

+ 4
- 4
src/pokedex/pokedex.c 查看文件

@@ -457,10 +457,9 @@ void pdex_loop(u8 tid) {
457 457
         if (!pal_fade_control.active) {
458 458
             task_del(tid);
459 459
             pdex_vram_free_bgmaps();
460
-            free(pokedex_context->lookup);
461
-            free(pokedex_context);
462
-            set_callback2(c2_overworld_switch_start_menu);
463
-            set_callback1(c1_overworld);
460
+            pdex_free_memory();
461
+            void region_select_load(void);
462
+            set_callback2(region_select_load);
464 463
         }
465 464
         break;
466 465
     case 15:
@@ -505,6 +504,7 @@ void pdex_load(void) {
505 504
 
506 505
     pokedex_context->pokemon_oam = -1;
507 506
     pokedex_context->state = 0;
507
+    pokedex_context->hardware_scroll_amount = 0;
508 508
     task_add(pdex_loop, 0);
509 509
     set_callback2(pdex_cb_handler);
510 510
 }

+ 7
- 0
src/pokedex/pokedex_common.c 查看文件

@@ -97,6 +97,13 @@ void pdex_vram_free_bgmaps(void) {
97 97
     }
98 98
 }
99 99
 
100
+void pdex_free_memory(void)
101
+{
102
+    if(pokedex_context->lookup != NULL)
103
+        free(pokedex_context->lookup);
104
+    free(pokedex_context);
105
+}
106
+
100 107
 void pdex_vram_allocate_bgmaps(void) {
101 108
     bgid_set_tilemap(0, malloc(0x800));
102 109
     bgid_set_tilemap(1, malloc(0x800));

+ 4
- 0
src/pokedex/pokedex_common.h 查看文件

@@ -30,6 +30,9 @@
30 30
 #define DEX_ARROW_TAG_EPAL 0x1304
31 31
 #define DEX_SCROLL_TAG 0x1305
32 32
 #define DEX_REGION_SELECT 0x1306
33
+#define DEX_DETAIL_TYPE1 0x130E
34
+#define DEX_DETAIL_TYPE2 0x130F
35
+#define DEX_DETAIL_TYPEPAL 0x130E
33 36
 
34 37
 #define DEX_REGION_PAL(i) (0x1307 + i)
35 38
 #define DEX_REGION_ICON(i) (0x1307 + i)
@@ -38,6 +41,7 @@ void pdex_cb_handler(void);
38 41
 void pdex_vblank_handler(void);
39 42
 void pdex_vram_setup(void);
40 43
 void pdex_vram_free_bgmaps(void);
44
+void pdex_free_memory(void);
41 45
 
42 46
 void pdex_load(void);
43 47
 

+ 84
- 1
src/pokedex/pokedex_detail.c 查看文件

@@ -26,6 +26,42 @@ struct TextboxTemplate dexdetail_boxes[] = {
26 26
     {.bg_id = 0xFF},
27 27
 };
28 28
 
29
+u8 dexdetail_type_to_oam_type[18] = {0, 9, 8, 12, 6, 5, 11, 10, 14, 17, 1, 2, 3,4, 13, 7, 16, 15};
30
+
31
+#define O_TYPE(t) (dexdetail_type_to_oam_type[t])
32
+
33
+struct OamData dexdetail_type_oam = {
34
+    .affine_mode = 0,
35
+    .obj_mode = 0,
36
+    .mosaic = false,
37
+    .shape = 1,
38
+    .size = 2,
39
+};
40
+
41
+void dexdetail_update_type_oam(u8 type, struct Object *obj) {
42
+    memcpy((void *)((0x06010000) + (obj->final_oam.tile_num * 0x20)),
43
+           pokemon_type_chart_gfx + (128 * O_TYPE(type)) + (512 * (O_TYPE(type) >> 2)), 128);
44
+    memcpy((void *)((0x06010000) + 128 + (obj->final_oam.tile_num * 0x20)),
45
+           pokemon_type_chart_gfx + 512 + (128 * O_TYPE(type)) + (512 * (O_TYPE(type) >> 2)), 128);
46
+}
47
+
48
+s8 dexdetail_load_type_oam(u8 type, u16 tag) {
49
+    struct SpriteTiles typeTiles = {(&pokemon_type_chart_gfx[0]) + 256 * O_TYPE(type), 256, tag};
50
+    gpu_tile_obj_alloc_tag_and_upload(&typeTiles);
51
+    const struct Template typeTemplate = {
52
+        .tiles_tag = tag,
53
+        .pal_tag = DEX_DETAIL_TYPEPAL,
54
+        .oam = &dexdetail_type_oam,
55
+        .animation = &anim_image_empty,
56
+        .graphics = &typeTiles,
57
+        .rotscale = &rotscale_empty,
58
+        .callback = oac_nullsub,
59
+    };
60
+    s8 id = (s8)template_instanciate_forward_search(&typeTemplate, 100, 100, 0);
61
+    dexdetail_update_type_oam(type, &objects[id]);
62
+    return id;
63
+}
64
+
29 65
 void dexdetail_load_pokemon(u16 dexindex) {
30 66
     u16 species = pokedex_context->lookup[dexindex].species;
31 67
     rboxid_clear_pixels(TB_PKNAME, 0);
@@ -91,6 +127,31 @@ void dexdetail_load_pokemon(u16 dexindex) {
91 127
         objects[pokedex_context->detail_pokemon_oam].pos1.y = 55;
92 128
     }
93 129
 
130
+    // draw the first type icon
131
+    if (pokedex_context->detail_type_oam[0] != -1) {
132
+        dexdetail_update_type_oam(pokemon_base_stats[species].type[0], &objects[pokedex_context->detail_type_oam[0]]);
133
+    } else {
134
+        pokedex_context->detail_type_oam[0] =
135
+            dexdetail_load_type_oam(pokemon_base_stats[species].type[0], DEX_DETAIL_TYPE1);
136
+        objects[pokedex_context->detail_type_oam[0]].pos1.x = 156;
137
+        objects[pokedex_context->detail_type_oam[0]].pos1.y = 80;
138
+    }
139
+    // draw the second type icon eventually
140
+    if (pokemon_base_stats[species].type[0] != pokemon_base_stats[species].type[1]) {
141
+        if (pokedex_context->detail_type_oam[1] != -1) {
142
+            dexdetail_update_type_oam(pokemon_base_stats[species].type[1],
143
+                                      &objects[pokedex_context->detail_type_oam[1]]);
144
+        } else {
145
+            pokedex_context->detail_type_oam[1] =
146
+                dexdetail_load_type_oam(pokemon_base_stats[species].type[1], DEX_DETAIL_TYPE2);
147
+            objects[pokedex_context->detail_type_oam[1]].pos1.x = 210;
148
+            objects[pokedex_context->detail_type_oam[1]].pos1.y = 80;
149
+        }
150
+        OBJID_SHOW(pokedex_context->detail_type_oam[1]);
151
+    } else {
152
+        OBJID_HIDE(pokedex_context->detail_type_oam[1]);
153
+    }
154
+
94 155
     rboxid_update_tilemap_and_tileset(TB_DESC);
95 156
     rboxid_update_tilemap_and_tileset(TB_PKNAME);
96 157
     rboxid_update_tilemap_and_tileset(TB_PKSIZE);
@@ -102,7 +163,6 @@ void dexdetail_loop(u8 tid) {
102 163
     case 0:
103 164
         bgid_send_tilemap(2);
104 165
         dexdetail_load_pokemon(pokedex_context->cursor_position_top + pokedex_context->cursor_position_internal);
105
-
106 166
         palette_bg_faded_fill_black();
107 167
         pokedex_context->state++;
108 168
         break;
@@ -115,17 +175,38 @@ void dexdetail_loop(u8 tid) {
115 175
         fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 16, 0, 0x0000);
116 176
         pokedex_context->state++;
117 177
         break;
178
+    case 2:
179
+        switch (super.buttons_new) {
180
+        case KEY_B:
181
+            pokedex_context->state = 12;
182
+            pokedex_context->cursor_position_top =
183
+                pokedex_context->cursor_position_top + pokedex_context->cursor_position_internal;
184
+            pokedex_context->cursor_position_internal = 0;
185
+            fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 0, 16, 0x0000);
186
+            break;
187
+        }
188
+        break;
189
+    case 12:
190
+        if (!pal_fade_control.active) {
191
+            task_del(tid);
192
+            pdex_vram_free_bgmaps();
193
+            set_callback2(pdex_load);
194
+        }
195
+        break;
118 196
     default:
119 197
         break;
120 198
     }
121 199
 }
122 200
 
201
+struct SpritePalette dexdetail_type_pal = {&pokemon_type_chart_pal[0], DEX_DETAIL_TYPEPAL};
202
+
123 203
 void dexdetail_load_gfx(void) {
124 204
     rbox_init_from_templates(&dexdetail_boxes[0]);
125 205
     lz77UnCompVram(pdexDetailBgTiles, (void *)0x0600C000);
126 206
     LZ77UnCompWram(pdexDetailBgMap, bgid_get_tilemap(2));
127 207
     gpu_pal_apply_compressed(pdexDetailBgPal, 0, 32);
128 208
     gpu_pal_apply(pdex_text_pal, 15 * 16, 32);
209
+    gpu_pal_obj_alloc_tag_and_apply(&dexdetail_type_pal);
129 210
 
130 211
     lcd_io_set(REG_ID_WIN0H, (8 << 8) | (232));
131 212
     lcd_io_set(REG_ID_WIN0V, ((100 << 8) | (160)));
@@ -140,6 +221,8 @@ void dexdetail_load(void) {
140 221
     dexdetail_load_gfx();
141 222
     pokedex_context->state = 0;
142 223
     pokedex_context->detail_pokemon_oam = -1;
224
+    pokedex_context->detail_type_oam[0] = -1;
225
+    pokedex_context->detail_type_oam[1] = -1;
143 226
     task_add(dexdetail_loop, 0);
144 227
     set_callback2(pdex_cb_handler);
145 228
 }

+ 1
- 4
src/pokedex/pokedex_region.c 查看文件

@@ -210,9 +210,7 @@ void region_loop(u8 tid) {
210 210
     case 11:
211 211
         if (!pal_fade_control.active) {
212 212
             task_del(tid);
213
-            if(pokedex_context->lookup != NULL)
214
-                free(pokedex_context->lookup);
215
-            free(pokedex_context);
213
+            pdex_free_memory();
216 214
             set_callback2(c2_overworld_switch_start_menu);
217 215
             set_callback1(c1_overworld);
218 216
         }
@@ -225,7 +223,6 @@ void region_loop(u8 tid) {
225 223
 
226 224
 void region_select_load(void) {
227 225
     pdex_vram_setup();
228
-
229 226
     pokedex_context = malloc_and_clear(sizeof(struct PdexCtx));
230 227
 
231 228
     region_select_load_gfx();