Afegit mouse.cpp per amagar el cursor quan no està moventse
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "player.h"
|
||||
#include "fade.h"
|
||||
#include "lang.h"
|
||||
#include "mouse.h"
|
||||
|
||||
// Textos
|
||||
constexpr const char TEXT_COPYRIGHT[] = "@2020,2025 JailDesigner";
|
||||
@@ -39,20 +40,20 @@ Credits::Credits()
|
||||
throw std::runtime_error("Failed to create SDL texture for text.");
|
||||
}
|
||||
section::name = section::Name::CREDITS;
|
||||
//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_};
|
||||
// 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_};
|
||||
balloon_manager_->setPlayArea(play_area_);
|
||||
|
||||
|
||||
fade_in_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade_in_->setType(FadeType::FULLSCREEN);
|
||||
fade_in_->setPost(50);
|
||||
fade_in_->setMode(FadeMode::IN);
|
||||
fade_in_->activate();
|
||||
|
||||
|
||||
fade_out_->setColor(0, 0, 0);
|
||||
fade_out_->setType(FadeType::FULLSCREEN);
|
||||
fade_out_->setPost(400);
|
||||
|
||||
|
||||
initPlayers();
|
||||
SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND);
|
||||
fillTextTexture();
|
||||
@@ -158,6 +159,9 @@ void Credits::checkEvents()
|
||||
section::options = section::Options::QUIT_FROM_EVENT;
|
||||
break;
|
||||
}
|
||||
|
||||
// Comprueba el cursor
|
||||
Mouse::handleEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "tabe.h" // Para Tabe
|
||||
#include "text.h" // Para Text
|
||||
#include "texture.h" // Para Texture
|
||||
#include <iostream>
|
||||
#include "mouse.h"
|
||||
struct JA_Sound_t; // lines 37-37
|
||||
|
||||
// Constructor
|
||||
@@ -1270,6 +1270,8 @@ void Game::checkEvents()
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// Comprueba el cursor
|
||||
Mouse::handleEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1625,11 +1627,16 @@ void Game::initDemo(int player_id)
|
||||
{
|
||||
if (demo_.enabled)
|
||||
{
|
||||
// Cambia el estado del juego
|
||||
state_ = GameState::PLAYING;
|
||||
|
||||
// Aleatoriza la asignación del fichero con los datos del modo demostracion
|
||||
const auto demo1 = rand() % 2;
|
||||
const auto demo2 = (demo1 == 0) ? 1 : 0;
|
||||
demo_.data.emplace_back(Resource::get()->getDemoData(demo1));
|
||||
demo_.data.emplace_back(Resource::get()->getDemoData(demo2));
|
||||
{
|
||||
const auto demo1 = rand() % 2;
|
||||
const auto demo2 = (demo1 == 0) ? 1 : 0;
|
||||
demo_.data.emplace_back(Resource::get()->getDemoData(demo1));
|
||||
demo_.data.emplace_back(Resource::get()->getDemoData(demo2));
|
||||
}
|
||||
|
||||
// Selecciona una pantalla al azar
|
||||
{
|
||||
@@ -1645,8 +1652,13 @@ void Game::initDemo(int player_id)
|
||||
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
|
||||
if (rand() % 2 == 0)
|
||||
if (rand() % 3 != 0)
|
||||
{
|
||||
const auto other_player_id = player_id == 1 ? 2 : 1;
|
||||
auto other_player = getPlayer(other_player_id);
|
||||
@@ -1804,9 +1816,15 @@ void Game::updateDemo()
|
||||
{
|
||||
if (demo_.enabled)
|
||||
{
|
||||
// Actualiza ambos fades
|
||||
fade_in_->update();
|
||||
fade_out_->update();
|
||||
|
||||
// Incrementa el contador de la demo
|
||||
if (demo_.counter < TOTAL_DEMO_DATA)
|
||||
{
|
||||
demo_.counter++;
|
||||
}
|
||||
|
||||
// Activa el fundido antes de acabar con los datos de la demo
|
||||
if (demo_.counter == TOTAL_DEMO_DATA - 200)
|
||||
@@ -1871,7 +1889,7 @@ void Game::updateGameStateEnteringPlayer()
|
||||
{
|
||||
state_ = GameState::SHOWING_GET_READY_MESSAGE;
|
||||
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 "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
|
||||
#include "utils.h" // Para Color, Zone, fade_color, orange_color
|
||||
#include "mouse.h"
|
||||
|
||||
// Constructor
|
||||
HiScoreTable::HiScoreTable()
|
||||
@@ -78,7 +79,7 @@ void HiScoreTable::update()
|
||||
Screen::get()->update();
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
globalInputs::update();
|
||||
|
||||
// Actualiza el fondo
|
||||
background_->update();
|
||||
@@ -196,6 +197,9 @@ void HiScoreTable::checkEvents()
|
||||
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)
|
||||
if (Input::get()->checkAnyButtonPressed())
|
||||
{
|
||||
//JA_StopMusic();
|
||||
// JA_StopMusic();
|
||||
section::name = section::Name::TITLE;
|
||||
section::options = section::Options::TITLE_1;
|
||||
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "texture.h" // Para Texture
|
||||
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
||||
#include "utils.h" // Para Color, shdw_txt_color, Zone, no_color
|
||||
#include "mouse.h"
|
||||
|
||||
// Constructor
|
||||
Instructions::Instructions()
|
||||
@@ -217,7 +218,7 @@ void Instructions::update()
|
||||
Screen::get()->update();
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
globalInputs::update();
|
||||
|
||||
// Incrementa el contador
|
||||
counter_++;
|
||||
@@ -301,6 +302,9 @@ void Instructions::checkEvents()
|
||||
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)
|
||||
if (Input::get()->checkAnyButtonPressed())
|
||||
{
|
||||
//JA_StopMusic();
|
||||
// JA_StopMusic();
|
||||
section::name = section::Name::TITLE;
|
||||
section::options = section::Options::TITLE_1;
|
||||
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para Zone, BLOCK, Color, bg_color
|
||||
#include "writer.h" // Para Writer
|
||||
#include "mouse.h"
|
||||
|
||||
// Constructor
|
||||
Intro::Intro()
|
||||
@@ -169,13 +170,18 @@ void Intro::checkEvents()
|
||||
case SDL_WINDOWEVENT:
|
||||
{
|
||||
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||
{
|
||||
reloadTextures();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Comprueba el cursor
|
||||
Mouse::handleEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,7 +390,7 @@ void Intro::update()
|
||||
updateScenes();
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
globalInputs::update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para Color, Zone
|
||||
#include "mouse.h"
|
||||
|
||||
// Constructor
|
||||
Logo::Logo()
|
||||
@@ -92,6 +93,9 @@ void Logo::checkEvents()
|
||||
reloadTextures();
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el cursor
|
||||
Mouse::handleEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +206,7 @@ void Logo::update()
|
||||
}
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
globalInputs::update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 "on_screen_help.h" // Para OnScreenHelp
|
||||
#include "options.h" // Para Options, OptionsVideo, options, Options...
|
||||
#include "mouse.h"
|
||||
|
||||
#ifndef NO_SHADERS
|
||||
#include "jail_shader.h" // para init, render
|
||||
@@ -259,6 +260,7 @@ void Screen::update()
|
||||
Notifier::get()->update();
|
||||
updateFPS();
|
||||
OnScreenHelp::get()->update();
|
||||
Mouse::updateCursorVisibility();
|
||||
}
|
||||
|
||||
// Agita la pantalla
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "texture.h" // Para Texture
|
||||
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
||||
#include "utils.h" // Para Color, Zone, fade_color, no_color, BLOCK
|
||||
#include "mouse.h"
|
||||
|
||||
// Constructor
|
||||
Title::Title()
|
||||
@@ -134,7 +135,7 @@ void Title::update()
|
||||
|
||||
// Actualiza el mosaico de fondo
|
||||
tiled_bg_->update();
|
||||
|
||||
|
||||
if (counter_ == 100)
|
||||
{
|
||||
fade_->activate();
|
||||
@@ -270,6 +271,9 @@ void Title::checkEvents()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el cursor
|
||||
Mouse::handleEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user