ajustos de qualitat, canvi de tecles, persistencia de opcions, etc

This commit is contained in:
2026-04-11 09:16:39 +02:00
parent 3b052ca3a0
commit 49f6ed41e6
19 changed files with 149 additions and 157 deletions

View File

@@ -9,6 +9,9 @@
#include "core/locale/locale.hpp" // Para Locale
#include "core/rendering/render_info.hpp" // Para RenderInfo
#include "core/rendering/screen.hpp" // Para Screen
#ifdef _DEBUG
#include "core/system/debug.hpp" // Para Debug (persistencia de render_info en debug.yaml)
#endif
#include "game/options.hpp" // Para Options, options, OptionsVideo, Section
#include "game/scene_manager.hpp" // Para SceneManager
#include "game/ui/console.hpp" // Para Console
@@ -292,7 +295,16 @@ namespace GlobalInputs {
break;
case InputAction::TOGGLE_INFO:
if (RenderInfo::get() != nullptr) { RenderInfo::get()->toggle(); }
if (RenderInfo::get() != nullptr) {
// Leemos la intención antes del toggle: isActive() incluye la
// animación VANISHING, así que justo después de un toggle ACTIVE→OFF
// seguiría devolviendo true y la persistencia no detectaría el cambio.
const bool WAS_ACTIVE = RenderInfo::get()->isActive();
RenderInfo::get()->toggle();
#ifdef _DEBUG
if (Debug::get() != nullptr) { Debug::get()->setRenderInfoEnabled(!WAS_ACTIVE); }
#endif
}
break;
case InputAction::NONE:

View File

@@ -178,6 +178,13 @@ void Debug::loadFromFile() {
if (needs_save) { saveToFile(); }
}
// Persiste el estado del overlay RenderInfo en debug.yaml
void Debug::setRenderInfoEnabled(bool value) {
if (render_info_enabled_ == value) { return; }
render_info_enabled_ = value;
saveToFile();
}
// Guarda la configuración de debug en debug.yaml
void Debug::saveToFile() const {
std::ofstream file(debug_file_path_);

View File

@@ -49,6 +49,7 @@ class Debug {
void setInitialScene(SceneManager::Scene s) { initial_scene_ = s; } // Establece la escena inicial de debug
[[nodiscard]] auto getLazyLoading() const -> bool { return lazy_loading_; } // Indica si el modo lazy de recursos está activo
[[nodiscard]] auto getRenderInfoEnabled() const -> bool { return render_info_enabled_; } // Indica si el overlay RenderInfo arranca activo
void setRenderInfoEnabled(bool value); // Persiste el estado del overlay RenderInfo en debug.yaml
private:
static Debug* debug; // [SINGLETON] Objeto privado

View File

@@ -20,6 +20,7 @@
#include "core/resources/resource_cache.hpp" // Para Resource::Cache
#include "core/resources/resource_list.hpp" // Para Resource::List
#include "core/resources/resource_types.hpp" // Para RoomResource
#include "core/system/debug.hpp" // Para Debug (persistencia de render_info)
#include "external/fkyaml_node.hpp" // Para fkyaml::node (loadSettings)
#include "game/editor/editor_statusbar.hpp" // Para EditorStatusBar
#include "game/entities/player.hpp" // Para Player
@@ -76,7 +77,6 @@ void MapEditor::loadSettings() {
try {
auto yaml = fkyaml::node::deserialize(content);
if (yaml.contains("grid")) { settings_.grid = yaml["grid"].get_value<bool>(); }
if (yaml.contains("show_render_info")) { settings_.show_render_info = yaml["show_render_info"].get_value<bool>(); }
if (yaml.contains("minimap_bg")) {
if (yaml["minimap_bg"].is_integer()) {
settings_.minimap_bg = static_cast<Uint8>(yaml["minimap_bg"].get_value<int>());
@@ -106,19 +106,17 @@ void MapEditor::saveSettings() const {
file << "# Map Editor Settings\n";
file << "grid: " << (settings_.grid ? "true" : "false") << "\n";
file << "show_render_info: " << (settings_.show_render_info ? "true" : "false") << "\n";
file << "minimap_bg: " << static_cast<int>(settings_.minimap_bg) << "\n";
file << "minimap_conn: " << static_cast<int>(settings_.minimap_conn) << "\n";
file.close();
}
// Muestra/oculta render info (persistente)
// Muestra/oculta render info (persistente en debug.yaml, fuente de verdad global)
auto MapEditor::showInfo(bool show) -> std::string {
settings_.show_render_info = show;
if (RenderInfo::get()->isActive() != show) {
RenderInfo::get()->toggle();
}
saveSettings();
if (Debug::get() != nullptr) { Debug::get()->setRenderInfoEnabled(show); }
return show ? "Info ON" : "Info OFF";
}
@@ -203,18 +201,12 @@ void MapEditor::enter(std::shared_ptr<Room> room, std::shared_ptr<Player> player
if (!reenter_) {
// Solo guardar estado previo en el primer enter (no en re-enter tras cambio de room)
invincible_before_editor_ = Options::cheats.invincible;
render_info_before_editor_ = RenderInfo::get()->isActive();
}
reenter_ = false;
// Forzar invencibilidad
Options::cheats.invincible = Options::Cheat::State::ENABLED;
// Aplicar el setting de render_info del editor
if (settings_.show_render_info != RenderInfo::get()->isActive()) {
RenderInfo::get()->toggle();
}
// Activar scope de la consola para el editor
Console::get()->setScope("editor");
@@ -256,10 +248,6 @@ void MapEditor::exit() {
if (!reenter_) {
// Solo restaurar en el exit final (no en cambio de room)
Options::cheats.invincible = invincible_before_editor_;
if (RenderInfo::get()->isActive() != render_info_before_editor_) {
RenderInfo::get()->toggle();
}
}
// Restaurar prompt y scope de la consola
@@ -443,8 +431,13 @@ void MapEditor::render() {
// Maneja eventos del editor
void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-function-cognitive-complexity)
// Si el tile picker está abierto, los eventos van a él
// Si el tile picker está abierto, los eventos van a él.
// Excepción: la T lo cierra como toggle (sin tocar el brush).
if (tile_picker_.isOpen()) {
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_T && static_cast<int>(event.key.repeat) == 0) {
tile_picker_.close();
return;
}
tile_picker_.handleEvent(event);
return;
}
@@ -528,7 +521,7 @@ void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-fun
}
}
// T: abrir TilePicker
// T: abrir TilePicker (el cierre con T también se gestiona arriba, antes de delegar al picker)
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_T && static_cast<int>(event.key.repeat) == 0) {
// Deseleccionar entidades
selection_.clear();
@@ -1464,7 +1457,8 @@ void MapEditor::updateStatusBarInfo() { // NOLINT(readability-function-cognitiv
// Propiedades de la habitación
std::string ts_marker = room_data_.tile_set_overridden ? " (ts*)" : "";
std::string mu_marker = room_data_.music_overridden ? " (mu*)" : "";
line2 = "zone:" + room_data_.zone + ts_marker + mu_marker;
std::string bg_marker = room_data_.bg_color_overridden ? "*" : "";
line2 = "zone:" + room_data_.zone + ts_marker + mu_marker + " bg:" + std::to_string(room_data_.bg_color) + bg_marker;
line3 = "u:" + conn(room_data_.upper_room) + " d:" + conn(room_data_.lower_room) +
" l:" + conn(room_data_.left_room) + " r:" + conn(room_data_.right_room);
break;
@@ -1509,7 +1503,7 @@ auto MapEditor::getSetCompletions() const -> std::vector<std::string> {
case EntityType::DOOR:
return {"ID", "ANIMATION"};
default:
return {"ZONE", "TILESET", "MUSIC", "UP", "DOWN", "LEFT", "RIGHT"};
return {"ZONE", "TILESET", "MUSIC", "BGCOLOR", "UP", "DOWN", "LEFT", "RIGHT"};
}
}
@@ -1733,6 +1727,10 @@ auto MapEditor::setRoomProperty(const std::string& property, const std::string&
if (!room_data_.music_overridden) {
room_data_.music = zone->music;
}
if (!room_data_.bg_color_overridden) {
room_data_.bg_color = zone->bg_color;
room_->setBgColor(zone->bg_color);
}
autosave();
return "zone: " + val;
}
@@ -1758,6 +1756,30 @@ auto MapEditor::setRoomProperty(const std::string& property, const std::string&
return "tileset: " + tileset;
}
if (property == "BGCOLOR") {
// "reset" / "none" limpia el override y vuelve a heredar de la zona
if (val == "reset" || val == "none") {
room_data_.bg_color_overridden = false;
const Zone::Data* zone = ZoneManager::get()->getZone(room_data_.zone);
if (zone != nullptr) {
room_data_.bg_color = zone->bg_color;
room_->setBgColor(zone->bg_color);
}
autosave();
return "bgcolor: (inherit from zone)";
}
int color = 0;
try {
color = std::stoi(val);
} catch (...) { return "usage: set bgcolor <0-255|reset>"; }
if (color < 0 || color > 255) { return "bgcolor must be 0-255"; }
room_data_.bg_color = static_cast<Uint8>(color);
room_data_.bg_color_overridden = true;
room_->setBgColor(static_cast<Uint8>(color));
autosave();
return "bgcolor: " + std::to_string(color);
}
if (property == "MUSIC") {
// "reset" / "none" limpia el override y vuelve a heredar de la zona
if (val == "reset" || val == "none") {
@@ -1875,7 +1897,7 @@ auto MapEditor::setRoomProperty(const std::string& property, const std::string&
return toLower(property) + ": " + connection;
}
return "Unknown property: " + property + " (use: zone, itemcolor1, itemcolor2, conveyor, tileset, music, up, down, left, right)";
return "Unknown property: " + property + " (use: zone, itemcolor1, itemcolor2, conveyor, tileset, music, bgcolor, up, down, left, right)";
}
// Crea una nueva habitación

View File

@@ -156,7 +156,6 @@ class MapEditor {
// Opciones persistentes del editor
struct Settings {
bool grid{false};
bool show_render_info{false};
Uint8 minimap_bg{2};
Uint8 minimap_conn{14};
};
@@ -257,8 +256,7 @@ class MapEditor {
// Estado previo (para restaurar al salir)
Options::Cheat::State invincible_before_editor_{Options::Cheat::State::DISABLED};
bool render_info_before_editor_{false};
bool reenter_{false}; // true cuando es un re-enter tras cambio de room (no tocar render_info)
bool reenter_{false}; // true cuando es un re-enter tras cambio de room
};
#endif // _DEBUG

View File

@@ -198,6 +198,17 @@ void Room::setTileSet(const std::string& tile_set_file) {
bg_color_);
tilemap_renderer_->initialize(collision_map_->getCollisionTileMap());
}
// Cambia el color de fondo en vivo (para editor)
void Room::setBgColor(Uint8 bg_color) {
bg_color_ = bg_color;
tilemap_renderer_ = std::make_unique<TilemapRenderer>(
tile_map_,
tile_set_width_,
surface_,
bg_color_);
tilemap_renderer_->initialize(collision_map_->getCollisionTileMap());
}
#endif
// Actualiza las variables y objetos de la habitación

View File

@@ -47,6 +47,7 @@ class Room {
std::string music; // Resuelto: zona o override del yaml
bool tile_set_overridden{false}; // True si el yaml tenía tileSetFile explícito
bool music_overridden{false}; // True si el yaml tenía music explícito
bool bg_color_overridden{false}; // True si el yaml tenía bgColor explícito
std::vector<int> tile_map;
std::vector<int> collision_tile_map;
std::vector<Enemy::Data> enemies;
@@ -85,6 +86,7 @@ class Room {
void setCollisionTile(int index, int value);
void setConnection(Border border, const std::string& room_name);
void setTileSet(const std::string& tile_set_file);
void setBgColor(Uint8 bg_color);
[[nodiscard]] auto getTileSetWidth() const -> int { return tile_set_width_; }
#endif
void update(float delta_time);

View File

@@ -136,6 +136,14 @@ void RoomFormat::parseRoomConfig(const fkyaml::node& yaml, Room::Data& room, con
room.music = zone->music;
}
// bgColor: zona, override si está en el yaml
if (room_node.contains("bgColor")) {
room.bg_color = readColorNode(room_node["bgColor"]);
room.bg_color_overridden = true;
} else if (zone != nullptr) {
room.bg_color = zone->bg_color;
}
// Room connections
if (room_node.contains("connections")) {
parseRoomConnections(room_node["connections"], room);
@@ -508,15 +516,17 @@ auto RoomFormat::loadFromString(const std::string& yaml_content, const std::stri
auto RoomFormat::createDefault() -> Room::Data {
Room::Data data;
// Zona por defecto (resuelve tile_set_file y music desde ZoneManager)
// Zona por defecto (resuelve tile_set_file, music y bg_color desde ZoneManager)
const Zone::Data* zone = ZoneManager::get()->getDefaultZone();
if (zone != nullptr) {
data.zone = zone->name;
data.tile_set_file = zone->tile_set_file;
data.music = zone->music;
data.bg_color = zone->bg_color;
}
data.tile_set_overridden = false;
data.music_overridden = false;
data.bg_color_overridden = false;
// Conexiones a cero
data.upper_room = "0";
@@ -559,6 +569,11 @@ auto RoomFormat::buildContent(const Room::Data& room_data) -> std::string { //
out << " music: " << room_data.music << "\n";
}
// bgColor solo si es override explícito del valor heredado de la zona
if (room_data.bg_color_overridden) {
out << " bgColor: " << static_cast<int>(room_data.bg_color) << "\n";
}
// Conexiones
out << "\n";
out << " # Conexiones de la habitación (null = sin conexión)\n";

View File

@@ -1,5 +1,7 @@
#pragma once
#include <SDL3/SDL.h>
#include <string> // Para string
/**
@@ -17,6 +19,7 @@ namespace Zone {
std::string name; // Nombre único de la zona (ej. "neighborhood", "cave")
std::string tile_set_file; // Fichero de tileset por defecto (ej. "neighborhood.gif")
std::string music; // Pista de música por defecto (ej. "574070_KUVO_Farewell_to_school.ogg")
Uint8 bg_color{0}; // Color de fondo por defecto (índice de paleta)
};
} // namespace Zone

View File

@@ -57,6 +57,9 @@ void ZoneManager::loadFromFile(const std::string& file_path) {
if (zone_node.contains("music")) {
zone.music = zone_node["music"].get_value<std::string>();
}
if (zone_node.contains("bgColor")) {
zone.bg_color = static_cast<Uint8>(zone_node["bgColor"].get_value<int>());
}
if (zone.name.empty()) {
std::cerr << "ZoneManager: skipping zone without name\n";

View File

@@ -850,6 +850,9 @@ static auto cmdShow(const std::vector<std::string>& args) -> std::string {
#endif
if (RenderInfo::get()->isActive()) { return "Info overlay already ON"; }
RenderInfo::get()->toggle();
#ifdef _DEBUG
if (Debug::get() != nullptr) { Debug::get()->setRenderInfoEnabled(true); }
#endif
return "Info overlay ON";
}
@@ -858,6 +861,9 @@ static auto cmdHide(const std::vector<std::string>& args) -> std::string {
if (args.empty() || args[0] != "INFO") { return "usage: hide [info]"; }
if (!RenderInfo::get()->isActive()) { return "Info overlay already OFF"; }
RenderInfo::get()->toggle();
#ifdef _DEBUG
if (Debug::get() != nullptr) { Debug::get()->setRenderInfoEnabled(false); }
#endif
return "Info overlay OFF";
}
@@ -1087,6 +1093,7 @@ void CommandRegistry::registerHandlers() { // NOLINT(readability-function-cogni
};
dynamic_providers_["SET ITEMCOLOR1"] = color_provider;
dynamic_providers_["SET ITEMCOLOR2"] = color_provider;
dynamic_providers_["SET BGCOLOR"] = color_provider;
// SET ANIMATION: animaciones disponibles para la entidad seleccionada en
// el editor. La lista la calcula MapEditor escaneando data/<carpeta>/ del