44 void Draw(
bool* p_open)
override {
50 ImGui::TextDisabled(
ICON_MD_INFO " No dungeon rooms loaded.");
56 const bool room_id_valid =
57 (room_id >= 0 && room_id < static_cast<int>(rooms->size()));
60 const bool reserved_region_present =
62 const bool save_enabled =
64 if (!reserved_region_present) {
66 " WaterFill reserved region missing (use an "
67 "expanded-collision Oracle ROM)");
69 tr(
"Expected ROM >= 0x%X bytes (WaterFill end). Current ROM is %zu "
76 ImGui::TextColored(theme.text_warning_yellow,
ICON_MD_LOCK
77 " Read-only: Water Fill saving is disabled");
79 tr(
"Set save_dungeon_water_fill_zones=true in the .yaze project and "
80 "reopen it before authoring zones."));
89 if (ImGui::Checkbox(tr(
"Show Water Fill Overlay"), &show_overlay)) {
94 ImGui::TextUnformatted(tr(
"Authoring"));
97 json_options.
filters.push_back({
"Water Fill Zones",
"json"});
98 json_options.
filters.push_back({
"All Files",
"*"});
100 ImGui::BeginDisabled(!reserved_region_present || !save_enabled);
108 if (!zones_or.ok()) {
112 auto zones = std::move(zones_or.value());
113 for (
const auto& z : zones) {
115 z.room_id >=
static_cast<int>(rooms->size())) {
122 zones.size(), path.c_str());
125 }
catch (
const std::exception& e) {
132 if (ImGui::Button(
ICON_MD_TUNE " Normalize Masks Now")) {
140 for (
const auto& z : zones) {
141 auto& r = (*rooms)[z.room_id];
142 if (r.water_fill_sram_bit_mask() != z.sram_bit_mask) {
143 r.set_water_fill_sram_bit_mask(z.sram_bit_mask);
151 absl::StrFormat(
"Normalized masks (%d room(s) updated)", changed);
155 ImGui::EndDisabled();
166 "water_fill_zones.json",
"json");
168 std::ofstream file(path);
169 if (!file.is_open()) {
171 absl::StrFormat(
"Cannot write file: %s", path.c_str());
177 zones.size(), path.c_str());
192 ImGui::TextWrapped(tr(
193 "Import/export uses a room-indexed JSON format. Normalize masks before "
194 "saving to avoid duplicate SRAM bits."));
197 if (!room_id_valid) {
200 auto& room = (*rooms)[room_id];
201 const bool room_loaded = room.IsLoaded();
205 " Room not loaded yet (open it to paint and validate sprites).");
210 tr(
"Painting requires an active interaction context."));
214 int brush_radius = std::clamp(state.paint_brush_radius, 0, 8);
215 if (ImGui::SliderInt(tr(
"Brush Radius"), &brush_radius, 0, 8)) {
216 state.paint_brush_radius = brush_radius;
219 ImGui::TextDisabled(tr(
"%dx%d"), (brush_radius * 2) + 1,
220 (brush_radius * 2) + 1);
224 const bool can_paint =
225 reserved_region_present && room_loaded && save_enabled;
226 ImGui::BeginDisabled(!can_paint);
227 if (ImGui::Checkbox(tr(
"Paint Mode"), &is_painting)) {
236 ImGui::EndDisabled();
239 ImGui::TextColored(theme.text_warning_yellow,
240 tr(
"Left-drag paints; Alt-drag erases"));
244 const int tile_count = room.WaterFillTileCount();
246 ImGui::Text(tr(
"Zone Tiles: %d"), tile_count);
247 if (tile_count > 255) {
248 ImGui::TextColored(theme.status_error,
253 bool has_switch_sprite =
false;
254 for (
const auto& spr : room.GetSprites()) {
255 if (spr.id() == 0x04 || spr.id() == 0x21) {
256 has_switch_sprite =
true;
260 if (!has_switch_sprite) {
263 " No PullSwitch (0x04) / PushSwitch (0x21) sprite found");
266 ImGui::TextDisabled(tr(
"Sprite checks require the room to be loaded."));
270 uint8_t mask = room.water_fill_sram_bit_mask();
271 std::string preview =
272 (mask == 0) ?
"Auto (0x00)" : absl::StrFormat(
"0x%02X", mask);
273 ImGui::BeginDisabled(!reserved_region_present || !save_enabled);
274 if (ImGui::BeginCombo(tr(
"SRAM Bit Mask ($7EF411)"), preview.c_str())) {
275 auto option = [&](
const char* label, uint8_t val) {
276 const bool selected = (mask == val);
277 if (ImGui::Selectable(label, selected)) {
278 room.set_water_fill_sram_bit_mask(val);
283 option(
"Auto (0x00)", 0x00);
284 option(
"Bit 0 (0x01)", 0x01);
285 option(
"Bit 1 (0x02)", 0x02);
286 option(
"Bit 2 (0x04)", 0x04);
287 option(
"Bit 3 (0x08)", 0x08);
288 option(
"Bit 4 (0x10)", 0x10);
289 option(
"Bit 5 (0x20)", 0x20);
290 option(
"Bit 6 (0x40)", 0x40);
291 option(
"Bit 7 (0x80)", 0x80);
297 if (ImGui::Button(tr(
"Clear Water Fill Zone"))) {
298 room.ClearWaterFillZone();
300 ImGui::EndDisabled();
303 tr(
"Water fill zones are serialized as compact tile offset lists. "
304 "Keep zones under 255 tiles per room."));
310 if (ImGui::CollapsingHeader(tr(
"Zone Overview"),
311 ImGuiTreeNodeFlags_DefaultOpen)) {
319 std::vector<ZoneRow> rows;
321 std::unordered_map<uint8_t, int> mask_counts;
322 int rooms_over_tile_limit = 0;
323 int rooms_unassigned_mask = 0;
325 for (
int rid = 0; rid < static_cast<int>(rooms->size()); ++rid) {
326 auto& r = (*rooms)[rid];
327 const int tiles = r.WaterFillTileCount();
330 rows.push_back(ZoneRow{rid, tiles, r.water_fill_sram_bit_mask(),
331 r.water_fill_dirty()});
333 rooms_over_tile_limit++;
335 if (r.water_fill_sram_bit_mask() == 0) {
336 rooms_unassigned_mask++;
338 mask_counts[r.water_fill_sram_bit_mask()]++;
342 std::sort(rows.begin(), rows.end(),
343 [](
const ZoneRow& a,
const ZoneRow& b) {
344 return a.room_id < b.room_id;
347 int duplicate_masks = 0;
348 for (
const auto& [mask, count] : mask_counts) {
349 if (mask != 0 && count > 1) {
354 ImGui::Text(tr(
"Rooms with zones: %zu / 8"), rows.size());
355 if (rows.size() > 8) {
356 ImGui::TextColored(theme.status_error,
359 if (rooms_over_tile_limit > 0) {
360 ImGui::TextColored(theme.status_error,
362 rooms_over_tile_limit);
364 if (duplicate_masks > 0) {
365 ImGui::TextColored(theme.status_error,
367 " Duplicate SRAM bit masks detected (%d mask(s))",
370 if (rooms_unassigned_mask > 0) {
371 ImGui::TextColored(theme.text_warning_yellow,
373 " %d room(s) use Auto mask (assigned on save)",
374 rooms_unassigned_mask);
377 if (ImGui::BeginTable(
"##WaterFillZoneOverview", 6,
378 ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg |
379 ImGuiTableFlags_SizingFixedFit)) {
380 ImGui::TableSetupColumn(
"Room");
381 ImGui::TableSetupColumn(
"Tiles");
382 ImGui::TableSetupColumn(
"Mask");
383 ImGui::TableSetupColumn(
"Dirty");
384 ImGui::TableSetupColumn(
"Dup?");
385 ImGui::TableSetupColumn(
"Action");
386 ImGui::TableHeadersRow();
388 for (
const auto& row : rows) {
389 const bool is_current = (row.room_id == room_id);
391 (row.mask != 0 && mask_counts.contains(row.mask) &&
392 mask_counts[row.mask] > 1);
394 ImGui::TableNextRow();
395 ImGui::TableNextColumn();
397 ImGui::TextColored(theme.text_info, tr(
"0x%02X"), row.room_id);
399 ImGui::Text(tr(
"0x%02X"), row.room_id);
402 ImGui::TableNextColumn();
403 ImGui::Text(
"%d", row.tiles);
405 ImGui::TableNextColumn();
407 ImGui::TextDisabled(tr(
"Auto"));
409 ImGui::Text(tr(
"0x%02X"), row.mask);
412 ImGui::TableNextColumn();
413 ImGui::TextUnformatted(row.dirty ?
"Yes" :
"No");
415 ImGui::TableNextColumn();
419 ImGui::TextDisabled(
"-");
422 ImGui::TableNextColumn();
424 ImGui::PushID(row.room_id);
425 if (ImGui::SmallButton(tr(
"Open"))) {
430 ImGui::TextDisabled(
"-");