Compare commits
4 Commits
d4e3995d71
...
7b3f82aa34
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b3f82aa34 | |||
| 3a36bf6530 | |||
| 195d812d2a | |||
| fdb85ac393 |
@@ -36,9 +36,11 @@ El joc permet tant l'ús del teclat com d'un comandament. Les tecles per a jugar
|
||||
- **Tecla F1**: Disminueix la mida de la finestra.
|
||||
- **Tecla F2**: Augmenta la mida de la finestra.
|
||||
- **Tecla F3**: Alterna entre el mode de pantalla completa i el mode finestra.
|
||||
- **Tecla F4**: Activa o desactiva els shaders
|
||||
- **Tecla F5**: Canvia la paleta de colors del joc.
|
||||
- **Tecla B**: Activa o desactiva el marge de colors en mode finestra.
|
||||
- **Tecla F4**: Activa o desactiva els shaders.
|
||||
- **Tecla F5**: Estableix la següent paleta de colors.
|
||||
- **Tecla F6**: Estableix la paleta de colors prèvia.
|
||||
- **Tecla F7**: Activa o desactiva el escalat exacte.
|
||||
- **Tecla B**: Activa o desactiva el marge de colors.
|
||||
|
||||

|
||||
|
||||
|
||||
@@ -87,8 +87,10 @@ void Cheevos::unlock(int id)
|
||||
|
||||
// Marcar el logro como completado
|
||||
cheevos_list_.at(INDEX).completed = true;
|
||||
|
||||
// Mostrar notificación en la pantalla
|
||||
Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", cheevos_list_.at(INDEX).caption}, NotificationText::LEFT, cheevos_list_.at(INDEX).icon);
|
||||
Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", cheevos_list_.at(INDEX).caption}, NotificationText::CENTER, CHEEVO_NOTIFICATION_DURATION/*, cheevos_list_.at(INDEX).icon*/);
|
||||
|
||||
// Guardar el estado de los logros
|
||||
saveToFile();
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ Director::Director(int argc, const char *argv[])
|
||||
|
||||
// Crea los objetos
|
||||
Screen::init(window_, renderer_);
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
Resource::init();
|
||||
Notifier::init("", "8bithud");
|
||||
Screen::get()->setNotificationsEnabled(true);
|
||||
@@ -84,7 +85,6 @@ Director::Director(int argc, const char *argv[])
|
||||
initInput();
|
||||
Debug::init();
|
||||
Cheevos::init(Asset::get()->get("cheevos.bin"));
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
}
|
||||
|
||||
Director::~Director()
|
||||
@@ -247,6 +247,7 @@ void Director::initInput()
|
||||
Input::get()->bindKey(InputAction::TOGGLE_SHADERS, SDL_SCANCODE_F4);
|
||||
Input::get()->bindKey(InputAction::NEXT_PALETTE, SDL_SCANCODE_F5);
|
||||
Input::get()->bindKey(InputAction::PREVIOUS_PALETTE, SDL_SCANCODE_F6);
|
||||
Input::get()->bindKey(InputAction::TOGGLE_INTEGER_SCALE, SDL_SCANCODE_F7);
|
||||
Input::get()->bindKey(InputAction::TOGGLE_MUSIC, SDL_SCANCODE_M);
|
||||
Input::get()->bindKey(InputAction::TOGGLE_BORDER, SDL_SCANCODE_B);
|
||||
|
||||
|
||||
@@ -266,17 +266,10 @@ void Game::checkDebugEvents(const SDL_Event &event)
|
||||
changeRoom(room_->getRoom(BORDER_RIGHT));
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F7:
|
||||
Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS"}, NotificationText::LEFT, 3, false, "F7");
|
||||
case SDL_SCANCODE_7:
|
||||
Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS"}, NotificationText::CENTER, CHEEVO_NOTIFICATION_DURATION, -1, false, "F7");
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F8:
|
||||
Notifier::get()->show({"JAILDESIGNER", "IS LOGGED IN"}, NotificationText::LEFT, 4, false);
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F9:
|
||||
Notifier::get()->show({"JAILDESIGNER", "IS LOGGED IN"}, NotificationText::LEFT, 5, false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace globalInputs
|
||||
else
|
||||
{
|
||||
// Si la notificación de salir no está activa, muestra la notificación
|
||||
Notifier::get()->show({code}, NotificationText::CENTER, -1, true, code);
|
||||
Notifier::get()->show({code}, NotificationText::CENTER, 2000, -1, true, code);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,5 +104,13 @@ namespace globalInputs
|
||||
Screen::get()->previousPalette();
|
||||
Notifier::get()->show({"PALETTE " + options.video.palette}, NotificationText::CENTER);
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(InputAction::TOGGLE_INTEGER_SCALE, REPEAT_FALSE))
|
||||
{
|
||||
options.video.integer_scale = !options.video.integer_scale;
|
||||
SDL_RenderSetIntegerScale(Screen::get()->getRenderer(), options.video.integer_scale ? SDL_TRUE : SDL_FALSE);
|
||||
Screen::get()->setVideoMode(options.video.mode);
|
||||
Notifier::get()->show({"INTEGER SCALE " + std::string(options.video.integer_scale ? "ENABLED" : "DISABLED")}, NotificationText::CENTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ enum class InputAction
|
||||
WINDOW_INC_ZOOM,
|
||||
WINDOW_DEC_ZOOM,
|
||||
TOGGLE_VIDEOMODE,
|
||||
TOGGLE_INTEGER_SCALE,
|
||||
TOGGLE_BORDER,
|
||||
TOGGLE_MUSIC,
|
||||
NEXT_PALETTE,
|
||||
|
||||
@@ -39,105 +39,77 @@ Notifier::Notifier(const std::string &icon_file, const std::string &text)
|
||||
: icon_surface_(!icon_file.empty() ? Resource::get()->getSurface(icon_file) : nullptr),
|
||||
text_(Resource::get()->getText(text)),
|
||||
bg_color_(options.notifications.color),
|
||||
wait_time_(150),
|
||||
stack_(false),
|
||||
has_icons_(!icon_file.empty()) {}
|
||||
|
||||
// Dibuja las notificaciones por pantalla
|
||||
void Notifier::render()
|
||||
{
|
||||
for (int i = (int)notifications_.size() - 1; i >= 0; --i)
|
||||
for (auto it = notifications_.rbegin(); it != notifications_.rend(); ++it)
|
||||
{
|
||||
notifications_[i].sprite->render();
|
||||
it->sprite->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado de las notificaiones
|
||||
void Notifier::update()
|
||||
{
|
||||
for (int i = 0; i < (int)notifications_.size(); ++i)
|
||||
for (auto ¬ification : notifications_)
|
||||
{
|
||||
// Si la notificación anterior está "saliendo", no hagas nada
|
||||
if (i > 0)
|
||||
if (!notifications_.empty() && ¬ification != ¬ifications_.front())
|
||||
{
|
||||
if (notifications_[i - 1].state == NotificationStatus::RISING)
|
||||
auto &previous_notification = *(std::prev(¬ification));
|
||||
if (previous_notification.state == NotificationStatus::RISING)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
notifications_[i].counter++;
|
||||
|
||||
// Hace sonar la notificación en el primer frame
|
||||
if (notifications_[i].counter == 1)
|
||||
switch (notification.state)
|
||||
{
|
||||
if (options.notifications.sound)
|
||||
case NotificationStatus::RISING:
|
||||
{
|
||||
const int DIRECTION = (options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? 1 : -1;
|
||||
notification.rect.y += DIRECTION;
|
||||
|
||||
if (notification.rect.y == notification.y)
|
||||
{
|
||||
if (notifications_[i].state == NotificationStatus::RISING)
|
||||
{
|
||||
// Reproduce el sonido de la notificación
|
||||
JA_PlaySound(Resource::get()->getSound("notify.wav"));
|
||||
}
|
||||
notification.state = NotificationStatus::STAY;
|
||||
notification.start_time = SDL_GetTicks();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NotificationStatus::STAY:
|
||||
{
|
||||
notification.elapsed_time = SDL_GetTicks() - notification.start_time;
|
||||
if (notification.elapsed_time >= notification.display_duration)
|
||||
{
|
||||
notification.state = NotificationStatus::VANISHING;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Comprueba los estados
|
||||
if (notifications_[i].state == NotificationStatus::RISING)
|
||||
case NotificationStatus::VANISHING:
|
||||
{
|
||||
// const float step = ((float)notifications_[i].counter / notifications_[i].travel_dist);
|
||||
// const int alpha = 255 * step;
|
||||
// constexpr int ALPHA = 255;
|
||||
const int DIRECTION = (options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? -1 : 1;
|
||||
notification.rect.y += DIRECTION;
|
||||
|
||||
if (options.notifications.getVerticalPosition() == NotificationPosition::TOP)
|
||||
if (notification.rect.y == notification.y - notification.travel_dist)
|
||||
{
|
||||
notifications_[i].rect.y++;
|
||||
}
|
||||
else if (options.notifications.getVerticalPosition() == NotificationPosition::BOTTOM)
|
||||
{
|
||||
notifications_[i].rect.y--;
|
||||
}
|
||||
// notifications_[i].surface->setAlpha(ALPHA);
|
||||
|
||||
if (notifications_[i].rect.y == notifications_[i].y)
|
||||
{
|
||||
notifications_[i].state = NotificationStatus::STAY;
|
||||
// notifications_[i].surface->setAlpha(255);
|
||||
notifications_[i].counter = 0;
|
||||
notification.state = NotificationStatus::FINISHED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
else if (notifications_[i].state == NotificationStatus::STAY)
|
||||
{
|
||||
if (notifications_[i].counter == wait_time_)
|
||||
{
|
||||
notifications_[i].state = NotificationStatus::VANISHING;
|
||||
notifications_[i].counter = 0;
|
||||
}
|
||||
}
|
||||
else if (notifications_[i].state == NotificationStatus::VANISHING)
|
||||
{
|
||||
case NotificationStatus::FINISHED:
|
||||
break;
|
||||
|
||||
// const float step = (notifications_[i].counter / (float)notifications_[i].travel_dist);
|
||||
// const int ALPHA = 255 * (1 - step);
|
||||
// constexpr int ALPHA = 255;
|
||||
|
||||
if (options.notifications.getVerticalPosition() == NotificationPosition::TOP)
|
||||
{
|
||||
notifications_[i].rect.y--;
|
||||
}
|
||||
else if (options.notifications.getVerticalPosition() == NotificationPosition::BOTTOM)
|
||||
{
|
||||
notifications_[i].rect.y++;
|
||||
}
|
||||
// notifications_[i].surface->setAlpha(ALPHA);
|
||||
|
||||
if (notifications_[i].rect.y == notifications_[i].y - notifications_[i].travel_dist)
|
||||
{
|
||||
notifications_[i].state = NotificationStatus::FINISHED;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
notifications_[i].sprite->setPosition(notifications_[i].rect);
|
||||
notification.sprite->setPosition(notification.rect);
|
||||
}
|
||||
|
||||
clearFinishedNotifications();
|
||||
@@ -146,16 +118,16 @@ void Notifier::update()
|
||||
// Elimina las notificaciones finalizadas
|
||||
void Notifier::clearFinishedNotifications()
|
||||
{
|
||||
for (int i = (int)notifications_.size() - 1; i >= 0; --i)
|
||||
{
|
||||
if (notifications_[i].state == NotificationStatus::FINISHED)
|
||||
{
|
||||
notifications_.erase(notifications_.begin() + i);
|
||||
}
|
||||
}
|
||||
notifications_.erase(
|
||||
std::remove_if(notifications_.begin(), notifications_.end(),
|
||||
[](const Notification ¬ification)
|
||||
{
|
||||
return notification.state == NotificationStatus::FINISHED;
|
||||
}),
|
||||
notifications_.end());
|
||||
}
|
||||
|
||||
void Notifier::show(std::vector<std::string> texts, NotificationText text_is, int icon, bool can_be_removed, const std::string &code)
|
||||
void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Uint32 display_duration, int icon, bool can_be_removed, const std::string &code)
|
||||
{
|
||||
// Si no hay texto, acaba
|
||||
if (texts.empty())
|
||||
@@ -179,11 +151,12 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
|
||||
for (const auto &text : texts)
|
||||
{
|
||||
if (text.length() > longest.length())
|
||||
{
|
||||
longest = text;
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
//const int text_size = text_->getCharacterSize();
|
||||
const int text_size = 6;
|
||||
const auto PADDING_IN_H = text_size;
|
||||
const auto PADDING_IN_V = text_size / 2;
|
||||
@@ -194,33 +167,33 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
|
||||
const auto SHAPE = NotificationShape::SQUARED;
|
||||
|
||||
// Posición horizontal
|
||||
auto desp_h = 0;
|
||||
if (options.notifications.getHorizontalPosition() == NotificationPosition::LEFT)
|
||||
int desp_h = 0;
|
||||
switch (options.notifications.getHorizontalPosition())
|
||||
{
|
||||
case NotificationPosition::LEFT:
|
||||
desp_h = PADDING_OUT_;
|
||||
}
|
||||
else if (options.notifications.getHorizontalPosition() == NotificationPosition::CENTER)
|
||||
{
|
||||
break;
|
||||
|
||||
case NotificationPosition::CENTER:
|
||||
desp_h = ((options.game.width / 2) - (WIDTH / 2));
|
||||
}
|
||||
else if (options.notifications.getHorizontalPosition() == NotificationPosition::RIGHT)
|
||||
{
|
||||
break;
|
||||
|
||||
case NotificationPosition::RIGHT:
|
||||
desp_h = options.game.width - WIDTH - PADDING_OUT_;
|
||||
break;
|
||||
|
||||
default:
|
||||
desp_h = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// Posición vertical
|
||||
const int DESP_V = (options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? PADDING_OUT_ : options.game.height - HEIGHT - PADDING_OUT_;
|
||||
|
||||
// Offset
|
||||
const auto TRAVEL_DIST = HEIGHT + PADDING_OUT_;
|
||||
auto offset = 0;
|
||||
if (options.notifications.getVerticalPosition() == NotificationPosition::TOP)
|
||||
{
|
||||
offset = !notifications_.empty() ? notifications_.back().y + notifications_.back().travel_dist : DESP_V;
|
||||
}
|
||||
else if (options.notifications.getVerticalPosition() == NotificationPosition::BOTTOM)
|
||||
{
|
||||
offset = !notifications_.empty() ? notifications_.back().y - notifications_.back().travel_dist : DESP_V;
|
||||
}
|
||||
const int TRAVEL_MOD = (options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? 1 : -1;
|
||||
const int OFFSET = !notifications_.empty() ? notifications_.back().y + TRAVEL_MOD * notifications_.back().travel_dist : DESP_V;
|
||||
|
||||
// Crea la notificacion
|
||||
Notification n;
|
||||
@@ -228,12 +201,13 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
|
||||
// Inicializa variables
|
||||
n.code = code;
|
||||
n.can_be_removed = can_be_removed;
|
||||
n.y = offset;
|
||||
n.y = OFFSET;
|
||||
n.travel_dist = TRAVEL_DIST;
|
||||
n.texts = texts;
|
||||
n.shape = SHAPE;
|
||||
int y_pos = offset + ((options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? -TRAVEL_DIST : TRAVEL_DIST);
|
||||
n.rect = {desp_h, y_pos, WIDTH, HEIGHT};
|
||||
n.display_duration = display_duration;
|
||||
const int Y_POS = OFFSET + ((options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? -TRAVEL_DIST : TRAVEL_DIST);
|
||||
n.rect = {desp_h, Y_POS, WIDTH, HEIGHT};
|
||||
|
||||
// Crea la textura
|
||||
n.surface = std::make_shared<Surface>(WIDTH, HEIGHT);
|
||||
@@ -303,6 +277,9 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
|
||||
|
||||
// Añade la notificación a la lista
|
||||
notifications_.emplace_back(n);
|
||||
|
||||
// Reproduce el sonido de la notificación
|
||||
JA_PlaySound(Resource::get()->getSound("notify.wav"));
|
||||
}
|
||||
|
||||
// Indica si hay notificaciones activas
|
||||
|
||||
@@ -9,6 +9,11 @@ class SSprite; // lines 9-9
|
||||
class Text; // lines 10-10
|
||||
class Surface; // lines 11-11
|
||||
|
||||
// Constantes
|
||||
constexpr Uint32 DEFAULT_NOTIFICATION_DURATION = 2000;
|
||||
constexpr Uint32 CHEEVO_NOTIFICATION_DURATION = 4000;
|
||||
|
||||
// Justificado para las notificaciones
|
||||
enum class NotificationText
|
||||
{
|
||||
LEFT,
|
||||
@@ -41,24 +46,39 @@ private:
|
||||
|
||||
struct Notification
|
||||
{
|
||||
std::shared_ptr<Surface> surface;
|
||||
std::shared_ptr<SSprite> sprite;
|
||||
std::vector<std::string> texts;
|
||||
int counter;
|
||||
NotificationStatus state;
|
||||
NotificationShape shape;
|
||||
SDL_Rect rect;
|
||||
int y;
|
||||
int travel_dist;
|
||||
std::string code; // Permite asignar un código a la notificación
|
||||
bool can_be_removed;
|
||||
int height;
|
||||
std::shared_ptr<Surface> surface; // Superficie asociada a la notificación
|
||||
std::shared_ptr<SSprite> sprite; // Sprite asociado para gráficos o animaciones
|
||||
std::vector<std::string> texts; // Lista de textos incluidos en la notificación
|
||||
NotificationStatus state; // Estado actual de la notificación (RISING, SHOWING, etc.)
|
||||
NotificationShape shape; // Forma de la notificación (ej. SQUARED o ROUNDED)
|
||||
SDL_Rect rect; // Dimensiones y posición de la notificación en pantalla
|
||||
int y; // Posición actual en el eje Y
|
||||
int travel_dist; // Distancia a recorrer (por ejemplo, en animaciones)
|
||||
std::string code; // Código identificador único para esta notificación
|
||||
bool can_be_removed; // Indica si la notificación puede ser eliminada
|
||||
int height; // Altura de la notificación
|
||||
Uint32 start_time; // Momento en que se creó la notificación
|
||||
Uint32 elapsed_time; // Tiempo transcurrido desde la creación
|
||||
Uint32 display_duration; // Duración total para mostrar la notificación
|
||||
|
||||
// Constructor
|
||||
explicit Notification()
|
||||
: surface(nullptr), sprite(nullptr), texts(), counter(0), state(NotificationStatus::RISING),
|
||||
shape(NotificationShape::SQUARED), rect{0, 0, 0, 0}, y(0), travel_dist(0), code(""),
|
||||
can_be_removed(true), height(0) {}
|
||||
: surface(nullptr), // Inicializar superficie como nula
|
||||
sprite(nullptr), // Inicializar sprite como nulo
|
||||
texts(), // Inicializar lista de textos vacía
|
||||
state(NotificationStatus::RISING), // Estado inicial como "RISING"
|
||||
shape(NotificationShape::SQUARED), // Forma inicial como "SQUARED"
|
||||
rect{0, 0, 0, 0}, // Rectángulo inicial vacío
|
||||
y(0), // Posición Y inicializada a 0
|
||||
travel_dist(0), // Distancia inicializada a 0
|
||||
code(""), // Código identificador vacío
|
||||
can_be_removed(true), // Inicialmente se puede eliminar
|
||||
height(0), // Altura inicializada a 0
|
||||
start_time(0), // Tiempo de creación inicializado a 0
|
||||
elapsed_time(0), // Tiempo transcurrido inicializado a 0
|
||||
display_duration(0) // Duración inicializada a 0
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
std::shared_ptr<Surface> icon_surface_; // Textura para los iconos de las notificaciones
|
||||
@@ -66,7 +86,6 @@ private:
|
||||
|
||||
// Variables
|
||||
Uint8 bg_color_; // Color de fondo de las notificaciones
|
||||
int wait_time_; // Tiempo que se ve la notificación
|
||||
std::vector<Notification> notifications_; // La lista de notificaciones activas
|
||||
bool stack_; // Indica si las notificaciones se apilan
|
||||
bool has_icons_; // Indica si el notificador tiene textura para iconos
|
||||
@@ -102,7 +121,7 @@ public:
|
||||
void update();
|
||||
|
||||
// Muestra una notificación de texto por pantalla
|
||||
void show(std::vector<std::string> texts, NotificationText text_is = NotificationText::LEFT, int icon = -1, bool can_be_removed = true, const std::string &code = std::string());
|
||||
void show(std::vector<std::string> texts, NotificationText text_is = NotificationText::LEFT, Uint32 display_duration = DEFAULT_NOTIFICATION_DURATION, int icon = -1, bool can_be_removed = true, const std::string &code = std::string());
|
||||
|
||||
// Indica si hay notificaciones activas
|
||||
bool isActive();
|
||||
|
||||
Reference in New Issue
Block a user