From a43ae21014f23535947fca25eda8643e282bf30f Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 12 May 2026 13:35:01 +0200 Subject: [PATCH] feat(editor): preview del brush d'entitat i fons del picker mes clar --- data/config/editor.yaml | 4 ++-- data/maps/p1/r1.yaml | 13 +++++++------ source/game/editor/editor.cpp | 24 ++++++++++++++++++++++++ source/game/editor/editor.hpp | 6 ++++++ 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/data/config/editor.yaml b/data/config/editor.yaml index 26fb9b6..8f58ad6 100644 --- a/data/config/editor.yaml +++ b/data/config/editor.yaml @@ -8,6 +8,6 @@ picker: # Colors ARGB en hex. Accepta enter (0xFF2244FF) o cadena ("#FF2244FF"). colors: - border: "0xFF2244FF" # vora 1 px que envolta canvas i picker - picker_bg: "0xFF101824" # fons del picker + border: "0xFF6A86C8" # vora 1 px que envolta canvas i picker (blau suau) + picker_bg: "0xFFC8C0D8" # fons del picker (lavanda clara) picker_hover: "0xFFFFFFFF" # vora 1 px del tile sota el cursor diff --git a/data/maps/p1/r1.yaml b/data/maps/p1/r1.yaml index 4db9337..cf0a269 100644 --- a/data/maps/p1/r1.yaml +++ b/data/maps/p1/r1.yaml @@ -88,8 +88,6 @@ entities: position: [12, 2] - type: torch position: [16, 2] - - type: sarcophagus - sarc_position: [0, 0] - type: sarcophagus sarc_position: [1, 0] - type: sarcophagus @@ -131,11 +129,14 @@ entities: - type: torch position: [4, 2] - type: door - - type: column - position: [6, 5] - frame: 2 - type: mummy position: [10, 11] + - type: column + position: [3, 4] + frame: 2 - type: stone - position: [10, 5] + position: [5, 4] frame: 16 + - type: stone + position: [4, 4] + frame: 19 diff --git a/source/game/editor/editor.cpp b/source/game/editor/editor.cpp index d57fb93..0ba3acd 100644 --- a/source/game/editor/editor.cpp +++ b/source/game/editor/editor.cpp @@ -1092,6 +1092,28 @@ void Editor::updateTilePicker(const Tilemap& tilemap, int canvas_x, int canvas_y } } +void Editor::renderEntityBrushPreview(const Tilemap& tilemap) const { + auto it = std::ranges::find_if(editable_entities_, [this](const auto& e) { return e.name == brush_entity_; }); + if (it == editable_entities_.end() || it->sprite == nullptr) { return; } + const int FRAME = (brush_entity_frame_ >= 0) ? brush_entity_frame_ : 0; + const int ATLAS_COLS = (it->frame_w > 0) ? (it->sprite->getWidth() / it->frame_w) : 1; + const int ATLAS_COLS_SAFE = (ATLAS_COLS > 0) ? ATLAS_COLS : 1; + const int A_COL = FRAME % ATLAS_COLS_SAFE; + const int A_ROW = FRAME / ATLAS_COLS_SAFE; + const SDL_FRect SRC{ + .x = static_cast(A_COL * it->frame_w), + .y = static_cast(A_ROW * it->frame_h), + .w = static_cast(it->frame_w), + .h = static_cast(it->frame_h), + }; + const int TS = tilemap.getTileSize(); + const int TILE_PX = tilemap.getOriginX() + (cursor_col_ * TS); + const int TILE_PY = tilemap.getOriginY() + (cursor_row_ * TS); + const int DST_X = TILE_PX + ((TS - it->frame_w) / 2); + const int DST_Y = TILE_PY + TS - it->frame_h; + it->sprite->render(DST_X, DST_Y, &SRC, SDL_FLIP_NONE); +} + void Editor::render(const Tilemap& tilemap, const EntityManager& entities) const { if (!active_) { return; } auto& screen = Screen::get(); @@ -1109,6 +1131,8 @@ void Editor::render(const Tilemap& tilemap, const EntityManager& entities) const const int PX = tilemap.getOriginX() + (cursor_col_ * tilemap.getTileSize()); const int PY = tilemap.getOriginY() + (cursor_row_ * tilemap.getTileSize()); tilemap.renderTilePreview(PX, PY, brush_tile_); + } else if (mode_ == Mode::ENTITY && !brush_entity_.empty() && cursor_col_ >= 0 && cursor_row_ >= 0) { + renderEntityBrushPreview(tilemap); } else if (mode_ == Mode::HAND && picker_ == Picker::NONE) { // Marcs d'entitat: hover (tenue) i selecció (brillant). El // pickerHoverArgb el reusem com a "selecció brillant"; el diff --git a/source/game/editor/editor.hpp b/source/game/editor/editor.hpp index cdf99f9..508e112 100644 --- a/source/game/editor/editor.hpp +++ b/source/game/editor/editor.hpp @@ -145,6 +145,12 @@ class Editor { void renderEntityPicker(const Tilemap& tilemap) const; void renderEntityFramePicker() const; + // Preview del sprite de l'entitat seleccionada com a brush, snapped al + // tile sota el cursor. Anchor "feet": base del sprite a la base inferior + // del tile, centrat horitzontalment — així stone cau exactament i column + // sobresurt cap amunt, coincidint amb el resultat de col·locar. + void renderEntityBrushPreview(const Tilemap& tilemap) const; + bool active_{false}; Mode mode_{Mode::TILE}; Picker picker_{Picker::NONE};