Merge pull request #1053 from Sierraffinity/text-drawdownarrow-fix

Fix TextPrinterDrawDownArrow fakematch
This commit is contained in:
Sierra A 2020-05-20 19:50:52 -07:00 committed by GitHub
commit 02416dc79c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 56 deletions

View file

@ -178,7 +178,7 @@ bool16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u8 speed, voi
for (i = 0; i < 7; i++)
{
gTempTextPrinter.subUnion.fields[i] = 0;
gTempTextPrinter.subStructFields[i] = 0;
}
gTempTextPrinter.printerTemplate = *printerTemplate;
@ -187,7 +187,7 @@ bool16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u8 speed, voi
gTempTextPrinter.japanese = 0;
GenerateFontHalfRowLookupTable(printerTemplate->fgColor, printerTemplate->bgColor, printerTemplate->shadowColor);
if (speed != TEXT_SPEED_FF && speed != 0x0)
if (speed != TEXT_SPEED_FF && speed != 0)
{
--gTempTextPrinter.textSpeed;
gTextPrinters[printerTemplate->windowId] = gTempTextPrinter;
@ -202,7 +202,7 @@ bool16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u8 speed, voi
}
if (speed != TEXT_SPEED_FF)
CopyWindowToVram(gTempTextPrinter.printerTemplate.windowId, 2);
CopyWindowToVram(gTempTextPrinter.printerTemplate.windowId, 2);
gTextPrinters[printerTemplate->windowId].active = 0;
}
gUnknown_03002F84 = 0;
@ -215,7 +215,7 @@ void RunTextPrinters(void)
if (gUnknown_03002F84 == 0)
{
for (i = 0; i < 0x20; ++i)
for (i = 0; i < NUM_TEXT_PRINTERS; ++i)
{
if (gTextPrinters[i].active)
{
@ -1297,11 +1297,11 @@ void ClearTextSpan(struct TextPrinter *textPrinter, u32 width)
u16 Font0Func(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub;
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
if (subStruct->hasGlyphIdBeenSet == FALSE)
{
textPrinter->subUnion.sub.glyphId = 0;
subStruct->glyphId = 0;
subStruct->hasGlyphIdBeenSet = TRUE;
}
return RenderText(textPrinter);
@ -1309,11 +1309,11 @@ u16 Font0Func(struct TextPrinter *textPrinter)
u16 Font1Func(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub;
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
if (subStruct->hasGlyphIdBeenSet == FALSE)
{
textPrinter->subUnion.sub.glyphId = 1;
subStruct->glyphId = 1;
subStruct->hasGlyphIdBeenSet = TRUE;
}
return RenderText(textPrinter);
@ -1321,11 +1321,11 @@ u16 Font1Func(struct TextPrinter *textPrinter)
u16 Font2Func(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub;
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
if (subStruct->hasGlyphIdBeenSet == FALSE)
{
textPrinter->subUnion.sub.glyphId = 2;
subStruct->glyphId = 2;
subStruct->hasGlyphIdBeenSet = TRUE;
}
return RenderText(textPrinter);
@ -1333,11 +1333,11 @@ u16 Font2Func(struct TextPrinter *textPrinter)
u16 Font3Func(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub;
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
if (subStruct->hasGlyphIdBeenSet == FALSE)
{
textPrinter->subUnion.sub.glyphId = 3;
subStruct->glyphId = 3;
subStruct->hasGlyphIdBeenSet = TRUE;
}
return RenderText(textPrinter);
@ -1345,11 +1345,11 @@ u16 Font3Func(struct TextPrinter *textPrinter)
u16 Font4Func(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub;
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
if (subStruct->hasGlyphIdBeenSet == FALSE)
{
textPrinter->subUnion.sub.glyphId = 4;
subStruct->glyphId = 4;
subStruct->hasGlyphIdBeenSet = TRUE;
}
return RenderText(textPrinter);
@ -1357,11 +1357,11 @@ u16 Font4Func(struct TextPrinter *textPrinter)
u16 Font5Func(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub;
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
if (subStruct->hasGlyphIdBeenSet == FALSE)
{
textPrinter->subUnion.sub.glyphId = 5;
subStruct->glyphId = 5;
subStruct->hasGlyphIdBeenSet = TRUE;
}
return RenderText(textPrinter);
@ -1369,11 +1369,11 @@ u16 Font5Func(struct TextPrinter *textPrinter)
u16 Font7Func(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub;
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
if (subStruct->hasGlyphIdBeenSet == FALSE)
{
textPrinter->subUnion.sub.glyphId = 7;
subStruct->glyphId = 7;
subStruct->hasGlyphIdBeenSet = TRUE;
}
return RenderText(textPrinter);
@ -1381,11 +1381,11 @@ u16 Font7Func(struct TextPrinter *textPrinter)
u16 Font8Func(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub;
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
if (subStruct->hasGlyphIdBeenSet == FALSE)
{
textPrinter->subUnion.sub.glyphId = 8;
subStruct->glyphId = 8;
subStruct->hasGlyphIdBeenSet = TRUE;
}
return RenderText(textPrinter);
@ -1393,10 +1393,12 @@ u16 Font8Func(struct TextPrinter *textPrinter)
void TextPrinterInitDownArrowCounters(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub;
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
if (gTextFlags.autoScroll == 1)
{
subStruct->autoScrollDelay = 0;
}
else
{
subStruct->downArrowYPosIdx = 0;
@ -1406,14 +1408,14 @@ void TextPrinterInitDownArrowCounters(struct TextPrinter *textPrinter)
void TextPrinterDrawDownArrow(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub;
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
const u8 *arrowTiles;
if (gTextFlags.autoScroll == 0)
{
if (subStruct->downArrowDelay != 0)
{
subStruct->downArrowDelay = ((*(u32*)&textPrinter->subUnion.sub) << 19 >> 27) - 1; // convoluted way of getting downArrowDelay, necessary to match
subStruct->downArrowDelay--;
}
else
{
@ -1422,16 +1424,16 @@ void TextPrinterDrawDownArrow(struct TextPrinter *textPrinter)
textPrinter->printerTemplate.bgColor << 4 | textPrinter->printerTemplate.bgColor,
textPrinter->printerTemplate.currentX,
textPrinter->printerTemplate.currentY,
0x8,
0x10);
8,
16);
switch (gTextFlags.useAlternateDownArrow)
{
case 0:
case FALSE:
default:
arrowTiles = gDownArrowTiles;
break;
case 1:
case TRUE:
arrowTiles = gDarkDownArrowTiles;
break;
}
@ -1440,17 +1442,17 @@ void TextPrinterDrawDownArrow(struct TextPrinter *textPrinter)
textPrinter->printerTemplate.windowId,
arrowTiles,
0,
gDownArrowYCoords[*(u32*)subStruct << 17 >> 30], // subStruct->downArrowYPosIdx but again, stupidly retrieved
0x8,
0x10,
gDownArrowYCoords[subStruct->downArrowYPosIdx],
8,
16,
textPrinter->printerTemplate.currentX,
textPrinter->printerTemplate.currentY,
0x8,
0x10);
CopyWindowToVram(textPrinter->printerTemplate.windowId, 0x2);
8,
16);
CopyWindowToVram(textPrinter->printerTemplate.windowId, 2);
subStruct->downArrowDelay = 0x8;
subStruct->downArrowYPosIdx = (*(u32*)subStruct << 17 >> 30) + 1;
subStruct->downArrowDelay = 8;
subStruct->downArrowYPosIdx++;
}
}
}
@ -1462,14 +1464,14 @@ void TextPrinterClearDownArrow(struct TextPrinter *textPrinter)
textPrinter->printerTemplate.bgColor << 4 | textPrinter->printerTemplate.bgColor,
textPrinter->printerTemplate.currentX,
textPrinter->printerTemplate.currentY,
0x8,
0x10);
CopyWindowToVram(textPrinter->printerTemplate.windowId, 0x2);
8,
16);
CopyWindowToVram(textPrinter->printerTemplate.windowId, 2);
}
bool8 TextPrinterWaitAutoMode(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub;
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
if (subStruct->autoScrollDelay == 49)
{
@ -1477,7 +1479,7 @@ bool8 TextPrinterWaitAutoMode(struct TextPrinter *textPrinter)
}
else
{
++subStruct->autoScrollDelay;
subStruct->autoScrollDelay++;
return FALSE;
}
}
@ -1563,7 +1565,7 @@ void DrawDownArrow(u8 windowId, u16 x, u16 y, u8 bgColor, bool8 drawArrow, u8 *c
u16 RenderText(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub;
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
u16 currChar;
s32 width;
s32 widthHelper;

View file

@ -200,15 +200,7 @@ struct TextPrinter
void (*callback)(struct TextPrinterTemplate *, u16); // 0x10
union
#if !MODERN
__attribute__((packed))
#endif
{
struct TextPrinterSubStruct sub;
u8 fields[7];
} subUnion;
u8 subStructFields[7]; // always cast to struct TextPrinterSubStruct... so why bother
u8 active;
u8 state; // 0x1C
u8 textSpeed;

View file

@ -13,13 +13,13 @@ static void DecompressGlyphFont6(u16);
u16 Font6Func(struct TextPrinter *textPrinter)
{
u16 char_;
struct TextPrinterSubStruct *sub;
struct TextPrinterSubStruct *subStruct;
subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
sub = &textPrinter->subUnion.sub;
switch (textPrinter->state)
{
case 0:
if (gMain.heldKeys & (A_BUTTON | B_BUTTON) && sub->hasPrintBeenSpedUp)
if (gMain.heldKeys & (A_BUTTON | B_BUTTON) && subStruct->hasPrintBeenSpedUp)
{
textPrinter->delayCounter = 0;
}
@ -28,7 +28,7 @@ u16 Font6Func(struct TextPrinter *textPrinter)
textPrinter->delayCounter --;
if (gTextFlags.canABSpeedUpPrint && gMain.newKeys & (A_BUTTON | B_BUTTON))
{
sub->hasPrintBeenSpedUp = TRUE;
subStruct->hasPrintBeenSpedUp = TRUE;
textPrinter->delayCounter = 0;
}
return 3;
@ -81,7 +81,7 @@ u16 Font6Func(struct TextPrinter *textPrinter)
textPrinter->printerTemplate.currentChar++;
return 2;
case 6:
sub->glyphId = *textPrinter->printerTemplate.currentChar;
subStruct->glyphId = *textPrinter->printerTemplate.currentChar;
textPrinter->printerTemplate.currentChar++;
return 2;
case 7:
@ -94,7 +94,7 @@ u16 Font6Func(struct TextPrinter *textPrinter)
textPrinter->state = 1;
if (gTextFlags.autoScroll)
{
sub->autoScrollDelay = 0;
subStruct->autoScrollDelay = 0;
}
return 3;
case 10: