From d0fb28d544cf8bde1a6216ef2118047a1fb2b2e7 Mon Sep 17 00:00:00 2001 From: Eric Robinson <68359262+kphoenix137@users.noreply.github.com> Date: Sat, 13 Dec 2025 03:36:22 -0500 Subject: [PATCH] Cleanup DrawAutomapText (#8345) --- Source/automap.cpp | 111 +++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 60 deletions(-) diff --git a/Source/automap.cpp b/Source/automap.cpp index 745e520fb..c7b4e0746 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -1411,54 +1411,59 @@ void DrawAutomapText(const Surface &out) { Point linePosition { 8, 8 }; + auto advanceLine = [&](int numLines = 1) { + linePosition.y += 15 * numLines; + }; + + auto drawStringAndAdvanceLine = [&](std::string_view text, TextRenderOptions opts = {}, int numLines = 1) { + DrawString(out, text, linePosition, opts); + advanceLine(numLines); + }; + if (*GetOptions().Graphics.showFPS) { - linePosition.y += 15; + advanceLine(); } if (gbIsMultiplayer) { if (GameName != "0.0.0.0" && !IsLoopback) { std::string description = std::string(_("Game: ")); description.append(GameName); - DrawString(out, description, linePosition); - linePosition.y += 15; + drawStringAndAdvanceLine(description); } std::string description; if (IsLoopback) { description = std::string(_("Offline Game")); - } else if (!PublicGame) { + } else if (PublicGame) { + description = std::string(_("Public Game")); + } else { description = std::string(_("Password: ")); description.append(GamePassword); - } else { - description = std::string(_("Public Game")); } - DrawString(out, description, linePosition); - linePosition.y += 15; + drawStringAndAdvanceLine(description); } if (setlevel) { - DrawString(out, _(QuestLevelNames[setlvlnum]), linePosition); - return; - } - - std::string description; - switch (leveltype) { - case DTYPE_NEST: - description = fmt::format(fmt::runtime(_("Level: Nest {:d}")), currlevel - 16); - break; - case DTYPE_CRYPT: - description = fmt::format(fmt::runtime(_("Level: Crypt {:d}")), currlevel - 20); - break; - case DTYPE_TOWN: - description = std::string(_("Town")); - break; - default: - description = fmt::format(fmt::runtime(_("Level: {:d}")), currlevel); - break; + drawStringAndAdvanceLine(_(QuestLevelNames[setlvlnum])); + } else { + std::string description; + switch (leveltype) { + case DTYPE_NEST: + description = fmt::format(fmt::runtime(_("Level: Nest {:d}")), currlevel - 16); + break; + case DTYPE_CRYPT: + description = fmt::format(fmt::runtime(_("Level: Crypt {:d}")), currlevel - 20); + break; + case DTYPE_TOWN: + description = std::string(_("Town")); + break; + default: + description = fmt::format(fmt::runtime(_("Level: {:d}")), currlevel); + break; + } + drawStringAndAdvanceLine(description); } - DrawString(out, description, linePosition); - linePosition.y += 15; std::string_view difficulty; switch (sgGameInitInfo.nDifficulty) { case DIFF_NORMAL: @@ -1472,42 +1477,28 @@ void DrawAutomapText(const Surface &out) break; } - const std::string difficultyString = fmt::format(fmt::runtime(_(/* TRANSLATORS: {:s} means: Game Difficulty. */ "Difficulty: {:s}")), difficulty); - DrawString(out, difficultyString, linePosition); + const std::string description = fmt::format(fmt::runtime(_(/* TRANSLATORS: {:s} means: Game Difficulty. */ "Difficulty: {:s}")), difficulty); + drawStringAndAdvanceLine(description); #ifdef _DEBUG - const TextRenderOptions debugTextOptions { + const TextRenderOptions disabled { + .flags = UiFlags::ColorBlack, + }; + const TextRenderOptions enabled { .flags = UiFlags::ColorOrange, }; - linePosition.y += 45; - if (DebugGodMode) { - linePosition.y += 15; - DrawString(out, "God Mode", linePosition, debugTextOptions); - } - if (DebugInvisible) { - linePosition.y += 15; - DrawString(out, "Invisible", linePosition, debugTextOptions); - } - if (DisableLighting) { - linePosition.y += 15; - DrawString(out, "Fullbright", linePosition, debugTextOptions); - } - if (DebugVision) { - linePosition.y += 15; - DrawString(out, "Draw Vision", linePosition, debugTextOptions); - } - if (DebugPath) { - linePosition.y += 15; - DrawString(out, "Draw Path", linePosition, debugTextOptions); - } - if (DebugGrid) { - linePosition.y += 15; - DrawString(out, "Draw Grid", linePosition, debugTextOptions); - } - if (DebugScrollViewEnabled) { - linePosition.y += 15; - DrawString(out, "Scroll View", linePosition, debugTextOptions); - } + + advanceLine(); + drawStringAndAdvanceLine("Debug toggles:"); + drawStringAndAdvanceLine("Player:"); + drawStringAndAdvanceLine("God Mode", DebugGodMode ? enabled : disabled); + drawStringAndAdvanceLine("Invisible", DebugInvisible ? enabled : disabled); + drawStringAndAdvanceLine("Display:"); + drawStringAndAdvanceLine("Fullbright", DisableLighting ? enabled : disabled); + drawStringAndAdvanceLine("Draw Vision", DebugVision ? enabled : disabled); + drawStringAndAdvanceLine("Draw Path", DebugPath ? enabled : disabled); + drawStringAndAdvanceLine("Draw Grid", DebugGrid ? enabled : disabled); + drawStringAndAdvanceLine("Scroll View", DebugScrollViewEnabled ? enabled : disabled); #endif }