87 lines
2.0 KiB
C++
87 lines
2.0 KiB
C++
#include "writer.h"
|
|
|
|
#include "text.h" // Para Text
|
|
|
|
// Actualiza el objeto
|
|
void Writer::update(float delta_time) {
|
|
if (enabled_) {
|
|
if (!completed_) {
|
|
// No completado
|
|
writing_timer_ += delta_time;
|
|
if (writing_timer_ >= speed_ms_) {
|
|
index_++;
|
|
writing_timer_ = 0.0f;
|
|
}
|
|
|
|
if (index_ == length_) {
|
|
completed_ = true;
|
|
}
|
|
} else {
|
|
// Completado
|
|
enabled_timer_ += delta_time;
|
|
finished_ = enabled_timer_ >= enabled_timer_target_;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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
|
|
void Writer::setSpeed(int value) {
|
|
// Convierte frames a milisegundos (frames * 16.67ms)
|
|
constexpr float FRAME_TIME_MS = 1000.0f / 60.0f;
|
|
speed_ms_ = static_cast<float>(value) * FRAME_TIME_MS;
|
|
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;
|
|
}
|
|
|
|
// 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_;
|
|
} |