treballant en la pantalla de càrrega de recursos

This commit is contained in:
2025-11-01 08:52:03 +01:00
parent 16aa4f52aa
commit cb09198bfe
6 changed files with 55 additions and 9 deletions

View File

@@ -90,6 +90,9 @@ Screen::Screen()
// Establece la surface que actuará como renderer para recibir las llamadas a render() // Establece la surface que actuará como renderer para recibir las llamadas a render()
renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(game_surface_); renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(game_surface_);
// Crea el objeto de texto para la pantalla de carga
createText();
// Extrae el nombre de las paletas desde su ruta // Extrae el nombre de las paletas desde su ruta
processPaletteList(); processPaletteList();
@@ -575,3 +578,12 @@ auto Screen::initSDLVideo() -> bool {
std::cout << "** Video system initialized successfully\n"; std::cout << "** Video system initialized successfully\n";
return true; return true;
} }
// Crea el objeto de texto
void Screen::createText() {
// Carga la surface de la fuente directamente del archivo
auto surface = std::make_shared<Surface>(Asset::get()->get("aseprite.gif"));
// Crea el objeto de texto (el constructor de Text carga el archivo text_file internamente)
text_ = std::make_shared<Text>(surface, Asset::get()->get("aseprite.txt"));
}

View File

@@ -9,6 +9,7 @@
#include "utils/utils.hpp" // Para Color #include "utils/utils.hpp" // Para Color
class Surface; class Surface;
class Text;
namespace Rendering { namespace Rendering {
class ShaderBackend; class ShaderBackend;
} }
@@ -70,6 +71,7 @@ class Screen {
std::shared_ptr<Surface> border_surface_; // Surface para pintar el el borde de la pantalla std::shared_ptr<Surface> border_surface_; // Surface para pintar el el borde de la pantalla
std::shared_ptr<std::shared_ptr<Surface>> renderer_surface_; // Puntero a la Surface que actua std::shared_ptr<std::shared_ptr<Surface>> renderer_surface_; // Puntero a la Surface que actua
std::unique_ptr<Rendering::ShaderBackend> shader_backend_; // Backend de shaders (OpenGL/Metal/Vulkan) std::unique_ptr<Rendering::ShaderBackend> shader_backend_; // Backend de shaders (OpenGL/Metal/Vulkan)
std::shared_ptr<Text> text_; // Objeto para escribir texto en pantalla de carga
// Variables // Variables
int window_width_; // Ancho de la pantalla o ventana int window_width_; // Ancho de la pantalla o ventana
@@ -120,6 +122,7 @@ class Screen {
void renderInfo(); // Muestra información por pantalla void renderInfo(); // Muestra información por pantalla
void getDisplayInfo(); // Obtiene información sobre la pantalla void getDisplayInfo(); // Obtiene información sobre la pantalla
auto initSDLVideo() -> bool; // Arranca SDL VIDEO y crea la ventana auto initSDLVideo() -> bool; // Arranca SDL VIDEO y crea la ventana
void createText(); // Crea el objeto de texto
// Constructor // Constructor
Screen(); Screen();
@@ -212,4 +215,5 @@ class Screen {
auto getRenderer() -> SDL_Renderer*; auto getRenderer() -> SDL_Renderer*;
auto getRendererSurface() -> std::shared_ptr<Surface>; auto getRendererSurface() -> std::shared_ptr<Surface>;
auto getBorderSurface() -> std::shared_ptr<Surface>; auto getBorderSurface() -> std::shared_ptr<Surface>;
[[nodiscard]] auto getText() const -> std::shared_ptr<Text> { return text_; }
}; };

View File

@@ -15,7 +15,10 @@
#include "external/jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_Loa... #include "external/jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_Loa...
#include "game/gameplay/room.hpp" // Para RoomData, loadRoomFile, loadRoomTileFile #include "game/gameplay/room.hpp" // Para RoomData, loadRoomFile, loadRoomTileFile
#include "game/options.hpp" // Para Options, OptionsGame, options #include "game/options.hpp" // Para Options, OptionsGame, options
#include "game/defaults.hpp" // Para GameDefaults::VERSION
#include "utils/defines.hpp" // Para WINDOW_CAPTION
#include "utils/utils.hpp" // Para getFileName, printWithDots, PaletteColor #include "utils/utils.hpp" // Para getFileName, printWithDots, PaletteColor
#include "version.h" // Para Version::GIT_HASH
struct JA_Music_t; // lines 17-17 struct JA_Music_t; // lines 17-17
struct JA_Sound_t; // lines 18-18 struct JA_Sound_t; // lines 18-18
@@ -32,7 +35,10 @@ void Resource::destroy() { delete Resource::resource; }
auto Resource::get() -> Resource* { return Resource::resource; } auto Resource::get() -> Resource* { return Resource::resource; }
// Constructor // Constructor
Resource::Resource() { load(); } Resource::Resource() {
loading_text_ = Screen::get()->getText();
load();
}
// Vacia todos los vectores de recursos // Vacia todos los vectores de recursos
void Resource::clear() { void Resource::clear() {
@@ -408,13 +414,36 @@ void Resource::renderProgress() {
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK)); Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
auto surface = Screen::get()->getRendererSurface(); auto surface = Screen::get()->getRendererSurface();
const Uint8 TEXT_COLOR = static_cast<Uint8>(PaletteColor::WHITE);
const int TEXT_HEIGHT = loading_text_->getCharacterSize();
const int CENTER_X = Options::game.width / 2;
const int CENTER_Y = Options::game.height / 2;
// Draw APP_NAME centered above center
const std::string APP_NAME = WINDOW_CAPTION;
loading_text_->writeColored(
CENTER_X - (loading_text_->lenght(APP_NAME) / 2),
CENTER_Y - TEXT_HEIGHT,
APP_NAME,
TEXT_COLOR);
// Draw VERSION centered below center
const std::string VERSION_TEXT = "(" + std::string(Version::GIT_HASH) + ")";
loading_text_->writeColored(
CENTER_X - (loading_text_->lenght(VERSION_TEXT) / 2),
CENTER_Y + TEXT_HEIGHT,
VERSION_TEXT,
TEXT_COLOR);
// Draw progress bar border
const float WIRED_BAR_WIDTH = Options::game.width - (X_PADDING * 2); const float WIRED_BAR_WIDTH = Options::game.width - (X_PADDING * 2);
SDL_FRect rect_wired = {X_PADDING, BAR_POSITION, WIRED_BAR_WIDTH, X_PADDING}; SDL_FRect rect_wired = {X_PADDING, BAR_POSITION, WIRED_BAR_WIDTH, X_PADDING};
surface->drawRectBorder(&rect_wired, static_cast<Uint8>(PaletteColor::WHITE)); surface->drawRectBorder(&rect_wired, TEXT_COLOR);
// Draw progress bar fill
const float FULL_BAR_WIDTH = WIRED_BAR_WIDTH * count_.getPercentage(); const float FULL_BAR_WIDTH = WIRED_BAR_WIDTH * count_.getPercentage();
SDL_FRect rect_full = {X_PADDING, BAR_POSITION, FULL_BAR_WIDTH, X_PADDING}; SDL_FRect rect_full = {X_PADDING, BAR_POSITION, FULL_BAR_WIDTH, X_PADDING};
surface->fillRect(&rect_full, static_cast<Uint8>(PaletteColor::WHITE)); surface->fillRect(&rect_full, TEXT_COLOR);
Screen::get()->render(); Screen::get()->render();
} }

View File

@@ -153,6 +153,7 @@ class Resource {
std::vector<ResourceRoom> rooms_; // Vector con las habitaciones std::vector<ResourceRoom> rooms_; // Vector con las habitaciones
ResourceCount count_; // Contador de recursos ResourceCount count_; // Contador de recursos
std::shared_ptr<Text> loading_text_; // Texto para la pantalla de carga
// Carga los sonidos // Carga los sonidos
void loadSounds(); void loadSounds();

View File

@@ -7,6 +7,7 @@
#include <utility> #include <utility>
#include "core/rendering/screen.hpp" // Para ScreenFilter #include "core/rendering/screen.hpp" // Para ScreenFilter
#include "utils/defines.hpp" // Para WINDOW_CAPTION
#include "utils/utils.hpp" // Para Color, Palette #include "utils/utils.hpp" // Para Color, Palette
// --- Namespace Options: gestión de configuración y opciones del juego --- // --- Namespace Options: gestión de configuración y opciones del juego ---
@@ -87,7 +88,7 @@ struct Stats {
// Estructura con opciones de la ventana // Estructura con opciones de la ventana
struct Window { struct Window {
std::string caption{"JailDoctor's Dilemma"}; // Texto que aparece en la barra de título de la ventana std::string caption{WINDOW_CAPTION}; // Texto que aparece en la barra de título de la ventana
int zoom{GameDefaults::WINDOW_ZOOM}; // Zoom de la ventana int zoom{GameDefaults::WINDOW_ZOOM}; // Zoom de la ventana
int max_zoom{GameDefaults::WINDOW_ZOOM}; // Máximo tamaño de zoom para la ventana int max_zoom{GameDefaults::WINDOW_ZOOM}; // Máximo tamaño de zoom para la ventana
@@ -96,7 +97,7 @@ struct Window {
// Constructor // Constructor
Window(int window_zoom, int maximum_zoom) Window(int window_zoom, int maximum_zoom)
: caption("JailDoctor's Dilemma"), : caption(WINDOW_CAPTION),
zoom(window_zoom), zoom(window_zoom),
max_zoom(maximum_zoom) {} max_zoom(maximum_zoom) {}
}; };

View File

@@ -9,7 +9,6 @@
// Textos // Textos
constexpr const char* WINDOW_CAPTION = "JailDoctor's Dilemma"; constexpr const char* WINDOW_CAPTION = "JailDoctor's Dilemma";
constexpr const char* TEXT_COPYRIGHT = "@2022 JailDesigner"; constexpr const char* TEXT_COPYRIGHT = "@2022 JailDesigner";
constexpr const char* VERSION = "1.10";
// Velocidad del juego // Velocidad del juego
constexpr Uint32 GAME_SPEED = 15; constexpr Uint32 GAME_SPEED = 15;