separacio de linies automatica en console
This commit is contained in:
@@ -792,11 +792,9 @@ static const std::vector<ConsoleCommand> COMMANDS = {
|
||||
{.keyword = "HELP", .execute = [](const std::vector<std::string>&) -> std::string {
|
||||
printHelp();
|
||||
std::string result =
|
||||
"Commands (see terminal):\n"
|
||||
"fullscreen, zoom, intscale, vsync, driver\n"
|
||||
"palette, audio, music, sound, set\n"
|
||||
"restart, kiosk, exit, quit, show\n"
|
||||
"hide, size, help\n";
|
||||
"Commands:\n"
|
||||
"fullscreen, zoom, intscale, vsync, driver, palette, audio, music, sound, set, restart, kiosk, exit, quit, show, hide, size, help\n"
|
||||
"-- more info on the terminal";
|
||||
|
||||
#ifdef _DEBUG
|
||||
result += "\n[debug] debug room scene";
|
||||
@@ -807,14 +805,9 @@ static const std::vector<ConsoleCommand> COMMANDS = {
|
||||
{.keyword = "?", .execute = [](const std::vector<std::string>&) -> std::string {
|
||||
printHelp();
|
||||
std::string result =
|
||||
"Commands (see terminal):\n"
|
||||
"[video] fullscreen zoom\n"
|
||||
"intscale vsync driver\n"
|
||||
"palette\n"
|
||||
"[audio] audio music sound\n"
|
||||
"[game] set restart kiosk\n"
|
||||
"exit quit\n"
|
||||
"[info] show hide size help";
|
||||
"Commands:\n"
|
||||
"fullscreen, zoom, intscale, vsync, driver, palette, audio, music, sound, set, restart, kiosk, exit, quit, show, hide, size, help\n"
|
||||
"-- more info on the terminal";
|
||||
#ifdef _DEBUG
|
||||
result += "\n[debug] debug room scene";
|
||||
result += "\ncheat";
|
||||
@@ -832,6 +825,39 @@ static auto calcTargetHeight(int num_msg_lines) -> float {
|
||||
return static_cast<float>((TEXT_SIZE * (num_msg_lines + 1)) + (PADDING_IN_V * 2));
|
||||
}
|
||||
|
||||
// Divide text en líneas respetando los \n existentes y haciendo word-wrap por ancho en píxeles
|
||||
auto Console::wrapText(const std::string& text) const -> std::vector<std::string> {
|
||||
constexpr int PADDING_IN_H = 6; // TEXT_SIZE; simétrico a ambos lados
|
||||
const int MAX_PX = static_cast<int>(Options::game.width) - (2 * PADDING_IN_H);
|
||||
|
||||
std::vector<std::string> result;
|
||||
std::istringstream segment_stream(text);
|
||||
std::string segment;
|
||||
|
||||
while (std::getline(segment_stream, segment)) {
|
||||
if (segment.empty()) {
|
||||
result.emplace_back();
|
||||
continue;
|
||||
}
|
||||
std::string current_line;
|
||||
std::istringstream word_stream(segment);
|
||||
std::string word;
|
||||
while (word_stream >> word) {
|
||||
const std::string TEST = current_line.empty() ? word : (current_line + ' ' + word);
|
||||
if (text_->length(TEST) <= MAX_PX) {
|
||||
current_line = TEST;
|
||||
} else {
|
||||
if (!current_line.empty()) { result.push_back(current_line); }
|
||||
current_line = word;
|
||||
}
|
||||
}
|
||||
if (!current_line.empty()) { result.push_back(current_line); }
|
||||
}
|
||||
|
||||
if (result.empty()) { result.emplace_back(); }
|
||||
return result;
|
||||
}
|
||||
|
||||
// ── Singleton ─────────────────────────────────────────────────────────────────
|
||||
|
||||
// [SINGLETON]
|
||||
@@ -1115,17 +1141,8 @@ void Console::processCommand() {
|
||||
}
|
||||
if (!found) { result = "Unknown: " + cmd; }
|
||||
|
||||
// Split en '\n' y truncar cada línea a MAX_LINE_CHARS
|
||||
msg_lines_.clear();
|
||||
std::istringstream stream(result);
|
||||
std::string line;
|
||||
while (std::getline(stream, line)) {
|
||||
if (static_cast<int>(line.size()) > MAX_LINE_CHARS) {
|
||||
line.resize(MAX_LINE_CHARS);
|
||||
}
|
||||
msg_lines_.push_back(std::move(line));
|
||||
}
|
||||
if (msg_lines_.empty()) { msg_lines_.push_back({}); }
|
||||
// Word-wrap automático según el ancho disponible en píxeles
|
||||
msg_lines_ = wrapText(result);
|
||||
|
||||
// Actualizar la altura objetivo para animar el resize
|
||||
target_height_ = calcTargetHeight(static_cast<int>(msg_lines_.size()));
|
||||
|
||||
Reference in New Issue
Block a user