Переглянути джерело

update scrolling speed of pokedex, resolves #19

SBird1337 6 роки тому
джерело
коміт
bd963f9ca6

+ 1
- 1
g3headers

@@ -1 +1 @@
1
-Subproject commit e0402c99b51968537abb0f09ed017558e2055385
1
+Subproject commit 98ab5bcce4025410bc8ba8ffac90c12480dffeb2

+ 519
- 0
src/pokedex/pokedex.c Переглянути файл

@@ -0,0 +1,519 @@
1
+#include <agb_debug.h>
2
+#include <constants/pkmns.h>
3
+#include <pokeagb/pokeagb.h>
4
+#include <pokedex/pdexArrow.h>
5
+#include <pokedex/pdexBall.h>
6
+#include <pokedex/pdexBg.h>
7
+#include <pokedex/pdexScrollBar.h>
8
+#include <pokedex/pdexSelectHalf.h>
9
+
10
+#include "pokedex_common.h"
11
+
12
+#define TB_TITLE 0
13
+#define TB_PKMN 1
14
+#define TB_SEEN 2
15
+#define TB_CAUGHT 3
16
+#define TB_MAIN 4
17
+
18
+#define TB_SEEN_Y (6)
19
+#define TB_CAUGHT_Y 3
20
+
21
+#define DEX_SCROLL_MIN 23
22
+#define DEX_SCROLL_MAX 146
23
+#define SCROLL_SPEED_MAX 6
24
+
25
+void pdex_load(void);
26
+void pdex_vblank_handler(void);
27
+void pdex_loop(u8 tid);
28
+void pdex_cb_handler(void);
29
+
30
+extern const pchar pdex_str_title[];
31
+extern const pchar pdex_str_seen[];
32
+extern const pchar pdex_str_caught[];
33
+extern const pchar pdex_str_empty[];
34
+
35
+static const u8 pdex_y_offset[] = {19, 35, 51, 67, 83, 99, 115, 131};
36
+static const u16 scroll_speed_delays[] = {20, 20, 20, 20,10, 5, 0};
37
+
38
+struct TextboxTemplate pdex_boxes[] = {
39
+    {.bg_id = 0, .x = 11, .y = 0, .width = 10, .height = 2, .pal_id = 15, .charbase = 1},
40
+    {.bg_id = 0, .x = 2, .y = 2, .width = 10, .height = 2, .pal_id = 15, .charbase = 21},
41
+    {.bg_id = 0, .x = 3, .y = 13, .width = 9, .height = 3, .pal_id = 15, .charbase = 41},
42
+    {.bg_id = 0, .x = 3, .y = 16, .width = 9, .height = 2, .pal_id = 15, .charbase = 59},
43
+
44
+    {.bg_id = 1, .x = 16, .y = 0, .width = 11, .height = 32, .pal_id = 15, .charbase = 77},
45
+
46
+    {.bg_id = 0xFF},
47
+};
48
+
49
+s16 pdex_get_y_offset(s8 n) {
50
+    s8 modOffset = n + pokedex_context->hardware_scroll_amount;
51
+    dprintf("mod_offset: %d\n", modOffset);
52
+    if (modOffset < -1) {
53
+        modOffset += 16;
54
+    }
55
+
56
+    if (modOffset > 14) {
57
+        modOffset -= 16;
58
+    }
59
+    return (19 + (16 * modOffset));
60
+}
61
+
62
+void pdex_main_box_species_fill(s8 n, u16 species, bool seen, bool caught) {
63
+    seen = true;
64
+    s16 y = pdex_get_y_offset(n);
65
+    dprintf("trying to print box to y: %d\n", y);
66
+    rboxid_fill_rectangle(TB_MAIN, 0, 0, y, 11 * 8, 16);
67
+    const pchar *stringToPrint = (seen || caught) ? &pokemon_names[species][0] : &pdex_str_empty[0];
68
+    const pchar stringWhitespace[] = {0x0, 0xFF};
69
+    fmt_int_10(string_buffer, pokedex_context->cursor_position_top + n, 2, 3);
70
+    pstrcat(string_buffer, &stringWhitespace[0]);
71
+    pstrcat(string_buffer, stringToPrint);
72
+    rboxid_print(TB_MAIN, FONT_DEX_STD, 4, y, &pdex_text_color, 0, string_buffer);
73
+}
74
+
75
+void pdex_update_balls(void) {
76
+    for (u8 i = 0; i < 8; ++i) {
77
+        if (pdex_lazy_lookup_entry(i + pokedex_context->cursor_position_top)->caught)
78
+            OBJID_SHOW(pokedex_context->ball_oams[i]);
79
+        else
80
+            OBJID_HIDE(pokedex_context->ball_oams[i]);
81
+    }
82
+}
83
+
84
+void pdex_update_page_full() {
85
+    rboxid_clear_pixels(TB_MAIN, 0);
86
+    for (u16 i = pokedex_context->cursor_position_top; i < pokedex_context->cursor_position_top + 8; ++i) {
87
+        pdex_main_box_species_fill(i - pokedex_context->cursor_position_top, pdex_lazy_lookup_entry(i)->species,
88
+                                   pdex_lazy_lookup_entry(i)->seen, pdex_lazy_lookup_entry(i)->caught);
89
+    }
90
+    pdex_update_balls();
91
+    rboxid_update_tilemap_and_tileset(TB_MAIN);
92
+}
93
+
94
+void pdex_load_sc(void) {
95
+    rboxid_clear_pixels(TB_SEEN, 0);
96
+    rboxid_clear_pixels(TB_CAUGHT, 0);
97
+    u32 seen = pokedex_count(false) + 10;
98
+    u32 caught = pokedex_count(true);
99
+    pchar seenBuffer[4];
100
+    pchar caughtBuffer[4];
101
+    fmt_int_10(seenBuffer, seen, 0, MAX3_COUNT_DIGITS(seen));
102
+    fmt_int_10(caughtBuffer, caught, 0, MAX3_COUNT_DIGITS(caught));
103
+
104
+    u32 twidthSeen = font_get_width_of_string(FONT_DEX_STD, seenBuffer, 0x0000);
105
+    u32 twidthCaught = font_get_width_of_string(FONT_DEX_STD, caughtBuffer, 0x0000);
106
+
107
+    rboxid_print(TB_SEEN, FONT_DEX_STD, 0, TB_SEEN_Y, &pdex_text_color, 0, &pdex_str_seen[0]);
108
+    rboxid_print(TB_CAUGHT, FONT_DEX_STD, 0, TB_CAUGHT_Y, &pdex_text_color, 0, &pdex_str_caught[0]);
109
+
110
+    rboxid_print(TB_SEEN, FONT_DEX_STD, TB_STD_RIGHT(twidthSeen, TB_BOT_LEN_PX), TB_SEEN_Y + 1, &pdex_text_color, 0,
111
+                 seenBuffer);
112
+    rboxid_print(TB_CAUGHT, FONT_DEX_STD, TB_STD_RIGHT(twidthCaught, TB_BOT_LEN_PX), TB_CAUGHT_Y + 1, &pdex_text_color,
113
+                 0, caughtBuffer);
114
+
115
+    rboxid_update_tilemap_and_tileset(TB_SEEN);
116
+    rboxid_update_tilemap_and_tileset(TB_CAUGHT);
117
+}
118
+
119
+void pdex_pokemon_load(u16 species) {
120
+    /* this is very temporary */
121
+    rboxid_clear_pixels(TB_PKMN, 0);
122
+    u32 twidth = font_get_width_of_string(FONT_DEX_STD, &pokemon_names[species][0], 0x0000);
123
+    rboxid_print(TB_PKMN, FONT_DEX_STD, TB_STD_CENTER(twidth, TB_STD_LEN_PX), 3, &pdex_text_color, 0,
124
+                 &pokemon_names[species][0]);
125
+    if (pokedex_context->pokemon_oam != -1) {
126
+        lz77UnCompVram(pokemon_graphics_front[species].data,
127
+                       ((void *)(objects[pokedex_context->pokemon_oam].final_oam.tile_num * 32) + ADDR_VRAM + 0x10000));
128
+        gpu_pal_apply_compressed(pokemon_palette_normal[species].data,
129
+                                 16 * (objects[pokedex_context->pokemon_oam].final_oam.palette_num + 16), 32);
130
+    } else {
131
+        struct SpriteTiles pkmnTiles = {pokemon_graphics_front[species].data, 2048, DEX_PKMN_TAG};
132
+        struct SpritePalette pkmnPal = {pokemon_palette_normal[species].data, DEX_PKMN_TAG};
133
+        const struct Template pkmnTemplate = {
134
+            .tiles_tag = DEX_PKMN_TAG,
135
+            .pal_tag = DEX_PKMN_TAG,
136
+            .oam = &pdex_oam_pkmn,
137
+            .animation = &anim_image_empty,
138
+            .graphics = &pkmnTiles,
139
+            .rotscale = &rotscale_empty,
140
+            .callback = oac_nullsub,
141
+        };
142
+        gpu_tile_obj_decompress_alloc_tag_and_upload(&pkmnTiles);
143
+
144
+        gpu_pal_decompress_alloc_tag_and_upload(&pkmnPal);
145
+        pokedex_context->pokemon_oam = (s8)template_instanciate_forward_search(&pkmnTemplate, 10, 10, 0);
146
+
147
+        objects[pokedex_context->pokemon_oam].pos1.x = 55;
148
+        objects[pokedex_context->pokemon_oam].pos1.y = 76;
149
+    }
150
+    rboxid_update_tilemap_and_tileset(TB_PKMN);
151
+}
152
+
153
+struct SpriteTiles pdex_ball_tiles = {pdexBallTiles, 128, DEX_BALL_TAG};
154
+struct SpritePalette pdex_ball_pal = {pdexBallPal, DEX_BALL_TAG};
155
+const struct OamData pdex_ball_oam = {
156
+    .affine_mode = 0,
157
+    .obj_mode = 0,
158
+    .mosaic = false,
159
+    .shape = 0,
160
+    .size = 1,
161
+};
162
+
163
+const struct Template pdex_ball_template = {
164
+    .tiles_tag = DEX_BALL_TAG,
165
+    .pal_tag = DEX_BALL_TAG,
166
+    .oam = &pdex_ball_oam,
167
+    .animation = &anim_image_empty,
168
+    .graphics = &pdex_ball_tiles,
169
+    .rotscale = &rotscale_empty,
170
+    .callback = oac_nullsub,
171
+};
172
+
173
+void pdex_pokeballs_init(void) {
174
+    gpu_tile_obj_decompress_alloc_tag_and_upload(&pdex_ball_tiles);
175
+    gpu_pal_obj_alloc_tag_and_apply(&pdex_ball_pal);
176
+    for (u8 i = 0; i < 8; ++i) {
177
+        pokedex_context->ball_oams[i] =
178
+            template_instanciate_forward_search(&pdex_ball_template, 124, 8 + pdex_y_offset[i], 1);
179
+    }
180
+}
181
+
182
+void pdex_oac_cursor_follow(struct Object *obj) { obj->pos1.y = objects[pokedex_context->cursor_main_oam].pos1.y; }
183
+
184
+void pdex_oac_cursor_main(struct Object *obj) {
185
+    obj->pos1.y = 13 + pdex_y_offset[pokedex_context->cursor_position_internal];
186
+}
187
+
188
+struct SpriteTiles pdex_cursor_tiles = {pdexSelectHalfTiles, 1024, DEX_CURSOR_TAG};
189
+struct SpritePalette pdex_cursor_pal = {pdexSelectHalfPal, DEX_CURSOR_TAG};
190
+const struct OamData pdex_cursor_oam = {
191
+    .affine_mode = 0,
192
+    .obj_mode = 0,
193
+    .mosaic = false,
194
+    .shape = 1,
195
+    .size = 3,
196
+};
197
+
198
+const struct Template pdex_ball_main_template = {
199
+    .tiles_tag = DEX_CURSOR_TAG,
200
+    .pal_tag = DEX_CURSOR_TAG,
201
+    .oam = &pdex_cursor_oam,
202
+    .animation = &anim_image_empty,
203
+    .graphics = &pdex_cursor_tiles,
204
+    .rotscale = &rotscale_empty,
205
+    .callback = pdex_oac_cursor_main,
206
+};
207
+
208
+const struct Template pdex_ball_follow_template = {
209
+    .tiles_tag = DEX_CURSOR_TAG,
210
+    .pal_tag = DEX_CURSOR_TAG,
211
+    .oam = &pdex_cursor_oam,
212
+    .animation = &anim_image_empty,
213
+    .graphics = &pdex_cursor_tiles,
214
+    .rotscale = &rotscale_empty,
215
+    .callback = pdex_oac_cursor_follow,
216
+};
217
+
218
+void pdex_cursor_init(void) {
219
+    gpu_tile_obj_decompress_alloc_tag_and_upload(&pdex_cursor_tiles);
220
+    gpu_pal_obj_alloc_tag_and_apply(&pdex_cursor_pal);
221
+    pokedex_context->cursor_main_oam = template_instanciate_forward_search(&pdex_ball_main_template, 144, 32, 0);
222
+    pokedex_context->cursor_follow_oam =
223
+        template_instanciate_forward_search(&pdex_ball_follow_template, 144 + 48, 32, 0);
224
+    objects[pokedex_context->cursor_follow_oam].final_oam.h_flip = true;
225
+}
226
+
227
+void pdex_oac_scroll_bar(struct Object *obj) {
228
+    obj->pos1.y = 23 + (((pokedex_context->cursor_position_top + pokedex_context->cursor_position_internal) * 123) /
229
+                        PDEX_LAST_SHOWN);
230
+}
231
+
232
+void pdex_oac_arrow(struct Object *obj) {
233
+    if (obj->priv[0]) {
234
+        // this is the down facing arrow
235
+        if (pokedex_context->cursor_position_top + 8 > PDEX_LAST_SHOWN) {
236
+            obj->final_oam.palette_num = obj->priv[2];
237
+        } else {
238
+            obj->final_oam.palette_num = obj->priv[1];
239
+        }
240
+    } else {
241
+        // this is the up facing arrow
242
+        if (pokedex_context->cursor_position_top == pokedex_context->first_seen) {
243
+            obj->final_oam.palette_num = obj->priv[2];
244
+        } else {
245
+            obj->final_oam.palette_num = obj->priv[1];
246
+        }
247
+    }
248
+}
249
+
250
+struct SpriteTiles pdex_scroll_bar_tiles = {pdexScrollBarTiles, 32, DEX_SCROLL_TAG};
251
+struct SpritePalette pdex_scroll_bar_pal = {pdexScrollBarPal, DEX_SCROLL_TAG};
252
+struct SpriteTiles pdex_arrow_tiles = {pdexArrowTiles, 128, DEX_ARROW_TAG};
253
+struct SpritePalette pdex_arrow_pal = {pdexArrowPal, DEX_ARROW_TAG};
254
+struct SpritePalette pdex_arrow_pal_gray = {pdexArrowPal, DEX_ARROW_TAG_EPAL};
255
+
256
+const struct OamData pdex_scroll_bar_oam = {
257
+    .affine_mode = 0,
258
+    .obj_mode = 0,
259
+    .mosaic = false,
260
+    .shape = 0,
261
+    .size = 0,
262
+};
263
+
264
+const struct OamData pdex_arrow_oam = {
265
+    .affine_mode = 0,
266
+    .obj_mode = 0,
267
+    .mosaic = false,
268
+    .shape = 0,
269
+    .size = 1,
270
+};
271
+
272
+const struct Template pdex_scroll_bar_template = {
273
+    .tiles_tag = DEX_SCROLL_TAG,
274
+    .pal_tag = DEX_SCROLL_TAG,
275
+    .oam = &pdex_scroll_bar_oam,
276
+    .animation = &anim_image_empty,
277
+    .graphics = &pdex_scroll_bar_tiles,
278
+    .rotscale = &rotscale_empty,
279
+    .callback = pdex_oac_scroll_bar,
280
+};
281
+
282
+const struct Template pdex_arrow_template = {
283
+    .tiles_tag = DEX_ARROW_TAG,
284
+    .pal_tag = DEX_ARROW_TAG,
285
+    .oam = &pdex_arrow_oam,
286
+    .animation = &anim_image_empty,
287
+    .graphics = &pdex_arrow_tiles,
288
+    .rotscale = &rotscale_empty,
289
+    .callback = pdex_oac_arrow,
290
+};
291
+
292
+void pdex_load_scroll_ui(void) {
293
+    gpu_tile_obj_decompress_alloc_tag_and_upload(&pdex_scroll_bar_tiles);
294
+    gpu_tile_obj_decompress_alloc_tag_and_upload(&pdex_arrow_tiles);
295
+    gpu_pal_obj_alloc_tag_and_apply(&pdex_scroll_bar_pal);
296
+    u8 normalPal = gpu_pal_obj_alloc_tag_and_apply(&pdex_arrow_pal);
297
+    u8 grayPal = gpu_pal_obj_alloc_tag_and_apply(&pdex_arrow_pal_gray);
298
+    tint_palette_gray(&palette_bg_unfaded[16 * (16 + grayPal)], 16);
299
+    (void)template_instanciate_forward_search(&pdex_scroll_bar_template, 233, 23, 0);
300
+    u8 upArrow = template_instanciate_forward_search(&pdex_arrow_template, 232, 19, 0);
301
+    u8 downArrow = template_instanciate_forward_search(&pdex_arrow_template, 232, 150, 0);
302
+    objects[downArrow].priv[0] = true;
303
+    objects[downArrow].final_oam.v_flip = true;
304
+    objects[upArrow].priv[1] = normalPal;
305
+    objects[downArrow].priv[1] = normalPal;
306
+    objects[upArrow].priv[2] = grayPal;
307
+    objects[downArrow].priv[2] = grayPal;
308
+}
309
+
310
+void pdex_data_setup(void) { pokedex_context->first_seen = 1; }
311
+
312
+void pdex_hardware_scroll(bool up) {
313
+    if (up) {
314
+        if (pokedex_context->hardware_scroll_amount > -15) {
315
+            bgid_mod_y_offset(1, -(16 << 8), 1);
316
+            pokedex_context->hardware_scroll_amount--;
317
+        } else {
318
+            pokedex_context->hardware_scroll_amount = 0;
319
+            bgid_mod_y_offset(1, 0, 0);
320
+        }
321
+    } else {
322
+
323
+        if (pokedex_context->hardware_scroll_amount < 15) {
324
+            bgid_mod_y_offset(1, 16 << 8, 1);
325
+            pokedex_context->hardware_scroll_amount++;
326
+        } else {
327
+            pokedex_context->hardware_scroll_amount = 0;
328
+            bgid_mod_y_offset(1, 0, 0);
329
+        }
330
+    }
331
+}
332
+
333
+void pdex_fill_previous_slot(void) {
334
+    u16 pIndex = pokedex_context->cursor_position_top - 1;
335
+    pdex_main_box_species_fill(-1, pdex_lazy_lookup_entry(pIndex)->species, pdex_lazy_lookup_entry(pIndex)->seen,
336
+                               pdex_lazy_lookup_entry(pIndex)->caught);
337
+}
338
+
339
+void pdex_fill_next_slot(void) {
340
+    u16 pIndex = pokedex_context->cursor_position_top + 8;
341
+    pdex_main_box_species_fill(8, pdex_lazy_lookup_entry(pIndex)->species, pdex_lazy_lookup_entry(pIndex)->seen,
342
+                               pdex_lazy_lookup_entry(pIndex)->caught);
343
+}
344
+
345
+void pdex_try_advance(u8 reverse) {
346
+    if (reverse) {
347
+        if (pokedex_context->cursor_position_internal > 0) {
348
+            pokedex_context->cursor_position_internal--;
349
+            m4aSongNumStart(600);
350
+        } else if ((pokedex_context->cursor_position_top) > (pokedex_context->first_seen)) {
351
+            pdex_fill_previous_slot();
352
+            pokedex_context->cursor_position_top--;
353
+            pdex_hardware_scroll(true);
354
+            m4aSongNumStart(600);
355
+        }
356
+    } else {
357
+        if (pokedex_context->cursor_position_internal < 7) {
358
+            pokedex_context->cursor_position_internal++;
359
+            m4aSongNumStart(600);
360
+        } else if (pokedex_context->cursor_position_top < (PDEX_LAST_SHOWN - 7)) {
361
+            pdex_fill_next_slot();
362
+            pokedex_context->cursor_position_top++;
363
+            pdex_hardware_scroll(false);
364
+            m4aSongNumStart(600);
365
+        }
366
+    }
367
+
368
+    u16 pkIndexToLoad = pokedex_context->cursor_position_internal + pokedex_context->cursor_position_top;
369
+    if (pdex_lazy_lookup_entry(pkIndexToLoad)->seen || pdex_lazy_lookup_entry(pkIndexToLoad)->caught)
370
+        pdex_pokemon_load(pdex_lazy_lookup_entry(pkIndexToLoad)->species);
371
+    else
372
+        pdex_pokemon_load(pdex_lazy_lookup_entry(pkIndexToLoad)->species); /* debug, just display the mofo */
373
+    pdex_update_balls();
374
+}
375
+
376
+void pdex_loop(u8 tid) {
377
+    switch (pokedex_context->state) {
378
+    case 0:
379
+        pokedex_context->state++;
380
+        break;
381
+    case 1:
382
+        for (u8 i = 0; i < 4; ++i)
383
+            bgid_send_tilemap(i);
384
+        rboxid_clear_pixels(TB_TITLE, 0);
385
+        rboxid_print(TB_TITLE, FONT_DEX_STD, 0, 0, &pdex_text_color, 0, &pdex_str_title[0]);
386
+        rboxid_update_tilemap_and_tileset(TB_TITLE);
387
+
388
+        pdex_data_setup();
389
+        pdex_cursor_init();
390
+
391
+        pdex_pokeballs_init();
392
+        pdex_load_scroll_ui();
393
+        pdex_pokemon_load(
394
+            pdex_lazy_lookup_entry(pokedex_context->cursor_position_top + pokedex_context->cursor_position_internal)
395
+                ->species);
396
+        pdex_load_sc();
397
+        pdex_update_page_full();
398
+
399
+        palette_bg_faded_fill_black();
400
+        pokedex_context->state++;
401
+        break;
402
+    case 2:
403
+        gpu_sync_bg_show(0);
404
+        gpu_sync_bg_show(1);
405
+        gpu_sync_bg_hide(3);
406
+
407
+        gpu_sync_bg_show(2);
408
+        fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 16, 0, 0x0000);
409
+        pokedex_context->state++;
410
+
411
+        break;
412
+    case 3:
413
+        if (!pal_fade_control.active)
414
+            pokedex_context->state++;
415
+        break;
416
+    case 4:
417
+        /* main control */
418
+        if (super.buttons_new & KEY_A) {
419
+            pokedex_context->state = 15;
420
+            m4aSongNumStart(5);
421
+        }
422
+        if (super.buttons_new & KEY_B) {
423
+            pokedex_context->state = 10;
424
+            m4aSongNumStart(601);
425
+        }
426
+        if ((super.buttons_new & KEY_DOWN)) {
427
+            pdex_try_advance(false);
428
+            pokedex_context->scroll_speed = 0;
429
+            pokedex_context->delay_count = 0;
430
+        } else if (super.buttons_held & KEY_DOWN) {
431
+            if (pokedex_context->scroll_speed < SCROLL_SPEED_MAX) {
432
+                if (pokedex_context->delay_count >= scroll_speed_delays[pokedex_context->scroll_speed]) {
433
+                    pdex_try_advance(false);
434
+                    pokedex_context->delay_count = 0;
435
+                    pokedex_context->scroll_speed++;
436
+                } else {
437
+                    pokedex_context->delay_count++;
438
+                }
439
+            } else {
440
+                pdex_try_advance(false);
441
+            }
442
+        }
443
+        if ((super.buttons_new & KEY_UP)) {
444
+            pdex_try_advance(true);
445
+            pokedex_context->scroll_speed = 0;
446
+            pokedex_context->delay_count = 0;
447
+        } else if (super.buttons_held & KEY_UP) {
448
+            if (pokedex_context->scroll_speed < SCROLL_SPEED_MAX) {
449
+                if (pokedex_context->delay_count >= scroll_speed_delays[pokedex_context->scroll_speed]) {
450
+                    pdex_try_advance(true);
451
+                    pokedex_context->delay_count = 0;
452
+                    pokedex_context->scroll_speed++;
453
+                } else {
454
+                    pokedex_context->delay_count++;
455
+                }
456
+            } else {
457
+                pdex_try_advance(true);
458
+            }
459
+        }
460
+        break;
461
+    case 10:
462
+        /* control flow exit */
463
+        fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 0, 16, 0x000);
464
+        pokedex_context->state++;
465
+        break;
466
+    case 11:
467
+        if (!pal_fade_control.active) {
468
+            task_del(tid);
469
+            pdex_vram_free_bgmaps();
470
+            pdex_free_memory();
471
+            void region_select_load(void);
472
+            set_callback2(region_select_load);
473
+        }
474
+        break;
475
+    case 15:
476
+        /* load the detail screen */
477
+        fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 0, 16, 0x0000);
478
+        pokedex_context->state++;
479
+        break;
480
+    case 16:
481
+        if (!pal_fade_control.active) {
482
+            pdex_vram_free_bgmaps();
483
+            task_del(tid);
484
+            void dexdetail_load(void);
485
+            set_callback2(dexdetail_load);
486
+        }
487
+    default:
488
+        break;
489
+    }
490
+}
491
+
492
+void pdex_load_gfx(void) {
493
+    /*TODO: setup text boxes here */
494
+    rbox_init_from_templates(&pdex_boxes[0]);
495
+
496
+    lz77UnCompVram(pdexBgTiles, (void *)0x0600C000);
497
+    LZ77UnCompWram(pdexBgMap, bgid_get_tilemap(2));
498
+    gpu_pal_apply_compressed(pdexBgPal, 0, 32);
499
+    gpu_pal_apply(pdex_text_pal, 15 * 16, 32);
500
+
501
+    /*setup window*/
502
+    lcd_io_set(REG_ID_WIN0H, (128 << 8) | (216));
503
+    lcd_io_set(REG_ID_WIN0V, ((20 << 8) | (148)));
504
+    lcd_io_set(REG_ID_WININ, WIN_BG0 | WIN_BG1 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
505
+    lcd_io_set(REG_ID_WINOUT, WIN_BG0 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
506
+    bgid_mark_for_sync(0);
507
+}
508
+
509
+void pdex_load(void) {
510
+
511
+    pdex_vram_setup();
512
+    pdex_load_gfx();
513
+
514
+    pokedex_context->pokemon_oam = -1;
515
+    pokedex_context->state = 0;
516
+    pokedex_context->hardware_scroll_amount = 0;
517
+    task_add(pdex_loop, 0);
518
+    set_callback2(pdex_cb_handler);
519
+}

+ 159
- 0
src/pokedex/pokedex_common.c Переглянути файл

@@ -0,0 +1,159 @@
1
+#include "pokedex_common.h"
2
+#include <pokeagb/pokeagb.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
+const struct OamData pdex_oam_pkmn = {
53
+    .affine_mode = 0,
54
+    .obj_mode = 0,
55
+    .mosaic = false,
56
+    .shape = 0,
57
+    .size = 3,
58
+};
59
+
60
+struct TextColor pdex_text_color = {0, 1, 2};
61
+
62
+void pdex_vblank_handler(void) {
63
+    gpu_sprites_upload();
64
+    copy_queue_process();
65
+    gpu_pal_upload();
66
+}
67
+
68
+u8 pstr_lines(pchar *str) {
69
+    u8 lines = 1;
70
+    while (*str != 0xFF) {
71
+        if (*str == 0xFE)
72
+            lines++;
73
+        str++;
74
+    }
75
+    return lines;
76
+}
77
+
78
+void pdex_cb_handler(void) {
79
+    if (pal_fade_control.active)
80
+        process_palfade();
81
+    else {
82
+        task_exec();
83
+        objc_exec();
84
+        obj_sync_superstate();
85
+        tilemaps_sync();
86
+        remoboxes_upload_tilesets();
87
+    }
88
+}
89
+
90
+void pdex_vram_free_bgmaps(void) {
91
+    for (u8 i = 0; i < 3; ++i) {
92
+        void *tmap = bgid_get_tilemap(i);
93
+        if (tmap != NULL) {
94
+            free(tmap);
95
+            bgid_nullify_tilemap(i);
96
+        }
97
+    }
98
+}
99
+
100
+struct PdexLookup *pdex_fill_lookup(u16 dexIndex) {
101
+    u16 species = pokedex_index_to_species(dexIndex);
102
+    pokedex_context->lookup[dexIndex].species = species;
103
+    pokedex_context->lookup[dexIndex].seen = dex_flag_pokedex_index(dexIndex, DEX_FLAG_CHECK_SEEN);
104
+    pokedex_context->lookup[dexIndex].caught = dex_flag_pokedex_index(dexIndex, DEX_FLAG_CHECK_CAUGHT);
105
+    return &pokedex_context->lookup[dexIndex];
106
+}
107
+
108
+struct PdexLookup *pdex_lazy_lookup_entry(u16 dexIndex) {
109
+    if (pokedex_context->lookup[dexIndex].species != -1) {
110
+        return &pokedex_context->lookup[dexIndex];
111
+    } else {
112
+        return pdex_fill_lookup(dexIndex);
113
+    }
114
+}
115
+
116
+void pdex_free_memory(void) {
117
+    if (pokedex_context->lookup != NULL)
118
+        free(pokedex_context->lookup);
119
+    free(pokedex_context);
120
+}
121
+
122
+void pdex_alloc_memory(void) {
123
+    pokedex_context = malloc_and_clear(sizeof(struct PdexCtx));
124
+    pokedex_context->lookup = malloc_and_clear((PDEX_LAST_SHOWN + 1) * sizeof(struct PdexLookup));
125
+    memset(pokedex_context->lookup, 0xFF, (PDEX_LAST_SHOWN + 1) * sizeof(struct PdexLookup));
126
+}
127
+
128
+void pdex_vram_allocate_bgmaps(void) {
129
+    bgid_set_tilemap(0, malloc(0x800));
130
+    bgid_set_tilemap(1, malloc(0x800));
131
+    bgid_set_tilemap(2, malloc(0x800));
132
+}
133
+
134
+void pdex_vram_setup(void) {
135
+    vblank_handler_set(NULL);
136
+    pal_fade_control_and_dead_struct_reset();
137
+    gpu_tile_bg_drop_all_sets(true);
138
+    obj_and_aux_reset_all();
139
+    gpu_tile_obj_tags_reset();
140
+    gpu_pal_allocator_reset();
141
+    rboxes_free();
142
+    tasks_init();
143
+    bg_vram_setup(0, &pdex_bg_config[0], 4);
144
+    u32 set = 0;
145
+    CpuFastSet((void *)&set, (void *)0x06000000, CPUModeFS(0x10000, CPUFSSET));
146
+
147
+    bgid_mod_x_offset(0, 0, 0);
148
+    bgid_mod_y_offset(0, 0, 0);
149
+    bgid_mod_x_offset(1, 0, 0);
150
+    bgid_mod_y_offset(1, 0, 0);
151
+    bgid_mod_x_offset(2, 0, 0);
152
+    bgid_mod_y_offset(2, 0, 0);
153
+    bgid_mod_x_offset(3, 0, 0);
154
+    bgid_mod_y_offset(3, 0, 0);
155
+
156
+    vblank_handler_set(pdex_vblank_handler);
157
+    interrupts_enable(INTERRUPT_VBLANK);
158
+    pdex_vram_allocate_bgmaps();
159
+}

+ 59
- 0
src/pokedex/pokedex_common.h Переглянути файл

@@ -0,0 +1,59 @@
1
+#ifndef PDEX_C_H_
2
+#define PDEX_C_H_
3
+
4
+#include <pokeagb/pokeagb.h>
5
+
6
+#define PDEX_LAST_SHOWN 813
7
+
8
+#define CPUFSCPY 0
9
+#define CPUFSSET 1
10
+#define CPUModeFS(size, mode) ((size >> 2) | (mode << 24))
11
+#define MAX3_COUNT_DIGITS(n) (n >= 100 ? 3 : (n >= 10 ? 2 : 1))
12
+
13
+#define OBJID_HIDE(objid) objects[objid].final_oam.affine_mode = 2
14
+#define OBJID_SHOW(objid) objects[objid].final_oam.affine_mode = 0
15
+
16
+#define PDEX_FADEIN_SPD 1
17
+
18
+#define FONT_DEX_STD 1
19
+
20
+#define TB_STD_LEN 10
21
+#define TB_STD_LEN_PX (TB_STD_LEN * 8)
22
+#define TB_BOT_LEN 9
23
+#define TB_BOT_LEN_PX (TB_BOT_LEN * 8)
24
+
25
+#define TB_STD_CENTER(t,w) (((w - t) >> 1) + 2)
26
+#define TB_STD_RIGHT(t,w) ((w - t))
27
+
28
+#define DEX_PKMN_TAG 0x1300
29
+#define DEX_BALL_TAG 0x1301
30
+#define DEX_CURSOR_TAG 0x1302
31
+#define DEX_ARROW_TAG 0x1303
32
+#define DEX_ARROW_TAG_EPAL 0x1304
33
+#define DEX_SCROLL_TAG 0x1305
34
+#define DEX_REGION_SELECT 0x1306
35
+#define DEX_DETAIL_TYPE1 0x130E
36
+#define DEX_DETAIL_TYPE2 0x130F
37
+#define DEX_DETAIL_TYPEPAL 0x130E
38
+
39
+#define DEX_REGION_PAL(i) (0x1307 + i)
40
+#define DEX_REGION_ICON(i) (0x1307 + i)
41
+
42
+void pdex_cb_handler(void);
43
+void pdex_vblank_handler(void);
44
+void pdex_vram_setup(void);
45
+void pdex_vram_free_bgmaps(void);
46
+void pdex_free_memory(void);
47
+void pdex_alloc_memory(void);
48
+struct PdexLookup *pdex_lazy_lookup_entry(u16 dexIndex);
49
+
50
+void pdex_load(void);
51
+
52
+const u16 pdex_text_pal[16];
53
+const struct BgConfig pdex_bg_config[4];
54
+struct TextColor pdex_text_color;
55
+const struct OamData pdex_oam_pkmn;
56
+
57
+u8 pstr_lines(pchar* str);
58
+
59
+#endif

+ 234
- 0
src/pokedex/pokedex_detail.c Переглянути файл

@@ -0,0 +1,234 @@
1
+#include <agb_debug.h>
2
+#include <pokeagb/pokeagb.h>
3
+#include <pokedex/pdexDetailBg.h>
4
+
5
+#include "pokedex_common.h"
6
+
7
+#define TB_PKNAME 0
8
+#define TB_PKSIZE 1
9
+#define TB_DESC 2
10
+
11
+#define TB_PKNAME_W 30
12
+#define TB_SW_W 12
13
+
14
+extern pchar pdex_entry_debug[];
15
+extern pchar pdex_str_size[];
16
+extern pchar pdex_str_weight[];
17
+extern pchar pdex_str_size_unit[];
18
+extern pchar pdex_str_weight_unit[];
19
+extern pchar pdex_str_comma[];
20
+
21
+struct TextboxTemplate dexdetail_boxes[] = {
22
+    {.bg_id = 0, .x = 0, .y = 0, .width = TB_PKNAME_W, .height = 4, .pal_id = 15, .charbase = 1},
23
+    {.bg_id = 0, .x = 17, .y = 5, .width = TB_SW_W, .height = 4, .pal_id = 15, .charbase = 121},
24
+    {.bg_id = 1, .x = 1, .y = 0, .width = 28, .height = 20, .pal_id = 15, .charbase = 161},
25
+
26
+    {.bg_id = 0xFF},
27
+};
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
+
65
+void dexdetail_load_pokemon(u16 dexindex) {
66
+    u16 species = pdex_lazy_lookup_entry(dexindex)->species;
67
+    rboxid_clear_pixels(TB_PKNAME, 0);
68
+    rboxid_clear_pixels(TB_PKSIZE, 0);
69
+    rboxid_clear_pixels(TB_DESC, 0);
70
+    u16 twidth = font_get_width_of_string(FONT_DEX_STD, &pokemon_names[species][0], 0x0000);
71
+    rboxid_print(TB_PKNAME, FONT_DEX_STD, TB_STD_CENTER(twidth, 8 * TB_PKNAME_W), 0, &pdex_text_color, 0,
72
+                 &pokemon_names[species][0]);
73
+
74
+    pchar *strType = &pokedex_data[dexindex].category_name[0];
75
+    u16 typeTwidth = font_get_width_of_string(FONT_DEX_STD, strType, 0x0000);
76
+    rboxid_print(TB_PKNAME, FONT_DEX_STD, TB_STD_CENTER(typeTwidth, 88) + 110, 14, &pdex_text_color, 0, strType);
77
+    rboxid_print(TB_PKSIZE, FONT_DEX_STD, 4, 1, &pdex_text_color, 0, pdex_str_size);
78
+    rboxid_print(TB_PKSIZE, FONT_DEX_STD, 4, 14, &pdex_text_color, 0, pdex_str_weight);
79
+
80
+    u16 weightNumber = pokedex_data[dexindex].weight / 10;
81
+    u16 weightDecimal = pokedex_data[dexindex].weight % 10;
82
+    pchar buffer[20];
83
+    fmt_int_10(string_buffer, weightNumber, 0, 3);
84
+    fmt_int_10(&buffer[0], weightDecimal, 0, 1);
85
+    pstrcat(string_buffer, pdex_str_comma);
86
+    pstrcat(string_buffer, buffer);
87
+    pstrcat(string_buffer, pdex_str_weight_unit);
88
+    u16 weightTwidth = font_get_width_of_string(FONT_DEX_STD, string_buffer, 0x0000);
89
+
90
+    rboxid_print(TB_PKSIZE, FONT_DEX_STD, TB_STD_RIGHT(weightTwidth, TB_SW_W * 8) - 6, 1, &pdex_text_color, 0,
91
+                 string_buffer);
92
+
93
+    u16 sizeNumber = pokedex_data[dexindex].height / 10;
94
+    u16 sizeDecimal = pokedex_data[dexindex].height % 10;
95
+    fmt_int_10(string_buffer, sizeNumber, 0, 3);
96
+    fmt_int_10(&buffer[0], sizeDecimal, 0, 1);
97
+    pstrcat(string_buffer, pdex_str_comma);
98
+    pstrcat(string_buffer, buffer);
99
+    pstrcat(string_buffer, pdex_str_size_unit);
100
+
101
+    rboxid_print(TB_PKSIZE, FONT_DEX_STD, TB_STD_RIGHT(weightTwidth, TB_SW_W * 8) - 6, 14, &pdex_text_color, 0,
102
+                 string_buffer);
103
+
104
+    rboxid_print(TB_DESC, FONT_DEX_STD, 3, 2, &pdex_text_color, 0, pokedex_data[dexindex].description1);
105
+
106
+    /* load the species sprite */
107
+    if (pokedex_context->detail_pokemon_oam != -1) {
108
+
109
+    } else {
110
+        struct SpriteTiles pkmnTiles = {pokemon_graphics_front[species].data, 2048, DEX_PKMN_TAG};
111
+        struct SpritePalette pkmnPal = {pokemon_palette_normal[species].data, DEX_PKMN_TAG};
112
+        const struct Template pkmnTemplate = {
113
+            .tiles_tag = DEX_PKMN_TAG,
114
+            .pal_tag = DEX_PKMN_TAG,
115
+            .oam = &pdex_oam_pkmn,
116
+            .animation = &anim_image_empty,
117
+            .graphics = &pkmnTiles,
118
+            .rotscale = &rotscale_empty,
119
+            .callback = oac_nullsub,
120
+        };
121
+        gpu_tile_obj_decompress_alloc_tag_and_upload(&pkmnTiles);
122
+
123
+        gpu_pal_decompress_alloc_tag_and_upload(&pkmnPal);
124
+        pokedex_context->detail_pokemon_oam = (s8)template_instanciate_forward_search(&pkmnTemplate, 10, 10, 0);
125
+
126
+        objects[pokedex_context->detail_pokemon_oam].pos1.x = 55;
127
+        objects[pokedex_context->detail_pokemon_oam].pos1.y = 55;
128
+    }
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
+
155
+    rboxid_update_tilemap_and_tileset(TB_DESC);
156
+    rboxid_update_tilemap_and_tileset(TB_PKNAME);
157
+    rboxid_update_tilemap_and_tileset(TB_PKSIZE);
158
+}
159
+
160
+void dexdetail_loop(u8 tid) {
161
+    (void)tid;
162
+    switch (pokedex_context->state) {
163
+    case 0:
164
+        bgid_send_tilemap(2);
165
+        dexdetail_load_pokemon(pokedex_context->cursor_position_top + pokedex_context->cursor_position_internal);
166
+        palette_bg_faded_fill_black();
167
+        pokedex_context->state++;
168
+        break;
169
+    case 1:
170
+        gpu_sync_bg_show(0);
171
+        gpu_sync_bg_show(1);
172
+        gpu_sync_bg_hide(3);
173
+
174
+        gpu_sync_bg_show(2);
175
+        fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 16, 0, 0x0000);
176
+        pokedex_context->state++;
177
+        break;
178
+    case 2:
179
+        switch (super.buttons_new) {
180
+        case KEY_B:
181
+            pokedex_context->state = 12;
182
+            u16 dexindex = pokedex_context->cursor_position_top + pokedex_context->cursor_position_internal;
183
+            if (dexindex <= PDEX_LAST_SHOWN - 7) {
184
+                pokedex_context->cursor_position_top = dexindex;
185
+                pokedex_context->cursor_position_internal = 0;
186
+            } else {
187
+                pokedex_context->cursor_position_top = PDEX_LAST_SHOWN - 7;
188
+                pokedex_context->cursor_position_internal = (dexindex - pokedex_context->cursor_position_top);
189
+            }
190
+
191
+            fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 0, 16, 0x0000);
192
+            break;
193
+        }
194
+        break;
195
+    case 12:
196
+        if (!pal_fade_control.active) {
197
+            task_del(tid);
198
+            pdex_vram_free_bgmaps();
199
+            set_callback2(pdex_load);
200
+        }
201
+        break;
202
+    default:
203
+        break;
204
+    }
205
+}
206
+
207
+struct SpritePalette dexdetail_type_pal = {&pokemon_type_chart_pal[0], DEX_DETAIL_TYPEPAL};
208
+
209
+void dexdetail_load_gfx(void) {
210
+    rbox_init_from_templates(&dexdetail_boxes[0]);
211
+    lz77UnCompVram(pdexDetailBgTiles, (void *)0x0600C000);
212
+    LZ77UnCompWram(pdexDetailBgMap, bgid_get_tilemap(2));
213
+    gpu_pal_apply_compressed(pdexDetailBgPal, 0, 32);
214
+    gpu_pal_apply(pdex_text_pal, 15 * 16, 32);
215
+    gpu_pal_obj_alloc_tag_and_apply(&dexdetail_type_pal);
216
+
217
+    lcd_io_set(REG_ID_WIN0H, (8 << 8) | (232));
218
+    lcd_io_set(REG_ID_WIN0V, ((100 << 8) | (160)));
219
+    lcd_io_set(REG_ID_WININ, WIN_BG0 | WIN_BG1 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
220
+    lcd_io_set(REG_ID_WINOUT, WIN_BG0 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
221
+    bgid_mod_y_offset(1, -24576, 1);
222
+    bgid_mark_for_sync(0);
223
+}
224
+
225
+void dexdetail_load(void) {
226
+    pdex_vram_setup();
227
+    dexdetail_load_gfx();
228
+    pokedex_context->state = 0;
229
+    pokedex_context->detail_pokemon_oam = -1;
230
+    pokedex_context->detail_type_oam[0] = -1;
231
+    pokedex_context->detail_type_oam[1] = -1;
232
+    task_add(dexdetail_loop, 0);
233
+    set_callback2(pdex_cb_handler);
234
+}

+ 231
- 0
src/pokedex/pokedex_region.c Переглянути файл

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

+ 92
- 0
src/pokedex/pokedex_string.s Переглянути файл

@@ -0,0 +1,92 @@
1
+.align 2
2
+.thumb
3
+.text
4
+.global pdex_str_title
5
+pdex_str_title:
6
+    .string LAN_DE "Amitec Pokédex"
7
+    .string LAN_EN "Amitec Pokédex"
8
+
9
+.global pdex_str_seen
10
+pdex_str_seen:
11
+    .string LAN_DE "Ges.:"
12
+    .string LAN_EN "Seen:"
13
+
14
+.global pdex_str_caught
15
+pdex_str_caught:
16
+    .string LAN_DE "Gef.:"
17
+    .string LAN_EN "Caught:"
18
+
19
+.global pdex_str_size
20
+pdex_str_size:
21
+    .string LAN_DE "Größe:"
22
+    .string LAN_EN "Size:"
23
+
24
+.global pdex_str_weight
25
+pdex_str_weight:
26
+    .string LAN_DE "Gewicht:"
27
+    .string LAN_EN "Weight:"
28
+
29
+.global pdex_str_size_unit
30
+pdex_str_size_unit:
31
+    .string LAN_DE "m"
32
+    .string LAN_EN "m"
33
+
34
+.global pdex_str_weight_unit
35
+pdex_str_weight_unit:
36
+    .string LAN_DE "kg"
37
+    .string LAN_EN "kg"
38
+
39
+.global pdex_str_comma
40
+pdex_str_comma:
41
+    .string LAN_DE ","
42
+    .string LAN_EN ","
43
+
44
+.global pdex_str_empty
45
+pdex_str_empty:
46
+    .string LAN_DE "----------"
47
+    .string LAN_EN "----------"
48
+
49
+.align 2
50
+.global pdex_str_regions
51
+pdex_str_regions:
52
+.word pdex_str_empty
53
+.word pdex_str_kanto
54
+.word pdex_str_jotho
55
+.word pdex_str_hoeen
56
+.word pdex_str_sinnoh
57
+.word pdex_str_unova
58
+.word pdex_str_kalos
59
+.word pdex_str_alola
60
+
61
+pdex_str_kanto:
62
+    .string LAN_DE "Kanto"
63
+    .string LAN_EN "Kanto"
64
+
65
+pdex_str_jotho:
66
+    .string LAN_DE "Johto"
67
+    .string LAN_EN "Johto"
68
+
69
+pdex_str_hoeen:
70
+    .string LAN_DE "Hoenn"
71
+    .string LAN_EN "Hoenn"
72
+
73
+pdex_str_sinnoh:
74
+    .string LAN_DE "Sinnoh"
75
+    .string LAN_EN "Sinnoh"
76
+
77
+pdex_str_unova:
78
+    .string LAN_DE "Einall"
79
+    .string LAN_EN " Unova"
80
+
81
+pdex_str_kalos:
82
+    .string LAN_DE "Kalos"
83
+    .string LAN_EN "Kalos"
84
+
85
+pdex_str_alola:
86
+    .string LAN_DE "Alola"
87
+    .string LAN_EN "Alola"
88
+
89
+.global pdex_entry_debug
90
+pdex_entry_debug:
91
+    .string LAN_DE "Glurak fliegt durch die Lüfte, um starke\nGegner aufzuspüren. Sein heißer Feuer-\natem bringt alles zum Schmelzen.\nAber es richtet seinen Feueratem nie auf\nschwächere Gegner."
92
+    .string LAN_EN "Glurak fliegt durch die Lüfte, um starke Gegner aufzuspüren.\nSein heißer Feueratem bringt alles zum Schmelzen.\nAber es richtet seinen Feueratem nie auf schwächere Gegner."