Afegida nova tipografia 04b_25
Eliminades tipografies que no s'utilitzaven La classe Text ara pot tornar una textura amb el text
This commit is contained in:
@@ -495,16 +495,12 @@ void Director::setFileList()
|
||||
Asset::get()->add(prefix + "/data/font/8bithud.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/8bithud.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/nokia.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/nokia_big2.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/nokia.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/nokia2.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/nokia2.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/nokia_big2.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/smb2_big.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/smb2_big.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/smb2.gif", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/smb2_palette1.pal", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/font/smb2.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/04b_25.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/04b_25.txt", AssetType::FONT);
|
||||
|
||||
// Textos
|
||||
Asset::get()->add(prefix + "/data/lang/es_ES.txt", AssetType::LANG);
|
||||
|
||||
@@ -205,9 +205,9 @@ void Game::setResources()
|
||||
// Texto
|
||||
{
|
||||
text_ = std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"));
|
||||
text_big_ = std::make_unique<Text>(Resource::get()->getTexture("smb2_big.png"), Resource::get()->getTextFile("smb2_big.txt"));
|
||||
text_nokia2_ = std::make_unique<Text>(Resource::get()->getTexture("nokia2.png"), Resource::get()->getTextFile("nokia2.txt"));
|
||||
text_nokia2_big_ = std::make_unique<Text>(Resource::get()->getTexture("nokia_big2.png"), Resource::get()->getTextFile("nokia_big2.txt"));
|
||||
text_nokia2_ = std::make_unique<Text>(Resource::get()->getTexture("nokia.png"), Resource::get()->getTextFile("nokia.txt"));
|
||||
text_nokia2_big_ = std::make_unique<Text>(Resource::get()->getTexture("nokia.png"), Resource::get()->getTextFile("nokia.txt"));
|
||||
text_04b_25_ = std::make_unique<Text>(Resource::get()->getTexture("04b_25.png"), Resource::get()->getTextFile("04b_25.txt"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ private:
|
||||
std::vector<std::vector<std::string>> explosions_animations_; // Vector con las animaciones de las explosiones
|
||||
|
||||
std::unique_ptr<Text> text_; // Fuente para los textos del juego
|
||||
std::unique_ptr<Text> text_big_; // Fuente de texto grande
|
||||
std::unique_ptr<Text> text_04b_25_; // Fuente de texto grande
|
||||
std::unique_ptr<Text> text_nokia2_; // Otra fuente de texto para mensajes
|
||||
std::unique_ptr<Text> text_nokia2_big_; // Y la versión en grande
|
||||
|
||||
|
||||
@@ -139,9 +139,7 @@ Intro::Intro()
|
||||
texts_[8]->setSpeed(16);
|
||||
|
||||
for (auto &text : texts_)
|
||||
{
|
||||
text->center(param.game.game_area.center_x);
|
||||
}
|
||||
}
|
||||
|
||||
// Recarga todas las texturas
|
||||
@@ -171,9 +169,7 @@ void Intro::checkEvents()
|
||||
case SDL_WINDOWEVENT:
|
||||
{
|
||||
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||
{
|
||||
reloadTextures();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <iostream> // Para cerr
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "screen.h" // Para Screen
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para Color, getFileName, printWithDots
|
||||
|
||||
@@ -122,26 +123,35 @@ Text::Text(std::shared_ptr<Texture> texture, std::shared_ptr<TextFile> text_file
|
||||
// Escribe texto en pantalla
|
||||
void Text::write(int x, int y, const std::string &text, int kerning, int lenght)
|
||||
{
|
||||
auto shift = 0;
|
||||
int shift = 0;
|
||||
|
||||
if (lenght == -1)
|
||||
{
|
||||
lenght = text.length();
|
||||
}
|
||||
|
||||
sprite_->setY(y);
|
||||
const auto width = sprite_->getWidth();
|
||||
const auto height = sprite_->getHeight();
|
||||
for (int i = 0; i < lenght; ++i)
|
||||
{
|
||||
const auto index = static_cast<int>(text[i]);
|
||||
sprite_->setSpriteClip(offset_[index].x, offset_[index].y, width, height);
|
||||
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 += fixed_width_ ? box_width_ : (offset_[int(text[i])].w + kerning);
|
||||
shift += offset_[static_cast<int>(text[i])].w + kerning;
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe el texto en una textura
|
||||
std::shared_ptr<Texture> Text::writeToTexture(int x, int y, const std::string &text, int kerning)
|
||||
{
|
||||
auto renderer = Screen::get()->getRenderer();
|
||||
auto texture = std::make_shared<Texture>(renderer);
|
||||
auto width = lenght(text, kerning);
|
||||
texture->createBlank(width, box_height_);
|
||||
texture->setAsRenderTarget(renderer);
|
||||
write(0, 0, text, kerning);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Escribe el texto con colores
|
||||
void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int lenght)
|
||||
{
|
||||
@@ -211,12 +221,9 @@ void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerni
|
||||
// Obtiene la longitud en pixels de una cadena
|
||||
int Text::lenght(const std::string &text, int kerning) const
|
||||
{
|
||||
auto shift = 0;
|
||||
|
||||
for (int i = 0; i < (int)text.length(); ++i)
|
||||
{
|
||||
shift += (offset_[int(text[i])].w + kerning);
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -51,6 +51,9 @@ public:
|
||||
// Escribe el texto en pantalla
|
||||
void write(int x, int y, const std::string &text, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe el texto en una textura
|
||||
std::shared_ptr<Texture> writeToTexture(int x, int y, const std::string &text, int kerning = 1);
|
||||
|
||||
// Escribe el texto con colores
|
||||
void writeColored(int x, int y, const std::string &text, Color color, int kerning = 1, int lenght = -1);
|
||||
|
||||
|
||||
@@ -60,6 +60,9 @@ Texture::~Texture()
|
||||
// Carga una imagen desde un fichero
|
||||
bool Texture::loadFromFile(const std::string &file_path)
|
||||
{
|
||||
if (file_path.empty())
|
||||
return false;
|
||||
|
||||
int req_format = STBI_rgb_alpha;
|
||||
int width, height, orig_format;
|
||||
unsigned char *data = stbi_load(file_path.c_str(), &width, &height, &orig_format, req_format);
|
||||
|
||||
Reference in New Issue
Block a user