8#include "absl/strings/str_format.h"
9#include "imgui/imgui.h"
31 if (item_index.has_value()) {
35 static_cast<float>(canvas_y));
69 int encoded_x = pixel_x / 4;
70 int encoded_y = pixel_y / 16;
73 encoded_x = std::clamp(encoded_x, 0, 255);
74 encoded_y = std::clamp(encoded_y, 0, 255);
76 auto& pot_items = room->GetPotItems();
81 static_cast<uint16_t
>((encoded_y << 8) | encoded_x);
93 if (!canvas->IsMouseHovering())
return;
95 const ImGuiIO& io = ImGui::GetIO();
96 ImVec2 canvas_pos = canvas->zero_point();
100 int canvas_x =
static_cast<int>((io.MousePos.x - canvas_pos.x) / scale);
101 int canvas_y =
static_cast<int>((io.MousePos.y - canvas_pos.y) / scale);
110 ImVec2 rect_min(canvas_pos.x + snapped_x * scale,
111 canvas_pos.y + snapped_y * scale);
112 ImVec2 rect_max(rect_min.x + 16 * scale, rect_min.y + 16 * scale);
115 ImU32 fill_color = IM_COL32(200, 200, 50, 100);
116 ImU32 outline_color = IM_COL32(255, 255, 50, 200);
118 canvas->draw_list()->AddRectFilled(rect_min, rect_max, fill_color);
119 canvas->draw_list()->AddRect(rect_min, rect_max, outline_color, 0.0f, 0,
124 canvas->draw_list()->AddText(rect_min, IM_COL32(255, 255, 255, 255),
134 const auto& pot_items = room->GetPotItems();
138 int pixel_x = pot_item.GetPixelX();
139 int pixel_y = pot_item.GetPixelY();
151 ImDrawList* draw_list = ImGui::GetWindowDrawList();
155 ImVec2 pos(canvas_pos.x + pixel_x * scale, canvas_pos.y + pixel_y * scale);
156 ImVec2 size(16 * scale, 16 * scale);
159 static float pulse = 0.0f;
160 pulse += ImGui::GetIO().DeltaTime * 3.0f;
161 float alpha = 0.5f + 0.3f * sinf(pulse);
163 ImU32 color = IM_COL32(255, 255, 0, 180);
165 (color & 0x00FFFFFF) | (
static_cast<ImU32
>(alpha * 100) << 24);
167 draw_list->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y),
169 draw_list->AddRect(pos, ImVec2(pos.x + size.x, pos.y + size.y), color, 0.0f,
173 ImVec2 text_pos(pos.x, pos.y - 14 * scale);
174 draw_list->AddText(text_pos, IM_COL32(255, 255, 255, 220),
"Item");
178 int canvas_x,
int canvas_y)
const {
182 if (!room)
return std::nullopt;
186 int room_x =
static_cast<int>(canvas_x / scale);
187 int room_y =
static_cast<int>(canvas_y / scale);
190 const auto& pot_items = room->GetPotItems();
191 for (
size_t i = 0; i < pot_items.size(); ++i) {
192 const auto& pot_item = pot_items[i];
194 int item_x = pot_item.GetPixelX();
195 int item_y = pot_item.GetPixelY();
198 if (room_x >= item_x && room_x < item_x + 16 && room_y >= item_y &&
199 room_y < item_y + 16) {
223 auto& pot_items = room->GetPotItems();
227 pot_items.erase(pot_items.begin() +
242 int pixel_x =
static_cast<int>(canvas_x / scale);
243 int pixel_y =
static_cast<int>(canvas_y / scale);
247 int encoded_x = pixel_x / 4;
248 int encoded_y = pixel_y / 16;
251 encoded_x = std::clamp(encoded_x, 0, 255);
252 encoded_y = std::clamp(encoded_y, 0, 255);
258 new_item.
position =
static_cast<uint16_t
>((encoded_y << 8) | encoded_x);
262 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.