yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
entity.cc
Go to the documentation of this file.
2#include "util/i18n/tr.h"
3
4#include <fstream>
5#include <string>
6
10#include "app/gui/core/style.h"
12#include "imgui.h"
13#include "util/hex.h"
14#include "zelda3/common.h"
16
17namespace yaze {
18namespace editor {
19
20using ImGui::BeginChild;
21using ImGui::Button;
22using ImGui::Checkbox;
23using ImGui::EndChild;
24using ImGui::SameLine;
25using ImGui::Selectable;
26using ImGui::Text;
27
28constexpr float kInputFieldSize = 30.f;
29
31 ImVec2 canvas_p0, ImVec2 scrolling,
32 float scale) {
33 // Get the mouse position relative to the canvas
34 const ImGuiIO& io = ImGui::GetIO();
35 const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y);
36 const ImVec2 mouse_pos(io.MousePos.x - origin.x, io.MousePos.y - origin.y);
37
38 // Scale entity bounds to match canvas zoom level
39 float scaled_x = entity.x_ * scale;
40 float scaled_y = entity.y_ * scale;
41 float scaled_size = 16.0f * scale;
42
43 // Check if the mouse is hovering over the scaled entity bounds
44 return mouse_pos.x >= scaled_x && mouse_pos.x <= scaled_x + scaled_size &&
45 mouse_pos.y >= scaled_y && mouse_pos.y <= scaled_y + scaled_size;
46}
47
49 const gui::CanvasRuntime& rt) {
50 // Use runtime geometry to compute mouse position relative to canvas
51 const ImGuiIO& io = ImGui::GetIO();
52 const ImVec2 origin(rt.canvas_p0.x + rt.scrolling.x,
53 rt.canvas_p0.y + rt.scrolling.y);
54 const ImVec2 mouse_pos(io.MousePos.x - origin.x, io.MousePos.y - origin.y);
55
56 // Scale entity bounds to match canvas zoom level
57 float scaled_x = entity.x_ * rt.scale;
58 float scaled_y = entity.y_ * rt.scale;
59 float scaled_size = 16.0f * rt.scale;
60
61 // Check if the mouse is hovering over the scaled entity bounds
62 return mouse_pos.x >= scaled_x && mouse_pos.x <= scaled_x + scaled_size &&
63 mouse_pos.y >= scaled_y && mouse_pos.y <= scaled_y + scaled_size;
64}
65
66void MoveEntityOnGrid(zelda3::GameEntity* entity, ImVec2 canvas_p0,
67 ImVec2 scrolling, bool free_movement, float scale) {
68 // Get the mouse position relative to the canvas
69 const ImGuiIO& io = ImGui::GetIO();
70 const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y);
71 const ImVec2 mouse_pos(io.MousePos.x - origin.x, io.MousePos.y - origin.y);
72
73 // Convert screen position to world position accounting for scale
74 float world_x = mouse_pos.x / scale;
75 float world_y = mouse_pos.y / scale;
76
77 // Calculate the new position on the 16x16 or 8x8 grid (in world coordinates)
78 // Overworld sprite records encode positions in 16-pixel units, even when
79 // the general entity free-movement modifier is held.
80 int grid_size =
81 free_movement && entity->entity_type_ != zelda3::GameEntity::kSprite ? 8
82 : 16;
83 int new_x = static_cast<int>(world_x) / grid_size * grid_size;
84 int new_y = static_cast<int>(world_y) / grid_size * grid_size;
85
86 // Update the entity position
87 entity->set_x(new_x);
88 entity->set_y(new_y);
89}
90
92 bool set_done = false;
93 if (set_done) {
94 set_done = false;
95 }
96 if (ImGui::BeginPopup("Entrance Inserter")) {
97 static int entrance_id = 0;
98 if (ImGui::IsWindowAppearing()) {
99 entrance_id = 0;
100 }
101
102 gui::InputHex("Entrance ID", &entrance_id);
103
104 if (Button(ICON_MD_DONE)) {
105 set_done = true;
106 ImGui::CloseCurrentPopup();
107 }
108
109 SameLine();
110 if (Button(ICON_MD_CANCEL)) {
111 ImGui::CloseCurrentPopup();
112 }
113
114 ImGui::EndPopup();
115 }
116 return set_done;
117}
118
120 bool set_done = false;
121
122 if (ImGui::BeginPopupModal(
124 .c_str(),
125 NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
126 if (ImGui::IsWindowAppearing()) {
127 // Reset state if needed
128 }
129
130 ImGui::Text(tr("Entrance ID: %d"), entrance.entrance_id_);
131 ImGui::Separator();
132
133 gui::InputHexWord("Map ID", &entrance.map_id_);
134 gui::InputHexByte("Entrance ID", &entrance.entrance_id_,
135 kInputFieldSize + 20);
136 gui::InputHex("X Position", &entrance.x_);
137 gui::InputHex("Y Position", &entrance.y_);
138
139 ImGui::Text("Kind: %s", entrance.is_hole_ ? "Hole" : "Entrance");
140
141 ImGui::Separator();
142
143 if (Button(tr("Save"))) {
144 set_done = true;
145 ImGui::CloseCurrentPopup();
146 }
147 ImGui::SameLine();
148 if (Button(tr("Delete"))) {
149 entrance.deleted = true;
150 set_done = true;
151 ImGui::CloseCurrentPopup();
152 }
153 ImGui::SameLine();
154 if (Button(tr("Cancel"))) {
155 ImGui::CloseCurrentPopup();
156 }
157
158 ImGui::EndPopup();
159 }
160 return set_done;
161}
162
164 if (ImGui::BeginPopup("Exit Inserter")) {
165 static int exit_id = 0;
166 static int room_id = 0;
167 static int x_pos = 0;
168 static int y_pos = 0;
169
170 if (ImGui::IsWindowAppearing()) {
171 exit_id = 0;
172 room_id = 0;
173 x_pos = 0;
174 y_pos = 0;
175 }
176
177 ImGui::Text(tr("Insert New Exit"));
178 ImGui::Separator();
179
180 gui::InputHex("Exit ID", &exit_id);
181 gui::InputHex("Room ID", &room_id);
182 gui::InputHex("X Position", &x_pos);
183 gui::InputHex("Y Position", &y_pos);
184
185 if (Button(tr("Create Exit"))) {
186 // This would need to be connected to the overworld editor to actually
187 // create the exit
188 ImGui::CloseCurrentPopup();
189 }
190
191 SameLine();
192 if (Button(tr("Cancel"))) {
193 ImGui::CloseCurrentPopup();
194 }
195
196 ImGui::EndPopup();
197 }
198}
199
201 bool set_done = false;
202 if (ImGui::BeginPopupModal(
203 gui::MakePopupId(gui::EditorNames::kOverworld, "Exit Editor").c_str(),
204 NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
205 // Normal door: None = 0, Wooden = 1, Bombable = 2
206 static int doorType = 0;
207 // Fancy door: None = 0, Sanctuary = 1, Palace = 2
208 static int fancyDoorType = 0;
209
210 static int xPos = 0;
211 static int yPos = 0;
212
213 // Special overworld exit properties
214 static int centerY = 0;
215 static int centerX = 0;
216 static int unk1 = 0;
217 static int unk2 = 0;
218 static int linkPosture = 0;
219 static int spriteGFX = 0;
220 static int bgGFX = 0;
221 static int palette = 0;
222 static int sprPal = 0;
223 static int top = 0;
224 static int bottom = 0;
225 static int left = 0;
226 static int right = 0;
227 static int leftEdgeOfMap = 0;
228 static bool special_exit = false;
229 static bool show_properties = false;
230
231 if (ImGui::IsWindowAppearing()) {
232 // Reset state from entity
233 doorType = exit.door_type_1_;
234 fancyDoorType = exit.door_type_2_;
235 xPos = 0; // Unknown mapping
236 yPos = 0; // Unknown mapping
237
238 // Reset other static vars to avoid pollution
239 centerY = 0;
240 centerX = 0;
241 unk1 = 0;
242 unk2 = 0;
243 linkPosture = 0;
244 spriteGFX = 0;
245 bgGFX = 0;
246 palette = 0;
247 sprPal = 0;
248 top = 0;
249 bottom = 0;
250 left = 0;
251 right = 0;
252 leftEdgeOfMap = 0;
253 special_exit = false;
254 show_properties = false;
255 }
256
257 gui::InputHexWord("Room", &exit.room_id_);
258 SameLine();
259 ImGui::Text("Row: %02X", exit.entity_id_);
260 gui::InputHexWord("Map", &exit.map_id_);
261 SameLine();
262 Checkbox(tr("Automatic"), &exit.is_automatic_);
263
264 gui::InputHex("X Positon", &exit.x_);
265 SameLine();
266 gui::InputHex("Y Position", &exit.y_);
267
268 ImGui::BeginDisabled(exit.is_automatic_);
269 gui::InputHexWord("X Camera", &exit.x_camera_);
270 SameLine();
271 gui::InputHexWord("Y Camera", &exit.y_camera_);
272
273 gui::InputHexWord("X Scroll", &exit.x_scroll_);
274 SameLine();
275 gui::InputHexWord("Y Scroll", &exit.y_scroll_);
276 ImGui::EndDisabled();
277
278 ImGui::Separator();
279
280 Checkbox(tr("Show properties"), &show_properties);
281 if (show_properties) {
282 Text(tr("Deleted? %s"), exit.deleted_ ? "true" : "false");
283 Text(tr("Hole? %s"), exit.is_hole_ ? "true" : "false");
284 Text(tr("Auto-calc scroll/camera? %s"),
285 exit.is_automatic_ ? "true" : "false");
286 Text(tr("Map ID: 0x%02X"), exit.map_id_);
287 Text(tr("Game coords: (%d, %d)"), exit.game_x_, exit.game_y_);
288 }
289
290 gui::TextWithSeparators("Advanced Door/Exit Controls");
291
292 if (ImGui::RadioButton(tr("None"), &doorType, 0))
293 exit.door_type_1_ = doorType;
294 SameLine();
295 if (ImGui::RadioButton(tr("Wooden"), &doorType, 1))
296 exit.door_type_1_ = doorType;
297 SameLine();
298 if (ImGui::RadioButton(tr("Bombable"), &doorType, 2))
299 exit.door_type_1_ = doorType;
300
301 // If door type is not None, input positions
302 if (doorType != 0) {
303 gui::InputHex("Door X pos", &xPos);
304 gui::InputHex("Door Y pos", &yPos);
305 }
306
307 if (ImGui::RadioButton(tr("None##Fancy"), &fancyDoorType, 0))
308 exit.door_type_2_ = fancyDoorType;
309 SameLine();
310 if (ImGui::RadioButton(tr("Sanctuary"), &fancyDoorType, 1))
311 exit.door_type_2_ = fancyDoorType;
312 SameLine();
313 if (ImGui::RadioButton(tr("Palace"), &fancyDoorType, 2))
314 exit.door_type_2_ = fancyDoorType;
315
316 // If fancy door type is not None, input positions
317 if (fancyDoorType != 0) {
318 // Placeholder for fancy door's X position
319 gui::InputHex("Fancy Door X pos", &xPos);
320 // Placeholder for fancy door's Y position
321 gui::InputHex("Fancy Door Y pos", &yPos);
322 }
323
324 Checkbox(tr("Special exit"), &special_exit);
325 if (special_exit) {
326 gui::InputHex("Center X", &centerX);
327
328 gui::InputHex("Center Y", &centerY);
329 gui::InputHex("Unk1", &unk1);
330 gui::InputHex("Unk2", &unk2);
331
332 gui::InputHex("Link's posture", &linkPosture);
333 gui::InputHex("Sprite GFX", &spriteGFX);
334 gui::InputHex("BG GFX", &bgGFX);
335 gui::InputHex("Palette", &palette);
336 gui::InputHex("Spr Pal", &sprPal);
337
338 gui::InputHex("Top", &top);
339 gui::InputHex("Bottom", &bottom);
340 gui::InputHex("Left", &left);
341 gui::InputHex("Right", &right);
342
343 gui::InputHex("Left edge of map", &leftEdgeOfMap);
344 }
345
346 if (Button(ICON_MD_DONE)) {
347 set_done = true; // FIX: Save changes when Done is clicked
348 ImGui::CloseCurrentPopup();
349 }
350
351 SameLine();
352
353 if (Button(ICON_MD_CANCEL)) {
354 // FIX: Discard changes - don't set set_done
355 ImGui::CloseCurrentPopup();
356 }
357
358 SameLine();
359 if (Button(ICON_MD_DELETE)) {
360 exit.deleted_ = true;
361 set_done = true; // FIX: Save deletion when Delete is clicked
362 ImGui::CloseCurrentPopup();
363 }
364
365 ImGui::EndPopup();
366 }
367
368 return set_done;
369}
370
372 // Contents of the Context Menu
373 if (ImGui::BeginPopup("Item Inserter")) {
374 static size_t new_item_id = 0;
375 Text(tr("Add Item"));
376 BeginChild("ScrollRegion", ImVec2(150, 150), true,
377 ImGuiWindowFlags_AlwaysVerticalScrollbar);
378 for (size_t i = 0; i < zelda3::kSecretItemNames.size(); i++) {
379 if (Selectable(zelda3::kSecretItemNames[i].c_str(), i == new_item_id)) {
380 new_item_id = i;
381 }
382 }
383 EndChild();
384
385 if (Button(ICON_MD_DONE)) {
386 // Add the new item to the overworld
387 new_item_id = 0;
388 ImGui::CloseCurrentPopup();
389 }
390 SameLine();
391
392 if (Button(ICON_MD_CANCEL)) {
393 ImGui::CloseCurrentPopup();
394 }
395
396 ImGui::EndPopup();
397 }
398}
399
401 bool set_done = false;
402 if (ImGui::BeginPopupModal(
403 gui::MakePopupId(gui::EditorNames::kOverworld, "Item Editor").c_str(),
404 NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
405 BeginChild("ScrollRegion", ImVec2(150, 150), true,
406 ImGuiWindowFlags_AlwaysVerticalScrollbar);
407 ImGui::BeginGroup();
408 for (size_t i = 0; i < zelda3::kSecretItemNames.size(); i++) {
409 if (Selectable(zelda3::kSecretItemNames[i].c_str(), item.id_ == i)) {
410 item.id_ = i;
411 item.entity_id_ = i;
412 item.UpdateMapProperties(item.map_id_, nullptr);
413 }
414 }
415 ImGui::EndGroup();
416 EndChild();
417
418 if (Button(ICON_MD_DONE)) {
419 set_done = true;
420 ImGui::CloseCurrentPopup();
421 }
422 SameLine();
423 if (Button(ICON_MD_CLOSE)) {
424 ImGui::CloseCurrentPopup();
425 }
426 SameLine();
427 if (Button(ICON_MD_DELETE)) {
428 item.deleted = true;
429 set_done = true;
430 ImGui::CloseCurrentPopup();
431 }
432
433 ImGui::EndPopup();
434 }
435 return set_done;
436}
437
438const ImGuiTableSortSpecs* SpriteItem::s_current_sort_specs = nullptr;
439
440void DrawSpriteTable(std::function<void(int)> onSpriteSelect,
441 int& selected_id) {
442 static ImGuiTextFilter filter;
443 static std::vector<SpriteItem> items;
444
445 // Initialize items if empty
446 if (items.empty()) {
447 for (int i = 0; i < 256; ++i) {
448 items.push_back(SpriteItem{i, zelda3::kSpriteDefaultNames[i].data()});
449 }
450 }
451
452 filter.Draw("Filter", 180);
453
454 if (ImGui::BeginTable("##sprites", 2,
455 ImGuiTableFlags_Sortable | ImGuiTableFlags_Resizable)) {
456 ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_DefaultSort, 0.0f,
458 ImGui::TableSetupColumn("Name", 0, 0.0f, SpriteItemColumnID_Name);
459 ImGui::TableHeadersRow();
460
461 // Handle sorting
462 if (ImGuiTableSortSpecs* sort_specs = ImGui::TableGetSortSpecs()) {
463 if (sort_specs->SpecsDirty) {
464 SpriteItem::SortWithSortSpecs(sort_specs, items);
465 sort_specs->SpecsDirty = false;
466 }
467 }
468
469 // Display filtered and sorted items
470 for (const auto& item : items) {
471 if (filter.PassFilter(item.name)) {
472 ImGui::TableNextRow();
473 ImGui::TableSetColumnIndex(0);
474 Text("%d", item.id);
475 ImGui::TableSetColumnIndex(1);
476
477 if (Selectable(item.name, selected_id == item.id,
478 ImGuiSelectableFlags_SpanAllColumns)) {
479 selected_id = item.id;
480 onSpriteSelect(item.id);
481 }
482 }
483 }
484 ImGui::EndTable();
485 }
486}
487
489 if (ImGui::BeginPopup("Sprite Inserter")) {
490 static int new_sprite_id = 0;
491 static int x_pos = 0;
492 static int y_pos = 0;
493
494 if (ImGui::IsWindowAppearing()) {
495 new_sprite_id = 0;
496 x_pos = 0;
497 y_pos = 0;
498 }
499
500 ImGui::Text(tr("Add New Sprite"));
501 ImGui::Separator();
502
503 BeginChild("ScrollRegion", ImVec2(250, 200), true,
504 ImGuiWindowFlags_AlwaysVerticalScrollbar);
505 DrawSpriteTable([](int selected_id) { new_sprite_id = selected_id; },
506 new_sprite_id);
507 EndChild();
508
509 ImGui::Separator();
510 ImGui::Text(tr("Position:"));
511 gui::InputHex("X Position", &x_pos);
512 gui::InputHex("Y Position", &y_pos);
513
514 if (Button(tr("Add Sprite"))) {
515 // This would need to be connected to the overworld editor to actually
516 // create the sprite
517 new_sprite_id = 0;
518 x_pos = 0;
519 y_pos = 0;
520 ImGui::CloseCurrentPopup();
521 }
522 SameLine();
523
524 if (Button(tr("Cancel"))) {
525 ImGui::CloseCurrentPopup();
526 }
527
528 ImGui::EndPopup();
529 }
530}
531
533 static bool set_done = false;
534 if (set_done) {
535 set_done = false;
536 return true;
537 }
538 if (ImGui::BeginPopupModal(
540 .c_str(),
541 NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
542 static int selected_id = 0;
543 if (ImGui::IsWindowAppearing()) {
544 selected_id = sprite.id();
545 }
546
547 BeginChild("ScrollRegion", ImVec2(350, 350), true,
548 ImGuiWindowFlags_AlwaysVerticalScrollbar);
549 ImGui::BeginGroup();
550 Text("%s", sprite.name().c_str());
551
553 [&sprite](int id) {
554 sprite.set_id(id);
555 sprite.UpdateMapProperties(sprite.map_id(), nullptr);
556 },
557 selected_id);
558 ImGui::EndGroup();
559 EndChild();
560
561 if (Button(ICON_MD_DONE)) {
562 set_done = true; // FIX: Save changes when Done is clicked
563 ImGui::CloseCurrentPopup();
564 }
565 SameLine();
566 if (Button(ICON_MD_CLOSE)) {
567 // FIX: Discard changes - don't set set_done
568 ImGui::CloseCurrentPopup();
569 }
570 SameLine();
571 if (Button(ICON_MD_DELETE)) {
572 sprite.set_deleted(true);
573 set_done = true; // FIX: Save deletion when Delete is clicked
574 ImGui::CloseCurrentPopup();
575 }
576
577 ImGui::EndPopup();
578 }
579 return set_done;
580}
581
583 zelda3::DiggableTiles* diggable_tiles,
584 const std::vector<gfx::Tile16>& tiles16,
585 const std::array<uint8_t, 0x200>& all_tiles_types) {
586 static bool set_done = false;
587 if (set_done) {
588 set_done = false;
589 return true;
590 }
591
592 if (ImGui::BeginPopupModal(gui::MakePopupId(gui::EditorNames::kOverworld,
593 "Diggable Tiles Editor")
594 .c_str(),
595 NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
596 static ImGuiTextFilter filter;
597 static int patch_mode = 0; // 0=Vanilla, 1=ZS Compatible, 2=Custom
598 static zelda3::DiggableTilesPatchConfig patch_config;
599 static std::string export_message;
600
601 // Stats header
602 int diggable_count = diggable_tiles->GetDiggableCount();
603 Text(tr("Diggable Tiles: %d / 512"), diggable_count);
604 ImGui::Separator();
605
606 // Filter
607 filter.Draw("Filter by Tile ID", 200);
608 SameLine();
609 if (Button(tr("Clear Filter"))) {
610 filter.Clear();
611 }
612
613 // Scrollable tile list
614 BeginChild("TileList", ImVec2(400, 300), true,
615 ImGuiWindowFlags_AlwaysVerticalScrollbar);
616
617 // Display tiles in a grid-like format
618 int cols = 8;
619 int col = 0;
620 for (uint16_t tile_id = 0;
621 tile_id < zelda3::kMaxDiggableTileId && tile_id < tiles16.size();
622 ++tile_id) {
623 char id_str[16];
624 snprintf(id_str, sizeof(id_str), "$%03X", tile_id);
625
626 if (!filter.PassFilter(id_str)) {
627 continue;
628 }
629
630 bool is_diggable = diggable_tiles->IsDiggable(tile_id);
631 bool would_be_diggable = zelda3::DiggableTiles::IsTile16Diggable(
632 tiles16[tile_id], all_tiles_types);
633
634 // Color coding: green if auto-detected, yellow if manually set
635 std::optional<gui::StyleColorGuard> dig_color;
636 if (is_diggable) {
637 if (would_be_diggable) {
638 dig_color.emplace(ImGuiCol_Text, ImVec4(0.2f, 0.8f, 0.2f, 1.0f));
639 } else {
640 dig_color.emplace(ImGuiCol_Text, ImVec4(0.8f, 0.8f, 0.2f, 1.0f));
641 }
642 }
643
644 if (Checkbox(id_str, &is_diggable)) {
645 diggable_tiles->SetDiggable(tile_id, is_diggable);
646 }
647
648 dig_color.reset();
649
650 if (ImGui::IsItemHovered()) {
651 ImGui::SetTooltip(tr("Tile $%03X - %s"), tile_id,
652 would_be_diggable ? "Auto-detected as diggable"
653 : "Manually configured");
654 }
655
656 col++;
657 if (col < cols) {
658 SameLine();
659 } else {
660 col = 0;
661 }
662 }
663
664 EndChild();
665
666 ImGui::Separator();
667
668 // Action buttons
669 if (Button(ICON_MD_AUTO_FIX_HIGH " Auto-Detect")) {
670 diggable_tiles->Clear();
671 for (uint16_t tile_id = 0;
672 tile_id < zelda3::kMaxDiggableTileId && tile_id < tiles16.size();
673 ++tile_id) {
674 if (zelda3::DiggableTiles::IsTile16Diggable(tiles16[tile_id],
675 all_tiles_types)) {
676 diggable_tiles->SetDiggable(tile_id, true);
677 }
678 }
679 }
680 if (ImGui::IsItemHovered()) {
681 ImGui::SetTooltip(
682 tr("Set diggable status based on tile types.\n"
683 "A tile is diggable if all 4 component tiles\n"
684 "have type 0x48 or 0x4A (diggable ground)."));
685 }
686
687 SameLine();
688 if (Button(ICON_MD_RESTART_ALT " Vanilla Defaults")) {
689 diggable_tiles->SetVanillaDefaults();
690 }
691 if (ImGui::IsItemHovered()) {
692 ImGui::SetTooltip(
693 tr("Reset to vanilla diggable tiles:\n$034, $035, $071, "
694 "$0DA, $0E1, $0E2, $0F8, $10D, $10E, $10F"));
695 }
696
697 SameLine();
698 if (Button(ICON_MD_CLEAR " Clear All")) {
699 diggable_tiles->Clear();
700 }
701
702 ImGui::Separator();
703
704 // Patch export section
705 if (ImGui::CollapsingHeader(tr("ASM Patch Export"))) {
706 ImGui::Indent();
707
708 Text(tr("Patch Mode:"));
709 ImGui::RadioButton(tr("Vanilla"), &patch_mode, 0);
710 SameLine();
711 ImGui::RadioButton(tr("ZS Compatible"), &patch_mode, 1);
712 SameLine();
713 ImGui::RadioButton(tr("Custom"), &patch_mode, 2);
714
715 patch_config.use_zs_compatible_mode = (patch_mode == 1);
716
717 if (patch_mode == 2) {
718 // Custom address inputs
719 static int hook_addr = patch_config.hook_address;
720 static int table_addr = patch_config.table_address;
721 static int freespace_addr = patch_config.freespace_address;
722
723 gui::InputHex("Hook Address", &hook_addr);
724 gui::InputHex("Table Address", &table_addr);
725 gui::InputHex("Freespace", &freespace_addr);
726
727 patch_config.hook_address = hook_addr;
728 patch_config.table_address = table_addr;
729 patch_config.freespace_address = freespace_addr;
730 }
731
732 if (Button(ICON_MD_FILE_DOWNLOAD " Export .asm Patch")) {
733 std::string patch_content = zelda3::DiggableTilesPatch::GeneratePatch(
734 *diggable_tiles, patch_config);
735 const std::string out_path = "diggable_tiles_patch.asm";
736 std::ofstream out(out_path, std::ios::trunc);
737 if (out.good()) {
738 out << patch_content;
739 out.close();
740 export_message = "Exported patch to " + out_path;
741 } else {
742 export_message = "Failed to write " + out_path;
743 }
744 }
745 if (!export_message.empty()) {
746 ImGui::TextWrapped("%s", export_message.c_str());
747 }
748
749 ImGui::Unindent();
750 }
751
752 ImGui::Separator();
753
754 // Save/Cancel buttons
755 if (Button(ICON_MD_DONE " Save")) {
756 set_done = true;
757 ImGui::CloseCurrentPopup();
758 }
759 SameLine();
760 if (Button(ICON_MD_CANCEL " Cancel")) {
761 ImGui::CloseCurrentPopup();
762 }
763
764 ImGui::EndPopup();
765 }
766
767 return set_done;
768}
769
770} // namespace editor
771} // namespace yaze
static std::string GeneratePatch(const DiggableTiles &diggable_tiles, const DiggableTilesPatchConfig &config={})
Generate ASM patch code for the diggable tiles table.
Manages diggable tile state as a 512-bit bitfield.
int GetDiggableCount() const
Get the count of tiles marked as diggable.
void SetVanillaDefaults()
Reset to vanilla diggable tiles.
void SetDiggable(uint16_t tile_id, bool diggable)
Set or clear the diggable bit for a Map16 tile ID.
static bool IsTile16Diggable(const gfx::Tile16 &tile16, const std::array< uint8_t, 0x200 > &all_tiles_types)
Check if a Tile16 should be diggable based on its component tiles.
bool IsDiggable(uint16_t tile_id) const
Check if a Map16 tile ID is marked as diggable.
void Clear()
Clear all diggable bits.
Base class for all overworld and dungeon entities.
Definition common.h:31
enum yaze::zelda3::GameEntity::EntityType entity_type_
auto set_x(int x)
Definition common.h:62
auto set_y(int y)
Definition common.h:63
Represents an overworld exit that transitions from dungeon to overworld.
void UpdateMapProperties(uint16_t room_map_id, const void *context=nullptr) override
Update entity properties based on map position.
A class for managing sprites in the overworld and underworld.
Definition sprite.h:39
auto id() const
Definition sprite.h:107
auto name() const
Definition sprite.h:131
void UpdateMapProperties(uint16_t map_id, const void *context=nullptr) override
Update entity properties based on map position.
Definition sprite.cc:328
auto map_id() const
Definition sprite.h:113
auto set_id(uint8_t id)
Definition sprite.h:108
auto set_deleted(bool deleted)
Definition sprite.h:133
#define ICON_MD_CANCEL
Definition icons.h:364
#define ICON_MD_FILE_DOWNLOAD
Definition icons.h:744
#define ICON_MD_AUTO_FIX_HIGH
Definition icons.h:218
#define ICON_MD_CLEAR
Definition icons.h:416
#define ICON_MD_DONE
Definition icons.h:607
#define ICON_MD_DELETE
Definition icons.h:530
#define ICON_MD_CLOSE
Definition icons.h:418
#define ICON_MD_RESTART_ALT
Definition icons.h:1602
void DrawExitInserterPopup()
Definition entity.cc:163
bool DrawSpriteEditorPopup(zelda3::Sprite &sprite)
Definition entity.cc:532
void DrawItemInsertPopup()
Definition entity.cc:371
bool DrawEntranceInserterPopup()
Definition entity.cc:91
void DrawSpriteInserterPopup()
Definition entity.cc:488
void DrawSpriteTable(std::function< void(int)> onSpriteSelect, int &selected_id)
Definition entity.cc:440
bool DrawOverworldEntrancePopup(zelda3::OverworldEntrance &entrance)
Definition entity.cc:119
bool DrawItemEditorPopup(zelda3::OverworldItem &item)
Definition entity.cc:400
bool DrawDiggableTilesEditorPopup(zelda3::DiggableTiles *diggable_tiles, const std::vector< gfx::Tile16 > &tiles16, const std::array< uint8_t, 0x200 > &all_tiles_types)
Draw popup dialog for editing diggable tiles configuration.
Definition entity.cc:582
void MoveEntityOnGrid(zelda3::GameEntity *entity, ImVec2 canvas_p0, ImVec2 scrolling, bool free_movement, float scale)
Move entity to grid-aligned position based on mouse.
Definition entity.cc:66
constexpr float kInputFieldSize
Definition entity.cc:28
@ SpriteItemColumnID_ID
Definition entity.h:69
@ SpriteItemColumnID_Name
Definition entity.h:70
bool DrawExitEditorPopup(zelda3::OverworldExit &exit)
Definition entity.cc:200
bool IsMouseHoveringOverEntity(const zelda3::GameEntity &entity, ImVec2 canvas_p0, ImVec2 scrolling, float scale)
Check if mouse is hovering over an entity.
Definition entity.cc:30
constexpr const char * kOverworld
Definition popup_id.h:53
bool InputHexWord(const char *label, uint16_t *data, float input_width, bool no_step)
Definition input.cc:462
bool InputHex(const char *label, uint64_t *data)
Definition input.cc:438
std::string MakePopupId(size_t session_id, const std::string &editor_name, const std::string &popup_name)
Generate session-aware popup IDs to prevent conflicts in multi-editor layouts.
Definition popup_id.h:23
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:483
void TextWithSeparators(const absl::string_view &text)
Definition style.cc:828
const std::vector< std::string > kSecretItemNames
const std::string kSpriteDefaultNames[256]
Definition sprite.cc:16
constexpr int kMaxDiggableTileId
static const ImGuiTableSortSpecs * s_current_sort_specs
Definition entity.h:77
static void SortWithSortSpecs(ImGuiTableSortSpecs *sort_specs, std::vector< SpriteItem > &items)
Definition entity.h:79
Configuration for diggable tiles ASM patch generation.