2018-02-02 16:06:20 +01:00
|
|
|
#include "global.h"
|
2018-12-03 16:10:41 +01:00
|
|
|
#include "decompress.h"
|
|
|
|
#include "graphics.h"
|
2018-02-02 16:06:20 +01:00
|
|
|
#include "item_icon.h"
|
2018-11-29 12:24:28 +01:00
|
|
|
#include "alloc.h"
|
2018-02-02 16:06:20 +01:00
|
|
|
#include "sprite.h"
|
|
|
|
#include "constants/items.h"
|
|
|
|
|
|
|
|
// EWRAM vars
|
|
|
|
EWRAM_DATA void *gItemIconDecompressionBuffer = NULL;
|
|
|
|
EWRAM_DATA void *gItemIcon4x4Buffer = NULL;
|
|
|
|
|
|
|
|
// const rom data
|
2018-12-03 16:10:41 +01:00
|
|
|
#include "data/item_icon_table.h"
|
2018-02-02 16:06:20 +01:00
|
|
|
|
|
|
|
static const struct OamData sOamData_ItemIcon =
|
|
|
|
{
|
|
|
|
.y = 0,
|
|
|
|
.affineMode = 0,
|
|
|
|
.objMode = 0,
|
|
|
|
.mosaic = 0,
|
|
|
|
.bpp = 0,
|
|
|
|
.shape = 0,
|
|
|
|
.x = 0,
|
|
|
|
.matrixNum = 0,
|
|
|
|
.size = 2,
|
|
|
|
.tileNum = 0,
|
|
|
|
.priority = 1,
|
|
|
|
.paletteNum = 2,
|
|
|
|
.affineParam = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd sSpriteAnim_ItemIcon[] =
|
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 0),
|
|
|
|
ANIMCMD_END
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd *const sSpriteAnimTable_ItemIcon[] =
|
|
|
|
{
|
|
|
|
sSpriteAnim_ItemIcon
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct SpriteTemplate gItemIconSpriteTemplate =
|
|
|
|
{
|
|
|
|
.tileTag = 0,
|
|
|
|
.paletteTag = 0,
|
|
|
|
.oam = &sOamData_ItemIcon,
|
|
|
|
.anims = sSpriteAnimTable_ItemIcon,
|
|
|
|
.images = NULL,
|
|
|
|
.affineAnims = gDummySpriteAffineAnimTable,
|
|
|
|
.callback = SpriteCallbackDummy,
|
|
|
|
};
|
|
|
|
|
|
|
|
// code
|
|
|
|
bool8 AllocItemIconTemporaryBuffers(void)
|
|
|
|
{
|
|
|
|
gItemIconDecompressionBuffer = gItemIconDecompressionBuffer; // needed to match
|
|
|
|
gItemIconDecompressionBuffer = Alloc(0x120);
|
|
|
|
if (gItemIconDecompressionBuffer == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gItemIcon4x4Buffer = gItemIcon4x4Buffer; // needed to match
|
|
|
|
gItemIcon4x4Buffer = AllocZeroed(0x200);
|
|
|
|
if (gItemIcon4x4Buffer == NULL)
|
|
|
|
{
|
|
|
|
Free(gItemIconDecompressionBuffer);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FreeItemIconTemporaryBuffers(void)
|
|
|
|
{
|
|
|
|
Free(gItemIconDecompressionBuffer);
|
|
|
|
Free(gItemIcon4x4Buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CopyItemIconPicTo4x4Buffer(const void *src, void *dest)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
CpuCopy16(src + i * 96, dest + i * 128, 0x60);
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 AddItemIconSprite(u16 tilesTag, u16 paletteTag, u16 itemId)
|
|
|
|
{
|
|
|
|
if (!AllocItemIconTemporaryBuffers())
|
|
|
|
{
|
|
|
|
return MAX_SPRITES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
u8 spriteId;
|
|
|
|
struct SpriteSheet spriteSheet;
|
|
|
|
struct CompressedSpritePalette spritePalette;
|
|
|
|
struct SpriteTemplate *spriteTemplate;
|
|
|
|
|
|
|
|
LZDecompressWram(GetItemIconPicOrPalette(itemId, 0), gItemIconDecompressionBuffer);
|
|
|
|
CopyItemIconPicTo4x4Buffer(gItemIconDecompressionBuffer, gItemIcon4x4Buffer);
|
|
|
|
spriteSheet.data = gItemIcon4x4Buffer;
|
|
|
|
spriteSheet.size = 0x200;
|
|
|
|
spriteSheet.tag = tilesTag;
|
|
|
|
LoadSpriteSheet(&spriteSheet);
|
|
|
|
|
|
|
|
spritePalette.data = GetItemIconPicOrPalette(itemId, 1);
|
|
|
|
spritePalette.tag = paletteTag;
|
|
|
|
LoadCompressedObjectPalette(&spritePalette);
|
|
|
|
|
|
|
|
spriteTemplate = Alloc(sizeof(*spriteTemplate));
|
|
|
|
CpuCopy16(&gItemIconSpriteTemplate, spriteTemplate, sizeof(*spriteTemplate));
|
|
|
|
spriteTemplate->tileTag = tilesTag;
|
|
|
|
spriteTemplate->paletteTag = paletteTag;
|
|
|
|
spriteId = CreateSprite(spriteTemplate, 0, 0, 0);
|
|
|
|
|
|
|
|
FreeItemIconTemporaryBuffers();
|
|
|
|
Free(spriteTemplate);
|
|
|
|
|
|
|
|
return spriteId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 AddCustomItemIconSprite(struct SpriteTemplate *customSpriteTemplate, u16 tilesTag, u16 paletteTag, u16 itemId)
|
|
|
|
{
|
|
|
|
if (!AllocItemIconTemporaryBuffers())
|
|
|
|
{
|
|
|
|
return MAX_SPRITES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
u8 spriteId;
|
|
|
|
struct SpriteSheet spriteSheet;
|
|
|
|
struct CompressedSpritePalette spritePalette;
|
|
|
|
struct SpriteTemplate *spriteTemplate;
|
|
|
|
|
|
|
|
LZDecompressWram(GetItemIconPicOrPalette(itemId, 0), gItemIconDecompressionBuffer);
|
|
|
|
CopyItemIconPicTo4x4Buffer(gItemIconDecompressionBuffer, gItemIcon4x4Buffer);
|
|
|
|
spriteSheet.data = gItemIcon4x4Buffer;
|
|
|
|
spriteSheet.size = 0x200;
|
|
|
|
spriteSheet.tag = tilesTag;
|
|
|
|
LoadSpriteSheet(&spriteSheet);
|
|
|
|
|
|
|
|
spritePalette.data = GetItemIconPicOrPalette(itemId, 1);
|
|
|
|
spritePalette.tag = paletteTag;
|
|
|
|
LoadCompressedObjectPalette(&spritePalette);
|
|
|
|
|
|
|
|
spriteTemplate = Alloc(sizeof(*spriteTemplate));
|
|
|
|
CpuCopy16(customSpriteTemplate, spriteTemplate, sizeof(*spriteTemplate));
|
|
|
|
spriteTemplate->tileTag = tilesTag;
|
|
|
|
spriteTemplate->paletteTag = paletteTag;
|
|
|
|
spriteId = CreateSprite(spriteTemplate, 0, 0, 0);
|
|
|
|
|
|
|
|
FreeItemIconTemporaryBuffers();
|
|
|
|
Free(spriteTemplate);
|
|
|
|
|
|
|
|
return spriteId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const void *GetItemIconPicOrPalette(u16 itemId, u8 which)
|
|
|
|
{
|
2018-12-05 15:31:01 +01:00
|
|
|
if (itemId == 0xFFFF)
|
2018-02-02 16:06:20 +01:00
|
|
|
itemId = ITEM_FIELD_ARROW;
|
2018-07-07 14:24:19 +02:00
|
|
|
else if (itemId >= ITEMS_COUNT)
|
2018-02-02 16:06:20 +01:00
|
|
|
itemId = 0;
|
|
|
|
|
|
|
|
return gItemIconTable[itemId][which];
|
|
|
|
}
|