yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_canvas_viewer.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_DUNGEON_CANVAS_VIEWER_H
2#define YAZE_APP_EDITOR_DUNGEON_DUNGEON_CANVAS_VIEWER_H
3
4#include <map>
5
6#include "app/gui/canvas.h"
7#include "app/rom.h"
11#include "imgui/imgui.h"
12
13namespace yaze {
14namespace editor {
15
25 public:
26 explicit DungeonCanvasViewer(Rom* rom = nullptr)
28
29 // DrawDungeonTabView() removed - using EditorCard system instead
30 void DrawDungeonCanvas(int room_id);
31 void Draw(int room_id);
32
33 void SetRom(Rom* rom) {
34 rom_ = rom;
35 }
36 Rom* rom() const { return rom_; }
37
38 // Room data access
39 void SetRooms(std::array<zelda3::Room, 0x128>* rooms) { rooms_ = rooms; }
40 // Used by overworld editor when double-clicking entrances
41 void set_active_rooms(const ImVector<int>& rooms) { active_rooms_ = rooms; }
43
44 // Palette access
46 void SetCurrentPaletteId(uint64_t id) { current_palette_id_ = id; }
48
49 // Canvas access
50 gui::Canvas& canvas() { return canvas_; }
51 const gui::Canvas& canvas() const { return canvas_; }
52
53 // Object interaction access
55
56 // Enable/disable object interaction mode
59
60 // Layer visibility controls (per-room)
61 void SetBG1Visible(int room_id, bool visible) {
62 GetRoomLayerSettings(room_id).bg1_visible = visible;
63 }
64 void SetBG2Visible(int room_id, bool visible) {
65 GetRoomLayerSettings(room_id).bg2_visible = visible;
66 }
67 bool IsBG1Visible(int room_id) const {
68 auto it = room_layer_settings_.find(room_id);
69 return it != room_layer_settings_.end() ? it->second.bg1_visible : true;
70 }
71 bool IsBG2Visible(int room_id) const {
72 auto it = room_layer_settings_.find(room_id);
73 return it != room_layer_settings_.end() ? it->second.bg2_visible : true;
74 }
75
76 // BG2 layer type controls (per-room)
77 void SetBG2LayerType(int room_id, int type) {
78 GetRoomLayerSettings(room_id).bg2_layer_type = type;
79 }
80 int GetBG2LayerType(int room_id) const {
81 auto it = room_layer_settings_.find(room_id);
82 return it != room_layer_settings_.end() ? it->second.bg2_layer_type : 0;
83 }
84
85 // Set the object to be placed
88 }
92
93 private:
94 void DisplayObjectInfo(const zelda3::RoomObject &object, int canvas_x,
95 int canvas_y);
96 void RenderSprites(const zelda3::Room& room);
97
98 // Coordinate conversion helpers
99 std::pair<int, int> RoomToCanvasCoordinates(int room_x, int room_y) const;
100 std::pair<int, int> CanvasToRoomCoordinates(int canvas_x, int canvas_y) const;
101 bool IsWithinCanvasBounds(int canvas_x, int canvas_y, int margin = 32) const;
102
103 // Object dimension calculation
104 void CalculateWallDimensions(const zelda3::RoomObject& object, int& width, int& height);
105
106 // Visualization
108
109 // Room graphics management
110 // Load: Read from ROM, Render: Process pixels, Draw: Display on canvas
111 absl::Status LoadAndRenderRoomGraphics(int room_id);
112 void DrawRoomBackgroundLayers(int room_id); // Draw room buffers to canvas
113
114 Rom* rom_ = nullptr;
115 gui::Canvas canvas_{"##DungeonCanvas", ImVec2(0x200, 0x200)};
116 // ObjectRenderer removed - use ObjectDrawer for rendering (production system)
118
119 // Room data
120 std::array<zelda3::Room, 0x128>* rooms_ = nullptr;
121 // Used by overworld editor for double-click entrance → open dungeon room
122 ImVector<int> active_rooms_;
124
125 // Object interaction state
127
128 // Per-room layer visibility settings
130 bool bg1_visible = true;
131 bool bg2_visible = true;
132 int bg2_layer_type = 0; // 0=Normal, 1=Translucent, 2=Addition, etc.
133 };
134 std::map<int, RoomLayerSettings> room_layer_settings_;
135
136 // Helper to get settings for a room (creates default if not exists)
138 return room_layer_settings_[room_id];
139 }
140
141 // Palette data
145
146 // Object rendering cache
154 std::vector<ObjectRenderCache> object_render_cache_;
155 uint64_t last_palette_hash_ = 0;
156
157 // Debug state flags
161 bool show_layer_info_ = false;
162 int layout_override_ = -1; // -1 for no override
163
164 // Object outline filtering toggles
166 bool show_type1_objects = true; // Standard objects (0x00-0xFF)
167 bool show_type2_objects = true; // Extended objects (0x100-0x1FF)
168 bool show_type3_objects = true; // Special objects (0xF00-0xFFF)
169 bool show_layer0_objects = true; // Layer 0 (BG1)
170 bool show_layer1_objects = true; // Layer 1 (BG2)
171 bool show_layer2_objects = true; // Layer 2 (BG3)
172 };
174};
175
176} // namespace editor
177} // namespace yaze
178
179#endif
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
Handles the main dungeon canvas rendering and interaction.
std::map< int, RoomLayerSettings > room_layer_settings_
std::pair< int, int > CanvasToRoomCoordinates(int canvas_x, int canvas_y) const
std::pair< int, int > RoomToCanvasCoordinates(int room_x, int room_y) const
RoomLayerSettings & GetRoomLayerSettings(int room_id)
std::array< zelda3::Room, 0x128 > * rooms_
absl::Status LoadAndRenderRoomGraphics(int room_id)
void set_active_rooms(const ImVector< int > &rooms)
void SetBG2LayerType(int room_id, int type)
void SetCurrentPaletteGroup(const gfx::PaletteGroup &group)
void DrawObjectPositionOutlines(const zelda3::Room &room)
DungeonObjectInteraction object_interaction_
DungeonObjectInteraction & object_interaction()
void SetPreviewObject(const zelda3::RoomObject &object)
void SetBG1Visible(int room_id, bool visible)
void SetBG2Visible(int room_id, bool visible)
void RenderSprites(const zelda3::Room &room)
bool IsWithinCanvasBounds(int canvas_x, int canvas_y, int margin=32) const
void CalculateWallDimensions(const zelda3::RoomObject &object, int &width, int &height)
std::vector< ObjectRenderCache > object_render_cache_
void SetRooms(std::array< zelda3::Room, 0x128 > *rooms)
const gui::Canvas & canvas() const
void DisplayObjectInfo(const zelda3::RoomObject &object, int canvas_x, int canvas_y)
Handles object selection, placement, and interaction within the dungeon canvas.
void SetPreviewObject(const zelda3::RoomObject &object, bool loaded)
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:66
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:54
Main namespace for the application.
Represents a group of palettes.