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>
11#include "app/editor/editor.h"
14#include "core/project.h"
15#include "rom/rom.h"
16#include "zelda3/dungeon/room.h"
18#include "zelda3/game_data.h"
19// object_renderer.h removed - using ObjectDrawer for production rendering
20#include "imgui/imgui.h"
23
24namespace yaze {
25namespace editor {
26
27class ObjectTileEditorPanel;
28
33 public:
34 explicit DungeonObjectSelector(Rom* rom = nullptr) : rom_(rom) {}
35
36 // Unified context setter (preferred)
38 rom_ = ctx.rom;
40 }
41 EditorContext context() const { return {rom_, game_data_}; }
42
43 // Individual setters for compatibility
44 void SetRom(Rom* rom) { rom_ = rom; }
45 Rom* rom() const { return rom_; }
48
49 // Room data access
50 void set_rooms(DungeonRoomStore* rooms) { rooms_ = rooms; }
52 void set_current_room_id(int room_id) { current_room_id_ = room_id; }
53
54 // Palette access
58 // Replace the active palette group used by preview rendering. The preview
59 // cache is keyed on (object_id, subtype, room.blockset(), room.palette()),
60 // none of which capture the *contents* of the palette group: switching
61 // dungeons between two palette banks that happen to use the same numeric
62 // slot value will keep cache hits valid by key but stale by color. Since
63 // the cache rebuilds in well under a frame, we conservatively invalidate
64 // on every palette-group swap rather than fingerprint the group.
65 void SetCurrentPaletteGroup(const gfx::PaletteGroup& palette_group) {
66 current_palette_group_ = palette_group;
68 }
69 void SetCurrentPaletteId(uint64_t palette_id) {
70 current_palette_id_ = palette_id;
71 }
72 void SetCustomObjectsFolder(const std::string& folder);
73
74 // Object selection callbacks
76 std::function<void(const zelda3::RoomObject&)> callback) {
78 }
79
80 // Get current preview object for placement
82 bool IsObjectLoaded() const { return object_loaded_; }
83
84 // AssetBrowser-style object selection
86
87 // Programmatic selection
88 void SelectObject(int obj_id, int subtype = -1);
89
90 // Tile editor panel and project references for custom object creation
94 void SetProject(project::YazeProject* project) { project_ = project; }
95
96 // Invalidate preview and layout caches (e.g., after new custom object added)
98
99 // Test-only inspection. Increments every time InvalidatePreviewCache runs
100 // so unit tests can pin behavioral contracts (e.g. SetCurrentPaletteGroup
101 // must invalidate) without needing a full rendering pipeline.
108
109 private:
110 bool MatchesObjectFilter(int obj_id, int filter_type);
111 bool MatchesObjectSearch(int obj_id, const std::string& name,
112 int subtype = -1) const;
113 void CalculateObjectDimensions(const zelda3::RoomObject& object, int& width,
114 int& height);
115 bool DrawObjectPreview(const zelda3::RoomObject& object, ImVec2 top_left,
116 float size);
117 zelda3::RoomObject MakePreviewObject(int obj_id) const;
119 ImU32 GetObjectTypeColor(int object_id);
120 std::string GetObjectTypeSymbol(int object_id);
122 void DrawCustomObjectWorkshopButton(int custom_count);
123 void DrawCustomObjectWorkshopPopup(float item_size);
125
126 // Custom object creation dialog state
132 char create_filename_[128] = {0};
133
134 // References for custom object creation
137
138 Rom* rom_ = nullptr;
142
143 // Room data
146
147 // Palette data
151
153
154 // Object preview system
157 bool object_loaded_ = false;
158
159 // Callback for object selection
161
162 // Object selection state
164
165 // UI state for object browser filter
167 int object_subtype_tab_ = 0; // 0=Type1, 1=Type2, 2=Type3
168 int object_grid_density_ = 1; // 0=Small, 1=Medium, 2=Large
169 char object_search_buffer_[64] = {0};
170
171 // Registry initialization flag
173
174 // Performance: enable/disable graphical preview rendering
176
177 // Preview cache for object selector grid
178 // Key: object_id (or object_id+subtype for custom objects)
179 // Value: BackgroundBuffer with rendered preview
180 std::map<uint64_t, std::unique_ptr<gfx::BackgroundBuffer>> preview_cache_;
184
185 std::map<uint32_t, zelda3::ObjectTileLayout> layout_cache_;
186
187 // Bumped by InvalidatePreviewCache() to give tests a way to assert the
188 // cache invalidation contract without poking at the cache directly.
190
191 bool GetOrCreatePreview(const zelda3::RoomObject& object, float size,
193};
194
195} // namespace editor
196} // namespace yaze
197
198#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.
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 SetProject(project::YazeProject *project)
void SetGameData(zelda3::GameData *game_data)
bool MatchesObjectSearch(int obj_id, const std::string &name, int subtype=-1) const
void set_rooms(DungeonRoomStore *rooms)
void SetCurrentPaletteGroup(const gfx::PaletteGroup &palette_group)
std::size_t preview_cache_invalidations_for_testing() const
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 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).
Minimal registry for dungeon objects (vanilla or custom).
Lightweight view into the essential runtime context (Rom + GameData)
Definition editor.h:72
zelda3::GameData * game_data
Definition editor.h:74
Represents a group of palettes.
Modern project structure with comprehensive settings consolidation.
Definition project.h:172