Skip to content

Commit 02c7450

Browse files
committed
Completely remove the base alignment from drawTextMain
This only affects previous alignments very slightly, so there's not much of a point in having a base alignment in the first place. With this change, TextLengthScaled is initialized right away, and it's value only gets updated when necessary, similar to TextLength from the previous version of the code.
1 parent 4c1350d commit 02c7450

File tree

2 files changed

+22
-45
lines changed

2 files changed

+22
-45
lines changed

ttyd-tools/rel/source/draw.cpp

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -293,33 +293,28 @@ void drawTextMain(const char *text, int32_t x, int32_t y,
293293
}
294294

295295
float NewPosX = intToFloat(x);
296-
uint32_t TextLength = 0;
296+
float TextLengthScaled = 0.f; // Failsafe; 0.f value won't be used
297297

298298
// Check if aligning the text to the right
299299
if (alignRight)
300300
{
301-
#ifdef TTYD_JP
302-
const char *AlignBase = ttyd::win_main::str_999_jpn_winMain;
303-
#else
304-
const char *AlignBase = ttyd::win_main::str_999_winMain;
305-
#endif
306-
uint32_t BaseLength = ttyd::fontmgr::FontGetMessageWidth(AlignBase);
307-
TextLength = ttyd::fontmgr::FontGetMessageWidth(text);
301+
uint32_t TextLength = ttyd::fontmgr::FontGetMessageWidth(text);
302+
TextLengthScaled = intToFloat(static_cast<int32_t>(TextLength)) * scale;
308303

309-
NewPosX += intToFloat(BaseLength - TextLength) * scale;
304+
NewPosX -= TextLengthScaled;
310305
}
311306

312307
// Check if there's a width limit
313308
float ScaleX = scale;
314309
if (!std::signbit(width)) // Check if positive, works for checking against +0.0 and -0.0
315310
{
316-
// Prevent calling FontGetMessageWidth again if unnecessary
317-
if (TextLength == 0)
311+
// If not aligning the text to the right, then TextLengthScaled needs to be calculated
312+
if (!alignRight)
318313
{
319-
TextLength = ttyd::fontmgr::FontGetMessageWidth(text);
314+
uint32_t TextLength = ttyd::fontmgr::FontGetMessageWidth(text);
315+
TextLengthScaled = intToFloat(static_cast<int32_t>(TextLength)) * scale;
320316
}
321317

322-
float TextLengthScaled = intToFloat(static_cast<int32_t>(TextLength)) * scale;
323318
if (TextLengthScaled > width)
324319
{
325320
ScaleX = (width / TextLengthScaled) * scale;
@@ -1163,7 +1158,7 @@ void drawMarioStats()
11631158
// Draw the text
11641159
PosX = TextPosX;
11651160
PosY = TextPosY;
1166-
ValuesPosX = TextPosX + 120;
1161+
ValuesPosX = TextPosX + 148;
11671162
ExitLoop = false;
11681163

11691164
for (uint32_t j = 0; j < TotalColumns; j++)
@@ -2767,13 +2762,7 @@ void drawBattlesStatusesList()
27672762
Color = 0xFFFFFFFF;
27682763
}
27692764

2770-
int32_t TextPosXIncrement = 291;
2771-
2772-
#ifdef TTYD_JP
2773-
TextPosXIncrement -= 3;
2774-
#endif
2775-
2776-
drawTextAlignRight(TextToDraw, TextPosX + TextPosXIncrement, TextPosY, Color, TextScale);
2765+
drawTextAlignRight(TextToDraw, TextPosX + 319, TextPosY, Color, TextScale);
27772766
TextPosY -= 30;
27782767
}
27792768
}
@@ -3887,7 +3876,7 @@ void drawCheatsModifyMarioCoordinates()
38873876
"%.6f",
38883877
Coordinate);
38893878

3890-
// Make sure the text wont go offscreen
3879+
// Make sure the text won't go offscreen
38913880
int32_t CoordinateMaxStringLength = 34;
38923881

38933882
#ifdef TTYD_JP
@@ -4789,7 +4778,7 @@ void drawWarpIndexEntranceList()
47894778
drawTextMultipleLines(tempDisplayBuffer, PosX + 170, PosY, mapAndBeroDetails.MapColor, Scale);
47904779

47914780
// Draw the current page
4792-
int32_t PageNumberPosX = 223;
4781+
int32_t PageNumberPosX = 233;
47934782
uint32_t tempCurrentPage = MenuVar.CurrentPage;
47944783
drawPageNumber(PageNumberPosX, PosY, tempCurrentPage);
47954784

@@ -5232,13 +5221,17 @@ void Mod::drawSequenceInPauseMenu(ttyd::dispdrv::CameraId cameraId, void *winWor
52325221
"%" PRIu32,
52335222
getSequencePosition());
52345223

5235-
#ifndef TTYD_JP
5224+
int32_t PosXIncrement = 255;
5225+
5226+
#ifdef TTYD_JP
5227+
PosXIncrement += 4;
5228+
#else
52365229
Scale = 0.9f;
52375230
#endif
52385231

52395232
drawTextAlignRight(
52405233
tempDisplaybuffer,
5241-
WindowPosX + 214,
5234+
WindowPosX + PosXIncrement,
52425235
WindowPosY + PosYIncrement,
52435236
Color,
52445237
Scale);

ttyd-tools/rel/source/menu.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3827,13 +3827,9 @@ void drawMenu()
38273827
drawSingleColumnMain();
38283828

38293829
// Draw the version number
3830-
int32_t PosX = 205;
3830+
int32_t PosX = 233;
38313831
int32_t PosY = 180;
38323832

3833-
#ifdef TTYD_JP
3834-
PosX -= 3;
3835-
#endif
3836-
38373833
drawVersionNumber(PosX, PosY);
38383834

38393835
// Draw the error message if the player tried to use the battle menu while not in a battle
@@ -3975,13 +3971,9 @@ void drawMenu()
39753971
drawSingleColumn(PosY, MaxOptionsPerPage, tempCurrentPage, false);
39763972

39773973
// Draw the page number
3978-
int32_t PosX = 205;
3974+
int32_t PosX = 233;
39793975
// int32_t PosY = 180;
39803976

3981-
#ifdef TTYD_JP
3982-
PosX -= 3;
3983-
#endif
3984-
39853977
drawPageNumber(PosX, PosY, tempCurrentPage);
39863978
break;
39873979
}
@@ -4429,13 +4421,9 @@ void drawMenu()
44294421
drawSingleColumnMain();
44304422

44314423
// Draw the page number
4432-
int32_t PosX = 205;
4424+
int32_t PosX = 233;
44334425
int32_t PosY = 180;
44344426

4435-
#ifdef TTYD_JP
4436-
PosX -= 3;
4437-
#endif
4438-
44394427
drawPageNumber(PosX, PosY, tempCurrentPage);
44404428

44414429
// Draw each actor
@@ -4507,13 +4495,9 @@ void drawMenu()
45074495
drawBattlesStatusesList();
45084496

45094497
// Draw the page number
4510-
int32_t PosX = 208;
4498+
int32_t PosX = 236;
45114499
int32_t PosY = 180;
45124500

4513-
#ifdef TTYD_JP
4514-
PosX -= 2;
4515-
#endif
4516-
45174501
drawPageNumber(PosX, PosY, tempCurrentPage);
45184502

45194503
if (tempSelectedOption > 0)

0 commit comments

Comments
 (0)