1#ifndef YAZE_APP_EDITOR_DUNGEON_PANELS_ITEM_EDITOR_PANEL_H_
2#define YAZE_APP_EDITOR_DUNGEON_PANELS_ITEM_EDITOR_PANEL_H_
10#include "absl/strings/str_format.h"
19#include "imgui/imgui.h"
48 std::string
GetId()
const override {
return "dungeon.item_editor"; }
58 void Draw(
bool* p_open)
override {
61 ImGui::TextDisabled(tr(
"No room data available"));
67 ImGui::TextDisabled(tr(
"No room selected"));
134 ImGui::TextColored(theme.status_warning,
144 ImGui::TextColored(theme.text_secondary_gray,
154 float available_height = ImGui::GetContentRegionAvail().y;
156 float reserved_height = 120.0f;
159 std::max(150.0f, std::min(400.0f, available_height - reserved_height));
162 float panel_width = ImGui::GetContentRegionAvail().x;
164 std::max(36.0f, std::min(48.0f, (panel_width - 40.0f) / 6.0f));
166 std::max(1,
static_cast<int>(panel_width / (item_size + 8)));
168 ImGui::BeginChild(
"##ItemGrid", ImVec2(0, grid_height),
true,
169 ImGuiWindowFlags_HorizontalScrollbar);
175 ImGui::PushID(
static_cast<int>(i));
180 button_color.x = std::min(1.0f, button_color.x + 0.2f);
181 button_color.y = std::min(1.0f, button_color.y + 0.2f);
182 button_color.z = std::min(1.0f, button_color.z + 0.2f);
187 {ImGuiCol_Button, button_color},
188 {ImGuiCol_ButtonHovered,
189 ImVec4(std::min(1.0f, button_color.x + 0.1f),
190 std::min(1.0f, button_color.y + 0.1f),
191 std::min(1.0f, button_color.z + 0.1f), 1.0f)},
192 {ImGuiCol_ButtonActive,
193 ImVec4(std::min(1.0f, button_color.x + 0.2f),
194 std::min(1.0f, button_color.y + 0.2f),
195 std::min(1.0f, button_color.z + 0.2f), 1.0f)},
201 absl::StrFormat(
"%s\n%02X", icon,
static_cast<int>(i));
202 if (ImGui::Button(label.c_str(), ImVec2(item_size, item_size))) {
207 true,
static_cast<uint8_t
>(i));
212 if (ImGui::IsItemHovered()) {
213 ImGui::SetTooltip(tr(
"%s (0x%02X)\nClick to select for placement"),
219 ImVec2 min = ImGui::GetItemRectMin();
220 ImVec2 max = ImGui::GetItemRectMax();
222 ImGui::ColorConvertFloat4ToU32(theme.dungeon_selection_primary);
223 ImGui::GetWindowDrawList()->AddRect(min, max, sel_color, 0.0f, 0, 2.0f);
229 if (col < items_per_row) {
242 const auto& items = room.GetPotItems();
243 int selected_item_index = -1;
246 const auto selected_entity =
249 selected_item_index =
static_cast<int>(selected_entity.index);
253 ImGui::Text(
ICON_MD_LIST " Room Items (%zu):", items.size());
262 ImGui::TextColored(theme.text_secondary_gray,
267 if (selected_item_index >= 0 &&
268 selected_item_index <
static_cast<int>(items.size()) &&
270 uint8_t raw_item_type = items[selected_item_index].item;
271 ImGui::AlignTextToFramePadding();
272 ImGui::TextUnformatted(tr(
"Selected raw type"));
274 ImGui::SetNextItemWidth(72.0f);
276 "##SelectedItemRawType", ImGuiDataType_U8, &raw_item_type,
"%02X",
277 ImGuiInputTextFlags_CharsHexadecimal,
278 {
reinterpret_cast<uintptr_t
>(
rooms_),
280 static_cast<uint64_t
>(selected_item_index)});
282 "Selected pot item raw type byte");
291 float list_height = std::max(100.0f, ImGui::GetContentRegionAvail().y);
292 ImGui::BeginChild(
"##ItemList", ImVec2(0, list_height),
true);
293 for (
size_t i = 0; i < items.size(); ++i) {
294 const auto& item = items[i];
296 ImGui::PushID(
static_cast<int>(i));
298 const char* item_name =
301 const std::string row_label =
302 absl::StrFormat(
"[%zu] %s (0x%02X)", i, item_name, item.item);
303 const bool row_selected = ImGui::Selectable(
304 row_label.c_str(), selected_item_index ==
static_cast<int>(i));
306 "selectable", absl::StrFormat(
"item_row_%zu", i),
307 "Select a pot item in the current dungeon room");
309 ImGui::TextColored(theme.text_secondary_gray,
"@ (%d,%d)",
310 item.GetTileX(), item.GetTileY());
323 if (item_id == 0 || item_id == 22) {
325 }
else if (item_id >= 1 && item_id <= 7) {
327 }
else if (item_id == 8) {
329 }
else if (item_id >= 15 && item_id <= 17) {
331 }
else if (item_id >= 23 && item_id <= 27) {
339 if (item_id == 0 || item_id == 22) {
341 }
else if (item_id == 1 || item_id == 7) {
343 }
else if (item_id == 4 || item_id == 6 || item_id == 11 || item_id == 19 ||
346 }
else if (item_id == 8) {
348 }
else if (item_id == 5 || item_id == 10) {
350 }
else if (item_id == 9) {
352 }
else if (item_id == 12 || item_id == 13) {
354 }
else if (item_id == 14) {
356 }
else if (item_id >= 15 && item_id <= 17) {
358 }
else if (item_id == 18) {
360 }
else if (item_id == 20) {
362 }
else if (item_id == 23) {
364 }
else if (item_id == 24) {
366 }
else if (item_id == 25) {
368 }
else if (item_id == 26) {
370 }
else if (item_id == 27) {
372 }
else if (item_id == 2) {
374 }
else if (item_id == 3) {
DungeonObjectInteraction & object_interaction()
void SetItemPlacementMode(bool enabled, uint8_t item_id=0)
SelectedEntity GetSelectedEntity() const
InteractionCoordinator & entity_coordinator()
Get the interaction coordinator for entity handling.
bool HasEntitySelection() const
void SelectEntity(EntityType type, size_t index)
ItemInteractionHandler & item_handler()
WindowContent for placing and managing dungeon pot items.
std::string GetIcon() const override
Material Design icon for this panel.
static constexpr size_t kPotItemCount
static constexpr const char * kPotItemNames[]
int GetPriority() const override
Get display priority for menu ordering.
ImVec4 GetItemTypeColor(int item_id, const AgentUITheme &theme)
void SetCanvasViewer(DungeonCanvasViewer *viewer)
void SetOpenSelectionInspectorCallback(std::function< void()> callback)
std::function< void(const zelda3::PotItem &) item_placed_callback_)
std::string GetEditorCategory() const override
Editor category this panel belongs to.
void DrawPlacementControls()
std::string GetId() const override
Unique identifier for this panel.
DungeonCanvasViewer * canvas_viewer_
void SetItemPlacedCallback(std::function< void(const zelda3::PotItem &)> callback)
std::string GetDisplayName() const override
Human-readable name shown in menus and title bars.
const char * GetItemTypeIcon(int item_id)
std::function< void()> open_selection_inspector_callback_
ItemEditorPanel(int *current_room_id, DungeonRoomStore *rooms, DungeonCanvasViewer *canvas_viewer=nullptr)
void Draw(bool *p_open) override
Draw the panel content.
DungeonRoomStore * rooms_
bool MutateItemType(size_t index, uint8_t new_type)
Change one pot item's raw type byte in place.
Base interface for all logical window content components.
RAII guard for ImGui style colors.
#define ICON_MD_FLUTTER_DASH
#define ICON_MD_LANDSCAPE
#define ICON_MD_SWAP_HORIZ
#define ICON_MD_AUTO_AWESOME
#define ICON_MD_BUG_REPORT
#define ICON_MD_TOGGLE_ON
#define ICON_MD_BROKEN_IMAGE
#define ICON_MD_INVENTORY
#define ICON_MD_ARROW_UPWARD
#define ICON_MD_OPEN_IN_NEW
#define ICON_MD_MONETIZATION_ON
const AgentUITheme & GetTheme()
void AutoRegisterLastItem(const std::string &widget_type, const std::string &explicit_label, const std::string &description)
Automatically register the last ImGui item.
bool InputScalarDeferred(const char *label, ImGuiDataType data_type, void *data, const char *format, ImGuiInputTextFlags flags, InputScalarTargetIdentity target_identity)
Centralized theme colors for Agent UI components.
ImVec4 dungeon_sprite_layer0
ImVec4 dungeon_object_chest
ImVec4 dungeon_object_pot
ImVec4 dungeon_object_stairs
ImVec4 dungeon_object_default