45 void Draw(
bool* p_open)
override {
51 ImGui::TextDisabled(
ICON_MD_INFO " No dungeon rooms loaded.");
57 const bool room_id_valid =
58 (room_id >= 0 && room_id < static_cast<int>(rooms->size()));
61 const bool reserved_region_present =
63 const bool save_enabled =
65 if (!reserved_region_present) {
67 " WaterFill reserved region missing (use an "
68 "expanded-collision Oracle ROM)");
70 tr(
"Expected ROM >= 0x%X bytes (WaterFill end). Current ROM is %zu "
77 ImGui::TextColored(theme.text_warning_yellow,
ICON_MD_LOCK
78 " Read-only: Water Fill saving is disabled");
80 tr(
"Set save_dungeon_water_fill_zones=true in the .yaze project and "
81 "reopen it before authoring zones."));
90 if (ImGui::Checkbox(tr(
"Show Water Fill Overlay"), &show_overlay)) {
95 ImGui::TextUnformatted(tr(
"Authoring"));
98 json_options.
filters.push_back({
"Water Fill Zones",
"json"});
99 json_options.
filters.push_back({
"All Files",
"*"});
101 ImGui::BeginDisabled(!reserved_region_present || !save_enabled);
109 if (!zones_or.ok()) {
113 auto zones = std::move(zones_or.value());
114 for (
const auto& z : zones) {
116 z.room_id >=
static_cast<int>(rooms->size())) {
123 zones.size(), path.c_str());
126 }
catch (
const std::exception& e) {
133 if (ImGui::Button(
ICON_MD_TUNE " Normalize Masks Now")) {
141 for (
const auto& z : zones) {
142 auto& r = (*rooms)[z.room_id];
143 if (r.water_fill_sram_bit_mask() != z.sram_bit_mask) {
144 r.set_water_fill_sram_bit_mask(z.sram_bit_mask);
152 absl::StrFormat(
"Normalized masks (%d room(s) updated)", changed);
156 ImGui::EndDisabled();
167 "water_fill_zones.json",
"json");
169 std::ofstream file(path);
170 if (!file.is_open()) {
172 absl::StrFormat(
"Cannot write file: %s", path.c_str());
178 zones.size(), path.c_str());
193 ImGui::TextWrapped(tr(
194 "Import/export uses a room-indexed JSON format. Normalize masks before "
195 "saving to avoid duplicate SRAM bits."));
198 if (!room_id_valid) {
201 auto& room = (*rooms)[room_id];
202 const bool room_loaded = room.IsLoaded();
206 " Room not loaded yet (open it to paint and validate sprites).");
211 tr(
"Painting requires an active interaction context."));
215 int brush_radius = std::clamp(state.paint_brush_radius, 0, 8);
216 if (ImGui::SliderInt(tr(
"Brush Radius"), &brush_radius, 0, 8)) {
217 state.paint_brush_radius = brush_radius;
220 ImGui::TextDisabled(tr(
"%dx%d"), (brush_radius * 2) + 1,
221 (brush_radius * 2) + 1);
225 const bool can_paint =
226 reserved_region_present && room_loaded && save_enabled;
227 ImGui::BeginDisabled(!can_paint);
228 if (ImGui::Checkbox(tr(
"Paint Mode"), &is_painting)) {
237 ImGui::EndDisabled();
240 ImGui::TextColored(theme.text_warning_yellow,
241 tr(
"Left-drag paints; Alt-drag erases"));
245 const int tile_count = room.WaterFillTileCount();
247 ImGui::Text(tr(
"Zone Tiles: %d"), tile_count);
248 if (tile_count > 255) {
249 ImGui::TextColored(theme.status_error,
254 bool has_switch_sprite =
false;
255 for (
const auto& spr : room.GetSprites()) {
256 if (spr.id() == 0x04 || spr.id() == 0x21) {
257 has_switch_sprite =
true;
261 if (!has_switch_sprite) {
264 " No PullSwitch (0x04) / PushSwitch (0x21) sprite found");
267 ImGui::TextDisabled(tr(
"Sprite checks require the room to be loaded."));
271 uint8_t mask = room.water_fill_sram_bit_mask();
272 std::string preview =
273 (mask == 0) ?
"Auto (0x00)" : absl::StrFormat(
"0x%02X", mask);
274 ImGui::BeginDisabled(!reserved_region_present || !save_enabled);
275 if (ImGui::BeginCombo(tr(
"SRAM Bit Mask ($7EF411)"), preview.c_str())) {
276 auto option = [&](
const char* label, uint8_t val) {
277 const bool selected = (mask == val);
278 if (ImGui::Selectable(label, selected)) {
279 room.set_water_fill_sram_bit_mask(val);
284 option(
"Auto (0x00)", 0x00);
285 option(
"Bit 0 (0x01)", 0x01);
286 option(
"Bit 1 (0x02)", 0x02);
287 option(
"Bit 2 (0x04)", 0x04);
288 option(
"Bit 3 (0x08)", 0x08);
289 option(
"Bit 4 (0x10)", 0x10);
290 option(
"Bit 5 (0x20)", 0x20);
291 option(
"Bit 6 (0x40)", 0x40);
292 option(
"Bit 7 (0x80)", 0x80);
298 if (ImGui::Button(tr(
"Clear Water Fill Zone"))) {
299 room.ClearWaterFillZone();
301 ImGui::EndDisabled();
304 tr(
"Water fill zones are serialized as compact tile offset lists. "
305 "Keep zones under 255 tiles per room."));
311 if (ImGui::CollapsingHeader(tr(
"Zone Overview"),
312 ImGuiTreeNodeFlags_DefaultOpen)) {
320 std::vector<ZoneRow> rows;
322 std::unordered_map<uint8_t, int> mask_counts;
323 int rooms_over_tile_limit = 0;
324 int rooms_unassigned_mask = 0;
326 for (
int rid = 0; rid < static_cast<int>(rooms->size()); ++rid) {
327 auto& r = (*rooms)[rid];
328 const int tiles = r.WaterFillTileCount();
331 rows.push_back(ZoneRow{rid, tiles, r.water_fill_sram_bit_mask(),
332 r.water_fill_dirty()});
334 rooms_over_tile_limit++;
336 if (r.water_fill_sram_bit_mask() == 0) {
337 rooms_unassigned_mask++;
339 mask_counts[r.water_fill_sram_bit_mask()]++;
343 std::sort(rows.begin(), rows.end(),
344 [](
const ZoneRow& a,
const ZoneRow& b) {
345 return a.room_id < b.room_id;
348 int duplicate_masks = 0;
349 for (
const auto& [mask, count] : mask_counts) {
350 if (mask != 0 && count > 1) {
355 ImGui::Text(tr(
"Rooms with zones: %zu / 8"), rows.size());
356 if (rows.size() > 8) {
357 ImGui::TextColored(theme.status_error,
360 if (rooms_over_tile_limit > 0) {
361 ImGui::TextColored(theme.status_error,
363 rooms_over_tile_limit);
365 if (duplicate_masks > 0) {
366 ImGui::TextColored(theme.status_error,
368 " Duplicate SRAM bit masks detected (%d mask(s))",
371 if (rooms_unassigned_mask > 0) {
372 ImGui::TextColored(theme.text_warning_yellow,
374 " %d room(s) use Auto mask (assigned on save)",
375 rooms_unassigned_mask);
378 if (ImGui::BeginTable(
"##WaterFillZoneOverview", 6,
379 ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg |
380 ImGuiTableFlags_SizingFixedFit)) {
381 ImGui::TableSetupColumn(
"Room");
382 ImGui::TableSetupColumn(
"Tiles");
383 ImGui::TableSetupColumn(
"Mask");
384 ImGui::TableSetupColumn(
"Dirty");
385 ImGui::TableSetupColumn(
"Dup?");
386 ImGui::TableSetupColumn(
"Action");
387 ImGui::TableHeadersRow();
389 for (
const auto& row : rows) {
390 const bool is_current = (row.room_id == room_id);
392 (row.mask != 0 && mask_counts.contains(row.mask) &&
393 mask_counts[row.mask] > 1);
395 ImGui::TableNextRow();
396 ImGui::TableNextColumn();
398 ImGui::TextColored(theme.text_info, tr(
"0x%02X"), row.room_id);
400 ImGui::Text(tr(
"0x%02X"), row.room_id);
403 ImGui::TableNextColumn();
404 ImGui::Text(
"%d", row.tiles);
406 ImGui::TableNextColumn();
408 ImGui::TextDisabled(tr(
"Auto"));
410 ImGui::Text(tr(
"0x%02X"), row.mask);
413 ImGui::TableNextColumn();
414 ImGui::TextUnformatted(row.dirty ?
"Yes" :
"No");
416 ImGui::TableNextColumn();
420 ImGui::TextDisabled(
"-");
423 ImGui::TableNextColumn();
425 ImGui::PushID(row.room_id);
426 if (ImGui::SmallButton(tr(
"Open"))) {
431 ImGui::TextDisabled(
"-");