Els objectes de Text es precarreguen al inici
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
#include "define_buttons.h"
|
||||
#include <utility> // Para move
|
||||
#include "input.h" // Para Input, InputType
|
||||
#include "lang.h" // Para getText
|
||||
#include "options.h" // Para OptionsController, Options, options
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
||||
#include "section.h" // Para Name, Options, name, options
|
||||
#include "text.h" // Para Text
|
||||
#include <utility> // Para move
|
||||
#include "input.h" // Para Input, InputType
|
||||
#include "lang.h" // Para getText
|
||||
#include "options.h" // Para OptionsController, Options, options
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
||||
#include "resource.h" // Para Resource
|
||||
#include "section.h" // Para Name, Options, name, options
|
||||
#include "text.h" // Para Text
|
||||
|
||||
// Constructor
|
||||
DefineButtons::DefineButtons(std::unique_ptr<Text> text_)
|
||||
DefineButtons::DefineButtons()
|
||||
: input_(Input::get()),
|
||||
text_(std::move(text_))
|
||||
text_(Resource::get()->getText("8bithud"))
|
||||
{
|
||||
// Inicializa variables
|
||||
x_ = param.game.width / 2;
|
||||
|
||||
@@ -58,7 +58,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
explicit DefineButtons(std::unique_ptr<Text> text);
|
||||
DefineButtons();
|
||||
|
||||
// Destructor
|
||||
~DefineButtons() = default;
|
||||
|
||||
@@ -118,8 +118,7 @@ Director::Director(int argc, const char *argv[])
|
||||
Resource::init();
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||
bindInputs();
|
||||
auto notifier_text = std::make_shared<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||
Notifier::init(std::string(), notifier_text, Asset::get()->get("notify.wav"));
|
||||
Notifier::init(std::string(), Resource::get()->getText("8bithud"), Asset::get()->get("notify.wav"));
|
||||
OnScreenHelp::init();
|
||||
globalInputs::init();
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ void Game::updateStage()
|
||||
createMessage(paths, Resource::get()->getTexture("last_stage"));
|
||||
else
|
||||
{
|
||||
auto text = std::make_unique<Text>(Resource::get()->getTexture("04b_25.png"), Resource::get()->getTextFile("04b_25.txt"));
|
||||
auto text = Resource::get()->getText("04b_25");
|
||||
const std::string caption = std::to_string(10 - current_stage_) + lang::getText(38);
|
||||
createMessage(paths, text->writeToTexture(caption, 2, -2));
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ HiScoreTable::HiScoreTable()
|
||||
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
fade_(std::make_unique<Fade>()),
|
||||
background_(std::make_unique<Background>()),
|
||||
text_(std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"))),
|
||||
text_(Resource::get()->getText("smb2")),
|
||||
counter_(0),
|
||||
ticks_(0),
|
||||
view_area_({0, 0, param.game.width, param.game.height}),
|
||||
|
||||
@@ -33,7 +33,7 @@ private:
|
||||
|
||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
||||
std::unique_ptr<Text> text_; // Objeto para escribir texto
|
||||
std::shared_ptr<Text> text_; // Objeto para escribir texto
|
||||
|
||||
// Variables
|
||||
Uint16 counter_; // Contador
|
||||
|
||||
@@ -26,7 +26,7 @@ Instructions::Instructions()
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
texture_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
text_(std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"))),
|
||||
text_(Resource::get()->getText("smb2")),
|
||||
tiled_bg_(std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::STATIC)),
|
||||
fade_(std::make_unique<Fade>())
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@ private:
|
||||
|
||||
std::vector<std::shared_ptr<Texture>> item_textures_; // Vector con las texturas de los items
|
||||
std::vector<std::unique_ptr<Sprite>> sprites_; // Vector con los sprites de los items
|
||||
std::unique_ptr<Text> text_; // Objeto para escribir texto
|
||||
std::shared_ptr<Text> text_; // Objeto para escribir texto
|
||||
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
// Constructor
|
||||
Intro::Intro()
|
||||
: texture_(Resource::get()->getTexture("intro.png")),
|
||||
text_(std::make_shared<Text>(Resource::get()->getTexture("nokia.png"), Resource::get()->getTextFile("nokia.txt")))
|
||||
text_(Resource::get()->getText("nokia"))
|
||||
{
|
||||
|
||||
// Inicializa variables
|
||||
|
||||
@@ -94,7 +94,7 @@ void OnScreenHelp::fillTexture()
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), texture);
|
||||
|
||||
// Crea el objeto para el texto
|
||||
auto text = std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||
auto text = Resource::get()->getText("8bithud");
|
||||
|
||||
// Crea la textura con los gráficos
|
||||
auto controllersTexture = Resource::get()->getTexture("controllers.png");
|
||||
@@ -169,7 +169,7 @@ void OnScreenHelp::toggleState()
|
||||
// Calcula la longitud en pixels del texto más largo
|
||||
auto OnScreenHelp::getLargestStringSize() -> int const
|
||||
{
|
||||
auto text = std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||
auto text = Resource::get()->getText("8bithud");
|
||||
auto size = 0;
|
||||
|
||||
for (int i = 107; i <= 113; ++i)
|
||||
|
||||
@@ -42,6 +42,7 @@ Resource::Resource()
|
||||
loadAnimations();
|
||||
loadDemoData();
|
||||
addPalettes();
|
||||
createText();
|
||||
createTextures();
|
||||
std::cout << "\n** RESOURCES LOADED" << std::endl;
|
||||
}
|
||||
@@ -106,6 +107,21 @@ std::shared_ptr<TextFile> Resource::getTextFile(const std::string &name)
|
||||
throw std::runtime_error("TextFile no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene el objeto de texto a partir de un nombre
|
||||
std::shared_ptr<Text> Resource::getText(const std::string &name)
|
||||
{
|
||||
auto it = std::find_if(texts_.begin(), texts_.end(), [&name](const auto &t)
|
||||
{ return t.name == name; });
|
||||
|
||||
if (it != texts_.end())
|
||||
{
|
||||
return it->text;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Text no encontrado " << name << std::endl;
|
||||
throw std::runtime_error("Text no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la animación a partir de un nombre
|
||||
AnimationsFileBuffer &Resource::getAnimation(const std::string &name)
|
||||
{
|
||||
@@ -239,7 +255,7 @@ void Resource::createTextures()
|
||||
};
|
||||
|
||||
std::cout << "\n>> CREATING TEXTURES" << std::endl;
|
||||
auto text = std::make_unique<Text>(getTexture("04b_25.png"), getTextFile("04b_25.txt"));
|
||||
auto text = getText("04b_25");
|
||||
|
||||
// Tamaño normal
|
||||
std::vector<NameAndText> strings = {
|
||||
@@ -270,3 +286,21 @@ void Resource::createTextures()
|
||||
printWithDots("Texture : ", s.name, "[ DONE ]");
|
||||
}
|
||||
}
|
||||
|
||||
// Crea los objetos de texto
|
||||
void Resource::createText()
|
||||
{
|
||||
std::cout << "\n>> CREATING TEXT_OBJECTS" << std::endl;
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> resources = {
|
||||
{"04b_25", "04b_25.png"},
|
||||
{"8bithud", "8bithud.png"},
|
||||
{"nokia", "nokia.png"},
|
||||
{"smb2", "smb2.gif"}};
|
||||
|
||||
for (const auto &resource : resources)
|
||||
{
|
||||
texts_.emplace_back(ResourceText(resource.first, std::make_shared<Text>(getTexture(resource.second), getTextFile(resource.first + ".txt"))));
|
||||
printWithDots("Text : ", resource.first, "[ DONE ]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,17 @@ struct ResourceTextFile
|
||||
: name(name), text_file(text_file) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar objetos Text y su nombre
|
||||
struct ResourceText
|
||||
{
|
||||
std::string name; // Nombre del objeto
|
||||
std::shared_ptr<Text> text; // Objeto
|
||||
|
||||
// Constructor
|
||||
ResourceText(const std::string &name, std::shared_ptr<Text> text)
|
||||
: name(name), text(text) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar ficheros animaciones y su nombre
|
||||
struct ResourceAnimation
|
||||
{
|
||||
@@ -75,6 +86,7 @@ private:
|
||||
std::vector<ResourceMusic> musics_; // Vector con las musicas
|
||||
std::vector<ResourceTexture> textures_; // Vector con las musicas
|
||||
std::vector<ResourceTextFile> text_files_; // Vector con los ficheros de texto
|
||||
std::vector<ResourceText> texts_; // Vector con los objetos de texto
|
||||
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
|
||||
std::vector<DemoData> demos_; // Vector con los ficheros de datos para el modo demostración
|
||||
|
||||
@@ -102,6 +114,9 @@ private:
|
||||
// Crea texturas
|
||||
void createTextures();
|
||||
|
||||
// Crea los objetos de texto
|
||||
void createText();
|
||||
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
|
||||
|
||||
// Constructor
|
||||
@@ -132,6 +147,9 @@ public:
|
||||
// Obtiene el fichero de texto a partir de un nombre
|
||||
std::shared_ptr<TextFile> getTextFile(const std::string &name);
|
||||
|
||||
// Obtiene el objeto de texto a partir de un nombre
|
||||
std::shared_ptr<Text> getText(const std::string &name);
|
||||
|
||||
// Obtiene la animación a partir de un nombre
|
||||
AnimationsFileBuffer &getAnimation(const std::string &name);
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ Scoreboard::Scoreboard()
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
game_power_meter_texture_(Resource::get()->getTexture("game_power_meter.png")),
|
||||
power_meter_sprite_(std::make_unique<Sprite>(game_power_meter_texture_)),
|
||||
text_scoreboard_(std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt")))
|
||||
text_scoreboard_(Resource::get()->getText("8bithud"))
|
||||
{
|
||||
// Inicializa variables
|
||||
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||
|
||||
@@ -52,7 +52,7 @@ private:
|
||||
|
||||
std::shared_ptr<Texture> game_power_meter_texture_; // Textura con el marcador de poder de la fase
|
||||
std::unique_ptr<Sprite> power_meter_sprite_; // Sprite para el medidor de poder de la fase
|
||||
std::unique_ptr<Text> text_scoreboard_; // Fuente para el marcador del juego
|
||||
std::shared_ptr<Text> text_scoreboard_; // Fuente para el marcador del juego
|
||||
|
||||
SDL_Texture *background_ = nullptr; // Textura para dibujar el marcador
|
||||
std::vector<SDL_Texture *> panel_texture_; // Texturas para dibujar cada panel
|
||||
|
||||
@@ -28,14 +28,13 @@
|
||||
|
||||
// Constructor
|
||||
Title::Title()
|
||||
: text1_(std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"))),
|
||||
text2_(std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"))),
|
||||
: text_(Resource::get()->getText("smb2")),
|
||||
fade_(std::make_unique<Fade>()),
|
||||
tiled_bg_(std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::RANDOM)),
|
||||
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)),
|
||||
mini_logo_texture_(Resource::get()->getTexture("logo_jailgames_mini.png")),
|
||||
mini_logo_sprite_(std::make_unique<Sprite>(mini_logo_texture_, param.game.game_area.center_x - mini_logo_texture_->getWidth() / 2, 0, mini_logo_texture_->getWidth(), mini_logo_texture_->getHeight())),
|
||||
define_buttons_(std::make_unique<DefineButtons>(std::move(text2_))),
|
||||
define_buttons_(std::make_unique<DefineButtons>()),
|
||||
num_controllers_(Input::get()->getNumControllers())
|
||||
{
|
||||
// Configura objetos
|
||||
@@ -146,7 +145,7 @@ void Title::render()
|
||||
// 'PRESS TO PLAY'
|
||||
if (counter_ % 50 > 14 && !define_buttons_->isEnabled())
|
||||
{
|
||||
text1_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, param.title.press_start_position, lang::getText(23), 1, no_color, 1, shadow);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, param.title.press_start_position, lang::getText(23), 1, no_color, 1, shadow);
|
||||
}
|
||||
|
||||
// Mini logo
|
||||
@@ -156,7 +155,7 @@ void Title::render()
|
||||
mini_logo_sprite_->render();
|
||||
|
||||
// Texto con el copyright
|
||||
text1_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, pos2, TEXT_COPYRIGHT, 1, no_color, 1, shadow);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, pos2, TEXT_COPYRIGHT, 1, no_color, 1, shadow);
|
||||
}
|
||||
|
||||
// Define Buttons
|
||||
|
||||
@@ -40,8 +40,7 @@ class Title
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
std::unique_ptr<Text> text1_; // Objeto de texto para poder escribir textos en pantalla
|
||||
std::unique_ptr<Text> text2_; // Objeto de texto para poder escribir textos en pantalla
|
||||
std::shared_ptr<Text> text_; // Objeto de texto para poder escribir textos en pantalla
|
||||
std::unique_ptr<Fade> fade_; // Objeto para realizar fundidos en pantalla
|
||||
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
||||
std::unique_ptr<GameLogo> game_logo_; // Objeto para dibujar el logo con el título del juego
|
||||
|
||||
Reference in New Issue
Block a user