Pokedex Plus fixes (#4514)

* Pokedex plus no longer allows browsing unseen evos

* Restore "has no evolutions" printing

* only print "has no evolution" text at 0 depth

* Revert config changes

* fix duplicate icons and removed eevee hardcodes

* add new scope and indentation fixes

* actually introduce new scope
This commit is contained in:
sneed 2024-05-18 11:53:01 +03:00 committed by GitHub
parent 635db6312c
commit 982934c4aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -302,6 +302,7 @@ static const u32 sPokedexPlusHGSS_ScreenSearchNational_Tilemap[] = INCBIN_U32("g
#define MAX_SEARCH_PARAM_CURSOR_POS (MAX_SEARCH_PARAM_ON_SCREEN - 1) #define MAX_SEARCH_PARAM_CURSOR_POS (MAX_SEARCH_PARAM_ON_SCREEN - 1)
#define MAX_MONS_ON_SCREEN 4 #define MAX_MONS_ON_SCREEN 4
#define MAX_EVOLUTION_ICONS 8
#define LIST_SCROLL_STEP 16 #define LIST_SCROLL_STEP 16
@ -596,7 +597,7 @@ static void Task_LoadEvolutionScreen(u8 taskId);
static void Task_HandleEvolutionScreenInput(u8 taskId); static void Task_HandleEvolutionScreenInput(u8 taskId);
static void Task_SwitchScreensFromEvolutionScreen(u8 taskId); static void Task_SwitchScreensFromEvolutionScreen(u8 taskId);
static void Task_ExitEvolutionScreen(u8 taskId); static void Task_ExitEvolutionScreen(u8 taskId);
static u8 PrintEvolutionTargetSpeciesAndMethod(u8 taskId, u16 species, u8 depth, u8 depth_i); static void PrintEvolutionTargetSpeciesAndMethod(u8 taskId, u16 species, u8 depth, u32 *depth_i, u32 alreadyPrintedIcons[], u32 *icon_depth_i);
static u8 PrintPreEvolutions(u8 taskId, u16 species); static u8 PrintPreEvolutions(u8 taskId, u16 species);
//Stat bars on scrolling screens //Stat bars on scrolling screens
static void TryDestroyStatBars(void); static void TryDestroyStatBars(void);
@ -3874,18 +3875,18 @@ static void Task_LoadInfoScreen(u8 taskId)
gMain.state++; gMain.state++;
break; break;
case 6: case 6:
{ {
u32 preservedPalettes = 0; u32 preservedPalettes = 0;
if (gTasks[taskId].tBgLoaded) if (gTasks[taskId].tBgLoaded)
preservedPalettes = 0x14; // each bit represents a palette index preservedPalettes = 0x14; // each bit represents a palette index
if (gTasks[taskId].tMonSpriteDone) if (gTasks[taskId].tMonSpriteDone)
preservedPalettes |= (1 << (gSprites[gTasks[taskId].tMonSpriteId].oam.paletteNum + 16)); preservedPalettes |= (1 << (gSprites[gTasks[taskId].tMonSpriteId].oam.paletteNum + 16));
BeginNormalPaletteFade(~preservedPalettes, 0, 16, 0, RGB_BLACK); BeginNormalPaletteFade(~preservedPalettes, 0, 16, 0, RGB_BLACK);
SetVBlankCallback(gPokedexVBlankCB); SetVBlankCallback(gPokedexVBlankCB);
gMain.state++; gMain.state++;
}
break; break;
}
case 7: case 7:
SetGpuReg(REG_OFFSET_BLDCNT, 0); SetGpuReg(REG_OFFSET_BLDCNT, 0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0); SetGpuReg(REG_OFFSET_BLDALPHA, 0);
@ -4951,7 +4952,7 @@ static void Task_LoadStatsScreen(u8 taskId)
gMain.state++; gMain.state++;
break; break;
case 7: case 7:
{ {
u32 preservedPalettes = 0; u32 preservedPalettes = 0;
if (gTasks[taskId].data[2] != 0) if (gTasks[taskId].data[2] != 0)
@ -4961,8 +4962,8 @@ static void Task_LoadStatsScreen(u8 taskId)
BeginNormalPaletteFade(~preservedPalettes, 0, 16, 0, RGB_BLACK); BeginNormalPaletteFade(~preservedPalettes, 0, 16, 0, RGB_BLACK);
SetVBlankCallback(gPokedexVBlankCB); SetVBlankCallback(gPokedexVBlankCB);
gMain.state++; gMain.state++;
}
break; break;
}
case 8: case 8:
SetGpuReg(REG_OFFSET_BLDCNT, 0); SetGpuReg(REG_OFFSET_BLDCNT, 0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0); SetGpuReg(REG_OFFSET_BLDALPHA, 0);
@ -6078,20 +6079,29 @@ static void Task_LoadEvolutionScreen(u8 taskId)
gMain.state++; gMain.state++;
break; break;
case 4: case 4:
{
u32 alreadyPrintedIcons[MAX_EVOLUTION_ICONS] = {0};
u32 depth = sPokedexView->numPreEvolutions;
u32 iconDepth = depth;
//Print evo info and icons //Print evo info and icons
gTasks[taskId].data[3] = 0; gTasks[taskId].data[3] = 0;
PrintEvolutionTargetSpeciesAndMethod(taskId, NationalPokedexNumToSpeciesHGSS(sPokedexListItem->dexNum), 0, sPokedexView->numPreEvolutions); PrintEvolutionTargetSpeciesAndMethod(taskId, NationalPokedexNumToSpeciesHGSS(sPokedexListItem->dexNum), 0, &depth, alreadyPrintedIcons, &iconDepth);
LoadSpritePalette(&gSpritePalette_Arrow); LoadSpritePalette(&gSpritePalette_Arrow);
GetSeenFlagTargetSpecies(); GetSeenFlagTargetSpecies();
if (sPokedexView->sEvoScreenData.numAllEvolutions != 0 && sPokedexView->sEvoScreenData.numSeen != 0) if (sPokedexView->sEvoScreenData.numAllEvolutions > 0 && sPokedexView->sEvoScreenData.numSeen > 0)
{ {
sPokedexView->sEvoScreenData.arrowSpriteId = CreateSprite(&gSpriteTemplate_Arrow, 7, 58, 0); u32 pos;
for (pos = 0; !sPokedexView->sEvoScreenData.seen[pos]; pos++)
;
sPokedexView->sEvoScreenData.menuPos = pos;
sPokedexView->sEvoScreenData.arrowSpriteId = CreateSprite(&gSpriteTemplate_Arrow, 7, 58 + 9 * pos, 0);
gSprites[sPokedexView->sEvoScreenData.arrowSpriteId].animNum = 2; gSprites[sPokedexView->sEvoScreenData.arrowSpriteId].animNum = 2;
} }
gMain.state++; gMain.state++;
break; break;
}
case 5: case 5:
{ {
u32 preservedPalettes = 0; u32 preservedPalettes = 0;
if (gTasks[taskId].data[2] != 0) if (gTasks[taskId].data[2] != 0)
@ -6101,8 +6111,8 @@ static void Task_LoadEvolutionScreen(u8 taskId)
BeginNormalPaletteFade(~preservedPalettes, 0, 16, 0, RGB_BLACK); BeginNormalPaletteFade(~preservedPalettes, 0, 16, 0, RGB_BLACK);
SetVBlankCallback(gPokedexVBlankCB); SetVBlankCallback(gPokedexVBlankCB);
gMain.state++; gMain.state++;
}
break; break;
}
case 6: case 6:
SetGpuReg(REG_OFFSET_BLDCNT, 0); SetGpuReg(REG_OFFSET_BLDCNT, 0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0); SetGpuReg(REG_OFFSET_BLDALPHA, 0);
@ -6144,34 +6154,36 @@ static void Task_HandleEvolutionScreenInput(u8 taskId)
PlaySE(SE_PIN); PlaySE(SE_PIN);
} }
if (sPokedexView->sEvoScreenData.numAllEvolutions != 0 && sPokedexView->sEvoScreenData.numSeen != 0) if (sPokedexView->sEvoScreenData.numAllEvolutions > 0 && sPokedexView->sEvoScreenData.numSeen > 0)
{ {
u8 base_y = 58; u8 base_y = 58;
u8 base_y_offset = 9; u8 base_y_offset = 9;
u8 pos = sPokedexView->sEvoScreenData.menuPos; u8 pos = sPokedexView->sEvoScreenData.menuPos;
u8 max = sPokedexView->sEvoScreenData.numAllEvolutions; u8 max = sPokedexView->sEvoScreenData.numAllEvolutions - 1;
if (JOY_NEW(DPAD_DOWN)) if (JOY_NEW(DPAD_DOWN))
{ {
while (TRUE) do
{ {
pos += 1; if (pos < max)
if (pos >= max) pos++;
else
pos = 0; pos = 0;
} while (!sPokedexView->sEvoScreenData.seen[pos]);
if (sPokedexView->sEvoScreenData.seen[pos] == TRUE)
break;
}
gSprites[sPokedexView->sEvoScreenData.arrowSpriteId].y = base_y + base_y_offset * pos; gSprites[sPokedexView->sEvoScreenData.arrowSpriteId].y = base_y + base_y_offset * pos;
sPokedexView->sEvoScreenData.menuPos = pos; sPokedexView->sEvoScreenData.menuPos = pos;
} }
else if (JOY_NEW(DPAD_UP)) else if (JOY_NEW(DPAD_UP))
{ {
if (sPokedexView->sEvoScreenData.menuPos == 0) do
sPokedexView->sEvoScreenData.menuPos = sPokedexView->sEvoScreenData.numAllEvolutions - 1; {
else if (pos > 0)
sPokedexView->sEvoScreenData.menuPos -= 1; pos--;
else
pos = max;
} while (!sPokedexView->sEvoScreenData.seen[pos]);
gSprites[sPokedexView->sEvoScreenData.arrowSpriteId].y = base_y + base_y_offset * sPokedexView->sEvoScreenData.menuPos; gSprites[sPokedexView->sEvoScreenData.arrowSpriteId].y = base_y + base_y_offset * pos;
sPokedexView->sEvoScreenData.menuPos = pos;
} }
if (JOY_NEW(A_BUTTON)) if (JOY_NEW(A_BUTTON))
@ -6227,10 +6239,9 @@ static void Task_HandleEvolutionScreenInput(u8 taskId)
} }
} }
static void HandleTargetSpeciesPrint(u8 taskId, u16 targetSpecies, u16 previousTargetSpecies, u8 base_x, u8 base_y, u8 base_y_offset, u8 base_i, bool8 isEevee) static void HandleTargetSpeciesPrintText(u32 targetSpecies, u32 base_x, u32 base_y, u32 base_y_offset, u32 base_i)
{ {
u8 iterations = 6; bool32 seen = GetSetPokedexFlag(SpeciesToNationalPokedexNum(targetSpecies), FLAG_GET_SEEN);
bool8 seen = GetSetPokedexFlag(SpeciesToNationalPokedexNum(targetSpecies), FLAG_GET_SEEN);
if (seen || !HGSS_HIDE_UNSEEN_EVOLUTION_NAMES) if (seen || !HGSS_HIDE_UNSEEN_EVOLUTION_NAMES)
StringCopy(gStringVar3, GetSpeciesName(targetSpecies)); //evolution mon name StringCopy(gStringVar3, GetSpeciesName(targetSpecies)); //evolution mon name
@ -6238,29 +6249,17 @@ static void HandleTargetSpeciesPrint(u8 taskId, u16 targetSpecies, u16 previousT
StringCopy(gStringVar3, gText_ThreeQuestionMarks); //show questionmarks instead of name StringCopy(gStringVar3, gText_ThreeQuestionMarks); //show questionmarks instead of name
StringExpandPlaceholders(gStringVar3, sText_EVO_Name); //evolution mon name StringExpandPlaceholders(gStringVar3, sText_EVO_Name); //evolution mon name
PrintInfoScreenTextSmall(gStringVar3, base_x, base_y + base_y_offset*base_i); //evolution mon name PrintInfoScreenTextSmall(gStringVar3, base_x, base_y + base_y_offset*base_i); //evolution mon name
}
//Print mon icon in the top row static void HandleTargetSpeciesPrintIcon(u8 taskId, u16 targetSpecies, u8 base_i, u8 iterations)
if (isEevee) {
{ u32 personality = GetPokedexMonPersonality(targetSpecies);
iterations = 9; LoadMonIconPalettePersonality(targetSpecies, personality); //Loads pallete for current mon
if (targetSpecies == previousTargetSpecies) if (iterations > 6) // Print icons closer to each other if there are many evolutions
return; gTasks[taskId].data[4+base_i] = CreateMonIcon(targetSpecies, SpriteCB_MonIcon, 45 + 26*base_i, 31, 4, personality);
else if (targetSpecies == SPECIES_GLACEON) else
base_i -= 1; gTasks[taskId].data[4+base_i] = CreateMonIcon(targetSpecies, SpriteCB_MonIcon, 50 + 32*base_i, 31, 4, personality);
else if (targetSpecies == SPECIES_SYLVEON) gSprites[gTasks[taskId].data[4+base_i]].oam.priority = 0;
base_i -= 2;
}
if (base_i < iterations)
{
u32 personality = GetPokedexMonPersonality(targetSpecies);
LoadMonIconPalettePersonality(targetSpecies, personality); //Loads pallete for current mon
if (isEevee)
gTasks[taskId].data[4+base_i] = CreateMonIcon(targetSpecies, SpriteCB_MonIcon, 45 + 26*base_i, 31, 4, personality); //Create pokemon sprite
else
gTasks[taskId].data[4+base_i] = CreateMonIcon(targetSpecies, SpriteCB_MonIcon, 50 + 32*base_i, 31, 4, personality); //Create pokemon sprite
gSprites[gTasks[taskId].data[4+base_i]].oam.priority = 0;
}
} }
static void CreateCaughtBallEvolutionScreen(u16 targetSpecies, u8 x, u8 y, u16 unused) static void CreateCaughtBallEvolutionScreen(u16 targetSpecies, u8 x, u8 y, u16 unused)
@ -6417,12 +6416,11 @@ static u8 PrintPreEvolutions(u8 taskId, u16 species)
#define EVO_SCREEN_CRITS_DIGITS 1 #define EVO_SCREEN_CRITS_DIGITS 1
#define EVO_SCREEN_DMG_DIGITS 2 #define EVO_SCREEN_DMG_DIGITS 2
static u8 PrintEvolutionTargetSpeciesAndMethod(u8 taskId, u16 species, u8 depth, u8 depth_i) static void PrintEvolutionTargetSpeciesAndMethod(u8 taskId, u16 species, u8 depth, u32 *depth_i, u32 alreadyPrintedIcons[], u32 *icon_depth_i)
{ {
u16 i; int i;
const struct MapHeader *mapHeader; const struct MapHeader *mapHeader;
u16 targetSpecies = 0; u16 targetSpecies = 0;
u16 previousTargetSpecies = 0;
u16 item; u16 item;
@ -6431,21 +6429,25 @@ static u8 PrintEvolutionTargetSpeciesAndMethod(u8 taskId, u16 species, u8 depth,
u8 base_x_offset = 54+8; u8 base_x_offset = 54+8;
u8 base_y = 51; u8 base_y = 51;
u8 base_y_offset = 9; u8 base_y_offset = 9;
u8 base_i = 0;
u8 times = 0; u8 times = 0;
u8 depth_x = 16; u8 depth_x = 16;
bool8 isEevee = FALSE;
const struct Evolution *evolutions = GetSpeciesEvolutions(species); const struct Evolution *evolutions = GetSpeciesEvolutions(species);
if (sPokedexView->sEvoScreenData.isMega) if (sPokedexView->sEvoScreenData.isMega)
return 0; return;
if (evolutions == NULL)
return 0;
StringCopy(gStringVar1, GetSpeciesName(species)); StringCopy(gStringVar1, GetSpeciesName(species));
if (species == SPECIES_EEVEE) //If there are no evolutions print text and return
isEevee = TRUE; if (evolutions == NULL)
{
if (depth == 0)
{
StringExpandPlaceholders(gStringVar4, sText_EVO_NONE);
PrintInfoScreenTextSmall(gStringVar4, base_x-7-7, base_y + base_y_offset*(*depth_i));
}
return;
}
//Calculate number of possible direct evolutions (e.g. Eevee has 5 but torchic has 1) //Calculate number of possible direct evolutions (e.g. Eevee has 5 but torchic has 1)
for (i = 0; evolutions[i].method != EVOLUTIONS_END; i++) for (i = 0; evolutions[i].method != EVOLUTIONS_END; i++)
@ -6456,24 +6458,29 @@ static u8 PrintEvolutionTargetSpeciesAndMethod(u8 taskId, u16 species, u8 depth,
gTasks[taskId].data[3] = times; gTasks[taskId].data[3] = times;
sPokedexView->sEvoScreenData.numAllEvolutions += times; sPokedexView->sEvoScreenData.numAllEvolutions += times;
//If there are no evolutions print text
if (times == 0 && depth == 0)
{
StringExpandPlaceholders(gStringVar4, sText_EVO_NONE);
PrintInfoScreenTextSmall(gStringVar4, base_x-7-7, base_y + base_y_offset*depth_i);
}
//If there are evolutions find out which and print them 1 by 1 //If there are evolutions find out which and print them 1 by 1
for (i = 0; i < times; i++) for (i = 0; i < times; i++)
{ {
base_i = i + depth_i; int j;
left = !left; left = !left;
previousTargetSpecies = targetSpecies;
targetSpecies = evolutions[i].targetSpecies; targetSpecies = evolutions[i].targetSpecies;
sPokedexView->sEvoScreenData.targetSpecies[base_i] = targetSpecies; sPokedexView->sEvoScreenData.targetSpecies[*depth_i] = targetSpecies;
CreateCaughtBallEvolutionScreen(targetSpecies, base_x + depth_x*depth-9, base_y + base_y_offset*base_i, 0); CreateCaughtBallEvolutionScreen(targetSpecies, base_x + depth_x*depth-9, base_y + base_y_offset*(*depth_i), 0);
HandleTargetSpeciesPrint(taskId, targetSpecies, previousTargetSpecies, base_x + depth_x*depth, base_y, base_y_offset, base_i, isEevee); //evolution mon name HandleTargetSpeciesPrintText(targetSpecies, base_x + depth_x*depth, base_y, base_y_offset, *depth_i); //evolution mon name
for (j = 0; j < MAX_EVOLUTION_ICONS; j++)
{
if (alreadyPrintedIcons[j] == targetSpecies)
break;
if (alreadyPrintedIcons[j] == SPECIES_NONE)
{
HandleTargetSpeciesPrintIcon(taskId, targetSpecies, *icon_depth_i, times);
alreadyPrintedIcons[j] = targetSpecies;
(*icon_depth_i)++;
break;
}
}
switch (evolutions[i].method) switch (evolutions[i].method)
{ {
@ -6665,12 +6672,11 @@ static u8 PrintEvolutionTargetSpeciesAndMethod(u8 taskId, u16 species, u8 depth,
StringExpandPlaceholders(gStringVar4, sText_EVO_UNKNOWN ); StringExpandPlaceholders(gStringVar4, sText_EVO_UNKNOWN );
break; break;
}//Switch end }//Switch end
PrintInfoScreenTextSmall(gStringVar4, base_x + depth_x*depth+base_x_offset, base_y + base_y_offset*base_i); //Print actual instructions PrintInfoScreenTextSmall(gStringVar4, base_x + depth_x*depth+base_x_offset, base_y + base_y_offset*(*depth_i)); //Print actual instructions
depth_i += PrintEvolutionTargetSpeciesAndMethod(taskId, targetSpecies, depth+1, base_i+1); (*depth_i)++;
PrintEvolutionTargetSpeciesAndMethod(taskId, targetSpecies, depth+1, depth_i, alreadyPrintedIcons, icon_depth_i);
}//For loop end }//For loop end
return times;
} }
static void Task_SwitchScreensFromEvolutionScreen(u8 taskId) static void Task_SwitchScreensFromEvolutionScreen(u8 taskId)
@ -6792,7 +6798,7 @@ static void Task_LoadFormsScreen(u8 taskId)
gMain.state++; gMain.state++;
break; break;
case 5: case 5:
{ {
u32 preservedPalettes = 0; u32 preservedPalettes = 0;
if (gTasks[taskId].data[2] != 0) if (gTasks[taskId].data[2] != 0)
@ -6802,8 +6808,8 @@ static void Task_LoadFormsScreen(u8 taskId)
BeginNormalPaletteFade(~preservedPalettes, 0, 16, 0, RGB_BLACK); BeginNormalPaletteFade(~preservedPalettes, 0, 16, 0, RGB_BLACK);
SetVBlankCallback(gPokedexVBlankCB); SetVBlankCallback(gPokedexVBlankCB);
gMain.state++; gMain.state++;
}
break; break;
}
case 6: case 6:
SetGpuReg(REG_OFFSET_BLDCNT, 0); SetGpuReg(REG_OFFSET_BLDCNT, 0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0); SetGpuReg(REG_OFFSET_BLDALPHA, 0);
@ -7082,7 +7088,7 @@ static void Task_LoadCryScreen(u8 taskId)
gMain.state++; gMain.state++;
break; break;
case 6: case 6:
{ {
struct CryScreenWindow waveformWindow; struct CryScreenWindow waveformWindow;
waveformWindow.unk0 = 0x4020; waveformWindow.unk0 = 0x4020;
@ -7095,10 +7101,10 @@ static void Task_LoadCryScreen(u8 taskId)
gMain.state++; gMain.state++;
gDexCryScreenState = 0; gDexCryScreenState = 0;
} }
}
break; break;
}
case 7: case 7:
{ {
struct CryScreenWindow cryMeter; struct CryScreenWindow cryMeter;
cryMeter.paletteNo = 9; cryMeter.paletteNo = 9;
@ -7112,8 +7118,8 @@ static void Task_LoadCryScreen(u8 taskId)
CopyBgTilemapBufferToVram(1); CopyBgTilemapBufferToVram(1);
CopyBgTilemapBufferToVram(2); CopyBgTilemapBufferToVram(2);
CopyBgTilemapBufferToVram(3); CopyBgTilemapBufferToVram(3);
}
break; break;
}
case 8: case 8:
BeginNormalPaletteFade(PALETTES_ALL & ~(0x14), 0, 0x10, 0, RGB_BLACK); BeginNormalPaletteFade(PALETTES_ALL & ~(0x14), 0, 0x10, 0, RGB_BLACK);
SetVBlankCallback(gPokedexVBlankCB); SetVBlankCallback(gPokedexVBlankCB);
@ -7252,15 +7258,15 @@ static void Task_LoadSizeScreen(u8 taskId)
gMain.state++; gMain.state++;
break; break;
case 3: case 3:
{ {
u8 string[64]; u8 string[64];
StringCopy(string, gText_SizeComparedTo); StringCopy(string, gText_SizeComparedTo);
StringAppend(string, gSaveBlock2Ptr->playerName); StringAppend(string, gSaveBlock2Ptr->playerName);
PrintInfoScreenText(string, GetStringCenterAlignXOffset(FONT_NORMAL, string, 0xF0), 0x79); PrintInfoScreenText(string, GetStringCenterAlignXOffset(FONT_NORMAL, string, 0xF0), 0x79);
gMain.state++; gMain.state++;
}
break; break;
}
case 4: case 4:
ResetPaletteFade(); ResetPaletteFade();
gMain.state++; gMain.state++;