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
114 bool ResizeObjects(int room_id, const std::vector<size_t>& indices, int delta,
115 bool horizontal = false);
116
120 bool PlaceObjectAt(int room_id, const zelda3::RoomObject& object, int x,
121 int y);
122
134
135 void UpdateObjectsId(int room_id, const std::vector<size_t>& indices,
136 int16_t new_id);
137
138 void UpdateObjectsSize(int room_id, const std::vector<size_t>& indices,
139 uint8_t new_size);
140
141 // Returns false when the request is rejected. Accepted no-op updates return
142 // true so inspector controls can distinguish validation failures from an
143 // already-selected target.
144 bool UpdateObjectsLayer(int room_id, const std::vector<size_t>& indices,
145 int new_layer);
146
150 void SetPreviewObject(const zelda3::RoomObject& object);
152
155
157 static GhostPreviewGeometry CalculateGhostPreviewGeometry(
158 const zelda3::RoomObject& object);
159
163
164 // ========================================================================
165 // Clipboard Operations
166 // ========================================================================
167
171 void CopyObjectsToClipboard(int room_id, const std::vector<size_t>& indices);
172
177 std::vector<size_t> PasteFromClipboard(int room_id, int offset_x,
178 int offset_y);
179
184 std::vector<size_t> PasteFromClipboardAt(int room_id, int target_x,
185 int target_y);
186
190 bool HasClipboardData() const { return !clipboard_.empty(); }
191
195 void ClearClipboard() { clipboard_.clear(); }
196
197 private:
198 // Placement state
202 std::unique_ptr<gfx::BackgroundBuffer> ghost_preview_buffer_;
207
208 // Clipboard
209 std::vector<zelda3::RoomObject> clipboard_;
210
212
213 // Drag state
214 bool is_dragging_ = false;
215 ImVec2 drag_start_{0, 0};
216 ImVec2 drag_current_{0, 0};
221
222 ImVec2 ApplyDragModifiers(const ImVec2& delta) const;
223 void DrawSmartGuides(const std::vector<zelda3::RoomObject>& objects) const;
224
225 zelda3::Room* GetRoom(int room_id);
226 void NotifyChange(zelda3::Room* room);
227};
228
229} // namespace yaze::editor
230
231#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
void RefreshPreviewGraphics()
Refresh graphics without replacing the current placement geometry.
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.
const zelda3::RoomObject & GetPreviewObject() const
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
std::optional< size_t > GetEntityAtPosition(int canvas_x, int canvas_y) const override
Get entity at canvas position.
bool ResizeObjects(int room_id, const std::vector< size_t > &indices, int delta, bool horizontal=false)
Resize objects by a delta; horizontal selects packed-floor width.
void InitDrag(const ImVec2 &start_pos)
Editors are the view controllers for the application.
Shared context for all interaction handlers.