forked from jaildesigner-jailgames/jaildoctors_dilemma
lo mateix
This commit is contained in:
@@ -110,7 +110,6 @@ void Demo::update()
|
||||
// Actualiza los objetos
|
||||
room_->update();
|
||||
scoreboard_->update();
|
||||
screen_->updateFX();
|
||||
checkRoomChange();
|
||||
|
||||
screen_->update();
|
||||
@@ -129,7 +128,6 @@ void Demo::render()
|
||||
room_->renderItems();
|
||||
renderRoomName();
|
||||
scoreboard_->render();
|
||||
screen_->renderFX();
|
||||
|
||||
// Actualiza la pantalla
|
||||
screen_->render();
|
||||
|
||||
@@ -184,11 +184,13 @@ void Game::checkInput()
|
||||
{
|
||||
board_->music = !board_->music;
|
||||
board_->music ? JA_ResumeMusic() : JA_PauseMusic();
|
||||
Notifier::get()->show({"MUSIC " + std::string(board_->music ? "ENABLED" : "DISABLED")}, NotificationText::CENTER);
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_pause, REPEAT_FALSE))
|
||||
{
|
||||
switchPause();
|
||||
Notifier::get()->show({std::string(paused_ ? "GAME PAUSED" : "GAME RUNNING")}, NotificationText::CENTER);
|
||||
}
|
||||
|
||||
globalInputs::check();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "global_inputs.h"
|
||||
#include <string> // for basic_string
|
||||
#include <vector> // for vector
|
||||
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||
#include "notifier.h" // for Notifier
|
||||
#include "options.h" // for Section, Options, options, SectionState, Optio...
|
||||
#include "screen.h" // for Screen
|
||||
#include "utils.h" // for Palette
|
||||
#include <string> // for basic_string
|
||||
#include <vector> // for vector
|
||||
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||
#include "notifier.h" // for Notifier
|
||||
#include "options.h" // for Section, Options, options, SectionState, Optio...
|
||||
#include "screen.h" // for Screen
|
||||
#include "utils.h" // for Palette
|
||||
|
||||
namespace globalInputs
|
||||
{
|
||||
@@ -78,14 +78,18 @@ namespace globalInputs
|
||||
|
||||
else if (Input::get()->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||
{
|
||||
Screen::get()->decWindowZoom();
|
||||
Notifier::get()->show({"WINDOW ZOOM x" + std::to_string(options.window.zoom)}, NotificationText::CENTER);
|
||||
if (Screen::get()->decWindowZoom())
|
||||
{
|
||||
Notifier::get()->show({"WINDOW ZOOM x" + std::to_string(options.window.zoom)}, NotificationText::CENTER);
|
||||
}
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||
{
|
||||
Screen::get()->incWindowZoom();
|
||||
Notifier::get()->show({"WINDOW ZOOM x" + std::to_string(options.window.zoom)}, NotificationText::CENTER);
|
||||
if (Screen::get()->incWindowZoom())
|
||||
{
|
||||
Notifier::get()->show({"WINDOW ZOOM x" + std::to_string(options.window.zoom)}, NotificationText::CENTER);
|
||||
}
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(input_toggle_shaders, REPEAT_FALSE))
|
||||
|
||||
@@ -214,15 +214,18 @@ struct OptionsStats
|
||||
// Estructura con opciones de la ventana
|
||||
struct OptionsWindow
|
||||
{
|
||||
int zoom; // Zoom de la ventana
|
||||
int zoom; // Zoom de la ventana
|
||||
int max_zoom; // Máximo tamaño de zoom para la ventana
|
||||
|
||||
// Constructor por defecto
|
||||
OptionsWindow()
|
||||
: zoom(DEFAULT_WINDOW_ZOOM) {}
|
||||
: zoom(DEFAULT_WINDOW_ZOOM),
|
||||
max_zoom(DEFAULT_WINDOW_ZOOM) {}
|
||||
|
||||
// Constructor
|
||||
OptionsWindow(int z)
|
||||
: zoom(z) {}
|
||||
OptionsWindow(int z, int mz)
|
||||
: zoom(z),
|
||||
max_zoom(mz) {}
|
||||
};
|
||||
|
||||
// Estructura para gestionar el borde de la pantalla
|
||||
|
||||
@@ -40,15 +40,22 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
: window_(window),
|
||||
renderer_(renderer)
|
||||
{
|
||||
adjustGameCanvasRect();
|
||||
calculateWindowSize();
|
||||
// Obtiene información sobre la pantalla
|
||||
SDL_DisplayMode DM;
|
||||
SDL_GetCurrentDisplayMode(0, &DM);
|
||||
|
||||
iniFade();
|
||||
iniSpectrumFade();
|
||||
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
|
||||
options.window.max_zoom = std::min(DM.w / options.game.width, DM.h / options.game.height);
|
||||
|
||||
adjustGameCanvasRect();
|
||||
adjustWindowSize();
|
||||
|
||||
// Define el color del borde para el modo de pantalla completa
|
||||
border_color_ = {0x00, 0x00, 0x00};
|
||||
|
||||
// Establece el modo de escalado
|
||||
SDL_RenderSetIntegerScale(renderer_, options.video.integer_scale ? SDL_TRUE : SDL_FALSE);
|
||||
|
||||
// Crea la textura donde se dibujan los graficos del juego
|
||||
game_canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width, options.game.height);
|
||||
if (game_canvas_ == nullptr)
|
||||
@@ -143,37 +150,23 @@ void Screen::setVideoMode(int videoMode)
|
||||
// Muestra el puntero
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
|
||||
calculateWindowSize();
|
||||
adjustGameCanvasRect();
|
||||
|
||||
// Modifica el tamaño de la ventana
|
||||
SDL_SetWindowSize(window_, window_width_ * options.window.zoom, window_height_ * options.window.zoom);
|
||||
SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
// Modifica el tamaño del renderizador
|
||||
const int extra_width = options.video.border.enabled ? options.video.border.width * 2 : 0;
|
||||
const int extra_height = options.video.border.enabled ? options.video.border.height * 2 : 0;
|
||||
SDL_RenderSetLogicalSize(renderer_, options.game.width + extra_width, options.game.height + extra_height);
|
||||
SDL_SetWindowFullscreen(window_, videoMode);
|
||||
adjustWindowSize();
|
||||
adjustGameCanvasRect();
|
||||
adjustRenderLogicalSize();
|
||||
}
|
||||
|
||||
// Modo pantalla completa
|
||||
else
|
||||
{
|
||||
calculateWindowSize();
|
||||
adjustGameCanvasRect();
|
||||
// Oculta el puntero
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
adjustWindowSize();
|
||||
|
||||
// Modifica el tamaño del renderizador
|
||||
const int extra_width = options.video.border.enabled ? options.video.border.width * 2 : 0;
|
||||
const int extra_height = options.video.border.enabled ? options.video.border.height * 2 : 0;
|
||||
SDL_RenderSetLogicalSize(renderer_, options.game.width + extra_width, options.game.height + extra_height);
|
||||
// Habilitar el escalado entero
|
||||
SDL_RenderSetIntegerScale(renderer_, options.video.integer_scale ? SDL_TRUE : SDL_FALSE);
|
||||
adjustGameCanvasRect();
|
||||
SDL_SetWindowFullscreen(window_, videoMode);
|
||||
}
|
||||
|
||||
|
||||
// Actualiza las opciones
|
||||
options.video.mode = videoMode;
|
||||
|
||||
@@ -202,27 +195,41 @@ void Screen::toggleVideoMode()
|
||||
setVideoMode(options.video.mode);
|
||||
}
|
||||
|
||||
// Cambia el tamaño de la ventana
|
||||
void Screen::setWindowZoom(int size)
|
||||
// Reduce el tamaño de la ventana
|
||||
bool Screen::decWindowZoom()
|
||||
{
|
||||
options.window.zoom = size;
|
||||
setVideoMode(0);
|
||||
if (options.video.mode == 0)
|
||||
{
|
||||
int previous_zoom = options.window.zoom;
|
||||
options.window.zoom = std::max(--options.window.zoom, 1);
|
||||
|
||||
if (options.window.zoom != previous_zoom)
|
||||
{
|
||||
adjustWindowSize();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reduce el tamaño de la ventana
|
||||
void Screen::decWindowZoom()
|
||||
{
|
||||
--options.window.zoom;
|
||||
options.window.zoom = std::max(options.window.zoom, 1);
|
||||
setVideoMode(0);
|
||||
}
|
||||
|
||||
// Aumenta el tamaño de la ventana
|
||||
void Screen::incWindowZoom()
|
||||
bool Screen::incWindowZoom()
|
||||
{
|
||||
++options.window.zoom;
|
||||
options.window.zoom = std::min(options.window.zoom, 4);
|
||||
setVideoMode(0);
|
||||
if (options.video.mode == 0)
|
||||
{
|
||||
int previous_zoom = options.window.zoom;
|
||||
options.window.zoom = std::min(++options.window.zoom, options.window.max_zoom);
|
||||
|
||||
if (options.window.zoom != previous_zoom)
|
||||
{
|
||||
adjustWindowSize();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cambia el color del borde
|
||||
@@ -261,139 +268,9 @@ void Screen::setBorderEnabled(bool value) { options.video.border.enabled = value
|
||||
void Screen::toggleBorder()
|
||||
{
|
||||
options.video.border.enabled = !options.video.border.enabled;
|
||||
setVideoMode(options.video.mode);
|
||||
}
|
||||
|
||||
// Activa el fade
|
||||
void Screen::setFade() { fade_ = true; }
|
||||
|
||||
// Comprueba si ha terminado el fade
|
||||
bool Screen::fadeEnded()
|
||||
{
|
||||
if (fade_ || fade_counter_ > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Activa el spectrum fade
|
||||
void Screen::setspectrumFade()
|
||||
{
|
||||
spectrum_fade_ = true;
|
||||
}
|
||||
|
||||
// Comprueba si ha terminado el spectrum fade
|
||||
bool Screen::spectrumFadeEnded()
|
||||
{
|
||||
if (spectrum_fade_ || spectrum_fade_counter_ > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Inicializa las variables para el fade
|
||||
void Screen::iniFade()
|
||||
{
|
||||
fade_ = false;
|
||||
fade_counter_ = 0;
|
||||
fade_lenght_ = 200;
|
||||
}
|
||||
|
||||
// Actualiza el fade
|
||||
void Screen::updateFade()
|
||||
{
|
||||
if (!fade_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
fade_counter_++;
|
||||
if (fade_counter_ > fade_lenght_)
|
||||
{
|
||||
iniFade();
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el fade
|
||||
void Screen::renderFade()
|
||||
{
|
||||
if (!fade_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const SDL_Rect rect = {0, 0, options.game.width, options.game.height};
|
||||
Color color = {0, 0, 0};
|
||||
const float step = (float)fade_counter_ / (float)fade_lenght_;
|
||||
const int alpha = 0 + (255 - 0) * step;
|
||||
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, alpha);
|
||||
SDL_RenderFillRect(renderer_, &rect);
|
||||
}
|
||||
|
||||
// Inicializa las variables para el fade spectrum
|
||||
void Screen::iniSpectrumFade()
|
||||
{
|
||||
spectrum_fade_ = false;
|
||||
spectrum_fade_counter_ = 0;
|
||||
spectrum_fade_lenght_ = 50;
|
||||
|
||||
spectrum_color_.clear();
|
||||
|
||||
// Inicializa el vector de colores
|
||||
const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
|
||||
for (auto v : vColors)
|
||||
{
|
||||
spectrum_color_.push_back(stringToColor(options.video.palette, v));
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el spectrum fade
|
||||
void Screen::updateSpectrumFade()
|
||||
{
|
||||
if (!spectrum_fade_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
spectrum_fade_counter_++;
|
||||
if (spectrum_fade_counter_ > spectrum_fade_lenght_)
|
||||
{
|
||||
iniSpectrumFade();
|
||||
SDL_SetTextureColorMod(game_canvas_, 255, 255, 255);
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el spectrum fade
|
||||
void Screen::renderSpectrumFade()
|
||||
{
|
||||
if (!spectrum_fade_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const float step = (float)spectrum_fade_counter_ / (float)spectrum_fade_lenght_;
|
||||
const int max = spectrum_color_.size() - 1;
|
||||
const int index = max + (0 - max) * step;
|
||||
const Color c = spectrum_color_[index];
|
||||
SDL_SetTextureColorMod(game_canvas_, c.r, c.g, c.b);
|
||||
}
|
||||
|
||||
// Actualiza los efectos
|
||||
void Screen::updateFX()
|
||||
{
|
||||
updateFade();
|
||||
updateSpectrumFade();
|
||||
}
|
||||
|
||||
// Dibuja los efectos
|
||||
void Screen::renderFX()
|
||||
{
|
||||
renderFade();
|
||||
renderSpectrumFade();
|
||||
adjustWindowSize();
|
||||
adjustGameCanvasRect();
|
||||
adjustRenderLogicalSize();
|
||||
}
|
||||
|
||||
// Dibuja las notificaciones
|
||||
@@ -466,29 +343,32 @@ void Screen::hide()
|
||||
}
|
||||
|
||||
// Calcula el tamaño de la ventana
|
||||
void Screen::calculateWindowSize()
|
||||
void Screen::adjustWindowSize()
|
||||
{
|
||||
if (options.video.border.enabled)
|
||||
window_width_ = options.game.width + (options.video.border.enabled ? options.video.border.width * 2 : 0);
|
||||
window_height_ = options.game.height + (options.video.border.enabled ? options.video.border.height * 2 : 0);
|
||||
|
||||
if (options.video.mode == 0)
|
||||
{
|
||||
window_width_ = options.game.width + options.video.border.width * 2;
|
||||
window_height_ = options.game.height + options.video.border.height * 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
window_width_ = options.game.width;
|
||||
window_height_ = options.game.height;
|
||||
SDL_SetWindowSize(window_, window_width_ * options.window.zoom, window_height_ * options.window.zoom);
|
||||
SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
}
|
||||
}
|
||||
|
||||
// Ajusta game_canvas_rect_
|
||||
void Screen::adjustGameCanvasRect()
|
||||
{
|
||||
if (options.video.border.enabled)
|
||||
{
|
||||
game_canvas_rect_ = {options.video.border.width, options.video.border.height, options.game.width, options.game.height};
|
||||
}
|
||||
else
|
||||
{
|
||||
game_canvas_rect_ = {0, 0, options.game.width, options.game.height};
|
||||
}
|
||||
game_canvas_rect_ = {
|
||||
options.video.border.enabled ? options.video.border.width : 0,
|
||||
options.video.border.enabled ? options.video.border.height : 0,
|
||||
options.game.width,
|
||||
options.game.height};
|
||||
}
|
||||
|
||||
// Ajusta el tamaño lógico del renderizador
|
||||
void Screen::adjustRenderLogicalSize()
|
||||
{
|
||||
const int extra_width = options.video.border.enabled ? options.video.border.width * 2 : 0;
|
||||
const int extra_height = options.video.border.enabled ? options.video.border.height * 2 : 0;
|
||||
SDL_RenderSetLogicalSize(renderer_, options.game.width + extra_width, options.game.height + extra_height);
|
||||
}
|
||||
@@ -33,33 +33,6 @@ private:
|
||||
SDL_Rect game_canvas_rect_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
||||
Color border_color_; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||
|
||||
// Variables - Efectos
|
||||
bool fade_; // Indica si esta activo el efecto de fade
|
||||
int fade_counter_; // Temporizador para el efecto de fade
|
||||
int fade_lenght_; // Duración del fade
|
||||
bool spectrum_fade_; // Indica si esta activo el efecto de fade spectrum
|
||||
int spectrum_fade_counter_; // Temporizador para el efecto de fade spectrum
|
||||
int spectrum_fade_lenght_; // Duración del fade spectrum
|
||||
std::vector<Color> spectrum_color_; // Colores para el fade spectrum
|
||||
|
||||
// Inicializa las variables para el fade
|
||||
void iniFade();
|
||||
|
||||
// Actualiza el fade
|
||||
void updateFade();
|
||||
|
||||
// Dibuja el fade
|
||||
void renderFade();
|
||||
|
||||
// Inicializa las variables para el fade spectrum
|
||||
void iniSpectrumFade();
|
||||
|
||||
// Actualiza el spectrum fade
|
||||
void updateSpectrumFade();
|
||||
|
||||
// Dibuja el spectrum fade
|
||||
void renderSpectrumFade();
|
||||
|
||||
// Dibuja las notificaciones
|
||||
void renderNotifications();
|
||||
|
||||
@@ -70,11 +43,14 @@ private:
|
||||
void renderPresent();
|
||||
|
||||
// Calcula el tamaño de la ventana
|
||||
void calculateWindowSize();
|
||||
void adjustWindowSize();
|
||||
|
||||
// Ajusta game_canvas_rect_
|
||||
void adjustGameCanvasRect();
|
||||
|
||||
// Ajusta el tamaño lógico del renderizador
|
||||
void adjustRenderLogicalSize();
|
||||
|
||||
// Constructor
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer);
|
||||
|
||||
@@ -113,14 +89,11 @@ public:
|
||||
// Camibia entre pantalla completa y ventana
|
||||
void toggleVideoMode();
|
||||
|
||||
// Cambia el tamaño de la ventana
|
||||
void setWindowZoom(int size);
|
||||
|
||||
// Reduce el tamaño de la ventana
|
||||
void decWindowZoom();
|
||||
bool decWindowZoom();
|
||||
|
||||
// Aumenta el tamaño de la ventana
|
||||
void incWindowZoom();
|
||||
bool incWindowZoom();
|
||||
|
||||
// Cambia el color del borde
|
||||
void setBorderColor(Color color);
|
||||
@@ -138,24 +111,6 @@ public:
|
||||
// Cambia entre borde visible y no visible
|
||||
void toggleBorder();
|
||||
|
||||
// Activa el fade
|
||||
void setFade();
|
||||
|
||||
// Comprueba si ha terminado el fade
|
||||
bool fadeEnded();
|
||||
|
||||
// Activa el spectrum fade
|
||||
void setspectrumFade();
|
||||
|
||||
// Comprueba si ha terminado el spectrum fade
|
||||
bool spectrumFadeEnded();
|
||||
|
||||
// Actualiza los efectos
|
||||
void updateFX();
|
||||
|
||||
// Dibuja los efectos
|
||||
void renderFX();
|
||||
|
||||
// Cambia el estado de los shaders
|
||||
void toggleShaders();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user