From b5e822c65fe66d0209d34fefba7defab7a055bee Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 2 Apr 2026 19:16:01 +0200 Subject: [PATCH] retocs sucosets al minimap --- data/console/commands.yaml | 5 ++-- source/game/editor/map_editor.cpp | 36 ++++++++++++++++++++++++++++- source/game/editor/map_editor.hpp | 4 ++++ source/game/editor/mini_map.cpp | 31 ++++++++++++++----------- source/game/editor/mini_map.hpp | 9 ++++---- source/game/ui/console_commands.cpp | 13 ++++++++++- 6 files changed, 76 insertions(+), 22 deletions(-) diff --git a/data/console/commands.yaml b/data/console/commands.yaml index afeeb3b..bdfd3b0 100644 --- a/data/console/commands.yaml +++ b/data/console/commands.yaml @@ -215,9 +215,10 @@ categories: - keyword: EDIT handler: cmd_edit description: "Map editor mode (GAME only)" - usage: "EDIT [ON|OFF|REVERT|SHOW|HIDE] [INFO|GRID]" + usage: "EDIT [ON|OFF|REVERT|SHOW|HIDE|MAPBG] [...]" + dynamic_completions: true completions: - EDIT: [ON, OFF, REVERT, SHOW, HIDE] + EDIT: [ON, OFF, REVERT, SHOW, HIDE, MAPBG, MAPCONN] EDIT SHOW: [INFO, GRID] EDIT HIDE: [INFO, GRID] diff --git a/source/game/editor/map_editor.cpp b/source/game/editor/map_editor.cpp index bcfa4d5..3b9ebaf 100644 --- a/source/game/editor/map_editor.cpp +++ b/source/game/editor/map_editor.cpp @@ -64,6 +64,14 @@ void MapEditor::loadSettings() { auto yaml = fkyaml::node::deserialize(content); if (yaml.contains("grid")) { settings_.grid = yaml["grid"].get_value(); } if (yaml.contains("show_render_info")) { settings_.show_render_info = yaml["show_render_info"].get_value(); } + if (yaml.contains("minimap_bg")) { + if (yaml["minimap_bg"].is_string()) { settings_.minimap_bg = yaml["minimap_bg"].get_value(); } + else if (yaml["minimap_bg"].is_integer()) { settings_.minimap_bg = std::to_string(yaml["minimap_bg"].get_value()); } + } + if (yaml.contains("minimap_conn")) { + if (yaml["minimap_conn"].is_string()) { settings_.minimap_conn = yaml["minimap_conn"].get_value(); } + else if (yaml["minimap_conn"].is_integer()) { settings_.minimap_conn = std::to_string(yaml["minimap_conn"].get_value()); } + } } catch (...) { // Fichero corrupto o vacío, usar defaults } @@ -80,6 +88,8 @@ void MapEditor::saveSettings() { 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: " << settings_.minimap_bg << "\n"; + file << "minimap_conn: " << settings_.minimap_conn << "\n"; file.close(); } @@ -100,13 +110,37 @@ auto MapEditor::showGrid(bool show) -> std::string { return show ? "Grid ON" : "Grid OFF"; } +// Parsea un color por nombre o índice numérico +static auto parseColor(const std::string& value) -> Uint8 { + try { return static_cast(std::stoi(value)); } + catch (...) { return stringToColor(value); } +} + void MapEditor::toggleMiniMap() { if (!mini_map_) { - mini_map_ = std::make_unique(); + mini_map_ = std::make_unique(parseColor(settings_.minimap_bg), parseColor(settings_.minimap_conn)); } mini_map_visible_ = !mini_map_visible_; } +auto MapEditor::setMiniMapBg(const std::string& color) -> std::string { + settings_.minimap_bg = toLower(color); + saveSettings(); + if (mini_map_) { + mini_map_->rebuild(parseColor(settings_.minimap_bg), parseColor(settings_.minimap_conn)); + } + return "minimap bg: " + settings_.minimap_bg; +} + +auto MapEditor::setMiniMapConn(const std::string& color) -> std::string { + settings_.minimap_conn = toLower(color); + saveSettings(); + if (mini_map_) { + mini_map_->rebuild(parseColor(settings_.minimap_bg), parseColor(settings_.minimap_conn)); + } + return "minimap conn: " + settings_.minimap_conn; +} + // Entra en modo editor void MapEditor::enter(std::shared_ptr room, std::shared_ptr player, const std::string& room_path, std::shared_ptr scoreboard_data) { if (active_) { return; } diff --git a/source/game/editor/map_editor.hpp b/source/game/editor/map_editor.hpp index e45dd40..743ec51 100644 --- a/source/game/editor/map_editor.hpp +++ b/source/game/editor/map_editor.hpp @@ -49,6 +49,8 @@ class MapEditor { auto showGrid(bool show) -> std::string; [[nodiscard]] auto isGridEnabled() const -> bool { return settings_.grid; } void toggleMiniMap(); + auto setMiniMapBg(const std::string& color) -> std::string; + auto setMiniMapConn(const std::string& color) -> std::string; // Comandos para items auto setItemProperty(const std::string& property, const std::string& value) -> std::string; @@ -68,6 +70,8 @@ class MapEditor { struct Settings { bool grid{false}; bool show_render_info{false}; + std::string minimap_bg{"blue"}; + std::string minimap_conn{"white"}; }; Settings settings_; void loadSettings(); diff --git a/source/game/editor/mini_map.cpp b/source/game/editor/mini_map.cpp index eae4406..0ca063d 100644 --- a/source/game/editor/mini_map.cpp +++ b/source/game/editor/mini_map.cpp @@ -17,13 +17,20 @@ #include "utils/utils.hpp" // Para stringToColor // Constructor: construye todo el minimapa -MiniMap::MiniMap() { +MiniMap::MiniMap(Uint8 bg_color, Uint8 conn_color) : bg_color_(bg_color), conn_color_(conn_color) { buildTileColorTable("standard.gif"); layoutRooms(); buildRoomSurfaces(); composeFinalSurface(); } +// Regenera la surface final con nuevo color de fondo +void MiniMap::rebuild(Uint8 bg_color, Uint8 conn_color) { + bg_color_ = bg_color; + conn_color_ = conn_color; + composeFinalSurface(); +} + // Analiza el tileset y crea tabla: tile_index → color predominante void MiniMap::buildTileColorTable(const std::string& tileset_name) { auto tileset = Resource::Cache::get()->getSurface(tileset_name); @@ -196,7 +203,7 @@ void MiniMap::composeFinalSurface() { Screen::get()->setRendererSurface(map_surface_); // 1. Fondo general - map_surface_->clear(COLOR_BACKGROUND); + map_surface_->clear(bg_color_); // 2. Líneas de conexión entre rooms (debajo de todo) drawConnections(); @@ -240,22 +247,22 @@ void MiniMap::drawConnections() { int px = cellPixelX(mini.pos.x); int py = cellPixelY(mini.pos.y); - // Conexión derecha: línea horizontal desde el borde derecho de esta room hasta el borde izquierdo de la vecina + // Conexión derecha if (room_data->right_room != "0" && !room_data->right_room.empty() && room_positions_.contains(room_data->right_room)) { int x1 = px + CELL_W; - int y_mid = py + CELL_H / 2; + int y_mid = py + CELL_H / 2 - 1; SDL_FRect line = {.x = static_cast(x1), .y = static_cast(y_mid), - .w = static_cast(GAP), .h = 1.0F}; - map_surface_->fillRect(&line, COLOR_CONNECTION); + .w = static_cast(GAP), .h = 3.0F}; + map_surface_->fillRect(&line, conn_color_); } - // Conexión abajo: línea vertical desde el borde inferior de esta room hasta el borde superior de la vecina + // Conexión abajo if (room_data->lower_room != "0" && !room_data->lower_room.empty() && room_positions_.contains(room_data->lower_room)) { - int x_mid = px + CELL_W / 2; + int x_mid = px + CELL_W / 2 - 1; int y1 = py + CELL_H; SDL_FRect line = {.x = static_cast(x_mid), .y = static_cast(y1), - .w = 1.0F, .h = static_cast(GAP)}; - map_surface_->fillRect(&line, COLOR_CONNECTION); + .w = 3.0F, .h = static_cast(GAP)}; + map_surface_->fillRect(&line, conn_color_); } } } @@ -267,10 +274,6 @@ void MiniMap::render(const std::string& current_room) { auto game_surface = Screen::get()->getRendererSurface(); if (!game_surface) { return; } - // Fondo negro en el play area - SDL_FRect bg = {.x = 0, .y = 0, .w = static_cast(PlayArea::WIDTH), .h = static_cast(PlayArea::HEIGHT)}; - game_surface->fillRect(&bg, 0); - // Centrar el minimapa en el play area, centrado en la room actual auto it = room_positions_.find(current_room); if (it == room_positions_.end()) { return; } diff --git a/source/game/editor/mini_map.hpp b/source/game/editor/mini_map.hpp index 4079412..3d6c9d0 100644 --- a/source/game/editor/mini_map.hpp +++ b/source/game/editor/mini_map.hpp @@ -21,10 +21,11 @@ class Surface; */ class MiniMap { public: - MiniMap(); + explicit MiniMap(Uint8 bg_color = 2, Uint8 conn_color = 14); ~MiniMap() = default; - void render(const std::string& current_room); // Dibuja el minimapa centrado en la room actual + void render(const std::string& current_room); + void rebuild(Uint8 bg_color, Uint8 conn_color); // Regenera la surface final [[nodiscard]] auto isReady() const -> bool { return !room_positions_.empty(); } private: @@ -76,10 +77,10 @@ class MiniMap { static constexpr int PADDING = 4; // Padding alrededor del minimapa // Colores del minimapa (índices de paleta) - static constexpr Uint8 COLOR_BACKGROUND = 2; // Fondo general (blue, si border es 0 usamos 2) + Uint8 bg_color_{2}; // Fondo general (configurable) + Uint8 conn_color_{14}; // Líneas de conexión (configurable) static constexpr Uint8 COLOR_ROOM_BORDER = 0; // Borde de cada miniroom static constexpr Uint8 COLOR_SHADOW = 1; // Sombra de cada miniroom - static constexpr Uint8 COLOR_CONNECTION = 14; // Líneas de conexión entre rooms }; #endif // _DEBUG diff --git a/source/game/ui/console_commands.cpp b/source/game/ui/console_commands.cpp index 8a9929c..57765af 100644 --- a/source/game/ui/console_commands.cpp +++ b/source/game/ui/console_commands.cpp @@ -709,7 +709,16 @@ static auto cmd_edit(const std::vector& args) -> std::string { if (args[1] == "INFO") { return MapEditor::get()->showInfo(show); } if (args[1] == "GRID") { return MapEditor::get()->showGrid(show); } } - return "usage: edit [on|off|revert|show|hide] [info|grid]"; + // EDIT MAPBG/MAPCONN + if (args[0] == "MAPBG" && args.size() >= 2) { + if (!MapEditor::get() || !MapEditor::get()->isActive()) { return "Editor not active"; } + return MapEditor::get()->setMiniMapBg(args[1]); + } + if (args[0] == "MAPCONN" && args.size() >= 2) { + if (!MapEditor::get() || !MapEditor::get()->isActive()) { return "Editor not active"; } + return MapEditor::get()->setMiniMapConn(args[1]); + } + return "usage: edit [on|off|revert|show|hide|mapbg|mapconn] [...]"; } // SET — modifica propiedad del enemigo seleccionado o de la habitación @@ -1007,6 +1016,8 @@ void CommandRegistry::registerHandlers() { }; dynamic_providers_["SET COLOR"] = color_provider; dynamic_providers_["SET BGCOLOR"] = color_provider; + dynamic_providers_["EDIT MAPBG"] = color_provider; + dynamic_providers_["EDIT MAPCONN"] = color_provider; dynamic_providers_["SET BORDER"] = color_provider; dynamic_providers_["SET ITEMCOLOR1"] = color_provider; dynamic_providers_["SET ITEMCOLOR2"] = color_provider;