From c69f59fa5b162d32aa5eb811fe31f619c41ebc79 Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Wed, 23 Aug 2023 02:51:21 +0200 Subject: [PATCH] Game console fixes --- src/client/component/game_console.cpp | 13 +++++++++++-- src/common/utils/string.cpp | 26 +++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/client/component/game_console.cpp b/src/client/component/game_console.cpp index ecd46c3a..32bb6129 100644 --- a/src/client/component/game_console.cpp +++ b/src/client/component/game_console.cpp @@ -239,7 +239,15 @@ namespace game_console else if (matches.size() == 1) { auto* const dvar = game::Dvar_FindVar(matches[0].name.data()); - const auto line_count = dvar ? 3 : 1; + auto line_count = dvar ? 3 : 1; + + for (const auto& c : matches[0].description) + { + if (c == '\n') + { + ++line_count; + } + } const auto height = draw_hint_box(line_count, dvars::con_inputHintBoxColor->current.vector); draw_hint_text(0, matches[0].name.data(), dvar @@ -290,11 +298,12 @@ namespace game_console { const auto value = game::Dvar_ValueToString(dvar, nullptr, &dvar->current); const auto truncated = utils::string::truncate(value, 34, "..."); + const auto truncated_desc = utils::string::truncate(matches[i].description, 160, "..."); draw_hint_text(static_cast(i), truncated.data(), dvars::con_inputDvarValueColor->current.vector, offset); - draw_hint_text(static_cast(i), matches[i].description.data(), + draw_hint_text(static_cast(i), truncated_desc.data(), dvars::con_inputDvarValueColor->current.vector, offset * 1.5f); } } diff --git a/src/common/utils/string.cpp b/src/common/utils/string.cpp index 43c37e3f..eca34948 100644 --- a/src/common/utils/string.cpp +++ b/src/common/utils/string.cpp @@ -216,9 +216,29 @@ namespace utils::string std::string truncate(const std::string& text, const size_t length, const std::string& end) { - return text.size() <= length - ? text - : text.substr(0, length - end.size()) + end; + const auto new_line = text.find_first_of('\n'); + if (text.size() <= length) + { + if (new_line == std::string::npos) + { + return text; + } + else + { + return text.substr(0, new_line + 1); + } + } + else + { + if (new_line == std::string::npos) + { + return text.substr(0, length - end.size()) + end; + } + else + { + return text.substr(0, std::min(new_line + 1, length) - end.size()) + end; + } + } } bool strstr_lower(const char* a, const char* b)