segon commit
This commit is contained in:
103
source/game/editor/mini_map.hpp
Normal file
103
source/game/editor/mini_map.hpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <functional> // Para function
|
||||
#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:
|
||||
explicit MiniMap(Uint8 bg_color = 2, Uint8 conn_color = 14);
|
||||
~MiniMap() = default;
|
||||
|
||||
void render(const std::string& current_room);
|
||||
void handleEvent(const SDL_Event& event, const std::string& current_room);
|
||||
void rebuild(Uint8 bg_color, Uint8 conn_color);
|
||||
void centerOnRoom(const std::string& room_name);
|
||||
[[nodiscard]] auto isReady() const -> bool { return !room_positions_.empty(); }
|
||||
|
||||
// Callback al hacer click en una minihabitación (nombre del room)
|
||||
std::function<void(const std::string&)> on_navigate;
|
||||
|
||||
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 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)); }
|
||||
|
||||
// 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
|
||||
Uint8 tileset_transparent_{16}; // Color transparente del tileset
|
||||
|
||||
// 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};
|
||||
|
||||
// Viewport: offset de la surface del minimapa respecto al play area
|
||||
float view_x_{0.0F}; // Offset X actual
|
||||
float view_y_{0.0F}; // Offset Y actual
|
||||
bool dragging_{false};
|
||||
float drag_start_x_{0.0F}; // Posición del ratón al inicio del drag
|
||||
float drag_start_y_{0.0F};
|
||||
float view_start_x_{0.0F}; // Viewport al inicio del drag
|
||||
float view_start_y_{0.0F};
|
||||
|
||||
// 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)
|
||||
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
|
||||
};
|
||||
|
||||
#endif // _DEBUG
|
||||
Reference in New Issue
Block a user