pokeemerald/src/mail.c

555 lines
17 KiB
C
Raw Normal View History

2017-10-12 21:59:43 +02:00
#include "global.h"
2017-12-03 19:19:11 +01:00
#include "mail.h"
2017-12-05 18:55:48 +01:00
#include "constants/items.h"
2017-10-12 21:59:43 +02:00
#include "main.h"
2017-10-14 15:52:56 +02:00
#include "overworld.h"
2017-10-13 04:59:01 +02:00
#include "task.h"
2018-01-29 17:47:12 +01:00
#include "scanline_effect.h"
2017-10-13 04:59:01 +02:00
#include "palette.h"
2017-11-19 22:48:46 +01:00
#include "text.h"
2017-10-13 04:59:01 +02:00
#include "menu.h"
2017-10-13 05:05:36 +02:00
#include "menu_helpers.h"
2017-10-13 04:59:01 +02:00
#include "text_window.h"
2017-10-13 14:47:26 +02:00
#include "string_util.h"
#include "international_string_util.h"
#include "strings.h"
2017-10-13 04:59:01 +02:00
#include "gpu_regs.h"
#include "bg.h"
#include "pokemon_icon.h"
2017-12-11 19:27:51 +01:00
#include "constants/species.h"
2017-10-12 21:59:43 +02:00
#include "malloc.h"
#include "easy_chat.h"
2017-12-03 19:19:11 +01:00
2017-12-28 23:15:37 +01:00
extern const u16 gMailPalette_Orange[];
extern const u16 gMailPalette_Harbor[];
extern const u16 gMailPalette_Glitter[];
extern const u16 gMailPalette_Mech[];
extern const u16 gMailPalette_Wood[];
extern const u16 gMailPalette_Wave[];
extern const u16 gMailPalette_Bead[];
extern const u16 gMailPalette_Shadow[];
extern const u16 gMailPalette_Tropic[];
extern const u16 gMailPalette_Dream[];
extern const u16 gMailPalette_Fab[];
extern const u16 gMailPalette_Retro[];
extern const u8 gMailTiles_Orange[];
extern const u8 gMailTilemap_Orange[];
extern const u8 gMailTiles_Harbor[];
extern const u8 gMailTilemap_Harbor[];
extern const u8 gMailTiles_Glitter[];
extern const u8 gMailTilemap_Glitter[];
extern const u8 gMailTiles_Mech[];
extern const u8 gMailTilemap_Mech[];
extern const u8 gMailTiles_Wood[];
extern const u8 gMailTilemap_Wood[];
extern const u8 gMailTiles_Wave[];
extern const u8 gMailTilemap_Wave[];
extern const u8 gMailTiles_Bead[];
extern const u8 gMailTilemap_Bead[];
extern const u8 gMailTiles_Shadow[];
extern const u8 gMailTilemap_Shadow[];
extern const u8 gMailTiles_Tropic[];
extern const u8 gMailTilemap_Tropic[];
extern const u8 gMailTiles_Dream[];
extern const u8 gMailTilemap_Dream[];
extern const u8 gMailTiles_Fab[];
extern const u8 gMailTilemap_Fab[];
extern const u8 gMailTiles_Retro[];
extern const u8 gMailTilemap_Retro[];
2017-10-12 21:59:43 +02:00
// Static type declarations
struct UnkMailStruct
{
2017-10-13 18:19:51 +02:00
u32 numEasyChatWords:2;
u32 xOffset:6;
u32 lineHeight:8;
2017-10-12 21:59:43 +02:00
};
struct MailLayout
{
2017-10-13 18:19:51 +02:00
u8 numSubStructs;
u8 signatureYPos;
u8 signatureWidth;
u8 wordsXPos;
u8 wordsYPos;
2017-10-13 06:11:55 +02:00
const struct UnkMailStruct *var8;
2017-10-12 21:59:43 +02:00
};
2017-10-13 18:19:51 +02:00
struct MailGraphics
{
const u16 *palette;
const u8 *tiles;
const u8 *tileMap;
u16 var0C;
u16 var0E;
u16 color10;
u16 color12;
};
2017-12-03 19:19:11 +01:00
struct MailRead
2017-10-12 21:59:43 +02:00
{
2017-10-13 14:47:26 +02:00
/*0x0000*/ u8 strbuf[8][64];
/*0x0200*/ u8 playerName[12];
2017-10-12 21:59:43 +02:00
/*0x020C*/ MainCallback callback;
2017-10-13 04:59:01 +02:00
/*0x0210*/ MainCallback callback2;
2017-10-12 21:59:43 +02:00
/*0x0214*/ struct MailStruct *mail;
/*0x0218*/ bool8 flag;
2017-10-13 17:47:17 +02:00
/*0x0219*/ u8 signatureWidth;
2017-10-12 21:59:43 +02:00
/*0x021a*/ u8 mailType;
2017-10-13 18:03:15 +02:00
/*0x021b*/ u8 animsActive;
/*0x021c*/ u8 monIconSprite;
2017-10-12 21:59:43 +02:00
/*0x021d*/ u8 language;
/*0x021e*/ bool8 playerIsSender;
/*0x0220*/ void (*parserSingle)(u8 *dest, u16 word);
/*0x0224*/ void (*parserMultiple)(u8 *dest, const u16 *src, u16 length1, u16 length2);
/*0x0228*/ const struct MailLayout *layout;
2017-10-13 04:59:01 +02:00
/*0x022c*/ u8 bg1TilemapBuffer[0x1000];
/*0x122c*/ u8 bg2TilemapBuffer[0x1000];
2017-12-03 19:19:11 +01:00
};
// Static RAM declarations
static EWRAM_DATA struct MailRead *sMailRead = NULL;
2017-10-12 21:59:43 +02:00
// Static ROM declarations
2017-12-03 19:19:11 +01:00
static void CB2_InitMailRead(void);
static void sub_8121A1C(void);
static void sub_8121B1C(void);
static void VBlankCB_MailRead(void);
static void CB2_MailRead(void);
static void CB2_WaitForPaletteExitOnKeyPress(void);
static void CB2_ExitOnKeyPress(void);
static void CB2_ExitMailReadFreeVars(void);
2017-10-12 21:59:43 +02:00
// .rodata
2017-12-03 19:19:11 +01:00
static const struct BgTemplate sUnknown_0859F290[] = {
2017-10-13 06:11:55 +02:00
{
.bg = 0,
.charBaseIndex = 2,
.mapBaseIndex = 31,
.priority = 0
}, {
.bg = 1,
.charBaseIndex = 0,
.mapBaseIndex = 30,
.priority = 1
}, {
.bg = 2,
.charBaseIndex = 0,
.mapBaseIndex = 29,
.priority = 2
}
};
2017-12-03 19:19:11 +01:00
static const struct WindowTemplate sUnknown_0859F29C[] = {
2017-10-13 06:11:55 +02:00
{
.priority = 0,
.tilemapLeft = 2,
.tilemapTop = 3,
.width = 26,
.height = 15,
.paletteNum = 15,
.baseBlock = 1
2017-10-13 14:47:26 +02:00
},
DUMMY_WIN_TEMPLATE
2017-10-13 06:11:55 +02:00
};
2017-12-03 19:19:11 +01:00
static const u8 sUnknown_0859F2AC[] = {
2017-10-13 06:11:55 +02:00
0,
10,
11
};
2017-12-03 19:19:11 +01:00
static const u16 sUnknown_0859F2B0[][2] = {
2017-10-13 06:11:55 +02:00
{ 0x6ACD, 0x51A5 },
{ 0x45FC, 0x38D4 }
};
2017-12-03 19:19:11 +01:00
static const struct MailGraphics sUnknown_0859F2B8[] = {
2017-10-13 06:11:55 +02:00
{
2017-12-28 23:15:37 +01:00
gMailPalette_Orange, gMailTiles_Orange, gMailTilemap_Orange, 0x02c0, 0x0000, 0x294a, 0x6739
2017-10-13 06:11:55 +02:00
}, {
2017-12-28 23:15:37 +01:00
gMailPalette_Harbor, gMailTiles_Harbor, gMailTilemap_Harbor, 0x02e0, 0x0000, 0x7fff, 0x4631
2017-10-13 06:11:55 +02:00
}, {
2017-12-28 23:15:37 +01:00
gMailPalette_Glitter, gMailTiles_Glitter, gMailTilemap_Glitter, 0x0400, 0x0000, 0x294a, 0x6739
2017-10-13 06:11:55 +02:00
}, {
2017-12-28 23:15:37 +01:00
gMailPalette_Mech, gMailTiles_Mech, gMailTilemap_Mech, 0x01e0, 0x0000, 0x7fff, 0x4631
2017-10-13 06:11:55 +02:00
}, {
2017-12-28 23:15:37 +01:00
gMailPalette_Wood, gMailTiles_Wood, gMailTilemap_Wood, 0x02e0, 0x0000, 0x7fff, 0x4631
2017-10-13 06:11:55 +02:00
}, {
2017-12-28 23:15:37 +01:00
gMailPalette_Wave, gMailTiles_Wave, gMailTilemap_Wave, 0x0300, 0x0000, 0x294a, 0x6739
2017-10-13 06:11:55 +02:00
}, {
2017-12-28 23:15:37 +01:00
gMailPalette_Bead, gMailTiles_Bead, gMailTilemap_Bead, 0x0140, 0x0000, 0x7fff, 0x4631
2017-10-13 06:11:55 +02:00
}, {
2017-12-28 23:15:37 +01:00
gMailPalette_Shadow, gMailTiles_Shadow, gMailTilemap_Shadow, 0x0300, 0x0000, 0x7fff, 0x4631
2017-10-13 06:11:55 +02:00
}, {
2017-12-28 23:15:37 +01:00
gMailPalette_Tropic, gMailTiles_Tropic, gMailTilemap_Tropic, 0x0220, 0x0000, 0x294a, 0x6739
2017-10-13 06:11:55 +02:00
}, {
2017-12-28 23:15:37 +01:00
gMailPalette_Dream, gMailTiles_Dream, gMailTilemap_Dream, 0x0340, 0x0000, 0x294a, 0x6739
2017-10-13 06:11:55 +02:00
}, {
2017-12-28 23:15:37 +01:00
gMailPalette_Fab, gMailTiles_Fab, gMailTilemap_Fab, 0x02a0, 0x0000, 0x294a, 0x6739
2017-10-13 06:11:55 +02:00
}, {
2017-12-28 23:15:37 +01:00
gMailPalette_Retro, gMailTiles_Retro, gMailTilemap_Retro, 0x0520, 0x0000, 0x294a, 0x6739
2017-10-13 06:11:55 +02:00
}
};
2017-12-03 19:19:11 +01:00
static const struct UnkMailStruct Unknown_0859F3A8[] = {
2017-10-13 18:19:51 +02:00
{ .numEasyChatWords = 3, .lineHeight = 16 },
{ .numEasyChatWords = 3, .lineHeight = 16 },
{ .numEasyChatWords = 3, .lineHeight = 16 }
2017-10-13 06:11:55 +02:00
};
2017-12-03 19:19:11 +01:00
static const struct MailLayout sUnknown_0859F3B4[] = {
2017-10-13 17:47:17 +02:00
{ 0x03, 0x00, 0x00, 0x02, 0x04, Unknown_0859F3A8 },
{ 0x03, 0x00, 0x00, 0x02, 0x04, Unknown_0859F3A8 },
{ 0x03, 0x00, 0x00, 0x02, 0x04, Unknown_0859F3A8 },
{ 0x03, 0x00, 0x00, 0x02, 0x04, Unknown_0859F3A8 },
{ 0x03, 0x00, 0x00, 0x02, 0x04, Unknown_0859F3A8 },
{ 0x03, 0x00, 0x00, 0x02, 0x04, Unknown_0859F3A8 },
{ 0x03, 0x00, 0x00, 0x02, 0x04, Unknown_0859F3A8 },
{ 0x03, 0x00, 0x00, 0x02, 0x04, Unknown_0859F3A8 },
{ 0x03, 0x00, 0x00, 0x02, 0x04, Unknown_0859F3A8 },
{ 0x03, 0x00, 0x00, 0x02, 0x04, Unknown_0859F3A8 },
{ 0x03, 0x08, 0x00, 0x02, 0x04, Unknown_0859F3A8 },
{ 0x03, 0x00, 0x00, 0x02, 0x00, Unknown_0859F3A8 }
2017-10-13 06:11:55 +02:00
};
2017-12-03 19:19:11 +01:00
static const struct UnkMailStruct Unknown_0859F444[] = {
2017-10-13 18:19:51 +02:00
{ .numEasyChatWords = 2, .lineHeight = 16 },
{ .numEasyChatWords = 2, .lineHeight = 16 },
{ .numEasyChatWords = 2, .lineHeight = 16 },
{ .numEasyChatWords = 2, .lineHeight = 16 },
{ .numEasyChatWords = 1, .lineHeight = 16 }
2017-10-13 06:11:55 +02:00
};
2017-12-03 19:19:11 +01:00
static const struct MailLayout sUnknown_0859F458[] = {
2017-10-13 17:47:17 +02:00
{ 0x05, 0x07, 0x58, 0x0b, 0x1e, Unknown_0859F444 },
{ 0x05, 0x0a, 0x60, 0x09, 0x1e, Unknown_0859F444 },
{ 0x05, 0x0c, 0x68, 0x05, 0x1e, Unknown_0859F444 },
{ 0x05, 0x05, 0x60, 0x08, 0x1e, Unknown_0859F444 },
{ 0x05, 0x0a, 0x60, 0x09, 0x1e, Unknown_0859F444 },
{ 0x05, 0x09, 0x70, 0x05, 0x1e, Unknown_0859F444 },
{ 0x05, 0x0c, 0x68, 0x09, 0x1e, Unknown_0859F444 },
{ 0x05, 0x0d, 0x68, 0x0d, 0x1e, Unknown_0859F444 },
{ 0x05, 0x09, 0x60, 0x09, 0x1e, Unknown_0859F444 },
{ 0x05, 0x09, 0x60, 0x09, 0x1e, Unknown_0859F444 },
{ 0x05, 0x11, 0x68, 0x0f, 0x1e, Unknown_0859F444 },
{ 0x05, 0x09, 0x60, 0x05, 0x1e, Unknown_0859F444 }
2017-10-13 06:11:55 +02:00
};
2017-10-12 21:59:43 +02:00
// .text
2017-12-03 19:19:11 +01:00
void ReadMail(struct MailStruct *mail, void (*callback)(void), bool8 flag)
{
2017-10-12 21:59:43 +02:00
u16 buffer[2];
u16 species;
2017-12-03 19:19:11 +01:00
sMailRead = calloc(1, sizeof(*sMailRead));
sMailRead->language = LANGUAGE_ENGLISH;
sMailRead->playerIsSender = TRUE;
sMailRead->parserSingle = CopyEasyChatWord;
sMailRead->parserMultiple = ConvertEasyChatWordsToString;
if (IS_ITEM_MAIL(mail->itemId))
{
sMailRead->mailType = mail->itemId - ITEM_ORANGE_MAIL;
2017-10-12 21:59:43 +02:00
}
else
{
2017-12-03 19:19:11 +01:00
sMailRead->mailType = 0;
2017-10-12 21:59:43 +02:00
flag = FALSE;
}
2017-12-03 19:19:11 +01:00
switch (sMailRead->playerIsSender)
2017-10-12 21:59:43 +02:00
{
case FALSE:
default:
2017-12-03 19:19:11 +01:00
sMailRead->layout = &sUnknown_0859F3B4[sMailRead->mailType];
2017-10-12 21:59:43 +02:00
break;
case TRUE:
2017-12-03 19:19:11 +01:00
sMailRead->layout = &sUnknown_0859F458[sMailRead->mailType];
2017-10-12 21:59:43 +02:00
break;
}
2017-12-03 19:19:11 +01:00
species = MailSpeciesToSpecies(mail->species, buffer);
2017-10-12 21:59:43 +02:00
if (species >= SPECIES_BULBASAUR && species < NUM_SPECIES)
{
2017-12-03 19:19:11 +01:00
switch (sMailRead->mailType)
2017-10-12 21:59:43 +02:00
{
default:
2017-12-03 19:19:11 +01:00
sMailRead->animsActive = 0;
2017-10-12 21:59:43 +02:00
break;
case ITEM_BEAD_MAIL - ITEM_ORANGE_MAIL:
2017-12-03 19:19:11 +01:00
sMailRead->animsActive = 1;
2017-10-12 21:59:43 +02:00
break;
case ITEM_DREAM_MAIL - ITEM_ORANGE_MAIL:
2017-12-03 19:19:11 +01:00
sMailRead->animsActive = 2;
2017-10-12 21:59:43 +02:00
break;
}
}
else
{
2017-12-03 19:19:11 +01:00
sMailRead->animsActive = 0;
2017-10-12 21:59:43 +02:00
}
2017-12-03 19:19:11 +01:00
sMailRead->mail = mail;
sMailRead->callback = callback;
sMailRead->flag = flag;
SetMainCallback2(CB2_InitMailRead);
2017-10-12 21:59:43 +02:00
}
2017-10-13 04:59:01 +02:00
2017-12-03 19:19:11 +01:00
static bool8 MailReadBuildGraphics(void)
2017-10-13 04:59:01 +02:00
{
u16 icon;
switch (gMain.state)
{
case 0:
SetVBlankCallback(NULL);
2018-01-16 18:59:06 +01:00
ScanlineEffect_Stop();
2017-10-13 04:59:01 +02:00
SetGpuReg(REG_OFFSET_DISPCNT, 0x0000);
break;
case 1:
CpuFill16(0, (void *)OAM, OAM_SIZE);
break;
case 2:
ResetPaletteFade();
break;
case 3:
ResetTasks();
break;
case 4:
ResetSpriteData();
break;
case 5:
FreeAllSpritePalettes();
reset_temp_tile_data_buffers();
SetGpuReg(REG_OFFSET_BG0HOFS, 0x0000);
SetGpuReg(REG_OFFSET_BG0VOFS, 0x0000);
SetGpuReg(REG_OFFSET_BG1HOFS, 0x0000);
SetGpuReg(REG_OFFSET_BG1VOFS, 0x0000);
SetGpuReg(REG_OFFSET_BG2VOFS, 0x0000);
SetGpuReg(REG_OFFSET_BG2HOFS, 0x0000);
SetGpuReg(REG_OFFSET_BG3HOFS, 0x0000);
SetGpuReg(REG_OFFSET_BG3VOFS, 0x0000);
2017-12-03 19:19:11 +01:00
SetGpuReg(REG_OFFSET_BLDCNT, 0x0000);
2017-10-13 04:59:01 +02:00
SetGpuReg(REG_OFFSET_BLDALPHA, 0x0000);
break;
case 6:
ResetBgsAndClearDma3BusyFlags(0);
2017-12-03 19:19:11 +01:00
InitBgsFromTemplates(0, sUnknown_0859F290, 3);
SetBgTilemapBuffer(1, sMailRead->bg1TilemapBuffer);
SetBgTilemapBuffer(2, sMailRead->bg2TilemapBuffer);
2017-10-13 04:59:01 +02:00
break;
case 7:
2017-12-03 19:19:11 +01:00
InitWindows(sUnknown_0859F29C);
2017-10-13 04:59:01 +02:00
DeactivateAllTextPrinters();
break;
case 8:
2017-12-03 19:19:11 +01:00
decompress_and_copy_tile_data_to_vram(1, sUnknown_0859F2B8[sMailRead->mailType].tiles, 0, 0, 0);
2017-10-13 04:59:01 +02:00
break;
case 9:
if (free_temp_tile_data_buffers_if_possible())
{
return FALSE;
}
break;
case 10:
FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 30, 20);
FillBgTilemapBufferRect_Palette0(2, 1, 0, 0, 30, 20);
2017-12-03 19:19:11 +01:00
CopyToBgTilemapBuffer(1, sUnknown_0859F2B8[sMailRead->mailType].tileMap, 0, 0);
2017-10-13 04:59:01 +02:00
break;
case 11:
CopyBgTilemapBufferToVram(0);
CopyBgTilemapBufferToVram(1);
CopyBgTilemapBufferToVram(2);
break;
case 12:
2017-11-08 18:05:47 +01:00
LoadPalette(GetOverworldTextboxPalettePtr(), 240, 32);
2017-12-03 19:19:11 +01:00
gPlttBufferUnfaded[250] = sUnknown_0859F2B8[sMailRead->mailType].color10;
gPlttBufferFaded[250] = sUnknown_0859F2B8[sMailRead->mailType].color10;
gPlttBufferUnfaded[251] = sUnknown_0859F2B8[sMailRead->mailType].color12;
gPlttBufferFaded[251] = sUnknown_0859F2B8[sMailRead->mailType].color12;
LoadPalette(sUnknown_0859F2B8[sMailRead->mailType].palette, 0, 32);
gPlttBufferUnfaded[10] = sUnknown_0859F2B0[gSaveBlock2Ptr->playerGender][0];
gPlttBufferFaded[10] = sUnknown_0859F2B0[gSaveBlock2Ptr->playerGender][0];
gPlttBufferUnfaded[11] = sUnknown_0859F2B0[gSaveBlock2Ptr->playerGender][1];
gPlttBufferFaded[11] = sUnknown_0859F2B0[gSaveBlock2Ptr->playerGender][1];
2017-10-13 04:59:01 +02:00
break;
case 13:
2017-12-03 19:19:11 +01:00
if (sMailRead->flag)
2017-10-13 04:59:01 +02:00
{
sub_8121A1C();
}
break;
case 14:
2017-12-03 19:19:11 +01:00
if (sMailRead->flag)
2017-10-13 04:59:01 +02:00
{
sub_8121B1C();
RunTextPrinters();
}
break;
case 15:
if (sub_8087598() == TRUE)
{
return FALSE;
}
break;
case 16:
2017-12-03 19:19:11 +01:00
SetVBlankCallback(VBlankCB_MailRead);
2017-10-13 04:59:01 +02:00
gPaletteFade.bufferTransferDisabled = TRUE;
break;
case 17:
2017-12-03 19:19:11 +01:00
icon = sub_80D2E84(sMailRead->mail->species);
switch (sMailRead->animsActive)
2017-10-13 04:59:01 +02:00
{
case 1:
2018-04-13 14:21:49 +02:00
LoadMonIconPalette(icon);
2017-12-03 19:19:11 +01:00
sMailRead->monIconSprite = sub_80D2D78(icon, SpriteCallbackDummy, 0x60, 0x80, 0, 0);
2017-10-13 04:59:01 +02:00
break;
case 2:
2018-04-13 14:21:49 +02:00
LoadMonIconPalette(icon);
2017-12-03 19:19:11 +01:00
sMailRead->monIconSprite = sub_80D2D78(icon, SpriteCallbackDummy, 0x28, 0x80, 0, 0);
2017-10-13 04:59:01 +02:00
break;
}
break;
case 18:
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
ShowBg(0);
ShowBg(1);
ShowBg(2);
BeginNormalPaletteFade(-1, 0, 16, 0, 0);
gPaletteFade.bufferTransferDisabled = FALSE;
2017-12-03 19:19:11 +01:00
sMailRead->callback2 = CB2_WaitForPaletteExitOnKeyPress;
2017-10-13 04:59:01 +02:00
return TRUE;
default:
return FALSE;
}
2017-12-03 19:19:11 +01:00
gMain.state++;
2017-10-13 04:59:01 +02:00
return FALSE;
}
2017-10-13 05:05:36 +02:00
2017-12-03 19:19:11 +01:00
static void CB2_InitMailRead(void)
2017-10-13 05:05:36 +02:00
{
do
{
2017-12-03 19:19:11 +01:00
if (MailReadBuildGraphics() == TRUE)
2017-10-13 05:05:36 +02:00
{
2017-12-03 19:19:11 +01:00
SetMainCallback2(CB2_MailRead);
2017-10-13 05:05:36 +02:00
break;
}
} while (sub_81221AC() != TRUE);
}
2017-10-13 14:47:26 +02:00
2017-12-03 19:19:11 +01:00
static void sub_8121A1C(void)
2017-10-13 14:47:26 +02:00
{
u16 i;
u8 total;
u8 *ptr;
total = 0;
2017-12-03 19:19:11 +01:00
for (i = 0; i < sMailRead->layout->numSubStructs; i ++)
2017-10-13 14:47:26 +02:00
{
2017-12-03 19:19:11 +01:00
ConvertEasyChatWordsToString(sMailRead->strbuf[i], &sMailRead->mail->words[total], sMailRead->layout->var8[i].numEasyChatWords, 1);
total += sMailRead->layout->var8[i].numEasyChatWords;
2017-10-13 14:47:26 +02:00
}
2017-12-03 19:19:11 +01:00
ptr = StringCopy(sMailRead->playerName, sMailRead->mail->playerName);
if (!sMailRead->playerIsSender)
2017-10-13 14:47:26 +02:00
{
StringCopy(ptr, gText_FromSpace);
2017-12-03 19:19:11 +01:00
sMailRead->signatureWidth = sMailRead->layout->signatureWidth - (StringLength(sMailRead->playerName) * 8 - 0x60);
2017-10-13 14:47:26 +02:00
}
else
{
2017-12-03 19:19:11 +01:00
sub_81DB52C(sMailRead->playerName);
sMailRead->signatureWidth = sMailRead->layout->signatureWidth;
2017-10-13 14:47:26 +02:00
}
}
2017-10-13 17:47:17 +02:00
2017-12-03 19:19:11 +01:00
static void sub_8121B1C(void)
2017-10-13 17:47:17 +02:00
{
u16 i;
u8 strbuf[0x20];
u8 y;
u8 *bufptr;
s32 box_x;
s32 box_y;
y = 0;
PutWindowTilemap(0);
PutWindowTilemap(1);
FillWindowPixelBuffer(0, 0);
FillWindowPixelBuffer(1, 0);
2017-12-03 19:19:11 +01:00
for (i = 0; i < sMailRead->layout->numSubStructs; i ++)
2017-10-13 17:47:17 +02:00
{
2017-12-03 19:19:11 +01:00
if (sMailRead->strbuf[i][0] == EOS || sMailRead->strbuf[i][0] == CHAR_SPACE)
2017-10-13 17:47:17 +02:00
{
continue;
}
2017-12-03 19:19:11 +01:00
box_print(0, 1, sMailRead->layout->var8[i].xOffset + sMailRead->layout->wordsYPos, y + sMailRead->layout->wordsXPos, sUnknown_0859F2AC, 0, sMailRead->strbuf[i]);
y += sMailRead->layout->var8[i].lineHeight;
2017-10-13 17:47:17 +02:00
}
bufptr = StringCopy(strbuf, gText_FromSpace);
2017-12-03 19:19:11 +01:00
StringCopy(bufptr, sMailRead->playerName);
box_x = GetStringCenterAlignXOffset(1, strbuf, sMailRead->signatureWidth) + 0x68;
box_y = sMailRead->layout->signatureYPos + 0x58;
box_print(0, 1, box_x, box_y, sUnknown_0859F2AC, 0, strbuf);
2017-10-13 17:47:17 +02:00
CopyWindowToVram(0, 3);
CopyWindowToVram(1, 3);
}
2017-10-13 18:03:15 +02:00
2017-12-03 19:19:11 +01:00
static void VBlankCB_MailRead(void)
2017-10-13 18:03:15 +02:00
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
2017-12-03 19:19:11 +01:00
static void CB2_MailRead(void)
2017-10-13 18:03:15 +02:00
{
2017-12-03 19:19:11 +01:00
if (sMailRead->animsActive != 0)
2017-10-13 18:03:15 +02:00
{
AnimateSprites();
BuildOamBuffer();
}
2017-12-03 19:19:11 +01:00
sMailRead->callback2();
2017-10-13 18:03:15 +02:00
}
2017-12-03 19:19:11 +01:00
static void CB2_WaitForPaletteExitOnKeyPress(void)
2017-10-13 18:03:15 +02:00
{
if (!UpdatePaletteFade())
{
2017-12-03 19:19:11 +01:00
sMailRead->callback2 = CB2_ExitOnKeyPress;
2017-10-13 18:03:15 +02:00
}
}
2017-12-03 19:19:11 +01:00
static void CB2_ExitOnKeyPress(void)
2017-10-13 18:03:15 +02:00
{
if (gMain.newKeys & (A_BUTTON | B_BUTTON))
{
BeginNormalPaletteFade(-1, 0, 0, 16, 0);
2017-12-03 19:19:11 +01:00
sMailRead->callback2 = CB2_ExitMailReadFreeVars;
2017-10-13 18:03:15 +02:00
}
}
2017-12-03 19:19:11 +01:00
static void CB2_ExitMailReadFreeVars(void)
2017-10-13 18:03:15 +02:00
{
if (!UpdatePaletteFade())
{
2017-12-03 19:19:11 +01:00
SetMainCallback2(sMailRead->callback);
switch (sMailRead->animsActive)
2017-10-13 18:03:15 +02:00
{
case 1:
case 2:
2018-04-13 14:21:49 +02:00
FreeMonIconPalette(sub_80D2E84(sMailRead->mail->species));
2017-12-03 19:19:11 +01:00
sub_80D2EF8(&gSprites[sMailRead->monIconSprite]);
2017-10-13 18:03:15 +02:00
}
2017-12-03 19:19:11 +01:00
memset(sMailRead, 0, sizeof(*sMailRead));
2017-10-13 18:03:15 +02:00
ResetPaletteFade();
UnsetBgTilemapBuffer(0);
UnsetBgTilemapBuffer(1);
ResetBgsAndClearDma3BusyFlags(0);
FreeAllWindowBuffers();
2017-12-03 19:19:11 +01:00
FREE_AND_SET_NULL(sMailRead);
2017-10-13 18:03:15 +02:00
}
}