Arreglos estetics i de colorets en hiscore_table.cpp
This commit is contained in:
@@ -4,23 +4,28 @@
|
||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_SIZE_CHANGED
|
||||
#include <stdlib.h> // Para rand
|
||||
#include <algorithm> // Para max
|
||||
#include <functional> // Para function
|
||||
#include <vector> // Para vector
|
||||
#include "background.h" // Para Background
|
||||
#include "fade.h" // Para Fade, FadeMode, FadeType
|
||||
#include "global_inputs.h" // Para check
|
||||
#include "global_inputs.h" // Para check, update
|
||||
#include "input.h" // Para Input
|
||||
#include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state
|
||||
#include "lang.h" // Para getText
|
||||
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
||||
#include "mouse.h" // Para handleEvent
|
||||
#include "options.h" // Para Options, OptionsGame, options
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamFade
|
||||
#include "path_sprite.h" // Para PathSprite, Path, PathType
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.h" // Para Name, name, Options, options
|
||||
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
|
||||
#include "utils.h" // Para Color, Zone, fade_color, orange_color
|
||||
#include "mouse.h"
|
||||
#include "section.h" // Para Name, name, Options, options, Attr...
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para Text, TEXT_COLOR, TEXT_SHADOW
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para Color, easeOutQuint, fade_color
|
||||
|
||||
// Constructor
|
||||
HiScoreTable::HiScoreTable()
|
||||
@@ -28,30 +33,17 @@ 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_(Resource::get()->getText("smb2")),
|
||||
counter_(0),
|
||||
ticks_(0),
|
||||
view_area_({0, 0, param.game.width, param.game.height}),
|
||||
fade_mode_(FadeMode::IN)
|
||||
fade_mode_(FadeMode::IN),
|
||||
background_fade_color_(Color(0, 0, 0))
|
||||
{
|
||||
// Inicializa el resto de variables
|
||||
// Inicializa el resto
|
||||
section::name = section::Name::HI_SCORE_TABLE;
|
||||
|
||||
// Inicializa objetos
|
||||
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
|
||||
background_->setPos(param.game.game_area.rect);
|
||||
background_->setCloudsSpeed(-0.1f);
|
||||
background_->setGradientNumber(1);
|
||||
background_->setTransition(0.8f);
|
||||
background_->setSunProgression(1.0f);
|
||||
background_->setMoonProgression(0.6f);
|
||||
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade_->setType(FadeType::RANDOM_SQUARE);
|
||||
fade_->setPostDuration(param.fade.post_duration);
|
||||
fade_->setMode(fade_mode_);
|
||||
fade_->activate();
|
||||
|
||||
// Crea los sprites con los textos
|
||||
initFade();
|
||||
initBackground();
|
||||
createSprites();
|
||||
}
|
||||
|
||||
@@ -97,7 +89,7 @@ void HiScoreTable::update()
|
||||
|
||||
if (counter_ == 150)
|
||||
{
|
||||
background_->setColor(Color(0, 0, 0));
|
||||
background_->setColor(background_fade_color_.darken());
|
||||
background_->setAlpha(96);
|
||||
}
|
||||
|
||||
@@ -161,8 +153,6 @@ void HiScoreTable::render()
|
||||
// Recarga todas las texturas
|
||||
void HiScoreTable::reloadTextures()
|
||||
{
|
||||
text_->reLoadTexture();
|
||||
fillTexture();
|
||||
}
|
||||
|
||||
// Comprueba los eventos
|
||||
@@ -268,6 +258,9 @@ std::string HiScoreTable::format(int number)
|
||||
// Crea los sprites con los textos
|
||||
void HiScoreTable::createSprites()
|
||||
{
|
||||
auto header_text = Resource::get()->getText("04b_25");
|
||||
auto entry_text = Resource::get()->getText("smb2");
|
||||
|
||||
// Obtiene el tamaño de la textura
|
||||
int backbuffer_width;
|
||||
int backbuffer_height;
|
||||
@@ -276,32 +269,34 @@ void HiScoreTable::createSprites()
|
||||
// Hay 27 letras - 7 de puntos quedan 20 caracteres 20 - name_lenght 0 num_dots
|
||||
constexpr int max_names = 10;
|
||||
constexpr int space_between_header = 32;
|
||||
const int space_between_lines = text_->getCharacterSize() * 2;
|
||||
const int size = space_between_header + space_between_lines * (max_names - 1) + text_->getCharacterSize();
|
||||
const int space_between_lines = entry_text->getCharacterSize() * 2;
|
||||
const int size = space_between_header + space_between_lines * (max_names - 1) + entry_text->getCharacterSize();
|
||||
const int first_line = (param.game.height - size) / 2;
|
||||
|
||||
// Crea el sprite para el texto de cabecera
|
||||
header_ = std::make_unique<Sprite>(text_->writeDXToTexture(TEXT_COLOR | TEXT_SHADOW, lang::getText(42), 1, orange_color, 1, shdw_txt_color));
|
||||
header_ = std::make_unique<Sprite>(header_text->writeDXToTexture(TEXT_COLOR, lang::getText(42), -2, background_fade_color_.getInverse().lighten(25)));
|
||||
header_->setPosition(param.game.game_area.center_x - (header_->getWidth() / 2), first_line);
|
||||
|
||||
// Crea los sprites para las entradas en la tabla de puntuaciones
|
||||
const int animation = rand() % 4;
|
||||
for (int i = 0; i < max_names; ++i)
|
||||
{
|
||||
const auto name_lenght = options.game.hi_score_table.at(i).name.length();
|
||||
const auto table_position = (i + 1 >= 10) ? format(i + 1) + ". " : " " + format(i + 1) + ". ";
|
||||
const auto score = format(options.game.hi_score_table.at(i).score);
|
||||
const auto score_lenght = score.size();
|
||||
const auto num_dots = 25 - name_lenght - score_lenght;
|
||||
const auto num_dots = 25 - table_position.size() - options.game.hi_score_table.at(i).name.size() - score.size();
|
||||
std::string dots;
|
||||
for (int j = 0; j < (int)num_dots; ++j)
|
||||
{
|
||||
dots = dots + ".";
|
||||
}
|
||||
const auto line = options.game.hi_score_table.at(i).name + dots + score;
|
||||
const auto line = table_position + options.game.hi_score_table.at(i).name + dots + score;
|
||||
|
||||
entry_names_.emplace_back(std::make_shared<PathSprite>(text_->writeDXToTexture(TEXT_SHADOW, line, 1, orange_color, 1, shdw_txt_color)));
|
||||
if (false)
|
||||
entry_names_.emplace_back(std::make_shared<PathSprite>(entry_text->writeDXToTexture(TEXT_SHADOW, line, 1, orange_color, 1, shdw_txt_color)));
|
||||
switch (animation)
|
||||
{
|
||||
if (i % 1 == 0)
|
||||
case 0: // Ambos lados alternativamente
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
entry_names_.back()->addPath(
|
||||
-entry_names_.back()->getWidth(),
|
||||
@@ -325,9 +320,38 @@ void HiScoreTable::createSprites()
|
||||
0);
|
||||
entry_names_.back()->setPosition(backbuffer_width, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (true)
|
||||
case 1: // Entran por la izquierda
|
||||
{
|
||||
entry_names_.back()->addPath(
|
||||
-entry_names_.back()->getWidth(),
|
||||
(backbuffer_width - entry_names_.back()->getWidth()) / 2,
|
||||
PathType::HORIZONTAL,
|
||||
(i * space_between_lines) + first_line + space_between_header,
|
||||
80,
|
||||
easeOutQuint,
|
||||
0);
|
||||
entry_names_.back()->setPosition(-entry_names_.back()->getWidth(), 0);
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: // Entran por la derecha
|
||||
{
|
||||
entry_names_.back()->addPath(
|
||||
backbuffer_width,
|
||||
(backbuffer_width - entry_names_.back()->getWidth()) / 2,
|
||||
PathType::HORIZONTAL,
|
||||
(i * space_between_lines) + first_line + space_between_header,
|
||||
80,
|
||||
easeOutQuint,
|
||||
0);
|
||||
entry_names_.back()->setPosition(backbuffer_width, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
case 3: // Entran desde la parte inferior
|
||||
{
|
||||
entry_names_.back()->addPath(
|
||||
backbuffer_height,
|
||||
@@ -339,14 +363,18 @@ void HiScoreTable::createSprites()
|
||||
0);
|
||||
entry_names_.back()->setPosition(0, backbuffer_height);
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las posiciones de los sprites de texto
|
||||
void HiScoreTable::updateSprites()
|
||||
{
|
||||
constexpr int init_counter = 220;
|
||||
const int counter_between_entries = text_->getCharacterSize() * 2;
|
||||
constexpr int init_counter = 190;
|
||||
const int counter_between_entries = 16;
|
||||
if (counter_ >= init_counter)
|
||||
{
|
||||
const int counter2 = counter_ - init_counter;
|
||||
@@ -363,4 +391,59 @@ void HiScoreTable::updateSprites()
|
||||
{
|
||||
entry->update();
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializa el fade
|
||||
void HiScoreTable::initFade()
|
||||
{
|
||||
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade_->setType(FadeType::RANDOM_SQUARE);
|
||||
fade_->setPostDuration(param.fade.post_duration);
|
||||
fade_->setMode(fade_mode_);
|
||||
fade_->activate();
|
||||
}
|
||||
|
||||
// Inicializa el fondo
|
||||
void HiScoreTable::initBackground()
|
||||
{
|
||||
background_->setPos(param.game.game_area.rect);
|
||||
background_->setCloudsSpeed(-0.1f);
|
||||
|
||||
const int lucky = rand() % 3;
|
||||
//const int lucky = 2;
|
||||
switch (lucky)
|
||||
{
|
||||
case 0: // Fondo verde
|
||||
{
|
||||
background_->setGradientNumber(2);
|
||||
background_->setTransition(0.0f);
|
||||
background_->setSunProgression(1.0f);
|
||||
background_->setMoonProgression(0.4f);
|
||||
background_fade_color_ = Color(0x00, 0x79, 0x6b);
|
||||
break;
|
||||
}
|
||||
|
||||
case 1: // Fondo naranja
|
||||
{
|
||||
background_->setGradientNumber(1);
|
||||
background_->setTransition(0.0f);
|
||||
background_->setSunProgression(0.65f);
|
||||
background_->setMoonProgression(0.0f);
|
||||
background_fade_color_ = Color(0xff, 0x6b, 0x97);
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: // Fondo azul
|
||||
{
|
||||
background_->setGradientNumber(0);
|
||||
background_->setTransition(0.0f);
|
||||
background_->setSunProgression(0.0f);
|
||||
background_->setMoonProgression(0.0f);
|
||||
background_fade_color_ = Color(0x02, 0x88, 0xd1);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user