8#include "absl/strings/str_format.h"
9#include "imgui/imgui.h"
32 if (item_index.has_value()) {
36 ImVec2(
static_cast<float>(canvas_x),
static_cast<float>(canvas_y));
71 int encoded_x = pixel_x / 4;
72 int encoded_y = pixel_y / 16;
75 encoded_x = std::clamp(encoded_x, 0, 255);
76 encoded_y = std::clamp(encoded_y, 0, 255);
78 auto& pot_items = room->GetPotItems();
83 static_cast<uint16_t
>((encoded_y << 8) | encoded_x);
96 if (!canvas->IsMouseHovering())
99 const ImGuiIO& io = ImGui::GetIO();
100 ImVec2 canvas_pos = canvas->zero_point();
104 int canvas_x =
static_cast<int>((io.MousePos.x - canvas_pos.x) / scale);
105 int canvas_y =
static_cast<int>((io.MousePos.y - canvas_pos.y) / scale);
114 ImVec2 rect_min(canvas_pos.x + snapped_x * scale,
115 canvas_pos.y + snapped_y * scale);
116 ImVec2 rect_max(rect_min.x + 16 * scale, rect_min.y + 16 * scale);
119 ImU32 fill_color = IM_COL32(200, 200, 50, 100);
120 ImU32 outline_color = IM_COL32(255, 255, 50, 200);
122 canvas->draw_list()->AddRectFilled(rect_min, rect_max, fill_color);
123 canvas->draw_list()->AddRect(rect_min, rect_max, outline_color, 0.0f, 0,
128 canvas->draw_list()->AddText(rect_min, IM_COL32(255, 255, 255, 255),
140 const auto& pot_items = room->GetPotItems();
145 int pixel_x = pot_item.GetPixelX();
146 int pixel_y = pot_item.GetPixelY();
158 ImDrawList* draw_list = ImGui::GetWindowDrawList();
162 ImVec2 pos(canvas_pos.x + pixel_x * scale, canvas_pos.y + pixel_y * scale);
163 ImVec2 size(16 * scale, 16 * scale);
166 static float pulse = 0.0f;
167 pulse += ImGui::GetIO().DeltaTime * 3.0f;
168 float alpha = 0.5f + 0.3f * sinf(pulse);
170 ImU32 color = IM_COL32(255, 255, 0, 180);
172 (color & 0x00FFFFFF) | (
static_cast<ImU32
>(alpha * 100) << 24);
174 draw_list->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y),
176 draw_list->AddRect(pos, ImVec2(pos.x + size.x, pos.y + size.y), color, 0.0f,
180 ImVec2 text_pos(pos.x, pos.y - 14 * scale);
181 draw_list->AddText(text_pos, IM_COL32(255, 255, 255, 220),
"Item");
185 int canvas_x,
int canvas_y)
const {
195 int room_x =
static_cast<int>(canvas_x / scale);
196 int room_y =
static_cast<int>(canvas_y / scale);
199 const auto& pot_items = room->GetPotItems();
200 for (
size_t i = 0; i < pot_items.size(); ++i) {
201 const auto& pot_item = pot_items[i];
203 int item_x = pot_item.GetPixelX();
204 int item_y = pot_item.GetPixelY();
207 if (room_x >= item_x && room_x < item_x + 16 && room_y >= item_y &&
208 room_y < item_y + 16) {
234 auto& pot_items = room->GetPotItems();
239 pot_items.erase(pot_items.begin() +
256 int pixel_x =
static_cast<int>(canvas_x / scale);
257 int pixel_y =
static_cast<int>(canvas_y / scale);
261 int encoded_x = pixel_x / 4;
262 int encoded_y = pixel_y / 16;
265 encoded_x = std::clamp(encoded_x, 0, 255);
266 encoded_y = std::clamp(encoded_y, 0, 255);
272 new_item.
position =
static_cast<uint16_t
>((encoded_y << 8) | encoded_x);
276 room->GetPotItems().push_back(new_item);
InteractionContext * ctx_
float GetCanvasScale() const
Get canvas global scale.
zelda3::Room * GetCurrentRoom() const
Get current room (convenience method)
bool HasValidContext() const
Check if context is valid.
ImVec2 GetCanvasZeroPoint() const
Get canvas zero point (for screen coordinate conversion)
void DrawSelectionHighlight() override
Draw selection highlight for selected entities.
std::optional< size_t > selected_item_index_
bool HandleClick(int canvas_x, int canvas_y) override
Handle mouse click at canvas position.
void DrawGhostPreview() override
Draw ghost preview during placement.
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.
void ClearSelection()
Clear item selection.
std::optional< size_t > GetEntityAtPosition(int canvas_x, int canvas_y) const override
Get entity at canvas position.
bool item_placement_mode_
void DeleteSelected()
Delete selected item.
void HandleRelease() override
Handle mouse release.
void SelectItem(size_t index)
Select item at index.
Editors are the view controllers for the application.
const zelda3::Room * GetCurrentRoomConst() const
Get const pointer to current room.
void NotifyEntityChanged() const
Notify that entity has changed.
void NotifyInvalidateCache() const
Notify that cache invalidation is needed.
void NotifyMutation() const
Notify that a mutation is about to happen.