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

Handles functional mutations and queries for tile objects. More...

#include <tile_object_handler.h>

Inheritance diagram for yaze::editor::TileObjectHandler:
Collaboration diagram for yaze::editor::TileObjectHandler:

Public Types

enum class  PlacementBlockReason { kNone = 0 , kInvalidRoom , kObjectLimit }
 

Public Member Functions

 TileObjectHandler ()
 
 TileObjectHandler (InteractionContext *ctx)
 
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.
 
bool HandleMouseWheel (float delta) override
 
void DrawGhostPreview () override
 Draw ghost preview during placement.
 
void DrawSelectionHighlight () override
 Draw selection highlight for selected entities.
 
void InitDrag (const ImVec2 &start_pos)
 
void BeginMarqueeSelection (const ImVec2 &start_pos)
 
void HandleMarqueeSelection (const ImVec2 &mouse_pos, bool mouse_left_down, bool mouse_left_released, bool shift_down, bool toggle_down, bool alt_down, bool draw_box=true)
 
std::optional< size_t > GetEntityAtPosition (int canvas_x, int canvas_y) const override
 Get entity at canvas position.
 
void MoveObjects (int room_id, const std::vector< size_t > &indices, int delta_x, int delta_y, bool notify_mutation=true)
 Move a set of objects by a tile delta.
 
std::vector< size_t > DuplicateObjects (int room_id, const std::vector< size_t > &indices, int delta_x, int delta_y, bool notify_mutation=true)
 Clone a set of objects and move them by a tile delta.
 
void DeleteObjects (int room_id, std::vector< size_t > indices)
 Delete objects by indices.
 
void DeleteAllObjects (int room_id)
 Delete all objects in a room.
 
void SendToFront (int room_id, const std::vector< size_t > &indices)
 Reorder objects.
 
void SendToBack (int room_id, const std::vector< size_t > &indices)
 
void MoveForward (int room_id, const std::vector< size_t > &indices)
 
void MoveBackward (int room_id, const std::vector< size_t > &indices)
 
void ResizeObjects (int room_id, const std::vector< size_t > &indices, int delta)
 Resize objects by a delta.
 
bool PlaceObjectAt (int room_id, const zelda3::RoomObject &object, int x, int y)
 Place a new object. Returns false if blocked by ROM limits.
 
bool was_placement_blocked () const
 True if the most recent PlaceObjectAt was blocked.
 
PlacementBlockReason placement_block_reason () const
 
void clear_placement_blocked ()
 
void UpdateObjectsId (int room_id, const std::vector< size_t > &indices, int16_t new_id)
 
void UpdateObjectsSize (int room_id, const std::vector< size_t > &indices, uint8_t new_size)
 
void UpdateObjectsLayer (int room_id, const std::vector< size_t > &indices, int new_layer)
 
void SetPreviewObject (const zelda3::RoomObject &object)
 Set object for placement.
 
void CopyObjectsToClipboard (int room_id, const std::vector< size_t > &indices)
 Copy objects to internal clipboard.
 
std::vector< size_t > PasteFromClipboard (int room_id, int offset_x, int offset_y)
 Paste objects from clipboard with offset.
 
std::vector< size_t > PasteFromClipboardAt (int room_id, int target_x, int target_y)
 Paste objects from clipboard at target location. Use first clipboard item as origin.
 
bool HasClipboardData () const
 Check if clipboard has data.
 
void ClearClipboard ()
 Clear the clipboard.
 
- 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.
 
void DrawPostPlacementToast ()
 

Private Member Functions

void RenderGhostPreviewBitmap ()
 
std::pair< int, int > CalculateObjectBounds (const zelda3::RoomObject &object)
 
ImVec2 ApplyDragModifiers (const ImVec2 &delta) const
 
zelda3::RoomGetRoom (int room_id)
 
void NotifyChange (zelda3::Room *room)
 

Private Attributes

bool object_placement_mode_ = false
 
PlacementBlockReason placement_block_reason_ = PlacementBlockReason::kNone
 
zelda3::RoomObject preview_object_ {-1, 0, 0, 0}
 
std::unique_ptr< gfx::BackgroundBufferghost_preview_buffer_
 
std::vector< zelda3::RoomObjectclipboard_
 
bool is_dragging_ = false
 
ImVec2 drag_start_ {0, 0}
 
ImVec2 drag_current_ {0, 0}
 
int drag_last_dx_ = 0
 
int drag_last_dy_ = 0
 
bool drag_has_duplicated_ = false
 
bool drag_mutation_started_ = false
 

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::RoomGetCurrentRoom () const
 Get current room (convenience method)
 
- Protected Attributes inherited from yaze::editor::BaseEntityHandler
InteractionContextctx_ = nullptr
 
float toast_expire_time_ = 0.0f
 
- Static Protected Attributes inherited from yaze::editor::BaseEntityHandler
static constexpr float kToastDuration = 1.5f
 

Detailed Description

Handles functional mutations and queries for tile objects.

This class abstracts the raw manipulation of zelda3::RoomObject vectors, providing a cleaner API for the UI and future CLI.

Definition at line 19 of file tile_object_handler.h.

Member Enumeration Documentation

◆ PlacementBlockReason

Enumerator
kNone 
kInvalidRoom 
kObjectLimit 

Definition at line 21 of file tile_object_handler.h.

Constructor & Destructor Documentation

◆ TileObjectHandler() [1/2]

yaze::editor::TileObjectHandler::TileObjectHandler ( )
inline

Definition at line 27 of file tile_object_handler.h.

◆ TileObjectHandler() [2/2]

yaze::editor::TileObjectHandler::TileObjectHandler ( InteractionContext * ctx)
inlineexplicit

Definition at line 28 of file tile_object_handler.h.

References yaze::editor::BaseEntityHandler::SetContext().

Here is the call graph for this function:

Member Function Documentation

◆ BeginPlacement()

void yaze::editor::TileObjectHandler::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 44 of file tile_object_handler.cc.

References object_placement_mode_, and RenderGhostPreviewBitmap().

Here is the call graph for this function:

◆ CancelPlacement()

void yaze::editor::TileObjectHandler::CancelPlacement ( )
overridevirtual

Cancel current placement.

Called when user presses Escape or switches modes. Override to clean up placement state.

Implements yaze::editor::BaseEntityHandler.

Definition at line 49 of file tile_object_handler.cc.

References ghost_preview_buffer_, and object_placement_mode_.

Referenced by yaze::editor::InteractionCoordinator::CancelCurrentMode(), and yaze::editor::InteractionCoordinator::CancelPlacement().

◆ IsPlacementActive()

◆ HandleClick()

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

◆ HandleDrag()

◆ HandleRelease()

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

Handle mouse release.

Called when left mouse button is released after a drag.

Implements yaze::editor::BaseEntityHandler.

Definition at line 208 of file tile_object_handler.cc.

References yaze::editor::BaseEntityHandler::ctx_, drag_has_duplicated_, drag_mutation_started_, is_dragging_, yaze::editor::kTileObjects, and yaze::editor::InteractionContext::NotifyInvalidateCache().

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

Here is the call graph for this function:

◆ HandleMouseWheel()

◆ DrawGhostPreview()

◆ DrawSelectionHighlight()

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

◆ InitDrag()

void yaze::editor::TileObjectHandler::InitDrag ( const ImVec2 & start_pos)

◆ BeginMarqueeSelection()

void yaze::editor::TileObjectHandler::BeginMarqueeSelection ( const ImVec2 & start_pos)

◆ HandleMarqueeSelection()

◆ GetEntityAtPosition()

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

◆ MoveObjects()

void yaze::editor::TileObjectHandler::MoveObjects ( int room_id,
const std::vector< size_t > & indices,
int delta_x,
int delta_y,
bool notify_mutation = true )

Move a set of objects by a tile delta.

Definition at line 359 of file tile_object_handler.cc.

References yaze::editor::BaseEntityHandler::ctx_, GetRoom(), yaze::editor::kTileObjects, NotifyChange(), and yaze::editor::InteractionContext::NotifyMutation().

Referenced by HandleDrag().

Here is the call graph for this function:

◆ DuplicateObjects()

std::vector< size_t > yaze::editor::TileObjectHandler::DuplicateObjects ( int room_id,
const std::vector< size_t > & indices,
int delta_x,
int delta_y,
bool notify_mutation = true )

Clone a set of objects and move them by a tile delta.

Returns
Indices of the newly created clones.

Definition at line 497 of file tile_object_handler.cc.

References yaze::editor::BaseEntityHandler::ctx_, GetRoom(), yaze::editor::kTileObjects, NotifyChange(), and yaze::editor::InteractionContext::NotifyMutation().

Referenced by HandleDrag().

Here is the call graph for this function:

◆ DeleteObjects()

void yaze::editor::TileObjectHandler::DeleteObjects ( int room_id,
std::vector< size_t > indices )

Delete objects by indices.

Definition at line 522 of file tile_object_handler.cc.

References yaze::editor::BaseEntityHandler::ctx_, GetRoom(), yaze::editor::kTileObjects, NotifyChange(), and yaze::editor::InteractionContext::NotifyMutation().

Here is the call graph for this function:

◆ DeleteAllObjects()

void yaze::editor::TileObjectHandler::DeleteAllObjects ( int room_id)

Delete all objects in a room.

Definition at line 535 of file tile_object_handler.cc.

References yaze::editor::BaseEntityHandler::ctx_, GetRoom(), yaze::editor::kTileObjects, NotifyChange(), and yaze::editor::InteractionContext::NotifyMutation().

Here is the call graph for this function:

◆ SendToFront()

void yaze::editor::TileObjectHandler::SendToFront ( int room_id,
const std::vector< size_t > & indices )

Reorder objects.

Definition at line 543 of file tile_object_handler.cc.

References yaze::editor::BaseEntityHandler::ctx_, GetRoom(), yaze::editor::kTileObjects, NotifyChange(), and yaze::editor::InteractionContext::NotifyMutation().

Here is the call graph for this function:

◆ SendToBack()

void yaze::editor::TileObjectHandler::SendToBack ( int room_id,
const std::vector< size_t > & indices )

◆ MoveForward()

void yaze::editor::TileObjectHandler::MoveForward ( int room_id,
const std::vector< size_t > & indices )

◆ MoveBackward()

void yaze::editor::TileObjectHandler::MoveBackward ( int room_id,
const std::vector< size_t > & indices )

◆ ResizeObjects()

void yaze::editor::TileObjectHandler::ResizeObjects ( int room_id,
const std::vector< size_t > & indices,
int delta )

Resize objects by a delta.

Definition at line 617 of file tile_object_handler.cc.

References yaze::editor::BaseEntityHandler::ctx_, GetRoom(), yaze::editor::kTileObjects, NotifyChange(), and yaze::editor::InteractionContext::NotifyMutation().

Referenced by HandleMouseWheel().

Here is the call graph for this function:

◆ PlaceObjectAt()

bool yaze::editor::TileObjectHandler::PlaceObjectAt ( int room_id,
const zelda3::RoomObject & object,
int x,
int y )

◆ was_placement_blocked()

bool yaze::editor::TileObjectHandler::was_placement_blocked ( ) const
inline

True if the most recent PlaceObjectAt was blocked.

Definition at line 107 of file tile_object_handler.h.

References kNone, and placement_block_reason_.

◆ placement_block_reason()

PlacementBlockReason yaze::editor::TileObjectHandler::placement_block_reason ( ) const
inline

Definition at line 110 of file tile_object_handler.h.

References placement_block_reason_.

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

◆ clear_placement_blocked()

void yaze::editor::TileObjectHandler::clear_placement_blocked ( )
inline

Definition at line 113 of file tile_object_handler.h.

References kNone, and placement_block_reason_.

◆ UpdateObjectsId()

void yaze::editor::TileObjectHandler::UpdateObjectsId ( int room_id,
const std::vector< size_t > & indices,
int16_t new_id )

◆ UpdateObjectsSize()

void yaze::editor::TileObjectHandler::UpdateObjectsSize ( int room_id,
const std::vector< size_t > & indices,
uint8_t new_size )

◆ UpdateObjectsLayer()

void yaze::editor::TileObjectHandler::UpdateObjectsLayer ( int room_id,
const std::vector< size_t > & indices,
int new_layer )

◆ SetPreviewObject()

void yaze::editor::TileObjectHandler::SetPreviewObject ( const zelda3::RoomObject & object)

Set object for placement.

Definition at line 657 of file tile_object_handler.cc.

References object_placement_mode_, preview_object_, and RenderGhostPreviewBitmap().

Here is the call graph for this function:

◆ CopyObjectsToClipboard()

void yaze::editor::TileObjectHandler::CopyObjectsToClipboard ( int room_id,
const std::vector< size_t > & indices )

Copy objects to internal clipboard.

Definition at line 703 of file tile_object_handler.cc.

References clipboard_, and GetRoom().

Here is the call graph for this function:

◆ PasteFromClipboard()

std::vector< size_t > yaze::editor::TileObjectHandler::PasteFromClipboard ( int room_id,
int offset_x,
int offset_y )

Paste objects from clipboard with offset.

Returns
Indices of newly pasted objects.

Definition at line 718 of file tile_object_handler.cc.

References clipboard_, yaze::editor::BaseEntityHandler::ctx_, GetRoom(), yaze::editor::kTileObjects, NotifyChange(), and yaze::editor::InteractionContext::NotifyMutation().

Referenced by PasteFromClipboardAt().

Here is the call graph for this function:

◆ PasteFromClipboardAt()

std::vector< size_t > yaze::editor::TileObjectHandler::PasteFromClipboardAt ( int room_id,
int target_x,
int target_y )

Paste objects from clipboard at target location. Use first clipboard item as origin.

Definition at line 739 of file tile_object_handler.cc.

References clipboard_, and PasteFromClipboard().

Here is the call graph for this function:

◆ HasClipboardData()

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

Check if clipboard has data.

Definition at line 152 of file tile_object_handler.h.

References clipboard_.

Referenced by yaze::editor::DungeonObjectInteraction::HasClipboardData().

◆ ClearClipboard()

void yaze::editor::TileObjectHandler::ClearClipboard ( )
inline

Clear the clipboard.

Definition at line 157 of file tile_object_handler.h.

References clipboard_.

◆ RenderGhostPreviewBitmap()

◆ CalculateObjectBounds()

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

Definition at line 694 of file tile_object_handler.cc.

References yaze::zelda3::DimensionService::Get(), and yaze::zelda3::DimensionService::GetPixelDimensions().

Referenced by DrawGhostPreview(), and RenderGhostPreviewBitmap().

Here is the call graph for this function:

◆ ApplyDragModifiers()

ImVec2 yaze::editor::TileObjectHandler::ApplyDragModifiers ( const ImVec2 & delta) const
private

Definition at line 224 of file tile_object_handler.cc.

Referenced by HandleDrag().

◆ GetRoom()

◆ NotifyChange()

Member Data Documentation

◆ object_placement_mode_

bool yaze::editor::TileObjectHandler::object_placement_mode_ = false
private

◆ placement_block_reason_

PlacementBlockReason yaze::editor::TileObjectHandler::placement_block_reason_ = PlacementBlockReason::kNone
private

◆ preview_object_

zelda3::RoomObject yaze::editor::TileObjectHandler::preview_object_ {-1, 0, 0, 0}
private

◆ ghost_preview_buffer_

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

◆ clipboard_

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

◆ is_dragging_

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

Definition at line 173 of file tile_object_handler.h.

Referenced by HandleDrag(), HandleRelease(), and InitDrag().

◆ drag_start_

ImVec2 yaze::editor::TileObjectHandler::drag_start_ {0, 0}
private

Definition at line 174 of file tile_object_handler.h.

Referenced by HandleDrag(), and InitDrag().

◆ drag_current_

ImVec2 yaze::editor::TileObjectHandler::drag_current_ {0, 0}
private

Definition at line 175 of file tile_object_handler.h.

Referenced by HandleDrag(), and InitDrag().

◆ drag_last_dx_

int yaze::editor::TileObjectHandler::drag_last_dx_ = 0
private

Definition at line 176 of file tile_object_handler.h.

Referenced by HandleDrag(), and InitDrag().

◆ drag_last_dy_

int yaze::editor::TileObjectHandler::drag_last_dy_ = 0
private

Definition at line 177 of file tile_object_handler.h.

Referenced by HandleDrag(), and InitDrag().

◆ drag_has_duplicated_

bool yaze::editor::TileObjectHandler::drag_has_duplicated_ = false
private

Definition at line 178 of file tile_object_handler.h.

Referenced by HandleDrag(), HandleRelease(), and InitDrag().

◆ drag_mutation_started_

bool yaze::editor::TileObjectHandler::drag_mutation_started_ = false
private

Definition at line 179 of file tile_object_handler.h.

Referenced by HandleDrag(), HandleRelease(), and InitDrag().


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