yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
item_interaction_handler.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_INTERACTION_ITEM_INTERACTION_HANDLER_H_
2#define YAZE_APP_EDITOR_DUNGEON_INTERACTION_ITEM_INTERACTION_HANDLER_H_
3
4#include <functional>
5#include <utility>
6
7#include "absl/status/status.h"
10
11namespace yaze {
12namespace editor {
13
20 public:
21 // ========================================================================
22 // BaseEntityHandler interface
23 // ========================================================================
24
25 void BeginPlacement() override;
26 void CancelPlacement() override { item_placement_mode_ = false; }
27 bool IsPlacementActive() const override { return item_placement_mode_; }
28
29 bool HandleClick(int canvas_x, int canvas_y) override;
30 void HandleDrag(ImVec2 current_pos, ImVec2 delta) override;
31 void HandleRelease() override;
32
33 void DrawGhostPreview() override;
34 void DrawSelectionHighlight() override;
35
36 std::optional<size_t> GetEntityAtPosition(int canvas_x,
37 int canvas_y) const override;
38
39 // ========================================================================
40 // Item-specific methods
41 // ========================================================================
42
46 void SetItemId(uint8_t id) { preview_item_id_ = id; }
47
51 uint8_t GetItemId() const { return preview_item_id_; }
52
56 void SelectItem(size_t index);
57
61 void ClearSelection();
62
66 bool HasSelection() const { return selected_item_index_.has_value(); }
67
71 std::optional<size_t> GetSelectedIndex() const {
73 }
74
78 void DeleteSelected();
79 void DeleteAll();
80 bool NudgeSelected(int delta_pixel_x, int delta_pixel_y);
81
89 bool MutateItemType(size_t index, uint8_t new_type);
90 // Pot-item positions use 8-pixel steps; edits preserve layer/control flags.
91 bool UpdateItem(size_t index, uint8_t type, int pixel_x, int pixel_y);
92
93 using ItemPlacementPreflight = std::function<absl::Status(
94 int room_id, const std::vector<zelda3::PotItem>& candidate)>;
96 item_placement_preflight_ = std::move(preflight);
97 }
99 std::function<void(const absl::Status&)> callback) {
100 mutation_error_callback_ = std::move(callback);
101 }
102 const absl::Status& mutation_status() const { return mutation_status_; }
103
104 private:
106 std::function<void(const absl::Status&)> mutation_error_callback_;
107 absl::Status mutation_status_ = absl::OkStatus();
108 bool PreflightPlacement(const std::vector<zelda3::PotItem>& candidate);
109
110 // Placement state
112 uint8_t preview_item_id_ = 0;
113
114 // Selection state
115 std::optional<size_t> selected_item_index_;
116 bool is_dragging_ = false;
119
123 void PlaceItemAtPosition(int canvas_x, int canvas_y);
124};
125
126} // namespace editor
127} // namespace yaze
128
129#endif // YAZE_APP_EDITOR_DUNGEON_INTERACTION_ITEM_INTERACTION_HANDLER_H_
Abstract base class for entity interaction handlers.
Handles pot item placement and interaction in the dungeon editor.
void DrawSelectionHighlight() override
Draw selection highlight for selected entities.
void SetItemPlacementPreflight(ItemPlacementPreflight preflight)
std::function< absl::Status( int room_id, const std::vector< zelda3::PotItem > &candidate)> ItemPlacementPreflight
std::function< void(const absl::Status &) mutation_error_callback_)
void SetMutationErrorCallback(std::function< void(const absl::Status &)> callback)
uint8_t GetItemId() const
Get current item ID for placement.
bool HandleClick(int canvas_x, int canvas_y) override
Handle mouse click at canvas position.
bool IsPlacementActive() const override
Check if placement mode is active.
void DrawGhostPreview() override
Draw ghost preview during placement.
bool PreflightPlacement(const std::vector< zelda3::PotItem > &candidate)
void BeginPlacement() override
Begin placement mode.
void PlaceItemAtPosition(int canvas_x, int canvas_y)
Place item at position.
void HandleDrag(ImVec2 current_pos, ImVec2 delta) override
Handle mouse drag.
std::optional< size_t > GetEntityAtPosition(int canvas_x, int canvas_y) const override
Get entity at canvas position.
bool HasSelection() const
Check if an item is selected.
bool NudgeSelected(int delta_pixel_x, int delta_pixel_y)
bool MutateItemType(size_t index, uint8_t new_type)
Change one pot item's raw type byte in place.
void SetItemId(uint8_t id)
Set item ID for placement.
void HandleRelease() override
Handle mouse release.
std::optional< size_t > GetSelectedIndex() const
Get selected item index.
void SelectItem(size_t index)
Select item at index.
void CancelPlacement() override
Cancel current placement.
bool UpdateItem(size_t index, uint8_t type, int pixel_x, int pixel_y)