106 lines
2.7 KiB
C++
106 lines
2.7 KiB
C++
#include "writer.hpp"
|
|
|
|
#include "text.hpp" // Para Text
|
|
|
|
// Actualiza el objeto (delta_time en ms)
|
|
void Writer::update(float delta_time) {
|
|
if (enabled_) {
|
|
if (!completed_) {
|
|
// No completado
|
|
writing_timer_ += delta_time;
|
|
if (writing_timer_ >= speed_interval_) {
|
|
index_++;
|
|
writing_timer_ = 0.0f;
|
|
}
|
|
|
|
if (index_ == length_) {
|
|
completed_ = true;
|
|
}
|
|
} else {
|
|
// Completado
|
|
enabled_timer_ += delta_time;
|
|
finished_ = enabled_timer_ >= enabled_timer_target_;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Actualiza el objeto (delta_time en segundos)
|
|
void Writer::updateS(float delta_time) {
|
|
// Convierte segundos a milisegundos y usa la lógica normal
|
|
update(delta_time * 1000.0f);
|
|
}
|
|
|
|
// Dibuja el objeto en pantalla
|
|
void Writer::render() const {
|
|
if (enabled_) {
|
|
text_->write(pos_x_, pos_y_, caption_, kerning_, index_);
|
|
}
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setPosX(int value) {
|
|
pos_x_ = value;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setPosY(int value) {
|
|
pos_y_ = value;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setKerning(int value) {
|
|
kerning_ = value;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setCaption(const std::string& text) {
|
|
caption_ = text;
|
|
length_ = text.length();
|
|
}
|
|
|
|
// Establece el valor de la variable (frames)
|
|
void Writer::setSpeed(int value) {
|
|
// Convierte frames a milisegundos (frames * 16.67ms)
|
|
constexpr float FRAME_TIME_MS = 16.67f;
|
|
speed_interval_ = static_cast<float>(value) * FRAME_TIME_MS;
|
|
writing_timer_ = 0.0f;
|
|
}
|
|
|
|
// Establece la velocidad en segundos entre caracteres
|
|
void Writer::setSpeedS(float value) {
|
|
// Convierte segundos a milisegundos para consistencia interna
|
|
speed_interval_ = value * 1000.0f;
|
|
writing_timer_ = 0.0f;
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Writer::setEnabled(bool value) {
|
|
enabled_ = value;
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
auto Writer::isEnabled() const -> bool {
|
|
return enabled_;
|
|
}
|
|
|
|
// Establece el temporizador para deshabilitar el objeto (en milisegundos)
|
|
void Writer::setFinishedTimerMs(float time_ms) {
|
|
enabled_timer_target_ = time_ms;
|
|
enabled_timer_ = 0.0f;
|
|
}
|
|
|
|
// Establece el temporizador para deshabilitar el objeto (en segundos)
|
|
void Writer::setFinishedTimerS(float time_s) {
|
|
enabled_timer_target_ = time_s * 1000.0f; // Convertir segundos a milisegundos
|
|
enabled_timer_ = 0.0f;
|
|
}
|
|
|
|
// Centra la cadena de texto a un punto X
|
|
void Writer::center(int x) {
|
|
setPosX(x - (text_->length(caption_, kerning_) / 2));
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
auto Writer::hasFinished() const -> bool {
|
|
return finished_;
|
|
} |