primera versió del editor de tiles
This commit is contained in:
@@ -81,6 +81,9 @@ void MapEditor::enter(std::shared_ptr<Room> room, std::shared_ptr<Player> player
|
||||
// Resetear estado
|
||||
drag_ = {};
|
||||
selected_enemy_ = -1;
|
||||
selected_item_ = -1;
|
||||
brush_tile_ = NO_BRUSH;
|
||||
painting_ = false;
|
||||
|
||||
active_ = true;
|
||||
std::cout << "MapEditor: ON (room " << room_path_ << ")\n";
|
||||
@@ -135,7 +138,14 @@ auto MapEditor::revert() -> std::string {
|
||||
room_->setBgColor(room_data_.bg_color);
|
||||
Screen::get()->setBorderColor(stringToColor(room_data_.border_color));
|
||||
|
||||
// Restaurar el tilemap completo
|
||||
for (int i = 0; i < static_cast<int>(room_data_.tile_map.size()); ++i) {
|
||||
room_->setTile(i, room_data_.tile_map[i]);
|
||||
}
|
||||
|
||||
selected_enemy_ = -1;
|
||||
selected_item_ = -1;
|
||||
brush_tile_ = NO_BRUSH;
|
||||
return "Reverted to original";
|
||||
}
|
||||
|
||||
@@ -171,6 +181,17 @@ void MapEditor::update(float delta_time) {
|
||||
updateDrag();
|
||||
}
|
||||
|
||||
// Si estamos pintando tiles, pintar en la posición actual del ratón
|
||||
if (painting_ && brush_tile_ != NO_BRUSH) {
|
||||
int tile_index = mouse_tile_y_ * 32 + mouse_tile_x_;
|
||||
if (tile_index >= 0 && tile_index < static_cast<int>(room_data_.tile_map.size())) {
|
||||
if (room_data_.tile_map[tile_index] != brush_tile_) {
|
||||
room_data_.tile_map[tile_index] = brush_tile_;
|
||||
room_->setTile(tile_index, brush_tile_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualizar la barra de estado
|
||||
updateStatusBarInfo();
|
||||
if (statusbar_) {
|
||||
@@ -212,10 +233,79 @@ void MapEditor::handleEvent(const SDL_Event& event) {
|
||||
return;
|
||||
}
|
||||
|
||||
// ESC: desactivar brush
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_ESCAPE && brush_tile_ != NO_BRUSH) {
|
||||
brush_tile_ = NO_BRUSH;
|
||||
return;
|
||||
}
|
||||
|
||||
// E: toggle borrador
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_E && static_cast<int>(event.key.repeat) == 0) {
|
||||
brush_tile_ = (brush_tile_ == ERASER_BRUSH) ? NO_BRUSH : ERASER_BRUSH;
|
||||
return;
|
||||
}
|
||||
|
||||
// Click derecho: abrir TilePicker del mapa
|
||||
if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN && event.button.button == SDL_BUTTON_RIGHT) {
|
||||
// Deseleccionar entidades
|
||||
selected_enemy_ = -1;
|
||||
selected_item_ = -1;
|
||||
|
||||
// Tile bajo el cursor como tile actual del picker
|
||||
int tile_index = mouse_tile_y_ * 32 + mouse_tile_x_;
|
||||
int current = (tile_index >= 0 && tile_index < static_cast<int>(room_data_.tile_map.size()))
|
||||
? room_data_.tile_map[tile_index]
|
||||
: -1;
|
||||
|
||||
tile_picker_.on_select = [this](int tile) {
|
||||
brush_tile_ = tile;
|
||||
};
|
||||
tile_picker_.open(room_->getTileSetFile(), current,
|
||||
stringToColor(room_data_.bg_color));
|
||||
return;
|
||||
}
|
||||
|
||||
// Click izquierdo
|
||||
if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN && event.button.button == SDL_BUTTON_LEFT) {
|
||||
// Si hay brush activo y no hacemos hit en ninguna entidad → pintar
|
||||
if (brush_tile_ != NO_BRUSH) {
|
||||
// Comprobar si hay hit en alguna entidad primero
|
||||
bool hit_entity = false;
|
||||
SDL_FRect player_rect = player_->getRect();
|
||||
if (pointInRect(mouse_game_x_, mouse_game_y_, player_rect)) { hit_entity = true; }
|
||||
|
||||
if (!hit_entity) {
|
||||
auto* enemy_mgr = room_->getEnemyManager();
|
||||
for (int i = 0; i < enemy_mgr->getCount() && !hit_entity; ++i) {
|
||||
if (pointInRect(mouse_game_x_, mouse_game_y_, enemy_mgr->getEnemy(i)->getRect())) { hit_entity = true; }
|
||||
}
|
||||
}
|
||||
if (!hit_entity) {
|
||||
auto* item_mgr = room_->getItemManager();
|
||||
for (int i = 0; i < item_mgr->getCount() && !hit_entity; ++i) {
|
||||
if (pointInRect(mouse_game_x_, mouse_game_y_, item_mgr->getItem(i)->getCollider())) { hit_entity = true; }
|
||||
}
|
||||
}
|
||||
|
||||
if (!hit_entity) {
|
||||
// Pintar tile y entrar en modo painting
|
||||
painting_ = true;
|
||||
int tile_index = mouse_tile_y_ * 32 + mouse_tile_x_;
|
||||
if (tile_index >= 0 && tile_index < static_cast<int>(room_data_.tile_map.size())) {
|
||||
room_data_.tile_map[tile_index] = brush_tile_;
|
||||
room_->setTile(tile_index, brush_tile_);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
handleMouseDown(mouse_game_x_, mouse_game_y_);
|
||||
} else if (event.type == SDL_EVENT_MOUSE_BUTTON_UP && event.button.button == SDL_BUTTON_LEFT) {
|
||||
handleMouseUp();
|
||||
if (painting_) {
|
||||
painting_ = false;
|
||||
autosave();
|
||||
} else {
|
||||
handleMouseUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -640,9 +730,17 @@ void MapEditor::updateStatusBarInfo() {
|
||||
" itm:" + room_data_.item_color1 + "/" + room_data_.item_color2;
|
||||
}
|
||||
|
||||
// Línea 4: brush activo
|
||||
std::string line4;
|
||||
if (brush_tile_ == ERASER_BRUSH) {
|
||||
line4 = "brush: eraser (e)";
|
||||
} else if (brush_tile_ != NO_BRUSH) {
|
||||
line4 = "brush: tile " + std::to_string(brush_tile_);
|
||||
}
|
||||
|
||||
statusbar_->setLine2(line2);
|
||||
statusbar_->setLine3(line3);
|
||||
statusbar_->setLine4("");
|
||||
statusbar_->setLine4(line4);
|
||||
statusbar_->setLine5(line5);
|
||||
|
||||
// Actualizar el prompt de la consola según la selección
|
||||
|
||||
Reference in New Issue
Block a user