migrant input: ja funcionen coses, pero encara queda
This commit is contained in:
@@ -97,6 +97,11 @@ void Director::init() {
|
|||||||
Resource::init(); // Inicializa el sistema de gestión de recursos
|
Resource::init(); // Inicializa el sistema de gestión de recursos
|
||||||
Input::init(Asset::get()->get("gamecontrollerdb.txt")); // Carga configuración de controles
|
Input::init(Asset::get()->get("gamecontrollerdb.txt")); // Carga configuración de controles
|
||||||
bindInputs(); // Asigna los controles a la entrada del sistema
|
bindInputs(); // Asigna los controles a la entrada del sistema
|
||||||
|
|
||||||
|
auto gamepads = Input::get()->getGamepads();
|
||||||
|
if (!gamepads.empty())
|
||||||
|
Options::controllers.front().gamepad = gamepads.front();
|
||||||
|
|
||||||
ServiceMenu::init(); // Inicializa el menú de servicio
|
ServiceMenu::init(); // Inicializa el menú de servicio
|
||||||
Notifier::init(std::string(), Resource::get()->getText("8bithud")); // Inicialización del sistema de notificaciones
|
Notifier::init(std::string(), Resource::get()->getText("8bithud")); // Inicialización del sistema de notificaciones
|
||||||
Screen::get()->getSingletons(); // Obtiene los punteros al resto de singletones
|
Screen::get()->getSingletons(); // Obtiene los punteros al resto de singletones
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ void incWindowSize() {
|
|||||||
// Comprueba el boton de servicio
|
// Comprueba el boton de servicio
|
||||||
auto checkServiceButton() -> bool {
|
auto checkServiceButton() -> bool {
|
||||||
// Teclado
|
// Teclado
|
||||||
if (Input::get()->checkAction(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
toggleServiceMenu();
|
toggleServiceMenu();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -172,7 +172,7 @@ auto checkServiceButton() -> bool {
|
|||||||
{
|
{
|
||||||
auto gamepads = Input::get()->getGamepads();
|
auto gamepads = Input::get()->getGamepads();
|
||||||
for (auto gamepad : gamepads) {
|
for (auto gamepad : gamepads) {
|
||||||
if (Input::get()->checkAction(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
if (Input::get()->checkAction(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||||
toggleServiceMenu();
|
toggleServiceMenu();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -190,37 +190,37 @@ auto checkServiceInputs() -> bool {
|
|||||||
// Teclado
|
// Teclado
|
||||||
{
|
{
|
||||||
// Arriba
|
// Arriba
|
||||||
if (Input::get()->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
ServiceMenu::get()->setSelectorUp();
|
ServiceMenu::get()->setSelectorUp();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Abajo
|
// Abajo
|
||||||
if (Input::get()->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
ServiceMenu::get()->setSelectorDown();
|
ServiceMenu::get()->setSelectorDown();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Derecha
|
// Derecha
|
||||||
if (Input::get()->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
ServiceMenu::get()->adjustOption(true);
|
ServiceMenu::get()->adjustOption(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Izquierda
|
// Izquierda
|
||||||
if (Input::get()->checkAction(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
ServiceMenu::get()->adjustOption(false);
|
ServiceMenu::get()->adjustOption(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aceptar
|
// Aceptar
|
||||||
if (Input::get()->checkAction(Input::Action::SM_SELECT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::SM_SELECT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
ServiceMenu::get()->selectOption();
|
ServiceMenu::get()->selectOption();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Atras
|
// Atras
|
||||||
if (Input::get()->checkAction(Input::Action::SM_BACK, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::SM_BACK, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
ServiceMenu::get()->moveBack();
|
ServiceMenu::get()->moveBack();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -231,37 +231,37 @@ auto checkServiceInputs() -> bool {
|
|||||||
auto gamepads = Input::get()->getGamepads();
|
auto gamepads = Input::get()->getGamepads();
|
||||||
for (auto gamepad : gamepads) {
|
for (auto gamepad : gamepads) {
|
||||||
// Arriba
|
// Arriba
|
||||||
if (Input::get()->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
if (Input::get()->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||||
ServiceMenu::get()->setSelectorUp();
|
ServiceMenu::get()->setSelectorUp();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Abajo
|
// Abajo
|
||||||
if (Input::get()->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
if (Input::get()->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||||
ServiceMenu::get()->setSelectorDown();
|
ServiceMenu::get()->setSelectorDown();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Derecha
|
// Derecha
|
||||||
if (Input::get()->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
if (Input::get()->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||||
ServiceMenu::get()->adjustOption(true);
|
ServiceMenu::get()->adjustOption(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Izquierda
|
// Izquierda
|
||||||
if (Input::get()->checkAction(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
if (Input::get()->checkAction(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||||
ServiceMenu::get()->adjustOption(false);
|
ServiceMenu::get()->adjustOption(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aceptar
|
// Aceptar
|
||||||
if (Input::get()->checkAction(Input::Action::SM_SELECT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
if (Input::get()->checkAction(Input::Action::SM_SELECT, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||||
ServiceMenu::get()->selectOption();
|
ServiceMenu::get()->selectOption();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Atras
|
// Atras
|
||||||
if (Input::get()->checkAction(Input::Action::SM_BACK, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
if (Input::get()->checkAction(Input::Action::SM_BACK, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||||
ServiceMenu::get()->moveBack();
|
ServiceMenu::get()->moveBack();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -275,7 +275,7 @@ auto checkInputs() -> bool {
|
|||||||
// Teclado
|
// Teclado
|
||||||
{
|
{
|
||||||
// Comprueba el teclado para cambiar entre pantalla completa y ventana
|
// Comprueba el teclado para cambiar entre pantalla completa y ventana
|
||||||
if (Input::get()->checkAction(Input::Action::WINDOW_FULLSCREEN, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::WINDOW_FULLSCREEN, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
Screen::get()->toggleFullscreen();
|
Screen::get()->toggleFullscreen();
|
||||||
const std::string MODE = Options::video.fullscreen ? Lang::getText("[NOTIFICATIONS] 11") : Lang::getText("[NOTIFICATIONS] 10");
|
const std::string MODE = Options::video.fullscreen ? Lang::getText("[NOTIFICATIONS] 11") : Lang::getText("[NOTIFICATIONS] 10");
|
||||||
Notifier::get()->show({MODE});
|
Notifier::get()->show({MODE});
|
||||||
@@ -283,7 +283,7 @@ auto checkInputs() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el teclado para decrementar el tamaño de la ventana
|
// Comprueba el teclado para decrementar el tamaño de la ventana
|
||||||
if (Input::get()->checkAction(Input::Action::WINDOW_DEC_SIZE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::WINDOW_DEC_SIZE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
if (Screen::get()->decWindowSize()) {
|
if (Screen::get()->decWindowSize()) {
|
||||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
|
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
|
||||||
}
|
}
|
||||||
@@ -291,7 +291,7 @@ auto checkInputs() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el teclado para incrementar el tamaño de la ventana
|
// Comprueba el teclado para incrementar el tamaño de la ventana
|
||||||
if (Input::get()->checkAction(Input::Action::WINDOW_INC_SIZE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::WINDOW_INC_SIZE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
if (Screen::get()->incWindowSize()) {
|
if (Screen::get()->incWindowSize()) {
|
||||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
|
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
|
||||||
}
|
}
|
||||||
@@ -299,7 +299,7 @@ auto checkInputs() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Salir
|
// Salir
|
||||||
if (Input::get()->checkAction(Input::Action::EXIT, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::EXIT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
quit();
|
quit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -311,50 +311,50 @@ auto checkInputs() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reset
|
// Reset
|
||||||
if (Input::get()->checkAction(Input::Action::RESET, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::RESET, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
reset();
|
reset();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Audio
|
// Audio
|
||||||
if (Input::get()->checkAction(Input::Action::TOGGLE_AUDIO, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::TOGGLE_AUDIO, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
toggleAudio();
|
toggleAudio();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Autofire
|
// Autofire
|
||||||
if (Input::get()->checkAction(Input::Action::TOGGLE_AUTO_FIRE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::TOGGLE_AUTO_FIRE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
toggleFireMode();
|
toggleFireMode();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Idioma
|
// Idioma
|
||||||
if (Input::get()->checkAction(Input::Action::CHANGE_LANG, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::CHANGE_LANG, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
changeLang();
|
changeLang();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shaders
|
// Shaders
|
||||||
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_SHADERS, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_SHADERS, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
toggleShaders();
|
toggleShaders();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Integer Scale
|
// Integer Scale
|
||||||
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_INTEGER_SCALE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_INTEGER_SCALE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
toggleIntegerScale();
|
toggleIntegerScale();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// VSync
|
// VSync
|
||||||
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_VSYNC, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_VSYNC, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
toggleVSync();
|
toggleVSync();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
// Debug info
|
// Debug info
|
||||||
if (Input::get()->checkAction(Input::Action::SHOW_INFO, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (Input::get()->checkAction(Input::Action::SHOW_INFO, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
Screen::get()->toggleDebugInfo();
|
Screen::get()->toggleDebugInfo();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,11 +51,11 @@ void Input::bindGameControllerButton(std::shared_ptr<Gamepad> gamepad, Action in
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si un input esta activo
|
// Comprueba si un input esta activo
|
||||||
auto Input::checkAction(Action action, bool repeat, Device device, std::shared_ptr<Gamepad> gamepad) -> bool {
|
auto Input::checkAction(Action action, bool repeat, bool check_keyboard, std::shared_ptr<Gamepad> gamepad) -> bool {
|
||||||
bool success_keyboard = false;
|
bool success_keyboard = false;
|
||||||
bool success_controller = false;
|
bool success_controller = false;
|
||||||
|
|
||||||
if (device == Device::KEYBOARD || device == Device::ANY) {
|
if (check_keyboard) {
|
||||||
if (repeat) { // El usuario quiere saber si está pulsada (estado mantenido)
|
if (repeat) { // El usuario quiere saber si está pulsada (estado mantenido)
|
||||||
success_keyboard = keyboard_.bindings[action].is_held;
|
success_keyboard = keyboard_.bindings[action].is_held;
|
||||||
} else { // El usuario quiere saber si ACABA de ser pulsada (evento de un solo fotograma)
|
} else { // El usuario quiere saber si ACABA de ser pulsada (evento de un solo fotograma)
|
||||||
@@ -64,7 +64,6 @@ auto Input::checkAction(Action action, bool repeat, Device device, std::shared_p
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (gamepad != nullptr) {
|
if (gamepad != nullptr) {
|
||||||
if ((device == Device::CONTROLLER) || (device == Device::ANY)) {
|
|
||||||
success_controller = checkAxisInput(action, gamepad, repeat);
|
success_controller = checkAxisInput(action, gamepad, repeat);
|
||||||
|
|
||||||
if (!success_controller) {
|
if (!success_controller) {
|
||||||
@@ -75,17 +74,16 @@ auto Input::checkAction(Action action, bool repeat, Device device, std::shared_p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return (success_keyboard || success_controller);
|
return (success_keyboard || success_controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si hay almenos un input activo
|
// Comprueba si hay almenos un input activo
|
||||||
auto Input::checkAnyInput(Device device, std::shared_ptr<Gamepad> gamepad) -> bool {
|
auto Input::checkAnyInput(bool check_keyboard, std::shared_ptr<Gamepad> gamepad) -> bool {
|
||||||
// Obtenemos el número total de acciones posibles para iterar sobre ellas.
|
// Obtenemos el número total de acciones posibles para iterar sobre ellas.
|
||||||
|
|
||||||
// --- Comprobación del Teclado ---
|
// --- Comprobación del Teclado ---
|
||||||
if (device == Device::KEYBOARD || device == Device::ANY) {
|
if (check_keyboard) {
|
||||||
for (const auto &pair : keyboard_.bindings) {
|
for (const auto &pair : keyboard_.bindings) {
|
||||||
// Simplemente leemos el estado pre-calculado por Input::update().
|
// Simplemente leemos el estado pre-calculado por Input::update().
|
||||||
// Ya no se llama a SDL_GetKeyboardState ni se modifica el estado '.active'.
|
// Ya no se llama a SDL_GetKeyboardState ni se modifica el estado '.active'.
|
||||||
@@ -98,7 +96,6 @@ auto Input::checkAnyInput(Device device, std::shared_ptr<Gamepad> gamepad) -> bo
|
|||||||
// --- Comprobación del Mando ---
|
// --- Comprobación del Mando ---
|
||||||
// Comprobamos si hay mandos y si el índice solicitado es válido.
|
// Comprobamos si hay mandos y si el índice solicitado es válido.
|
||||||
if (gamepad != nullptr) {
|
if (gamepad != nullptr) {
|
||||||
if (device == Device::CONTROLLER || device == Device::ANY) {
|
|
||||||
// Iteramos sobre todas las acciones, no sobre el número de mandos.
|
// Iteramos sobre todas las acciones, no sobre el número de mandos.
|
||||||
for (const auto &pair : gamepad->bindings) {
|
for (const auto &pair : gamepad->bindings) {
|
||||||
// Leemos el estado pre-calculado para el mando y la acción específicos.
|
// Leemos el estado pre-calculado para el mando y la acción específicos.
|
||||||
@@ -107,7 +104,6 @@ auto Input::checkAnyInput(Device device, std::shared_ptr<Gamepad> gamepad) -> bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Si llegamos hasta aquí, no se detectó ninguna nueva pulsación.
|
// Si llegamos hasta aquí, no se detectó ninguna nueva pulsación.
|
||||||
return false;
|
return false;
|
||||||
@@ -118,13 +114,13 @@ auto Input::checkAnyButton(bool repeat) -> bool {
|
|||||||
// Solo comprueba los botones definidos previamente
|
// Solo comprueba los botones definidos previamente
|
||||||
for (auto bi : button_inputs_) {
|
for (auto bi : button_inputs_) {
|
||||||
// Comprueba el teclado
|
// Comprueba el teclado
|
||||||
if (checkAction(bi, repeat, Device::KEYBOARD)) {
|
if (checkAction(bi, repeat, CHECK_KEYBOARD)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los mandos
|
// Comprueba los mandos
|
||||||
for (auto gamepad : gamepads_) {
|
for (auto gamepad : gamepads_) {
|
||||||
if (checkAction(bi, repeat, Device::CONTROLLER, gamepad)) {
|
if (checkAction(bi, repeat, DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ class Input {
|
|||||||
static constexpr bool ALLOW_REPEAT = true;
|
static constexpr bool ALLOW_REPEAT = true;
|
||||||
static constexpr bool DO_NOT_ALLOW_REPEAT = false;
|
static constexpr bool DO_NOT_ALLOW_REPEAT = false;
|
||||||
|
|
||||||
|
static constexpr bool CHECK_KEYBOARD = true;
|
||||||
|
static constexpr bool DO_NOT_CHECK_KEYBOARD = false;
|
||||||
|
|
||||||
// Acciones de entrada posibles en el juego
|
// Acciones de entrada posibles en el juego
|
||||||
enum class Action : int {
|
enum class Action : int {
|
||||||
// Inputs de movimiento
|
// Inputs de movimiento
|
||||||
@@ -66,13 +69,6 @@ class Input {
|
|||||||
SIZE,
|
SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Tipos de dispositivos de entrada
|
|
||||||
enum class Device : int {
|
|
||||||
KEYBOARD = 0,
|
|
||||||
CONTROLLER = 1,
|
|
||||||
ANY = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- Estructuras ---
|
// --- Estructuras ---
|
||||||
struct KeyState {
|
struct KeyState {
|
||||||
Uint8 scancode; // Scancode asociado
|
Uint8 scancode; // Scancode asociado
|
||||||
@@ -98,29 +94,41 @@ class Input {
|
|||||||
|
|
||||||
Keyboard()
|
Keyboard()
|
||||||
: bindings{
|
: bindings{
|
||||||
|
// Teclado - Movimiento del jugador
|
||||||
{Input::Action::UP, KeyState(SDL_SCANCODE_UP)},
|
{Input::Action::UP, KeyState(SDL_SCANCODE_UP)},
|
||||||
{Input::Action::DOWN, KeyState(SDL_SCANCODE_DOWN)},
|
{Input::Action::DOWN, KeyState(SDL_SCANCODE_DOWN)},
|
||||||
{Input::Action::LEFT, KeyState(SDL_SCANCODE_LEFT)},
|
{Input::Action::LEFT, KeyState(SDL_SCANCODE_LEFT)},
|
||||||
{Input::Action::RIGHT, KeyState(SDL_SCANCODE_RIGHT)},
|
{Input::Action::RIGHT, KeyState(SDL_SCANCODE_RIGHT)},
|
||||||
|
|
||||||
|
// Teclado - Disparo del jugador
|
||||||
{Input::Action::FIRE_LEFT, KeyState(SDL_SCANCODE_Q)},
|
{Input::Action::FIRE_LEFT, KeyState(SDL_SCANCODE_Q)},
|
||||||
{Input::Action::FIRE_CENTER, KeyState(SDL_SCANCODE_W)},
|
{Input::Action::FIRE_CENTER, KeyState(SDL_SCANCODE_W)},
|
||||||
{Input::Action::FIRE_RIGHT, KeyState(SDL_SCANCODE_E)},
|
{Input::Action::FIRE_RIGHT, KeyState(SDL_SCANCODE_E)},
|
||||||
|
|
||||||
|
// Teclado - Interfaz
|
||||||
{Input::Action::START, KeyState(SDL_SCANCODE_RETURN)},
|
{Input::Action::START, KeyState(SDL_SCANCODE_RETURN)},
|
||||||
|
|
||||||
|
// Teclado - Menu de servicio
|
||||||
{Input::Action::SERVICE, KeyState(SDL_SCANCODE_0)},
|
{Input::Action::SERVICE, KeyState(SDL_SCANCODE_0)},
|
||||||
{Input::Action::SM_SELECT, KeyState(SDL_SCANCODE_RETURN)},
|
{Input::Action::SM_SELECT, KeyState(SDL_SCANCODE_RETURN)},
|
||||||
{Input::Action::SM_BACK, KeyState(SDL_SCANCODE_BACKSPACE)},
|
{Input::Action::SM_BACK, KeyState(SDL_SCANCODE_BACKSPACE)},
|
||||||
|
|
||||||
|
// Teclado - Control del programa
|
||||||
{Input::Action::EXIT, KeyState(SDL_SCANCODE_ESCAPE)},
|
{Input::Action::EXIT, KeyState(SDL_SCANCODE_ESCAPE)},
|
||||||
{Input::Action::PAUSE, KeyState(SDL_SCANCODE_P)},
|
{Input::Action::PAUSE, KeyState(SDL_SCANCODE_P)},
|
||||||
{Input::Action::BACK, KeyState(SDL_SCANCODE_BACKSPACE)},
|
{Input::Action::BACK, KeyState(SDL_SCANCODE_BACKSPACE)},
|
||||||
|
|
||||||
{Input::Action::WINDOW_DEC_SIZE, KeyState(SDL_SCANCODE_F1)},
|
{Input::Action::WINDOW_DEC_SIZE, KeyState(SDL_SCANCODE_F1)},
|
||||||
{Input::Action::WINDOW_INC_SIZE, KeyState(SDL_SCANCODE_F2)},
|
{Input::Action::WINDOW_INC_SIZE, KeyState(SDL_SCANCODE_F2)},
|
||||||
{Input::Action::WINDOW_FULLSCREEN, KeyState(SDL_SCANCODE_F3)},
|
{Input::Action::WINDOW_FULLSCREEN, KeyState(SDL_SCANCODE_F3)},
|
||||||
{Input::Action::TOGGLE_VIDEO_SHADERS, KeyState(SDL_SCANCODE_F4)},
|
{Input::Action::TOGGLE_VIDEO_SHADERS, KeyState(SDL_SCANCODE_F4)},
|
||||||
{Input::Action::TOGGLE_VIDEO_INTEGER_SCALE, KeyState(SDL_SCANCODE_F5)},
|
{Input::Action::TOGGLE_VIDEO_INTEGER_SCALE, KeyState(SDL_SCANCODE_F5)},
|
||||||
{Input::Action::TOGGLE_VIDEO_VSYNC, KeyState(SDL_SCANCODE_F6)},
|
{Input::Action::TOGGLE_VIDEO_VSYNC, KeyState(SDL_SCANCODE_F6)},
|
||||||
|
|
||||||
{Input::Action::TOGGLE_AUDIO, KeyState(SDL_SCANCODE_F7)},
|
{Input::Action::TOGGLE_AUDIO, KeyState(SDL_SCANCODE_F7)},
|
||||||
{Input::Action::TOGGLE_AUTO_FIRE, KeyState(SDL_SCANCODE_F8)},
|
{Input::Action::TOGGLE_AUTO_FIRE, KeyState(SDL_SCANCODE_F8)},
|
||||||
{Input::Action::CHANGE_LANG, KeyState(SDL_SCANCODE_F9)},
|
{Input::Action::CHANGE_LANG, KeyState(SDL_SCANCODE_F9)},
|
||||||
|
|
||||||
{Input::Action::RESET, KeyState(SDL_SCANCODE_F10)},
|
{Input::Action::RESET, KeyState(SDL_SCANCODE_F10)},
|
||||||
{Input::Action::SHOW_INFO, KeyState(SDL_SCANCODE_F12)}} {}
|
{Input::Action::SHOW_INFO, KeyState(SDL_SCANCODE_F12)}} {}
|
||||||
};
|
};
|
||||||
@@ -136,9 +144,18 @@ class Input {
|
|||||||
instance_id(SDL_GetJoystickID(SDL_GetGamepadJoystick(gamepad))),
|
instance_id(SDL_GetJoystickID(SDL_GetGamepadJoystick(gamepad))),
|
||||||
name(std::string(SDL_GetGamepadName(gamepad)) + " #" + std::to_string(instance_id)),
|
name(std::string(SDL_GetGamepadName(gamepad)) + " #" + std::to_string(instance_id)),
|
||||||
bindings{
|
bindings{
|
||||||
|
// Mando - Movimiento del jugador
|
||||||
|
{Input::Action::UP, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_UP)},
|
||||||
|
{Input::Action::DOWN, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_DOWN)},
|
||||||
|
{Input::Action::LEFT, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_LEFT)},
|
||||||
|
{Input::Action::RIGHT, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_RIGHT)},
|
||||||
|
|
||||||
|
// Mando - Disparo del jugador
|
||||||
{Input::Action::FIRE_LEFT, ButtonState(SDL_GAMEPAD_BUTTON_WEST)},
|
{Input::Action::FIRE_LEFT, ButtonState(SDL_GAMEPAD_BUTTON_WEST)},
|
||||||
{Input::Action::FIRE_CENTER, ButtonState(SDL_GAMEPAD_BUTTON_NORTH)},
|
{Input::Action::FIRE_CENTER, ButtonState(SDL_GAMEPAD_BUTTON_NORTH)},
|
||||||
{Input::Action::FIRE_RIGHT, ButtonState(SDL_GAMEPAD_BUTTON_EAST)},
|
{Input::Action::FIRE_RIGHT, ButtonState(SDL_GAMEPAD_BUTTON_EAST)},
|
||||||
|
|
||||||
|
// Mando - Interfaz
|
||||||
{Input::Action::START, ButtonState(SDL_GAMEPAD_BUTTON_START)},
|
{Input::Action::START, ButtonState(SDL_GAMEPAD_BUTTON_START)},
|
||||||
{Input::Action::SERVICE, ButtonState(SDL_GAMEPAD_BUTTON_BACK)}} {}
|
{Input::Action::SERVICE, ButtonState(SDL_GAMEPAD_BUTTON_BACK)}} {}
|
||||||
|
|
||||||
@@ -161,8 +178,8 @@ class Input {
|
|||||||
|
|
||||||
// --- Métodos de consulta de entrada ---
|
// --- Métodos de consulta de entrada ---
|
||||||
void update(); // Comprueba fisicamente los botones y teclas que se han pulsado
|
void update(); // Comprueba fisicamente los botones y teclas que se han pulsado
|
||||||
auto checkAction(Action input, bool repeat = true, Device device = Device::ANY, std::shared_ptr<Gamepad> gamepad = nullptr) -> bool; // Comprueba si un input está activo
|
auto checkAction(Action input, bool repeat = true, bool check_keyboard = true, std::shared_ptr<Gamepad> gamepad = nullptr) -> bool; // Comprueba si un input está activo
|
||||||
auto checkAnyInput(Device device = Device::ANY, std::shared_ptr<Gamepad> gamepad = nullptr) -> bool; // Comprueba si hay al menos un input activo
|
auto checkAnyInput(bool check_keyboard = true, std::shared_ptr<Gamepad> gamepad = nullptr) -> bool; // Comprueba si hay al menos un input activo
|
||||||
auto checkAnyButton(bool repeat = DO_NOT_ALLOW_REPEAT) -> bool; // Comprueba si hay algún botón pulsado
|
auto checkAnyButton(bool repeat = DO_NOT_ALLOW_REPEAT) -> bool; // Comprueba si hay algún botón pulsado
|
||||||
|
|
||||||
// --- Métodos de gestión de mandos ---
|
// --- Métodos de gestión de mandos ---
|
||||||
|
|||||||
0
source/jail_shader.cpp
Normal file
0
source/jail_shader.cpp
Normal file
@@ -159,7 +159,6 @@ auto saveToFile() -> bool {
|
|||||||
file << "\n";
|
file << "\n";
|
||||||
file << "controller." << controller_index << ".name=" << controller.name << "\n";
|
file << "controller." << controller_index << ".name=" << controller.name << "\n";
|
||||||
file << "controller." << controller_index << ".player=" << controller.player_id << "\n";
|
file << "controller." << controller_index << ".player=" << controller.player_id << "\n";
|
||||||
file << "controller." << controller_index << ".type=" << static_cast<int>(controller.type) << "\n";
|
|
||||||
|
|
||||||
// Incrementa el índice
|
// Incrementa el índice
|
||||||
++controller_index;
|
++controller_index;
|
||||||
@@ -186,8 +185,6 @@ void parseAndSetController(const std::string& var, const std::string& value) {
|
|||||||
controller.name = value;
|
controller.name = value;
|
||||||
} else if (setting_key == "player") {
|
} else if (setting_key == "player") {
|
||||||
controller.player_id = std::clamp(std::stoi(value), 1, 2);
|
controller.player_id = std::clamp(std::stoi(value), 1, 2);
|
||||||
} else if (setting_key == "type") {
|
|
||||||
controller.type = static_cast<Input::Device>(std::stoi(value));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,31 +257,31 @@ auto set(const std::string& var, const std::string& value) -> bool {
|
|||||||
void setKeyboardToPlayer(int player_id) {
|
void setKeyboardToPlayer(int player_id) {
|
||||||
for (auto& controller : controllers) {
|
for (auto& controller : controllers) {
|
||||||
if (controller.player_id == player_id) {
|
if (controller.player_id == player_id) {
|
||||||
controller.type = Input::Device::ANY;
|
// controller.type = Input::Device::ANY;
|
||||||
} else {
|
} else {
|
||||||
controller.type = Input::Device::CONTROLLER;
|
// controller.type = Input::Device::CONTROLLER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Intercambia el teclado de jugador
|
// Intercambia el teclado de jugador
|
||||||
void swapKeyboard() {
|
void swapKeyboard() {
|
||||||
std::swap(controllers.at(0).type, controllers.at(1).type);
|
// std::swap(controllers.at(0).type, controllers.at(1).type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||||
void swapControllers() {
|
void swapControllers() {
|
||||||
std::swap(controllers.at(0).player_id, controllers.at(1).player_id);
|
std::swap(controllers.at(0).player_id, controllers.at(1).player_id);
|
||||||
std::swap(controllers.at(0).type, controllers.at(1).type);
|
// std::swap(controllers.at(0).type, controllers.at(1).type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Averigua quien está usando el teclado
|
// Averigua quien está usando el teclado
|
||||||
auto getPlayerWhoUsesKeyboard() -> int {
|
auto getPlayerWhoUsesKeyboard() -> int {
|
||||||
for (const auto& controller : controllers) {
|
// for (const auto& controller : controllers) {
|
||||||
if (controller.type == Input::Device::ANY) {
|
// if (controller.type == Input::Device::ANY) {
|
||||||
return controller.player_id;
|
// return controller.player_id;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ struct GamepadOptions {
|
|||||||
std::shared_ptr<Input::Gamepad> gamepad = nullptr; // Referencia al mando
|
std::shared_ptr<Input::Gamepad> gamepad = nullptr; // Referencia al mando
|
||||||
std::string name; // Nombre del mando
|
std::string name; // Nombre del mando
|
||||||
int player_id; // Jugador asociado al mando
|
int player_id; // Jugador asociado al mando
|
||||||
Input::Device type = Input::Device::CONTROLLER; // Tipo de dispositivo
|
|
||||||
|
|
||||||
GamepadOptions(int custom_player_id = INVALID_INDEX)
|
GamepadOptions(int custom_player_id = INVALID_INDEX)
|
||||||
: player_id(custom_player_id) {}
|
: player_id(custom_player_id) {}
|
||||||
|
|||||||
@@ -165,6 +165,12 @@ class Player {
|
|||||||
void setWalkingState(State state) { walking_state_ = state; }
|
void setWalkingState(State state) { walking_state_ = state; }
|
||||||
void addCredit() { ++credits_used_; }
|
void addCredit() { ++credits_used_; }
|
||||||
|
|
||||||
|
// Setter y getter para gamepad_
|
||||||
|
void setGamepad(std::shared_ptr<Input::Gamepad> gamepad) { gamepad_ = gamepad; }
|
||||||
|
[[nodiscard]] std::shared_ptr<Input::Gamepad> getGamepad() const { return gamepad_; }
|
||||||
|
void setUsesKeyboard(bool value) { uses_keyboard_ = value; }
|
||||||
|
[[nodiscard]] bool getUsesKeyboard() const { return uses_keyboard_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// --- Constantes ---
|
// --- Constantes ---
|
||||||
static constexpr int POWERUP_COUNTER = 1500; // Duración del estado PowerUp
|
static constexpr int POWERUP_COUNTER = 1500; // Duración del estado PowerUp
|
||||||
@@ -221,9 +227,7 @@ class Player {
|
|||||||
std::string last_enter_name_; // Último nombre introducido en la tabla de puntuaciones
|
std::string last_enter_name_; // Último nombre introducido en la tabla de puntuaciones
|
||||||
int waiting_counter_ = 0; // Contador para el estado de espera
|
int waiting_counter_ = 0; // Contador para el estado de espera
|
||||||
std::shared_ptr<Input::Gamepad> gamepad_ = nullptr; // Dispositivo asociado
|
std::shared_ptr<Input::Gamepad> gamepad_ = nullptr; // Dispositivo asociado
|
||||||
// Setter y getter para gamepad_
|
bool uses_keyboard_ = false; // Indica si usa el teclado como dispositivo de control
|
||||||
void setGamepad(std::shared_ptr<Input::Gamepad> gamepad) { gamepad_ = gamepad; }
|
|
||||||
[[nodiscard]] std::shared_ptr<Input::Gamepad> getGamepad() const { return gamepad_; }
|
|
||||||
|
|
||||||
// --- Métodos internos ---
|
// --- Métodos internos ---
|
||||||
void shiftColliders(); // Actualiza el círculo de colisión a la posición del jugador
|
void shiftColliders(); // Actualiza el círculo de colisión a la posición del jugador
|
||||||
|
|||||||
@@ -1250,14 +1250,14 @@ void Game::checkPauseInput() {
|
|||||||
// Comprueba los mandos
|
// Comprueba los mandos
|
||||||
auto gamepads = input_->getGamepads();
|
auto gamepads = input_->getGamepads();
|
||||||
for (auto gamepad : gamepads) {
|
for (auto gamepad : gamepads) {
|
||||||
if (input_->checkAction(Input::Action::PAUSE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, gamepad)) {
|
if (input_->checkAction(Input::Action::PAUSE, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||||
pause(!paused_);
|
pause(!paused_);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el teclado
|
// Comprueba el teclado
|
||||||
if (input_->checkAction(Input::Action::PAUSE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
|
if (input_->checkAction(Input::Action::PAUSE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||||
pause(!paused_);
|
pause(!paused_);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1366,14 +1366,12 @@ void Game::handlePlayersInput() {
|
|||||||
|
|
||||||
// Maneja las entradas de movimiento y disparo para un jugador en modo normal.
|
// Maneja las entradas de movimiento y disparo para un jugador en modo normal.
|
||||||
void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player) {
|
void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player) {
|
||||||
const auto &controller = Options::controllers.at(0);
|
if (input_->checkAction(Input::Action::LEFT, Input::ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
|
|
||||||
if (input_->checkAction(Input::Action::LEFT, Input::ALLOW_REPEAT, controller.type, controller.gamepad)) {
|
|
||||||
player->setInput(Input::Action::LEFT);
|
player->setInput(Input::Action::LEFT);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo_.keys.left = 1;
|
demo_.keys.left = 1;
|
||||||
#endif
|
#endif
|
||||||
} else if (input_->checkAction(Input::Action::RIGHT, Input::ALLOW_REPEAT, controller.type, controller.gamepad)) {
|
} else if (input_->checkAction(Input::Action::RIGHT, Input::ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
player->setInput(Input::Action::RIGHT);
|
player->setInput(Input::Action::RIGHT);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo_.keys.right = 1;
|
demo_.keys.right = 1;
|
||||||
@@ -1391,18 +1389,17 @@ void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player) {
|
|||||||
|
|
||||||
// Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado.
|
// Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado.
|
||||||
void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire) {
|
void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire) {
|
||||||
const auto CONTROLLER = Options::controllers.at(0);
|
if (input_->checkAction(Input::Action::FIRE_CENTER, autofire, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
if (input_->checkAction(Input::Action::FIRE_CENTER, autofire, CONTROLLER.type, CONTROLLER.gamepad)) {
|
|
||||||
handleFireInput(player, BulletType::UP);
|
handleFireInput(player, BulletType::UP);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo_.keys.fire = 1;
|
demo_.keys.fire = 1;
|
||||||
#endif
|
#endif
|
||||||
} else if (input_->checkAction(Input::Action::FIRE_LEFT, autofire, CONTROLLER.type, CONTROLLER.gamepad)) {
|
} else if (input_->checkAction(Input::Action::FIRE_LEFT, autofire, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
handleFireInput(player, BulletType::LEFT);
|
handleFireInput(player, BulletType::LEFT);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo_.keys.fire_left = 1;
|
demo_.keys.fire_left = 1;
|
||||||
#endif
|
#endif
|
||||||
} else if (input_->checkAction(Input::Action::FIRE_RIGHT, autofire, CONTROLLER.type, CONTROLLER.gamepad)) {
|
} else if (input_->checkAction(Input::Action::FIRE_RIGHT, autofire, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
handleFireInput(player, BulletType::RIGHT);
|
handleFireInput(player, BulletType::RIGHT);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo_.keys.fire_right = 1;
|
demo_.keys.fire_right = 1;
|
||||||
@@ -1412,17 +1409,16 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire
|
|||||||
|
|
||||||
// Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
|
// Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
|
||||||
void Game::handlePlayerContinueInput(const std::shared_ptr<Player> &player) {
|
void Game::handlePlayerContinueInput(const std::shared_ptr<Player> &player) {
|
||||||
const auto CONTROLLER = Options::controllers.at(0);
|
if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
|
||||||
player->setPlayingState(Player::State::RESPAWNING);
|
player->setPlayingState(Player::State::RESPAWNING);
|
||||||
player->addCredit();
|
player->addCredit();
|
||||||
sendPlayerToTheFront(player);
|
sendPlayerToTheFront(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disminuye el contador de continuación si se presiona cualquier botón de disparo.
|
// Disminuye el contador de continuación si se presiona cualquier botón de disparo.
|
||||||
if (input_->checkAction(Input::Action::FIRE_LEFT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad) ||
|
if (input_->checkAction(Input::Action::FIRE_LEFT, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad()) ||
|
||||||
input_->checkAction(Input::Action::FIRE_CENTER, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad) ||
|
input_->checkAction(Input::Action::FIRE_CENTER, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad()) ||
|
||||||
input_->checkAction(Input::Action::FIRE_RIGHT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
input_->checkAction(Input::Action::FIRE_RIGHT, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
if (player->getContinueCounter() < param.scoreboard.skip_countdown_value) {
|
if (player->getContinueCounter() < param.scoreboard.skip_countdown_value) {
|
||||||
player->decContinueCounter();
|
player->decContinueCounter();
|
||||||
}
|
}
|
||||||
@@ -1431,8 +1427,7 @@ void Game::handlePlayerContinueInput(const std::shared_ptr<Player> &player) {
|
|||||||
|
|
||||||
// Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
|
// Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
|
||||||
void Game::handlePlayerWaitingInput(const std::shared_ptr<Player> &player) {
|
void Game::handlePlayerWaitingInput(const std::shared_ptr<Player> &player) {
|
||||||
const auto CONTROLLER = Options::controllers.at(0);
|
if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
|
||||||
player->setPlayingState(Player::State::ENTERING_SCREEN);
|
player->setPlayingState(Player::State::ENTERING_SCREEN);
|
||||||
player->addCredit();
|
player->addCredit();
|
||||||
sendPlayerToTheFront(player);
|
sendPlayerToTheFront(player);
|
||||||
@@ -1441,8 +1436,7 @@ void Game::handlePlayerWaitingInput(const std::shared_ptr<Player> &player) {
|
|||||||
|
|
||||||
// Procesa las entradas para la introducción del nombre del jugador.
|
// Procesa las entradas para la introducción del nombre del jugador.
|
||||||
void Game::handleNameInput(const std::shared_ptr<Player> &player) {
|
void Game::handleNameInput(const std::shared_ptr<Player> &player) {
|
||||||
const auto CONTROLLER = Options::controllers.at(0);
|
if (input_->checkAction(Input::Action::FIRE_LEFT, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
if (input_->checkAction(Input::Action::FIRE_LEFT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
|
||||||
if (player->isShowingName()) {
|
if (player->isShowingName()) {
|
||||||
player->setPlayingState(Player::State::CONTINUE);
|
player->setPlayingState(Player::State::CONTINUE);
|
||||||
} else if (player->getEnterNamePositionOverflow()) {
|
} else if (player->getEnterNamePositionOverflow()) {
|
||||||
@@ -1452,18 +1446,18 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player) {
|
|||||||
} else {
|
} else {
|
||||||
player->setInput(Input::Action::RIGHT);
|
player->setInput(Input::Action::RIGHT);
|
||||||
}
|
}
|
||||||
} else if (input_->checkAction(Input::Action::FIRE_CENTER, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad) ||
|
} else if (input_->checkAction(Input::Action::FIRE_CENTER, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad()) ||
|
||||||
input_->checkAction(Input::Action::FIRE_RIGHT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
input_->checkAction(Input::Action::FIRE_RIGHT, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
if (player->isShowingName()) {
|
if (player->isShowingName()) {
|
||||||
player->setPlayingState(Player::State::CONTINUE);
|
player->setPlayingState(Player::State::CONTINUE);
|
||||||
} else {
|
} else {
|
||||||
player->setInput(Input::Action::LEFT);
|
player->setInput(Input::Action::LEFT);
|
||||||
}
|
}
|
||||||
} else if (input_->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
} else if (input_->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
player->setInput(Input::Action::UP);
|
player->setInput(Input::Action::UP);
|
||||||
} else if (input_->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
} else if (input_->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
player->setInput(Input::Action::DOWN);
|
player->setInput(Input::Action::DOWN);
|
||||||
} else if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.gamepad)) {
|
} else if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
if (player->isShowingName()) {
|
if (player->isShowingName()) {
|
||||||
player->setPlayingState(Player::State::CONTINUE);
|
player->setPlayingState(Player::State::CONTINUE);
|
||||||
} else {
|
} else {
|
||||||
@@ -1594,14 +1588,16 @@ void Game::initPlayers(int player_id) {
|
|||||||
players_.emplace_back(std::make_unique<Player>(1, param.game.play_area.first_quarter_x - (Player::WIDTH / 2), Y, demo_.enabled, param.game.play_area.rect, player_textures_.at(0), player_animations_));
|
players_.emplace_back(std::make_unique<Player>(1, param.game.play_area.first_quarter_x - (Player::WIDTH / 2), Y, demo_.enabled, param.game.play_area.rect, player_textures_.at(0), player_animations_));
|
||||||
players_.back()->setScoreBoardPanel(Scoreboard::Id::LEFT);
|
players_.back()->setScoreBoardPanel(Scoreboard::Id::LEFT);
|
||||||
players_.back()->setName(Lang::getText("[SCOREBOARD] 1"));
|
players_.back()->setName(Lang::getText("[SCOREBOARD] 1"));
|
||||||
players_.back()->setController(getController(players_.back()->getId()));
|
//players_.back()->setController(getController(players_.back()->getId()));
|
||||||
|
players_.back()->setGamepad(Options::controllers.front().gamepad);
|
||||||
|
players_.back()->setUsesKeyboard(true);
|
||||||
players_.back()->setPlayingState(Player::State::WAITING);
|
players_.back()->setPlayingState(Player::State::WAITING);
|
||||||
|
|
||||||
// Crea al jugador dos y lo pone en modo espera
|
// Crea al jugador dos y lo pone en modo espera
|
||||||
players_.emplace_back(std::make_unique<Player>(2, param.game.play_area.third_quarter_x - (Player::WIDTH / 2), Y, demo_.enabled, param.game.play_area.rect, player_textures_.at(1), player_animations_));
|
players_.emplace_back(std::make_unique<Player>(2, param.game.play_area.third_quarter_x - (Player::WIDTH / 2), Y, demo_.enabled, param.game.play_area.rect, player_textures_.at(1), player_animations_));
|
||||||
players_.back()->setScoreBoardPanel(Scoreboard::Id::RIGHT);
|
players_.back()->setScoreBoardPanel(Scoreboard::Id::RIGHT);
|
||||||
players_.back()->setName(Lang::getText("[SCOREBOARD] 2"));
|
players_.back()->setName(Lang::getText("[SCOREBOARD] 2"));
|
||||||
players_.back()->setController(getController(players_.back()->getId()));
|
//players_.back()->setController(getController(players_.back()->getId()));
|
||||||
players_.back()->setPlayingState(Player::State::WAITING);
|
players_.back()->setPlayingState(Player::State::WAITING);
|
||||||
|
|
||||||
// Activa el jugador que coincide con el "player_id" o ambos si es "0"
|
// Activa el jugador que coincide con el "player_id" o ambos si es "0"
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ auto Title::isStartButtonPressed(const Options::GamepadOptions& controller) -> b
|
|||||||
return Input::get()->checkAction(
|
return Input::get()->checkAction(
|
||||||
Input::Action::START,
|
Input::Action::START,
|
||||||
Input::DO_NOT_ALLOW_REPEAT,
|
Input::DO_NOT_ALLOW_REPEAT,
|
||||||
controller.type,
|
Input::CHECK_KEYBOARD,
|
||||||
controller.gamepad);
|
controller.gamepad);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
0
source/service_menu.cpp
Normal file
0
source/service_menu.cpp
Normal file
0
source/service_menu.h
Normal file
0
source/service_menu.h
Normal file
Reference in New Issue
Block a user