Browse Source

pokedex almost finished

SBird1337 6 years ago
parent
commit
9a5685d3e7
2 changed files with 74 additions and 37 deletions
  1. 1
    1
      g3headers
  2. 73
    36
      src/pokedex/pokedex.c

+ 1
- 1
g3headers

1
-Subproject commit 7ab06a0eeb0381380decca9620759741f2b0a44e
1
+Subproject commit 4e715b48868f0ffa22959c430c8decb5c7785bfc

+ 73
- 36
src/pokedex/pokedex.c View File

112
     },
112
     },
113
 };
113
 };
114
 
114
 
115
-u16 pdex_get_y_offset(s8 n) {
115
+s16 pdex_get_y_offset(s8 n) {
116
     s8 modOffset = n + pokedex_context->hardware_scroll_amount;
116
     s8 modOffset = n + pokedex_context->hardware_scroll_amount;
117
-    if (modOffset < -1)
118
-        modOffset += 8;
119
-    if (modOffset > 15)
120
-        modOffset -= 8;
121
-    return 19 + (15 * modOffset);
117
+    s8 wrapOffset = 0;
118
+    dprintf("mod_offset: %d\n", modOffset);
119
+    if (modOffset < -1) {
120
+        modOffset += 17;
121
+        wrapOffset = 1;
122
+    }
123
+
124
+    if (modOffset > 15) {
125
+        wrapOffset = -1;
126
+        modOffset -= 17;
127
+    }
128
+    return (19 + (15 * modOffset)) + wrapOffset + (pokedex_context->overdo_amount);
122
 }
129
 }
123
 
130
 
124
 void pdex_main_box_species_fill(s8 n, u16 species, bool seen, bool caught) {
131
 void pdex_main_box_species_fill(s8 n, u16 species, bool seen, bool caught) {
132
+    s16 y = pdex_get_y_offset(n);
133
+    dprintf("trying to print box to y: %d\n", y);
134
+    rboxid_fill_rectangle(TB_MAIN, 0, 0, y, 11 * 8, 15);
125
     const pchar *stringToPrint = (seen || caught) ? &pokemon_names[species][0] : &pdex_str_empty[0];
135
     const pchar *stringToPrint = (seen || caught) ? &pokemon_names[species][0] : &pdex_str_empty[0];
126
     const pchar stringWhitespace[] = {0x0, 0xFF};
136
     const pchar stringWhitespace[] = {0x0, 0xFF};
127
     fmt_int_10(string_buffer, pokedex_context->cursor_position_top + n, 2, 3);
137
     fmt_int_10(string_buffer, pokedex_context->cursor_position_top + n, 2, 3);
128
     pstrcat(string_buffer, &stringWhitespace[0]);
138
     pstrcat(string_buffer, &stringWhitespace[0]);
129
     pstrcat(string_buffer, stringToPrint);
139
     pstrcat(string_buffer, stringToPrint);
130
-    rboxid_print(TB_MAIN, FONT_DEX_STD, 4, pdex_get_y_offset(n), &pdex_text_color, 0, string_buffer);
131
-    // show the pokéball if necessary
140
+    rboxid_print(TB_MAIN, FONT_DEX_STD, 4, y, &pdex_text_color, 0, string_buffer);
132
 }
141
 }
133
 
142
 
134
-void pdex_update_page_full() {
135
-    rboxid_clear_pixels(TB_MAIN, 0);
136
-    for (s8 i = pokedex_context->cursor_position_top - 1; i < pokedex_context->cursor_position_top + 9 + 7; ++i) {
137
-        pdex_main_box_species_fill(i - pokedex_context->cursor_position_top, pokedex_context->lookup[i].species,
138
-                                   pokedex_context->lookup[i].seen, pokedex_context->lookup[i].caught);
139
-    }
143
+void pdex_update_balls(void) {
140
     for (u8 i = 0; i < 9; ++i) {
144
     for (u8 i = 0; i < 9; ++i) {
141
         if (pokedex_context->lookup[i + pokedex_context->cursor_position_top].caught)
145
         if (pokedex_context->lookup[i + pokedex_context->cursor_position_top].caught)
142
             OBJID_SHOW(pokedex_context->ball_oams[i]);
146
             OBJID_SHOW(pokedex_context->ball_oams[i]);
143
         else
147
         else
144
             OBJID_HIDE(pokedex_context->ball_oams[i]);
148
             OBJID_HIDE(pokedex_context->ball_oams[i]);
145
     }
149
     }
150
+}
151
+
152
+void pdex_update_page_full() {
153
+    rboxid_clear_pixels(TB_MAIN, 0);
154
+    for (s8 i = pokedex_context->cursor_position_top; i < pokedex_context->cursor_position_top + 9; ++i) {
155
+        pdex_main_box_species_fill(i - pokedex_context->cursor_position_top, pokedex_context->lookup[i].species,
156
+                                   pokedex_context->lookup[i].seen, pokedex_context->lookup[i].caught);
157
+    }
158
+    pdex_update_balls();
146
     rboxid_update_tilemap_and_tileset(TB_MAIN);
159
     rboxid_update_tilemap_and_tileset(TB_MAIN);
147
 }
160
 }
148
 
161
 
306
 
319
 
307
 void pdex_hardware_scroll(bool up) {
320
 void pdex_hardware_scroll(bool up) {
308
     /* somewhat hacky wraparound scrolling, works though */
321
     /* somewhat hacky wraparound scrolling, works though */
322
+    /* TODO: Fix the one pixel off */
309
     if (up) {
323
     if (up) {
310
         if (pokedex_context->hardware_scroll_amount > -16) {
324
         if (pokedex_context->hardware_scroll_amount > -16) {
311
-            if (pokedex_context->hardware_scroll_amount != -8) {
312
-                bgid_mod_y_offset(1, -3840, 1);
313
-
314
-            } else {
315
-                bgid_mod_y_offset(1, -4096, 1);
316
-            }
325
+            bgid_mod_y_offset(1, -(15 << 8), 1);
317
             pokedex_context->hardware_scroll_amount--;
326
             pokedex_context->hardware_scroll_amount--;
318
         } else {
327
         } else {
319
             pokedex_context->hardware_scroll_amount = 0;
328
             pokedex_context->hardware_scroll_amount = 0;
329
+            // pokedex_context->overdo_amount++;
320
             bgid_mod_y_offset(1, 0, 0);
330
             bgid_mod_y_offset(1, 0, 0);
331
+            bgid_mod_y_offset(1, (256 * pokedex_context->overdo_amount), 1);
321
         }
332
         }
322
     } else {
333
     } else {
334
+
323
         if (pokedex_context->hardware_scroll_amount < 16) {
335
         if (pokedex_context->hardware_scroll_amount < 16) {
324
-            if (pokedex_context->hardware_scroll_amount != 8) {
325
-                bgid_mod_y_offset(1, 3840, 1);
326
-            } else {
327
-                bgid_mod_y_offset(1, 4096, 1);
328
-            }
336
+            bgid_mod_y_offset(1, 15 << 8, 1);
329
             pokedex_context->hardware_scroll_amount++;
337
             pokedex_context->hardware_scroll_amount++;
330
         } else {
338
         } else {
331
             pokedex_context->hardware_scroll_amount = 0;
339
             pokedex_context->hardware_scroll_amount = 0;
340
+            // pokedex_context->overdo_amount--;
332
             bgid_mod_y_offset(1, 0, 0);
341
             bgid_mod_y_offset(1, 0, 0);
342
+            bgid_mod_y_offset(1, (256 * pokedex_context->overdo_amount), 1);
333
         }
343
         }
334
     }
344
     }
335
 }
345
 }
336
 
346
 
347
+void pdex_fill_previous_slot(void) {
348
+    u16 pIndex = pokedex_context->cursor_position_top - 1;
349
+    pdex_main_box_species_fill(-1, pokedex_context->lookup[pIndex].species, pokedex_context->lookup[pIndex].seen,
350
+                               pokedex_context->lookup[pIndex].caught);
351
+}
352
+
353
+void pdex_fill_next_slot(void) {
354
+    u16 pIndex = pokedex_context->cursor_position_top + 9;
355
+    pdex_main_box_species_fill(9, pokedex_context->lookup[pIndex].species, pokedex_context->lookup[pIndex].seen,
356
+                               pokedex_context->lookup[pIndex].caught);
357
+}
358
+
337
 void pdex_try_advance(u8 reverse) {
359
 void pdex_try_advance(u8 reverse) {
338
-    bool dirty = false;
339
     if (reverse) {
360
     if (reverse) {
340
         if (pokedex_context->cursor_position_internal > 0) {
361
         if (pokedex_context->cursor_position_internal > 0) {
341
             pokedex_context->cursor_position_internal--;
362
             pokedex_context->cursor_position_internal--;
342
         } else if ((pokedex_context->cursor_position_top) > (pokedex_context->first_seen)) {
363
         } else if ((pokedex_context->cursor_position_top) > (pokedex_context->first_seen)) {
364
+            pdex_fill_previous_slot();
343
             pokedex_context->cursor_position_top--;
365
             pokedex_context->cursor_position_top--;
344
-            dirty = true;
366
+
367
+            pdex_hardware_scroll(true);
345
         }
368
         }
346
     } else {
369
     } else {
347
         if (pokedex_context->cursor_position_internal < 8) {
370
         if (pokedex_context->cursor_position_internal < 8) {
348
             pokedex_context->cursor_position_internal++;
371
             pokedex_context->cursor_position_internal++;
349
         } else if (pokedex_context->cursor_position_top < (PDEX_LAST_SHOWN - 8)) {
372
         } else if (pokedex_context->cursor_position_top < (PDEX_LAST_SHOWN - 8)) {
373
+            pdex_fill_next_slot();
350
             pokedex_context->cursor_position_top++;
374
             pokedex_context->cursor_position_top++;
351
-            dirty = true;
375
+            pdex_hardware_scroll(false);
352
         }
376
         }
353
     }
377
     }
354
-    if (dirty) {
355
-        pdex_update_page_full();
356
-    }
378
+
357
     u16 pkIndexToLoad = pokedex_context->cursor_position_internal + pokedex_context->cursor_position_top;
379
     u16 pkIndexToLoad = pokedex_context->cursor_position_internal + pokedex_context->cursor_position_top;
358
     if (pokedex_context->lookup[pkIndexToLoad].seen || pokedex_context->lookup[pkIndexToLoad].caught)
380
     if (pokedex_context->lookup[pkIndexToLoad].seen || pokedex_context->lookup[pkIndexToLoad].caught)
359
         pdex_pokemon_load(pokedex_context->lookup[pkIndexToLoad].species);
381
         pdex_pokemon_load(pokedex_context->lookup[pkIndexToLoad].species);
360
     else
382
     else
361
         pdex_pokemon_load(0);
383
         pdex_pokemon_load(0);
384
+    pdex_update_balls();
362
 }
385
 }
363
 
386
 
364
 void pdex_loop(u8 tid) {
387
 void pdex_loop(u8 tid) {
396
 
419
 
397
         break;
420
         break;
398
     case 3:
421
     case 3:
399
-        if ((super.buttons_new & KEY_DOWN)) {
422
+    if ((super.buttons_held & KEY_DOWN)) {
423
+        pokedex_context->held_frames++;
424
+        if (pokedex_context->held_frames == 10) {
400
             pdex_try_advance(false);
425
             pdex_try_advance(false);
401
-        } else if ((super.buttons_new & KEY_UP)) {
426
+            pokedex_context->held_frames = 0;
427
+        }
428
+    } else if ((super.buttons_held & KEY_UP)) {
429
+        pokedex_context->held_frames++;
430
+        if (pokedex_context->held_frames == 10) {
402
             pdex_try_advance(true);
431
             pdex_try_advance(true);
432
+            pokedex_context->held_frames = 0;
403
         }
433
         }
404
-        break;
405
-    default:
406
-        break;
434
+    } else if ((super.buttons_new & KEY_DOWN)) {
435
+        pokedex_context->held_frames = 0;
436
+        pdex_try_advance(false);
437
+    } else if ((super.buttons_new & KEY_UP)) {
438
+        pokedex_context->held_frames = 0;
439
+        pdex_try_advance(true);
407
     }
440
     }
441
+    break;
442
+default:
443
+    break;
444
+}
408
 }
445
 }
409
 
446
 
410
 bool sm_pdex_init(void) {
447
 bool sm_pdex_init(void) {