reorganitzat GlobalInputs
This commit is contained in:
@@ -13,20 +13,29 @@
|
|||||||
#include "utils/utils.hpp" // Para stringInVector
|
#include "utils/utils.hpp" // Para stringInVector
|
||||||
|
|
||||||
namespace GlobalInputs {
|
namespace GlobalInputs {
|
||||||
void quit() {
|
|
||||||
|
// Funciones internas
|
||||||
|
namespace {
|
||||||
|
void handleQuit() {
|
||||||
const std::string CODE = SceneManager::current == SceneManager::Scene::GAME ? "PRESS AGAIN TO RETURN TO MENU" : "PRESS AGAIN TO EXIT";
|
const std::string CODE = SceneManager::current == SceneManager::Scene::GAME ? "PRESS AGAIN TO RETURN TO MENU" : "PRESS AGAIN TO EXIT";
|
||||||
auto code_found = stringInVector(Notifier::get()->getCodes(), CODE);
|
auto code_found = stringInVector(Notifier::get()->getCodes(), CODE);
|
||||||
if (code_found) {
|
if (code_found) {
|
||||||
// Si la notificación de salir está activa, cambia de sección
|
// Si la notificación de salir está activa, cambia de sección
|
||||||
SceneManager::current = SceneManager::current == SceneManager::Scene::GAME ? SceneManager::Scene::TITLE : SceneManager::Scene::QUIT;
|
switch (SceneManager::current) {
|
||||||
|
case SceneManager::Scene::GAME:
|
||||||
|
SceneManager::current = SceneManager::Scene::TITLE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
SceneManager::current = SceneManager::Scene::QUIT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Si la notificación de salir no está activa, muestra la notificación
|
// Si la notificación de salir no está activa, muestra la notificación
|
||||||
Notifier::get()->show({CODE}, NotificationText::CENTER, 2000, -1, true, CODE);
|
Notifier::get()->show({CODE}, NotificationText::CENTER, 2000, -1, true, CODE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia de seccion
|
void handleSkipSection() {
|
||||||
void skipSection() {
|
|
||||||
switch (SceneManager::current) {
|
switch (SceneManager::current) {
|
||||||
case SceneManager::Scene::LOGO:
|
case SceneManager::Scene::LOGO:
|
||||||
case SceneManager::Scene::LOADING_SCREEN:
|
case SceneManager::Scene::LOADING_SCREEN:
|
||||||
@@ -44,61 +53,150 @@ void skipSection() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handleToggleBorder() {
|
||||||
|
Screen::get()->toggleBorder();
|
||||||
|
Notifier::get()->show({"BORDER " + std::string(Options::video.border.enabled ? "ENABLED" : "DISABLED")}, NotificationText::CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleToggleVideoMode() {
|
||||||
|
Screen::get()->toggleVideoMode();
|
||||||
|
Notifier::get()->show({"FULLSCREEN " + std::string(static_cast<int>(Options::video.fullscreen) == 0 ? "DISABLED" : "ENABLED")}, NotificationText::CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleDecWindowZoom() {
|
||||||
|
if (Screen::get()->decWindowZoom()) {
|
||||||
|
Notifier::get()->show({"WINDOW ZOOM x" + std::to_string(Options::window.zoom)}, NotificationText::CENTER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleIncWindowZoom() {
|
||||||
|
if (Screen::get()->incWindowZoom()) {
|
||||||
|
Notifier::get()->show({"WINDOW ZOOM x" + std::to_string(Options::window.zoom)}, NotificationText::CENTER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleToggleShaders() {
|
||||||
|
Screen::get()->toggleShaders();
|
||||||
|
Notifier::get()->show({"SHADERS " + std::string(Options::video.shaders ? "ENABLED" : "DISABLED")}, NotificationText::CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleNextPalette() {
|
||||||
|
Screen::get()->nextPalette();
|
||||||
|
Notifier::get()->show({"PALETTE " + Options::video.palette}, NotificationText::CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handlePreviousPalette() {
|
||||||
|
Screen::get()->previousPalette();
|
||||||
|
Notifier::get()->show({"PALETTE " + Options::video.palette}, NotificationText::CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleToggleIntegerScale() {
|
||||||
|
Screen::get()->toggleIntegerScale();
|
||||||
|
Screen::get()->setVideoMode(Options::video.fullscreen);
|
||||||
|
Notifier::get()->show({"INTEGER SCALE " + std::string(Options::video.integer_scale ? "ENABLED" : "DISABLED")}, NotificationText::CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleShowDebugInfo() {
|
||||||
|
Screen::get()->toggleDebugInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detecta qué acción global ha sido presionada (si alguna)
|
||||||
|
InputAction getPressedAction() {
|
||||||
|
if (Input::get()->checkAction(InputAction::EXIT, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||||
|
return InputAction::EXIT;
|
||||||
|
}
|
||||||
|
if (Input::get()->checkAction(InputAction::ACCEPT, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||||
|
return InputAction::ACCEPT;
|
||||||
|
}
|
||||||
|
if (Input::get()->checkAction(InputAction::TOGGLE_BORDER, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||||
|
return InputAction::TOGGLE_BORDER;
|
||||||
|
}
|
||||||
|
if (Input::get()->checkAction(InputAction::TOGGLE_VIDEOMODE, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||||
|
return InputAction::TOGGLE_VIDEOMODE;
|
||||||
|
}
|
||||||
|
if (Input::get()->checkAction(InputAction::WINDOW_DEC_ZOOM, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||||
|
return InputAction::WINDOW_DEC_ZOOM;
|
||||||
|
}
|
||||||
|
if (Input::get()->checkAction(InputAction::WINDOW_INC_ZOOM, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||||
|
return InputAction::WINDOW_INC_ZOOM;
|
||||||
|
}
|
||||||
|
if (Input::get()->checkAction(InputAction::TOGGLE_SHADERS, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||||
|
return InputAction::TOGGLE_SHADERS;
|
||||||
|
}
|
||||||
|
if (Input::get()->checkAction(InputAction::NEXT_PALETTE, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||||
|
return InputAction::NEXT_PALETTE;
|
||||||
|
}
|
||||||
|
if (Input::get()->checkAction(InputAction::PREVIOUS_PALETTE, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||||
|
return InputAction::PREVIOUS_PALETTE;
|
||||||
|
}
|
||||||
|
if (Input::get()->checkAction(InputAction::TOGGLE_INTEGER_SCALE, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||||
|
return InputAction::TOGGLE_INTEGER_SCALE;
|
||||||
|
}
|
||||||
|
if (Input::get()->checkAction(InputAction::SHOW_DEBUG_INFO, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||||
|
return InputAction::SHOW_DEBUG_INFO;
|
||||||
|
}
|
||||||
|
return InputAction::NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
// Funciones públicas
|
||||||
|
|
||||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||||
void handle() {
|
void handle() {
|
||||||
if (Input::get()->checkAction(InputAction::EXIT, Input::DO_NOT_ALLOW_REPEAT)) {
|
// Detectar qué acción global está siendo presionada
|
||||||
quit();
|
InputAction action = getPressedAction();
|
||||||
}
|
|
||||||
|
|
||||||
else if (Input::get()->checkAction(InputAction::ACCEPT, Input::DO_NOT_ALLOW_REPEAT)) {
|
// Ejecutar el handler correspondiente usando switch statement
|
||||||
skipSection();
|
switch (action) {
|
||||||
}
|
case InputAction::EXIT:
|
||||||
|
handleQuit();
|
||||||
|
break;
|
||||||
|
|
||||||
else if (Input::get()->checkAction(InputAction::TOGGLE_BORDER, Input::DO_NOT_ALLOW_REPEAT)) {
|
case InputAction::ACCEPT:
|
||||||
Screen::get()->toggleBorder();
|
handleSkipSection();
|
||||||
Notifier::get()->show({"BORDER " + std::string(Options::video.border.enabled ? "ENABLED" : "DISABLED")}, NotificationText::CENTER);
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
else if (Input::get()->checkAction(InputAction::TOGGLE_VIDEOMODE, Input::DO_NOT_ALLOW_REPEAT)) {
|
case InputAction::TOGGLE_BORDER:
|
||||||
Screen::get()->toggleVideoMode();
|
handleToggleBorder();
|
||||||
Notifier::get()->show({"FULLSCREEN " + std::string(static_cast<int>(Options::video.fullscreen) == 0 ? "DISABLED" : "ENABLED")}, NotificationText::CENTER);
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
else if (Input::get()->checkAction(InputAction::WINDOW_DEC_ZOOM, Input::DO_NOT_ALLOW_REPEAT)) {
|
case InputAction::TOGGLE_VIDEOMODE:
|
||||||
if (Screen::get()->decWindowZoom()) {
|
handleToggleVideoMode();
|
||||||
Notifier::get()->show({"WINDOW ZOOM x" + std::to_string(Options::window.zoom)}, NotificationText::CENTER);
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (Input::get()->checkAction(InputAction::WINDOW_INC_ZOOM, Input::DO_NOT_ALLOW_REPEAT)) {
|
case InputAction::WINDOW_DEC_ZOOM:
|
||||||
if (Screen::get()->incWindowZoom()) {
|
handleDecWindowZoom();
|
||||||
Notifier::get()->show({"WINDOW ZOOM x" + std::to_string(Options::window.zoom)}, NotificationText::CENTER);
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (Input::get()->checkAction(InputAction::TOGGLE_SHADERS, Input::DO_NOT_ALLOW_REPEAT)) {
|
case InputAction::WINDOW_INC_ZOOM:
|
||||||
Screen::get()->toggleShaders();
|
handleIncWindowZoom();
|
||||||
Notifier::get()->show({"SHADERS " + std::string(Options::video.shaders ? "ENABLED" : "DISABLED")}, NotificationText::CENTER);
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
else if (Input::get()->checkAction(InputAction::NEXT_PALETTE, Input::DO_NOT_ALLOW_REPEAT)) {
|
case InputAction::TOGGLE_SHADERS:
|
||||||
Screen::get()->nextPalette();
|
handleToggleShaders();
|
||||||
Notifier::get()->show({"PALETTE " + Options::video.palette}, NotificationText::CENTER);
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
else if (Input::get()->checkAction(InputAction::PREVIOUS_PALETTE, Input::DO_NOT_ALLOW_REPEAT)) {
|
case InputAction::NEXT_PALETTE:
|
||||||
Screen::get()->previousPalette();
|
handleNextPalette();
|
||||||
Notifier::get()->show({"PALETTE " + Options::video.palette}, NotificationText::CENTER);
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
else if (Input::get()->checkAction(InputAction::TOGGLE_INTEGER_SCALE, Input::DO_NOT_ALLOW_REPEAT)) {
|
case InputAction::PREVIOUS_PALETTE:
|
||||||
Screen::get()->toggleIntegerScale();
|
handlePreviousPalette();
|
||||||
Screen::get()->setVideoMode(Options::video.fullscreen);
|
break;
|
||||||
Notifier::get()->show({"INTEGER SCALE " + std::string(Options::video.integer_scale ? "ENABLED" : "DISABLED")}, NotificationText::CENTER);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (Input::get()->checkAction(InputAction::SHOW_DEBUG_INFO, Input::DO_NOT_ALLOW_REPEAT)) {
|
case InputAction::TOGGLE_INTEGER_SCALE:
|
||||||
Screen::get()->toggleDebugInfo();
|
handleToggleIntegerScale();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case InputAction::SHOW_DEBUG_INFO:
|
||||||
|
handleShowDebugInfo();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case InputAction::NONE:
|
||||||
|
default:
|
||||||
|
// No se presionó ninguna acción global
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace GlobalInputs
|
} // namespace GlobalInputs
|
||||||
Reference in New Issue
Block a user