- afegides les habitacions de tot el joc (buides)
- minimapa mostra els numeros d'habitacio - tecla per a fer captures de pantalla
This commit is contained in:
@@ -119,7 +119,7 @@ namespace Defaults::Localization {
|
||||
} // namespace Defaults::Localization
|
||||
|
||||
namespace Defaults::Game::Room {
|
||||
constexpr const char* INITIAL = "03.yaml"; // Habitación de inicio
|
||||
constexpr const char* INITIAL = "001.yaml"; // Habitación de inicio
|
||||
} // namespace Defaults::Game::Room
|
||||
|
||||
namespace Defaults::Game::Player {
|
||||
|
||||
@@ -1806,7 +1806,7 @@ auto MapEditor::setRoomProperty(const std::string& property, const std::string&
|
||||
try {
|
||||
int num = std::stoi(val);
|
||||
char buf[16];
|
||||
std::snprintf(buf, sizeof(buf), "%02d.yaml", num);
|
||||
std::snprintf(buf, sizeof(buf), "%03d.yaml", num);
|
||||
connection = buf;
|
||||
} catch (...) {
|
||||
connection = val;
|
||||
@@ -1937,7 +1937,7 @@ auto MapEditor::createNewRoom(const std::string& direction) -> std::string { //
|
||||
int new_num = 1;
|
||||
while (used.contains(new_num)) { ++new_num; }
|
||||
char name_buf[16];
|
||||
std::snprintf(name_buf, sizeof(name_buf), "%02d.yaml", new_num);
|
||||
std::snprintf(name_buf, sizeof(name_buf), "%03d.yaml", new_num);
|
||||
std::string new_name = name_buf;
|
||||
|
||||
// Derivar la ruta de la carpeta de rooms
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
|
||||
#include "core/rendering/screen.hpp" // Para Screen
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/rendering/screenshot.hpp" // Para Screenshot::save
|
||||
#include "core/rendering/text.hpp" // Para Text (números de room)
|
||||
#include "core/resources/resource_cache.hpp" // Para Resource::Cache
|
||||
#include "game/gameplay/room.hpp" // Para Room::Data
|
||||
#include "utils/defines.hpp" // Para Tile::SIZE, PlayArea
|
||||
@@ -283,6 +285,25 @@ void MiniMap::drawConnections() {
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja los números de room centrados en cada celda
|
||||
void MiniMap::renderRoomNumbers(float offset_x, float offset_y) {
|
||||
auto text = Resource::Cache::get()->getText("8bithud");
|
||||
if (!text) { return; }
|
||||
|
||||
int font_h = text->getCharacterSize();
|
||||
|
||||
for (const auto& [name, mini] : room_positions_) {
|
||||
// "001.yaml" → "001"
|
||||
std::string number = name.substr(0, name.find_last_of('.'));
|
||||
|
||||
int text_w = text->length(number);
|
||||
int text_x = static_cast<int>(offset_x) + cellPixelX(mini.pos.x) + (CELL_W - text_w) / 2;
|
||||
int text_y = static_cast<int>(offset_y) + cellPixelY(mini.pos.y) + (CELL_H - font_h) / 2;
|
||||
|
||||
text->writeDX(Text::COLOR_FLAG | Text::SHADOW_FLAG, text_x, text_y, number, 1, COLOR_NUMBER_TEXT, 1, COLOR_NUMBER_SHADOW);
|
||||
}
|
||||
}
|
||||
|
||||
// Centra el viewport en una room
|
||||
void MiniMap::centerOnRoom(const std::string& room_name) {
|
||||
auto it = room_positions_.find(room_name);
|
||||
@@ -324,6 +345,9 @@ void MiniMap::render(const std::string& current_room) {
|
||||
SDL_FRect dst = {.x = vx, .y = vy, .w = static_cast<float>(map_width_ + SHADOW_OFFSET), .h = static_cast<float>(map_height_ + SHADOW_OFFSET)};
|
||||
map_surface_->render(nullptr, &dst);
|
||||
|
||||
// Números de room (sobre la surface del mapa, antes del highlight)
|
||||
if (show_numbers_) { renderRoomNumbers(vx, vy); }
|
||||
|
||||
// Highlight de la room actual (solo si está completamente visible en el play area)
|
||||
auto it = room_positions_.find(current_room);
|
||||
if (it != room_positions_.end()) {
|
||||
@@ -340,6 +364,32 @@ void MiniMap::render(const std::string& current_room) {
|
||||
|
||||
// Maneja eventos del minimapa (drag para explorar, click para navegar)
|
||||
void MiniMap::handleEvent(const SDL_Event& event, const std::string& current_room) {
|
||||
// Toggle de números de room
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_N && static_cast<int>(event.key.repeat) == 0) {
|
||||
show_numbers_ = !show_numbers_;
|
||||
return;
|
||||
}
|
||||
|
||||
// Captura del minimapa
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_S && static_cast<int>(event.key.repeat) == 0) {
|
||||
if (map_surface_) {
|
||||
// Renderizar números sobre map_surface_ si están activos
|
||||
if (show_numbers_) {
|
||||
auto prev = Screen::get()->getRendererSurface();
|
||||
Screen::get()->setRendererSurface(map_surface_);
|
||||
renderRoomNumbers(0.0F, 0.0F);
|
||||
Screen::get()->setRendererSurface(prev);
|
||||
}
|
||||
auto game_surface = Screen::get()->getRendererSurface();
|
||||
if (game_surface) { map_surface_->setPalette(game_surface->getPalette()); }
|
||||
std::string file = Screenshot::save(*map_surface_);
|
||||
if (!file.empty()) { std::cout << "MiniMap screenshot: " << file << "\n"; }
|
||||
// Recomponer para limpiar los números de la surface
|
||||
if (show_numbers_) { composeFinalSurface(); }
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN && event.button.button == SDL_BUTTON_LEFT) {
|
||||
// Guardar posición inicial para detectar si es click o drag
|
||||
float mouse_x = 0.0F;
|
||||
|
||||
@@ -62,6 +62,7 @@ class MiniMap {
|
||||
void composeFinalSurface();
|
||||
auto getRoomMiniSurface(const std::string& room_name) -> std::shared_ptr<Surface>;
|
||||
void drawConnections();
|
||||
void renderRoomNumbers(float offset_x, float offset_y);
|
||||
auto roomAtScreen(float screen_x, float screen_y) -> std::string;
|
||||
auto cellPixelX(int grid_x) const -> int { return PADDING + ((grid_x - min_grid_x_) * (CELL_W + GAP)); }
|
||||
auto cellPixelY(int grid_y) const -> int { return PADDING + ((grid_y - min_grid_y_) * (CELL_H + GAP)); }
|
||||
@@ -89,6 +90,7 @@ class MiniMap {
|
||||
float drag_start_y_{0.0F};
|
||||
float view_start_x_{0.0F}; // Viewport al inicio del drag
|
||||
float view_start_y_{0.0F};
|
||||
bool show_numbers_{false}; // Toggle para mostrar números de room
|
||||
|
||||
// Constantes
|
||||
static constexpr int ROOM_W = Map::WIDTH; // Ancho de una room en pixels del minimapa (1 pixel por tile)
|
||||
@@ -103,8 +105,10 @@ class MiniMap {
|
||||
// Colores del minimapa (índices de paleta)
|
||||
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_ROOM_BORDER = 0; // Borde de cada miniroom
|
||||
static constexpr Uint8 COLOR_SHADOW = 1; // Sombra de cada miniroom
|
||||
static constexpr Uint8 COLOR_NUMBER_TEXT = 15; // Texto de números (blanco)
|
||||
static constexpr Uint8 COLOR_NUMBER_SHADOW = 1; // Sombra de números (oscuro)
|
||||
};
|
||||
|
||||
#endif // _DEBUG
|
||||
|
||||
@@ -100,7 +100,7 @@ void RoomFormat::parseRoomConfig(const fkyaml::node& yaml, Room::Data& room, con
|
||||
|
||||
const auto& room_node = yaml["room"];
|
||||
|
||||
// Extract room number from filename (e.g., "01.yaml" → "01")
|
||||
// Extract room number from filename (e.g., "001.yaml" → "001")
|
||||
room.number = file_name.substr(0, file_name.find_last_of('.'));
|
||||
|
||||
// --- Resolución de zona + overrides (tileSetFile, music) ---
|
||||
|
||||
@@ -583,7 +583,7 @@ static auto changeRoomWithEditor(const std::string& room_file) -> std::string {
|
||||
|
||||
static auto cmdRoom(const std::vector<std::string>& args) -> std::string { // NOLINT(readability-function-cognitive-complexity)
|
||||
if (SceneManager::current != SceneManager::Scene::GAME) { return "Only available in GAME scene"; }
|
||||
if (args.empty()) { return "usage: room <1-60>|next|prev|left|right|up|down"; }
|
||||
if (args.empty()) { return "usage: room <num>|next|prev|left|right|up|down"; }
|
||||
|
||||
// DELETE: borrar la habitación actual
|
||||
if (args[0] == "DELETE") {
|
||||
@@ -619,11 +619,11 @@ static auto cmdRoom(const std::vector<std::string>& args) -> std::string { // N
|
||||
} else {
|
||||
try {
|
||||
num = std::stoi(args[0]);
|
||||
} catch (...) { return "usage: room <1-60>|next|prev|left|right|up|down"; }
|
||||
} catch (...) { return "usage: room <num>|next|prev|left|right|up|down"; }
|
||||
}
|
||||
if (num < 1 || num > 60) { return "Room must be between 1 and 60"; }
|
||||
if (num < 0) { return "Room number must be >= 0"; }
|
||||
char buf[16];
|
||||
std::snprintf(buf, sizeof(buf), "%02d.yaml", num);
|
||||
std::snprintf(buf, sizeof(buf), "%03d.yaml", num);
|
||||
return changeRoomWithEditor(buf);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user