From 6c3e231d51506ca3aabc4bc9b416510e4c80d160 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 7 Mar 2025 12:20:30 +0100 Subject: [PATCH] Arreglats alguns colorets que havia per ahi rebolicats fix: Credits no estava ben portat a surfaces --- source/credits.cpp | 38 ++++++++++---------------------- source/logo.cpp | 6 ++--- source/options.h | 2 +- source/resource.cpp | 8 +++---- source/screen.cpp | 2 +- source/screen.h | 2 +- source/title.cpp | 53 ++++++++++++++++++++++----------------------- 7 files changed, 46 insertions(+), 65 deletions(-) diff --git a/source/credits.cpp b/source/credits.cpp index 039a6d1e..ee7b7e86 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -162,47 +162,31 @@ void Credits::fillTexture() const int TEXT_LENGHT = text->lenght(texts_[22].label, 1) - text->lenght(" ", 1); // Se resta el ultimo caracter que es un espacio const int POS_X = ((PLAY_AREA_WIDTH - TEXT_LENGHT) / 2) + TEXT_LENGHT; text->writeColored(POS_X, 176, "}", static_cast(PaletteColor::BRIGHT_RED)); + Screen::get()->setRendererSurface(previuos_renderer); // Recoloca el sprite del brillo shining_sprite_->setPosX(POS_X + 2); // Rellena la textura que cubre el texto con color transparente - text_surface_->clear(static_cast(PaletteColor::TRANSPARENT)); + cover_surface_->clear(static_cast(PaletteColor::TRANSPARENT)); // Los primeros 8 pixels crea una malla - auto surface = Screen::get()->getRendererSurface(); auto color = static_cast(PaletteColor::BLACK); for (int i = 0; i < 256; i += 2) { - surface->putPixel(i, 0, color); - surface->putPixel(i, 2, color); - surface->putPixel(i, 4, color); - surface->putPixel(i, 6, color); + cover_surface_->putPixel(i, 0, color); + cover_surface_->putPixel(i, 2, color); + cover_surface_->putPixel(i, 4, color); + cover_surface_->putPixel(i, 6, color); - surface->putPixel(i + 1, 5, color); - surface->putPixel(i + 1, 7, color); + cover_surface_->putPixel(i + 1, 5, color); + cover_surface_->putPixel(i + 1, 7, color); } // El resto se rellena de color sólido SDL_Rect rect = {0, 8, 256, 192}; - surface->fillRect(&rect, color); + cover_surface_->fillRect(&rect, color); - for (int i = 0; i < 256; i += 2) - { - surface->putPixel(i, 0, color); - surface->putPixel(i, 2, color); - surface->putPixel(i, 4, color); - surface->putPixel(i, 6, color); - - surface->putPixel(i + 1, 5, color); - surface->putPixel(i + 1, 7, color); - } - - // El resto se rellena de color sólido - rect = {0, 8, 256, 192}; - surface->fillRect(&rect, color); - - Screen::get()->setRendererSurface(previuos_renderer); } // Actualiza el contador @@ -266,7 +250,7 @@ void Credits::render() Screen::get()->start(); // Limpia la pantalla - Screen::get()->clearSurface(1); + Screen::get()->clearSurface(static_cast(PaletteColor::BLACK)); if (counter_ < 1150) { @@ -279,7 +263,7 @@ void Credits::render() cover_surface_->render(0, offset * 2, &srcRect); // Dibuja el sprite con el brillo - shining_sprite_->render(); + shining_sprite_->render(1, static_cast(PaletteColor::BRIGHT_WHITE)); } // Vuelca el contenido del renderizador en pantalla diff --git a/source/logo.cpp b/source/logo.cpp index 4dd1f50c..a605ccd6 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -20,7 +20,7 @@ Logo::Logo() since_1998_sprite_(std::make_shared(since_1998_surface_, (256 - since_1998_surface_->getWidth()) / 2, 83 + jailgames_surface_->getHeight() + 5, since_1998_surface_->getWidth(), since_1998_surface_->getHeight())) { since_1998_sprite_->setClip(0, 0, since_1998_surface_->getWidth(), since_1998_surface_->getHeight()); - since_1998_color_ = static_cast(PaletteColor::BRIGHT_BLACK); + since_1998_color_ = static_cast(PaletteColor::BLACK); jailgames_color_ = static_cast(PaletteColor::WHITE); // Crea los sprites de cada linea @@ -51,7 +51,7 @@ Logo::Logo() } // Cambia el color del borde - Screen::get()->setBorderColor(static_cast(PaletteColor::BRIGHT_BLACK)); + Screen::get()->setBorderColor(static_cast(PaletteColor::BLACK)); } // Comprueba el manejador de eventos @@ -227,7 +227,7 @@ void Logo::render() { // Prepara para empezar a dibujar en la textura de juego Screen::get()->start(); - Screen::get()->clearSurface(); + Screen::get()->clearSurface(static_cast(PaletteColor::BLACK)); // Dibuja los objetos for (const auto &s : jailgames_sprite_) diff --git a/source/options.h b/source/options.h index d6e97d77..3c8328e1 100644 --- a/source/options.h +++ b/source/options.h @@ -81,7 +81,7 @@ constexpr Subsection DEFAULT_SUBSECTION = Subsection::LOGO_TO_INTRO; constexpr ControlScheme DEFAULT_CONTROL_SCHEME = ControlScheme::CURSOR; // Control por defecto constexpr NotificationPosition DEFAULT_NOTIFICATION_POSITION = NotificationPosition::UPPER_LEFT; // Posición de las notificaciones por defecto constexpr bool DEFAULT_NOTIFICATION_SOUND = true; // Sonido de las notificaciones por defecto -const Uint8 DEFAULT_NOTIFICATION_COLOR = 1; // Color de las notificaciones por defecto +const Uint8 DEFAULT_NOTIFICATION_COLOR = static_cast(PaletteColor::BLACK); // Color de las notificaciones por defecto constexpr bool DEFAULT_CONSOLE = false; // Consola desactivada por defecto constexpr const char *DEFAULT_VERSION = "1.10"; // Versión por defecto diff --git a/source/resource.cpp b/source/resource.cpp index a194a00a..5b54600d 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -428,18 +428,16 @@ void Resource::renderProgress() constexpr int BAR_HEIGHT = 10; const int bar_position = options.game.height - BAR_HEIGHT - Y_PADDING; Screen::get()->start(); - Screen::get()->clearSurface(); + Screen::get()->clearSurface(static_cast(PaletteColor::BLACK)); auto surface = Screen::get()->getRendererSurface(); const int wired_bar_width = options.game.width - (X_PADDING * 2); SDL_Rect rect_wired = {X_PADDING, bar_position, wired_bar_width, X_PADDING}; - surface->drawRectBorder(&rect_wired, stringToColor("white")); + surface->drawRectBorder(&rect_wired, static_cast(PaletteColor::WHITE)); const int full_bar_width = wired_bar_width * count_.getPercentage(); SDL_Rect rect_full = {X_PADDING, bar_position, full_bar_width, X_PADDING}; - surface->fillRect(&rect_full, stringToColor("white")); - - Screen::get()->render(); + surface->fillRect(&rect_full, static_cast(PaletteColor::WHITE)); } // Comprueba los eventos de la pantalla de carga diff --git a/source/screen.cpp b/source/screen.cpp index c5019367..76fa5696 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -49,7 +49,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) current_palette_ = findPalette(options.video.palette); // Define el color del borde para el modo de pantalla completa - border_color_ = 1; + border_color_ = static_cast(PaletteColor::BLACK); // Establece el modo de escalado SDL_RenderSetIntegerScale(renderer_, options.video.integer_scale ? SDL_TRUE : SDL_FALSE); diff --git a/source/screen.h b/source/screen.h index 9a671389..2126f4af 100644 --- a/source/screen.h +++ b/source/screen.h @@ -95,7 +95,7 @@ public: // Limpia la pantalla void clear(Color color = {0x00, 0x00, 0x00}); - void clearSurface(Uint8 index = 1); + void clearSurface(Uint8 index = 0); // Prepara para empezar a dibujar en la textura de juego void start(); diff --git a/source/title.cpp b/source/title.cpp index b2dd1d1a..0e5fd7ed 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -43,7 +43,7 @@ Title::Title() createCheevosTexture(); // Cambia el color del borde - Screen::get()->setBorderColor(static_cast(PaletteColor::BRIGHT_BLACK)); + Screen::get()->setBorderColor(static_cast(PaletteColor::BLACK)); // Rellena la textura de fondo con todos los gráficos fillSurface(); @@ -164,7 +164,8 @@ void Title::updateMarquee() // Comprueba si ha terminado la marquesina y la reinicia if (letters_[letters_.size() - 1].x < -10) - { // Inicializa la marquesina + { + // Inicializa la marquesina initMarquee(); } } @@ -246,10 +247,11 @@ void Title::render() { // Prepara para empezar a dibujar en la textura de juego Screen::get()->start(); - Screen::get()->clearSurface(stringToColor("black")); + Screen::get()->clearSurface(static_cast(PaletteColor::BLACK)); - if (state_ == TitleState::SHOW_MENU) + switch (state_) { + case TitleState::SHOW_MENU: // Dibuja la textura de fondo bg_surface_->render(0, 0); @@ -261,9 +263,10 @@ void Title::render() { cheevos_sprite_->render(); } - } - else - { + break; + + case TitleState::SHOW_LOADING_SCREEN: + case TitleState::FADE_LOADING_SCREEN: // Dibuja la pantalla de carga pCls(4); pBlit(0, 0, 0, 0, 256, 128); @@ -271,6 +274,10 @@ void Title::render() // Dibuja el logo del título title_logo_sprite_->render(); + break; + + default: + break; } // Vuelca el contenido del renderizador en pantalla @@ -291,18 +298,13 @@ void Title::run() // Desplaza la lista de logros void Title::moveCheevosList(int direction) { - const int speed = 2; - cheevos_surface_view_.y = direction == 0 ? cheevos_surface_view_.y - speed : cheevos_surface_view_.y + speed; + // Modifica la posición de la ventana de vista + constexpr int SPEED = 2; + cheevos_surface_view_.y = direction == 0 ? cheevos_surface_view_.y - SPEED : cheevos_surface_view_.y + SPEED; - const int bottom = cheevos_surface_->getHeight() - cheevos_surface_view_.h; - if (cheevos_surface_view_.y < 0) - { - cheevos_surface_view_.y = 0; - } - else if (cheevos_surface_view_.y > bottom) - { - cheevos_surface_view_.y = bottom; - } + // Ajusta los limites + const int BOTTOM = cheevos_surface_->getHeight() - cheevos_surface_view_.h; + cheevos_surface_view_.y = std::clamp(cheevos_surface_view_.y, 0, BOTTOM); cheevos_sprite_->setClip(cheevos_surface_view_); } @@ -315,7 +317,7 @@ void Title::fillSurface() Screen::get()->setRendererSurface(bg_surface_); // Rellena la textura de color - bg_surface_->clear(1); + bg_surface_->clear(static_cast(PaletteColor::BLACK)); // Pinta el gráfico del titulo a partir del sprite title_logo_sprite_->render(); @@ -327,7 +329,6 @@ void Title::fillSurface() text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 11 * TEXT_SIZE, "1.PLAY", 1, COLOR); text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 13 * TEXT_SIZE, "2.ACHIEVEMENTS", 1, COLOR); text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 15 * TEXT_SIZE, "3.REDEFINE KEYS", 1, COLOR); - //text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 20 * TEXT_SIZE, "ESC.EXIT GAME", 1, COLOR); // Devuelve el puntero del renderizador a su sitio Screen::get()->setRendererSurface(previuos_renderer); @@ -352,7 +353,7 @@ void Title::createCheevosTexture() Screen::get()->setRendererSurface(cheevos_surface_); // Rellena la textura con color sólido - const Uint8 CHEEVOS_BG_COLOR = stringToColor("black"); + const Uint8 CHEEVOS_BG_COLOR = static_cast(PaletteColor::BLACK); cheevos_surface_->clear(CHEEVOS_BG_COLOR); // Escribe la lista de logros en la textura @@ -363,20 +364,18 @@ void Title::createCheevosTexture() pos += TEXT->getCharacterSize(); const Uint8 CHEEVO_LOCKED_COLOR = stringToColor("white"); const Uint8 CHEEVO_UNLOCKED_COLOR = stringToColor("bright_green"); - Uint8 cheevoColor; constexpr int LINE_X1 = (CHEEVOS_TEXTURE_WIDTH / 7) * 3; constexpr int LINE_X2 = LINE_X1 + ((CHEEVOS_TEXTURE_WIDTH / 7) * 1); for (const auto &cheevo : CHEEVOS_LIST) { - cheevoColor = cheevo.completed ? CHEEVO_UNLOCKED_COLOR : CHEEVO_LOCKED_COLOR; + const Uint8 CHEEVO_COLOR = cheevo.completed ? CHEEVO_UNLOCKED_COLOR : CHEEVO_LOCKED_COLOR; pos += CHEEVOS_PADDING; constexpr int HALF = CHEEVOS_PADDING / 2; - auto surface = Screen::get()->getRendererSurface(); - surface->drawLine(LINE_X1, pos - HALF - 1, LINE_X2, pos - HALF - 1, cheevoColor); - TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.caption, 1, cheevoColor); + cheevos_surface_->drawLine(LINE_X1, pos - HALF - 1, LINE_X2, pos - HALF - 1, CHEEVO_COLOR); + TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.caption, 1, CHEEVO_COLOR); pos += TEXT->getCharacterSize() + 1; - TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.description, 1, cheevoColor); + TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.description, 1, CHEEVO_COLOR); pos += TEXT->getCharacterSize(); }