millores en la pantalla de càrrega de recursos

This commit is contained in:
2025-11-01 18:07:55 +01:00
parent b80e81dab3
commit 139d56f8b5
6 changed files with 52 additions and 48 deletions

View File

@@ -13,9 +13,9 @@
#include "core/resources/asset.hpp" // Para AssetType, Asset #include "core/resources/asset.hpp" // Para AssetType, Asset
#include "core/resources/resource_helper.hpp" // Para ResourceHelper #include "core/resources/resource_helper.hpp" // Para ResourceHelper
#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/defaults.hpp" // Para GameDefaults::VERSION
#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/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 #include "version.h" // Para Version::GIT_HASH
@@ -406,21 +406,23 @@ void Resource::calculateTotal() {
// Muestra el progreso de carga // Muestra el progreso de carga
void Resource::renderProgress() { void Resource::renderProgress() {
constexpr float X_PADDING = 10; constexpr float X_PADDING = 60.0F;
constexpr float Y_PADDING = 10; constexpr float Y_PADDING = 10.0F;
constexpr float BAR_HEIGHT = 10; constexpr float BAR_HEIGHT = 5.0F;
const float BAR_POSITION = Options::game.height - BAR_HEIGHT - Y_PADDING; const float BAR_POSITION = Options::game.height - BAR_HEIGHT - Y_PADDING;
Screen::get()->start(); Screen::get()->start();
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 Uint8 TEXT_COLOR = static_cast<Uint8>(PaletteColor::BRIGHT_WHITE);
const Uint8 BAR_COLOR = static_cast<Uint8>(PaletteColor::WHITE);
const int TEXT_HEIGHT = loading_text_->getCharacterSize(); const int TEXT_HEIGHT = loading_text_->getCharacterSize();
const int CENTER_X = Options::game.width / 2; const int CENTER_X = Options::game.width / 2;
const int CENTER_Y = Options::game.height / 2; const int CENTER_Y = Options::game.height / 2;
// Draw APP_NAME centered above center // Draw APP_NAME centered above center
const std::string APP_NAME = WINDOW_CAPTION; const std::string APP_NAME = spaceBetweenLetters(Version::APP_NAME);
loading_text_->writeColored( loading_text_->writeColored(
CENTER_X - (loading_text_->lenght(APP_NAME) / 2), CENTER_X - (loading_text_->lenght(APP_NAME) / 2),
CENTER_Y - TEXT_HEIGHT, CENTER_Y - TEXT_HEIGHT,
@@ -437,13 +439,13 @@ void Resource::renderProgress() {
// Draw progress bar border // 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, BAR_HEIGHT};
surface->drawRectBorder(&rect_wired, TEXT_COLOR); surface->drawRectBorder(&rect_wired, BAR_COLOR);
// Draw progress bar fill // 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, BAR_HEIGHT};
surface->fillRect(&rect_full, TEXT_COLOR); surface->fillRect(&rect_full, BAR_COLOR);
Screen::get()->render(); Screen::get()->render();
} }

View File

@@ -62,11 +62,6 @@ constexpr bool SOUND_ENABLED = true; // Sonido habilitado por defecto
constexpr bool NOTIFICATION_SOUND = true; // Sonido de las notificaciones por defecto constexpr bool NOTIFICATION_SOUND = true; // Sonido de las notificaciones por defecto
const Uint8 NOTIFICATION_COLOR = static_cast<Uint8>(PaletteColor::BLUE); // Color de las notificaciones por defecto const Uint8 NOTIFICATION_COLOR = static_cast<Uint8>(PaletteColor::BLUE); // Color de las notificaciones por defecto
// =============================================================================
// CONTROL
// =============================================================================
constexpr Options::ControlScheme CONTROL_SCHEME = Options::ControlScheme::CURSOR; // Control por defecto
// ============================================================================= // =============================================================================
// OTHER // OTHER
// ============================================================================= // =============================================================================

View File

@@ -183,14 +183,6 @@ auto saveToFile(const std::string& file_path) -> bool {
auto setOptions(const std::string& var, const std::string& value) -> bool { auto setOptions(const std::string& var, const std::string& value) -> bool {
static const std::unordered_map<std::string, std::function<void(const std::string&)>> OPTION_HANDLERS = { static const std::unordered_map<std::string, std::function<void(const std::string&)>> OPTION_HANDLERS = {
{"version", [](const std::string& v) { version = v; }}, {"version", [](const std::string& v) { version = v; }},
{"keys", [](const std::string& v) {
int val = safeStoi(v, static_cast<int>(GameDefaults::CONTROL_SCHEME));
if (val == static_cast<int>(ControlScheme::CURSOR) || val == static_cast<int>(ControlScheme::OPQA) || val == static_cast<int>(ControlScheme::WASD)) {
keys = static_cast<ControlScheme>(val);
} else {
keys = GameDefaults::CONTROL_SCHEME;
}
}},
{"window.zoom", [](const std::string& v) { {"window.zoom", [](const std::string& v) {
int val = safeStoi(v, GameDefaults::WINDOW_ZOOM); int val = safeStoi(v, GameDefaults::WINDOW_ZOOM);
if (val > 0) { if (val > 0) {

View File

@@ -215,7 +215,7 @@ inline Stats stats{}; // Datos con las estad
inline Notification notifications{}; // Opciones relativas a las notificaciones; inline Notification notifications{}; // Opciones relativas a las notificaciones;
inline Window window{}; // Opciones relativas a la ventana inline Window window{}; // Opciones relativas a la ventana
inline Audio audio{}; // Opciones relativas al audio inline Audio audio{}; // Opciones relativas al audio
inline ControlScheme keys{GameDefaults::CONTROL_SCHEME}; // Teclas usadas para jugar inline ControlScheme keys{ControlScheme::CURSOR}; // Teclas usadas para jugar
// --- Funciones --- // --- Funciones ---
void init(); // Crea e inicializa las opciones del programa void init(); // Crea e inicializa las opciones del programa

View File

@@ -450,3 +450,15 @@ void fillTextureWithColor(SDL_Renderer* renderer, SDL_Texture* texture, Uint8 r,
// Restaurar el render target previo // Restaurar el render target previo
SDL_SetRenderTarget(renderer, previous_target); SDL_SetRenderTarget(renderer, previous_target);
} }
// Añade espacios entre las letras de un string
auto spaceBetweenLetters(const std::string& input) -> std::string {
std::string result;
for (size_t i = 0; i < input.size(); ++i) {
result += input[i];
if (i != input.size() - 1) {
result += ' ';
}
}
return result;
}

View File

@@ -169,3 +169,6 @@ inline auto toSDLPoint(const SDL_FPoint& fpoint) -> SDL_Point {
.y = static_cast<int>(fpoint.y)}; .y = static_cast<int>(fpoint.y)};
return point; return point;
} }
// Añade espacios entre las letras de un string
auto spaceBetweenLetters(const std::string& input) -> std::string;