68 lines
2.4 KiB
C++
68 lines
2.4 KiB
C++
#include "global_events.hpp"
|
|
|
|
#include <SDL3/SDL.h> // Para SDL_EventType, SDL_Event, SDL_LogInfo, SDL_LogCategory
|
|
|
|
#include <cstddef> // Para size_t
|
|
#include <string> // Para allocator, operator+, string
|
|
#include <vector> // Para vector
|
|
|
|
#include "input.hpp" // Para Input
|
|
#include "lang.hpp" // Para getText
|
|
#include "mouse.hpp" // Para handleEvent
|
|
#include "options.hpp" // Para GamepadManager, gamepad_manager
|
|
#include "screen.hpp" // Para Screen
|
|
#include "section.hpp" // Para Name, Options, name, options
|
|
#include "ui/notifier.hpp" // Para Notifier
|
|
#include "ui/service_menu.hpp" // Para ServiceMenu
|
|
|
|
namespace GlobalEvents {
|
|
// Comprueba los eventos de Input y muestra notificaciones
|
|
void handleInputEvents(const SDL_Event& event) {
|
|
static auto* input_ = Input::get();
|
|
auto message = input_->handleEvent(event);
|
|
|
|
if (message.empty()) {
|
|
return;
|
|
}
|
|
|
|
// Reemplazo de palabras clave por texto localizado
|
|
size_t pos;
|
|
while ((pos = message.find(" CONNECTED")) != std::string::npos) {
|
|
message.replace(pos, std::string(" CONNECTED").length(), " " + Lang::getText("[NOTIFICATIONS] CONNECTED"));
|
|
}
|
|
while ((pos = message.find(" DISCONNECTED")) != std::string::npos) {
|
|
message.replace(pos, std::string(" DISCONNECTED").length(), " " + Lang::getText("[NOTIFICATIONS] DISCONNECTED"));
|
|
}
|
|
|
|
Options::gamepad_manager.assignAndLinkGamepads();
|
|
Options::gamepad_manager.resyncGamepadsWithPlayers();
|
|
Notifier::get()->show({message});
|
|
ServiceMenu::get()->refresh();
|
|
}
|
|
|
|
// Comprueba los eventos que se pueden producir en cualquier sección del juego
|
|
void handle(const SDL_Event& event) {
|
|
switch (event.type) {
|
|
case SDL_EVENT_QUIT: // Evento de salida de la aplicación
|
|
Section::name = Section::Name::QUIT;
|
|
Section::options = Section::Options::NONE;
|
|
return;
|
|
|
|
case SDL_EVENT_RENDER_DEVICE_RESET:
|
|
case SDL_EVENT_RENDER_TARGETS_RESET:
|
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "SDL_RENDER_TARGETS_RESET");
|
|
break;
|
|
|
|
case SDL_EVENT_WINDOW_RESIZED:
|
|
Screen::get()->initShaders();
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
ServiceMenu::get()->handleEvent(event);
|
|
Mouse::handleEvent(event);
|
|
handleInputEvents(event);
|
|
}
|
|
} // namespace GlobalEvents
|