forked from jaildesigner-jailgames/jaildoctors_dilemma
afegit typewriter effect a console
This commit is contained in:
@@ -893,10 +893,14 @@ void Console::redrawText() {
|
||||
SDL_FRect rect = {.x = 0, .y = 0, .w = WIDTH, .h = height_};
|
||||
surface_->drawRectBorder(&rect, BORDER_COLOR);
|
||||
|
||||
// Líneas de mensaje (una o más); las que no caben en la Surface no se dibujan
|
||||
// Líneas de mensaje con efecto typewriter (solo muestra los primeros typewriter_chars_)
|
||||
int y_pos = PADDING_IN_V;
|
||||
int remaining = typewriter_chars_;
|
||||
for (const auto& line : msg_lines_) {
|
||||
text_->writeColored(PADDING_IN_H, y_pos, line, MSG_COLOR);
|
||||
if (remaining <= 0) { break; }
|
||||
const int VISIBLE = std::min(remaining, static_cast<int>(line.size()));
|
||||
text_->writeColored(PADDING_IN_H, y_pos, line.substr(0, VISIBLE), MSG_COLOR);
|
||||
remaining -= VISIBLE;
|
||||
y_pos += TEXT_SIZE;
|
||||
}
|
||||
|
||||
@@ -924,6 +928,19 @@ void Console::update(float delta_time) {
|
||||
}
|
||||
}
|
||||
|
||||
// Efecto typewriter: revelar letras una a una (solo cuando ACTIVE)
|
||||
if (status_ == Status::ACTIVE) {
|
||||
int total_chars = 0;
|
||||
for (const auto& line : msg_lines_) { total_chars += static_cast<int>(line.size()); }
|
||||
if (typewriter_chars_ < total_chars) {
|
||||
typewriter_timer_ += delta_time;
|
||||
while (typewriter_timer_ >= TYPEWRITER_CHAR_DELAY && typewriter_chars_ < total_chars) {
|
||||
typewriter_timer_ -= TYPEWRITER_CHAR_DELAY;
|
||||
++typewriter_chars_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Animación de altura (resize cuando msg_lines_ cambia); solo en ACTIVE
|
||||
if (status_ == Status::ACTIVE && height_ != target_height_) {
|
||||
const float PREV_HEIGHT = height_;
|
||||
@@ -998,6 +1015,9 @@ void Console::toggle() {
|
||||
input_line_.clear();
|
||||
cursor_timer_ = 0.0F;
|
||||
cursor_visible_ = true;
|
||||
// El mensaje inicial ("JDD Console v1.0") aparece completo, sin typewriter
|
||||
typewriter_chars_ = static_cast<int>(msg_lines_[0].size());
|
||||
typewriter_timer_ = 0.0F;
|
||||
SDL_StartTextInput(SDL_GetKeyboardFocus());
|
||||
if (Notifier::get() != nullptr) {
|
||||
const int OFFSET = static_cast<int>(height_);
|
||||
@@ -1109,6 +1129,10 @@ void Console::processCommand() {
|
||||
|
||||
// Actualizar la altura objetivo para animar el resize
|
||||
target_height_ = calcTargetHeight(static_cast<int>(msg_lines_.size()));
|
||||
|
||||
// Reiniciar el typewriter para revelar la respuesta letra a letra
|
||||
typewriter_chars_ = 0;
|
||||
typewriter_timer_ = 0.0F;
|
||||
}
|
||||
}
|
||||
input_line_.clear();
|
||||
|
||||
Reference in New Issue
Block a user