yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::editor::ItemInteractionHandler Class Reference

Handles pot item placement and interaction in the dungeon editor. More...

#include <item_interaction_handler.h>

Inheritance diagram for yaze::editor::ItemInteractionHandler:
Collaboration diagram for yaze::editor::ItemInteractionHandler:

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.
 
- Public Member Functions inherited from yaze::editor::BaseEntityHandler
virtual ~BaseEntityHandler ()=default
 
void SetContext (InteractionContext *ctx)
 Set the interaction context.
 
InteractionContextcontext () const
 Get the interaction context.
 

Private Member Functions

void PlaceItemAtPosition (int canvas_x, int canvas_y)
 Place item at position.
 

Private Attributes

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
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::RoomGetCurrentRoom () const
 Get current room (convenience method)
 
- Protected Attributes inherited from yaze::editor::BaseEntityHandler
InteractionContextctx_ = nullptr
 

Detailed Description

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 15 of file item_interaction_handler.h.

Member Function Documentation

◆ BeginPlacement()

void yaze::editor::ItemInteractionHandler::BeginPlacement ( )
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 16 of file item_interaction_handler.cc.

References ClearSelection(), and item_placement_mode_.

Referenced by yaze::editor::InteractionCoordinator::SetMode().

Here is the call graph for this function:

◆ CancelPlacement()

void yaze::editor::ItemInteractionHandler::CancelPlacement ( )
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 22 of file item_interaction_handler.h.

References item_placement_mode_.

Referenced by yaze::editor::InteractionCoordinator::CancelCurrentMode().

◆ IsPlacementActive()

bool yaze::editor::ItemInteractionHandler::IsPlacementActive ( ) const
inlineoverridevirtual

◆ HandleClick()

bool yaze::editor::ItemInteractionHandler::HandleClick ( int canvas_x,
int canvas_y )
overridevirtual

Handle mouse click at canvas position.

Parameters
canvas_xUnscaled X position relative to canvas origin
canvas_yUnscaled Y position relative to canvas origin
Returns
true if click was handled by this handler

Implements yaze::editor::BaseEntityHandler.

Definition at line 21 of file item_interaction_handler.cc.

References ClearSelection(), drag_current_pos_, drag_start_pos_, GetEntityAtPosition(), yaze::editor::BaseEntityHandler::HasValidContext(), is_dragging_, item_placement_mode_, PlaceItemAtPosition(), and SelectItem().

Referenced by yaze::editor::InteractionCoordinator::HandleClick(), and yaze::editor::InteractionCoordinator::TrySelectEntityAtCursor().

◆ HandleDrag()

void yaze::editor::ItemInteractionHandler::HandleDrag ( ImVec2 current_pos,
ImVec2 delta )
overridevirtual

Handle mouse drag.

Parameters
current_posCurrent mouse position (screen coords)
deltaMouse movement since last frame

Implements yaze::editor::BaseEntityHandler.

Definition at line 44 of file item_interaction_handler.cc.

References drag_current_pos_, is_dragging_, and selected_item_index_.

Referenced by yaze::editor::InteractionCoordinator::HandleDrag().

◆ HandleRelease()

void yaze::editor::ItemInteractionHandler::HandleRelease ( )
overridevirtual

◆ DrawGhostPreview()

void yaze::editor::ItemInteractionHandler::DrawGhostPreview ( )
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 89 of file item_interaction_handler.cc.

References yaze::editor::InteractionContext::canvas, yaze::editor::BaseEntityHandler::ctx_, yaze::editor::BaseEntityHandler::GetCanvasScale(), yaze::editor::BaseEntityHandler::HasValidContext(), item_placement_mode_, yaze::editor::dungeon_coords::kTileSize, and preview_item_id_.

Referenced by yaze::editor::InteractionCoordinator::DrawGhostPreviews().

Here is the call graph for this function:

◆ DrawSelectionHighlight()

void yaze::editor::ItemInteractionHandler::DrawSelectionHighlight ( )
overridevirtual

◆ GetEntityAtPosition()

std::optional< size_t > yaze::editor::ItemInteractionHandler::GetEntityAtPosition ( int canvas_x,
int canvas_y ) const
overridevirtual

Get entity at canvas position.

Parameters
canvas_xUnscaled X position relative to canvas origin
canvas_yUnscaled Y position relative to canvas origin
Returns
Entity index if found, nullopt otherwise

Implements yaze::editor::BaseEntityHandler.

Definition at line 177 of file item_interaction_handler.cc.

References yaze::editor::BaseEntityHandler::ctx_, yaze::editor::BaseEntityHandler::GetCanvasScale(), yaze::editor::InteractionContext::GetCurrentRoomConst(), and yaze::editor::BaseEntityHandler::HasValidContext().

Referenced by HandleClick().

Here is the call graph for this function:

◆ SetItemId()

void yaze::editor::ItemInteractionHandler::SetItemId ( uint8_t id)
inline

Set item ID for placement.

Definition at line 42 of file item_interaction_handler.h.

References preview_item_id_.

◆ GetItemId()

uint8_t yaze::editor::ItemInteractionHandler::GetItemId ( ) const
inline

Get current item ID for placement.

Definition at line 47 of file item_interaction_handler.h.

References preview_item_id_.

◆ SelectItem()

void yaze::editor::ItemInteractionHandler::SelectItem ( size_t index)

Select item at index.

Definition at line 207 of file item_interaction_handler.cc.

References yaze::editor::BaseEntityHandler::ctx_, yaze::editor::InteractionContext::NotifyEntityChanged(), and selected_item_index_.

Referenced by HandleClick().

Here is the call graph for this function:

◆ ClearSelection()

void yaze::editor::ItemInteractionHandler::ClearSelection ( )

◆ HasSelection()

◆ GetSelectedIndex()

std::optional< size_t > yaze::editor::ItemInteractionHandler::GetSelectedIndex ( ) const
inline

Get selected item index.

Definition at line 67 of file item_interaction_handler.h.

References selected_item_index_.

◆ DeleteSelected()

◆ PlaceItemAtPosition()

Member Data Documentation

◆ item_placement_mode_

bool yaze::editor::ItemInteractionHandler::item_placement_mode_ = false
private

◆ preview_item_id_

uint8_t yaze::editor::ItemInteractionHandler::preview_item_id_ = 0
private

◆ selected_item_index_

std::optional<size_t> yaze::editor::ItemInteractionHandler::selected_item_index_
private

◆ is_dragging_

bool yaze::editor::ItemInteractionHandler::is_dragging_ = false
private

◆ drag_start_pos_

ImVec2 yaze::editor::ItemInteractionHandler::drag_start_pos_
private

Definition at line 82 of file item_interaction_handler.h.

Referenced by HandleClick().

◆ drag_current_pos_

ImVec2 yaze::editor::ItemInteractionHandler::drag_current_pos_
private

The documentation for this class was generated from the following files: