Afegit mouse.cpp per amagar el cursor quan no està moventse
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "fade.h"
|
#include "fade.h"
|
||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
|
#include "mouse.h"
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
constexpr const char TEXT_COPYRIGHT[] = "@2020,2025 JailDesigner";
|
constexpr const char TEXT_COPYRIGHT[] = "@2020,2025 JailDesigner";
|
||||||
@@ -39,8 +40,8 @@ Credits::Credits()
|
|||||||
throw std::runtime_error("Failed to create SDL texture for text.");
|
throw std::runtime_error("Failed to create SDL texture for text.");
|
||||||
}
|
}
|
||||||
section::name = section::Name::CREDITS;
|
section::name = section::Name::CREDITS;
|
||||||
//top_black_rect_ = {play_area_.x, 0, play_area_.w, black_bars_size_};
|
// top_black_rect_ = {play_area_.x, 0, play_area_.w, black_bars_size_};
|
||||||
//bottom_black_rect_ = {play_area_.x, param.game.game_area.rect.h - black_bars_size_, play_area_.w, black_bars_size_};
|
// bottom_black_rect_ = {play_area_.x, param.game.game_area.rect.h - black_bars_size_, play_area_.w, black_bars_size_};
|
||||||
balloon_manager_->setPlayArea(play_area_);
|
balloon_manager_->setPlayArea(play_area_);
|
||||||
|
|
||||||
fade_in_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
fade_in_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||||
@@ -158,6 +159,9 @@ void Credits::checkEvents()
|
|||||||
section::options = section::Options::QUIT_FROM_EVENT;
|
section::options = section::Options::QUIT_FROM_EVENT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba el cursor
|
||||||
|
Mouse::handleEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
#include "tabe.h" // Para Tabe
|
#include "tabe.h" // Para Tabe
|
||||||
#include "text.h" // Para Text
|
#include "text.h" // Para Text
|
||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
#include <iostream>
|
#include "mouse.h"
|
||||||
struct JA_Sound_t; // lines 37-37
|
struct JA_Sound_t; // lines 37-37
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -1270,6 +1270,8 @@ void Game::checkEvents()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
// Comprueba el cursor
|
||||||
|
Mouse::handleEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1625,11 +1627,16 @@ void Game::initDemo(int player_id)
|
|||||||
{
|
{
|
||||||
if (demo_.enabled)
|
if (demo_.enabled)
|
||||||
{
|
{
|
||||||
|
// Cambia el estado del juego
|
||||||
|
state_ = GameState::PLAYING;
|
||||||
|
|
||||||
// Aleatoriza la asignación del fichero con los datos del modo demostracion
|
// Aleatoriza la asignación del fichero con los datos del modo demostracion
|
||||||
|
{
|
||||||
const auto demo1 = rand() % 2;
|
const auto demo1 = rand() % 2;
|
||||||
const auto demo2 = (demo1 == 0) ? 1 : 0;
|
const auto demo2 = (demo1 == 0) ? 1 : 0;
|
||||||
demo_.data.emplace_back(Resource::get()->getDemoData(demo1));
|
demo_.data.emplace_back(Resource::get()->getDemoData(demo1));
|
||||||
demo_.data.emplace_back(Resource::get()->getDemoData(demo2));
|
demo_.data.emplace_back(Resource::get()->getDemoData(demo2));
|
||||||
|
}
|
||||||
|
|
||||||
// Selecciona una pantalla al azar
|
// Selecciona una pantalla al azar
|
||||||
{
|
{
|
||||||
@@ -1645,8 +1652,13 @@ void Game::initDemo(int player_id)
|
|||||||
Stage::total_power += Stage::get(i).power_to_complete;
|
Stage::total_power += Stage::get(i).power_to_complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pone al jugador en estado jugar
|
||||||
|
{
|
||||||
|
getPlayer(player_id)->setPlayingState(PlayerState::PLAYING);
|
||||||
|
}
|
||||||
|
|
||||||
// Activa o no al otro jugador
|
// Activa o no al otro jugador
|
||||||
if (rand() % 2 == 0)
|
if (rand() % 3 != 0)
|
||||||
{
|
{
|
||||||
const auto other_player_id = player_id == 1 ? 2 : 1;
|
const auto other_player_id = player_id == 1 ? 2 : 1;
|
||||||
auto other_player = getPlayer(other_player_id);
|
auto other_player = getPlayer(other_player_id);
|
||||||
@@ -1804,9 +1816,15 @@ void Game::updateDemo()
|
|||||||
{
|
{
|
||||||
if (demo_.enabled)
|
if (demo_.enabled)
|
||||||
{
|
{
|
||||||
|
// Actualiza ambos fades
|
||||||
|
fade_in_->update();
|
||||||
|
fade_out_->update();
|
||||||
|
|
||||||
// Incrementa el contador de la demo
|
// Incrementa el contador de la demo
|
||||||
if (demo_.counter < TOTAL_DEMO_DATA)
|
if (demo_.counter < TOTAL_DEMO_DATA)
|
||||||
|
{
|
||||||
demo_.counter++;
|
demo_.counter++;
|
||||||
|
}
|
||||||
|
|
||||||
// Activa el fundido antes de acabar con los datos de la demo
|
// Activa el fundido antes de acabar con los datos de la demo
|
||||||
if (demo_.counter == TOTAL_DEMO_DATA - 200)
|
if (demo_.counter == TOTAL_DEMO_DATA - 200)
|
||||||
@@ -1871,7 +1889,7 @@ void Game::updateGameStateEnteringPlayer()
|
|||||||
{
|
{
|
||||||
state_ = GameState::SHOWING_GET_READY_MESSAGE;
|
state_ = GameState::SHOWING_GET_READY_MESSAGE;
|
||||||
createMessage({paths_.at(0), paths_.at(1)}, Resource::get()->getTexture("game_text_get_ready"));
|
createMessage({paths_.at(0), paths_.at(1)}, Resource::get()->getTexture("game_text_get_ready"));
|
||||||
//JA_PlaySound(Resource::get()->getSound("voice_get_ready.wav"));
|
JA_PlaySound(Resource::get()->getSound("voice_get_ready.wav"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "section.h" // Para Name, name, Options, options
|
#include "section.h" // Para Name, name, Options, options
|
||||||
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
|
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
|
||||||
#include "utils.h" // Para Color, Zone, fade_color, orange_color
|
#include "utils.h" // Para Color, Zone, fade_color, orange_color
|
||||||
|
#include "mouse.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
HiScoreTable::HiScoreTable()
|
HiScoreTable::HiScoreTable()
|
||||||
@@ -196,6 +197,9 @@ void HiScoreTable::checkEvents()
|
|||||||
reloadTextures();
|
reloadTextures();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba el cursor
|
||||||
|
Mouse::handleEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +209,7 @@ void HiScoreTable::checkInput()
|
|||||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
||||||
if (Input::get()->checkAnyButtonPressed())
|
if (Input::get()->checkAnyButtonPressed())
|
||||||
{
|
{
|
||||||
//JA_StopMusic();
|
// JA_StopMusic();
|
||||||
section::name = section::Name::TITLE;
|
section::name = section::Name::TITLE;
|
||||||
section::options = section::Options::TITLE_1;
|
section::options = section::Options::TITLE_1;
|
||||||
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
||||||
#include "utils.h" // Para Color, shdw_txt_color, Zone, no_color
|
#include "utils.h" // Para Color, shdw_txt_color, Zone, no_color
|
||||||
|
#include "mouse.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Instructions::Instructions()
|
Instructions::Instructions()
|
||||||
@@ -301,6 +302,9 @@ void Instructions::checkEvents()
|
|||||||
reloadTextures();
|
reloadTextures();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba el cursor
|
||||||
|
Mouse::handleEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,7 +314,7 @@ void Instructions::checkInput()
|
|||||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
||||||
if (Input::get()->checkAnyButtonPressed())
|
if (Input::get()->checkAnyButtonPressed())
|
||||||
{
|
{
|
||||||
//JA_StopMusic();
|
// JA_StopMusic();
|
||||||
section::name = section::Name::TITLE;
|
section::name = section::Name::TITLE;
|
||||||
section::options = section::Options::TITLE_1;
|
section::options = section::Options::TITLE_1;
|
||||||
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
#include "utils.h" // Para Zone, BLOCK, Color, bg_color
|
#include "utils.h" // Para Zone, BLOCK, Color, bg_color
|
||||||
#include "writer.h" // Para Writer
|
#include "writer.h" // Para Writer
|
||||||
|
#include "mouse.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Intro::Intro()
|
Intro::Intro()
|
||||||
@@ -169,13 +170,18 @@ void Intro::checkEvents()
|
|||||||
case SDL_WINDOWEVENT:
|
case SDL_WINDOWEVENT:
|
||||||
{
|
{
|
||||||
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||||
|
{
|
||||||
reloadTextures();
|
reloadTextures();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba el cursor
|
||||||
|
Mouse::handleEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "sprite.h" // Para Sprite
|
#include "sprite.h" // Para Sprite
|
||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
#include "utils.h" // Para Color, Zone
|
#include "utils.h" // Para Color, Zone
|
||||||
|
#include "mouse.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo::Logo()
|
Logo::Logo()
|
||||||
@@ -92,6 +93,9 @@ void Logo::checkEvents()
|
|||||||
reloadTextures();
|
reloadTextures();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba el cursor
|
||||||
|
Mouse::handleEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
32
source/mouse.cpp
Normal file
32
source/mouse.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include "mouse.h"
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
namespace Mouse
|
||||||
|
{
|
||||||
|
Uint32 cursorHideTime = 3000; // Tiempo en milisegundos para ocultar el cursor
|
||||||
|
Uint32 lastMouseMoveTime = 0; // Última vez que el ratón se movió
|
||||||
|
bool cursorVisible = true; // Estado del cursor
|
||||||
|
|
||||||
|
void handleEvent(const SDL_Event &event)
|
||||||
|
{
|
||||||
|
if (event.type == SDL_MOUSEMOTION)
|
||||||
|
{
|
||||||
|
lastMouseMoveTime = SDL_GetTicks();
|
||||||
|
if (!cursorVisible)
|
||||||
|
{
|
||||||
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
|
cursorVisible = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateCursorVisibility()
|
||||||
|
{
|
||||||
|
Uint32 currentTime = SDL_GetTicks();
|
||||||
|
if (cursorVisible && (currentTime - lastMouseMoveTime > cursorHideTime))
|
||||||
|
{
|
||||||
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
|
cursorVisible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
source/mouse.h
Normal file
12
source/mouse.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
namespace Mouse
|
||||||
|
{
|
||||||
|
extern Uint32 cursorHideTime; // Tiempo en milisegundos para ocultar el cursor
|
||||||
|
extern Uint32 lastMouseMoveTime; // Última vez que el ratón se movió
|
||||||
|
extern bool cursorVisible; // Estado del cursor
|
||||||
|
|
||||||
|
void handleEvent(const SDL_Event &event);
|
||||||
|
void updateCursorVisibility();
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "notifier.h" // Para Notifier
|
#include "notifier.h" // Para Notifier
|
||||||
#include "on_screen_help.h" // Para OnScreenHelp
|
#include "on_screen_help.h" // Para OnScreenHelp
|
||||||
#include "options.h" // Para Options, OptionsVideo, options, Options...
|
#include "options.h" // Para Options, OptionsVideo, options, Options...
|
||||||
|
#include "mouse.h"
|
||||||
|
|
||||||
#ifndef NO_SHADERS
|
#ifndef NO_SHADERS
|
||||||
#include "jail_shader.h" // para init, render
|
#include "jail_shader.h" // para init, render
|
||||||
@@ -259,6 +260,7 @@ void Screen::update()
|
|||||||
Notifier::get()->update();
|
Notifier::get()->update();
|
||||||
updateFPS();
|
updateFPS();
|
||||||
OnScreenHelp::get()->update();
|
OnScreenHelp::get()->update();
|
||||||
|
Mouse::updateCursorVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Agita la pantalla
|
// Agita la pantalla
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
||||||
#include "utils.h" // Para Color, Zone, fade_color, no_color, BLOCK
|
#include "utils.h" // Para Color, Zone, fade_color, no_color, BLOCK
|
||||||
|
#include "mouse.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Title::Title()
|
Title::Title()
|
||||||
@@ -270,6 +271,9 @@ void Title::checkEvents()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba el cursor
|
||||||
|
Mouse::handleEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user