yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_room_graphics_panel.cc
Go to the documentation of this file.
2
3#include <algorithm>
4
10#include "imgui/imgui.h"
11
12namespace yaze {
13namespace editor {
14
16 if (!ImGui::Begin(GetDisplayName().c_str(), p_open)) {
17 ImGui::End();
18 return;
19 }
20
21 // Get context from ContentRegistry if not set via legacy constructor.
22 if (current_room_id_ == nullptr || rooms_ == nullptr) {
24 if (editor != nullptr) {
25 if (auto* dungeon_editor = dynamic_cast<DungeonEditorV2*>(editor)) {
26 current_room_id_ = dungeon_editor->mutable_current_room_id();
27 rooms_ = &dungeon_editor->rooms();
28 renderer_ = dungeon_editor->renderer();
29 }
30 }
31 }
32
33 if (current_room_id_ == nullptr || rooms_ == nullptr) {
34 ImGui::TextDisabled("No room data available");
35 ImGui::End();
36 return;
37 }
38
39 const int active_room_id = *current_room_id_;
40 if (active_room_id < 0 ||
41 active_room_id >= static_cast<int>(rooms_->size())) {
42 ImGui::TextDisabled("Invalid room ID: %d", active_room_id);
43 ImGui::End();
44 return;
45 }
46
47 auto& room = (*rooms_)[active_room_id];
48 // Refresh room sheet assignments from current room header values.
49 room.LoadRoomGraphics(room.blockset());
50 auto blocks = room.blocks();
51
52 if (renderer_ != nullptr) {
54 }
55
56 constexpr float kBlockWidth = 128.0f;
57 constexpr float kBlockHeight = 32.0f;
58 constexpr int kBlocksPerRow = 2;
59 constexpr float kPadding = 4.0f;
60
61 const int block_count = static_cast<int>(blocks.size());
62 const int row_count =
63 std::max(1, (block_count + kBlocksPerRow - 1) / kBlocksPerRow);
64 const ImVec2 canvas_size(
65 kPadding + (kBlockWidth + kPadding) * static_cast<float>(kBlocksPerRow),
66 kPadding + (kBlockHeight + kPadding) * static_cast<float>(row_count));
67
68 ImGui::Text("Room %03X Graphics Blocks", active_room_id);
69 ImGui::TextDisabled("Blockset %02X | Spriteset %02X", room.blockset(),
70 room.spriteset());
71 ImGui::Separator();
72
73 gui::CanvasFrameOptions frame_opts;
74 frame_opts.canvas_size = canvas_size;
75 frame_opts.draw_grid = false;
76 frame_opts.draw_overlay = false;
77 frame_opts.draw_context_menu = false;
78 frame_opts.render_popups = false;
79
80 auto runtime = gui::BeginCanvas(room_gfx_canvas_, frame_opts);
81 (void)runtime;
82
83 ImDrawList* draw_list = ImGui::GetWindowDrawList();
84 for (int i = 0; i < block_count; ++i) {
85 const uint8_t block_id = blocks[static_cast<size_t>(i)];
86 const int row = i / kBlocksPerRow;
87 const int col = i % kBlocksPerRow;
88 const ImVec2 local_pos(kPadding + col * (kBlockWidth + kPadding),
89 kPadding + row * (kBlockHeight + kPadding));
90
91 const auto& sheets = gfx::Arena::Get().gfx_sheets();
92 if (block_id < sheets.size() && sheets[block_id].texture() != 0) {
94 (ImTextureID)(intptr_t)sheets[block_id].texture(), local_pos,
95 ImVec2(kBlockWidth, kBlockHeight));
96 } else {
97 const ImVec2 zero = room_gfx_canvas_.zero_point();
98 const float scale = room_gfx_canvas_.global_scale();
99 const ImVec2 screen_pos(zero.x + local_pos.x, zero.y + local_pos.y);
100 const ImVec2 screen_end(screen_pos.x + kBlockWidth * scale,
101 screen_pos.y + kBlockHeight * scale);
102 draw_list->AddRect(screen_pos, screen_end,
103 ImGui::GetColorU32(gui::GetOutlineVec4()));
104 draw_list->AddText(ImVec2(screen_pos.x + 6.0f, screen_pos.y + 6.0f),
105 ImGui::GetColorU32(gui::GetTextSecondaryVec4()),
106 "Missing");
107 }
108 }
109
110 gui::EndCanvas(room_gfx_canvas_, runtime, frame_opts);
111
112 ImGui::End();
113}
114
115} // namespace editor
116} // namespace yaze
DungeonEditorV2 - Simplified dungeon editor using component delegation.
std::string GetDisplayName() const override
Human-readable name shown in menus and title bars.
std::array< zelda3::Room, 0x128 > * rooms_
void Draw(bool *p_open) override
Draw the panel content.
void ProcessTextureQueue(IRenderer *renderer)
Definition arena.cc:116
std::array< gfx::Bitmap, 223 > & gfx_sheets()
Get reference to all graphics sheets.
Definition arena.h:152
static Arena & Get()
Definition arena.cc:21
auto global_scale() const
Definition canvas.h:491
void AddImageAt(ImTextureID texture, ImVec2 local_top_left, ImVec2 size)
Definition canvas.cc:2489
auto zero_point() const
Definition canvas.h:443
Editor * current_editor()
Get the currently active editor.
void EndCanvas(Canvas &canvas)
Definition canvas.cc:1591
void BeginCanvas(Canvas &canvas, ImVec2 child_size)
Definition canvas.cc:1568
ImVec4 GetTextSecondaryVec4()
ImVec4 GetOutlineVec4()