feat(editor): preview del brush d'entitat i fons del picker mes clar
This commit is contained in:
1 parent
6749780356
commit
a43ae21014
4 files changed
+39
-8
No files matched your search
@@ -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 {
|
||||
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
|
||||
|
||||
@@ -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};
|
||||
|
||||
Reference in new issue
Block a user