From 8361e70087788ae1a09fd197d53bc72fa20a5208 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 8 May 2021 12:15:25 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8FUse=20DrawString=20in=20error?= =?UTF-8?q?.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/error.cpp | 32 +++++--------------------------- Source/help.cpp | 28 +++++++--------------------- Source/inv.cpp | 13 ++++++++----- 3 files changed, 20 insertions(+), 53 deletions(-) diff --git a/Source/error.cpp b/Source/error.cpp index 1bcd98c50..e980497a9 100644 --- a/Source/error.cpp +++ b/Source/error.cpp @@ -109,22 +109,19 @@ void ClrDiabloMsg() void DrawDiabloMsg(const CelOutputBuffer &out) { - int i, len, width, sx, sy; - BYTE c; - CelDrawTo(out, PANEL_X + 101, DIALOG_Y, *pSTextSlidCels, 1); CelDrawTo(out, PANEL_X + 527, DIALOG_Y, *pSTextSlidCels, 4); CelDrawTo(out, PANEL_X + 101, DIALOG_Y + 48, *pSTextSlidCels, 2); CelDrawTo(out, PANEL_X + 527, DIALOG_Y + 48, *pSTextSlidCels, 3); - sx = PANEL_X + 109; - for (i = 0; i < 35; i++) { + int sx = PANEL_X + 109; + for (int i = 0; i < 35; i++) { CelDrawTo(out, sx, DIALOG_Y, *pSTextSlidCels, 5); CelDrawTo(out, sx, DIALOG_Y + 48, *pSTextSlidCels, 7); sx += 12; } - sy = DIALOG_Y + 12; - for (i = 0; i < 3; i++) { + int sy = DIALOG_Y + 12; + for (int i = 0; i < 3; i++) { CelDrawTo(out, PANEL_X + 101, sy, *pSTextSlidCels, 6); CelDrawTo(out, PANEL_X + 527, sy, *pSTextSlidCels, 8); sy += 12; @@ -133,26 +130,7 @@ void DrawDiabloMsg(const CelOutputBuffer &out) DrawHalfTransparentRectTo(out, PANEL_X + 104, DIALOG_Y - 8, 432, 54); strcpy(tempstr, _(MsgStrings[msgflag])); - sx = PANEL_X + 101; - sy = DIALOG_Y + 24; - len = strlen(tempstr); - width = 0; - - for (i = 0; i < len; i++) { - width += fontkern[GameFontSmall][fontframe[GameFontSmall][gbFontTransTbl[(BYTE)tempstr[i]]]] + 1; - } - - if (width < 442) { - sx += (442 - width) / 2; - } - - for (i = 0; i < len; i++) { - c = fontframe[GameFontSmall][gbFontTransTbl[(BYTE)tempstr[i]]]; - if (c != '\0') { - PrintChar(out, sx, sy, c, COL_GOLD); - } - sx += fontkern[GameFontSmall][c] + 1; - } + DrawString(out, tempstr, { PANEL_X + 101, DIALOG_Y + 24, 442, 0 }, UIS_CENTER); if (msgdelay > 0 && msgdelay <= SDL_GetTicks() - 3500) { msgdelay = 0; diff --git a/Source/help.cpp b/Source/help.cpp index 2b2bea583..558d94457 100644 --- a/Source/help.cpp +++ b/Source/help.cpp @@ -459,25 +459,11 @@ void InitHelp() helpflag = false; } -static void DrawHelpLine(const CelOutputBuffer &out, int x, int y, char *text, text_color color) +static void DrawHelpLine(const CelOutputBuffer &out, int x, int y, char *text, uint16_t style) { - int sx, sy, width; - BYTE c; - - width = 0; - sx = x + 32 + PANEL_X; - sy = y * 12 + 44 + UI_OFFSET_Y; - while (*text) { - c = gbFontTransTbl[(BYTE)*text]; - text++; - c = fontframe[GameFontSmall][c]; - width += fontkern[GameFontSmall][c] + 1; - if (c) { - if (width <= 577) - PrintChar(out, sx, sy, c, color); - } - sx += fontkern[GameFontSmall][c] + 1; - } + const int sx = x + 32 + PANEL_X; + const int sy = y * 12 + 44 + UI_OFFSET_Y; + DrawString(out, text, { sx, sy, 577, 0 }, style); } void DrawHelp(const CelOutputBuffer &out) @@ -535,10 +521,10 @@ void DrawHelp(const CelOutputBuffer &out) while (*s == '\0') { s++; } - text_color col = COL_WHITE; + uint16_t style = UIS_SILVER; if (*s == '$') { s++; - col = COL_RED; + style = UIS_RED; } if (*s == '&') { HelpTop = help_select_line; @@ -563,7 +549,7 @@ void DrawHelp(const CelOutputBuffer &out) } if (c != 0) { tempstr[c] = '\0'; - DrawHelpLine(out, 0, i, tempstr, col); + DrawHelpLine(out, 0, i, tempstr, style); } if (*s == '|') { s++; diff --git a/Source/inv.cpp b/Source/inv.cpp index f6814a7f3..2af64e9f3 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -301,8 +301,6 @@ void DrawInv(const CelOutputBuffer &out) void DrawInvBelt(const CelOutputBuffer &out) { - BYTE fi, ff; - if (talkflag) { return; } @@ -335,9 +333,14 @@ void DrawInvBelt(const CelOutputBuffer &out) if (AllItemsList[plr[myplr].SpdList[i].IDidx].iUsable && plr[myplr].SpdList[i]._iStatFlag && plr[myplr].SpdList[i]._itype != ITYPE_GOLD) { - fi = i + 49; - ff = fontframe[GameFontSmall][gbFontTransTbl[fi]]; - PrintChar(out, InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X + INV_SLOT_SIZE_PX - fontkern[GameFontSmall][ff], InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, ff, COL_WHITE); + sprintf(tempstr, "%d", i + 1); + SDL_Rect rect { + InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X + INV_SLOT_SIZE_PX - GetLineWidth(tempstr), + InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, + 0, + 0 + }; + DrawString(out, tempstr, rect, UIS_SILVER); } } }