Text: revisada la classe
window_message: correcions
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
"[CREDITS] MUSIC_COMPOSED_BY": "MUSICA COMPOSADA PER",
|
||||
"[CREDITS] SOUND_EFFECTS": "EFECTES DE SO",
|
||||
|
||||
"[DEFINE_BUTTONS] TITLE": "define buttons title",
|
||||
"[DEFINE_BUTTONS] FIRE_LEFT": "Disparar cap a l'esquerra",
|
||||
"[DEFINE_BUTTONS] FIRE_UP": "Disparar cap amunt",
|
||||
"[DEFINE_BUTTONS] FIRE_RIGHT": "Disparar cap a la dreta",
|
||||
@@ -11,6 +12,10 @@
|
||||
"[DEFINE_BUTTONS] SERVICE_MENU": "Menu de servei",
|
||||
"[DEFINE_BUTTONS] PLAYER": "Jugador",
|
||||
"[DEFINE_BUTTONS] KEYBOARD": "Teclat",
|
||||
"[DEFINE_BUTTONS] CONFIGURATION_COMPLETE" : "Configuracio completada",
|
||||
"[DEFINE_BUTTONS] CONFIGURING" : "Configurant",
|
||||
"[DEFINE_BUTTONS] PRESS_BUTTON_FOR" : "Prem un boto per a",
|
||||
"[DEFINE_BUTTONS] CONFIGURED" : "configurat",
|
||||
|
||||
"[GAME_TEXT] 1": "Felicitats!!",
|
||||
"[GAME_TEXT] 2": " fases mes!",
|
||||
|
||||
@@ -8,9 +8,13 @@
|
||||
"[DEFINE_BUTTONS] FIRE_UP" : "Fire up",
|
||||
"[DEFINE_BUTTONS] FIRE_RIGHT" : "Fire right",
|
||||
"[DEFINE_BUTTONS] START" : "Start",
|
||||
"[DEFINE_BUTTONS] SERVICE_MENU": "Service menu",
|
||||
"[DEFINE_BUTTONS] SERVICE_MENU" : "Service menu",
|
||||
"[DEFINE_BUTTONS] PLAYER" : "Player",
|
||||
"[DEFINE_BUTTONS] KEYBOARD" : "Keyboard",
|
||||
"[DEFINE_BUTTONS] CONFIGURATION_COMPLETE": "Configuration complete",
|
||||
"[DEFINE_BUTTONS] CONFIGURING" : "Configuring",
|
||||
"[DEFINE_BUTTONS] PRESS_BUTTON_FOR" : "Press button for",
|
||||
"[DEFINE_BUTTONS] CONFIGURED" : "Configured",
|
||||
|
||||
"[GAME_TEXT] 1": "Congratulations!!",
|
||||
"[GAME_TEXT] 2": " stages left!",
|
||||
@@ -103,15 +107,15 @@
|
||||
"[SERVICE_MENU] NO_CONTROLLER": "None",
|
||||
"[SERVICE_MENU] SWAP_CONTROLLERS": "Swap Controllers",
|
||||
|
||||
"[SCOREBOARD] 1": "Player 1",
|
||||
"[SCOREBOARD] 2": "Player 2",
|
||||
"[SCOREBOARD] 3": "Multiplier",
|
||||
"[SCOREBOARD] 4": "High Score",
|
||||
"[SCOREBOARD] 5": "Stage",
|
||||
"[SCOREBOARD] 6": "Demo mode",
|
||||
"[SCOREBOARD] 7": "Game Over",
|
||||
"[SCOREBOARD] 8": "Press START",
|
||||
"[SCOREBOARD] 9": "to play",
|
||||
"[SCOREBOARD] 1" : "Player 1",
|
||||
"[SCOREBOARD] 2" : "Player 2",
|
||||
"[SCOREBOARD] 3" : "Multiplier",
|
||||
"[SCOREBOARD] 4" : "High Score",
|
||||
"[SCOREBOARD] 5" : "Stage",
|
||||
"[SCOREBOARD] 6" : "Demo mode",
|
||||
"[SCOREBOARD] 7" : "Game Over",
|
||||
"[SCOREBOARD] 8" : "Press START",
|
||||
"[SCOREBOARD] 9" : "to play",
|
||||
"[SCOREBOARD] 10": "Continue?",
|
||||
"[SCOREBOARD] 11": "Enter name",
|
||||
"[SCOREBOARD] 12": "Please",
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
{
|
||||
"[CREDITS] PROGRAMMED_AND_DESIGNED_BY": "PROGRAMADO Y DISENADO POR",
|
||||
"[CREDITS] PIXELART_DRAWN_BY": "GRAFICOS DIBUJADOS POR",
|
||||
"[CREDITS] MUSIC_COMPOSED_BY": "MUSICA COMPUESTA POR",
|
||||
"[CREDITS] SOUND_EFFECTS": "EFECTOS DE SONIDO",
|
||||
"[CREDITS] PIXELART_DRAWN_BY" : "GRAFICOS DIBUJADOS POR",
|
||||
"[CREDITS] MUSIC_COMPOSED_BY" : "MUSICA COMPUESTA POR",
|
||||
"[CREDITS] SOUND_EFFECTS" : "EFECTOS DE SONIDO",
|
||||
|
||||
"[DEFINE_BUTTONS] FIRE_LEFT": "Disparar a la izquierda",
|
||||
"[DEFINE_BUTTONS] FIRE_UP": "Disparar hacia arriba",
|
||||
"[DEFINE_BUTTONS] FIRE_RIGHT": "Disparar hacia la derecha",
|
||||
"[DEFINE_BUTTONS] START": "Start",
|
||||
"[DEFINE_BUTTONS] SERVICE_MENU": "Menu de servicio",
|
||||
"[DEFINE_BUTTONS] PLAYER": "Jugador",
|
||||
"[DEFINE_BUTTONS] KEYBOARD": "Teclado",
|
||||
"[DEFINE_BUTTONS] FIRE_LEFT" : "Disparar a la izquierda",
|
||||
"[DEFINE_BUTTONS] FIRE_UP" : "Disparar hacia arriba",
|
||||
"[DEFINE_BUTTONS] FIRE_RIGHT" : "Disparar hacia la derecha",
|
||||
"[DEFINE_BUTTONS] START" : "Start",
|
||||
"[DEFINE_BUTTONS] SERVICE_MENU" : "Menu de servicio",
|
||||
"[DEFINE_BUTTONS] PLAYER" : "Jugador",
|
||||
"[DEFINE_BUTTONS] KEYBOARD" : "Teclado",
|
||||
"[DEFINE_BUTTONS] CONFIGURATION_COMPLETE": "Configuracion completada",
|
||||
"[DEFINE_BUTTONS] CONFIGURING" : "Configurando",
|
||||
"[DEFINE_BUTTONS] PRESS_BUTTON_FOR" : "Pulsa un boton para",
|
||||
"[DEFINE_BUTTONS] CONFIGURED" : "Configurado",
|
||||
|
||||
"[GAME_TEXT] 1": "Felicidades!!",
|
||||
"[GAME_TEXT] 2": " fases mas!",
|
||||
|
||||
@@ -28,14 +28,14 @@ DefineButtons::DefineButtons()
|
||||
window_message_ = std::make_unique<WindowMessage>(
|
||||
text_renderer,
|
||||
Lang::getText("[DEFINE_BUTTONS] TITLE"),
|
||||
Color{20, 30, 50, 200}, // Fondo azul oscuro semi-transparente
|
||||
Color{20, 30, 50, 208}, // Fondo azul oscuro semi-transparente
|
||||
Color{100, 150, 200, 255}, // Borde azul claro
|
||||
Color{255, 255, 255, 255}, // Título blanco
|
||||
Color{100, 150, 200, 255}, // Titulo azul claro
|
||||
Color{220, 220, 220, 255} // Texto gris claro
|
||||
);
|
||||
|
||||
window_message_->setPadding(20.0f);
|
||||
window_message_->setLineSpacing(8.0f);
|
||||
window_message_->setPadding(0.0f);
|
||||
window_message_->setLineSpacing(0.0f);
|
||||
}
|
||||
|
||||
void DefineButtons::render() {
|
||||
@@ -173,10 +173,10 @@ void DefineButtons::updateWindowMessage() {
|
||||
|
||||
if (index_button_ < buttons_.size()) {
|
||||
// Mostrar progreso
|
||||
std::string progress = "(" + std::to_string(index_button_ + 1) + "/" +
|
||||
/*std::string progress = "(" + std::to_string(index_button_ + 1) + "/" +
|
||||
std::to_string(buttons_.size()) + ")";
|
||||
window_message_->addText(progress);
|
||||
window_message_->addText("");
|
||||
window_message_->addText("");*/
|
||||
|
||||
// Instrucción actual
|
||||
std::string instruction = Lang::getText("[DEFINE_BUTTONS] PRESS_BUTTON_FOR") + ":";
|
||||
@@ -184,7 +184,7 @@ void DefineButtons::updateWindowMessage() {
|
||||
window_message_->addText(buttons_.at(index_button_).label);
|
||||
|
||||
// Botones ya configurados
|
||||
if (index_button_ > 0) {
|
||||
/*if (index_button_ > 0) {
|
||||
window_message_->addText("");
|
||||
window_message_->addText(Lang::getText("[DEFINE_BUTTONS] CONFIGURED") + ":");
|
||||
|
||||
@@ -192,6 +192,6 @@ void DefineButtons::updateWindowMessage() {
|
||||
std::string configured = "✓ " + buttons_[i].label;
|
||||
window_message_->addText(configured);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,7 @@ auto Resource::getTexture(const std::string &name) -> std::shared_ptr<Texture> {
|
||||
}
|
||||
|
||||
// Obtiene el fichero de texto a partir de un nombre. Lanza excepción si no existe.
|
||||
auto Resource::getTextFile(const std::string &name) -> std::shared_ptr<TextFile> {
|
||||
auto Resource::getTextFile(const std::string &name) -> std::shared_ptr<Text::File> {
|
||||
auto it = std::find_if(text_files_.begin(), text_files_.end(), [&name](const auto &t) { return t.name == name; });
|
||||
|
||||
if (it != text_files_.end()) {
|
||||
@@ -225,7 +225,7 @@ void Resource::loadTextFiles() {
|
||||
for (const auto &l : list) {
|
||||
auto name = getFileName(l);
|
||||
updateLoadingProgress(name);
|
||||
text_files_.emplace_back(name, loadTextFile(l));
|
||||
text_files_.emplace_back(name, Text::loadFile(l));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class Resource {
|
||||
auto getSound(const std::string &name) -> JA_Sound_t *; // Obtiene el sonido por nombre
|
||||
auto getMusic(const std::string &name) -> JA_Music_t *; // Obtiene la música por nombre
|
||||
auto getTexture(const std::string &name) -> std::shared_ptr<Texture>; // Obtiene la textura por nombre
|
||||
auto getTextFile(const std::string &name) -> std::shared_ptr<TextFile>; // Obtiene el fichero de texto por nombre
|
||||
auto getTextFile(const std::string &name) -> std::shared_ptr<Text::File>; // Obtiene el fichero de texto por nombre
|
||||
auto getText(const std::string &name) -> std::shared_ptr<Text>; // Obtiene el objeto de texto por nombre
|
||||
auto getAnimation(const std::string &name) -> AnimationsFileBuffer &; // Obtiene la animación por nombre
|
||||
auto getDemoData(int index) -> DemoData &; // Obtiene los datos de demo por índice
|
||||
@@ -65,9 +65,9 @@ class Resource {
|
||||
|
||||
struct ResourceTextFile {
|
||||
std::string name; // Nombre del fichero
|
||||
std::shared_ptr<TextFile> text_file; // Objeto con los descriptores de la fuente de texto
|
||||
std::shared_ptr<Text::File> text_file; // Objeto con los descriptores de la fuente de texto
|
||||
|
||||
ResourceTextFile(std::string name, std::shared_ptr<TextFile> text_file)
|
||||
ResourceTextFile(std::string name, std::shared_ptr<Text::File> text_file)
|
||||
: name(std::move(name)), text_file(std::move(text_file)) {}
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR
|
||||
#include "text.h" // Para Text, Text::CENTER, Text::COLOR
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// .at(SINGLETON) Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
@@ -198,50 +198,50 @@ void Scoreboard::renderPanelContent(size_t panel_index) {
|
||||
|
||||
void Scoreboard::renderScoreMode(size_t panel_index) {
|
||||
// SCORE
|
||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_1_.x, slot4_1_.y, name_.at(panel_index), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_2_.x, slot4_2_.y, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(Text::COLOR | Text::CENTER, slot4_1_.x, slot4_1_.y, name_.at(panel_index), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::COLOR | Text::CENTER, slot4_2_.x, slot4_2_.y, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
|
||||
// MULT
|
||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 3"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_COLOR | TEXT_CENTER, slot4_4_.x, slot4_4_.y, "x" + std::to_string(mult_.at(panel_index)).substr(0, 3), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(Text::COLOR | Text::CENTER, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 3"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::COLOR | Text::CENTER, slot4_4_.x, slot4_4_.y, "x" + std::to_string(mult_.at(panel_index)).substr(0, 3), 1, text_color2_);
|
||||
}
|
||||
|
||||
void Scoreboard::renderDemoMode() {
|
||||
// DEMO MODE
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 6"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 6"), 1, text_color1_);
|
||||
|
||||
// PRESS START TO PLAY
|
||||
if (time_counter_ % 10 < 8) {
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 8"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y - 2, Lang::getText("[SCOREBOARD] 9"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 8"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y - 2, Lang::getText("[SCOREBOARD] 9"), 1, text_color1_);
|
||||
}
|
||||
}
|
||||
|
||||
void Scoreboard::renderWaitingMode() {
|
||||
// GAME OVER
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 7"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 7"), 1, text_color1_);
|
||||
|
||||
// PRESS START TO PLAY
|
||||
if (time_counter_ % 10 < 8) {
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 8"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y - 2, Lang::getText("[SCOREBOARD] 9"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 8"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y - 2, Lang::getText("[SCOREBOARD] 9"), 1, text_color1_);
|
||||
}
|
||||
}
|
||||
|
||||
void Scoreboard::renderGameOverMode() {
|
||||
// GAME OVER
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 7"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 7"), 1, text_color1_);
|
||||
|
||||
// PLEASE WAIT
|
||||
if (time_counter_ % 10 < 8) {
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 12"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y - 2, Lang::getText("[SCOREBOARD] 13"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 12"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y - 2, Lang::getText("[SCOREBOARD] 13"), 1, text_color1_);
|
||||
}
|
||||
}
|
||||
|
||||
void Scoreboard::renderStageInfoMode() {
|
||||
// STAGE
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, Lang::getText("[SCOREBOARD] 5") + std::to_string(stage_), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y, Lang::getText("[SCOREBOARD] 5") + std::to_string(stage_), 1, text_color1_);
|
||||
|
||||
// POWERMETER
|
||||
power_meter_sprite_->setSpriteClip(0, 0, 40, 7);
|
||||
@@ -250,28 +250,28 @@ void Scoreboard::renderStageInfoMode() {
|
||||
power_meter_sprite_->render();
|
||||
|
||||
// HI-SCORE
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 4"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 4"), 1, text_color1_);
|
||||
const std::string NAME = hi_score_name_.empty() ? "" : hi_score_name_ + " - ";
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, NAME + updateScoreText(hi_score_), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y, NAME + updateScoreText(hi_score_), 1, text_color2_);
|
||||
}
|
||||
|
||||
void Scoreboard::renderContinueMode(size_t panel_index) {
|
||||
// SCORE
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_.at(panel_index), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y, name_.at(panel_index), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
|
||||
// CONTINUE
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 10"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, std::to_string(continue_counter_.at(panel_index)), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 10"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y, std::to_string(continue_counter_.at(panel_index)), 1, text_color2_);
|
||||
}
|
||||
|
||||
void Scoreboard::renderEnterNameMode(size_t panel_index) {
|
||||
// SCORE
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_.at(panel_index), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y, name_.at(panel_index), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
|
||||
// ENTER NAME
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||
|
||||
renderNameInputField(panel_index);
|
||||
}
|
||||
@@ -302,14 +302,14 @@ void Scoreboard::renderNameInputField(size_t panel_index) {
|
||||
|
||||
void Scoreboard::renderShowNameMode(size_t panel_index) {
|
||||
// SCORE
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y, name_.at(panel_index), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y, name_.at(panel_index), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
|
||||
// NAME
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||
|
||||
/* TEXTO CENTRADO */
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, record_name_.at(panel_index), 1, getColorLikeKnightRider(name_colors_, loop_counter_ / 5));
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y, record_name_.at(panel_index), 1, getColorLikeKnightRider(name_colors_, loop_counter_ / 5));
|
||||
|
||||
/* TEXTO A LA IZQUIERDA */
|
||||
// text_scoreboard_->writeColored(enter_name_pos_.x, enter_name_pos_.y, record_name_.at(panelIndex), getColorLikeKnightRider(name_colors_, loop_counter_ / 5));
|
||||
@@ -317,12 +317,12 @@ void Scoreboard::renderShowNameMode(size_t panel_index) {
|
||||
|
||||
void Scoreboard::renderGameCompletedMode(size_t panel_index) {
|
||||
// GAME OVER
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 7"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y + 4, Lang::getText("[SCOREBOARD] 7"), 1, text_color1_);
|
||||
|
||||
// SCORE
|
||||
if (time_counter_ % 10 < 8) {
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 14"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y - 2, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y - 2, Lang::getText("[SCOREBOARD] 14"), 1, text_color1_);
|
||||
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y - 2, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ void Scoreboard::recalculateAnchors() {
|
||||
slot4_4_ = {COL, ROW4};
|
||||
|
||||
// Primer cuadrado para poner el nombre de record
|
||||
const int ENTER_NAME_LENGHT = text_scoreboard_->lenght(std::string(NAME_SIZE, 'A'));
|
||||
const int ENTER_NAME_LENGHT = text_scoreboard_->length(std::string(NAME_SIZE, 'A'));
|
||||
enter_name_pos_.x = COL - (ENTER_NAME_LENGHT / 2);
|
||||
enter_name_pos_.y = ROW4;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "mouse.h" // Para updateCursorVisibility
|
||||
#include "options.h" // Para VideoOptions, video, WindowOptions, window
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamDebug
|
||||
#include "text.h" // Para Text, TEXT_COLOR, TEXT_STROKE
|
||||
#include "text.h" // Para Text, Text::COLOR, Text::STROKE
|
||||
#include "texture.h" // Para Texture
|
||||
#include "ui/notifier.h" // Para Notifier
|
||||
#include "ui/service_menu.h" // Para ServiceMenu
|
||||
@@ -81,7 +81,7 @@ void Screen::start() { SDL_SetRenderTarget(renderer_, game_canvas_); }
|
||||
void Screen::render() {
|
||||
fps_.increment();
|
||||
renderOverlays(); // Renderiza todos los overlays y efectos
|
||||
renderScreen(); // Renderiza el contenido del game_canvas_
|
||||
renderPresent(); // Renderiza el contenido del game_canvas_
|
||||
}
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla exceptuando ciertas partes
|
||||
@@ -90,11 +90,11 @@ void Screen::coreRender() {
|
||||
#ifdef _DEBUG
|
||||
renderInfo();
|
||||
#endif
|
||||
renderScreen(); // Renderiza el contenido del game_canvas_
|
||||
renderPresent(); // Renderiza el contenido del game_canvas_
|
||||
}
|
||||
|
||||
// Renderiza el contenido del game_canvas_
|
||||
void Screen::renderScreen() {
|
||||
void Screen::renderPresent() {
|
||||
SDL_SetRenderTarget(renderer_, nullptr);
|
||||
clean();
|
||||
|
||||
@@ -212,11 +212,11 @@ void Screen::renderShake() {
|
||||
void Screen::renderInfo() {
|
||||
if (debug_info_.show) {
|
||||
// Resolution
|
||||
debug_info_.text->writeDX(TEXT_COLOR | TEXT_STROKE, param.game.width - debug_info_.text->lenght(Options::video.info) - 2, 1, Options::video.info, 1, param.debug.color, 1, param.debug.color.DARKEN(150));
|
||||
debug_info_.text->writeDX(Text::COLOR | Text::STROKE, param.game.width - debug_info_.text->length(Options::video.info) - 2, 1, Options::video.info, 1, param.debug.color, 1, param.debug.color.DARKEN(150));
|
||||
|
||||
// FPS
|
||||
const std::string FPS_TEXT = std::to_string(fps_.last_value) + " FPS";
|
||||
debug_info_.text->writeDX(TEXT_COLOR | TEXT_STROKE, param.game.width - debug_info_.text->lenght(FPS_TEXT) - 2, 1 + debug_info_.text->getCharacterSize(), FPS_TEXT, 1, param.debug.color, 1, param.debug.color.DARKEN(150));
|
||||
debug_info_.text->writeDX(Text::COLOR | Text::STROKE, param.game.width - debug_info_.text->length(FPS_TEXT) - 2, 1 + debug_info_.text->getCharacterSize(), FPS_TEXT, 1, param.debug.color, 1, param.debug.color.DARKEN(150));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -200,7 +200,7 @@ class Screen {
|
||||
void renderFlash(); // Dibuja el efecto de flash en la pantalla
|
||||
void renderShake(); // Aplica el efecto de agitar la pantalla
|
||||
void renderInfo(); // Muestra información por pantalla
|
||||
void renderScreen(); // Selecciona y ejecuta el método de renderizado adecuado
|
||||
void renderPresent(); // Selecciona y ejecuta el método de renderizado adecuado
|
||||
void loadShaders(); // Carga el contenido del archivo GLSL
|
||||
void adjustWindowSize(); // Calcula el tamaño de la ventana
|
||||
static void getDisplayInfo(); // Obtiene información sobre la pantalla
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.hpp" // Para Name, name
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
|
||||
#include "text.h" // Para Text, Text::CENTER, Text::SHADOW
|
||||
#include "texture.h" // Para Texture
|
||||
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
||||
#include "ui/service_menu.h" // Para ServiceMenu
|
||||
@@ -171,37 +171,37 @@ void Credits::fillTextTexture() {
|
||||
|
||||
// PROGRAMMED_AND_DESIGNED_BY
|
||||
int y = 0;
|
||||
text_grad->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(0), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
text_grad->writeDX(Text::CENTER | Text::SHADOW, param.game.game_area.center_x, y, TEXTS.at(0), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
|
||||
y += SPACE_POST_TITLE;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(4), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
text->writeDX(Text::CENTER | Text::SHADOW, param.game.game_area.center_x, y, TEXTS.at(4), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
|
||||
// PIXELART_DRAWN_BY
|
||||
y += SPACE_PRE_TITLE;
|
||||
text_grad->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(1), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
text_grad->writeDX(Text::CENTER | Text::SHADOW, param.game.game_area.center_x, y, TEXTS.at(1), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
y += SPACE_POST_TITLE;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(4), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
text->writeDX(Text::CENTER | Text::SHADOW, param.game.game_area.center_x, y, TEXTS.at(4), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
|
||||
// MUSIC_COMPOSED_BY
|
||||
y += SPACE_PRE_TITLE;
|
||||
text_grad->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(2), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
text_grad->writeDX(Text::CENTER | Text::SHADOW, param.game.game_area.center_x, y, TEXTS.at(2), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
|
||||
y += SPACE_POST_TITLE;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(5), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
text->writeDX(Text::CENTER | Text::SHADOW, param.game.game_area.center_x, y, TEXTS.at(5), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
y += SPACE_POST_TITLE;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(6), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
text->writeDX(Text::CENTER | Text::SHADOW, param.game.game_area.center_x, y, TEXTS.at(6), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
|
||||
// SOUND_EFFECTS
|
||||
y += SPACE_PRE_TITLE;
|
||||
text_grad->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(3), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
text_grad->writeDX(Text::CENTER | Text::SHADOW, param.game.game_area.center_x, y, TEXTS.at(3), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
y += SPACE_POST_TITLE;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(7), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
text->writeDX(Text::CENTER | Text::SHADOW, param.game.game_area.center_x, y, TEXTS.at(7), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
y += SPACE_POST_TITLE;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(8), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
text->writeDX(Text::CENTER | Text::SHADOW, param.game.game_area.center_x, y, TEXTS.at(8), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
y += SPACE_POST_TITLE;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(9), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
text->writeDX(Text::CENTER | Text::SHADOW, param.game.game_area.center_x, y, TEXTS.at(9), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
y += SPACE_POST_TITLE;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(10), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
text->writeDX(Text::CENTER | Text::SHADOW, param.game.game_area.center_x, y, TEXTS.at(10), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
|
||||
// Mini logo
|
||||
y += SPACE_PRE_TITLE;
|
||||
@@ -217,7 +217,7 @@ void Credits::fillTextTexture() {
|
||||
|
||||
// Texto con el copyright
|
||||
y += mini_logo_sprite->getHeight() + 3;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, std::string(TEXT_COPYRIGHT), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
text->writeDX(Text::CENTER | Text::SHADOW, param.game.game_area.center_x, y, std::string(TEXT_COPYRIGHT), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
|
||||
|
||||
// Resetea el renderizador
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.hpp" // Para Name, name, Options, options
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para Text, TEXT_SHADOW, TEXT_COLOR
|
||||
#include "text.h" // Para Text, Text::SHADOW, Text::COLOR
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h"
|
||||
|
||||
@@ -186,13 +186,13 @@ void HiScoreTable::createSprites() {
|
||||
const int FIRST_LINE = (param.game.height - SIZE) / 2;
|
||||
|
||||
// Crea el sprite para el texto de cabecera
|
||||
header_ = std::make_unique<Sprite>(header_text->writeDXToTexture(TEXT_COLOR, Lang::getText("[HIGHSCORE_TABLE] CAPTION"), -2, background_fade_color_.INVERSE().LIGHTEN(25)));
|
||||
header_ = std::make_unique<Sprite>(header_text->writeDXToTexture(Text::COLOR, Lang::getText("[HIGHSCORE_TABLE] CAPTION"), -2, background_fade_color_.INVERSE().LIGHTEN(25)));
|
||||
header_->setPosition(param.game.game_area.center_x - (header_->getWidth() / 2), FIRST_LINE);
|
||||
|
||||
// Crea los sprites para las entradas en la tabla de puntuaciones
|
||||
const int ANIMATION = rand() % 4;
|
||||
const std::string SAMPLE_LINE(ENTRY_LENGHT + 3, ' ');
|
||||
auto sample_entry = std::make_unique<Sprite>(entry_text->writeDXToTexture(TEXT_SHADOW, SAMPLE_LINE, 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR));
|
||||
auto sample_entry = std::make_unique<Sprite>(entry_text->writeDXToTexture(Text::SHADOW, SAMPLE_LINE, 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR));
|
||||
const auto ENTRY_WIDTH = sample_entry->getWidth();
|
||||
for (int i = 0; i < MAX_NAMES; ++i) {
|
||||
const auto TABLE_POSITION = format(i + 1) + ". ";
|
||||
@@ -205,7 +205,7 @@ void HiScoreTable::createSprites() {
|
||||
}
|
||||
const auto LINE = TABLE_POSITION + Options::settings.hi_score_table.at(i).name + dots + SCORE + ONE_CC;
|
||||
|
||||
entry_names_.emplace_back(std::make_shared<PathSprite>(entry_text->writeDXToTexture(TEXT_SHADOW, LINE, 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR)));
|
||||
entry_names_.emplace_back(std::make_shared<PathSprite>(entry_text->writeDXToTexture(Text::SHADOW, LINE, 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR)));
|
||||
const int DEFAULT_POS_X = (backbuffer_width - ENTRY_WIDTH) / 2;
|
||||
const int POS_X = (i < 9) ? DEFAULT_POS_X : DEFAULT_POS_X - entry_text->getCharacterSize();
|
||||
const int POS_Y = (i * SPACE_BETWEEN_LINES) + FIRST_LINE + SPACE_BETWEEN_HEADER;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.hpp" // Para Name, name, Options, options
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR, TEXT_SHADOW
|
||||
#include "text.h" // Para Text, Text::CENTER, Text::COLOR, Text::SHADOW
|
||||
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
||||
#include "utils.h"
|
||||
|
||||
@@ -145,26 +145,26 @@ void Instructions::fillTexture() {
|
||||
Lang::getText("[INSTRUCTIONS] 10"),
|
||||
Lang::getText("[INSTRUCTIONS] 11")};
|
||||
for (const auto &desc : ITEM_DESCRIPTIONS) {
|
||||
const int L = text_->lenght(desc);
|
||||
const int L = text_->length(desc);
|
||||
lenght = L > lenght ? L : lenght;
|
||||
}
|
||||
const int ANCHOR_ITEM = (param.game.width - (lenght + X_OFFSET)) / 2;
|
||||
|
||||
auto caption_style = TextStyle(ORANGE_TEXT_COLOR, SHADOW_TEXT_COLOR);
|
||||
auto text_style = TextStyle(NO_TEXT_COLOR, SHADOW_TEXT_COLOR);
|
||||
auto caption_style = Text::Style(Text::CENTER | Text::COLOR | Text::SHADOW, ORANGE_TEXT_COLOR, SHADOW_TEXT_COLOR);
|
||||
auto text_style = Text::Style(Text::CENTER | Text::COLOR | Text::SHADOW, NO_TEXT_COLOR, SHADOW_TEXT_COLOR);
|
||||
|
||||
// Escribe el texto de las instrucciones
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, FIRST_LINE, Lang::getText("[INSTRUCTIONS] 01"), caption_style);
|
||||
text_->writeStyle(param.game.game_area.center_x, FIRST_LINE, Lang::getText("[INSTRUCTIONS] 01"), caption_style);
|
||||
|
||||
const int ANCHOR1 = FIRST_LINE + SPACE_POST_HEADER;
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, ANCHOR1 + SPACE_BETWEEN_LINES * 0, Lang::getText("[INSTRUCTIONS] 02"), text_style);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, ANCHOR1 + SPACE_BETWEEN_LINES * 1, Lang::getText("[INSTRUCTIONS] 03"), text_style);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, ANCHOR1 + SPACE_NEW_PARAGRAPH + SPACE_BETWEEN_LINES * 2, Lang::getText("[INSTRUCTIONS] 04"), text_style);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, ANCHOR1 + SPACE_NEW_PARAGRAPH + SPACE_BETWEEN_LINES * 3, Lang::getText("[INSTRUCTIONS] 05"), text_style);
|
||||
text_->writeStyle(param.game.game_area.center_x, ANCHOR1 + SPACE_BETWEEN_LINES * 0, Lang::getText("[INSTRUCTIONS] 02"), text_style);
|
||||
text_->writeStyle(param.game.game_area.center_x, ANCHOR1 + SPACE_BETWEEN_LINES * 1, Lang::getText("[INSTRUCTIONS] 03"), text_style);
|
||||
text_->writeStyle(param.game.game_area.center_x, ANCHOR1 + SPACE_NEW_PARAGRAPH + SPACE_BETWEEN_LINES * 2, Lang::getText("[INSTRUCTIONS] 04"), text_style);
|
||||
text_->writeStyle(param.game.game_area.center_x, ANCHOR1 + SPACE_NEW_PARAGRAPH + SPACE_BETWEEN_LINES * 3, Lang::getText("[INSTRUCTIONS] 05"), text_style);
|
||||
|
||||
// Escribe el texto de los objetos y sus puntos
|
||||
const int ANCHOR2 = ANCHOR1 + SPACE_PRE_HEADER + SPACE_NEW_PARAGRAPH + SPACE_BETWEEN_LINES * 3;
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, ANCHOR2, Lang::getText("[INSTRUCTIONS] 06"), caption_style);
|
||||
text_->writeStyle(param.game.game_area.center_x, ANCHOR2, Lang::getText("[INSTRUCTIONS] 06"), caption_style);
|
||||
|
||||
const int ANCHOR3 = ANCHOR2 + SPACE_POST_HEADER;
|
||||
text_->writeShadowed(ANCHOR_ITEM + X_OFFSET, ANCHOR3 + SPACE_BETWEEN_ITEM_LINES * 0, Lang::getText("[INSTRUCTIONS] 07"), SHADOW_TEXT_COLOR);
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.hpp" // Para Name, name, Options, options, AttractMode, attract_mode
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para TEXT_CENTER, TEXT_SHADOW, Text
|
||||
#include "text.h" // Para Text::CENTER, Text::SHADOW, Text
|
||||
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
||||
#include "ui/notifier.h" // Para Notifier
|
||||
#include "ui/service_menu.h" // Para ServiceMenu
|
||||
@@ -405,7 +405,7 @@ void Title::updateStartPrompt() {
|
||||
|
||||
void Title::renderStartPrompt() {
|
||||
if (should_render_start_prompt_) {
|
||||
text_->writeDX(TEXT_CENTER | TEXT_SHADOW,
|
||||
text_->writeDX(Text::CENTER | Text::SHADOW,
|
||||
param.game.game_area.center_x,
|
||||
param.title.press_start_position,
|
||||
Lang::getText("[TITLE] PRESS_BUTTON_TO_PLAY"),
|
||||
@@ -422,7 +422,7 @@ void Title::renderCopyright() {
|
||||
mini_logo_sprite_->render();
|
||||
|
||||
// Texto con el copyright
|
||||
text_->writeDX(TEXT_CENTER | TEXT_SHADOW,
|
||||
text_->writeDX(Text::CENTER | Text::SHADOW,
|
||||
param.game.game_area.center_x,
|
||||
anchor_.copyright_text,
|
||||
std::string(TEXT_COPYRIGHT),
|
||||
|
||||
394
source/text.cpp
394
source/text.cpp
@@ -13,9 +13,208 @@
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h"
|
||||
|
||||
// Constructor
|
||||
Text::Text(std::shared_ptr<Texture> texture, const std::string &text_file) {
|
||||
// Carga los offsets desde el fichero
|
||||
auto tf = loadFile(text_file);
|
||||
|
||||
// Inicializa variables desde la estructura
|
||||
box_height_ = tf->box_height;
|
||||
box_width_ = tf->box_width;
|
||||
for (int i = 0; i < 128; ++i) {
|
||||
offset_[i].x = tf->offset[i].x;
|
||||
offset_[i].y = tf->offset[i].y;
|
||||
offset_[i].w = tf->offset[i].w;
|
||||
}
|
||||
|
||||
// Crea los objetos
|
||||
sprite_ = std::make_unique<Sprite>(texture, (SDL_FRect){0, 0, static_cast<float>(box_width_), static_cast<float>(box_height_)});
|
||||
|
||||
// Inicializa variables
|
||||
fixed_width_ = false;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Text::Text(std::shared_ptr<Texture> texture, std::shared_ptr<Text::File> text_file) {
|
||||
// Inicializa variables desde la estructura
|
||||
box_height_ = text_file->box_height;
|
||||
box_width_ = text_file->box_width;
|
||||
for (int i = 0; i < 128; ++i) {
|
||||
offset_[i].x = text_file->offset[i].x;
|
||||
offset_[i].y = text_file->offset[i].y;
|
||||
offset_[i].w = text_file->offset[i].w;
|
||||
}
|
||||
|
||||
// Crea los objetos
|
||||
sprite_ = std::make_unique<Sprite>(texture, (SDL_FRect){0, 0, static_cast<float>(box_width_), static_cast<float>(box_height_)});
|
||||
|
||||
// Inicializa variables
|
||||
fixed_width_ = false;
|
||||
}
|
||||
|
||||
// Escribe texto en pantalla
|
||||
void Text::write(int x, int y, const std::string &text, int kerning, int length) {
|
||||
int shift = 0;
|
||||
const std::string_view visible_text = (length == -1) ? std::string_view(text) : std::string_view(text).substr(0, length);
|
||||
|
||||
sprite_->setY(y);
|
||||
for (const auto ch : visible_text) {
|
||||
const auto index = static_cast<unsigned char>(ch);
|
||||
|
||||
if (index < offset_.size()) {
|
||||
sprite_->setSpriteClip(offset_[index].x, offset_[index].y, box_width_, box_height_);
|
||||
sprite_->setX(x + shift);
|
||||
sprite_->render();
|
||||
shift += offset_[index].w + kerning;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe el texto al doble de tamaño
|
||||
void Text::write2X(int x, int y, const std::string &text, int kerning, int length) {
|
||||
int shift = 0;
|
||||
const std::string_view visible_text = (length == -1) ? std::string_view(text) : std::string_view(text).substr(0, length);
|
||||
|
||||
for (const auto ch : visible_text) {
|
||||
const auto index = static_cast<unsigned char>(ch);
|
||||
|
||||
if (index < offset_.size()) {
|
||||
SDL_FRect rect = {
|
||||
static_cast<float>(offset_[index].x),
|
||||
static_cast<float>(offset_[index].y),
|
||||
static_cast<float>(box_width_),
|
||||
static_cast<float>(box_height_)};
|
||||
|
||||
sprite_->getTexture()->render(x + shift, y, &rect, 2.0F, 2.0F);
|
||||
shift += (offset_[index].w + kerning) * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe el texto en una textura
|
||||
auto Text::writeToTexture(const std::string &text, int zoom, int kerning, int length) -> std::shared_ptr<Texture> {
|
||||
auto *renderer = Screen::get()->getRenderer();
|
||||
auto texture = std::make_shared<Texture>(renderer);
|
||||
auto width = Text::length(text, kerning) * zoom;
|
||||
auto height = box_height_ * zoom;
|
||||
auto *temp = SDL_GetRenderTarget(renderer);
|
||||
|
||||
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
texture->setAsRenderTarget(renderer);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
zoom == 1 ? write(0, 0, text, kerning) : write2X(0, 0, text, kerning);
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Escribe el texto con extras en una textura
|
||||
auto Text::writeDXToTexture(Uint8 flags, const std::string &text, int kerning, Color text_color, Uint8 shadow_distance, Color shadow_color, int length) -> std::shared_ptr<Texture> {
|
||||
auto *renderer = Screen::get()->getRenderer();
|
||||
auto texture = std::make_shared<Texture>(renderer);
|
||||
auto width = Text::length(text, kerning) + shadow_distance;
|
||||
auto height = box_height_ + shadow_distance;
|
||||
auto *temp = SDL_GetRenderTarget(renderer);
|
||||
|
||||
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
texture->setAsRenderTarget(renderer);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
writeDX(flags, 0, 0, text, kerning, text_color, shadow_distance, shadow_color, length);
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Escribe el texto con colores
|
||||
void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int length) {
|
||||
sprite_->getTexture()->setColor(color.r, color.g, color.b);
|
||||
write(x, y, text, kerning, length);
|
||||
sprite_->getTexture()->setColor(255, 255, 255);
|
||||
}
|
||||
|
||||
// Escribe el texto con sombra
|
||||
void Text::writeShadowed(int x, int y, const std::string &text, Color color, Uint8 shadow_distance, int kerning, int length) {
|
||||
writeDX(Text::SHADOW, x, y, text, kerning, color, shadow_distance, color, length);
|
||||
write(x, y, text, kerning, length); // Dibuja el texto principal encima
|
||||
}
|
||||
|
||||
// Escribe el texto centrado en un punto x
|
||||
void Text::writeCentered(int x, int y, const std::string &text, int kerning, int length) {
|
||||
x -= (Text::length(text, kerning) / 2);
|
||||
write(x, y, text, kerning, length);
|
||||
}
|
||||
|
||||
// Escribe texto con extras
|
||||
void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerning, Color text_color, Uint8 shadow_distance, Color shadow_color, int length) {
|
||||
const auto CENTERED = ((flags & Text::CENTER) == Text::CENTER);
|
||||
const auto SHADOWED = ((flags & Text::SHADOW) == Text::SHADOW);
|
||||
const auto COLORED = ((flags & Text::COLOR) == Text::COLOR);
|
||||
const auto STROKED = ((flags & Text::STROKE) == Text::STROKE);
|
||||
|
||||
if (CENTERED) {
|
||||
x -= (Text::length(text, kerning) / 2);
|
||||
}
|
||||
|
||||
if (SHADOWED) {
|
||||
writeColored(x + shadow_distance, y + shadow_distance, text, shadow_color, kerning, length);
|
||||
}
|
||||
|
||||
if (STROKED) {
|
||||
for (int dist = 1; dist <= shadow_distance; ++dist) {
|
||||
for (int dy = -dist; dy <= dist; ++dy) {
|
||||
for (int dx = -dist; dx <= dist; ++dx) {
|
||||
writeColored(x + dx, y + dy, text, shadow_color, kerning, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (COLORED) {
|
||||
writeColored(x, y, text, text_color, kerning, length);
|
||||
} else {
|
||||
write(x, y, text, kerning, length);
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe texto a partir de un TextStyle
|
||||
void Text::writeStyle(int x, int y, const std::string &text, const Style &style, int length) {
|
||||
writeDX(style.flags, x, y, text, style.kerning, style.text_color, style.shadow_distance, style.shadow_color);
|
||||
}
|
||||
|
||||
// Obtiene la longitud en pixels de una cadena
|
||||
auto Text::length(const std::string &text, int kerning) const -> int {
|
||||
int shift = 0;
|
||||
for (const auto &ch : text) {
|
||||
// Convertimos a unsigned char para obtener el valor ASCII correcto (0-255)
|
||||
const auto index = static_cast<unsigned char>(ch);
|
||||
|
||||
// Verificamos si el carácter está dentro de los límites del array
|
||||
if (index < offset_.size()) {
|
||||
shift += (offset_[index].w + kerning);
|
||||
}
|
||||
}
|
||||
|
||||
// Descuenta el kerning del último caracter si el texto no está vacío
|
||||
return text.empty() ? 0 : shift - kerning;
|
||||
}
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
auto Text::getCharacterSize() const -> int {
|
||||
return box_width_;
|
||||
}
|
||||
|
||||
// Establece si se usa un tamaño fijo de letra
|
||||
void Text::setFixedWidth(bool value) {
|
||||
fixed_width_ = value;
|
||||
}
|
||||
|
||||
// Llena una estructuta TextFile desde un fichero
|
||||
auto loadTextFile(const std::string &file_path) -> std::shared_ptr<TextFile> {
|
||||
auto tf = std::make_shared<TextFile>();
|
||||
auto Text::loadFile(const std::string &file_path) -> std::shared_ptr<Text::File> {
|
||||
auto tf = std::make_shared<Text::File>();
|
||||
|
||||
// Inicializa a cero el vector con las coordenadas
|
||||
for (auto &i : tf->offset) {
|
||||
@@ -74,194 +273,3 @@ auto loadTextFile(const std::string &file_path) -> std::shared_ptr<TextFile> {
|
||||
|
||||
return tf;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Text::Text(std::shared_ptr<Texture> texture, const std::string &text_file) {
|
||||
// Carga los offsets desde el fichero
|
||||
auto tf = loadTextFile(text_file);
|
||||
|
||||
// Inicializa variables desde la estructura
|
||||
box_height_ = tf->box_height;
|
||||
box_width_ = tf->box_width;
|
||||
for (int i = 0; i < 128; ++i) {
|
||||
offset_[i].x = tf->offset[i].x;
|
||||
offset_[i].y = tf->offset[i].y;
|
||||
offset_[i].w = tf->offset[i].w;
|
||||
}
|
||||
|
||||
// Crea los objetos
|
||||
sprite_ = std::make_unique<Sprite>(texture, (SDL_FRect){0, 0, static_cast<float>(box_width_), static_cast<float>(box_height_)});
|
||||
|
||||
// Inicializa variables
|
||||
fixed_width_ = false;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Text::Text(std::shared_ptr<Texture> texture, std::shared_ptr<TextFile> text_file) {
|
||||
// Inicializa variables desde la estructura
|
||||
box_height_ = text_file->box_height;
|
||||
box_width_ = text_file->box_width;
|
||||
for (int i = 0; i < 128; ++i) {
|
||||
offset_[i].x = text_file->offset[i].x;
|
||||
offset_[i].y = text_file->offset[i].y;
|
||||
offset_[i].w = text_file->offset[i].w;
|
||||
}
|
||||
|
||||
// Crea los objetos
|
||||
sprite_ = std::make_unique<Sprite>(texture, (SDL_FRect){0, 0, static_cast<float>(box_width_), static_cast<float>(box_height_)});
|
||||
|
||||
// Inicializa variables
|
||||
fixed_width_ = false;
|
||||
}
|
||||
|
||||
// Escribe texto en pantalla
|
||||
void Text::write(int x, int y, const std::string &text, int kerning, int lenght) {
|
||||
int shift = 0;
|
||||
|
||||
if (lenght == -1) {
|
||||
lenght = text.length();
|
||||
}
|
||||
|
||||
sprite_->setY(y);
|
||||
for (int i = 0; i < lenght; ++i) {
|
||||
auto index = static_cast<int>(text[i]);
|
||||
sprite_->setSpriteClip(offset_[index].x, offset_[index].y, box_width_, box_height_);
|
||||
sprite_->setX(x + shift);
|
||||
sprite_->render();
|
||||
shift += offset_[static_cast<int>(text[i])].w + kerning;
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe texto en pantalla
|
||||
void Text::write2X(int x, int y, const std::string &text, int kerning) {
|
||||
int shift = 0;
|
||||
for (size_t i = 0; i < text.length(); ++i) {
|
||||
auto index = static_cast<size_t>(text[i]);
|
||||
SDL_FRect rect = {static_cast<float>(offset_[index].x), static_cast<float>(offset_[index].y), static_cast<float>(box_width_), static_cast<float>(box_height_)};
|
||||
sprite_->getTexture()->render(x + shift, y, &rect, 2.0F, 2.0F);
|
||||
shift += (offset_[index].w + kerning) * 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe el texto en una textura
|
||||
auto Text::writeToTexture(const std::string &text, int zoom, int kerning) -> std::shared_ptr<Texture> {
|
||||
auto *renderer = Screen::get()->getRenderer();
|
||||
auto texture = std::make_shared<Texture>(renderer);
|
||||
auto width = lenght(text, kerning) * zoom;
|
||||
auto height = box_height_ * zoom;
|
||||
auto *temp = SDL_GetRenderTarget(renderer);
|
||||
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
texture->setAsRenderTarget(renderer);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
zoom == 1 ? write(0, 0, text, kerning) : write2X(0, 0, text, kerning);
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Escribe el texto con extras en una textura
|
||||
auto Text::writeDXToTexture(Uint8 flags, const std::string &text, int kerning, Color text_color, Uint8 shadow_distance, Color shadow_color, int lenght) -> std::shared_ptr<Texture> {
|
||||
auto *renderer = Screen::get()->getRenderer();
|
||||
auto texture = std::make_shared<Texture>(renderer);
|
||||
auto width = Text::lenght(text, kerning) + shadow_distance;
|
||||
auto height = box_height_ + shadow_distance;
|
||||
auto *temp = SDL_GetRenderTarget(renderer);
|
||||
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
texture->setAsRenderTarget(renderer);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
writeDX(flags, 0, 0, text, kerning, text_color, shadow_distance, shadow_color, lenght);
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Escribe el texto con colores
|
||||
void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int lenght) {
|
||||
sprite_->getTexture()->setColor(color.r, color.g, color.b);
|
||||
write(x, y, text, kerning, lenght);
|
||||
sprite_->getTexture()->setColor(255, 255, 255);
|
||||
}
|
||||
|
||||
// Escribe el texto con sombra
|
||||
void Text::writeShadowed(int x, int y, const std::string &text, Color color, Uint8 shadow_distance, int kerning, int lenght) {
|
||||
sprite_->getTexture()->setColor(color.r, color.g, color.b);
|
||||
write(x + shadow_distance, y + shadow_distance, text, kerning, lenght);
|
||||
sprite_->getTexture()->setColor(255, 255, 255);
|
||||
write(x, y, text, kerning, lenght);
|
||||
}
|
||||
|
||||
// Escribe el texto centrado en un punto x
|
||||
void Text::writeCentered(int x, int y, const std::string &text, int kerning, int lenght) {
|
||||
x -= (Text::lenght(text, kerning) / 2);
|
||||
write(x, y, text, kerning, lenght);
|
||||
}
|
||||
|
||||
// Escribe texto con extras
|
||||
void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerning, Color text_color, Uint8 shadow_distance, Color shadow_color, int lenght) {
|
||||
const auto CENTERED = ((flags & TEXT_CENTER) == TEXT_CENTER);
|
||||
const auto SHADOWED = ((flags & TEXT_SHADOW) == TEXT_SHADOW);
|
||||
const auto COLORED = ((flags & TEXT_COLOR) == TEXT_COLOR);
|
||||
const auto STROKED = ((flags & TEXT_STROKE) == TEXT_STROKE);
|
||||
|
||||
if (CENTERED) {
|
||||
x -= (Text::lenght(text, kerning) / 2);
|
||||
}
|
||||
|
||||
if (SHADOWED) {
|
||||
writeColored(x + shadow_distance, y + shadow_distance, text, shadow_color, kerning, lenght);
|
||||
}
|
||||
|
||||
if (STROKED) {
|
||||
for (int dist = 1; dist <= shadow_distance; ++dist) {
|
||||
for (int dy = -dist; dy <= dist; ++dy) {
|
||||
for (int dx = -dist; dx <= dist; ++dx) {
|
||||
writeColored(x + dx, y + dy, text, shadow_color, kerning, lenght);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (COLORED) {
|
||||
writeColored(x, y, text, text_color, kerning, lenght);
|
||||
} else {
|
||||
write(x, y, text, kerning, lenght);
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe texto a partir de un TextStyle
|
||||
void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, const TextStyle &style, int length) {
|
||||
writeDX(flags, x, y, text, style.kerning, style.text_color, style.shadow_distance, style.shadow_color);
|
||||
}
|
||||
|
||||
// Obtiene la longitud en pixels de una cadena
|
||||
auto Text::lenght(const std::string &text, int kerning) const -> int {
|
||||
int shift = 0;
|
||||
for (size_t i = 0; i < text.length(); ++i) {
|
||||
shift += (offset_[static_cast<int>(text[i])].w + kerning);
|
||||
}
|
||||
|
||||
// Descuenta el kerning del último caracter
|
||||
return shift - kerning;
|
||||
}
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
auto Text::getCharacterSize() const -> int {
|
||||
return box_width_;
|
||||
}
|
||||
|
||||
// Establece si se usa un tamaño fijo de letra
|
||||
void Text::setFixedWidth(bool value) {
|
||||
fixed_width_ = value;
|
||||
}
|
||||
|
||||
// Establece una paleta
|
||||
void Text::setPalette(int number) {
|
||||
auto *temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
||||
sprite_->getTexture()->setPalette(number);
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
||||
}
|
||||
@@ -11,57 +11,57 @@
|
||||
|
||||
class Texture;
|
||||
|
||||
// --- Constantes para flags de texto ---
|
||||
constexpr int TEXT_COLOR = 1;
|
||||
constexpr int TEXT_SHADOW = 2;
|
||||
constexpr int TEXT_CENTER = 4;
|
||||
constexpr int TEXT_STROKE = 8;
|
||||
// --- Clase Text: pinta texto en pantalla a partir de un bitmap ---
|
||||
class Text {
|
||||
public:
|
||||
// --- Constantes para flags de texto ---
|
||||
static constexpr int COLOR = 1;
|
||||
static constexpr int SHADOW = 2;
|
||||
static constexpr int CENTER = 4;
|
||||
static constexpr int STROKE = 8;
|
||||
|
||||
// --- Estructuras auxiliares ---
|
||||
struct TextOffset {
|
||||
// --- Estructuras ---
|
||||
struct Offset {
|
||||
int x, y, w;
|
||||
};
|
||||
};
|
||||
|
||||
struct TextFile {
|
||||
struct File {
|
||||
int box_width; // Anchura de la caja de cada caracter en el png
|
||||
int box_height; // Altura de la caja de cada caracter en el png
|
||||
std::array<TextOffset, 128> offset = {}; // Vector con las posiciones y ancho de cada letra
|
||||
};
|
||||
std::array<Offset, 128> offset = {}; // Vector con las posiciones y ancho de cada letra
|
||||
};
|
||||
|
||||
struct TextStyle {
|
||||
struct Style {
|
||||
Uint8 flags;
|
||||
Color text_color;
|
||||
Color shadow_color;
|
||||
Uint8 shadow_distance;
|
||||
int kerning;
|
||||
|
||||
// Constructor con argumentos por defecto
|
||||
TextStyle(Color text = Color(),
|
||||
Style(Uint8 flags = 0,
|
||||
Color text = Color(),
|
||||
Color shadow = Color(),
|
||||
Uint8 distance = 1,
|
||||
int kern = 1)
|
||||
: text_color(text),
|
||||
: flags(flags),
|
||||
text_color(text),
|
||||
shadow_color(shadow),
|
||||
shadow_distance(distance),
|
||||
kerning(kern) {}
|
||||
};
|
||||
};
|
||||
|
||||
// Llena una estructura TextFile desde un fichero
|
||||
auto loadTextFile(const std::string &file_path) -> std::shared_ptr<TextFile>;
|
||||
|
||||
// --- Clase Text: pinta texto en pantalla a partir de un bitmap ---
|
||||
class Text {
|
||||
public:
|
||||
// --- Constructores y destructor ---
|
||||
Text(std::shared_ptr<Texture> texture, const std::string &text_file);
|
||||
Text(std::shared_ptr<Texture> texture, std::shared_ptr<TextFile> text_file);
|
||||
Text(std::shared_ptr<Texture> texture, std::shared_ptr<Text::File> text_file);
|
||||
~Text() = default;
|
||||
|
||||
// --- Métodos de escritura en pantalla ---
|
||||
void write(int x, int y, const std::string &text, int kerning = 1, int lenght = -1); // Escribe el texto en pantalla
|
||||
void write2X(int x, int y, const std::string &text, int kerning = 1); // Escribe el texto al doble de tamaño
|
||||
void write2X(int x, int y, const std::string &text, int kerning = 1, int length = -1); // Escribe el texto al doble de tamaño
|
||||
|
||||
// --- Escritura en textura ---
|
||||
auto writeToTexture(const std::string &text, int zoom = 1, int kerning = 1) -> std::shared_ptr<Texture>; // Escribe el texto en una textura
|
||||
auto writeToTexture(const std::string &text, int zoom = 1, int kerning = 1, int lenght = -1) -> std::shared_ptr<Texture>; // Escribe el texto en una textura
|
||||
auto writeDXToTexture(Uint8 flags, const std::string &text, int kerning = 1, Color text_color = Color(), Uint8 shadow_distance = 1, Color shadow_color = Color(), int lenght = -1) -> std::shared_ptr<Texture>; // Escribe el texto con extras en una textura
|
||||
|
||||
// --- Métodos de escritura avanzada ---
|
||||
@@ -69,15 +69,17 @@ class Text {
|
||||
void writeShadowed(int x, int y, const std::string &text, Color color, Uint8 shadow_distance = 1, int kerning = 1, int lenght = -1); // Escribe el texto con sombra
|
||||
void writeCentered(int x, int y, const std::string &text, int kerning = 1, int lenght = -1); // Escribe el texto centrado en un punto x
|
||||
void writeDX(Uint8 flags, int x, int y, const std::string &text, int kerning = 1, Color text_color = Color(), Uint8 shadow_distance = 1, Color shadow_color = Color(), int lenght = -1); // Escribe texto con extras
|
||||
void writeDX(Uint8 flags, int x, int y, const std::string &text, const TextStyle &style, int length = -1); // Escribe texto a partir de un TextStyle
|
||||
void writeStyle(int x, int y, const std::string &text, const Style &style, int length = -1); // Escribe texto a partir de un TextStyle
|
||||
|
||||
// --- Utilidades ---
|
||||
[[nodiscard]] auto lenght(const std::string &text, int kerning = 1) const -> int; // Obtiene la longitud en pixels de una cadena
|
||||
[[nodiscard]] auto length(const std::string &text, int kerning = 1) const -> int; // Obtiene la longitud en pixels de una cadena
|
||||
[[nodiscard]] auto getCharacterSize() const -> int; // Devuelve el tamaño de caracter actual
|
||||
|
||||
// --- Configuración ---
|
||||
void setFixedWidth(bool value); // Establece si se usa un tamaño fijo de letra
|
||||
void setPalette(int number); // Establece una paleta
|
||||
|
||||
// Llena una estructura Text::File desde un fichero
|
||||
static auto loadFile(const std::string &file_path) -> std::shared_ptr<Text::File>;
|
||||
|
||||
private:
|
||||
// --- Objetos y punteros ---
|
||||
@@ -87,6 +89,5 @@ class Text {
|
||||
int box_width_ = 0; // Anchura de la caja de cada caracter en el png
|
||||
int box_height_ = 0; // Altura de la caja de cada caracter en el png
|
||||
bool fixed_width_ = false; // Indica si el texto se ha de escribir con longitud fija en todas las letras
|
||||
std::array<TextOffset, 128> offset_ = {};
|
||||
; // Vector con las posiciones y ancho de cada letra
|
||||
std::array<Offset, 128> offset_ = {}; // Vector con las posiciones y ancho de cada letra
|
||||
};
|
||||
@@ -19,7 +19,7 @@ auto ActionListOption::getValueAsString() const -> std::string {
|
||||
auto ActionListOption::getMaxValueWidth(Text* text) const -> int {
|
||||
int max_width = 0;
|
||||
for (const auto& option : options_) {
|
||||
int width = text->lenght(option, -2);
|
||||
int width = text->length(option, -2);
|
||||
if (width > max_width) {
|
||||
max_width = width;
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ class BoolOption : public MenuOption {
|
||||
}
|
||||
auto getMaxValueWidth(Text *text_renderer) const -> int override {
|
||||
return std::max(
|
||||
text_renderer->lenght(Lang::getText("[SERVICE_MENU] ON"), -2),
|
||||
text_renderer->lenght(Lang::getText("[SERVICE_MENU] OFF"), -2));
|
||||
text_renderer->length(Lang::getText("[SERVICE_MENU] ON"), -2),
|
||||
text_renderer->length(Lang::getText("[SERVICE_MENU] OFF"), -2));
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -87,7 +87,7 @@ class IntOption : public MenuOption {
|
||||
|
||||
// Iterar por todos los valores posibles en el rango
|
||||
for (int value = min_value_; value <= max_value_; value += step_value_) {
|
||||
int width = text_renderer->lenght(std::to_string(value), -2);
|
||||
int width = text_renderer->length(std::to_string(value), -2);
|
||||
max_width = std::max(max_width, width);
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ class ListOption : public MenuOption {
|
||||
auto getMaxValueWidth(Text *text_renderer) const -> int override {
|
||||
int max_w = 0;
|
||||
for (const auto &val : value_list_) {
|
||||
max_w = std::max(max_w, text_renderer->lenght(val, -2));
|
||||
max_w = std::max(max_w, text_renderer->length(val, -2));
|
||||
}
|
||||
return max_w;
|
||||
}
|
||||
@@ -179,21 +179,17 @@ class ActionOption : public MenuOption {
|
||||
class ActionListOption : public MenuOption {
|
||||
public:
|
||||
using ValueGetter = std::function<std::string()>;
|
||||
using ValueSetter = std::function<void(const std::string&)>;
|
||||
using ValueSetter = std::function<void(const std::string &)>;
|
||||
using ActionExecutor = std::function<void()>;
|
||||
|
||||
ActionListOption(const std::string& caption, ServiceMenu::SettingsGroup group,
|
||||
std::vector<std::string> options, ValueGetter getter, ValueSetter setter,
|
||||
ActionExecutor action_executor, bool hidden = false)
|
||||
: MenuOption(caption, group, hidden), options_(std::move(options)),
|
||||
value_getter_(std::move(getter)), value_setter_(std::move(setter)),
|
||||
action_executor_(std::move(action_executor)), current_index_(0) {
|
||||
ActionListOption(const std::string &caption, ServiceMenu::SettingsGroup group, std::vector<std::string> options, ValueGetter getter, ValueSetter setter, ActionExecutor action_executor, bool hidden = false)
|
||||
: MenuOption(caption, group, hidden), options_(std::move(options)), value_getter_(std::move(getter)), value_setter_(std::move(setter)), action_executor_(std::move(action_executor)), current_index_(0) {
|
||||
updateCurrentIndex();
|
||||
}
|
||||
|
||||
[[nodiscard]] auto getBehavior() const -> Behavior override { return Behavior::BOTH; }
|
||||
[[nodiscard]] auto getValueAsString() const -> std::string override;
|
||||
[[nodiscard]] auto getMaxValueWidth(Text* text) const -> int override;
|
||||
[[nodiscard]] auto getMaxValueWidth(Text *text) const -> int override;
|
||||
void adjustValue(bool up) override;
|
||||
void executeAction() override;
|
||||
void sync(); // Sincroniza con el valor actual
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "menu_option.h" // Para MenuOption
|
||||
#include "param.h" // Para Param, param, ParamServiceMenu, ParamGame
|
||||
#include "screen.h" // Para Screen
|
||||
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR
|
||||
#include "text.h" // Para Text, Text::CENTER, Text::COLOR
|
||||
#include "utils.h" // Para Zone, truncateWithEllipsis
|
||||
|
||||
MenuRenderer::MenuRenderer(const ServiceMenu *menu_state, std::shared_ptr<Text> element_text, std::shared_ptr<Text> title_text)
|
||||
@@ -35,7 +35,7 @@ void MenuRenderer::render(const ServiceMenu *menu_state) {
|
||||
|
||||
// Dibuja el título
|
||||
float y = rect_.y + title_padding_;
|
||||
title_text_->writeDX(TEXT_COLOR | TEXT_CENTER, param.game.game_area.center_x, y, menu_state->getTitle(), -4, param.service_menu.title_color);
|
||||
title_text_->writeDX(Text::COLOR | Text::CENTER, param.game.game_area.center_x, y, menu_state->getTitle(), -4, param.service_menu.title_color);
|
||||
|
||||
// Dibuja la línea separadora
|
||||
y = rect_.y + upper_height_;
|
||||
@@ -54,18 +54,18 @@ void MenuRenderer::render(const ServiceMenu *menu_state) {
|
||||
if (menu_state->getCurrentGroupAlignment() == ServiceMenu::GroupAlignment::LEFT) {
|
||||
// Para opciones alineadas a la izquierda, truncamos el valor si es necesario
|
||||
const int available_width = rect_.w - (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2) -
|
||||
element_text_->lenght(option_pairs.at(i).first, -2) -
|
||||
element_text_->length(option_pairs.at(i).first, -2) -
|
||||
ServiceMenu::MIN_GAP_OPTION_VALUE;
|
||||
|
||||
std::string truncated_value = getTruncatedValue(option_pairs.at(i).second, available_width);
|
||||
|
||||
// Si la opción tiene Behavior::BOTH, añadir indicador visual
|
||||
if (i < display_options.size() && display_options[i]->getBehavior() == MenuOption::Behavior::BOTH) {
|
||||
truncated_value = "► " + truncated_value + " ◄";
|
||||
truncated_value = "-" + truncated_value + "-";
|
||||
}
|
||||
|
||||
element_text_->writeColored(rect_.x + ServiceMenu::OPTIONS_HORIZONTAL_PADDING, y, option_pairs.at(i).first, current_color, -2);
|
||||
const int X = rect_.x + rect_.w - ServiceMenu::OPTIONS_HORIZONTAL_PADDING - element_text_->lenght(truncated_value, -2);
|
||||
const int X = rect_.x + rect_.w - ServiceMenu::OPTIONS_HORIZONTAL_PADDING - element_text_->length(truncated_value, -2);
|
||||
element_text_->writeColored(X, y, truncated_value, current_color, -2);
|
||||
} else {
|
||||
// Para opciones centradas, también truncamos si es necesario
|
||||
@@ -74,10 +74,10 @@ void MenuRenderer::render(const ServiceMenu *menu_state) {
|
||||
|
||||
// Si la opción tiene Behavior::BOTH, añadir indicador visual
|
||||
if (i < display_options.size() && display_options[i]->getBehavior() == MenuOption::Behavior::BOTH) {
|
||||
truncated_caption = "► " + truncated_caption + " ◄";
|
||||
truncated_caption = "-" + truncated_caption + "-";
|
||||
}
|
||||
|
||||
element_text_->writeDX(TEXT_CENTER | TEXT_COLOR, rect_.x + rect_.w / 2, y, truncated_caption, -2, current_color);
|
||||
element_text_->writeDX(Text::CENTER | Text::COLOR, rect_.x + rect_.w / 2, y, truncated_caption, -2, current_color);
|
||||
}
|
||||
y += options_height_ + options_padding_;
|
||||
}
|
||||
@@ -196,7 +196,7 @@ void MenuRenderer::precalculateMenuWidths(const std::vector<std::unique_ptr<Menu
|
||||
if (option->getGroup() != sg) {
|
||||
continue;
|
||||
}
|
||||
max_option_width = std::max(max_option_width, element_text_->lenght(option->getCaption(), -2));
|
||||
max_option_width = std::max(max_option_width, element_text_->length(option->getCaption(), -2));
|
||||
if (menu_state->getCurrentGroupAlignment() == ServiceMenu::GroupAlignment::LEFT) {
|
||||
// Para calcular el ancho máximo, necesitamos considerar la truncación
|
||||
int max_available_value_width = static_cast<int>(max_menu_width_) - max_option_width -
|
||||
@@ -240,14 +240,14 @@ auto MenuRenderer::setRect(SDL_FRect rect) -> SDL_FRect {
|
||||
}
|
||||
|
||||
auto MenuRenderer::getTruncatedValueWidth(const std::string &value, int available_width) const -> int {
|
||||
int value_width = element_text_->lenght(value, -2);
|
||||
int value_width = element_text_->length(value, -2);
|
||||
if (value_width <= available_width) {
|
||||
return value_width;
|
||||
}
|
||||
|
||||
// Calculamos cuántos caracteres podemos mostrar más los puntos suspensivos
|
||||
// Estimamos el ancho de los puntos suspensivos como 3 caracteres promedio
|
||||
int ellipsis_width = element_text_->lenght("...", -2);
|
||||
int ellipsis_width = element_text_->length("...", -2);
|
||||
int available_for_text = available_width - ellipsis_width;
|
||||
|
||||
if (available_for_text <= 0) {
|
||||
@@ -260,17 +260,17 @@ auto MenuRenderer::getTruncatedValueWidth(const std::string &value, int availabl
|
||||
|
||||
// Verificamos el ancho real del texto truncado
|
||||
std::string truncated = truncateWithEllipsis(value, max_chars);
|
||||
return element_text_->lenght(truncated, -2);
|
||||
return element_text_->length(truncated, -2);
|
||||
}
|
||||
|
||||
auto MenuRenderer::getTruncatedValue(const std::string &value, int available_width) const -> std::string {
|
||||
int value_width = element_text_->lenght(value, -2);
|
||||
int value_width = element_text_->length(value, -2);
|
||||
if (value_width <= available_width) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// Calculamos cuántos caracteres podemos mostrar
|
||||
int ellipsis_width = element_text_->lenght("...", -2);
|
||||
int ellipsis_width = element_text_->length("...", -2);
|
||||
int available_for_text = available_width - ellipsis_width;
|
||||
|
||||
if (available_for_text <= 0) {
|
||||
@@ -283,7 +283,7 @@ auto MenuRenderer::getTruncatedValue(const std::string &value, int available_wid
|
||||
|
||||
// Ajustamos iterativamente hasta que el texto quepa
|
||||
std::string truncated = truncateWithEllipsis(value, max_chars);
|
||||
while (element_text_->lenght(truncated, -2) > available_width && max_chars > 1) {
|
||||
while (element_text_->length(truncated, -2) > available_width && max_chars > 1) {
|
||||
max_chars--;
|
||||
truncated = truncateWithEllipsis(value, max_chars);
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string&
|
||||
const float PADDING_IN_H = text_->getCharacterSize();
|
||||
const float PADDING_IN_V = text_->getCharacterSize() / 2;
|
||||
const int ICON_SPACE = icon >= 0 ? ICON_SIZE + PADDING_IN_H : 0;
|
||||
const float WIDTH = text_->lenght(longest) + (PADDING_IN_H * 2) + ICON_SPACE;
|
||||
const float WIDTH = text_->length(longest) + (PADDING_IN_H * 2) + ICON_SPACE;
|
||||
const float HEIGHT = (text_->getCharacterSize() * texts.size()) + (PADDING_IN_V * 2);
|
||||
const auto SHAPE = NotificationShape::SQUARED;
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ void ServiceMenu::selectOption() {
|
||||
current_settings_group_ = folder->getTargetGroup();
|
||||
selected_ = 0;
|
||||
updateMenu();
|
||||
} else if (selected_option->getBehavior() == MenuOption::Behavior::SELECT) {
|
||||
} else if (selected_option->getBehavior() == MenuOption::Behavior::SELECT or selected_option->getBehavior() == MenuOption::Behavior::BOTH) {
|
||||
selected_option->executeAction();
|
||||
}
|
||||
playSelectSound();
|
||||
@@ -554,7 +554,7 @@ void ServiceMenu::handleEvent(const SDL_Event &event) {
|
||||
}
|
||||
|
||||
// Procesar eventos normales del ServiceMenu
|
||||
switch (event.type) {
|
||||
/*switch (event.type) {
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
switch (event.key.key) {
|
||||
case SDLK_ESCAPE:
|
||||
@@ -611,5 +611,5 @@ void ServiceMenu::handleEvent(const SDL_Event &event) {
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <cmath> // Para pow
|
||||
#include <utility>
|
||||
|
||||
#include "text.h" // Para TEXT_CENTER, TEXT_COLOR, Text
|
||||
#include "text.h" // Para Text::CENTER, Text::COLOR, Text
|
||||
|
||||
// Constructor: inicializa el renderizador, el texto y el color del mensaje
|
||||
UIMessage::UIMessage(std::shared_ptr<Text> text_renderer, std::string message_text, const Color &color)
|
||||
@@ -70,7 +70,7 @@ void UIMessage::updateAnimation() {
|
||||
void UIMessage::render() {
|
||||
if (visible_) {
|
||||
text_renderer_->writeDX(
|
||||
TEXT_COLOR | TEXT_CENTER,
|
||||
Text::COLOR | Text::CENTER,
|
||||
base_x_,
|
||||
base_y_ + y_offset_,
|
||||
text_,
|
||||
|
||||
@@ -13,13 +13,15 @@ WindowMessage::WindowMessage(
|
||||
const Color& bg_color,
|
||||
const Color& border_color,
|
||||
const Color& title_color,
|
||||
const Color& text_color
|
||||
) : text_renderer_(std::move(text_renderer)),
|
||||
const Color& text_color)
|
||||
: text_renderer_(std::move(text_renderer)),
|
||||
title_(title),
|
||||
bg_color_(bg_color),
|
||||
border_color_(border_color),
|
||||
title_color_(title_color),
|
||||
text_color_(text_color) {
|
||||
text_color_(text_color),
|
||||
title_style_(Text::CENTER | Text::COLOR, title_color, title_color, 0, -2),
|
||||
text_style_(Text::CENTER | Text::COLOR, text_color, text_color, 0, -2) {
|
||||
}
|
||||
|
||||
void WindowMessage::render() {
|
||||
@@ -41,29 +43,29 @@ void WindowMessage::render() {
|
||||
|
||||
// Dibujar título si existe
|
||||
if (!title_.empty()) {
|
||||
text_renderer_->writeCentered(
|
||||
text_renderer_->writeStyle(
|
||||
rect_.x + rect_.w / 2.0f,
|
||||
current_y,
|
||||
title_
|
||||
//title_color_
|
||||
);
|
||||
title_,
|
||||
title_style_);
|
||||
current_y += text_renderer_->getCharacterSize() + line_spacing_ * 2;
|
||||
|
||||
// Línea separadora debajo del título
|
||||
SDL_SetRenderDrawColor(renderer, border_color_.r, border_color_.g, border_color_.b, border_color_.a);
|
||||
SDL_RenderLine(renderer,
|
||||
rect_.x + padding_, current_y - line_spacing_,
|
||||
rect_.x + rect_.w - padding_, current_y - line_spacing_);
|
||||
rect_.x + padding_,
|
||||
current_y - line_spacing_,
|
||||
rect_.x + rect_.w - padding_,
|
||||
current_y - line_spacing_);
|
||||
}
|
||||
|
||||
// Dibujar textos
|
||||
for (const auto& text : texts_) {
|
||||
text_renderer_->writeCentered(
|
||||
text_renderer_->writeStyle(
|
||||
rect_.x + rect_.w / 2.0f,
|
||||
current_y,
|
||||
text
|
||||
//text_color_
|
||||
);
|
||||
text,
|
||||
text_style_);
|
||||
current_y += text_renderer_->getCharacterSize() + line_spacing_;
|
||||
}
|
||||
}
|
||||
@@ -158,13 +160,13 @@ auto WindowMessage::calculateContentWidth() const -> float {
|
||||
|
||||
// Ancho del título
|
||||
if (!title_.empty()) {
|
||||
float title_width = text_renderer_->lenght(title_, -2);
|
||||
float title_width = text_renderer_->length(title_, -2);
|
||||
max_width = std::max(max_width, title_width);
|
||||
}
|
||||
|
||||
// Ancho de los textos
|
||||
for (const auto& text : texts_) {
|
||||
float text_width = text_renderer_->lenght(text, -2);
|
||||
float text_width = text_renderer_->length(text, -2);
|
||||
max_width = std::max(max_width, text_width);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "color.h"
|
||||
|
||||
class Text;
|
||||
#include "text.h"
|
||||
|
||||
class WindowMessage {
|
||||
public:
|
||||
@@ -77,6 +76,10 @@ class WindowMessage {
|
||||
Color title_color_;
|
||||
Color text_color_;
|
||||
|
||||
// Estilos
|
||||
Text::Style title_style_;
|
||||
Text::Style text_style_;
|
||||
|
||||
// Métodos privados
|
||||
void calculateAutoSize();
|
||||
[[nodiscard]] auto calculateContentHeight() const -> float;
|
||||
|
||||
@@ -78,7 +78,7 @@ void Writer::setFinishedCounter(int time) {
|
||||
|
||||
// Centra la cadena de texto a un punto X
|
||||
void Writer::center(int x) {
|
||||
setPosX(x - (text_->lenght(caption_, kerning_) / 2));
|
||||
setPosX(x - (text_->length(caption_, kerning_) / 2));
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
|
||||
Reference in New Issue
Block a user