Handles sprite placement and interaction in the dungeon editor. More...
#include <sprite_interaction_handler.h>
Public Types | |
| enum class | PlacementBlockReason { kNone = 0 , kInvalidRoom , kSpriteLimit } |
Public Member Functions | |
| void | BeginPlacement () override |
| Begin placement mode. | |
| void | CancelPlacement () override |
| Cancel current placement. | |
| bool | IsPlacementActive () const override |
| Check if placement mode is active. | |
| bool | HandleClick (int canvas_x, int canvas_y) override |
| Handle mouse click at canvas position. | |
| void | HandleDrag (ImVec2 current_pos, ImVec2 delta) override |
| Handle mouse drag. | |
| void | HandleRelease () override |
| Handle mouse release. | |
| void | DrawGhostPreview () override |
| Draw ghost preview during placement. | |
| void | DrawSelectionHighlight () override |
| Draw selection highlight for selected entities. | |
| std::optional< size_t > | GetEntityAtPosition (int canvas_x, int canvas_y) const override |
| Get entity at canvas position. | |
| void | SetSpriteId (uint8_t id) |
| Set sprite ID for placement. | |
| uint8_t | GetSpriteId () const |
| Get current sprite ID for placement. | |
| void | SelectSprite (size_t index) |
| Select sprite at index. | |
| void | ClearSelection () |
| Clear sprite selection. | |
| bool | HasSelection () const |
| Check if a sprite is selected. | |
| std::optional< size_t > | GetSelectedIndex () const |
| Get selected sprite index. | |
| void | DeleteSelected () |
| Delete selected sprite. | |
| bool | was_placement_blocked () const |
| True if the most recent PlaceSpriteAtPosition was blocked. | |
| PlacementBlockReason | placement_block_reason () const |
| void | clear_placement_blocked () |
Public Member Functions inherited from yaze::editor::BaseEntityHandler | |
| virtual | ~BaseEntityHandler ()=default |
| void | SetContext (InteractionContext *ctx) |
| Set the interaction context. | |
| InteractionContext * | context () const |
| Get the interaction context. | |
| virtual bool | HandleMouseWheel (float delta) |
| void | DrawPostPlacementToast () |
Private Member Functions | |
| void | PlaceSpriteAtPosition (int canvas_x, int canvas_y) |
| Place sprite at position. | |
| std::pair< int, int > | CanvasToSpriteCoords (int canvas_x, int canvas_y) const |
| Convert canvas to sprite coordinates (16-pixel grid) | |
Private Attributes | |
| bool | sprite_placement_mode_ = false |
| uint8_t | preview_sprite_id_ = 0 |
| PlacementBlockReason | placement_block_reason_ = PlacementBlockReason::kNone |
| std::optional< size_t > | selected_sprite_index_ |
| bool | is_dragging_ = false |
| ImVec2 | drag_start_pos_ |
| ImVec2 | drag_current_pos_ |
Additional Inherited Members | |
Protected Member Functions inherited from yaze::editor::BaseEntityHandler | |
| void | TriggerSuccessToast () |
| void | DrawSuccessToastOverlay (const char *msg, ImU32 color) const |
| std::pair< int, int > | RoomToCanvas (int room_x, int room_y) const |
| Convert room tile coordinates to canvas pixel coordinates. | |
| std::pair< int, int > | CanvasToRoom (int canvas_x, int canvas_y) const |
| Convert canvas pixel coordinates to room tile coordinates. | |
| bool | IsWithinBounds (int canvas_x, int canvas_y) const |
| Check if coordinates are within room bounds. | |
| ImVec2 | GetCanvasZeroPoint () const |
| Get canvas zero point (for screen coordinate conversion) | |
| float | GetCanvasScale () const |
| Get canvas global scale. | |
| bool | HasValidContext () const |
| Check if context is valid. | |
| zelda3::Room * | GetCurrentRoom () const |
| Get current room (convenience method) | |
Protected Attributes inherited from yaze::editor::BaseEntityHandler | |
| InteractionContext * | ctx_ = nullptr |
| float | toast_expire_time_ = 0.0f |
Static Protected Attributes inherited from yaze::editor::BaseEntityHandler | |
| static constexpr float | kToastDuration = 1.5f |
Handles sprite placement and interaction in the dungeon editor.
Sprites use a 16-pixel coordinate system (0-31 range for each axis).
Definition at line 15 of file sprite_interaction_handler.h.
|
strong |
| Enumerator | |
|---|---|
| kNone | |
| kInvalidRoom | |
| kSpriteLimit | |
Definition at line 17 of file sprite_interaction_handler.h.
|
overridevirtual |
Begin placement mode.
Called when user selects an entity to place from the palette. Override to initialize placement state.
Implements yaze::editor::BaseEntityHandler.
Definition at line 18 of file sprite_interaction_handler.cc.
References ClearSelection(), and sprite_placement_mode_.
Referenced by yaze::editor::InteractionCoordinator::SetMode().
|
inlineoverridevirtual |
Cancel current placement.
Called when user presses Escape or switches modes. Override to clean up placement state.
Implements yaze::editor::BaseEntityHandler.
Definition at line 28 of file sprite_interaction_handler.h.
References sprite_placement_mode_.
Referenced by yaze::editor::InteractionCoordinator::CancelCurrentMode(), and yaze::editor::InteractionCoordinator::CancelPlacement().
|
inlineoverridevirtual |
Check if placement mode is active.
Implements yaze::editor::BaseEntityHandler.
Definition at line 29 of file sprite_interaction_handler.h.
References sprite_placement_mode_.
Referenced by yaze::editor::InteractionCoordinator::DrawGhostPreviews(), yaze::editor::InteractionCoordinator::HandleClick(), yaze::editor::InteractionCoordinator::HandleMouseWheel(), and yaze::editor::InteractionCoordinator::IsPlacementActive().
|
overridevirtual |
Handle mouse click at canvas position.
| canvas_x | Unscaled X position relative to canvas origin |
| canvas_y | Unscaled Y position relative to canvas origin |
Implements yaze::editor::BaseEntityHandler.
Definition at line 23 of file sprite_interaction_handler.cc.
References ClearSelection(), drag_current_pos_, drag_start_pos_, GetEntityAtPosition(), yaze::editor::BaseEntityHandler::HasValidContext(), is_dragging_, PlaceSpriteAtPosition(), SelectSprite(), and sprite_placement_mode_.
Referenced by yaze::editor::InteractionCoordinator::HandleClick(), and yaze::editor::InteractionCoordinator::TrySelectEntityAtCursor().
|
overridevirtual |
Handle mouse drag.
| current_pos | Current mouse position (screen coords) |
| delta | Mouse movement since last frame |
Implements yaze::editor::BaseEntityHandler.
Definition at line 47 of file sprite_interaction_handler.cc.
References drag_current_pos_, is_dragging_, and selected_sprite_index_.
Referenced by yaze::editor::InteractionCoordinator::HandleDrag().
|
overridevirtual |
Handle mouse release.
Called when left mouse button is released after a drag.
Implements yaze::editor::BaseEntityHandler.
Definition at line 53 of file sprite_interaction_handler.cc.
References CanvasToSpriteCoords(), yaze::editor::BaseEntityHandler::ctx_, drag_current_pos_, yaze::editor::BaseEntityHandler::GetCurrentRoom(), is_dragging_, yaze::editor::dungeon_coords::kSpriteGridMax, yaze::editor::kSprites, yaze::editor::InteractionContext::NotifyEntityChanged(), yaze::editor::InteractionContext::NotifyMutation(), and selected_sprite_index_.
Referenced by yaze::editor::InteractionCoordinator::HandleRelease().
|
overridevirtual |
Draw ghost preview during placement.
Called every frame when placement mode is active. Shows preview of entity at cursor position.
Implements yaze::editor::BaseEntityHandler.
Definition at line 87 of file sprite_interaction_handler.cc.
References yaze::editor::InteractionContext::canvas, yaze::editor::BaseEntityHandler::ctx_, yaze::editor::BaseEntityHandler::GetCanvasScale(), yaze::editor::BaseEntityHandler::GetCurrentRoom(), yaze::editor::AgentUI::GetTheme(), yaze::editor::BaseEntityHandler::HasValidContext(), yaze::zelda3::kMaxTotalSprites, yaze::editor::dungeon_coords::kSpriteTileSize, preview_sprite_id_, and sprite_placement_mode_.
Referenced by yaze::editor::InteractionCoordinator::DrawGhostPreviews().
|
overridevirtual |
Draw selection highlight for selected entities.
Called every frame to show selection state.
Implements yaze::editor::BaseEntityHandler.
Definition at line 156 of file sprite_interaction_handler.cc.
References CanvasToSpriteCoords(), drag_current_pos_, yaze::editor::BaseEntityHandler::GetCanvasScale(), yaze::editor::BaseEntityHandler::GetCanvasZeroPoint(), yaze::editor::BaseEntityHandler::GetCurrentRoom(), yaze::editor::BaseEntityHandler::HasValidContext(), is_dragging_, yaze::editor::dungeon_coords::kSpriteGridMax, yaze::editor::dungeon_coords::kSpriteTileSize, and selected_sprite_index_.
Referenced by yaze::editor::InteractionCoordinator::DrawSelectionHighlights().
|
overridevirtual |
Get entity at canvas position.
| canvas_x | Unscaled X position relative to canvas origin |
| canvas_y | Unscaled Y position relative to canvas origin |
Implements yaze::editor::BaseEntityHandler.
Definition at line 212 of file sprite_interaction_handler.cc.
References yaze::editor::BaseEntityHandler::ctx_, yaze::editor::BaseEntityHandler::GetCanvasScale(), yaze::editor::InteractionContext::GetCurrentRoomConst(), yaze::editor::BaseEntityHandler::HasValidContext(), and yaze::editor::dungeon_coords::kSpriteTileSize.
Referenced by yaze::editor::InteractionCoordinator::GetEntityAtPosition(), and HandleClick().
|
inline |
Set sprite ID for placement.
Definition at line 48 of file sprite_interaction_handler.h.
References preview_sprite_id_.
|
inline |
Get current sprite ID for placement.
Definition at line 53 of file sprite_interaction_handler.h.
References preview_sprite_id_.
| void yaze::editor::SpriteInteractionHandler::SelectSprite | ( | size_t | index | ) |
Select sprite at index.
Definition at line 247 of file sprite_interaction_handler.cc.
References yaze::editor::BaseEntityHandler::ctx_, yaze::editor::InteractionContext::NotifyEntityChanged(), and selected_sprite_index_.
Referenced by HandleClick(), and yaze::editor::InteractionCoordinator::SelectEntity().
| void yaze::editor::SpriteInteractionHandler::ClearSelection | ( | ) |
Clear sprite selection.
Definition at line 252 of file sprite_interaction_handler.cc.
References is_dragging_, and selected_sprite_index_.
Referenced by BeginPlacement(), yaze::editor::InteractionCoordinator::ClearAllEntitySelections(), DeleteSelected(), and HandleClick().
|
inline |
Check if a sprite is selected.
Definition at line 68 of file sprite_interaction_handler.h.
References selected_sprite_index_.
Referenced by yaze::editor::InteractionCoordinator::DeleteSelectedEntity(), yaze::editor::InteractionCoordinator::GetSelectedEntityType(), yaze::editor::InteractionCoordinator::HandleDrag(), and yaze::editor::InteractionCoordinator::HasEntitySelection().
|
inline |
Get selected sprite index.
Definition at line 73 of file sprite_interaction_handler.h.
References selected_sprite_index_.
Referenced by yaze::editor::InteractionCoordinator::GetSelectedEntity().
| void yaze::editor::SpriteInteractionHandler::DeleteSelected | ( | ) |
Delete selected sprite.
Definition at line 257 of file sprite_interaction_handler.cc.
References ClearSelection(), yaze::editor::BaseEntityHandler::ctx_, yaze::editor::BaseEntityHandler::GetCurrentRoom(), yaze::editor::BaseEntityHandler::HasValidContext(), yaze::editor::kSprites, yaze::editor::InteractionContext::NotifyInvalidateCache(), yaze::editor::InteractionContext::NotifyMutation(), and selected_sprite_index_.
Referenced by yaze::editor::InteractionCoordinator::DeleteSelectedEntity().
|
inline |
True if the most recent PlaceSpriteAtPosition was blocked.
Definition at line 81 of file sprite_interaction_handler.h.
References kNone, and placement_block_reason_.
|
inline |
Definition at line 84 of file sprite_interaction_handler.h.
References placement_block_reason_.
|
inline |
Definition at line 87 of file sprite_interaction_handler.h.
References kNone, and placement_block_reason_.
|
private |
Place sprite at position.
Definition at line 276 of file sprite_interaction_handler.cc.
References CanvasToSpriteCoords(), yaze::editor::BaseEntityHandler::ctx_, yaze::editor::BaseEntityHandler::GetCurrentRoom(), yaze::editor::BaseEntityHandler::HasValidContext(), kInvalidRoom, yaze::zelda3::kMaxTotalSprites, kNone, yaze::editor::dungeon_coords::kSpriteGridMax, kSpriteLimit, yaze::editor::kSprites, yaze::editor::InteractionContext::NotifyInvalidateCache(), yaze::editor::InteractionContext::NotifyMutation(), placement_block_reason_, preview_sprite_id_, and yaze::editor::BaseEntityHandler::TriggerSuccessToast().
Referenced by HandleClick().
|
private |
Convert canvas to sprite coordinates (16-pixel grid)
Definition at line 316 of file sprite_interaction_handler.cc.
References yaze::editor::BaseEntityHandler::GetCanvasScale(), and yaze::editor::dungeon_coords::kSpriteTileSize.
Referenced by DrawSelectionHighlight(), HandleRelease(), and PlaceSpriteAtPosition().
|
private |
Definition at line 93 of file sprite_interaction_handler.h.
Referenced by BeginPlacement(), CancelPlacement(), DrawGhostPreview(), HandleClick(), and IsPlacementActive().
|
private |
Definition at line 94 of file sprite_interaction_handler.h.
Referenced by DrawGhostPreview(), GetSpriteId(), PlaceSpriteAtPosition(), and SetSpriteId().
|
private |
Definition at line 95 of file sprite_interaction_handler.h.
Referenced by clear_placement_blocked(), placement_block_reason(), PlaceSpriteAtPosition(), and was_placement_blocked().
|
private |
Definition at line 98 of file sprite_interaction_handler.h.
Referenced by ClearSelection(), DeleteSelected(), DrawSelectionHighlight(), GetSelectedIndex(), HandleDrag(), HandleRelease(), HasSelection(), and SelectSprite().
|
private |
Definition at line 99 of file sprite_interaction_handler.h.
Referenced by ClearSelection(), DrawSelectionHighlight(), HandleClick(), HandleDrag(), and HandleRelease().
|
private |
Definition at line 100 of file sprite_interaction_handler.h.
Referenced by HandleClick().
|
private |
Definition at line 101 of file sprite_interaction_handler.h.
Referenced by DrawSelectionHighlight(), HandleClick(), HandleDrag(), and HandleRelease().