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 "rom/rom.h"
18#include "zelda3/dungeon/room.h"
20#include "zelda3/game_data.h"
21// object_renderer.h removed - using ObjectDrawer for production rendering
22#include "imgui/imgui.h"
25
26namespace yaze {
27namespace editor {
28
29class ObjectTileEditorPanel;
30struct DungeonObjectSelectorTestAccess;
31
33 int columns = 1;
34 float item_size = 1.0f;
35 float leading_inset = 0.0f;
36};
37
39 bool valid = false;
40 float x = 0.0f;
41 float y = 0.0f;
42 float width = 0.0f;
43 float height = 0.0f;
44};
45
46// Pure responsive-layout helpers shared by the selector and its unit tests.
48 float available_width, float preferred_item_size, float item_spacing,
49 float min_item_size = 32.0f);
51 float source_height,
52 float box_width,
53 float box_height);
54bool MatchesDungeonObjectStreamFilter(int object_id, int selected_filter);
55bool IsDungeonCustomObjectRuntimeSlot(int object_id, int subtype);
56bool IsMinecartGraphicsRuntimeSlot(int object_id, int subtype);
57std::string GetDungeonCustomObjectSlotName(int object_id, int subtype);
58
63 public:
64 explicit DungeonObjectSelector(Rom* rom = nullptr) : rom_(rom) {}
66
67 // Unified context setter (preferred)
69 rom_ = ctx.rom;
71 }
72 EditorContext context() const { return {rom_, game_data_}; }
73
74 // Individual setters for compatibility
75 void SetRom(Rom* rom) { rom_ = rom; }
76 Rom* rom() const { return rom_; }
79
80 // Room data access
81 void set_rooms(DungeonRoomStore* rooms) { rooms_ = rooms; }
83 void set_current_room_id(int room_id) { current_room_id_ = room_id; }
84
85 // Palette access
86 // Replace the active palette group used by preview rendering. The preview
87 // cache is keyed on object identity plus room blockset, palette, and floor
88 // graphics, none of which capture the *contents* of the palette group: switching
89 // dungeons between two palette banks that happen to use the same numeric
90 // slot value will keep cache hits valid by key but stale by color. Since
91 // the cache rebuilds in well under a frame, we conservatively invalidate
92 // on every palette-group swap rather than fingerprint the group.
93 void SetCurrentPaletteGroup(const gfx::PaletteGroup& palette_group) {
94 current_palette_group_ = palette_group;
96 }
97 // Object selection callbacks
99 std::function<void(const zelda3::RoomObject&)> callback) {
100 object_selected_callback_ = callback;
101 }
102 void SetPlacementInvalidatedCallback(std::function<void()> callback) {
103 placement_invalidated_callback_ = std::move(callback);
104 }
105
106 // Get current preview object for placement
108 bool IsObjectLoaded() const { return object_loaded_; }
109
110 // AssetBrowser-style object selection
112
113 // Programmatic selection
114 void SelectObject(int obj_id, int subtype = -1);
115
116 // Fixed-slot custom-object management actions.
120 void SetOpenTileEditorWindowCallback(std::function<bool()> callback) {
121 open_tile_editor_window_callback_ = std::move(callback);
122 }
123 void SetOpenMinecartEditorWindowCallback(std::function<bool()> callback) {
124 open_minecart_editor_window_callback_ = std::move(callback);
125 }
126
127 // Invalidate preview and layout caches (e.g., after new custom object added)
130
131 // Break references to one DungeonEditorV2 session without mutating the
132 // process-wide custom-object manager used by other sessions.
134
135 // Test-only inspection. Increments every time InvalidatePreviewCache runs
136 // so unit tests can pin behavioral contracts (e.g. SetCurrentPaletteGroup
137 // must invalidate) without needing a full rendering pipeline.
145 bool matches_object_filter_for_testing(int obj_id, int filter_type) {
146 return MatchesObjectFilter(obj_id, filter_type);
147 }
148 std::string object_type_symbol_for_testing(int object_id) {
149 return GetObjectTypeSymbol(object_id);
150 }
151 static bool IsRepresentableChestObjectId(int object_id);
152
153 private:
155 enum class BrowserMode {
156 kObjects,
158 };
159
160 bool MatchesObjectFilter(int obj_id, int filter_type);
161 bool MatchesObjectSearch(int obj_id, const std::string& name,
162 int subtype = -1) const;
163 void CalculateObjectDimensions(const zelda3::RoomObject& object, int& width,
164 int& height);
165 bool DrawObjectPreview(const zelda3::RoomObject& object, ImVec2 top_left,
166 ImVec2 box_size);
167 zelda3::RoomObject MakePreviewObject(int obj_id) const;
169 ImU32 GetObjectTypeColor(int object_id);
170 std::string GetObjectTypeSymbol(int object_id);
171 absl::Status GetCustomObjectAssetStatus(int object_id, int subtype);
173 absl::Status OpenExistingCustomObjectEditor(int16_t object_id, int subtype,
174 int room_id);
175
179
180 // References for custom-object management.
185
186 Rom* rom_ = nullptr;
190 std::map<uint32_t, absl::Status> custom_asset_status_cache_;
191
192 // Room data
195
196 // Palette data
198
200
201 // Object preview system
203 bool object_loaded_ = false;
205
206 // Callback for object selection
208 std::function<void()> placement_invalidated_callback_;
209
210 // Object selection state
212
213 // UI state for object browser filter
215 int object_stream_filter_ = 0; // 0=All, 1=Type1, 2=Type2, 3=Type3
216 int object_grid_density_ = 0; // 0=Compact, 1=Medium, 2=Large
217 char object_search_buffer_[64] = {0};
218
219 // Registry initialization flag
221
222 // Performance: enable/disable graphical preview rendering
224
225 // Preview cache for object selector grid, keyed by object/subtype and the
226 // room graphics context that can change its rendered tiles.
227 // Value: BackgroundBuffer with rendered preview
228 std::map<uint64_t, std::unique_ptr<gfx::BackgroundBuffer>> preview_cache_;
236
237 std::map<uint32_t, zelda3::ObjectTileLayout> layout_cache_;
238
239 // Bumped by InvalidatePreviewCache() to give tests a way to assert the
240 // cache invalidation contract without poking at the cache directly.
242
243 void RetirePreviewCache();
245 static uint32_t MakeLayoutCacheKey(int object_id, uint8_t preview_size,
246 const zelda3::Room* room);
247 bool GetOrCreatePreview(const zelda3::RoomObject& object,
249};
250
251} // namespace editor
252} // namespace yaze
253
254#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.
void SynchronizePreviewCacheRoomContext(const zelda3::Room &room)
std::function< void()> placement_invalidated_callback_
std::function< bool()> open_minecart_editor_window_callback_
std::string object_type_symbol_for_testing(int object_id)
absl::Status OpenExistingCustomObjectEditor(int16_t object_id, int subtype, int room_id)
std::map< uint32_t, absl::Status > custom_asset_status_cache_
void CalculateObjectDimensions(const zelda3::RoomObject &object, int &width, int &height)
zelda3::DungeonObjectRegistry object_registry_
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)
absl::Status GetCustomObjectAssetStatus(int object_id, int subtype)
void SetOpenMinecartEditorWindowCallback(std::function< bool()> callback)
void SelectObject(int obj_id, int subtype=-1)
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 SetPlacementInvalidatedCallback(std::function< void()> callback)
void SetTileEditorPanel(ObjectTileEditorPanel *panel)
zelda3::RoomObject MakePreviewObject(int obj_id) const
std::map< uint32_t, zelda3::ObjectTileLayout > layout_cache_
bool GetOrCreatePreview(const zelda3::RoomObject &object, gfx::BackgroundBuffer **out)
static uint32_t MakeLayoutCacheKey(int object_id, uint8_t preview_size, const zelda3::Room *room)
bool MatchesObjectFilter(int obj_id, int filter_type)
void SetObjectSelectedCallback(std::function< void(const zelda3::RoomObject &)> callback)
bool DrawObjectPreview(const zelda3::RoomObject &object, ImVec2 top_left, ImVec2 box_size)
Panel for editing the tile8 composition of dungeon objects.
Minimal registry for dungeon objects (vanilla or custom).
bool MatchesDungeonObjectStreamFilter(int object_id, int selected_filter)
bool IsMinecartGraphicsRuntimeSlot(int object_id, int subtype)
bool IsDungeonCustomObjectRuntimeSlot(int object_id, int subtype)
DungeonObjectPreviewFit ResolveDungeonObjectPreviewFit(float source_width, float source_height, float box_width, float box_height)
std::string GetDungeonCustomObjectSlotName(int object_id, int subtype)
DungeonObjectSelectorGridLayout ResolveDungeonObjectSelectorGridLayout(float available_width, float preferred_item_size, float item_spacing, float min_item_size)
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.