la consola ja no va per velocitat sino per temps
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "core/input/key_config.hpp" // Para KeyConfig
|
||||
#include "core/rendering/screen.hpp" // Para Screen
|
||||
#include "core/rendering/sprite/sprite.hpp" // Para Sprite
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
@@ -15,6 +16,7 @@
|
||||
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||
#include "game/options.hpp" // Para Options
|
||||
#include "game/ui/notifier.hpp" // Para Notifier
|
||||
#include "utils/easing_functions.hpp" // Para Easing::cubicInOut
|
||||
|
||||
// ── Helpers de texto ──────────────────────────────────────────────────────────
|
||||
|
||||
@@ -220,11 +222,17 @@ void Console::update(float delta_time) { // NOLINT(readability-function-cogniti
|
||||
|
||||
// Animación de altura (resize cuando msg_lines_ cambia); solo en ACTIVE
|
||||
if (status_ == Status::ACTIVE && height_ != target_height_) {
|
||||
if (anim_progress_ == 0.0F) {
|
||||
// Iniciar animación de resize
|
||||
anim_start_ = height_;
|
||||
anim_end_ = target_height_;
|
||||
}
|
||||
anim_progress_ = std::min(anim_progress_ + (delta_time / ANIM_DURATION), 1.0F);
|
||||
const float PREV_HEIGHT = height_;
|
||||
if (height_ < target_height_) {
|
||||
height_ = std::min(height_ + (SLIDE_SPEED * delta_time), target_height_);
|
||||
} else {
|
||||
height_ = std::max(height_ - (SLIDE_SPEED * delta_time), target_height_);
|
||||
height_ = anim_start_ + ((anim_end_ - anim_start_) * Easing::cubicInOut(anim_progress_));
|
||||
if (anim_progress_ >= 1.0F) {
|
||||
height_ = target_height_;
|
||||
anim_progress_ = 0.0F;
|
||||
}
|
||||
// Actualizar el Notifier incrementalmente con el delta de altura
|
||||
if (Notifier::get() != nullptr) {
|
||||
@@ -246,28 +254,22 @@ void Console::update(float delta_time) { // NOLINT(readability-function-cogniti
|
||||
// Redibujar texto cada frame
|
||||
redrawText();
|
||||
|
||||
switch (status_) {
|
||||
case Status::RISING: {
|
||||
y_ += SLIDE_SPEED * delta_time;
|
||||
if (y_ >= 0.0F) {
|
||||
y_ = 0.0F;
|
||||
// Animación de apertura/cierre (basada en tiempo)
|
||||
if (status_ == Status::RISING || status_ == Status::VANISHING) {
|
||||
anim_progress_ = std::min(anim_progress_ + (delta_time / ANIM_DURATION), 1.0F);
|
||||
y_ = anim_start_ + ((anim_end_ - anim_start_) * Easing::cubicInOut(anim_progress_));
|
||||
|
||||
if (anim_progress_ >= 1.0F) {
|
||||
y_ = anim_end_;
|
||||
anim_progress_ = 0.0F;
|
||||
if (status_ == Status::RISING) {
|
||||
status_ = Status::ACTIVE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Status::VANISHING: {
|
||||
y_ -= SLIDE_SPEED * delta_time;
|
||||
if (y_ <= -height_) {
|
||||
y_ = -height_;
|
||||
} else {
|
||||
status_ = Status::HIDDEN;
|
||||
// Resetear el mensaje una vez completamente oculta
|
||||
msg_lines_ = {std::string(CONSOLE_NAME) + " " + std::string(CONSOLE_VERSION)};
|
||||
target_height_ = calcTargetHeight(static_cast<int>(msg_lines_.size()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_FRect rect = {.x = 0, .y = y_, .w = Options::game.width, .h = height_};
|
||||
@@ -291,6 +293,9 @@ void Console::toggle() {
|
||||
target_height_ = calcTargetHeight(static_cast<int>(msg_lines_.size()));
|
||||
height_ = target_height_;
|
||||
y_ = -height_;
|
||||
anim_start_ = y_;
|
||||
anim_end_ = 0.0F;
|
||||
anim_progress_ = 0.0F;
|
||||
status_ = Status::RISING;
|
||||
input_line_.clear();
|
||||
cursor_timer_ = 0.0F;
|
||||
@@ -308,8 +313,11 @@ void Console::toggle() {
|
||||
break;
|
||||
case Status::ACTIVE:
|
||||
// Al cerrar: mantener el texto visible hasta que esté completamente oculta
|
||||
anim_start_ = y_;
|
||||
anim_end_ = -height_;
|
||||
anim_progress_ = 0.0F;
|
||||
status_ = Status::VANISHING;
|
||||
target_height_ = height_; // No animar durante VANISHING
|
||||
target_height_ = height_; // No animar altura durante VANISHING
|
||||
history_index_ = -1;
|
||||
saved_input_.clear();
|
||||
SDL_StopTextInput(SDL_GetKeyboardFocus());
|
||||
@@ -332,6 +340,15 @@ void Console::handleEvent(const SDL_Event& event) { // NOLINT(readability-funct
|
||||
if (event.type == SDL_EVENT_TEXT_INPUT) {
|
||||
// Filtrar caracteres de control (tab, newline, etc.)
|
||||
if (static_cast<unsigned char>(event.text.text[0]) < 32) { return; }
|
||||
// Ignorar texto si la tecla toggle está pulsada (evita escribir su carácter)
|
||||
if (KeyConfig::get() != nullptr) {
|
||||
SDL_Keycode toggle_key = KeyConfig::get()->key("GLOBAL", "console");
|
||||
SDL_Scancode toggle_sc = SDL_GetScancodeFromKey(toggle_key, nullptr);
|
||||
if (toggle_sc != SDL_SCANCODE_UNKNOWN) {
|
||||
const bool* ks = SDL_GetKeyboardState(nullptr);
|
||||
if (ks[toggle_sc]) { return; }
|
||||
}
|
||||
}
|
||||
if (static_cast<int>(input_line_.size()) < MAX_LINE_CHARS) {
|
||||
input_line_ += event.text.text;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user