yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_room_graphics_panel.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_PANELS_DUNGEON_ROOM_GRAPHICS_PANEL_H_
2#define YAZE_APP_EDITOR_DUNGEON_PANELS_DUNGEON_ROOM_GRAPHICS_PANEL_H_
3
4#include <string>
5
11#include "app/gui/core/icons.h"
12#include "imgui/imgui.h"
13#include "zelda3/dungeon/room.h"
14
15namespace yaze {
16namespace editor {
17
28 public:
29 DungeonRoomGraphicsPanel(int* current_room_id,
30 std::array<zelda3::Room, 0x128>* rooms,
31 gfx::IRenderer* renderer = nullptr)
32 : current_room_id_(current_room_id),
33 rooms_(rooms),
34 renderer_(renderer),
35 room_gfx_canvas_("##RoomGfxCanvasPanel", ImVec2(256 + 1, 256 + 1)) {}
36
43 palette_dirty_ = true;
44 }
45
46 // ==========================================================================
47 // EditorPanel Identity
48 // ==========================================================================
49
50 std::string GetId() const override { return "dungeon.room_graphics"; }
51 std::string GetDisplayName() const override { return "Room Graphics"; }
52 std::string GetIcon() const override { return ICON_MD_IMAGE; }
53 std::string GetEditorCategory() const override { return "Dungeon"; }
54 int GetPriority() const override { return 50; }
55
56 // ==========================================================================
57 // EditorPanel Drawing
58 // ==========================================================================
59
60 void Draw(bool* p_open) override {
61 if (!current_room_id_ || !rooms_) {
62 ImGui::TextDisabled("No room data available");
63 return;
64 }
65
66 if (*current_room_id_ < 0 ||
67 *current_room_id_ >= static_cast<int>(rooms_->size())) {
68 ImGui::TextDisabled("No room selected");
69 return;
70 }
71
72 auto& room = (*rooms_)[*current_room_id_];
73
74 ImGui::Text("Room %03X Graphics", *current_room_id_);
75 ImGui::Text("Blockset: %02X", room.blockset);
76 ImGui::Separator();
77
78 gui::CanvasFrameOptions frame_opts;
79 frame_opts.draw_grid = true;
80 frame_opts.grid_step = 32.0f;
81 frame_opts.render_popups = true;
82 gui::CanvasFrame frame(room_gfx_canvas_, frame_opts);
84
85 auto blocks = room.blocks();
86
87 // Load graphics if not already loaded
88 if (blocks.empty()) {
89 room.LoadRoomGraphics(room.blockset);
90 blocks = room.blocks();
91 }
92
93 int current_block = 0;
94 constexpr int max_blocks_per_row = 2;
95 constexpr int block_width = 128;
96 constexpr int block_height = 32;
97
98 for (int block : blocks) {
99 if (current_block >= 16) break;
100
101 if (block < static_cast<int>(gfx::Arena::Get().gfx_sheets().size())) {
102 auto& gfx_sheet = gfx::Arena::Get().gfx_sheets()[block];
103
104 // Apply current room's palette to the sheet if dirty
105 if (palette_dirty_ && gfx_sheet.is_active() &&
107 // Use palette index based on block type (simplified: use palette 0)
108 int palette_index = 0;
109 if (current_palette_group_.size() > 0) {
110 gfx_sheet.SetPaletteWithTransparent(
111 current_palette_group_[palette_index], palette_index);
112 gfx_sheet.set_modified(true);
113 }
114 }
115
116 // Create or update texture
117 if (!gfx_sheet.texture() && gfx_sheet.is_active() &&
118 gfx_sheet.width() > 0) {
122 } else if (gfx_sheet.modified() && gfx_sheet.texture()) {
126 gfx_sheet.set_modified(false);
127 }
128
129 int row = current_block / max_blocks_per_row;
130 int col = current_block % max_blocks_per_row;
131
132 ImVec2 local_pos(2 + (col * block_width), 2 + (row * block_height));
133
134 if (gfx_sheet.texture() != 0) {
136 (ImTextureID)(intptr_t)gfx_sheet.texture(), local_pos,
137 ImVec2(block_width, block_height));
138 } else {
140 local_pos, ImVec2(block_width, block_height),
141 IM_COL32(40, 40, 40, 255));
142 room_gfx_canvas_.AddTextAt(ImVec2(local_pos.x + 10, local_pos.y + 10),
143 "No Graphics",
144 IM_COL32(255, 255, 255, 255));
145 }
146 }
147 current_block++;
148 }
149
150 // Clear dirty flag after processing all blocks
151 palette_dirty_ = false;
152 }
153
154 private:
155 int* current_room_id_ = nullptr;
156 std::array<zelda3::Room, 0x128>* rooms_ = nullptr;
159
160 // Palette tracking for proper sheet coloring
162 bool palette_dirty_ = true;
163};
164
165} // namespace editor
166} // namespace yaze
167
168#endif // YAZE_APP_EDITOR_DUNGEON_PANELS_DUNGEON_ROOM_GRAPHICS_PANEL_H_
EditorPanel for displaying room graphics blocks.
int GetPriority() const override
Get display priority for menu ordering.
std::string GetDisplayName() const override
Human-readable name shown in menus and title bars.
std::string GetId() const override
Unique identifier for this panel.
std::string GetEditorCategory() const override
Editor category this panel belongs to.
DungeonRoomGraphicsPanel(int *current_room_id, std::array< zelda3::Room, 0x128 > *rooms, gfx::IRenderer *renderer=nullptr)
void SetCurrentPaletteGroup(const gfx::PaletteGroup &group)
Set the current palette group for graphics rendering.
std::array< zelda3::Room, 0x128 > * rooms_
std::string GetIcon() const override
Material Design icon for this panel.
void Draw(bool *p_open) override
Draw the panel content.
Base interface for all logical panel components.
void QueueTextureCommand(TextureCommandType type, Bitmap *bitmap)
Definition arena.cc:34
void ProcessTextureQueue(IRenderer *renderer)
Definition arena.cc:110
std::array< gfx::Bitmap, 223 > & gfx_sheets()
Get reference to all graphics sheets.
Definition arena.h:101
static Arena & Get()
Definition arena.cc:19
Defines an abstract interface for all rendering operations.
Definition irenderer.h:40
Lightweight RAII guard for existing Canvas instances.
Definition canvas.h:872
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:150
void AddTextAt(ImVec2 local_pos, const std::string &text, uint32_t color)
Definition canvas.cc:2425
void AddRectFilledAt(ImVec2 local_top_left, ImVec2 size, uint32_t color)
Definition canvas.cc:2416
bool DrawTileSelector(int size, int size_y=0)
Definition canvas.cc:1011
void AddImageAt(ImTextureID texture, ImVec2 local_top_left, ImVec2 size)
Definition canvas.cc:2407
#define ICON_MD_IMAGE
Definition icons.h:982
Represents a group of palettes.
std::optional< float > grid_step
Definition canvas.h:70