forked from jaildesigner-jailgames/jaildoctors_dilemma
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 {
|
{.keyword = "HELP", .execute = [](const std::vector<std::string>&) -> std::string {
|
||||||
printHelp();
|
printHelp();
|
||||||
std::string result =
|
std::string result =
|
||||||
"Commands (see terminal):\n"
|
"Commands:\n"
|
||||||
"fullscreen, zoom, intscale, vsync, driver\n"
|
"fullscreen, zoom, intscale, vsync, driver, palette, audio, music, sound, set, restart, kiosk, exit, quit, show, hide, size, help\n"
|
||||||
"palette, audio, music, sound, set\n"
|
"-- more info on the terminal";
|
||||||
"restart, kiosk, exit, quit, show\n"
|
|
||||||
"hide, size, help\n";
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
result += "\n[debug] debug room scene";
|
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 {
|
{.keyword = "?", .execute = [](const std::vector<std::string>&) -> std::string {
|
||||||
printHelp();
|
printHelp();
|
||||||
std::string result =
|
std::string result =
|
||||||
"Commands (see terminal):\n"
|
"Commands:\n"
|
||||||
"[video] fullscreen zoom\n"
|
"fullscreen, zoom, intscale, vsync, driver, palette, audio, music, sound, set, restart, kiosk, exit, quit, show, hide, size, help\n"
|
||||||
"intscale vsync driver\n"
|
"-- more info on the terminal";
|
||||||
"palette\n"
|
|
||||||
"[audio] audio music sound\n"
|
|
||||||
"[game] set restart kiosk\n"
|
|
||||||
"exit quit\n"
|
|
||||||
"[info] show hide size help";
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
result += "\n[debug] debug room scene";
|
result += "\n[debug] debug room scene";
|
||||||
result += "\ncheat";
|
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));
|
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 ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
// [SINGLETON]
|
// [SINGLETON]
|
||||||
@@ -1115,17 +1141,8 @@ void Console::processCommand() {
|
|||||||
}
|
}
|
||||||
if (!found) { result = "Unknown: " + cmd; }
|
if (!found) { result = "Unknown: " + cmd; }
|
||||||
|
|
||||||
// Split en '\n' y truncar cada línea a MAX_LINE_CHARS
|
// Word-wrap automático según el ancho disponible en píxeles
|
||||||
msg_lines_.clear();
|
msg_lines_ = wrapText(result);
|
||||||
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({}); }
|
|
||||||
|
|
||||||
// Actualizar la altura objetivo para animar el resize
|
// Actualizar la altura objetivo para animar el resize
|
||||||
target_height_ = calcTargetHeight(static_cast<int>(msg_lines_.size()));
|
target_height_ = calcTargetHeight(static_cast<int>(msg_lines_.size()));
|
||||||
|
|||||||
@@ -49,12 +49,12 @@ class Console {
|
|||||||
|
|
||||||
// Constantes de consola
|
// Constantes de consola
|
||||||
static constexpr std::string_view CONSOLE_NAME = "JDD Console";
|
static constexpr std::string_view CONSOLE_NAME = "JDD Console";
|
||||||
static constexpr std::string_view CONSOLE_VERSION = "v1.0";
|
static constexpr std::string_view CONSOLE_VERSION = "v2.0";
|
||||||
static constexpr int MAX_LINE_CHARS = 32;
|
static constexpr int MAX_LINE_CHARS = 32;
|
||||||
static constexpr int MAX_HISTORY_SIZE = 20;
|
static constexpr int MAX_HISTORY_SIZE = 20;
|
||||||
static constexpr float CURSOR_ON_TIME = 0.5F;
|
static constexpr float CURSOR_ON_TIME = 0.5F;
|
||||||
static constexpr float CURSOR_OFF_TIME = 0.3F;
|
static constexpr float CURSOR_OFF_TIME = 0.3F;
|
||||||
static constexpr float TYPEWRITER_CHAR_DELAY = 0.03F; // segundos entre letra y letra
|
static constexpr float TYPEWRITER_CHAR_DELAY = 0.01F; // segundos entre letra y letra
|
||||||
|
|
||||||
// [SINGLETON]
|
// [SINGLETON]
|
||||||
static Console* console;
|
static Console* console;
|
||||||
@@ -67,6 +67,7 @@ class Console {
|
|||||||
void buildSurface(); // Crea la Surface con el aspecto visual
|
void buildSurface(); // Crea la Surface con el aspecto visual
|
||||||
void redrawText(); // Redibuja el texto dinámico (msg + input + cursor)
|
void redrawText(); // Redibuja el texto dinámico (msg + input + cursor)
|
||||||
void processCommand(); // Procesa el comando introducido por el usuario
|
void processCommand(); // Procesa el comando introducido por el usuario
|
||||||
|
[[nodiscard]] auto wrapText(const std::string& text) const -> std::vector<std::string>; // Word-wrap por ancho en píxeles
|
||||||
|
|
||||||
// Objetos de renderizado
|
// Objetos de renderizado
|
||||||
std::shared_ptr<Text> text_;
|
std::shared_ptr<Text> text_;
|
||||||
|
|||||||
Reference in New Issue
Block a user