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 <utility>
11
12#include "absl/status/status.h"
14#include "app/editor/editor.h"
17#include "core/project.h"
18#include "rom/rom.h"
19#include "zelda3/dungeon/room.h"
21#include "zelda3/game_data.h"
22// object_renderer.h removed - using ObjectDrawer for production rendering
23#include "imgui/imgui.h"
26
27namespace yaze {
28namespace editor {
29
30class ObjectTileEditorPanel;
31struct DungeonObjectSelectorTestAccess;
32
37 public:
38 explicit DungeonObjectSelector(Rom* rom = nullptr) : rom_(rom) {}
39
40 // Unified context setter (preferred)
42 rom_ = ctx.rom;
44 }
45 EditorContext context() const { return {rom_, game_data_}; }
46
47 // Individual setters for compatibility
48 void SetRom(Rom* rom) { rom_ = rom; }
49 Rom* rom() const { return rom_; }
52
53 // Room data access
54 void set_rooms(DungeonRoomStore* rooms) { rooms_ = rooms; }
56 void set_current_room_id(int room_id) { current_room_id_ = room_id; }
57
58 // Palette access
62 // Replace the active palette group used by preview rendering. The preview
63 // cache is keyed on (object_id, subtype, room.blockset(), room.palette()),
64 // none of which capture the *contents* of the palette group: switching
65 // dungeons between two palette banks that happen to use the same numeric
66 // slot value will keep cache hits valid by key but stale by color. Since
67 // the cache rebuilds in well under a frame, we conservatively invalidate
68 // on every palette-group swap rather than fingerprint the group.
69 void SetCurrentPaletteGroup(const gfx::PaletteGroup& palette_group) {
70 current_palette_group_ = palette_group;
72 }
73 void SetCurrentPaletteId(uint64_t palette_id) {
74 current_palette_id_ = palette_id;
75 }
76 void SetCustomObjectsFolder(const std::string& folder);
77
78 // Object selection callbacks
80 std::function<void(const zelda3::RoomObject&)> callback) {
82 }
83
84 // Get current preview object for placement
86 bool IsObjectLoaded() const { return object_loaded_; }
87
88 // AssetBrowser-style object selection
90
91 // Programmatic selection
92 void SelectObject(int obj_id, int subtype = -1);
93
94 // Tile editor panel and project references for custom object creation
98 void SetOpenTileEditorWindowCallback(std::function<bool()> callback) {
99 open_tile_editor_window_callback_ = std::move(callback);
100 }
101 void SetProject(project::YazeProject* project) { project_ = project; }
102
103 // Invalidate preview and layout caches (e.g., after new custom object added)
105
106 // Test-only inspection. Increments every time InvalidatePreviewCache runs
107 // so unit tests can pin behavioral contracts (e.g. SetCurrentPaletteGroup
108 // must invalidate) without needing a full rendering pipeline.
116 bool matches_object_filter_for_testing(int obj_id, int filter_type) {
117 return MatchesObjectFilter(obj_id, filter_type);
118 }
119 std::string object_type_symbol_for_testing(int object_id) {
120 return GetObjectTypeSymbol(object_id);
121 }
122 static bool IsRepresentableChestObjectId(int object_id);
123
124 private:
126 bool MatchesObjectFilter(int obj_id, int filter_type);
127 bool MatchesObjectSearch(int obj_id, const std::string& name,
128 int subtype = -1) const;
129 void CalculateObjectDimensions(const zelda3::RoomObject& object, int& width,
130 int& height);
131 bool DrawObjectPreview(const zelda3::RoomObject& object, ImVec2 top_left,
132 float size);
133 zelda3::RoomObject MakePreviewObject(int obj_id) const;
135 ImU32 GetObjectTypeColor(int object_id);
136 std::string GetObjectTypeSymbol(int object_id);
138 void DrawCustomObjectWorkshopButton(int custom_count);
139 void DrawCustomObjectWorkshopPopup(float item_size);
141 absl::Status OpenNewCustomObjectEditor(int width, int height,
142 const std::string& filename,
143 int16_t object_id, int room_id);
144
145 // Custom object creation dialog state
151 char create_filename_[128] = {0};
152
153 // References for custom object creation
158
159 Rom* rom_ = nullptr;
163
164 // Room data
167
168 // Palette data
172
174
175 // Object preview system
178 bool object_loaded_ = false;
179
180 // Callback for object selection
182
183 // Object selection state
185
186 // UI state for object browser filter
188 int object_subtype_tab_ = 0; // 0=Type1, 1=Type2, 2=Type3
189 int object_grid_density_ = 1; // 0=Small, 1=Medium, 2=Large
190 char object_search_buffer_[64] = {0};
191
192 // Registry initialization flag
194
195 // Performance: enable/disable graphical preview rendering
197
198 // Preview cache for object selector grid
199 // Key: object_id (or object_id+subtype for custom objects)
200 // Value: BackgroundBuffer with rendered preview
201 std::map<uint64_t, std::unique_ptr<gfx::BackgroundBuffer>> preview_cache_;
205
206 std::map<uint32_t, zelda3::ObjectTileLayout> layout_cache_;
207
208 // Bumped by InvalidatePreviewCache() to give tests a way to assert the
209 // cache invalidation contract without poking at the cache directly.
211
212 bool GetOrCreatePreview(const zelda3::RoomObject& object, float size,
214};
215
216} // namespace editor
217} // namespace yaze
218
219#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.
absl::Status OpenNewCustomObjectEditor(int width, int height, const std::string &filename, int16_t object_id, int room_id)
std::string object_type_symbol_for_testing(int object_id)
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)
bool matches_object_filter_for_testing(int obj_id, int filter_type)
std::size_t preview_cache_invalidations_for_testing() const
static bool IsRepresentableChestObjectId(int object_id)
void SelectObject(int obj_id, int subtype=-1)
void SetCurrentPaletteId(uint64_t palette_id)
const zelda3::RoomObject & GetPreviewObject() const
std::function< bool()> open_tile_editor_window_callback_
std::function< void(const zelda3::RoomObject &) object_selected_callback_)
std::map< uint64_t, std::unique_ptr< gfx::BackgroundBuffer > > preview_cache_
void SetOpenTileEditorWindowCallback(std::function< bool()> callback)
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