feat(editor): preview del brush d'entitat i fons del picker mes clar

This commit is contained in:
JailDesigner committed 2026-05-12 13:35:01 +02:00
1 parent 6749780356
commit a43ae21014
4 files changed
+39 -8

No files matched your search

+2 -2
View File
@@ -8,6 +8,6 @@ picker:
# Colors ARGB en hex. Accepta enter (0xFF2244FF) o cadena ("#FF2244FF"). # Colors ARGB en hex. Accepta enter (0xFF2244FF) o cadena ("#FF2244FF").
colors: colors:
border: "0xFF2244FF" # vora 1 px que envolta canvas i picker border: "0xFF6A86C8" # vora 1 px que envolta canvas i picker (blau suau)
picker_bg: "0xFF101824" # fons del picker picker_bg: "0xFFC8C0D8" # fons del picker (lavanda clara)
picker_hover: "0xFFFFFFFF" # vora 1 px del tile sota el cursor picker_hover: "0xFFFFFFFF" # vora 1 px del tile sota el cursor
+7 -6
View File
@@ -88,8 +88,6 @@ entities:
position: [12, 2] position: [12, 2]
- type: torch - type: torch
position: [16, 2] position: [16, 2]
- type: sarcophagus
sarc_position: [0, 0]
- type: sarcophagus - type: sarcophagus
sarc_position: [1, 0] sarc_position: [1, 0]
- type: sarcophagus - type: sarcophagus
@@ -131,11 +129,14 @@ entities:
- type: torch - type: torch
position: [4, 2] position: [4, 2]
- type: door - type: door
- type: column
position: [6, 5]
frame: 2
- type: mummy - type: mummy
position: [10, 11] position: [10, 11]
- type: column
position: [3, 4]
frame: 2
- type: stone - type: stone
position: [10, 5] position: [5, 4]
frame: 16 frame: 16
- type: stone
position: [4, 4]
frame: 19
+24
View File
@@ -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<float>(A_COL * it->frame_w),
.y = static_cast<float>(A_ROW * it->frame_h),
.w = static_cast<float>(it->frame_w),
.h = static_cast<float>(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 { void Editor::render(const Tilemap& tilemap, const EntityManager& entities) const {
if (!active_) { return; } if (!active_) { return; }
auto& screen = Screen::get(); 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 PX = tilemap.getOriginX() + (cursor_col_ * tilemap.getTileSize());
const int PY = tilemap.getOriginY() + (cursor_row_ * tilemap.getTileSize()); const int PY = tilemap.getOriginY() + (cursor_row_ * tilemap.getTileSize());
tilemap.renderTilePreview(PX, PY, brush_tile_); 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) { } else if (mode_ == Mode::HAND && picker_ == Picker::NONE) {
// Marcs d'entitat: hover (tenue) i selecció (brillant). El // Marcs d'entitat: hover (tenue) i selecció (brillant). El
// pickerHoverArgb el reusem com a "selecció brillant"; el // pickerHoverArgb el reusem com a "selecció brillant"; el
+6
View File
@@ -145,6 +145,12 @@ class Editor {
void renderEntityPicker(const Tilemap& tilemap) const; void renderEntityPicker(const Tilemap& tilemap) const;
void renderEntityFramePicker() 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}; bool active_{false};
Mode mode_{Mode::TILE}; Mode mode_{Mode::TILE};
Picker picker_{Picker::NONE}; Picker picker_{Picker::NONE};