yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
tile_object_handler.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_INTERACTION_TILE_OBJECT_HANDLER_H
2#define YAZE_APP_EDITOR_DUNGEON_INTERACTION_TILE_OBJECT_HANDLER_H
3
4#include <vector>
11
12namespace yaze::editor {
13
21 public:
33
35 kNone = 0,
38 };
39
42
43 // ========================================================================
44 // BaseEntityHandler interface
45 // ========================================================================
46
47 void BeginPlacement() override;
48 void CancelPlacement() override;
49 bool IsPlacementActive() const override { return object_placement_mode_; }
50
51 bool HandleClick(int canvas_x, int canvas_y) override;
52 void HandleDrag(ImVec2 current_pos, ImVec2 delta) override;
53 void HandleRelease() override;
54 bool HandleMouseWheel(float delta) override;
55
56 void DrawGhostPreview() override;
57 void DrawSelectionHighlight() override;
58
59 void InitDrag(const ImVec2& start_pos);
60
61 // ========================================================================
62 // Marquee (Rectangle) Selection
63 // ========================================================================
64
65 // Begin a rectangle selection drag on empty space (canvas-local coords).
66 void BeginMarqueeSelection(const ImVec2& start_pos);
67
68 // Update/draw active marquee selection and finalize on mouse release.
69 void HandleMarqueeSelection(const ImVec2& mouse_pos, bool mouse_left_down,
70 bool mouse_left_released, bool shift_down,
71 bool toggle_down, bool alt_down,
72 bool draw_box = true);
73
74 std::optional<size_t> GetEntityAtPosition(int canvas_x,
75 int canvas_y) const override;
76
80 void MoveObjects(int room_id, const std::vector<size_t>& indices, int delta_x,
81 int delta_y, bool notify_mutation = true);
82
87 std::vector<size_t> DuplicateObjects(int room_id,
88 const std::vector<size_t>& indices,
89 int delta_x, int delta_y,
90 bool notify_mutation = true);
91
95 void DeleteObjects(int room_id, std::vector<size_t> indices);
96
100 void DeleteAllObjects(int room_id);
101
105 void SendToFront(int room_id, const std::vector<size_t>& indices);
106 void SendToBack(int room_id, const std::vector<size_t>& indices);
107 void MoveForward(int room_id, const std::vector<size_t>& indices);
108 void MoveBackward(int room_id, const std::vector<size_t>& indices);
109
113 void ResizeObjects(int room_id, const std::vector<size_t>& indices,
114 int delta);
115
119 bool PlaceObjectAt(int room_id, const zelda3::RoomObject& object, int x,
120 int y);
121
133
134 void UpdateObjectsId(int room_id, const std::vector<size_t>& indices,
135 int16_t new_id);
136
137 void UpdateObjectsSize(int room_id, const std::vector<size_t>& indices,
138 uint8_t new_size);
139
140 // Returns false when the request is rejected. Accepted no-op updates return
141 // true so inspector controls can distinguish validation failures from an
142 // already-selected target.
143 bool UpdateObjectsLayer(int room_id, const std::vector<size_t>& indices,
144 int new_layer);
145
149 void SetPreviewObject(const zelda3::RoomObject& object);
150
152 static GhostPreviewGeometry CalculateGhostPreviewGeometry(
153 const zelda3::RoomObject& object);
154
158
159 // ========================================================================
160 // Clipboard Operations
161 // ========================================================================
162
166 void CopyObjectsToClipboard(int room_id, const std::vector<size_t>& indices);
167
172 std::vector<size_t> PasteFromClipboard(int room_id, int offset_x,
173 int offset_y);
174
179 std::vector<size_t> PasteFromClipboardAt(int room_id, int target_x,
180 int target_y);
181
185 bool HasClipboardData() const { return !clipboard_.empty(); }
186
190 void ClearClipboard() { clipboard_.clear(); }
191
192 private:
193 // Placement state
197 std::unique_ptr<gfx::BackgroundBuffer> ghost_preview_buffer_;
200
201 // Clipboard
202 std::vector<zelda3::RoomObject> clipboard_;
203
205
206 // Drag state
207 bool is_dragging_ = false;
208 ImVec2 drag_start_{0, 0};
209 ImVec2 drag_current_{0, 0};
214
215 ImVec2 ApplyDragModifiers(const ImVec2& delta) const;
216 void DrawSmartGuides(const std::vector<zelda3::RoomObject>& objects) const;
217
218 zelda3::Room* GetRoom(int room_id);
219 void NotifyChange(zelda3::Room* room);
220};
221
222} // namespace yaze::editor
223
224#endif // YAZE_APP_EDITOR_DUNGEON_INTERACTION_TILE_OBJECT_HANDLER_H
Abstract base class for entity interaction handlers.
void SetContext(InteractionContext *ctx)
Set the interaction context.
Handles functional mutations and queries for tile objects.
void DrawGhostPreview() override
Draw ghost preview during placement.
void DrawSmartGuides(const std::vector< zelda3::RoomObject > &objects) const
std::vector< zelda3::RoomObject > clipboard_
bool was_placement_blocked() const
True if the most recent PlaceObjectAt was blocked.
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)
void BeginPlacement() override
Begin placement mode.
bool HandleMouseWheel(float delta) override
std::unique_ptr< gfx::BackgroundBuffer > ghost_preview_buffer_
void ClearClipboard()
Clear the clipboard.
bool HasClipboardData() const
Check if clipboard has data.
void UpdateObjectsSize(int room_id, const std::vector< size_t > &indices, uint8_t new_size)
void SendToFront(int room_id, const std::vector< size_t > &indices)
Reorder objects.
const gfx::BackgroundBuffer * ghost_preview_buffer_for_testing() const
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 DeleteAllObjects(int room_id)
Delete all objects in a room.
void MoveBackward(int room_id, const std::vector< size_t > &indices)
ImVec2 ApplyDragModifiers(const ImVec2 &delta) const
void HandleRelease() override
Handle mouse release.
void CopyObjectsToClipboard(int room_id, const std::vector< size_t > &indices)
Copy objects to internal clipboard.
void HandleDrag(ImVec2 current_pos, ImVec2 delta) override
Handle mouse drag.
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.
void DrawSelectionHighlight() override
Draw selection highlight for selected entities.
bool IsPlacementActive() const override
Check if placement mode is active.
bool UpdateObjectsLayer(int room_id, const std::vector< size_t > &indices, int new_layer)
bool PlaceObjectAt(int room_id, const zelda3::RoomObject &object, int x, int y)
Place a new object. Returns false if blocked by ROM limits.
void SendToBack(int room_id, const std::vector< size_t > &indices)
std::vector< size_t > PasteFromClipboard(int room_id, int offset_x, int offset_y)
Paste objects from clipboard with offset.
bool HandleClick(int canvas_x, int canvas_y) override
Handle mouse click at canvas position.
void SetPreviewObject(const zelda3::RoomObject &object)
Set object for placement.
PlacementBlockReason placement_block_reason() const
void BeginMarqueeSelection(const ImVec2 &start_pos)
void MoveForward(int room_id, const std::vector< size_t > &indices)
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.
void CancelPlacement() override
Cancel current placement.
PlacementBlockReason placement_block_reason_
void DeleteObjects(int room_id, std::vector< size_t > indices)
Delete objects by indices.
TileObjectHandler(InteractionContext *ctx)
static GhostPreviewGeometry CalculateGhostPreviewGeometry(const zelda3::RoomObject &object)
Resolve the render anchor and visual extent used by placement previews.
void UpdateObjectsId(int room_id, const std::vector< size_t > &indices, int16_t new_id)
zelda3::Room * GetRoom(int room_id)
PlacementCapacityState GhostCapacityState
void NotifyChange(zelda3::Room *room)
GhostCapacityState GetPlacementGhostCapacityState() const
void ResizeObjects(int room_id, const std::vector< size_t > &indices, int delta)
Resize objects by a delta.
std::optional< size_t > GetEntityAtPosition(int canvas_x, int canvas_y) const override
Get entity at canvas position.
void InitDrag(const ImVec2 &start_pos)
Editors are the view controllers for the application.
Shared context for all interaction handlers.