From e29c1d05a283c1c48ea695c911551235dbf6702e Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 17 Nov 2021 00:13:23 +0000 Subject: [PATCH] Improve Help screen layout + fix CJ --- Source/help.cpp | 76 ++++++++++++++++++++++++++++++++++++++++------- Source/stores.cpp | 5 ++-- Source/stores.h | 2 +- 3 files changed, 68 insertions(+), 15 deletions(-) diff --git a/Source/help.cpp b/Source/help.cpp index 281f40602..c4822d070 100644 --- a/Source/help.cpp +++ b/Source/help.cpp @@ -96,6 +96,49 @@ const char *const HelpText[] = { std::vector HelpTextLines; +constexpr int PaddingTop = 32; +constexpr int PaddingLeft = 32; +constexpr int ContentPaddingTop = 19; +constexpr int ContentOuterHeight = 180; + +constexpr int PanelHeight = 297; +constexpr int ContentTextWidth = 577; + +int LineHeight() +{ + return IsSmallFontTall() ? 18 : 14; +} + +int BlankLineHeight() +{ + return 12; +} + +int DividerLineMarginY() +{ + return BlankLineHeight() / 2; +} + +int HeaderHeight() +{ + return PaddingTop + LineHeight() + 2 * BlankLineHeight() + DividerLineMarginY(); +} + +int ContentPaddingY() +{ + return BlankLineHeight(); +} + +int ContentsTextHeight() +{ + return PanelHeight - HeaderHeight() - DividerLineMarginY() - 2 * ContentPaddingY() - BlankLineHeight(); +} + +int NumVisibleLines() +{ + return (ContentsTextHeight() - 1) / LineHeight() + 1; // Ceil +} + } // namespace void InitHelp() @@ -130,21 +173,30 @@ void DrawHelp(const Surface &out) DrawSTextHelp(); DrawQTextBack(out); + const int lineHeight = LineHeight(); + const int blankLineHeight = BlankLineHeight(); + const char *title; if (gbIsHellfire) title = gbIsSpawn ? _("Shareware Hellfire Help") : _("Hellfire Help"); else title = gbIsSpawn ? _("Shareware Diablo Help") : _("Diablo Help"); - PrintSString(out, 0, 2, title, UiFlags::ColorWhitegold | UiFlags::AlignCenter); - DrawSLine(out, 5); + const int sx = PANEL_X + PaddingLeft; + const int sy = UI_OFFSET_Y; + + DrawString(out, title, + { { sx, sy + PaddingTop + blankLineHeight }, { ContentTextWidth, lineHeight } }, + UiFlags::ColorWhitegold | UiFlags::AlignCenter); - const int sx = PANEL_X + 32; - const int sy = UI_OFFSET_Y + 51; + const int titleBottom = sy + HeaderHeight(); + DrawSLine(out, titleBottom); - for (int i = 6; i < 21; i++) { - const char *line = HelpTextLines[i - 6 + SkipLines].c_str(); - if (line[0] == '\0') { + const int numLines = NumVisibleLines(); + const int contentY = titleBottom + DividerLineMarginY() + ContentPaddingY(); + for (int i = 0; i < numLines; i++) { + const string_view line = HelpTextLines[i + SkipLines]; + if (line.empty()) { continue; } @@ -152,13 +204,15 @@ void DrawHelp(const Surface &out) UiFlags style = UiFlags::ColorWhite; if (line[0] == '$') { offset = 1; - style = UiFlags::ColorRed; + style = UiFlags::ColorBlue; } - DrawString(out, &line[offset], { { sx, sy + i * 12 }, { 577, 12 } }, style); + DrawString(out, line.substr(offset), { { sx, contentY + i * lineHeight }, { ContentTextWidth, lineHeight } }, style, /*spacing=*/1, lineHeight); } - PrintSString(out, 0, 23, _("Press ESC to end or the arrow keys to scroll."), UiFlags::ColorWhitegold | UiFlags::AlignCenter); + DrawString(out, _("Press ESC to end or the arrow keys to scroll."), + { { sx, contentY + ContentsTextHeight() + ContentPaddingY() + blankLineHeight }, { ContentTextWidth, lineHeight } }, + UiFlags::ColorWhitegold | UiFlags::AlignCenter); } void DisplayHelp() @@ -175,7 +229,7 @@ void HelpScrollUp() void HelpScrollDown() { - if (SkipLines < HelpTextLines.size() - 15) + if (SkipLines + NumVisibleLines() < HelpTextLines.size()) SkipLines++; } diff --git a/Source/stores.cpp b/Source/stores.cpp index 29f12e3f7..5d03c4b83 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -2326,10 +2326,9 @@ void PrintSString(const Surface &out, int margin, int line, const char *text, Ui } } -void DrawSLine(const Surface &out, int y) +void DrawSLine(const Surface &out, int sy) { int sx = 26; - const int sy = PaddingTop + stext[y].y + TextHeight() / 2; int width = 587; if (!stextsize) { @@ -2509,7 +2508,7 @@ void DrawSText(const Surface &out) CalculateLineHeights(); for (int i = 0; i < STORE_LINES; i++) { if (stext[i].IsDivider()) - DrawSLine(out, i); + DrawSLine(out, PaddingTop + stext[i].y + TextHeight() / 2); if (stext[i].IsText()) PrintSString(out, stext[i]._sx, i, stext[i]._sstr, stext[i].flags, stext[i]._sval); } diff --git a/Source/stores.h b/Source/stores.h index b65297c0a..5c837e607 100644 --- a/Source/stores.h +++ b/Source/stores.h @@ -110,7 +110,7 @@ void InitStores(); void SetupTownStores(); void FreeStoreMem(); void PrintSString(const Surface &out, int margin, int line, const char *text, UiFlags flags, int price = 0); -void DrawSLine(const Surface &out, int y); +void DrawSLine(const Surface &out, int sy); void DrawSTextHelp(); void ClearSText(int s, int e); void StartStore(talk_id s);