afegides notificacions per als inputs externs al joc
This commit is contained in:
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
Binary file not shown.
@@ -10,7 +10,7 @@ Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapF
|
||||
this->renderer = renderer;
|
||||
this->options = options;
|
||||
bgColor = options->notification.color;
|
||||
waitTime = 300;
|
||||
waitTime = 100;
|
||||
|
||||
// Crea objetos
|
||||
iconTexture = new Texture(renderer, iconFile);
|
||||
@@ -151,17 +151,20 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
{
|
||||
// Inicializa variables
|
||||
const int iconSize = 16;
|
||||
const int padding = text->getCharacterSize();
|
||||
const int iconSpace = icon >= 0 ? iconSize + padding : 0;
|
||||
const int paddingOut = 1;
|
||||
const int paddingIn = text->getCharacterSize() / 2;
|
||||
const int iconSpace = icon >= 0 ? iconSize + paddingIn : 0;
|
||||
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
||||
const int width = text->lenght(txt) + (padding * 2) + iconSpace;
|
||||
const int height = (text->getCharacterSize() * 2) + (padding * 2);
|
||||
const int width = text->lenght(txt) + (paddingIn * 2) + iconSpace;
|
||||
const int numTexts = text2 == "" ? 1 : 2;
|
||||
const int height = (text->getCharacterSize() * numTexts) + (paddingIn * 2);
|
||||
const notification_shape_t shape = notification_shape_squared;
|
||||
|
||||
// Posición horizontal
|
||||
int despH = 0;
|
||||
if (options->notification.posH == pos_left)
|
||||
{
|
||||
despH = padding;
|
||||
despH = paddingOut;
|
||||
}
|
||||
else if (options->notification.posH == pos_middle)
|
||||
{
|
||||
@@ -169,21 +172,21 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
}
|
||||
else
|
||||
{
|
||||
despH = options->video.gameWidth - width - padding;
|
||||
despH = options->video.gameWidth - width - paddingOut;
|
||||
}
|
||||
|
||||
// Posición vertical
|
||||
int despV = 0;
|
||||
if (options->notification.posV == pos_top)
|
||||
{
|
||||
despV = padding;
|
||||
despV = paddingOut;
|
||||
}
|
||||
else
|
||||
{
|
||||
despV = options->video.gameHeight - height - padding;
|
||||
despV = options->video.gameHeight - height - paddingOut;
|
||||
}
|
||||
|
||||
const int travelDist = height + padding;
|
||||
const int travelDist = height + paddingOut;
|
||||
|
||||
// Offset
|
||||
int offset = 0;
|
||||
@@ -206,6 +209,7 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
n.state = ns_rising;
|
||||
n.text1 = text1;
|
||||
n.text2 = text2;
|
||||
n.shape = shape;
|
||||
if (options->notification.posV == pos_top)
|
||||
{
|
||||
n.rect = {despH, offset - travelDist, width, height};
|
||||
@@ -226,6 +230,8 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
// Dibuja el fondo de la notificación
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_Rect rect;
|
||||
if (shape == notification_shape_rounded)
|
||||
{
|
||||
rect = {4, 0, width - (4 * 2), height};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
@@ -237,12 +243,19 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
|
||||
rect = {0, 4, width, height - (4 * 2)};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
|
||||
else if (shape == notification_shape_squared)
|
||||
{
|
||||
SDL_RenderClear(renderer);
|
||||
}
|
||||
|
||||
|
||||
// Dibuja el icono de la notificación
|
||||
if (icon >= 0)
|
||||
if (icon >= 0 && numTexts == 2)
|
||||
{
|
||||
Sprite *sp = new Sprite({0, 0, iconSize, iconSize}, iconTexture);
|
||||
sp->setPos({padding, padding, iconSize, iconSize});
|
||||
sp->setPos({paddingIn, paddingIn, iconSize, iconSize});
|
||||
sp->setSpriteClip({iconSize * (icon % 10), iconSize * (icon / 10), iconSize, iconSize});
|
||||
sp->render();
|
||||
delete sp;
|
||||
@@ -250,21 +263,21 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
|
||||
// Escribe el texto de la notificación
|
||||
color_t color = {255, 255, 255};
|
||||
if (text2 != "")
|
||||
if (numTexts == 2)
|
||||
{ // Dos lineas de texto
|
||||
text->writeColored(padding + iconSpace, padding, text1, color);
|
||||
text->writeColored(padding + iconSpace, padding + text->getCharacterSize() + 1, text2, color);
|
||||
text->writeColored(paddingIn + iconSpace, paddingIn, text1, color);
|
||||
text->writeColored(paddingIn + iconSpace, paddingIn + text->getCharacterSize() + 1, text2, color);
|
||||
}
|
||||
else
|
||||
{ // Una linea de texto
|
||||
text->writeColored(padding + iconSpace, (height / 2) - (text->getCharacterSize() / 2), text1, color);
|
||||
text->writeColored(paddingIn + iconSpace, paddingIn, text1, color);
|
||||
}
|
||||
|
||||
// Deja de dibujar en la textura
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
|
||||
// Crea el sprite de la notificación
|
||||
n.sprite = new Sprite(n.rect, n.texture, renderer);
|
||||
n.sprite = new Sprite(n.rect, n.texture);
|
||||
|
||||
// Deja la notificación invisible
|
||||
n.texture->setAlpha(0);
|
||||
|
||||
@@ -34,6 +34,12 @@ private:
|
||||
bottomRight
|
||||
};
|
||||
|
||||
enum notification_shape_t
|
||||
{
|
||||
notification_shape_rounded,
|
||||
notification_shape_squared,
|
||||
};
|
||||
|
||||
struct notification_t
|
||||
{
|
||||
std::string text1;
|
||||
@@ -46,6 +52,7 @@ private:
|
||||
SDL_Rect rect;
|
||||
int y;
|
||||
int travelDist;
|
||||
notification_shape_t shape;
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
|
||||
@@ -37,6 +37,9 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *
|
||||
shakeEffect.origin = 0;
|
||||
attenuateEffect = false;
|
||||
|
||||
// Crea los objetos
|
||||
notify = new Notify(renderer, asset->get("notify.png"), asset->get("8bithud.png"), asset->get("8bithud.txt"), asset->get("notify.wav"), options);
|
||||
|
||||
// Define el color del borde para el modo de pantalla completa
|
||||
borderColor = {0x00, 0x00, 0x00};
|
||||
|
||||
@@ -53,6 +56,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *
|
||||
// Destructor
|
||||
Screen::~Screen()
|
||||
{
|
||||
delete notify;
|
||||
SDL_DestroyTexture(gameCanvas);
|
||||
}
|
||||
|
||||
@@ -232,7 +236,7 @@ void Screen::setVideoMode(int videoMode)
|
||||
// Camibia entre pantalla completa y ventana
|
||||
void Screen::switchVideoMode()
|
||||
{
|
||||
options->video.mode = (options->video.mode == VIDEO_MODE_WINDOW) ? VIDEO_MODE_FULLSCREEN : VIDEO_MODE_WINDOW;
|
||||
options->video.mode = options->video.mode == VIDEO_MODE_WINDOW ? VIDEO_MODE_FULLSCREEN : VIDEO_MODE_WINDOW;
|
||||
setVideoMode(options->video.mode);
|
||||
}
|
||||
|
||||
@@ -309,21 +313,29 @@ void Screen::checkInput()
|
||||
if (input->checkInput(input_window_fullscreen, DO_NOT_ALLOW_REPEAT))
|
||||
{
|
||||
switchVideoMode();
|
||||
const std::string mode = options->video.mode == VIDEO_MODE_WINDOW ? "Window" : "Fullscreen";
|
||||
showNotification(mode + " mode");
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_window_dec_size, DO_NOT_ALLOW_REPEAT))
|
||||
{
|
||||
decWindowSize();
|
||||
const std::string size = std::to_string(options->video.window.size);
|
||||
showNotification("Window size x" + size);
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_window_inc_size, DO_NOT_ALLOW_REPEAT))
|
||||
{
|
||||
incWindowSize();
|
||||
const std::string size = std::to_string(options->video.window.size);
|
||||
showNotification("Window size x" + size);
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_video_shaders, DO_NOT_ALLOW_REPEAT))
|
||||
{
|
||||
switchShaders();
|
||||
const std::string value = options->video.shaders ? "on" : "off";
|
||||
showNotification("Shaders " + value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ bool Director::setFileList()
|
||||
asset->add(prefix + "/data/config/gamecontrollerdb.txt", t_data);
|
||||
|
||||
// Notificaciones
|
||||
asset->add(prefix + "/data/notifications/notify.png", t_bitmap);
|
||||
asset->add(prefix + "/data/notification/notify.png", t_bitmap);
|
||||
|
||||
// Musicas
|
||||
asset->add(prefix + "/data/music/intro.ogg", t_music);
|
||||
@@ -308,8 +308,6 @@ bool Director::setFileList()
|
||||
asset->add(prefix + "/data/sound/hiscore.wav", t_sound);
|
||||
asset->add(prefix + "/data/sound/itemdrop.wav", t_sound);
|
||||
asset->add(prefix + "/data/sound/itempickup.wav", t_sound);
|
||||
asset->add(prefix + "/data/sound/menu_move.wav", t_sound);
|
||||
asset->add(prefix + "/data/sound/menu_select.wav", t_sound);
|
||||
asset->add(prefix + "/data/sound/player_collision.wav", t_sound);
|
||||
asset->add(prefix + "/data/sound/stage_change.wav", t_sound);
|
||||
asset->add(prefix + "/data/sound/title.wav", t_sound);
|
||||
|
||||
@@ -1899,9 +1899,6 @@ void Game::update()
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
if (counter == 0)
|
||||
createPowerBall();
|
||||
|
||||
// Actualiza el contador de juego
|
||||
counter++;
|
||||
|
||||
@@ -2136,6 +2133,7 @@ void Game::checkInput()
|
||||
else if (input->checkInput(input_reset, DO_NOT_ALLOW_REPEAT))
|
||||
{
|
||||
section->name = SECTION_PROG_LOGO;
|
||||
screen->showNotification("Reset");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2615,12 +2613,14 @@ bool Game::allPlayersAreDead()
|
||||
// Comprueba los eventos que hay en cola
|
||||
void Game::checkEvents()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
if (keyStates[SDL_SCANCODE_H] != 0)
|
||||
{
|
||||
createItemScoreSprite(param->gameWidth / 2, param->gameWidth / 2, n1000Sprite);
|
||||
}
|
||||
#endif
|
||||
|
||||
while (SDL_PollEvent(eventHandler) != 0)
|
||||
{
|
||||
|
||||
@@ -68,6 +68,9 @@ void HiScoreTable::update()
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Actualiza el objeto screen
|
||||
screen->update();
|
||||
|
||||
// Actualiza el fondo
|
||||
background->update();
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ void Instructions::iniSprites()
|
||||
for (int i = 0; i < (int)itemTextures.size(); ++i)
|
||||
{
|
||||
Sprite *sprite = new Sprite(0, 0, param->itemSize, param->itemSize, itemTextures[i]);
|
||||
sprite->setPos({spritePos.x, spritePos.y + ((param->itemSize + itemSpace) * i)});
|
||||
sprite->setPos((SDL_Point){spritePos.x, spritePos.y + ((param->itemSize + itemSpace) * i)});
|
||||
sprites.push_back(sprite);
|
||||
}
|
||||
}
|
||||
@@ -229,6 +229,9 @@ void Instructions::update()
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Actualiza el objeto screen
|
||||
screen->update();
|
||||
|
||||
// Incrementa el contador
|
||||
counter++;
|
||||
|
||||
|
||||
@@ -375,6 +375,9 @@ void Intro::update()
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Actualiza el objeto screen
|
||||
screen->update();
|
||||
|
||||
// Actualiza los objetos
|
||||
for (auto bitmap : bitmaps)
|
||||
{
|
||||
|
||||
@@ -244,6 +244,9 @@ void Logo::update()
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Actualiza el objeto screen
|
||||
screen->update();
|
||||
|
||||
// Comprueba las entradas
|
||||
checkInput();
|
||||
|
||||
|
||||
@@ -81,6 +81,9 @@ void Title::update()
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Actualiza el objeto screen
|
||||
screen->update();
|
||||
|
||||
// Actualiza el objeto 'defineButtons'
|
||||
defineButtons->update();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user