43 void Draw(
bool* p_open)
override {
49 ImGui::TextDisabled(
ICON_MD_INFO " No dungeon rooms loaded.");
55 const bool room_id_valid =
56 (room_id >= 0 && room_id < static_cast<int>(rooms->size()));
59 const bool reserved_region_present =
61 if (!reserved_region_present) {
63 " WaterFill reserved region missing (use an "
64 "expanded-collision Oracle ROM)");
66 tr(
"Expected ROM >= 0x%X bytes (WaterFill end). Current ROM is %zu "
73 if (ImGui::Checkbox(tr(
"Show Water Fill Overlay"), &show_overlay)) {
78 ImGui::TextUnformatted(tr(
"Authoring"));
81 json_options.
filters.push_back({
"Water Fill Zones",
"json"});
82 json_options.
filters.push_back({
"All Files",
"*"});
84 ImGui::BeginDisabled(!reserved_region_present);
96 auto zones = std::move(zones_or.value());
97 for (
const auto& z : zones) {
99 z.room_id >=
static_cast<int>(rooms->size())) {
106 zones.size(), path.c_str());
109 }
catch (
const std::exception& e) {
116 if (ImGui::Button(
ICON_MD_TUNE " Normalize Masks Now")) {
124 for (
const auto& z : zones) {
125 auto& r = (*rooms)[z.room_id];
126 if (r.water_fill_sram_bit_mask() != z.sram_bit_mask) {
127 r.set_water_fill_sram_bit_mask(z.sram_bit_mask);
135 absl::StrFormat(
"Normalized masks (%d room(s) updated)", changed);
139 ImGui::EndDisabled();
150 "water_fill_zones.json",
"json");
152 std::ofstream file(path);
153 if (!file.is_open()) {
155 absl::StrFormat(
"Cannot write file: %s", path.c_str());
161 zones.size(), path.c_str());
176 ImGui::TextWrapped(tr(
177 "Import/export uses a room-indexed JSON format. Normalize masks before "
178 "saving to avoid duplicate SRAM bits."));
181 if (!room_id_valid) {
184 auto& room = (*rooms)[room_id];
185 const bool room_loaded = room.IsLoaded();
189 " Room not loaded yet (open it to paint and validate sprites).");
194 tr(
"Painting requires an active interaction context."));
198 int brush_radius = std::clamp(state.paint_brush_radius, 0, 8);
199 if (ImGui::SliderInt(tr(
"Brush Radius"), &brush_radius, 0, 8)) {
200 state.paint_brush_radius = brush_radius;
203 ImGui::TextDisabled(tr(
"%dx%d"), (brush_radius * 2) + 1,
204 (brush_radius * 2) + 1);
208 const bool can_paint = reserved_region_present && room_loaded;
209 ImGui::BeginDisabled(!can_paint);
210 if (ImGui::Checkbox(tr(
"Paint Mode"), &is_painting)) {
219 ImGui::EndDisabled();
222 ImGui::TextColored(theme.text_warning_yellow,
223 tr(
"Left-drag paints; Alt-drag erases"));
227 const int tile_count = room.WaterFillTileCount();
229 ImGui::Text(tr(
"Zone Tiles: %d"), tile_count);
230 if (tile_count > 255) {
231 ImGui::TextColored(theme.status_error,
236 bool has_switch_sprite =
false;
237 for (
const auto& spr : room.GetSprites()) {
238 if (spr.id() == 0x04 || spr.id() == 0x21) {
239 has_switch_sprite =
true;
243 if (!has_switch_sprite) {
246 " No PullSwitch (0x04) / PushSwitch (0x21) sprite found");
249 ImGui::TextDisabled(tr(
"Sprite checks require the room to be loaded."));
253 uint8_t mask = room.water_fill_sram_bit_mask();
254 std::string preview =
255 (mask == 0) ?
"Auto (0x00)" : absl::StrFormat(
"0x%02X", mask);
256 ImGui::BeginDisabled(!reserved_region_present);
257 if (ImGui::BeginCombo(tr(
"SRAM Bit Mask ($7EF411)"), preview.c_str())) {
258 auto option = [&](
const char* label, uint8_t val) {
259 const bool selected = (mask == val);
260 if (ImGui::Selectable(label, selected)) {
261 room.set_water_fill_sram_bit_mask(val);
266 option(
"Auto (0x00)", 0x00);
267 option(
"Bit 0 (0x01)", 0x01);
268 option(
"Bit 1 (0x02)", 0x02);
269 option(
"Bit 2 (0x04)", 0x04);
270 option(
"Bit 3 (0x08)", 0x08);
271 option(
"Bit 4 (0x10)", 0x10);
272 option(
"Bit 5 (0x20)", 0x20);
273 option(
"Bit 6 (0x40)", 0x40);
274 option(
"Bit 7 (0x80)", 0x80);
280 if (ImGui::Button(tr(
"Clear Water Fill Zone"))) {
281 room.ClearWaterFillZone();
283 ImGui::EndDisabled();
286 tr(
"Water fill zones are serialized as compact tile offset lists. "
287 "Keep zones under 255 tiles per room."));
293 if (ImGui::CollapsingHeader(tr(
"Zone Overview"),
294 ImGuiTreeNodeFlags_DefaultOpen)) {
302 std::vector<ZoneRow> rows;
304 std::unordered_map<uint8_t, int> mask_counts;
305 int rooms_over_tile_limit = 0;
306 int rooms_unassigned_mask = 0;
308 for (
int rid = 0; rid < static_cast<int>(rooms->size()); ++rid) {
309 auto& r = (*rooms)[rid];
310 const int tiles = r.WaterFillTileCount();
313 rows.push_back(ZoneRow{rid, tiles, r.water_fill_sram_bit_mask(),
314 r.water_fill_dirty()});
316 rooms_over_tile_limit++;
318 if (r.water_fill_sram_bit_mask() == 0) {
319 rooms_unassigned_mask++;
321 mask_counts[r.water_fill_sram_bit_mask()]++;
325 std::sort(rows.begin(), rows.end(),
326 [](
const ZoneRow& a,
const ZoneRow& b) {
327 return a.room_id < b.room_id;
330 int duplicate_masks = 0;
331 for (
const auto& [mask, count] : mask_counts) {
332 if (mask != 0 && count > 1) {
337 ImGui::Text(tr(
"Rooms with zones: %zu / 8"), rows.size());
338 if (rows.size() > 8) {
339 ImGui::TextColored(theme.status_error,
342 if (rooms_over_tile_limit > 0) {
343 ImGui::TextColored(theme.status_error,
345 rooms_over_tile_limit);
347 if (duplicate_masks > 0) {
348 ImGui::TextColored(theme.status_error,
350 " Duplicate SRAM bit masks detected (%d mask(s))",
353 if (rooms_unassigned_mask > 0) {
354 ImGui::TextColored(theme.text_warning_yellow,
356 " %d room(s) use Auto mask (assigned on save)",
357 rooms_unassigned_mask);
360 if (ImGui::BeginTable(
"##WaterFillZoneOverview", 6,
361 ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg |
362 ImGuiTableFlags_SizingFixedFit)) {
363 ImGui::TableSetupColumn(
"Room");
364 ImGui::TableSetupColumn(
"Tiles");
365 ImGui::TableSetupColumn(
"Mask");
366 ImGui::TableSetupColumn(
"Dirty");
367 ImGui::TableSetupColumn(
"Dup?");
368 ImGui::TableSetupColumn(
"Action");
369 ImGui::TableHeadersRow();
371 for (
const auto& row : rows) {
372 const bool is_current = (row.room_id == room_id);
374 (row.mask != 0 && mask_counts.contains(row.mask) &&
375 mask_counts[row.mask] > 1);
377 ImGui::TableNextRow();
378 ImGui::TableNextColumn();
380 ImGui::TextColored(theme.text_info, tr(
"0x%02X"), row.room_id);
382 ImGui::Text(tr(
"0x%02X"), row.room_id);
385 ImGui::TableNextColumn();
386 ImGui::Text(
"%d", row.tiles);
388 ImGui::TableNextColumn();
390 ImGui::TextDisabled(tr(
"Auto"));
392 ImGui::Text(tr(
"0x%02X"), row.mask);
395 ImGui::TableNextColumn();
396 ImGui::TextUnformatted(row.dirty ?
"Yes" :
"No");
398 ImGui::TableNextColumn();
402 ImGui::TextDisabled(
"-");
405 ImGui::TableNextColumn();
407 ImGui::PushID(row.room_id);
408 if (ImGui::SmallButton(tr(
"Open"))) {
413 ImGui::TextDisabled(
"-");