86 lines
3.1 KiB
C++
86 lines
3.1 KiB
C++
#pragma once
|
|
|
|
#ifdef _DEBUG
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <memory> // Para shared_ptr
|
|
#include <string> // Para string
|
|
#include <unordered_map> // Para unordered_map
|
|
#include <vector> // Para vector
|
|
|
|
class Surface;
|
|
|
|
/**
|
|
* @brief Minimapa global del juego para el editor
|
|
*
|
|
* Genera una vista en miniatura de todas las habitaciones del juego,
|
|
* posicionadas según sus conexiones.
|
|
* Cada tile del mapa se representa como 1 pixel del color predominante de ese tile.
|
|
* Resultado: cada room = 32x16 pixels.
|
|
*/
|
|
class MiniMap {
|
|
public:
|
|
MiniMap();
|
|
~MiniMap() = default;
|
|
|
|
void render(const std::string& current_room); // Dibuja el minimapa centrado en la room actual
|
|
[[nodiscard]] auto isReady() const -> bool { return !room_positions_.empty(); }
|
|
|
|
private:
|
|
// Posición de una room en el grid del minimapa
|
|
struct GridPos {
|
|
int x{0};
|
|
int y{0};
|
|
};
|
|
|
|
// Una room renderizada
|
|
struct RoomMini {
|
|
std::shared_ptr<Surface> surface; // 32x16 pixels
|
|
GridPos pos; // Posición en el grid
|
|
};
|
|
|
|
void buildTileColorTable(const std::string& tileset_name);
|
|
void buildRoomSurfaces();
|
|
void layoutRooms();
|
|
void composeFinalSurface();
|
|
auto getRoomMiniSurface(const std::string& room_name) -> std::shared_ptr<Surface>;
|
|
void drawConnections();
|
|
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); }
|
|
|
|
// Tabla de color predominante por tile index
|
|
std::vector<Uint8> tile_colors_; // tile_index → palette color index
|
|
int tileset_width_{0}; // Ancho del tileset en tiles
|
|
|
|
// Rooms renderizadas y posicionadas
|
|
std::unordered_map<std::string, RoomMini> room_positions_;
|
|
|
|
// Surface final compuesta
|
|
std::shared_ptr<Surface> map_surface_;
|
|
int map_width_{0}; // Ancho en pixels
|
|
int map_height_{0}; // Alto en pixels
|
|
|
|
// Offset para normalizar coordenadas
|
|
int min_grid_x_{0};
|
|
int min_grid_y_{0};
|
|
|
|
// Constantes
|
|
static constexpr int ROOM_W = 32; // Ancho de una room en pixels del minimapa
|
|
static constexpr int ROOM_H = 16; // Alto de una room en pixels del minimapa
|
|
static constexpr int BORDER = 1; // Borde alrededor de cada room
|
|
static constexpr int CELL_W = ROOM_W + BORDER * 2; // Room + borde
|
|
static constexpr int CELL_H = ROOM_H + BORDER * 2;
|
|
static constexpr int GAP = 4; // Separación entre celdas
|
|
static constexpr int SHADOW_OFFSET = 1; // Desplazamiento de la sombra
|
|
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)
|
|
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
|