forked from jaildesigner-jailgames/jaildoctors_dilemma
Ja pinta cosetes per pantalla
This commit is contained in:
@@ -108,7 +108,9 @@ bool Asset::checkFile(const std::string &path) const
|
||||
file.close();
|
||||
|
||||
if (!success)
|
||||
{
|
||||
printWithDots("Checking file : ", getFileName(path), "[ ERROR ]");
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ Director::Director(int argc, const char *argv[])
|
||||
Screen::init(window_, renderer_);
|
||||
Screen::get()->setBorderColor(border_color);
|
||||
Resource::init();
|
||||
Notifier::init("notify.gif", "8bithud");
|
||||
Notifier::init("", "8bithud");
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||
initInput();
|
||||
Debug::init();
|
||||
|
||||
@@ -21,7 +21,7 @@ void initOptions()
|
||||
options = Options();
|
||||
|
||||
#ifdef DEBUG
|
||||
options.section = SectionState(Section::CREDITS, Subsection::NONE);
|
||||
options.section = SectionState(Section::LOGO, Subsection::LOGO_TO_INTRO);
|
||||
options.console = true;
|
||||
#else
|
||||
options.section = SectionState(Section::LOGO, Subsection::LOGO_TO_INTRO);
|
||||
|
||||
@@ -405,16 +405,17 @@ void Resource::renderProgress()
|
||||
constexpr int BAR_HEIGHT = 10;
|
||||
const int bar_position = options.game.height - BAR_HEIGHT - Y_PADDING;
|
||||
Screen::get()->start();
|
||||
Screen::get()->clear();
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 255, 255, 255, 255);
|
||||
|
||||
const int wired_bar_width = options.game.width - (X_PADDING * 2);
|
||||
SDL_Rect rect_wired = {X_PADDING, bar_position, wired_bar_width, X_PADDING};
|
||||
SDL_RenderDrawRect(Screen::get()->getRenderer(), &rect_wired);
|
||||
|
||||
const int full_bar_width = wired_bar_width * count_.getPercentage();
|
||||
SDL_Rect rect_full = {X_PADDING, bar_position, full_bar_width, X_PADDING};
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect_full);
|
||||
Screen::get()->clear(4);
|
||||
|
||||
//SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 255, 255, 255, 255);
|
||||
//
|
||||
//const int wired_bar_width = options.game.width - (X_PADDING * 2);
|
||||
//SDL_Rect rect_wired = {X_PADDING, bar_position, wired_bar_width, X_PADDING};
|
||||
//SDL_RenderDrawRect(Screen::get()->getRenderer(), &rect_wired);
|
||||
//
|
||||
//const int full_bar_width = wired_bar_width * count_.getPercentage();
|
||||
//SDL_Rect rect_full = {X_PADDING, bar_position, full_bar_width, X_PADDING};
|
||||
//SDL_RenderFillRect(Screen::get()->getRenderer(), &rect_full);
|
||||
|
||||
Screen::get()->renderWithoutNotifier();
|
||||
}
|
||||
|
||||
@@ -52,10 +52,28 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
SDL_RenderSetIntegerScale(renderer_, options.video.integer_scale ? SDL_TRUE : SDL_FALSE);
|
||||
|
||||
// Crea la textura donde se dibujan los graficos del juego
|
||||
game_texture_ = createTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, options.game.width, options.game.height);
|
||||
game_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, options.game.width, options.game.height);
|
||||
//game_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, options.game.width, options.game.height);
|
||||
if (!game_texture_)
|
||||
{
|
||||
// Registrar el error si está habilitado
|
||||
if (options.console)
|
||||
{
|
||||
std::cerr << "Error: game_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Crea la textura donde se dibuja el borde que rodea el area de juego
|
||||
border_texture_ = createTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2);
|
||||
border_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2);
|
||||
//border_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2);
|
||||
if (!border_texture_)
|
||||
{
|
||||
// Registrar el error si está habilitado
|
||||
if (options.console)
|
||||
{
|
||||
std::cerr << "Error: border_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Crea la surface donde se dibujan los graficos del juego
|
||||
game_surface_ = std::make_shared<Surface>(nullptr, options.game.width, options.game.height);
|
||||
@@ -107,7 +125,7 @@ void Screen::render()
|
||||
game_surface_->copyToTexture(renderer_, game_texture_);
|
||||
|
||||
// Renderiza sobre gameCanvas los overlays
|
||||
renderNotifications();
|
||||
//renderNotifications();
|
||||
|
||||
// Si está el borde activo, vuelca gameCanvas sobre borderCanvas
|
||||
if (options.video.border.enabled)
|
||||
|
||||
@@ -18,9 +18,15 @@ Surface::Surface(std::shared_ptr<SurfaceData> surface_dest, int w, int h)
|
||||
|
||||
Surface::Surface(std::shared_ptr<SurfaceData> surface_dest, const std::string &file_path)
|
||||
: surface_data_dest_(surface_dest),
|
||||
surface_data_(std::make_shared<SurfaceData>(loadSurface(Asset::get()->get(file_path)))),
|
||||
original_surface_data_(surface_data_),
|
||||
transparent_color_(0) {}
|
||||
transparent_color_(0)
|
||||
{
|
||||
// Carga la SurfaceData
|
||||
SurfaceData loadedData = loadSurface(file_path);
|
||||
surface_data_ = std::make_shared<SurfaceData>(std::move(loadedData));
|
||||
|
||||
// Inicializa el puntero original
|
||||
original_surface_data_ = surface_data_;
|
||||
}
|
||||
|
||||
Surface::~Surface() {}
|
||||
|
||||
@@ -54,6 +60,7 @@ SurfaceData Surface::loadSurface(const std::string &file_path)
|
||||
}
|
||||
|
||||
// Crear y devolver directamente el objeto SurfaceData
|
||||
printWithDots("Surface : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
||||
return SurfaceData(w, h, pixels);
|
||||
}
|
||||
|
||||
@@ -85,13 +92,8 @@ void Surface::loadPalette(const std::string &file_path)
|
||||
}
|
||||
|
||||
// Copiar los datos de la paleta al std::array
|
||||
printWithDots("Palette : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
||||
std::copy(pal.get(), pal.get() + palette_.size(), palette_.begin());
|
||||
|
||||
for (auto p : palette_)
|
||||
{
|
||||
std::cout << std::hex << p << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// Establece un color en la paleta
|
||||
@@ -128,7 +130,8 @@ Uint8 Surface::getPixel(int x, int y)
|
||||
// Dibuja un rectangulo
|
||||
void Surface::fillRect(std::shared_ptr<SurfaceData> surface_data, SDL_Rect *rect, Uint8 color)
|
||||
{
|
||||
if (!rect) return; // Verificar si el rectángulo es válido
|
||||
if (!rect)
|
||||
return; // Verificar si el rectángulo es válido
|
||||
|
||||
// Limitar los valores del rectángulo al tamaño de la superficie
|
||||
int x_start = std::max(0, rect->x);
|
||||
|
||||
@@ -586,22 +586,4 @@ void fillTextureWithColor(SDL_Renderer *renderer, SDL_Texture *texture, Uint8 r,
|
||||
|
||||
// Restaurar el render target previo
|
||||
SDL_SetRenderTarget(renderer, previous_target);
|
||||
}
|
||||
|
||||
// Crea un SDL_Texture
|
||||
SDL_Texture *createTexture(SDL_Renderer *renderer, int width, int height, Uint32 format, int access, bool logError)
|
||||
{
|
||||
// Crear la textura
|
||||
SDL_Texture *texture = SDL_CreateTexture(renderer, format, access, width, height);
|
||||
if (texture == nullptr)
|
||||
{
|
||||
// Registrar el error si está habilitado
|
||||
if (logError)
|
||||
{
|
||||
std::cerr << "Error: Texture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
@@ -134,7 +134,4 @@ bool stringInVector(const std::vector<std::string> &vec, const std::string &str)
|
||||
void playMusic(const std::string &music_path);
|
||||
|
||||
// Rellena una textura de un color
|
||||
void fillTextureWithColor(SDL_Renderer *renderer, SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
|
||||
// Crea un SDL_Texture
|
||||
SDL_Texture *createTexture(SDL_Renderer *renderer, int width, int height, Uint32 format = SDL_PIXELFORMAT_RGBA8888, int access = SDL_TEXTUREACCESS_TARGET, bool logError = false);
|
||||
void fillTextureWithColor(SDL_Renderer *renderer, SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
Reference in New Issue
Block a user