Use window constants in berry_blender

This commit is contained in:
GriffinR 2022-09-29 12:15:17 -04:00
parent 16be1e8447
commit dd5daa3208

View File

@ -106,6 +106,13 @@ enum {
// Last berry that an NPC can put in
#define NUM_NPC_BERRIES ITEM_TO_BERRY(ITEM_ASPEAR_BERRY)
enum {
// Windows 0-3 are used implicitly in several loops over BLENDER_MAX_PLAYERS
// i.e. window 0 is for player 1, window 1 for player 2, etc.
WIN_MSG = BLENDER_MAX_PLAYERS,
WIN_RESULTS,
};
struct BlenderBerry
{
u16 itemId;
@ -200,7 +207,7 @@ static void SpriteCB_ScoreSymbolBest(struct Sprite *);
static void InitLocalPlayers(u8);
static void CB2_LoadBerryBlender(void);
static void UpdateBlenderCenter(void);
static bool32 Blender_PrintText(s16 *, const u8 *, s32 );
static bool32 PrintMessage(s16 *, const u8 *, s32 );
static void StartBlender(void);
static void CB2_StartBlenderLink(void);
static void CB2_StartBlenderLocal(void);
@ -332,7 +339,7 @@ static const struct BgTemplate sBgTemplates[3] =
static const struct WindowTemplate sWindowTemplates[] =
{
{
{ // Player 1
.bg = 0,
.tilemapLeft = 1,
.tilemapTop = 6,
@ -341,7 +348,7 @@ static const struct WindowTemplate sWindowTemplates[] =
.paletteNum = 14,
.baseBlock = 0x28,
},
{
{ // Player 2
.bg = 0,
.tilemapLeft = 22,
.tilemapTop = 6,
@ -350,7 +357,7 @@ static const struct WindowTemplate sWindowTemplates[] =
.paletteNum = 14,
.baseBlock = 0x36,
},
{
{ // Player 3
.bg = 0,
.tilemapLeft = 1,
.tilemapTop = 12,
@ -359,7 +366,7 @@ static const struct WindowTemplate sWindowTemplates[] =
.paletteNum = 14,
.baseBlock = 0x44,
},
{
{ // Player 4
.bg = 0,
.tilemapLeft = 22,
.tilemapTop = 12,
@ -368,7 +375,7 @@ static const struct WindowTemplate sWindowTemplates[] =
.paletteNum = 14,
.baseBlock = 0x52,
},
{
[WIN_MSG] = {
.bg = 0,
.tilemapLeft = 2,
.tilemapTop = 15,
@ -377,7 +384,7 @@ static const struct WindowTemplate sWindowTemplates[] =
.paletteNum = 14,
.baseBlock = 0x60,
},
{
[WIN_RESULTS] = {
.bg = 0,
.tilemapLeft = 5,
.tilemapTop = 3,
@ -1107,7 +1114,7 @@ static void CB2_LoadBerryBlender(void)
sBerryBlender->mainState++;
break;
case 4:
if (Blender_PrintText(&sBerryBlender->textState, sText_BerryBlenderStart, GetPlayerTextSpeedDelay()))
if (PrintMessage(&sBerryBlender->textState, sText_BerryBlenderStart, GetPlayerTextSpeedDelay()))
sBerryBlender->mainState++;
break;
case 5:
@ -1337,7 +1344,7 @@ static void CB2_StartBlenderLink(void)
}
break;
case 5:
Blender_PrintText(&sBerryBlender->textState, sText_CommunicationStandby, 0);
PrintMessage(&sBerryBlender->textState, sText_CommunicationStandby, 0);
sBerryBlender->mainState = 8;
sBerryBlender->framesToWait = 0;
break;
@ -1363,7 +1370,7 @@ static void CB2_StartBlenderLink(void)
if (++sBerryBlender->framesToWait > 20)
{
// Wait for partners' berries
ClearDialogWindowAndFrameToTransparent(4, TRUE);
ClearDialogWindowAndFrameToTransparent(WIN_MSG, TRUE);
if (GetBlockReceivedStatus() == GetLinkPlayerCountAsBitFlags())
{
for (i = 0; i < GetLinkPlayerCount(); i++)
@ -2664,7 +2671,7 @@ static void CB2_EndBlenderGame(void)
}
break;
case 7:
if (Blender_PrintText(&sBerryBlender->textState, sText_WouldLikeToBlendAnotherBerry, GetPlayerTextSpeedDelay()))
if (PrintMessage(&sBerryBlender->textState, sText_WouldLikeToBlendAnotherBerry, GetPlayerTextSpeedDelay()))
sBerryBlender->gameEndState++;
break;
case 9:
@ -2748,7 +2755,7 @@ static void CB2_EndBlenderGame(void)
sBerryBlender->gameEndState++;
break;
case 13:
if (Blender_PrintText(&sBerryBlender->textState, sText_CommunicationStandby, GetPlayerTextSpeedDelay()))
if (PrintMessage(&sBerryBlender->textState, sText_CommunicationStandby, GetPlayerTextSpeedDelay()))
{
SetMainCallback2(CB2_CheckPlayAgainLink);
sBerryBlender->gameEndState = 0;
@ -2858,7 +2865,7 @@ static void CB2_CheckPlayAgainLink(void)
StringAppend(gStringVar4, sText_HasNoBerriesToPut);
break;
case 3:
if (Blender_PrintText(&sBerryBlender->textState, gStringVar4, GetPlayerTextSpeedDelay()))
if (PrintMessage(&sBerryBlender->textState, gStringVar4, GetPlayerTextSpeedDelay()))
{
sBerryBlender->framesToWait = 0;
sBerryBlender->gameEndState++;
@ -2869,7 +2876,7 @@ static void CB2_CheckPlayAgainLink(void)
sBerryBlender->gameEndState = 5;
break;
case 5:
Blender_PrintText(&sBerryBlender->textState, gText_SavingDontTurnOff2, 0);
PrintMessage(&sBerryBlender->textState, gText_SavingDontTurnOff2, 0);
SetLinkStandbyCallback();
sBerryBlender->gameEndState++;
break;
@ -2965,7 +2972,7 @@ static void CB2_CheckPlayAgainLocal(void)
StringCopy(gStringVar4, sText_RunOutOfBerriesForBlending);
break;
case 3:
if (Blender_PrintText(&sBerryBlender->textState, gStringVar4, GetPlayerTextSpeedDelay()))
if (PrintMessage(&sBerryBlender->textState, gStringVar4, GetPlayerTextSpeedDelay()))
sBerryBlender->gameEndState = 9;
break;
case 9:
@ -3495,7 +3502,7 @@ static bool8 PrintBlendingResults(void)
u8 *txtPtr;
xPos = GetStringCenterAlignXOffset(FONT_NORMAL, sText_BlendingResults, 0xA8);
Blender_AddTextPrinter(5, sText_BlendingResults, xPos, 1, TEXT_SKIP_DRAW, 0);
Blender_AddTextPrinter(WIN_RESULTS, sText_BlendingResults, xPos, 1, TEXT_SKIP_DRAW, 0);
if (sBerryBlender->numPlayers == BLENDER_MAX_PLAYERS)
yPos = 17;
@ -3510,15 +3517,15 @@ static bool8 PrintBlendingResults(void)
StringAppend(sBerryBlender->stringVar, sText_Dot);
StringAppend(sBerryBlender->stringVar, gText_Space);
StringAppend(sBerryBlender->stringVar, gLinkPlayers[place].name);
Blender_AddTextPrinter(5, sBerryBlender->stringVar, 8, yPos, TEXT_SKIP_DRAW, 3);
Blender_AddTextPrinter(WIN_RESULTS, sBerryBlender->stringVar, 8, yPos, TEXT_SKIP_DRAW, 3);
StringCopy(sBerryBlender->stringVar, sBerryBlender->blendedBerries[place].name);
ConvertInternationalString(sBerryBlender->stringVar, gLinkPlayers[place].language);
StringAppend(sBerryBlender->stringVar, sText_SpaceBerry);
Blender_AddTextPrinter(5, sBerryBlender->stringVar, 0x54, yPos, TEXT_SKIP_DRAW, 3);
Blender_AddTextPrinter(WIN_RESULTS, sBerryBlender->stringVar, 0x54, yPos, TEXT_SKIP_DRAW, 3);
}
Blender_AddTextPrinter(5, sText_MaximumSpeed, 0, 0x51, TEXT_SKIP_DRAW, 3);
Blender_AddTextPrinter(WIN_RESULTS, sText_MaximumSpeed, 0, 0x51, TEXT_SKIP_DRAW, 3);
ConvertIntToDecimalStringN(sBerryBlender->stringVar, sBerryBlender->maxRPM / 100, STR_CONV_MODE_RIGHT_ALIGN, 3);
StringAppend(sBerryBlender->stringVar, sText_Dot);
@ -3527,8 +3534,8 @@ static bool8 PrintBlendingResults(void)
StringAppend(sBerryBlender->stringVar, sText_RPM);
xPos = GetStringRightAlignXOffset(FONT_NORMAL, sBerryBlender->stringVar, 0xA8);
Blender_AddTextPrinter(5, sBerryBlender->stringVar, xPos, 0x51, TEXT_SKIP_DRAW, 3);
Blender_AddTextPrinter(5, sText_Time, 0, 0x61, TEXT_SKIP_DRAW, 3);
Blender_AddTextPrinter(WIN_RESULTS, sBerryBlender->stringVar, xPos, 0x51, TEXT_SKIP_DRAW, 3);
Blender_AddTextPrinter(WIN_RESULTS, sText_Time, 0, 0x61, TEXT_SKIP_DRAW, 3);
seconds = (sBerryBlender->gameFrameTime / 60) % 60;
minutes = (sBerryBlender->gameFrameTime / (60 * 60));
@ -3540,12 +3547,12 @@ static bool8 PrintBlendingResults(void)
StringAppend(sBerryBlender->stringVar, sText_Sec);
xPos = GetStringRightAlignXOffset(FONT_NORMAL, sBerryBlender->stringVar, 0xA8);
Blender_AddTextPrinter(5, sBerryBlender->stringVar, xPos, 0x61, TEXT_SKIP_DRAW, 3);
Blender_AddTextPrinter(WIN_RESULTS, sBerryBlender->stringVar, xPos, 0x61, TEXT_SKIP_DRAW, 3);
sBerryBlender->framesToWait = 0;
sBerryBlender->mainState++;
CopyWindowToVram(5, COPYWIN_GFX);
CopyWindowToVram(WIN_RESULTS, COPYWIN_GFX);
}
break;
case 4:
@ -3553,7 +3560,7 @@ static bool8 PrintBlendingResults(void)
sBerryBlender->mainState++;
break;
case 5:
ClearStdWindowAndFrameToTransparent(5, TRUE);
ClearStdWindowAndFrameToTransparent(WIN_RESULTS, TRUE);
for (i = 0; i < BLENDER_MAX_PLAYERS; i++)
{
@ -3581,7 +3588,7 @@ static bool8 PrintBlendingResults(void)
sBerryBlender->mainState++;
break;
case 6:
if (Blender_PrintText(&sBerryBlender->textState, sBerryBlender->stringVar, GetPlayerTextSpeedDelay()))
if (PrintMessage(&sBerryBlender->textState, sBerryBlender->stringVar, GetPlayerTextSpeedDelay()))
{
TryUpdateBerryBlenderRecord();
return TRUE;
@ -3692,9 +3699,9 @@ static bool8 PrintBlendingRanking(void)
}
break;
case 3:
DrawStdFrameWithCustomTileAndPalette(5, FALSE, 1, 0xD);
DrawStdFrameWithCustomTileAndPalette(WIN_RESULTS, FALSE, 1, 0xD);
xPos = GetStringCenterAlignXOffset(FONT_NORMAL, sText_Ranking, 168);
Blender_AddTextPrinter(5, sText_Ranking, xPos, 1, TEXT_SKIP_DRAW, 0);
Blender_AddTextPrinter(WIN_RESULTS, sText_Ranking, xPos, 1, TEXT_SKIP_DRAW, 0);
sBerryBlender->scoreIconIds[SCORE_BEST] = CreateSprite(&sSpriteTemplate_ScoreSymbols, 128, 52, 0);
StartSpriteAnim(&gSprites[sBerryBlender->scoreIconIds[SCORE_BEST]], SCOREANIM_BEST_STATIC);
@ -3718,20 +3725,20 @@ static bool8 PrintBlendingRanking(void)
StringAppend(sBerryBlender->stringVar, sText_Dot);
StringAppend(sBerryBlender->stringVar, gText_Space);
StringAppend(sBerryBlender->stringVar, gLinkPlayers[place].name);
Blender_AddTextPrinter(5, sBerryBlender->stringVar, 0, yPos, TEXT_SKIP_DRAW, 3);
Blender_AddTextPrinter(WIN_RESULTS, sBerryBlender->stringVar, 0, yPos, TEXT_SKIP_DRAW, 3);
ConvertIntToDecimalStringN(sBerryBlender->stringVar, sBerryBlender->scores[place][SCORE_BEST], STR_CONV_MODE_RIGHT_ALIGN, 3);
Blender_AddTextPrinter(5, sBerryBlender->stringVar, 78, yPos, TEXT_SKIP_DRAW, 3);
Blender_AddTextPrinter(WIN_RESULTS, sBerryBlender->stringVar, 78, yPos, TEXT_SKIP_DRAW, 3);
ConvertIntToDecimalStringN(sBerryBlender->stringVar, sBerryBlender->scores[place][SCORE_GOOD], STR_CONV_MODE_RIGHT_ALIGN, 3);
Blender_AddTextPrinter(5, sBerryBlender->stringVar, 78 + 32, yPos, TEXT_SKIP_DRAW, 3);
Blender_AddTextPrinter(WIN_RESULTS, sBerryBlender->stringVar, 78 + 32, yPos, TEXT_SKIP_DRAW, 3);
ConvertIntToDecimalStringN(sBerryBlender->stringVar, sBerryBlender->scores[place][SCORE_MISS], STR_CONV_MODE_RIGHT_ALIGN, 3);
Blender_AddTextPrinter(5, sBerryBlender->stringVar, 78 + 64, yPos, TEXT_SKIP_DRAW, 3);
Blender_AddTextPrinter(WIN_RESULTS, sBerryBlender->stringVar, 78 + 64, yPos, TEXT_SKIP_DRAW, 3);
}
PutWindowTilemap(5);
CopyWindowToVram(5, COPYWIN_FULL);
PutWindowTilemap(WIN_RESULTS);
CopyWindowToVram(WIN_RESULTS, COPYWIN_FULL);
sBerryBlender->framesToWait = 0;
sBerryBlender->mainState++;
@ -3875,26 +3882,24 @@ static void Blender_AddTextPrinter(u8 windowId, const u8 *string, u8 x, u8 y, s3
}
if (caseId != 3)
{
FillWindowPixelBuffer(windowId, PIXEL_FILL(txtColor[0]));
}
AddTextPrinterParameterized4(windowId, FONT_NORMAL, x, y, letterSpacing, 1, txtColor, speed, string);
}
static bool32 Blender_PrintText(s16 *textState, const u8 *string, s32 textSpeed)
static bool32 PrintMessage(s16 *textState, const u8 *string, s32 textSpeed)
{
switch (*textState)
{
case 0:
DrawDialogFrameWithCustomTileAndPalette(4, FALSE, 0x14, 0xF);
Blender_AddTextPrinter(4, string, 0, 1, textSpeed, 0);
PutWindowTilemap(4);
CopyWindowToVram(4, COPYWIN_FULL);
DrawDialogFrameWithCustomTileAndPalette(WIN_MSG, FALSE, 0x14, 0xF);
Blender_AddTextPrinter(WIN_MSG, string, 0, 1, textSpeed, 0);
PutWindowTilemap(WIN_MSG);
CopyWindowToVram(WIN_MSG, COPYWIN_FULL);
(*textState)++;
break;
case 1:
if (!IsTextPrinterActive(4))
if (!IsTextPrinterActive(WIN_MSG))
{
*textState = 0;
return TRUE;