diff options
-rw-r--r-- | Add-a-fourth-stats-page.md | 389 | ||||
-rw-r--r-- | Tutorials.md | 2 | ||||
-rw-r--r-- | screenshots/fourth-stats-page.png | bin | 0 -> 1540 bytes |
3 files changed, 390 insertions, 1 deletions
diff --git a/Add-a-fourth-stats-page.md b/Add-a-fourth-stats-page.md new file mode 100644 index 0000000..019d1dd --- /dev/null +++ b/Add-a-fourth-stats-page.md @@ -0,0 +1,389 @@ +This tutorial is for how to add a fourth page to Pokémon stats. As an example, we'll make an orange page after the pink, green, and blue ones. + +(The code for this feature was adapted from [i-am-the-pokeman](https://github.com/i-am-the-pokeman/pokecrystal-4th-stat-screen/).) + + +## Contents + +1. [Define the fourth page's colors](#1-define-the-fourth-pages-colors) +2. [Load and apply the fourth page's palette](#2-load-and-apply-the-fourth-pages-palette) +3. [Display the fourth page's content](#3-display-the-fourth-pages-content) +4. [Account for the shifted page indexes](#4-account-for-the-shifted-page-indexes) + + +## 1. Define the fourth page's colors + +Edit [gfx/stats/pages.pal](../blob/master/gfx/stats/pages.pal): + +```diff + ; pink + RGB 31, 31, 31 + RGB 31, 19, 31 + RGB 31, 15, 31 + RGB 00, 00, 00 + ; green + RGB 31, 31, 31 + RGB 21, 31, 14 + RGB 17, 31, 00 + RGB 00, 00, 00 + ; blue + RGB 31, 31, 31 + RGB 17, 31, 31 + RGB 17, 31, 31 + RGB 00, 00, 00 ++; orange ++ RGB 31, 31, 31 ++ RGB 30, 24, 16 ++ RGB 30, 22, 12 ++ RGB 00, 00, 00 +``` + +And edit [gfx/stats/stats.pal](../blob/master/gfx/stats/stats.pal): + +```diff + ; pink + RGB 31, 19, 31 + ; green + RGB 21, 31, 14 + ; blue + RGB 17, 31, 31 ++; orange ++ RGB 30, 24, 16 +``` + +`RGB` colors define 5-bit red, green, and blue channels, each from 0 to 31. (On a PC, typically 8-bit color channels go from 0 to 255, or in hex 00 to FF. Just multiply or divide by 8 to convert between them; e.g. `RGB 30, 24, 16` looks like [#F0C080](https://www.color-hex.com/color/F0C080).) + +Both of these files sort the pages in order from left to right. + + +## 2. Load and apply the fourth page's palette + +Edit [engine/gfx/cgb_layouts.asm](../blob/master/engine/gfx/cgb_layouts.asm): + +```diff + _CGB_StatsScreenHPPals: + ld de, wBGPals1 + ld a, [wCurHPPal] + ld l, a + ld h, $0 + add hl, hl + add hl, hl + ld bc, HPBarPals + add hl, bc + call LoadPalette_White_Col1_Col2_Black ; hp palette + ld a, [wCurPartySpecies] + ld bc, wTempMonDVs + call GetPlayerOrMonPalettePointer + call LoadPalette_White_Col1_Col2_Black ; mon palette + ld hl, ExpBarPalette + call LoadPalette_White_Col1_Col2_Black ; exp palette + ld hl, StatsScreenPagePals + ld de, wBGPals1 palette 3 +- ld bc, 3 palettes ; pink, green, and blue page palettes ++ ld bc, 4 palettes ; pink, green, blue, and orange page palettes + ld a, BANK(wBGPals1) + call FarCopyWRAM + call WipeAttrmap + + hlcoord 0, 0, wAttrmap + lb bc, 8, SCREEN_WIDTH + ld a, $1 ; mon palette + call FillBoxCGB + + hlcoord 10, 16, wAttrmap + ld bc, 10 + ld a, $2 ; exp palette + call ByteFill + +- hlcoord 13, 5, wAttrmap ++ hlcoord 11, 5, wAttrmap + lb bc, 2, 2 + ld a, $3 ; pink page palette + call FillBoxCGB + +- hlcoord 15, 5, wAttrmap ++ hlcoord 13, 5, wAttrmap + lb bc, 2, 2 + ld a, $4 ; green page palette + call FillBoxCGB + +- hlcoord 17, 5, wAttrmap ++ hlcoord 15, 5, wAttrmap + lb bc, 2, 2 + ld a, $5 ; blue page palette + call FillBoxCGB ++ ++ hlcoord 17, 5, wAttrmap ++ lb bc, 2, 2 ++ ld a, $6 ; orange page palette ++ call FillBoxCGB + + call ApplyAttrmap + call ApplyPals + ld a, $1 + ldh [hCGBPalUpdate], a + ret + + StatsScreenPagePals: + INCLUDE "gfx/stats/pages.pal" + + StatsScreenPals: + INCLUDE "gfx/stats/stats.pal" +``` + +Here we load the new fourth palette, and change where the palettes are applied to the screen. The pink, green, and blue page icons are going to shift left to make room for a fourth orange icon. + + +## 3. Display the fourth page's content + +Edit [engine/pokemon/stats_screen.asm](../blob/master/engine/pokemon/stats_screen.asm): + +```diff +- const_def 1 +- const PINK_PAGE ; 1 +- const GREEN_PAGE ; 2 +- const BLUE_PAGE ; 3 +-NUM_STAT_PAGES EQU const_value + -1 ++ const_def ++ const PINK_PAGE ; 0 ++ const GREEN_PAGE ; 1 ++ const BLUE_PAGE ; 2 ++ const ORANGE_PAGE ; 3 ++NUM_STAT_PAGES EQU const_value +``` + +Instead of three constants from 1 to 3, we'll use four constants from 0 to 3. We're not using 1 to 4, because 4 in binary is %100, and these values need to fit in two bits. + +```diff + StatsScreenMain: + xor a + ld [wJumptableIndex], a +-; ??? +- ld [wcf64], a +- ld a, [wcf64] +- and %11111100 +- or 1 +- ld [wcf64], a ++ ld [wcf64], a ; PINK_PAGE + .loop + ld a, [wJumptableIndex] + and $ff ^ (1 << 7) + ld hl, StatsScreenPointerTable + rst JumpTable + call StatsScreen_WaitAnim ; check for keys? + ld a, [wJumptableIndex] + bit 7, a + jr z, .loop + ret + + StatsScreenMobile: + xor a + ld [wJumptableIndex], a +-; ??? +- ld [wcf64], a +- ld a, [wcf64] +- and %11111100 +- or 1 +- ld [wcf64], a ++ ld [wcf64], a ; PINK_PAGE + .loop + farcall Mobile_SetOverworldDelay + ld a, [wJumptableIndex] + and $ff ^ (1 << 7) + ld hl, StatsScreenPointerTable + rst JumpTable + call StatsScreen_WaitAnim + farcall MobileComms_CheckInactivityTimer + jr c, .exit + ld a, [wJumptableIndex] + bit 7, a + jr z, .loop + + .exit + ret +``` + +This code was a bit messy and redundant, but the intended effect is to start at the pink page. We changed its index from 1 to 0, so that needed updating. + +```diff + StatsScreen_JoypadAction: + ... + + .a_button + ld a, c +- cp BLUE_PAGE ; last page ++ cp ORANGE_PAGE ; last page + jr z, .b_button + .d_right + inc c +- ld a, BLUE_PAGE ; last page ++ ld a, ORANGE_PAGE ; last page + cp c + jr nc, .set_page + ld c, PINK_PAGE ; first page + jr .set_page + + .d_left ++ ld a, c + dec c ++ and a ; cp PINK_PAGE ; first page + jr nz, .set_page +- ld c, BLUE_PAGE ; last page ++ ld c, ORANGE_PAGE ; last page + jr .set_page + + .done + ret + + .set_page + ld a, [wcf64] + and %11111100 + or c + ld [wcf64], a + ld h, 4 + call StatsScreen_SetJumptableIndex + ret +``` + +Pressing left and right navigates between the pages, wrapping around the ends if necessary. The orange page is last, not the blue page any more, and some logic also needed updating since a page index of 0 is now possible. + +```diff + StatsScreen_PlacePageSwitchArrows: +- hlcoord 12, 6 ++ hlcoord 10, 6 + ld [hl], "◀" + hlcoord 19, 6 + ld [hl], "▶" + ret +``` + +The arrow left of the page icons needs shifting further left to make room for a fourth icon. + +```diff + StatsScreen_LoadGFX: + ... + + .PageTilemap: + ld a, [wcf64] + maskbits NUM_STAT_PAGES +- dec a + ld hl, .Jumptable + rst JumpTable + ret + + .Jumptable: + ; entries correspond to *_PAGE constants + dw .PinkPage + dw .GreenPage + dw .BluePage ++ dw .OrangePage + + ... + ++.OrangePage: ++ ld de, HelloWorldString ++ hlcoord 1, 9 ++ call PlaceString ++ ret ++ ++HelloWorldString: ++ db "Hello world!@" ++ + IDNoString: + db "<ID>№.@" + + OTString: + db "OT/@" +``` + +This is where we display the actual content of the orange page (as well as another adjustment to account for the pink page's new index 0). This example will just say ["Hello world!"](https://en.wikipedia.org/wiki/%22Hello,_World!%22_program) + +```diff + StatsScreen_LoadPageIndicators: ++ hlcoord 11, 5 ++ ld a, $36 ; " " " " ++ call .load_square + hlcoord 13, 5 + ld a, $36 ; first of 4 small square tiles + call .load_square + hlcoord 15, 5 + ld a, $36 ; " " " " + call .load_square + hlcoord 17, 5 + ld a, $36 ; " " " " + call .load_square + ld a, c +- cp GREEN_PAGE +- ld a, $3a ; first of 4 large square tiles +- hlcoord 13, 5 ; PINK_PAGE (< GREEN_PAGE) +- jr c, .load_square +- hlcoord 15, 5 ; GREEN_PAGE (= GREEN_PAGE) +- jr z, .load_square +- hlcoord 17, 5 ; BLUE_PAGE (> GREEN_PAGE) ++ cp PINK_PAGE ++ hlcoord 11, 5 ++ jr z, .load_highlighted_square ++ cp GREEN_PAGE ++ hlcoord 13, 5 ++ jr z, .load_highlighted_square ++ cp BLUE_PAGE ++ hlcoord 15, 5 ++ jr z, .load_highlighted_square ++ ; must be ORANGE_PAGE ++ hlcoord 17, 5 ++.load_highlighted_square + .load_square + push bc + ld [hli], a + inc a + ld [hld], a + ld bc, SCREEN_WIDTH + add hl, bc + inc a + ld [hli], a + inc a + ld [hl], a + pop bc + ret +``` + +The current page's icon is shown larger than the rest. Apart from changing their coordinates, we also need to update the logic. With only three pages, a single less/equal/greater comparison to the middle page's index was enough to tell which one to highlight, but four pages need more thorough checking. + + +## 4. Account for the shifted page indexes + +Edit [engine/gfx/color.asm](../blob/master/engine/gfx/color.asm): + +```diff + LoadStatsScreenPals: + call CheckCGB + ret z + ld hl, StatsScreenPals + ld b, 0 +- dec c + add hl, bc + add hl, bc + ldh a, [rSVBK] + push af + ld a, BANK(wBGPals1) + ldh [rSVBK], a + ld a, [hli] + ld [wBGPals1 palette 0], a + ld [wBGPals1 palette 2], a + ld a, [hl] + ld [wBGPals1 palette 0 + 1], a + ld [wBGPals1 palette 2 + 1], a + pop af + ldh [rSVBK], a + call ApplyPals + ld a, $1 + ret +``` + +This function used to adjust the page index in `c` from 1–3 to 0–2. Now that indexes are 0–3, they don't need adjustment. + +Now we have a fourth stats page in-game! + + + +TODO: show caught data on the orange page. diff --git a/Tutorials.md b/Tutorials.md index eade602..ba70960 100644 --- a/Tutorials.md +++ b/Tutorials.md @@ -43,6 +43,7 @@ Tutorials may use diff syntax to show edits: - [Player gender](Add-a-new-player-gender) - [Mart (with new dialog and more items)](Add-a-new-Mart) - [Music song](Add-a-new-music-song) +- [Pokémon stats page](Add-a-fourth-stats-page) - [Pack pocket](Add-a-new-Pack-pocket) - [Radio channel](Add-a-new-radio-channel) - [Wild Pokémon slot](Add-a-new-wild-Pokémon-slot) @@ -146,7 +147,6 @@ Feel free to contribute one of these! - More daily and weekly events - Third region - Third trainer card page for Kanto badges -- Fourth stats page for caught data - Colored party menu icons (overworld or battle sprite colors) - Implement dynamic overhead+underfoot bridges - Trainer dialog and music change for their last Pokémon diff --git a/screenshots/fourth-stats-page.png b/screenshots/fourth-stats-page.png Binary files differnew file mode 100644 index 0000000..daeb08a --- /dev/null +++ b/screenshots/fourth-stats-page.png |