Game console fixes

This commit is contained in:
fed 2023-08-23 02:51:21 +02:00
parent 7823fa9a93
commit c69f59fa5b
2 changed files with 34 additions and 5 deletions

View File

@ -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<int>(i), truncated.data(),
dvars::con_inputDvarValueColor->current.vector, offset);
draw_hint_text(static_cast<int>(i), matches[i].description.data(),
draw_hint_text(static_cast<int>(i), truncated_desc.data(),
dvars::con_inputDvarValueColor->current.vector, offset * 1.5f);
}
}

View File

@ -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)