Browse Source

more pokedex progress, fix allocation and alignment issues

SBird1337 6 years ago
parent
commit
adc3486a8a

+ 1
- 1
g3headers

1
-Subproject commit 51b88ad16c551b386614c2e6f7d41c1acd552d92
1
+Subproject commit ef2af052b8e5436da9efb035e06ee091b8d53e69

+ 1
- 1
sots-private

1
-Subproject commit 25f3b9e569e5bc34cfc90edcb186ac26c6a9843c
1
+Subproject commit fcd34be58b09881a1306213a4feb1b546a76f41b

+ 21
- 9
src/pokedex/pokedex.c View File

17
 #define TB_CAUGHT 3
17
 #define TB_CAUGHT 3
18
 #define TB_MAIN 4
18
 #define TB_MAIN 4
19
 
19
 
20
-
21
-#define TB_STD_LEN 10
22
-#define TB_STD_LEN_PX (TB_STD_LEN * 8)
23
-#define TB_BOT_LEN 9
24
-#define TB_BOT_LEN_PX (TB_BOT_LEN * 8)
25
-
26
 #define TB_SEEN_Y (6)
20
 #define TB_SEEN_Y (6)
27
 #define TB_CAUGHT_Y 3
21
 #define TB_CAUGHT_Y 3
28
 
22
 
115
     rboxid_print(TB_SEEN, FONT_DEX_STD, 0, TB_SEEN_Y, &pdex_text_color, 0, &pdex_str_seen[0]);
109
     rboxid_print(TB_SEEN, FONT_DEX_STD, 0, TB_SEEN_Y, &pdex_text_color, 0, &pdex_str_seen[0]);
116
     rboxid_print(TB_CAUGHT, FONT_DEX_STD, 0, TB_CAUGHT_Y, &pdex_text_color, 0, &pdex_str_caught[0]);
110
     rboxid_print(TB_CAUGHT, FONT_DEX_STD, 0, TB_CAUGHT_Y, &pdex_text_color, 0, &pdex_str_caught[0]);
117
 
111
 
118
-    rboxid_print(TB_SEEN, FONT_DEX_STD, TB_STD_RIGHT(twidthSeen), TB_SEEN_Y + 1, &pdex_text_color, 0, seenBuffer);
119
-    rboxid_print(TB_CAUGHT, FONT_DEX_STD, TB_STD_RIGHT(twidthCaught), TB_CAUGHT_Y + 1, &pdex_text_color, 0,
112
+    rboxid_print(TB_SEEN, FONT_DEX_STD, TB_STD_RIGHT(twidthSeen,TB_BOT_LEN_PX), TB_SEEN_Y + 1, &pdex_text_color, 0, seenBuffer);
113
+    rboxid_print(TB_CAUGHT, FONT_DEX_STD, TB_STD_RIGHT(twidthCaught,TB_BOT_LEN_PX), TB_CAUGHT_Y + 1, &pdex_text_color, 0,
120
                  caughtBuffer);
114
                  caughtBuffer);
121
 
115
 
122
     rboxid_update_tilemap_and_tileset(TB_SEEN);
116
     rboxid_update_tilemap_and_tileset(TB_SEEN);
135
     /* this is very temporary */
129
     /* this is very temporary */
136
     rboxid_clear_pixels(TB_PKMN, 0);
130
     rboxid_clear_pixels(TB_PKMN, 0);
137
     u32 twidth = font_get_width_of_string(FONT_DEX_STD, &pokemon_names[species][0], 0x0000);
131
     u32 twidth = font_get_width_of_string(FONT_DEX_STD, &pokemon_names[species][0], 0x0000);
138
-    rboxid_print(TB_PKMN, FONT_DEX_STD, TB_STD_CENTER(twidth), 3, &pdex_text_color, 0, &pokemon_names[species][0]);
132
+    rboxid_print(TB_PKMN, FONT_DEX_STD, TB_STD_CENTER(twidth,TB_STD_LEN_PX), 3, &pdex_text_color, 0, &pokemon_names[species][0]);
139
     if (pokedex_context->pokemon_oam != -1) {
133
     if (pokedex_context->pokemon_oam != -1) {
140
         lz77UnCompVram(pokemon_graphics_front[species].data,
134
         lz77UnCompVram(pokemon_graphics_front[species].data,
141
                        ((void *)(objects[pokedex_context->pokemon_oam].final_oam.tile_num * 32) + ADDR_VRAM + 0x10000));
135
                        ((void *)(objects[pokedex_context->pokemon_oam].final_oam.tile_num * 32) + ADDR_VRAM + 0x10000));
442
         break;
436
         break;
443
     case 4:
437
     case 4:
444
         /* main control */
438
         /* main control */
439
+        if(super.buttons_new & KEY_A)
440
+        {
441
+            pokedex_context->state = 15;
442
+        }
445
         if (super.buttons_new & KEY_B) {
443
         if (super.buttons_new & KEY_B) {
446
             pokedex_context->state = 10;
444
             pokedex_context->state = 10;
447
         }
445
         }
460
     case 11:
458
     case 11:
461
         if (!pal_fade_control.active) {
459
         if (!pal_fade_control.active) {
462
             task_del(tid);
460
             task_del(tid);
461
+            pdex_vram_free_bgmaps();
463
             free(pokedex_context->lookup);
462
             free(pokedex_context->lookup);
464
             free(pokedex_context);
463
             free(pokedex_context);
465
             set_callback2(c2_overworld_switch_start_menu);
464
             set_callback2(c2_overworld_switch_start_menu);
466
             set_callback1(c1_overworld);
465
             set_callback1(c1_overworld);
467
         }
466
         }
468
         break;
467
         break;
468
+    case 15:
469
+        /* load the detail screen */
470
+        fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 0, 16, 0x0000);
471
+        pokedex_context->state++;
472
+        break;
473
+    case 16:
474
+        if(!pal_fade_control.active)
475
+        {
476
+            pdex_vram_free_bgmaps();
477
+            task_del(tid);
478
+            void dexdetail_load(void);
479
+            set_callback2(dexdetail_load);
480
+        }
469
     default:
481
     default:
470
         break;
482
         break;
471
     }
483
     }

+ 28
- 5
src/pokedex/pokedex_common.c View File

1
-#include <pokeagb/pokeagb.h>
2
 #include "pokedex_common.h"
1
 #include "pokedex_common.h"
2
+#include <pokeagb/pokeagb.h>
3
 
3
 
4
 const u16 pdex_text_pal[] = {rgb5(255, 0, 255), rgb5(255, 255, 255), rgb5(0, 0, 0),     rgb5(255, 0, 255),
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),
5
                              rgb5(255, 0, 255), rgb5(255, 0, 255),   rgb5(255, 0, 255), rgb5(255, 0, 255),
57
     gpu_pal_upload();
57
     gpu_pal_upload();
58
 }
58
 }
59
 
59
 
60
+u8 pstr_lines(pchar *str) {
61
+    u8 lines = 1;
62
+    while (*str != 0xFF) {
63
+        if (*str == 0xFE)
64
+            lines++;
65
+        str++;
66
+    }
67
+    return lines;
68
+}
69
+
60
 void pdex_cb_handler(void) {
70
 void pdex_cb_handler(void) {
61
     if (pal_fade_control.active)
71
     if (pal_fade_control.active)
62
         process_palfade();
72
         process_palfade();
69
     }
79
     }
70
 }
80
 }
71
 
81
 
82
+void pdex_vram_free_bgmaps(void) {
83
+    for (u8 i = 0; i < 3; ++i) {
84
+        void *tmap = bgid_get_tilemap(i);
85
+        if (tmap != NULL) {
86
+            free(tmap);
87
+            bgid_nullify_tilemap(i);
88
+        }
89
+    }
90
+}
91
+
92
+void pdex_vram_allocate_bgmaps(void) {
93
+    bgid_set_tilemap(0, malloc(0x800));
94
+    bgid_set_tilemap(1, malloc(0x800));
95
+    bgid_set_tilemap(2, malloc(0x800));
96
+}
97
+
72
 void pdex_vram_setup(void) {
98
 void pdex_vram_setup(void) {
73
     vblank_handler_set(NULL);
99
     vblank_handler_set(NULL);
74
     pal_fade_control_and_dead_struct_reset();
100
     pal_fade_control_and_dead_struct_reset();
93
 
119
 
94
     vblank_handler_set(pdex_vblank_handler);
120
     vblank_handler_set(pdex_vblank_handler);
95
     interrupts_enable(INTERRUPT_VBLANK);
121
     interrupts_enable(INTERRUPT_VBLANK);
96
-
97
-    u8 *bgMap = malloc(0x800);
98
-    bgid_set_tilemap(2, bgMap);
99
-    
122
+    pdex_vram_allocate_bgmaps();
100
 }
123
 }

+ 9
- 2
src/pokedex/pokedex_common.h View File

15
 
15
 
16
 #define FONT_DEX_STD 1
16
 #define FONT_DEX_STD 1
17
 
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))
18
+#define TB_STD_LEN 10
19
+#define TB_STD_LEN_PX (TB_STD_LEN * 8)
20
+#define TB_BOT_LEN 9
21
+#define TB_BOT_LEN_PX (TB_BOT_LEN * 8)
22
+
23
+#define TB_STD_CENTER(t,w) (((w - t) >> 1) + 2)
24
+#define TB_STD_RIGHT(t,w) ((w - t))
20
 
25
 
21
 #define DEX_PKMN_TAG 0x1300
26
 #define DEX_PKMN_TAG 0x1300
22
 #define DEX_BALL_TAG 0x1301
27
 #define DEX_BALL_TAG 0x1301
32
 void pdex_cb_handler(void);
37
 void pdex_cb_handler(void);
33
 void pdex_vblank_handler(void);
38
 void pdex_vblank_handler(void);
34
 void pdex_vram_setup(void);
39
 void pdex_vram_setup(void);
40
+void pdex_vram_free_bgmaps(void);
35
 
41
 
36
 void pdex_load(void);
42
 void pdex_load(void);
37
 
43
 
38
 const u16 pdex_text_pal[16];
44
 const u16 pdex_text_pal[16];
39
 const struct BgConfig pdex_bg_config[4];
45
 const struct BgConfig pdex_bg_config[4];
40
 struct TextColor pdex_text_color;
46
 struct TextColor pdex_text_color;
47
+u8 pstr_lines(pchar* str);
41
 
48
 
42
 #endif
49
 #endif

+ 91
- 0
src/pokedex/pokedex_detail.c View File

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 2
9
+#define TB_PKWEIGHT 3
10
+#define TB_DESC 2
11
+
12
+#define TB_PKNAME_W 30
13
+#define TB_SW_W 20
14
+
15
+extern pchar pdex_entry_debug[];
16
+extern pchar pdex_str_size[];
17
+extern pchar pdex_str_weight[];
18
+extern pchar pdex_str_size_unit[];
19
+extern pchar pdex_str_weight_unit[];
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
+
24
+    {.bg_id = 1, .x = 1, .y = 0, .width = 28, .height = 20, .pal_id = 15, .charbase = 121},
25
+
26
+    {.bg_id = 0xFF},
27
+};
28
+
29
+void dexdetail_load_pokemon(u16 dexindex) {
30
+    u16 species = pokedex_context->lookup[dexindex].species;
31
+    rboxid_clear_pixels(TB_PKNAME, 0);
32
+    u16 twidth = font_get_width_of_string(FONT_DEX_STD, &pokemon_names[species][0], 0x0000);
33
+    //rboxid_print(TB_PKNAME, FONT_DEX_STD, TB_STD_CENTER(twidth,8*TB_PKNAME_W), 0, &pdex_text_color, 0, &pokemon_names[species][0]);
34
+    rboxid_print(TB_PKNAME, FONT_DEX_STD, 0, 0, &pdex_text_color, 0, pdex_entry_debug);
35
+    pchar *strType = &pokedex_data[dexindex].category_name[0];
36
+    u16 typeTwidth = font_get_width_of_string(FONT_DEX_STD, strType, 0x0000);
37
+    rboxid_print(TB_PKNAME, FONT_DEX_STD, 50, 16, &pdex_text_color, 0, strType);
38
+    rboxid_update_tilemap_and_tileset(TB_PKNAME);
39
+
40
+}
41
+
42
+void dexdetail_loop(u8 tid) {
43
+    (void)tid;
44
+    switch (pokedex_context->state) {
45
+    case 0:
46
+        bgid_send_tilemap(2);
47
+        // rboxid_fill_rectangle(4, 1, 0, 0, 28 * 8, 20 * 8);
48
+        dexdetail_load_pokemon(pokedex_context->cursor_position_top + pokedex_context->cursor_position_internal);
49
+        //rboxid_clear_pixels(TB_DESC, 0);
50
+        //rboxid_print(TB_DESC, FONT_DEX_STD, 3, 2, &pdex_text_color, 0, pdex_entry_debug);
51
+        //rboxid_update_tilemap_and_tileset(TB_DESC);
52
+
53
+        palette_bg_faded_fill_black();
54
+        pokedex_context->state++;
55
+        break;
56
+    case 1:
57
+        gpu_sync_bg_show(0);
58
+        gpu_sync_bg_show(1);
59
+        gpu_sync_bg_hide(3);
60
+
61
+        gpu_sync_bg_show(2);
62
+        fade_screen(0xFFFFFFFF, PDEX_FADEIN_SPD, 16, 0, 0x0000);
63
+        pokedex_context->state++;
64
+        break;
65
+    default:
66
+        break;
67
+    }
68
+}
69
+
70
+void dexdetail_load_gfx(void) {
71
+    rbox_init_from_templates(&dexdetail_boxes[0]);
72
+    lz77UnCompVram(pdexDetailBgTiles, (void *)0x0600C000);
73
+    LZ77UnCompWram(pdexDetailBgMap, bgid_get_tilemap(2));
74
+    gpu_pal_apply_compressed(pdexDetailBgPal, 0, 32);
75
+    gpu_pal_apply(pdex_text_pal, 15 * 16, 32);
76
+
77
+    lcd_io_set(REG_ID_WIN0H, (8 << 8) | (232));
78
+    lcd_io_set(REG_ID_WIN0V, ((100 << 8) | (160)));
79
+    lcd_io_set(REG_ID_WININ, WIN_BG0 | WIN_BG1 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
80
+    lcd_io_set(REG_ID_WINOUT, WIN_BG0 | WIN_BG2 | WIN_BG3 | WIN_OBJ);
81
+    bgid_mod_y_offset(1, -24576, 1);
82
+    bgid_mark_for_sync(0);
83
+}
84
+
85
+void dexdetail_load(void) {
86
+    pdex_vram_setup();
87
+    dexdetail_load_gfx();
88
+    pokedex_context->state = 0;
89
+    task_add(dexdetail_loop, 0);
90
+    set_callback2(pdex_cb_handler);
91
+}

+ 1
- 2
src/pokedex/pokedex_region.c View File

189
     case 10:
189
     case 10:
190
         if (!pal_fade_control.active) {
190
         if (!pal_fade_control.active) {
191
             task_del(tid);
191
             task_del(tid);
192
-            if(bgid_get_tilemap(2) != NULL)
193
-                free(bgid_get_tilemap(2));
192
+            pdex_vram_free_bgmaps();
194
             set_callback2(pdex_load);
193
             set_callback2(pdex_load);
195
         }
194
         }
196
         break;
195
         break;

+ 27
- 1
src/pokedex/pokedex_string.s View File

16
     .string LAN_DE "Gef.:"
16
     .string LAN_DE "Gef.:"
17
     .string LAN_EN "Caught:"
17
     .string LAN_EN "Caught:"
18
 
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
+
19
 .global pdex_str_empty
39
 .global pdex_str_empty
20
 pdex_str_empty:
40
 pdex_str_empty:
21
     .string LAN_DE "----------"
41
     .string LAN_DE "----------"
22
     .string LAN_EN "----------"
42
     .string LAN_EN "----------"
23
 
43
 
44
+.align 2
24
 .global pdex_str_regions
45
 .global pdex_str_regions
25
 pdex_str_regions:
46
 pdex_str_regions:
26
 .word pdex_str_empty
47
 .word pdex_str_empty
58
 
79
 
59
 pdex_str_alola:
80
 pdex_str_alola:
60
     .string LAN_DE "Alola"
81
     .string LAN_DE "Alola"
61
-    .string LAN_EN "Alola"
82
+    .string LAN_EN "Alola"
83
+
84
+.global pdex_entry_debug
85
+pdex_entry_debug:
86
+    .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."
87
+    .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."