forked from jaildesigner-jailgames/jaildoctors_dilemma
Afegit globalEvents
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "global_inputs.h"
|
#include "global_inputs.h"
|
||||||
|
#include "global_events.h"
|
||||||
class Asset;
|
class Asset;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -78,12 +79,7 @@ void Credits::checkEvents()
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
globalEvents::check(event);
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
options.section.name = SECTION_QUIT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "global_inputs.h"
|
#include "global_inputs.h"
|
||||||
|
#include "global_events.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Demo::Demo()
|
Demo::Demo()
|
||||||
@@ -75,13 +76,7 @@ void Demo::checkEvents()
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
globalEvents::check(event);
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
options.section.name = SECTION_QUIT;
|
|
||||||
screen->setBorderColor(stringToColor(options.palette, "black"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "utils.h" // Para color_t, stringToColor, options_t
|
#include "utils.h" // Para color_t, stringToColor, options_t
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "global_inputs.h"
|
#include "global_inputs.h"
|
||||||
|
#include "global_events.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Ending::Ending()
|
Ending::Ending()
|
||||||
@@ -161,12 +162,7 @@ void Ending::checkEvents()
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
globalEvents::check(event);
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
options.section.name = SECTION_QUIT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "utils.h" // for color_t, stringToColor, options_t
|
#include "utils.h" // for color_t, stringToColor, options_t
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "global_inputs.h"
|
#include "global_inputs.h"
|
||||||
|
#include "global_events.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Ending2::Ending2()
|
Ending2::Ending2()
|
||||||
@@ -191,12 +192,7 @@ void Ending2::checkEvents()
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
globalEvents::check(event);
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
options.section.name = SECTION_QUIT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "notifier.h"
|
#include "notifier.h"
|
||||||
#include "global_inputs.h"
|
#include "global_inputs.h"
|
||||||
|
#include "global_events.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Game::Game()
|
Game::Game()
|
||||||
@@ -131,24 +132,13 @@ void Game::checkEvents()
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
globalEvents::check(event);
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
options.section.name = SECTION_QUIT;
|
|
||||||
screen_->setBorderColor(stringToColor(options.palette, "black"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type == SDL_RENDER_DEVICE_RESET || event.type == SDL_RENDER_TARGETS_RESET)
|
|
||||||
{
|
|
||||||
reLoadTextures();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
|
if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
|
||||||
{
|
{
|
||||||
switch (event.key.keysym.scancode)
|
switch (event.key.keysym.scancode)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
|
||||||
case SDL_SCANCODE_G:
|
case SDL_SCANCODE_G:
|
||||||
debug_->switchEnabled();
|
debug_->switchEnabled();
|
||||||
options.cheat.invincible = debug_->getEnabled();
|
options.cheat.invincible = debug_->getEnabled();
|
||||||
@@ -191,11 +181,11 @@ void Game::checkEvents()
|
|||||||
case SDL_SCANCODE_F9:
|
case SDL_SCANCODE_F9:
|
||||||
Notifier::get()->show("JAILDESIGNER IS LOGGED IN", "", 5);
|
Notifier::get()->show("JAILDESIGNER IS LOGGED IN", "", 5);
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "global_inputs.h"
|
#include "global_inputs.h"
|
||||||
|
#include "global_events.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
GameOver::GameOver()
|
GameOver::GameOver()
|
||||||
@@ -127,13 +128,7 @@ void GameOver::checkEvents()
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
globalEvents::check(event);
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
options.section.name = SECTION_QUIT;
|
|
||||||
options.section.subsection = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
24
source/global_events.cpp
Normal file
24
source/global_events.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include "global_events.h"
|
||||||
|
#include "options.h" // Para Options, options, OptionsGame, OptionsAudio
|
||||||
|
#include "mouse.h"
|
||||||
|
|
||||||
|
namespace globalEvents
|
||||||
|
{
|
||||||
|
// Comprueba los eventos que se pueden producir en cualquier sección del juego
|
||||||
|
void check(const SDL_Event &event)
|
||||||
|
{
|
||||||
|
// Evento de salida de la aplicación
|
||||||
|
if (event.type == SDL_QUIT)
|
||||||
|
{
|
||||||
|
options.section.name = SECTION_QUIT;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type == SDL_RENDER_DEVICE_RESET || event.type == SDL_RENDER_TARGETS_RESET)
|
||||||
|
{
|
||||||
|
//reLoadTextures();
|
||||||
|
}
|
||||||
|
|
||||||
|
Mouse::handleEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
source/global_events.h
Normal file
9
source/global_events.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL_events.h>
|
||||||
|
|
||||||
|
namespace globalEvents
|
||||||
|
{
|
||||||
|
// Comprueba los eventos que se pueden producir en cualquier sección del juego
|
||||||
|
void check(const SDL_Event &event);
|
||||||
|
}
|
||||||
@@ -69,6 +69,7 @@ namespace globalInputs
|
|||||||
else if (Input::get()->checkInput(input_toggle_shaders, REPEAT_FALSE))
|
else if (Input::get()->checkInput(input_toggle_shaders, REPEAT_FALSE))
|
||||||
{
|
{
|
||||||
Screen::get()->toggleShaders();
|
Screen::get()->toggleShaders();
|
||||||
|
Notifier::get()->show("HOLA");
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Input::get()->checkInput(input_toggle_palette, REPEAT_FALSE))
|
else if (Input::get()->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
namespace globalInputs
|
namespace globalInputs
|
||||||
{
|
{
|
||||||
// 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
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "utils.h" // for options_t, section_t, color_t, stringToC...
|
#include "utils.h" // for options_t, section_t, color_t, stringToC...
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "global_inputs.h"
|
#include "global_inputs.h"
|
||||||
|
#include "global_events.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
LoadingScreen::LoadingScreen()
|
LoadingScreen::LoadingScreen()
|
||||||
@@ -81,12 +82,7 @@ void LoadingScreen::checkEvents()
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
globalEvents::check(event);
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
options.section.name = SECTION_QUIT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "global_inputs.h"
|
#include "global_inputs.h"
|
||||||
|
#include "global_events.h"
|
||||||
class Asset; // lines 11-11
|
class Asset; // lines 11-11
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -76,12 +77,7 @@ void Logo::checkEvents()
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
globalEvents::check(event);
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
options.section.name = SECTION_QUIT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
33
source/mouse.cpp
Normal file
33
source/mouse.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include "mouse.h"
|
||||||
|
#include <SDL2/SDL_mouse.h> // Para SDL_ShowCursor
|
||||||
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
|
|
||||||
|
namespace Mouse
|
||||||
|
{
|
||||||
|
Uint32 cursor_hide_time = 3000; // Tiempo en milisegundos para ocultar el cursor
|
||||||
|
Uint32 last_mouse_move_time = 0; // Última vez que el ratón se movió
|
||||||
|
bool cursor_visible = true; // Estado del cursor
|
||||||
|
|
||||||
|
void handleEvent(const SDL_Event &event)
|
||||||
|
{
|
||||||
|
if (event.type == SDL_MOUSEMOTION)
|
||||||
|
{
|
||||||
|
last_mouse_move_time = SDL_GetTicks();
|
||||||
|
if (!cursor_visible)
|
||||||
|
{
|
||||||
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
|
cursor_visible = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateCursorVisibility()
|
||||||
|
{
|
||||||
|
Uint32 current_time = SDL_GetTicks();
|
||||||
|
if (cursor_visible && (current_time - last_mouse_move_time > cursor_hide_time))
|
||||||
|
{
|
||||||
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
|
cursor_visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
source/mouse.h
Normal file
14
source/mouse.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL_events.h> // Para SDL_Event
|
||||||
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
|
|
||||||
|
namespace Mouse
|
||||||
|
{
|
||||||
|
extern Uint32 cursor_hide_time; // Tiempo en milisegundos para ocultar el cursor
|
||||||
|
extern Uint32 last_mouse_move_time; // Última vez que el ratón se movió
|
||||||
|
extern bool cursor_visible; // Estado del cursor
|
||||||
|
|
||||||
|
void handleEvent(const SDL_Event &event);
|
||||||
|
void updateCursorVisibility();
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "jail_shader.h" // Para init, render
|
#include "jail_shader.h" // Para init, render
|
||||||
#include "notifier.h" // Para Notify
|
#include "notifier.h" // Para Notify
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
#include "mouse.h"
|
||||||
|
|
||||||
// [SINGLETON]
|
// [SINGLETON]
|
||||||
Screen *Screen::screen_ = nullptr;
|
Screen *Screen::screen_ = nullptr;
|
||||||
@@ -489,4 +490,5 @@ void Screen::toggleShaders()
|
|||||||
void Screen::update()
|
void Screen::update()
|
||||||
{
|
{
|
||||||
Notifier::get()->update();
|
Notifier::get()->update();
|
||||||
|
Mouse::updateCursorVisibility();
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "utils.h" // Para color_t, stringToColor, options_t
|
#include "utils.h" // Para color_t, stringToColor, options_t
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "global_inputs.h"
|
#include "global_inputs.h"
|
||||||
|
#include "global_events.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Title::Title()
|
Title::Title()
|
||||||
@@ -105,12 +106,7 @@ void Title::checkEvents()
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
globalEvents::check(event);
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
options.section.name = SECTION_QUIT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Solo se comprueban estas teclas si no está activo el menu de logros
|
// Solo se comprueban estas teclas si no está activo el menu de logros
|
||||||
if (event.type == SDL_KEYDOWN)
|
if (event.type == SDL_KEYDOWN)
|
||||||
@@ -149,62 +145,22 @@ void Title::checkInput()
|
|||||||
{
|
{
|
||||||
moveCheevosList(0);
|
moveCheevosList(0);
|
||||||
}
|
}
|
||||||
}
|
else if (input_->checkInput(input_accept, REPEAT_FALSE))
|
||||||
|
|
||||||
if (input_->checkInput(input_exit, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
if (show_cheevos_)
|
|
||||||
{
|
{
|
||||||
hideCheevosList();
|
hideCheevosList();
|
||||||
counter_ = 0;
|
counter_ = 0;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
options.section.name = SECTION_QUIT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input_->checkInput(input_toggle_border, REPEAT_FALSE))
|
if (input_->checkInput(input_accept, REPEAT_FALSE))
|
||||||
{
|
|
||||||
screen_->toggleBorder();
|
|
||||||
resource_->reLoadTextures();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen_->toggleVideoMode();
|
|
||||||
resource_->reLoadTextures();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input_->checkInput(input_toggle_shaders, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen_->toggleShaders();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input_->checkInput(input_window_dec_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen_->decWindowSize();
|
|
||||||
resource_->reLoadTextures();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input_->checkInput(input_window_inc_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen_->incWindowSize();
|
|
||||||
resource_->reLoadTextures();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input_->checkInput(input_toggle_palette, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
switchPalette();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input_->checkInput(input_accept, REPEAT_FALSE) || input_->checkInput(input_pause, REPEAT_FALSE))
|
|
||||||
{
|
{
|
||||||
if (state_ == show_loading_screen)
|
if (state_ == show_loading_screen)
|
||||||
{
|
{
|
||||||
state_ = fade_loading_screen;
|
state_ = fade_loading_screen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
globalInputs::check();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la marquesina
|
// Actualiza la marquesina
|
||||||
@@ -462,7 +418,7 @@ void Title::createCheevosTexture()
|
|||||||
SDL_RenderClear(renderer_);
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
// Escribe la lista de logros en la textura
|
// Escribe la lista de logros en la textura
|
||||||
const std::string cheevosOwner = "LOCAL ACHIEVEMENTS";
|
const std::string cheevosOwner = "ACHIEVEMENTS";
|
||||||
const std::string cheevosListCaption = cheevosOwner + " (" + std::to_string(Cheevos::get()->unlocked()) + " / " + std::to_string(Cheevos::get()->count()) + ")";
|
const std::string cheevosListCaption = cheevosOwner + " (" + std::to_string(Cheevos::get()->unlocked()) + " / " + std::to_string(Cheevos::get()->count()) + ")";
|
||||||
int pos = 2;
|
int pos = 2;
|
||||||
info_text_->writeDX(TXT_CENTER | TXT_COLOR, cheevos_texture_->getWidth() / 2, pos, cheevosListCaption, 1, stringToColor(options.palette, "bright_green"));
|
info_text_->writeDX(TXT_CENTER | TXT_COLOR, cheevos_texture_->getWidth() / 2, pos, cheevosListCaption, 1, stringToColor(options.palette, "bright_green"));
|
||||||
|
|||||||
Reference in New Issue
Block a user