Fix a sprite issue with B_SHOW_TYPES (#5157)

* Fixed issue where tiles were not freed

* Updated to destroy first

* Cleaned up returns

* Added typeIconTags
Added FreeAllTypeIconResources
Fixed issue where typeIcons were not being properly handled when hidden
This commit is contained in:
psf 2024-08-13 15:42:39 -07:00 committed by GitHub
parent f18859ac33
commit 38752b59b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -28,6 +28,7 @@ static bool32 ShouldFlipTypeIcon(bool32, u32, u32);
static void SpriteCB_TypeIcon(struct Sprite*);
static void DestroyTypeIcon(struct Sprite*);
static void FreeAllTypeIconResources(void);
static bool32 ShouldHideTypeIcon(u32);
static s32 GetTypeIconHideMovement(bool32, u32);
static s32 GetTypeIconSlideMovement(bool32, u32, s32);
@ -429,22 +430,45 @@ static void SpriteCB_TypeIcon(struct Sprite* sprite)
sprite->y = GetTypeIconBounceMovement(sprite->tVerticalPosition,position);
}
static const u32 typeIconTags[] =
{
TYPE_ICON_TAG,
TYPE_ICON_TAG_2
};
static void DestroyTypeIcon(struct Sprite* sprite)
{
u32 i;
u32 spriteId, tag;
DestroySpriteAndFreeResources(sprite);
for (i = 0; i < MAX_SPRITES; ++i)
for (spriteId = 0; spriteId < MAX_SPRITES; ++spriteId)
{
if (!gSprites[i].inUse)
if (!gSprites[spriteId].inUse)
continue;
if (gSprites[i].template->paletteTag == TYPE_ICON_TAG)
return;
for (tag = 0; tag < 2; tag++)
{
if (gSprites[spriteId].template->paletteTag == typeIconTags[tag])
return;
if (gSprites[spriteId].template->tileTag == typeIconTags[tag])
return;
}
}
FreeSpritePaletteByTag(TYPE_ICON_TAG);
FreeSpritePaletteByTag(TYPE_ICON_TAG_2);
FreeAllTypeIconResources();
}
static void FreeAllTypeIconResources(void)
{
u32 tag;
for (tag = 0; tag < 2; tag++)
{
FreeSpriteTilesByTag(typeIconTags[tag]);
FreeSpritePaletteByTag(typeIconTags[tag]);
}
}
static bool32 ShouldHideTypeIcon(u32 battlerId)