yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_object_selector.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_DUNGEON_OBJECT_SELECTOR_H
2#define YAZE_APP_EDITOR_DUNGEON_DUNGEON_OBJECT_SELECTOR_H
3
4#include <array>
5#include <cstdint>
6#include <functional>
7#include <map>
8#include <memory>
9#include <string>
10#include "app/editor/editor.h"
12#include "core/project.h"
14#include "rom/rom.h"
15#include "zelda3/dungeon/room.h"
17#include "zelda3/game_data.h"
18// object_renderer.h removed - using ObjectDrawer for production rendering
20#include "imgui/imgui.h"
25
26namespace yaze {
27namespace editor {
28
29class ObjectTileEditorPanel;
30
35 public:
36 explicit DungeonObjectSelector(Rom* rom = nullptr) : rom_(rom) {}
37
38 void DrawTileSelector();
39 void DrawObjectRenderer();
41 void Draw();
42
43 // Unified context setter (preferred)
45 rom_ = ctx.rom;
47 }
48 EditorContext context() const { return {rom_, game_data_}; }
49
50 // Individual setters for compatibility
51 void SetRom(Rom* rom) { rom_ = rom; }
52 Rom* rom() const { return rom_; }
55
56 // Editor system access
58 std::unique_ptr<zelda3::DungeonEditorSystem>* system) {
60 }
61 void set_object_editor(std::unique_ptr<zelda3::DungeonObjectEditor>* editor) {
62 object_editor_ = editor ? editor->get() : nullptr;
63 }
64
65 // Room data access
66 void set_rooms(std::array<zelda3::Room, 0x128>* rooms) { rooms_ = rooms; }
67 std::array<zelda3::Room, 0x128>* get_rooms() { return rooms_; }
68 void set_current_room_id(int room_id) { current_room_id_ = room_id; }
69
70 // Palette access
74 void SetCurrentPaletteGroup(const gfx::PaletteGroup& palette_group) {
75 current_palette_group_ = palette_group;
76 }
77 void SetCurrentPaletteId(uint64_t palette_id) {
78 current_palette_id_ = palette_id;
79 }
80 void SetCustomObjectsFolder(const std::string& folder);
81
82 // Object selection callbacks
84 std::function<void(const zelda3::RoomObject&)> callback) {
86 }
87
89 std::function<void(const zelda3::RoomObject&)> callback) {
91 }
92
93 void SetObjectDoubleClickCallback(std::function<void(int)> callback) {
95 }
96
97 // Get current preview object for placement
99 bool IsObjectLoaded() const { return object_loaded_; }
100
101 // AssetBrowser-style object selection
103
104 // Programmatic selection
105 void SelectObject(int obj_id, int subtype = -1);
106
107 // Tile editor panel and project references for custom object creation
111 void SetProject(project::YazeProject* project) { project_ = project; }
112
113 // Invalidate preview and layout caches (e.g., after new custom object added)
115
116 // Static editor indicator (highlights which object is being viewed in detail)
117 void SetStaticEditorObjectId(int obj_id) {
119 }
121
122 private:
123 void DrawRoomGraphics();
124 bool MatchesObjectFilter(int obj_id, int filter_type);
125 bool MatchesObjectSearch(int obj_id, const std::string& name,
126 int subtype = -1) const;
127 void CalculateObjectDimensions(const zelda3::RoomObject& object, int& width,
128 int& height);
129 void PlaceObjectAtPosition(int x, int y);
137 bool DrawObjectPreview(const zelda3::RoomObject& object, ImVec2 top_left,
138 float size);
139 zelda3::RoomObject MakePreviewObject(int obj_id) const;
141 ImU32 GetObjectTypeColor(int object_id);
142 std::string GetObjectTypeSymbol(int object_id);
143 void RenderObjectPrimitive(const zelda3::RoomObject& object, int x, int y);
146
147 // Custom object creation dialog state
152 char create_filename_[128] = {0};
153
154 // References for custom object creation
157
158 Rom* rom_ = nullptr;
160 gui::Canvas room_gfx_canvas_{"##RoomGfxCanvas",
161 ImVec2(0x100 + 1, 0x10 * 0x40 + 1)};
163
164 // Editor systems
165 std::unique_ptr<zelda3::DungeonEditorSystem>* dungeon_editor_system_ =
166 nullptr;
170
171 // Room data
172 std::array<zelda3::Room, 0x128>* rooms_ = nullptr;
174
175 // Palette data
179
181
182 // Object preview system
185 bool object_loaded_ = false;
186
187 // Callback for object selection
190 std::function<void(int)> object_double_click_callback_;
191
192 // Object selection state
194 int static_editor_object_id_ = -1; // Object currently open in static editor
195
196 // UI state for placement controls (previously static locals)
197 int place_x_ = 0;
198 int place_y_ = 0;
199
200 // UI state for object browser filter
202 int object_subtype_tab_ = 0; // 0=Type1, 1=Type2, 2=Type3
203 char object_search_buffer_[64] = {0};
204
205 // UI state for compact sprite editor
209
210 // UI state for compact item editor
212 int new_item_x_ = 0;
213 int new_item_y_ = 0;
214
215 // UI state for compact entrance editor
221
222 // UI state for compact door editor
223 int door_x_ = 0;
224 int door_y_ = 0;
227
228 // UI state for compact chest editor
229 int chest_x_ = 0;
230 int chest_y_ = 0;
232 bool chest_big_ = false;
233
234 // UI state for room properties editor
235 char room_name_[128] = {0};
236 int dungeon_id_ = 0;
238 bool is_boss_room_ = false;
239 bool is_save_room_ = false;
240 int music_id_ = 0;
241
242 // Registry initialization flag
244
245 // Performance: enable/disable graphical preview rendering
247
248 // Preview cache for object selector grid
249 // Key: object_id (or object_id+subtype for custom objects)
250 // Value: BackgroundBuffer with rendered preview
251 std::map<uint64_t, std::unique_ptr<gfx::BackgroundBuffer>> preview_cache_;
255
256 std::map<uint32_t, zelda3::ObjectTileLayout> layout_cache_;
257
258 bool GetOrCreatePreview(const zelda3::RoomObject& object, float size,
260
262};
263
264} // namespace editor
265} // namespace yaze
266
267#endif
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
Handles object selection, preview, and editing UI.
std::function< void(const zelda3::RoomObject &) object_placement_callback_)
zelda3::DungeonObjectEditor * object_editor_
std::array< zelda3::Room, 0x128 > * rooms_
bool GetOrCreatePreview(const zelda3::RoomObject &object, float size, gfx::BackgroundBuffer **out)
void SetCustomObjectsFolder(const std::string &folder)
void CalculateObjectDimensions(const zelda3::RoomObject &object, int &width, int &height)
zelda3::DungeonObjectRegistry object_registry_
void set_rooms(std::array< zelda3::Room, 0x128 > *rooms)
std::function< void(int)> object_double_click_callback_
void RenderObjectPrimitive(const zelda3::RoomObject &object, int x, int y)
void SetProject(project::YazeProject *project)
void SetGameData(zelda3::GameData *game_data)
void SetObjectDoubleClickCallback(std::function< void(int)> callback)
bool MatchesObjectSearch(int obj_id, const std::string &name, int subtype=-1) const
void set_object_editor(std::unique_ptr< zelda3::DungeonObjectEditor > *editor)
void SetCurrentPaletteGroup(const gfx::PaletteGroup &palette_group)
std::unique_ptr< zelda3::DungeonEditorSystem > * dungeon_editor_system_
std::array< zelda3::Room, 0x128 > * get_rooms()
void set_dungeon_editor_system(std::unique_ptr< zelda3::DungeonEditorSystem > *system)
void SelectObject(int obj_id, int subtype=-1)
void SetCurrentPaletteId(uint64_t palette_id)
const zelda3::RoomObject & GetPreviewObject() const
std::function< void(const zelda3::RoomObject &) object_selected_callback_)
std::map< uint64_t, std::unique_ptr< gfx::BackgroundBuffer > > preview_cache_
void SetTileEditorPanel(ObjectTileEditorPanel *panel)
zelda3::RoomObject MakePreviewObject(int obj_id) const
std::map< uint32_t, zelda3::ObjectTileLayout > layout_cache_
bool DrawObjectPreview(const zelda3::RoomObject &object, ImVec2 top_left, float size)
bool MatchesObjectFilter(int obj_id, int filter_type)
void SetObjectPlacementCallback(std::function< void(const zelda3::RoomObject &)> callback)
void SetObjectSelectedCallback(std::function< void(const zelda3::RoomObject &)> callback)
Panel for editing the tile8 composition of dungeon objects.
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:150
Interactive dungeon object editor with scroll wheel support.
Minimal registry for dungeon objects (vanilla or custom).
Lightweight view into the essential runtime context (Rom + GameData)
Definition editor.h:70
zelda3::GameData * game_data
Definition editor.h:72
Represents a group of palettes.
Modern project structure with comprehensive settings consolidation.
Definition project.h:120