Compare commits
3 Commits
58cacf7bda
...
dfe0a3d4e6
| Author | SHA1 | Date | |
|---|---|---|---|
| dfe0a3d4e6 | |||
| 66c3e0089c | |||
| 86323a0e56 |
@@ -279,3 +279,9 @@ MODE FORA DE LINEA
|
|||||||
|
|
||||||
## 93 - MENU OPCIONES
|
## 93 - MENU OPCIONES
|
||||||
TAULER DE PUNTS
|
TAULER DE PUNTS
|
||||||
|
|
||||||
|
## 94 - NOTIFICACIO COMANDAMENT
|
||||||
|
CONNECTAT
|
||||||
|
|
||||||
|
## 95 - NOTIFICACIO COMANDAMENT
|
||||||
|
DESCONNECTAT
|
||||||
@@ -279,3 +279,9 @@ OFFLINE MODE
|
|||||||
|
|
||||||
## 93 - MENU OPCIONES
|
## 93 - MENU OPCIONES
|
||||||
HISCORE TABLE
|
HISCORE TABLE
|
||||||
|
|
||||||
|
## 94 - GAMEPAD NOTIFICATION
|
||||||
|
CONNECTED
|
||||||
|
|
||||||
|
## 95 - GAMEPAD NOTIFICATION
|
||||||
|
DISCONNECTED
|
||||||
@@ -279,3 +279,9 @@ MODO SIN CONEXION
|
|||||||
|
|
||||||
## 93 - MENU OPCIONES
|
## 93 - MENU OPCIONES
|
||||||
TABLA DE PUNTUACIONES
|
TABLA DE PUNTUACIONES
|
||||||
|
|
||||||
|
## 94 - NOTIFICACION MANDO
|
||||||
|
CONECTADO
|
||||||
|
|
||||||
|
## 95 - NOTIFICACION MANDO
|
||||||
|
DESCONECTADO
|
||||||
@@ -91,6 +91,14 @@ Director::Director(int argc, const char *argv[]) {
|
|||||||
Director::~Director() {
|
Director::~Director() {
|
||||||
saveConfigFile();
|
saveConfigFile();
|
||||||
|
|
||||||
|
// Libera las secciones primero: sus destructores tocan audio/render SDL
|
||||||
|
// (p.ej. Intro::~Intro llama a JA_DeleteMusic) y deben ejecutarse antes
|
||||||
|
// de SDL_Quit().
|
||||||
|
logo.reset();
|
||||||
|
intro.reset();
|
||||||
|
title.reset();
|
||||||
|
game.reset();
|
||||||
|
|
||||||
delete asset;
|
delete asset;
|
||||||
delete input;
|
delete input;
|
||||||
delete screen;
|
delete screen;
|
||||||
@@ -687,6 +695,25 @@ SDL_AppResult Director::handleEvent(SDL_Event *event) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Hot-plug de mandos
|
||||||
|
if (event->type == SDL_EVENT_GAMEPAD_ADDED) {
|
||||||
|
std::string name;
|
||||||
|
if (input->handleGamepadAdded(event->gdevice.which, name)) {
|
||||||
|
screen->notify(name + " " + lang->getText(94),
|
||||||
|
color_t{0x40, 0xFF, 0x40},
|
||||||
|
color_t{0, 0, 0},
|
||||||
|
2500);
|
||||||
|
}
|
||||||
|
} else if (event->type == SDL_EVENT_GAMEPAD_REMOVED) {
|
||||||
|
std::string name;
|
||||||
|
if (input->handleGamepadRemoved(event->gdevice.which, name)) {
|
||||||
|
screen->notify(name + " " + lang->getText(95),
|
||||||
|
color_t{0xFF, 0x50, 0x50},
|
||||||
|
color_t{0, 0, 0},
|
||||||
|
2500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Gestiona la visibilidad del cursor según el movimiento del ratón
|
// Gestiona la visibilidad del cursor según el movimiento del ratón
|
||||||
Mouse::handleEvent(*event, options->videoMode != 0);
|
Mouse::handleEvent(*event, options->videoMode != 0);
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,11 @@ struct section_t;
|
|||||||
constexpr const char *WINDOW_CAPTION = "© 2020 Coffee Crisis — JailDesigner";
|
constexpr const char *WINDOW_CAPTION = "© 2020 Coffee Crisis — JailDesigner";
|
||||||
|
|
||||||
// Secciones activas del Director
|
// Secciones activas del Director
|
||||||
enum class ActiveSection { None, Logo, Intro, Title, Game };
|
enum class ActiveSection { None,
|
||||||
|
Logo,
|
||||||
|
Intro,
|
||||||
|
Title,
|
||||||
|
Game };
|
||||||
|
|
||||||
class Director {
|
class Director {
|
||||||
private:
|
private:
|
||||||
|
|||||||
124
source/input.cpp
124
source/input.cpp
@@ -20,10 +20,24 @@ Input::Input(std::string file) {
|
|||||||
gcb.active = false;
|
gcb.active = false;
|
||||||
gameControllerBindings.resize(input_number_of_inputs, gcb);
|
gameControllerBindings.resize(input_number_of_inputs, gcb);
|
||||||
|
|
||||||
|
numGamepads = 0;
|
||||||
verbose = true;
|
verbose = true;
|
||||||
enabled = true;
|
enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Input::~Input() {
|
||||||
|
for (auto *pad : connectedControllers) {
|
||||||
|
if (pad != nullptr) {
|
||||||
|
SDL_CloseGamepad(pad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connectedControllers.clear();
|
||||||
|
connectedControllerIds.clear();
|
||||||
|
controllerNames.clear();
|
||||||
|
numGamepads = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Actualiza el estado del objeto
|
// Actualiza el estado del objeto
|
||||||
void Input::update() {
|
void Input::update() {
|
||||||
if (disabledUntil == d_keyPressed && !checkAnyInput()) {
|
if (disabledUntil == d_keyPressed && !checkAnyInput()) {
|
||||||
@@ -82,7 +96,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameControllerFound())
|
if (gameControllerFound() && index >= 0 && index < (int)connectedControllers.size())
|
||||||
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY)) {
|
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY)) {
|
||||||
if (repeat) {
|
if (repeat) {
|
||||||
if (SDL_GetGamepadButton(connectedControllers[index], gameControllerBindings[input].button)) {
|
if (SDL_GetGamepadButton(connectedControllers[index], gameControllerBindings[input].button)) {
|
||||||
@@ -128,7 +142,7 @@ bool Input::checkAnyInput(int device, int index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameControllerFound()) {
|
if (gameControllerFound() && index >= 0 && index < (int)connectedControllers.size()) {
|
||||||
if (device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY) {
|
if (device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY) {
|
||||||
for (int i = 0; i < (int)gameControllerBindings.size(); ++i) {
|
for (int i = 0; i < (int)gameControllerBindings.size(); ++i) {
|
||||||
if (SDL_GetGamepadButton(connectedControllers[index], gameControllerBindings[i].button)) {
|
if (SDL_GetGamepadButton(connectedControllers[index], gameControllerBindings[i].button)) {
|
||||||
@@ -141,8 +155,30 @@ bool Input::checkAnyInput(int device, int index) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Busca si hay un mando conectado
|
// Construye el nombre visible de un mando
|
||||||
|
std::string Input::buildControllerName(SDL_Gamepad *pad, int padIndex) {
|
||||||
|
const char *padName = SDL_GetGamepadName(pad);
|
||||||
|
std::string name = padName ? padName : "Unknown";
|
||||||
|
if (name.size() > 25) {
|
||||||
|
name.resize(25);
|
||||||
|
}
|
||||||
|
return name + " #" + std::to_string(padIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Busca si hay un mando conectado. Cierra y limpia el estado previo para
|
||||||
|
// que la función sea idempotente si se invoca más de una vez.
|
||||||
bool Input::discoverGameController() {
|
bool Input::discoverGameController() {
|
||||||
|
// Cierra los mandos ya abiertos y limpia los vectores paralelos
|
||||||
|
for (auto *pad : connectedControllers) {
|
||||||
|
if (pad != nullptr) {
|
||||||
|
SDL_CloseGamepad(pad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connectedControllers.clear();
|
||||||
|
connectedControllerIds.clear();
|
||||||
|
controllerNames.clear();
|
||||||
|
numGamepads = 0;
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
if (SDL_WasInit(SDL_INIT_GAMEPAD) != SDL_INIT_GAMEPAD) {
|
if (SDL_WasInit(SDL_INIT_GAMEPAD) != SDL_INIT_GAMEPAD) {
|
||||||
@@ -157,42 +193,38 @@ bool Input::discoverGameController() {
|
|||||||
|
|
||||||
int nJoysticks = 0;
|
int nJoysticks = 0;
|
||||||
SDL_JoystickID *joysticks = SDL_GetJoysticks(&nJoysticks);
|
SDL_JoystickID *joysticks = SDL_GetJoysticks(&nJoysticks);
|
||||||
numGamepads = 0;
|
|
||||||
|
|
||||||
if (joysticks) {
|
if (joysticks) {
|
||||||
// Cuenta el numero de mandos
|
int gamepadCount = 0;
|
||||||
for (int i = 0; i < nJoysticks; ++i) {
|
for (int i = 0; i < nJoysticks; ++i) {
|
||||||
if (SDL_IsGamepad(joysticks[i])) {
|
if (SDL_IsGamepad(joysticks[i])) {
|
||||||
numGamepads++;
|
gamepadCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
std::cout << "\nChecking for game controllers...\n";
|
std::cout << "\nChecking for game controllers...\n";
|
||||||
std::cout << nJoysticks << " joysticks found, " << numGamepads << " are gamepads\n";
|
std::cout << nJoysticks << " joysticks found, " << gamepadCount << " are gamepads\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numGamepads > 0) {
|
if (gamepadCount > 0) {
|
||||||
found = true;
|
found = true;
|
||||||
int padIndex = 0;
|
int padIndex = 0;
|
||||||
|
|
||||||
for (int i = 0; i < nJoysticks; i++) {
|
for (int i = 0; i < nJoysticks; i++) {
|
||||||
if (!SDL_IsGamepad(joysticks[i])) continue;
|
if (!SDL_IsGamepad(joysticks[i])) continue;
|
||||||
|
|
||||||
// Abre el mando y lo añade a la lista
|
|
||||||
SDL_Gamepad *pad = SDL_OpenGamepad(joysticks[i]);
|
SDL_Gamepad *pad = SDL_OpenGamepad(joysticks[i]);
|
||||||
if (pad != nullptr) {
|
if (pad != nullptr) {
|
||||||
|
const std::string name = buildControllerName(pad, padIndex);
|
||||||
connectedControllers.push_back(pad);
|
connectedControllers.push_back(pad);
|
||||||
const std::string separator(" #");
|
connectedControllerIds.push_back(joysticks[i]);
|
||||||
const char *padName = SDL_GetGamepadName(pad);
|
controllerNames.push_back(name);
|
||||||
std::string name = padName ? padName : "Unknown";
|
numGamepads++;
|
||||||
name.resize(25);
|
padIndex++;
|
||||||
name = name + separator + std::to_string(padIndex);
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
std::cout << name << std::endl;
|
std::cout << name << std::endl;
|
||||||
}
|
}
|
||||||
controllerNames.push_back(name);
|
|
||||||
padIndex++;
|
|
||||||
} else {
|
} else {
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||||
@@ -209,6 +241,66 @@ bool Input::discoverGameController() {
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Procesa un evento SDL_EVENT_GAMEPAD_ADDED
|
||||||
|
bool Input::handleGamepadAdded(SDL_JoystickID jid, std::string &outName) {
|
||||||
|
if (!SDL_IsGamepad(jid)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si el mando ya está registrado no hace nada (ej. evento retroactivo tras el scan inicial)
|
||||||
|
for (SDL_JoystickID existing : connectedControllerIds) {
|
||||||
|
if (existing == jid) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Gamepad *pad = SDL_OpenGamepad(jid);
|
||||||
|
if (pad == nullptr) {
|
||||||
|
if (verbose) {
|
||||||
|
std::cout << "Failed to open gamepad " << jid << ": " << SDL_GetError() << std::endl;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int padIndex = (int)connectedControllers.size();
|
||||||
|
const std::string name = buildControllerName(pad, padIndex);
|
||||||
|
connectedControllers.push_back(pad);
|
||||||
|
connectedControllerIds.push_back(jid);
|
||||||
|
controllerNames.push_back(name);
|
||||||
|
numGamepads++;
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
|
std::cout << "Gamepad connected: " << name << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
outName = name;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Procesa un evento SDL_EVENT_GAMEPAD_REMOVED
|
||||||
|
bool Input::handleGamepadRemoved(SDL_JoystickID jid, std::string &outName) {
|
||||||
|
for (size_t i = 0; i < connectedControllerIds.size(); ++i) {
|
||||||
|
if (connectedControllerIds[i] != jid) continue;
|
||||||
|
|
||||||
|
outName = controllerNames[i];
|
||||||
|
if (connectedControllers[i] != nullptr) {
|
||||||
|
SDL_CloseGamepad(connectedControllers[i]);
|
||||||
|
}
|
||||||
|
connectedControllers.erase(connectedControllers.begin() + i);
|
||||||
|
connectedControllerIds.erase(connectedControllerIds.begin() + i);
|
||||||
|
controllerNames.erase(controllerNames.begin() + i);
|
||||||
|
numGamepads--;
|
||||||
|
if (numGamepads < 0) numGamepads = 0;
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
|
std::cout << "Gamepad disconnected: " << outName << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba si hay algun mando conectado
|
// Comprueba si hay algun mando conectado
|
||||||
bool Input::gameControllerFound() {
|
bool Input::gameControllerFound() {
|
||||||
if (numGamepads > 0) {
|
if (numGamepads > 0) {
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ class Input {
|
|||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
std::vector<SDL_Gamepad *> connectedControllers; // Vector con todos los mandos conectados
|
std::vector<SDL_Gamepad *> connectedControllers; // Vector con todos los mandos conectados
|
||||||
|
std::vector<SDL_JoystickID> connectedControllerIds; // Instance IDs paralelos para mapear eventos
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<keyBindings_t> keyBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
std::vector<keyBindings_t> keyBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
||||||
@@ -69,10 +70,16 @@ class Input {
|
|||||||
i_disable_e disabledUntil; // Tiempo que esta deshabilitado
|
i_disable_e disabledUntil; // Tiempo que esta deshabilitado
|
||||||
bool enabled; // Indica si está habilitado
|
bool enabled; // Indica si está habilitado
|
||||||
|
|
||||||
|
// Construye el nombre visible de un mando (name truncado + sufijo #N)
|
||||||
|
std::string buildControllerName(SDL_Gamepad *pad, int padIndex);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Input(std::string file);
|
Input(std::string file);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Input();
|
||||||
|
|
||||||
// Actualiza el estado del objeto
|
// Actualiza el estado del objeto
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
@@ -91,6 +98,14 @@ class Input {
|
|||||||
// Busca si hay un mando conectado
|
// Busca si hay un mando conectado
|
||||||
bool discoverGameController();
|
bool discoverGameController();
|
||||||
|
|
||||||
|
// Procesa un evento SDL_EVENT_GAMEPAD_ADDED. Devuelve true si el mando se ha añadido
|
||||||
|
// (no estaba ya registrado) y escribe el nombre visible en outName.
|
||||||
|
bool handleGamepadAdded(SDL_JoystickID jid, std::string &outName);
|
||||||
|
|
||||||
|
// Procesa un evento SDL_EVENT_GAMEPAD_REMOVED. Devuelve true si se ha encontrado y
|
||||||
|
// eliminado, y escribe el nombre visible en outName.
|
||||||
|
bool handleGamepadRemoved(SDL_JoystickID jid, std::string &outName);
|
||||||
|
|
||||||
// Comprueba si hay algun mando conectado
|
// Comprueba si hay algun mando conectado
|
||||||
bool gameControllerFound();
|
bool gameControllerFound();
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,9 @@
|
|||||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||||
#include <string> // for basic_string, char_traits, string
|
#include <string> // for basic_string, char_traits, string
|
||||||
|
|
||||||
|
#include "asset.h" // for Asset
|
||||||
#include "mouse.hpp" // for Mouse::cursorVisible, Mouse::lastMouseMoveTime
|
#include "mouse.hpp" // for Mouse::cursorVisible, Mouse::lastMouseMoveTime
|
||||||
class Asset;
|
#include "text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_STROKE
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options) {
|
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options) {
|
||||||
@@ -21,11 +22,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
|||||||
gameCanvasHeight = options->gameHeight;
|
gameCanvasHeight = options->gameHeight;
|
||||||
borderWidth = options->borderWidth * 2;
|
borderWidth = options->borderWidth * 2;
|
||||||
borderHeight = options->borderHeight * 2;
|
borderHeight = options->borderHeight * 2;
|
||||||
notificationLogicalWidth = gameCanvasWidth;
|
|
||||||
notificationLogicalHeight = gameCanvasHeight;
|
|
||||||
|
|
||||||
iniFade();
|
|
||||||
iniSpectrumFade();
|
|
||||||
|
|
||||||
// Define el color del borde para el modo de pantalla completa
|
// Define el color del borde para el modo de pantalla completa
|
||||||
borderColor = {0x00, 0x00, 0x00};
|
borderColor = {0x00, 0x00, 0x00};
|
||||||
@@ -44,12 +40,18 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
|||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
setVideoMode(options->videoMode);
|
setVideoMode(options->videoMode);
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa el sistema de notificaciones
|
||||||
notifyActive = false;
|
notificationText = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
|
||||||
|
notificationMessage = "";
|
||||||
|
notificationTextColor = {0xFF, 0xFF, 0xFF};
|
||||||
|
notificationOutlineColor = {0x00, 0x00, 0x00};
|
||||||
|
notificationEndTime = 0;
|
||||||
|
notificationY = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Screen::~Screen() {
|
Screen::~Screen() {
|
||||||
|
delete notificationText;
|
||||||
SDL_DestroyTexture(gameCanvas);
|
SDL_DestroyTexture(gameCanvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,6 +68,10 @@ void Screen::start() {
|
|||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
void Screen::blit() {
|
void Screen::blit() {
|
||||||
|
// Dibuja la notificación activa sobre el gameCanvas antes de presentar
|
||||||
|
SDL_SetRenderTarget(renderer, gameCanvas);
|
||||||
|
renderNotification();
|
||||||
|
|
||||||
// Vuelve a dejar el renderizador en modo normal
|
// Vuelve a dejar el renderizador en modo normal
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
|
|
||||||
@@ -234,116 +240,31 @@ void Screen::switchBorder() {
|
|||||||
setVideoMode(0);
|
setVideoMode(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activa el fade
|
// Muestra una notificación en la línea superior durante durationMs
|
||||||
void Screen::setFade() {
|
void Screen::notify(const std::string &text, color_t textColor, color_t outlineColor, Uint32 durationMs) {
|
||||||
fade = true;
|
notificationMessage = text;
|
||||||
|
notificationTextColor = textColor;
|
||||||
|
notificationOutlineColor = outlineColor;
|
||||||
|
notificationEndTime = SDL_GetTicks() + durationMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si ha terminado el fade
|
// Limpia la notificación actual
|
||||||
bool Screen::fadeEnded() {
|
void Screen::clearNotification() {
|
||||||
if (fade || fadeCounter > 0) {
|
notificationEndTime = 0;
|
||||||
return false;
|
notificationMessage.clear();
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activa el spectrum fade
|
// Dibuja la notificación activa (si la hay) sobre el gameCanvas
|
||||||
void Screen::setspectrumFade() {
|
void Screen::renderNotification() {
|
||||||
spectrumFade = true;
|
if (SDL_GetTicks() >= notificationEndTime) {
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si ha terminado el spectrum fade
|
|
||||||
bool Screen::spectrumFadeEnded() {
|
|
||||||
if (spectrumFade || spectrumFadeCounter > 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa las variables para el fade
|
|
||||||
void Screen::iniFade() {
|
|
||||||
fade = false;
|
|
||||||
fadeCounter = 0;
|
|
||||||
fadeLenght = 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el fade
|
|
||||||
void Screen::updateFade() {
|
|
||||||
if (!fade) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
notificationText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE,
|
||||||
fadeCounter++;
|
gameCanvasWidth / 2,
|
||||||
if (fadeCounter > fadeLenght) {
|
notificationY,
|
||||||
iniFade();
|
notificationMessage,
|
||||||
}
|
1,
|
||||||
}
|
notificationTextColor,
|
||||||
|
1,
|
||||||
// Dibuja el fade
|
notificationOutlineColor);
|
||||||
void Screen::renderFade() {
|
|
||||||
if (!fade) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SDL_FRect rect = {0, 0, (float)gameCanvasWidth, (float)gameCanvasHeight};
|
|
||||||
color_t color = {0, 0, 0};
|
|
||||||
const float step = (float)fadeCounter / (float)fadeLenght;
|
|
||||||
const int alpha = 0 + (255 - 0) * step;
|
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, alpha);
|
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa las variables para el fade spectrum
|
|
||||||
void Screen::iniSpectrumFade() {
|
|
||||||
spectrumFade = false;
|
|
||||||
spectrumFadeCounter = 0;
|
|
||||||
spectrumFadeLenght = 50;
|
|
||||||
|
|
||||||
spectrumColor.clear();
|
|
||||||
|
|
||||||
// Inicializa el vector de colores
|
|
||||||
const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
|
|
||||||
for (auto v : vColors) {
|
|
||||||
spectrumColor.push_back(stringToColor(options->palette, v));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el spectrum fade
|
|
||||||
void Screen::updateSpectrumFade() {
|
|
||||||
if (!spectrumFade) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
spectrumFadeCounter++;
|
|
||||||
if (spectrumFadeCounter > spectrumFadeLenght) {
|
|
||||||
iniSpectrumFade();
|
|
||||||
SDL_SetTextureColorMod(gameCanvas, 255, 255, 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja el spectrum fade
|
|
||||||
void Screen::renderSpectrumFade() {
|
|
||||||
if (!spectrumFade) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float step = (float)spectrumFadeCounter / (float)spectrumFadeLenght;
|
|
||||||
const int max = spectrumColor.size() - 1;
|
|
||||||
const int index = max + (0 - max) * step;
|
|
||||||
const color_t c = spectrumColor[index];
|
|
||||||
SDL_SetTextureColorMod(gameCanvas, c.r, c.g, c.b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza los efectos
|
|
||||||
void Screen::updateFX() {
|
|
||||||
updateFade();
|
|
||||||
updateSpectrumFade();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja los efectos
|
|
||||||
void Screen::renderFX() {
|
|
||||||
renderFade();
|
|
||||||
renderSpectrumFade();
|
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
#include <vector> // for vector
|
#include <string> // for string
|
||||||
|
|
||||||
#include "utils.h" // for color_t
|
#include "utils.h" // for color_t
|
||||||
class Asset;
|
class Asset;
|
||||||
|
class Text;
|
||||||
|
|
||||||
// Tipos de filtro
|
// Tipos de filtro
|
||||||
constexpr int FILTER_NEAREST = 0;
|
constexpr int FILTER_NEAREST = 0;
|
||||||
@@ -29,36 +30,17 @@ class Screen {
|
|||||||
int borderHeight; // Anltura del borde
|
int borderHeight; // Anltura del borde
|
||||||
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
||||||
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||||
bool notifyActive; // Indica si hay notificaciones activas
|
|
||||||
int notificationLogicalWidth; // Ancho lógico de las notificaciones en relación al tamaño de pantalla
|
|
||||||
int notificationLogicalHeight; // Alto lógico de las notificaciones en relación al tamaño de pantalla
|
|
||||||
|
|
||||||
// Variables - Efectos
|
// Notificaciones - una sola activa, sin apilación ni animaciones
|
||||||
bool fade; // Indica si esta activo el efecto de fade
|
Text *notificationText; // Fuente 8bithud dedicada a las notificaciones
|
||||||
int fadeCounter; // Temporizador para el efecto de fade
|
std::string notificationMessage; // Texto a mostrar
|
||||||
int fadeLenght; // Duración del fade
|
color_t notificationTextColor; // Color del texto
|
||||||
bool spectrumFade; // Indica si esta activo el efecto de fade spectrum
|
color_t notificationOutlineColor; // Color del outline
|
||||||
int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum
|
Uint32 notificationEndTime; // SDL_GetTicks() hasta el cual se muestra
|
||||||
int spectrumFadeLenght; // Duración del fade spectrum
|
int notificationY; // Fila vertical en el canvas virtual
|
||||||
std::vector<color_t> spectrumColor; // Colores para el fade spectrum
|
|
||||||
|
|
||||||
// Inicializa las variables para el fade
|
// Dibuja la notificación activa (si la hay) sobre el gameCanvas
|
||||||
void iniFade();
|
void renderNotification();
|
||||||
|
|
||||||
// Actualiza el fade
|
|
||||||
void updateFade();
|
|
||||||
|
|
||||||
// Dibuja el fade
|
|
||||||
void renderFade();
|
|
||||||
|
|
||||||
// Inicializa las variables para el fade spectrum
|
|
||||||
void iniSpectrumFade();
|
|
||||||
|
|
||||||
// Actualiza el spectrum fade
|
|
||||||
void updateSpectrumFade();
|
|
||||||
|
|
||||||
// Dibuja el spectrum fade
|
|
||||||
void renderSpectrumFade();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -107,21 +89,10 @@ class Screen {
|
|||||||
// Cambia entre borde visible y no visible
|
// Cambia entre borde visible y no visible
|
||||||
void switchBorder();
|
void switchBorder();
|
||||||
|
|
||||||
// Activa el fade
|
// Muestra una notificación en la línea superior del canvas durante durationMs.
|
||||||
void setFade();
|
// Sobrescribe cualquier notificación activa (sin apilación).
|
||||||
|
void notify(const std::string &text, color_t textColor, color_t outlineColor, Uint32 durationMs);
|
||||||
|
|
||||||
// Comprueba si ha terminado el fade
|
// Limpia la notificación actual
|
||||||
bool fadeEnded();
|
void clearNotification();
|
||||||
|
|
||||||
// Activa el spectrum fade
|
|
||||||
void setspectrumFade();
|
|
||||||
|
|
||||||
// Comprueba si ha terminado el spectrum fade
|
|
||||||
bool spectrumFadeEnded();
|
|
||||||
|
|
||||||
// Actualiza los efectos
|
|
||||||
void updateFX();
|
|
||||||
|
|
||||||
// Dibuja los efectos
|
|
||||||
void renderFX();
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1097,12 +1097,13 @@ void Title::createTiledBackground() {
|
|||||||
delete tile;
|
delete tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba cuantos mandos hay conectados para gestionar el menu de opciones
|
// Comprueba cuantos mandos hay conectados para gestionar el menu de opciones.
|
||||||
|
// El estado de Input lo mantiene al día Director via eventos SDL_EVENT_GAMEPAD_ADDED/REMOVED,
|
||||||
|
// así que aquí solo leemos la lista actual sin reescanear.
|
||||||
void Title::checkInputDevices() {
|
void Title::checkInputDevices() {
|
||||||
if (options->console) {
|
if (options->console) {
|
||||||
std::cout << "Filling devices for options menu..." << std::endl;
|
std::cout << "Filling devices for options menu..." << std::endl;
|
||||||
}
|
}
|
||||||
input->discoverGameController();
|
|
||||||
const int numControllers = input->getNumControllers();
|
const int numControllers = input->getNumControllers();
|
||||||
availableInputDevices.clear();
|
availableInputDevices.clear();
|
||||||
input_t temp;
|
input_t temp;
|
||||||
|
|||||||
Reference in New Issue
Block a user