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

Handles object selection, placement, and interaction within the dungeon canvas. More...

#include <dungeon_object_interaction.h>

Public Member Functions

 DungeonObjectInteraction (gui::Canvas *canvas)
 
void SetContext (const InteractionContext &ctx)
 Set the unified interaction context.
 
InteractionCoordinatorentity_coordinator ()
 Get the interaction coordinator for entity handling.
 
const InteractionCoordinatorentity_coordinator () const
 
void SetRom (Rom *rom)
 
void HandleCanvasMouseInput ()
 
void CheckForObjectSelection ()
 
void PlaceObjectAtPosition (int room_x, int room_y)
 
void DrawObjectSelectRect ()
 
void SelectObjectsInRect ()
 
void DrawSelectionHighlights ()
 
void DrawHoverHighlight (const std::vector< zelda3::RoomObject > &objects)
 
void DrawSelectBox ()
 
void DrawDragPreview ()
 
void DrawGhostPreview ()
 
void UpdateSelectedObjects ()
 
bool IsObjectInSelectBox (const zelda3::RoomObject &object) const
 
std::pair< int, int > RoomToCanvasCoordinates (int room_x, int room_y) const
 
std::pair< int, int > CanvasToRoomCoordinates (int canvas_x, int canvas_y) const
 
bool IsWithinCanvasBounds (int canvas_x, int canvas_y, int margin=32) const
 
void SetCurrentRoom (std::array< zelda3::Room, dungeon_coords::kRoomCount > *rooms, int room_id)
 
void SetPreviewObject (const zelda3::RoomObject &object, bool loaded)
 
void SetCurrentPaletteGroup (const gfx::PaletteGroup &group)
 
InteractionModeManagermode_manager ()
 
const InteractionModeManagermode_manager () const
 
bool IsObjectLoaded () const
 
void CancelPlacement ()
 
void SetDoorPlacementMode (bool enabled, zelda3::DoorType type=zelda3::DoorType::NormalDoor)
 
bool IsDoorPlacementActive () const
 
void SetPreviewDoorType (zelda3::DoorType type)
 
zelda3::DoorType GetPreviewDoorType () const
 
void DrawDoorGhostPreview ()
 
void PlaceDoorAtPosition (int canvas_x, int canvas_y)
 
void CancelDoorPlacement ()
 
void SetSpritePlacementMode (bool enabled, uint8_t sprite_id=0)
 
bool IsSpritePlacementActive () const
 
void SetPreviewSpriteId (uint8_t id)
 
uint8_t GetPreviewSpriteId () const
 
void DrawSpriteGhostPreview ()
 
void PlaceSpriteAtPosition (int canvas_x, int canvas_y)
 
void CancelSpritePlacement ()
 
void SetItemPlacementMode (bool enabled, uint8_t item_id=0)
 
bool IsItemPlacementActive () const
 
void SetPreviewItemId (uint8_t id)
 
uint8_t GetPreviewItemId () const
 
void DrawItemGhostPreview ()
 
void PlaceItemAtPosition (int canvas_x, int canvas_y)
 
void CancelItemPlacement ()
 
std::vector< size_t > GetSelectedObjectIndices () const
 
void SetSelectedObjects (const std::vector< size_t > &indices)
 
bool IsObjectSelectActive () const
 
void ClearSelection ()
 
bool IsObjectSelected (size_t index) const
 
size_t GetSelectionCount () const
 
void SetSelectionChangeCallback (std::function< void()> callback)
 
bool TrySelectObjectAtCursor ()
 
void HandleScrollWheelResize ()
 
size_t GetHoveredObjectIndex () const
 
void HandleDeleteSelected ()
 
void HandleCopySelected ()
 
void HandlePasteObjects ()
 
bool HasClipboardData () const
 
void SendSelectedToLayer (int target_layer)
 
void SendSelectedToFront ()
 
void SendSelectedToBack ()
 
void BringSelectedForward ()
 
void SendSelectedBackward ()
 
void SetLayerFilter (int layer)
 
int GetLayerFilter () const
 
bool IsLayerFilterActive () const
 
bool IsMaskModeActive () const
 
const char * GetLayerFilterName () const
 
void SetLayersMerged (bool merged)
 
bool AreLayersMerged () const
 
void HandleLayerKeyboardShortcuts ()
 
void SetObjectPlacedCallback (std::function< void(const zelda3::RoomObject &)> callback)
 
void SetCacheInvalidationCallback (std::function< void()> callback)
 
void SetMutationCallback (std::function< void()> callback)
 
void SetMutationHook (std::function< void()> callback)
 
void SetEditorSystem (zelda3::DungeonEditorSystem *system)
 
void SelectEntity (EntityType type, size_t index)
 
void ClearEntitySelection ()
 
bool HasEntitySelection () const
 
const SelectedEntityGetSelectedEntity () const
 
std::optional< SelectedEntityGetEntityAtPosition (int canvas_x, int canvas_y) const
 
void DrawEntitySelectionHighlights ()
 
void DrawDoorSnapIndicators ()
 
bool TrySelectEntityAtCursor ()
 
void HandleEntityDrag ()
 
void SetEntityChangedCallback (std::function< void()> callback)
 

Private Member Functions

std::pair< int, int > CalculateObjectBounds (const zelda3::RoomObject &object)
 
void RenderGhostPreviewBitmap ()
 

Private Attributes

gui::Canvascanvas_
 
zelda3::DungeonEditorSystemeditor_system_ = nullptr
 
std::array< zelda3::Room, dungeon_coords::kRoomCount > * rooms_ = nullptr
 
int current_room_id_ = 0
 
Romrom_ = nullptr
 
std::unique_ptr< zelda3::ObjectDrawerobject_drawer_
 
InteractionContext interaction_context_
 
InteractionCoordinator entity_coordinator_
 
InteractionModeManager mode_manager_
 
zelda3::RoomObject preview_object_ {0, 0, 0, 0, 0}
 
std::unique_ptr< gfx::BackgroundBufferghost_preview_buffer_
 
gfx::PaletteGroup current_palette_group_
 
ObjectSelection selection_
 
size_t hovered_object_index_ = static_cast<size_t>(-1)
 
bool has_hovered_object_ = false
 
std::function< void(const zelda3::RoomObject &) object_placed_callback_ )
 
std::vector< zelda3::RoomObjectclipboard_
 
bool has_clipboard_data_ = false
 
SelectedEntity selected_entity_
 
bool is_entity_mode_ = false
 

Detailed Description

Handles object selection, placement, and interaction within the dungeon canvas.

This component manages mouse interactions for object selection (similar to OverworldEditor), object placement, drag operations, and multi-object selection.

Definition at line 63 of file dungeon_object_interaction.h.

Constructor & Destructor Documentation

◆ DungeonObjectInteraction()

yaze::editor::DungeonObjectInteraction::DungeonObjectInteraction ( gui::Canvas * canvas)
inlineexplicit

Member Function Documentation

◆ SetContext()

void yaze::editor::DungeonObjectInteraction::SetContext ( const InteractionContext & ctx)
inline

Set the unified interaction context.

This is the preferred method for configuring the interaction handler. It propagates context to all sub-handlers.

Definition at line 81 of file dungeon_object_interaction.h.

References yaze::editor::InteractionContext::canvas, canvas_, entity_coordinator_, interaction_context_, and yaze::editor::InteractionCoordinator::SetContext().

Here is the call graph for this function:

◆ entity_coordinator() [1/2]

InteractionCoordinator & yaze::editor::DungeonObjectInteraction::entity_coordinator ( )
inline

Get the interaction coordinator for entity handling.

Use this for advanced entity operations (doors, sprites, items).

Definition at line 92 of file dungeon_object_interaction.h.

References entity_coordinator_.

◆ entity_coordinator() [2/2]

const InteractionCoordinator & yaze::editor::DungeonObjectInteraction::entity_coordinator ( ) const
inline

Definition at line 93 of file dungeon_object_interaction.h.

References entity_coordinator_.

◆ SetRom()

◆ HandleCanvasMouseInput()

◆ CheckForObjectSelection()

void yaze::editor::DungeonObjectInteraction::CheckForObjectSelection ( )

Definition at line 167 of file dungeon_object_interaction.cc.

References DrawObjectSelectRect().

Here is the call graph for this function:

◆ PlaceObjectAtPosition()

◆ DrawObjectSelectRect()

◆ SelectObjectsInRect()

void yaze::editor::DungeonObjectInteraction::SelectObjectsInRect ( )

Definition at line 212 of file dungeon_object_interaction.cc.

◆ DrawSelectionHighlights()

◆ DrawHoverHighlight()

◆ DrawSelectBox()

void yaze::editor::DungeonObjectInteraction::DrawSelectBox ( )

◆ DrawDragPreview()

◆ DrawGhostPreview()

◆ UpdateSelectedObjects()

void yaze::editor::DungeonObjectInteraction::UpdateSelectedObjects ( )

Definition at line 468 of file dungeon_object_interaction.cc.

◆ IsObjectInSelectBox()

bool yaze::editor::DungeonObjectInteraction::IsObjectInSelectBox ( const zelda3::RoomObject & object) const

Definition at line 473 of file dungeon_object_interaction.cc.

◆ RoomToCanvasCoordinates()

std::pair< int, int > yaze::editor::DungeonObjectInteraction::RoomToCanvasCoordinates ( int room_x,
int room_y ) const

◆ CanvasToRoomCoordinates()

std::pair< int, int > yaze::editor::DungeonObjectInteraction::CanvasToRoomCoordinates ( int canvas_x,
int canvas_y ) const

◆ IsWithinCanvasBounds()

bool yaze::editor::DungeonObjectInteraction::IsWithinCanvasBounds ( int canvas_x,
int canvas_y,
int margin = 32 ) const

Definition at line 492 of file dungeon_object_interaction.cc.

References canvas_, yaze::gui::Canvas::canvas_size(), and yaze::gui::Canvas::global_scale().

Here is the call graph for this function:

◆ SetCurrentRoom()

void yaze::editor::DungeonObjectInteraction::SetCurrentRoom ( std::array< zelda3::Room, dungeon_coords::kRoomCount > * rooms,
int room_id )

◆ SetPreviewObject()

◆ SetCurrentPaletteGroup()

void yaze::editor::DungeonObjectInteraction::SetCurrentPaletteGroup ( const gfx::PaletteGroup & group)
inline

◆ mode_manager() [1/2]

InteractionModeManager & yaze::editor::DungeonObjectInteraction::mode_manager ( )
inline

Definition at line 138 of file dungeon_object_interaction.h.

References mode_manager_.

◆ mode_manager() [2/2]

const InteractionModeManager & yaze::editor::DungeonObjectInteraction::mode_manager ( ) const
inline

Definition at line 139 of file dungeon_object_interaction.h.

References mode_manager_.

◆ IsObjectLoaded()

bool yaze::editor::DungeonObjectInteraction::IsObjectLoaded ( ) const
inline

◆ CancelPlacement()

void yaze::editor::DungeonObjectInteraction::CancelPlacement ( )
inline

◆ SetDoorPlacementMode()

◆ IsDoorPlacementActive()

bool yaze::editor::DungeonObjectInteraction::IsDoorPlacementActive ( ) const
inline

◆ SetPreviewDoorType()

void yaze::editor::DungeonObjectInteraction::SetPreviewDoorType ( zelda3::DoorType type)
inline

Definition at line 156 of file dungeon_object_interaction.h.

References yaze::editor::InteractionModeManager::GetModeState(), mode_manager_, and yaze::editor::ModeState::preview_door_type.

Here is the call graph for this function:

◆ GetPreviewDoorType()

zelda3::DoorType yaze::editor::DungeonObjectInteraction::GetPreviewDoorType ( ) const
inline

◆ DrawDoorGhostPreview()

◆ PlaceDoorAtPosition()

◆ CancelDoorPlacement()

void yaze::editor::DungeonObjectInteraction::CancelDoorPlacement ( )
inline

◆ SetSpritePlacementMode()

◆ IsSpritePlacementActive()

bool yaze::editor::DungeonObjectInteraction::IsSpritePlacementActive ( ) const
inline

◆ SetPreviewSpriteId()

void yaze::editor::DungeonObjectInteraction::SetPreviewSpriteId ( uint8_t id)
inline

Definition at line 176 of file dungeon_object_interaction.h.

References yaze::editor::InteractionModeManager::GetModeState(), mode_manager_, and yaze::editor::ModeState::preview_sprite_id.

Here is the call graph for this function:

◆ GetPreviewSpriteId()

uint8_t yaze::editor::DungeonObjectInteraction::GetPreviewSpriteId ( ) const
inline

◆ DrawSpriteGhostPreview()

◆ PlaceSpriteAtPosition()

◆ CancelSpritePlacement()

void yaze::editor::DungeonObjectInteraction::CancelSpritePlacement ( )
inline

◆ SetItemPlacementMode()

◆ IsItemPlacementActive()

bool yaze::editor::DungeonObjectInteraction::IsItemPlacementActive ( ) const
inline

◆ SetPreviewItemId()

void yaze::editor::DungeonObjectInteraction::SetPreviewItemId ( uint8_t id)
inline

Definition at line 195 of file dungeon_object_interaction.h.

References yaze::editor::InteractionModeManager::GetModeState(), mode_manager_, and yaze::editor::ModeState::preview_item_id.

Here is the call graph for this function:

◆ GetPreviewItemId()

uint8_t yaze::editor::DungeonObjectInteraction::GetPreviewItemId ( ) const
inline

◆ DrawItemGhostPreview()

◆ PlaceItemAtPosition()

◆ CancelItemPlacement()

void yaze::editor::DungeonObjectInteraction::CancelItemPlacement ( )
inline

◆ GetSelectedObjectIndices()

◆ SetSelectedObjects()

void yaze::editor::DungeonObjectInteraction::SetSelectedObjects ( const std::vector< size_t > & indices)
inline

◆ IsObjectSelectActive()

bool yaze::editor::DungeonObjectInteraction::IsObjectSelectActive ( ) const
inline

◆ ClearSelection()

◆ IsObjectSelected()

bool yaze::editor::DungeonObjectInteraction::IsObjectSelected ( size_t index) const
inline

Definition at line 223 of file dungeon_object_interaction.h.

References yaze::editor::ObjectSelection::IsObjectSelected(), and selection_.

Here is the call graph for this function:

◆ GetSelectionCount()

size_t yaze::editor::DungeonObjectInteraction::GetSelectionCount ( ) const
inline

Definition at line 226 of file dungeon_object_interaction.h.

References yaze::editor::ObjectSelection::GetSelectionCount(), and selection_.

Referenced by yaze::editor::ObjectEditorPanel::OnSelectionChanged().

Here is the call graph for this function:

◆ SetSelectionChangeCallback()

void yaze::editor::DungeonObjectInteraction::SetSelectionChangeCallback ( std::function< void()> callback)
inline

Definition at line 229 of file dungeon_object_interaction.h.

References selection_, and yaze::editor::ObjectSelection::SetSelectionChangedCallback().

Referenced by yaze::editor::ObjectEditorPanel::SetupSelectionCallbacks().

Here is the call graph for this function:

◆ TrySelectObjectAtCursor()

bool yaze::editor::DungeonObjectInteraction::TrySelectObjectAtCursor ( )

◆ HandleScrollWheelResize()

◆ GetHoveredObjectIndex()

size_t yaze::editor::DungeonObjectInteraction::GetHoveredObjectIndex ( ) const

◆ HandleDeleteSelected()

◆ HandleCopySelected()

void yaze::editor::DungeonObjectInteraction::HandleCopySelected ( )

Definition at line 637 of file dungeon_object_interaction.cc.

References clipboard_, current_room_id_, yaze::editor::ObjectSelection::GetSelectedIndices(), has_clipboard_data_, rooms_, and selection_.

Here is the call graph for this function:

◆ HandlePasteObjects()

◆ HasClipboardData()

bool yaze::editor::DungeonObjectInteraction::HasClipboardData ( ) const
inline

Definition at line 243 of file dungeon_object_interaction.h.

References has_clipboard_data_.

◆ SendSelectedToLayer()

void yaze::editor::DungeonObjectInteraction::SendSelectedToLayer ( int target_layer)

◆ SendSelectedToFront()

◆ SendSelectedToBack()

◆ BringSelectedForward()

◆ SendSelectedBackward()

◆ SetLayerFilter()

void yaze::editor::DungeonObjectInteraction::SetLayerFilter ( int layer)
inline

Definition at line 256 of file dungeon_object_interaction.h.

References selection_, and yaze::editor::ObjectSelection::SetLayerFilter().

Referenced by yaze::editor::DungeonCanvasViewer::DrawDungeonCanvas().

Here is the call graph for this function:

◆ GetLayerFilter()

int yaze::editor::DungeonObjectInteraction::GetLayerFilter ( ) const
inline

Definition at line 257 of file dungeon_object_interaction.h.

References yaze::editor::ObjectSelection::GetLayerFilter(), and selection_.

Referenced by yaze::editor::DungeonCanvasViewer::DrawDungeonCanvas().

Here is the call graph for this function:

◆ IsLayerFilterActive()

bool yaze::editor::DungeonObjectInteraction::IsLayerFilterActive ( ) const
inline

Definition at line 258 of file dungeon_object_interaction.h.

References yaze::editor::ObjectSelection::IsLayerFilterActive(), and selection_.

Referenced by yaze::editor::DungeonCanvasViewer::DrawDungeonCanvas().

Here is the call graph for this function:

◆ IsMaskModeActive()

bool yaze::editor::DungeonObjectInteraction::IsMaskModeActive ( ) const
inline

Definition at line 259 of file dungeon_object_interaction.h.

References yaze::editor::ObjectSelection::IsMaskModeActive(), and selection_.

Here is the call graph for this function:

◆ GetLayerFilterName()

const char * yaze::editor::DungeonObjectInteraction::GetLayerFilterName ( ) const
inline

Definition at line 260 of file dungeon_object_interaction.h.

References yaze::editor::ObjectSelection::GetLayerFilterName(), and selection_.

Here is the call graph for this function:

◆ SetLayersMerged()

void yaze::editor::DungeonObjectInteraction::SetLayersMerged ( bool merged)
inline

Definition at line 261 of file dungeon_object_interaction.h.

References selection_, and yaze::editor::ObjectSelection::SetLayersMerged().

Referenced by yaze::editor::DungeonCanvasViewer::DrawDungeonCanvas().

Here is the call graph for this function:

◆ AreLayersMerged()

bool yaze::editor::DungeonObjectInteraction::AreLayersMerged ( ) const
inline

Definition at line 262 of file dungeon_object_interaction.h.

References yaze::editor::ObjectSelection::AreLayersMerged(), and selection_.

Here is the call graph for this function:

◆ HandleLayerKeyboardShortcuts()

void yaze::editor::DungeonObjectInteraction::HandleLayerKeyboardShortcuts ( )

◆ SetObjectPlacedCallback()

void yaze::editor::DungeonObjectInteraction::SetObjectPlacedCallback ( std::function< void(const zelda3::RoomObject &)> callback)
inline

Definition at line 268 of file dungeon_object_interaction.h.

References object_placed_callback_.

◆ SetCacheInvalidationCallback()

void yaze::editor::DungeonObjectInteraction::SetCacheInvalidationCallback ( std::function< void()> callback)
inline

◆ SetMutationCallback()

void yaze::editor::DungeonObjectInteraction::SetMutationCallback ( std::function< void()> callback)
inline

◆ SetMutationHook()

void yaze::editor::DungeonObjectInteraction::SetMutationHook ( std::function< void()> callback)
inline

Definition at line 282 of file dungeon_object_interaction.h.

References SetMutationCallback().

Here is the call graph for this function:

◆ SetEditorSystem()

void yaze::editor::DungeonObjectInteraction::SetEditorSystem ( zelda3::DungeonEditorSystem * system)
inline

◆ SelectEntity()

◆ ClearEntitySelection()

◆ HasEntitySelection()

bool yaze::editor::DungeonObjectInteraction::HasEntitySelection ( ) const
inline

◆ GetSelectedEntity()

const SelectedEntity & yaze::editor::DungeonObjectInteraction::GetSelectedEntity ( ) const
inline

Definition at line 294 of file dungeon_object_interaction.h.

References selected_entity_.

◆ GetEntityAtPosition()

std::optional< SelectedEntity > yaze::editor::DungeonObjectInteraction::GetEntityAtPosition ( int canvas_x,
int canvas_y ) const

◆ DrawEntitySelectionHighlights()

◆ DrawDoorSnapIndicators()

◆ TrySelectEntityAtCursor()

◆ HandleEntityDrag()

◆ SetEntityChangedCallback()

void yaze::editor::DungeonObjectInteraction::SetEntityChangedCallback ( std::function< void()> callback)
inline

◆ CalculateObjectBounds()

std::pair< int, int > yaze::editor::DungeonObjectInteraction::CalculateObjectBounds ( const zelda3::RoomObject & object)
private

Definition at line 909 of file dungeon_object_interaction.cc.

References current_room_id_, yaze::zelda3::ObjectDimensionTable::Get(), object_drawer_, and rom_.

Referenced by DrawDragPreview(), GetHoveredObjectIndex(), and RenderGhostPreviewBitmap().

Here is the call graph for this function:

◆ RenderGhostPreviewBitmap()

Member Data Documentation

◆ canvas_

◆ editor_system_

zelda3::DungeonEditorSystem* yaze::editor::DungeonObjectInteraction::editor_system_ = nullptr
private

Definition at line 315 of file dungeon_object_interaction.h.

Referenced by SetEditorSystem().

◆ rooms_

◆ current_room_id_

◆ rom_

Rom* yaze::editor::DungeonObjectInteraction::rom_ = nullptr
private

◆ object_drawer_

std::unique_ptr<zelda3::ObjectDrawer> yaze::editor::DungeonObjectInteraction::object_drawer_
private

◆ interaction_context_

◆ entity_coordinator_

◆ mode_manager_

◆ preview_object_

zelda3::RoomObject yaze::editor::DungeonObjectInteraction::preview_object_ {0, 0, 0, 0, 0}
private

◆ ghost_preview_buffer_

std::unique_ptr<gfx::BackgroundBuffer> yaze::editor::DungeonObjectInteraction::ghost_preview_buffer_
private

◆ current_palette_group_

gfx::PaletteGroup yaze::editor::DungeonObjectInteraction::current_palette_group_
private

◆ selection_

◆ hovered_object_index_

size_t yaze::editor::DungeonObjectInteraction::hovered_object_index_ = static_cast<size_t>(-1)
private

Definition at line 343 of file dungeon_object_interaction.h.

◆ has_hovered_object_

bool yaze::editor::DungeonObjectInteraction::has_hovered_object_ = false
private

Definition at line 344 of file dungeon_object_interaction.h.

◆ object_placed_callback_

std::function<void(const zelda3::RoomObject&) yaze::editor::DungeonObjectInteraction::object_placed_callback_)
private

Definition at line 347 of file dungeon_object_interaction.h.

Referenced by PlaceObjectAtPosition(), and SetObjectPlacedCallback().

◆ clipboard_

std::vector<zelda3::RoomObject> yaze::editor::DungeonObjectInteraction::clipboard_
private

Definition at line 350 of file dungeon_object_interaction.h.

Referenced by HandleCopySelected(), and HandlePasteObjects().

◆ has_clipboard_data_

bool yaze::editor::DungeonObjectInteraction::has_clipboard_data_ = false
private

◆ selected_entity_

SelectedEntity yaze::editor::DungeonObjectInteraction::selected_entity_
private

◆ is_entity_mode_

bool yaze::editor::DungeonObjectInteraction::is_entity_mode_ = false
private

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