Handles pot item placement and interaction in the dungeon editor. More...
#include <item_interaction_handler.h>


Public Types | |
| using | ItemPlacementPreflight |
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 | SetItemId (uint8_t id) |
| Set item ID for placement. | |
| uint8_t | GetItemId () const |
| Get current item ID for placement. | |
| void | SelectItem (size_t index) |
| Select item at index. | |
| void | ClearSelection () |
| Clear item selection. | |
| bool | HasSelection () const |
| Check if an item is selected. | |
| std::optional< size_t > | GetSelectedIndex () const |
| Get selected item index. | |
| void | DeleteSelected () |
| Delete selected item. | |
| void | DeleteAll () |
| bool | NudgeSelected (int delta_pixel_x, int delta_pixel_y) |
| bool | MutateItemType (size_t index, uint8_t new_type) |
| Change one pot item's raw type byte in place. | |
| bool | UpdateItem (size_t index, uint8_t type, int pixel_x, int pixel_y) |
| void | SetItemPlacementPreflight (ItemPlacementPreflight preflight) |
| void | SetMutationErrorCallback (std::function< void(const absl::Status &)> callback) |
| const absl::Status & | mutation_status () const |
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 | |
| bool | PreflightPlacement (const std::vector< zelda3::PotItem > &candidate) |
| void | PlaceItemAtPosition (int canvas_x, int canvas_y) |
| Place item at position. | |
Private Attributes | |
| ItemPlacementPreflight | item_placement_preflight_ |
| std::function< void(const absl::Status &) | mutation_error_callback_ ) |
| absl::Status | mutation_status_ = absl::OkStatus() |
| bool | item_placement_mode_ = false |
| uint8_t | preview_item_id_ = 0 |
| std::optional< size_t > | selected_item_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) | |
| DungeonCanvasTransform | GetCanvasTransform () const |
| std::optional< ImVec2 > | GetPointerScreenPosition () const |
| 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 pot item placement and interaction in the dungeon editor.
Pot items use a special position encoding and snap to an 8-pixel grid.
Definition at line 19 of file item_interaction_handler.h.
Definition at line 93 of file item_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 17 of file item_interaction_handler.cc.
References ClearSelection(), item_placement_mode_, and mutation_status_.
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 26 of file item_interaction_handler.h.
References item_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 27 of file item_interaction_handler.h.
References item_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 item_interaction_handler.cc.
References ClearSelection(), drag_current_pos_, drag_start_pos_, GetEntityAtPosition(), yaze::editor::BaseEntityHandler::HasValidContext(), is_dragging_, yaze::editor::BaseEntityHandler::IsWithinBounds(), item_placement_mode_, PlaceItemAtPosition(), and SelectItem().
Referenced by yaze::editor::InteractionCoordinator::HandleClick(), and yaze::editor::InteractionCoordinator::TrySelectEntityAtCursor().
|
overridevirtual |
Handle mouse drag.
| current_pos | Current unscaled room-pixel position |
| delta | Mouse movement since last frame (screen pixels) |
Implements yaze::editor::BaseEntityHandler.
Definition at line 49 of file item_interaction_handler.cc.
References drag_current_pos_, is_dragging_, and selected_item_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 55 of file item_interaction_handler.cc.
References yaze::editor::BaseEntityHandler::ctx_, drag_current_pos_, yaze::zelda3::EncodePotItemPosition(), yaze::editor::BaseEntityHandler::GetCurrentRoom(), is_dragging_, yaze::editor::kItems, yaze::editor::dungeon_coords::kRoomPixelHeight, yaze::editor::dungeon_coords::kRoomPixelWidth, yaze::editor::InteractionContext::NotifyEntityChanged(), yaze::editor::InteractionContext::NotifyInvalidateCache(), yaze::editor::InteractionContext::NotifyMutation(), and selected_item_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 97 of file item_interaction_handler.cc.
References yaze::editor::InteractionContext::canvas, yaze::editor::BaseEntityHandler::ctx_, yaze::editor::BaseEntityHandler::GetCanvasTransform(), yaze::editor::BaseEntityHandler::GetPointerScreenPosition(), yaze::editor::AgentUI::GetTheme(), yaze::editor::BaseEntityHandler::HasValidContext(), item_placement_mode_, yaze::editor::dungeon_coords::kTileSize, preview_item_id_, yaze::editor::DungeonCanvasTransform::RoomPixelsToScreen(), yaze::editor::DungeonCanvasTransform::RoomSizeToScreen(), and yaze::editor::DungeonCanvasTransform::ScreenToRoomPixelCoordinates().
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 139 of file item_interaction_handler.cc.
References drag_current_pos_, yaze::editor::BaseEntityHandler::GetCanvasTransform(), yaze::editor::BaseEntityHandler::GetCurrentRoom(), yaze::editor::BaseEntityHandler::HasValidContext(), is_dragging_, yaze::editor::dungeon_coords::kTileSize, yaze::editor::DungeonCanvasTransform::RoomPixelsToScreen(), yaze::editor::DungeonCanvasTransform::RoomSizeToScreen(), yaze::editor::DungeonCanvasTransform::scale(), and selected_item_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 190 of file item_interaction_handler.cc.
References yaze::editor::BaseEntityHandler::ctx_, yaze::editor::InteractionContext::GetCurrentRoomConst(), yaze::zelda3::Room::GetPotItems(), yaze::editor::BaseEntityHandler::HasValidContext(), and yaze::editor::BaseEntityHandler::IsWithinBounds().
Referenced by yaze::editor::InteractionCoordinator::GetEntitiesAtPosition(), and HandleClick().

|
inline |
Set item ID for placement.
Definition at line 46 of file item_interaction_handler.h.
References preview_item_id_.
|
inline |
Get current item ID for placement.
Definition at line 51 of file item_interaction_handler.h.
References preview_item_id_.
Referenced by yaze::editor::ItemEditorPanel::DrawPlacementControls().
| void yaze::editor::ItemInteractionHandler::SelectItem | ( | size_t | index | ) |
Select item at index.
Definition at line 217 of file item_interaction_handler.cc.
References yaze::editor::BaseEntityHandler::ctx_, yaze::editor::InteractionContext::NotifyEntityChanged(), and selected_item_index_.
Referenced by yaze::editor::InteractionCoordinator::ApplySelection(), HandleClick(), yaze::editor::InteractionCoordinator::SelectEntity(), yaze::editor::InteractionCoordinator::SetSelectedEntities(), and yaze::editor::InteractionCoordinator::UpdateEntitySelection().

| void yaze::editor::ItemInteractionHandler::ClearSelection | ( | ) |
Clear item selection.
Definition at line 222 of file item_interaction_handler.cc.
References is_dragging_, and selected_item_index_.
Referenced by BeginPlacement(), yaze::editor::InteractionCoordinator::ClearAllEntitySelections(), DeleteAll(), DeleteSelected(), yaze::editor::InteractionCoordinator::HandleClick(), HandleClick(), yaze::editor::InteractionCoordinator::SelectEntitiesInRect(), yaze::editor::InteractionCoordinator::SetSelectedEntities(), and yaze::editor::InteractionCoordinator::UpdateEntitySelection().
|
inline |
Check if an item is selected.
Definition at line 66 of file item_interaction_handler.h.
References selected_item_index_.
Referenced by yaze::editor::InteractionCoordinator::GetSelectedEntityType(), yaze::editor::InteractionCoordinator::HandleDrag(), and yaze::editor::InteractionCoordinator::HasEntitySelection().
|
inline |
Get selected item index.
Definition at line 71 of file item_interaction_handler.h.
References selected_item_index_.
Referenced by yaze::editor::InteractionCoordinator::GetSelectedEntity(), and yaze::editor::InteractionCoordinator::TrySelectEntityAtCursor().
| void yaze::editor::ItemInteractionHandler::DeleteSelected | ( | ) |
Delete selected item.
Definition at line 227 of file item_interaction_handler.cc.
References ClearSelection(), yaze::editor::BaseEntityHandler::ctx_, yaze::editor::BaseEntityHandler::GetCurrentRoom(), yaze::editor::BaseEntityHandler::HasValidContext(), yaze::editor::kItems, yaze::editor::InteractionContext::NotifyEntityChanged(), yaze::editor::InteractionContext::NotifyInvalidateCache(), yaze::editor::InteractionContext::NotifyMutation(), and selected_item_index_.
| void yaze::editor::ItemInteractionHandler::DeleteAll | ( | ) |
Definition at line 248 of file item_interaction_handler.cc.
References ClearSelection(), yaze::editor::BaseEntityHandler::ctx_, yaze::editor::BaseEntityHandler::GetCurrentRoom(), yaze::editor::BaseEntityHandler::HasValidContext(), yaze::editor::kItems, yaze::editor::InteractionContext::NotifyEntityChanged(), yaze::editor::InteractionContext::NotifyInvalidateCache(), and yaze::editor::InteractionContext::NotifyMutation().
| bool yaze::editor::ItemInteractionHandler::NudgeSelected | ( | int | delta_pixel_x, |
| int | delta_pixel_y ) |
Definition at line 266 of file item_interaction_handler.cc.
References yaze::editor::BaseEntityHandler::ctx_, yaze::zelda3::EncodePotItemPosition(), yaze::editor::BaseEntityHandler::GetCurrentRoom(), yaze::editor::BaseEntityHandler::HasValidContext(), yaze::editor::kItems, yaze::editor::InteractionContext::NotifyEntityChanged(), yaze::editor::InteractionContext::NotifyInvalidateCache(), yaze::editor::InteractionContext::NotifyMutation(), and selected_item_index_.
| bool yaze::editor::ItemInteractionHandler::MutateItemType | ( | size_t | index, |
| uint8_t | new_type ) |
Change one pot item's raw type byte in place.
Routes through the normal item mutation notifications so GUI edits retain the same dirty-state, cache invalidation, and undo behavior as canvas interactions.
Definition at line 305 of file item_interaction_handler.cc.
References yaze::editor::BaseEntityHandler::ctx_, yaze::editor::BaseEntityHandler::GetCurrentRoom(), yaze::editor::BaseEntityHandler::HasValidContext(), yaze::editor::kItems, yaze::editor::InteractionContext::NotifyEntityChanged(), yaze::editor::InteractionContext::NotifyInvalidateCache(), and yaze::editor::InteractionContext::NotifyMutation().
Referenced by yaze::editor::anonymous_namespace{dungeon_entity_inspector.cc}::DrawItem(), yaze::editor::ItemEditorPanel::DrawRoomItems(), and UpdateItem().
| bool yaze::editor::ItemInteractionHandler::UpdateItem | ( | size_t | index, |
| uint8_t | type, | ||
| int | pixel_x, | ||
| int | pixel_y ) |
Definition at line 328 of file item_interaction_handler.cc.
References yaze::editor::BaseEntityHandler::ctx_, yaze::zelda3::EncodePotItemPosition(), yaze::editor::BaseEntityHandler::GetCurrentRoom(), yaze::editor::BaseEntityHandler::HasValidContext(), yaze::editor::kItems, MutateItemType(), yaze::editor::InteractionContext::NotifyEntityChanged(), yaze::editor::InteractionContext::NotifyInvalidateCache(), and yaze::editor::InteractionContext::NotifyMutation().
Referenced by yaze::editor::anonymous_namespace{dungeon_entity_inspector.cc}::DrawItem().
|
inline |
Definition at line 95 of file item_interaction_handler.h.
References item_placement_preflight_.
Referenced by yaze::editor::DungeonEditorV2::ConfigureViewerUndoHooks().
|
inline |
Definition at line 98 of file item_interaction_handler.h.
References mutation_error_callback_.
|
inline |
Definition at line 102 of file item_interaction_handler.h.
References mutation_status_.
|
private |
Definition at line 358 of file item_interaction_handler.cc.
References yaze::editor::BaseEntityHandler::ctx_, yaze::editor::InteractionContext::current_room_id, yaze::editor::BaseEntityHandler::GetCurrentRoom(), yaze::editor::BaseEntityHandler::HasValidContext(), item_placement_preflight_, mutation_error_callback_, and mutation_status_.
Referenced by PlaceItemAtPosition().

|
private |
Place item at position.
Definition at line 380 of file item_interaction_handler.cc.
References yaze::editor::BaseEntityHandler::ctx_, yaze::zelda3::EncodePotItemPosition(), yaze::editor::BaseEntityHandler::GetCurrentRoom(), yaze::editor::BaseEntityHandler::HasValidContext(), yaze::zelda3::PotItem::item, yaze::editor::kItems, mutation_status_, yaze::editor::InteractionContext::NotifyInvalidateCache(), yaze::editor::InteractionContext::NotifyMutation(), yaze::zelda3::PotItem::position, PreflightPlacement(), and preview_item_id_.
Referenced by HandleClick().
|
private |
Definition at line 105 of file item_interaction_handler.h.
Referenced by PreflightPlacement(), and SetItemPlacementPreflight().
|
private |
Definition at line 106 of file item_interaction_handler.h.
Referenced by PreflightPlacement(), and SetMutationErrorCallback().
|
private |
Definition at line 107 of file item_interaction_handler.h.
Referenced by BeginPlacement(), mutation_status(), PlaceItemAtPosition(), and PreflightPlacement().
|
private |
Definition at line 111 of file item_interaction_handler.h.
Referenced by BeginPlacement(), CancelPlacement(), DrawGhostPreview(), HandleClick(), and IsPlacementActive().
|
private |
Definition at line 112 of file item_interaction_handler.h.
Referenced by DrawGhostPreview(), GetItemId(), PlaceItemAtPosition(), and SetItemId().
|
private |
Definition at line 115 of file item_interaction_handler.h.
Referenced by ClearSelection(), DeleteSelected(), DrawSelectionHighlight(), GetSelectedIndex(), HandleDrag(), HandleRelease(), HasSelection(), NudgeSelected(), and SelectItem().
|
private |
Definition at line 116 of file item_interaction_handler.h.
Referenced by ClearSelection(), DrawSelectionHighlight(), HandleClick(), HandleDrag(), and HandleRelease().
|
private |
Definition at line 117 of file item_interaction_handler.h.
Referenced by HandleClick().
|
private |
Definition at line 118 of file item_interaction_handler.h.
Referenced by DrawSelectionHighlight(), HandleClick(), HandleDrag(), and HandleRelease().