yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
sprite_editor.cc
Go to the documentation of this file.
1#include "sprite_editor.h"
2#include "util/i18n/tr.h"
3
4#include <algorithm>
5#include <cerrno>
6#include <cstdio>
7#include <cstdlib>
8#include <cstring>
9#include <filesystem>
10
11#include "absl/cleanup/cleanup.h"
12#include "absl/strings/str_format.h"
27#include "app/gui/core/icons.h"
28#include "app/gui/core/input.h"
33#include "core/project.h"
34#include "util/file_util.h"
35#include "util/hex.h"
36#include "util/macro.h"
37#include "zelda3/dungeon/room.h"
38#include "zelda3/game_data.h"
40
41namespace yaze {
42namespace editor {
43
44using ImGui::BeginTable;
45using ImGui::Button;
46using ImGui::EndTable;
47using ImGui::Selectable;
48using ImGui::Separator;
49using ImGui::TableHeadersRow;
50using ImGui::TableNextColumn;
51using ImGui::TableNextRow;
52using ImGui::TableSetupColumn;
53using ImGui::Text;
54
55namespace {
56template <size_t N>
57void CopyStringToBuffer(const std::string& src, char (&dest)[N]) {
58 std::strncpy(dest, src.c_str(), N - 1);
59 dest[N - 1] = '\0';
60}
61
62int ParseIntOrDefault(const std::string& text, int fallback = 0) {
63 if (text.empty()) {
64 return fallback;
65 }
66 errno = 0;
67 char* end = nullptr;
68 long value = std::strtol(text.c_str(), &end, 0);
69 if (end == text.c_str() || errno == ERANGE) {
70 return fallback;
71 }
72 return static_cast<int>(value);
73}
74} // namespace
75
78 return;
79 auto* window_manager = dependencies_.window_manager;
80
81 // Register WindowContent implementations with callbacks
82 // EditorPanels provide both metadata (icon, name, priority) and drawing logic
83 window_manager->RegisterWindowContent(
84 std::make_unique<VanillaSpriteEditorPanel>([this]() {
86 if (rom_ && rom_->is_loaded()) {
88 } else {
89 ImGui::TextDisabled(tr("Load a ROM to view vanilla sprites"));
90 }
91 }));
92
93 window_manager->RegisterWindowContent(
94 std::make_unique<CustomSpriteEditorPanel>([this]() {
97 }));
98 window_manager->RegisterWindowContent(
99 std::make_unique<SpriteCatalogPanel>([this]() { DrawSpriteCatalog(); }));
100}
101
102absl::Status SpriteEditor::Load() {
103 gfx::ScopedTimer timer("SpriteEditor::Load");
105 gfx_buffer_loaded_ = false;
108 room_palette_cache_.reset();
109 if (sheets_loaded_) {
110 const auto slots = zelda3::SpriteSheetSlots(
111 game_data()->spriteset_ids[preview_spriteset_],
113 std::copy(slots.begin(), slots.end(), vanilla_sheets_);
115 std::copy(slots.begin(), slots.end(), current_sheets_);
116 }
118 (void)ReloadSpriteCatalog();
120 return absl::OkStatus();
121}
122
123absl::Status SpriteEditor::Update() {
124 if (rom() && rom()->is_loaded() && !sheets_loaded_) {
125 sheets_loaded_ = true;
126 }
127
128 // Update animation playback for custom sprites
129 float current_time = ImGui::GetTime();
130 float delta_time = current_time - last_frame_time_;
131 last_frame_time_ = current_time;
132 UpdateAnimationPlayback(delta_time);
133
134 // Handle editor-level shortcuts
136
137 // Panel drawing is handled by WorkspaceWindowManager via registered EditorPanels
138 // Each panel's Draw() callback invokes the appropriate draw method
139
140 // Commit any pending undo transaction at the end of the frame
142
143 return status_.ok() ? absl::OkStatus() : status_;
144}
145
147 // These keys are editor-wide, so they act only while one of this editor's
148 // panels has focus and no text field is taking input.
149 const bool panel_focused = shortcut_focus_;
150 shortcut_focus_ = false;
151 const ImGuiIO& io = ImGui::GetIO();
152 if (!panel_focused || io.WantTextInput) {
153 return;
154 }
155
156 // Animation playback
157 if (ImGui::IsKeyPressed(ImGuiKey_Space, false)) {
159 }
160
161 // Frame navigation
162 const bool bare_keys = !io.KeyCtrl && !io.KeyAlt && !io.KeySuper;
163 if (const auto* sprite = current_custom_sprite(); sprite && bare_keys) {
164 const int frame_count = static_cast<int>(sprite->editor.Frames.size());
165 int step = 0;
166 if (ImGui::IsKeyPressed(ImGuiKey_LeftBracket, false)) {
167 step = -1;
168 } else if (ImGui::IsKeyPressed(ImGuiKey_RightBracket, false)) {
169 step = 1;
170 }
171 const int next =
172 internal::StepFrameIndex(current_frame_, step, frame_count);
173 if (step != 0 && next != current_frame_) {
174 current_frame_ = next;
176 }
177 }
178
179 // Sprite navigation
180 if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_UpArrow, false)) {
181 if (current_sprite_id_ > 0) {
183 }
184 }
185 if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_DownArrow, false)) {
187 }
188}
189
191 // Inspect every pending document before Save can write any named asset.
192 for (const int index : dirty_sprite_indices_) {
193 if (index < 0 || index >= static_cast<int>(custom_sprite_paths_.size()) ||
194 custom_sprite_paths_[index].empty()) {
195 return absl::FailedPreconditionError(
196 "Autosave paused: untitled sprite assets are retained; use Sprite "
197 "Save As to choose their destinations");
198 }
199 }
200 return Save();
201}
202
203absl::Status SpriteEditor::Save() {
204 if (!dirty_sprite_indices_.empty()) {
206 const int selected = current_custom_sprite_index_;
207 const int frame = current_frame_;
208 absl::Cleanup restore = [this, selected, frame] {
210 current_frame_ = frame;
212 };
213 const auto pending = dirty_sprite_indices_;
214 for (const int index : pending) {
216 current_frame_ = 0;
217 const auto path = GetCurrentZsmPath();
218 if (path.empty())
220 else
221 SaveZsmFile(path);
222 if (!status_.ok())
223 return status_;
224 if (dirty_sprite_indices_.count(index))
225 return absl::CancelledError("Sprite Save As was cancelled");
226 }
227 return absl::OkStatus();
228 }
229 return absl::OkStatus();
230}
231
233 // Sidebar handled by EditorManager for card-based editors
234}
235
236// ============================================================
237// Vanilla Sprite Editor
238// ============================================================
239
241 if (sprite_id < 0 || sprite_id >= 256)
242 return;
243 current_sprite_id_ = sprite_id;
245 pending_sprite_tab_ = sprite_id;
246 if (!active_sprites_.contains(sprite_id))
247 active_sprites_.push_back(sprite_id);
248}
249
251 const auto id = static_cast<uint8_t>(current_sprite_id_);
253 id, project() ? project()->hack_manifest.hack_name() : "");
254 return override ? override : zelda3::SpriteOamRegistry::GetLayout(id);
255}
256
258 gui::AutoWidgetScope sprite_scope("Sprite/Vanilla");
259 if (ImGui::BeginTable("##SpriteCanvasTable", 3, ImGuiTableFlags_Resizable,
260 ImVec2(0, 0))) {
261 TableSetupColumn("Sprites List", ImGuiTableColumnFlags_WidthFixed, 256);
262 TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch,
263 ImGui::GetContentRegionAvail().x);
264 TableSetupColumn("Tile Selector", ImGuiTableColumnFlags_WidthFixed, 256);
265 TableHeadersRow();
266 TableNextRow();
267
268 TableNextColumn();
270
271 TableNextColumn();
272 if (active_sprites_.empty()) {
273 ImGui::TextWrapped("Select a sprite from the list to open its preview.");
274 }
275 if (gui::BeginThemedTabBar("SpriteTabBar", kSpriteTabBarFlags)) {
276 if (ImGui::TabItemButton(ICON_MD_ADD, kSpriteTabFlags)) {
278 }
279
280 for (int n = 0; n < active_sprites_.Size;) {
281 bool open = true;
282
283 const int sprite_id = active_sprites_[n];
284 if (sprite_id < 0 || sprite_id >= 256) {
285 active_sprites_.erase(active_sprites_.Data + n);
286 continue;
287 }
288
289 const auto label =
290 absl::StrFormat("%02X %s###SpriteTab%02X", sprite_id,
291 zelda3::kSpriteDefaultNames[sprite_id], sprite_id);
292 const auto flags = pending_sprite_tab_ == sprite_id
293 ? ImGuiTabItemFlags_SetSelected
294 : ImGuiTabItemFlags_None;
295 const bool selected = ImGui::BeginTabItem(label.c_str(), &open, flags);
297 absl::StrFormat("SpriteTab%02X", sprite_id));
298 if (selected) {
299 if (current_sprite_id_ != sprite_id) {
300 current_sprite_id_ = sprite_id;
302 }
304 ImGui::EndTabItem();
305 }
306
307 if (!open)
308 active_sprites_.erase(active_sprites_.Data + n);
309 else
310 n++;
311 }
312
315 }
316
317 TableNextColumn();
318 if (sheets_loaded_) {
319 DrawCurrentSheets(false);
320 }
321 ImGui::EndTable();
322 }
323}
324
326 if (ImGui::BeginChild(gui::GetID("##SpriteCanvas"),
327 ImGui::GetContentRegionAvail(), true)) {
330
331 // Static layouts are preview references, not a complete game renderer.
332 const auto* layout = CurrentPreviewLayout();
333 ImGui::SetCursorPos(ImVec2(10, 10));
334 ImGui::TextColored(gui::GetWarningColor(), "Experimental static preview");
335 if (!layout) {
336 ImGui::TextWrapped(
337 "No static OAM layout for sprite $%02X. Open or import a ZSM in "
338 "Custom Sprites to preview authored frames.",
340 } else if (layout->graphics_resource) {
341 ImGui::TextWrapped(
342 "%s ($%02X) requires external graphics (%s). This editor does not "
343 "yet preview that graphics source.",
344 layout->name, layout->sprite_id, layout->graphics_resource);
345 } else {
346 RenderVanillaSprite(*layout);
348 const auto& error = !graphics_binding_status_.ok()
351 ImGui::TextWrapped("Preview unavailable: %s",
352 std::string(error.message()).c_str());
353 } else {
356 Text(tr("Sprite: %s (0x%02X)"), layout->name, layout->sprite_id);
357 Text(tr("Tiles: %zu"), layout->tiles.size());
358 if (std::none_of(vanilla_preview_bitmap_.vector().begin(),
360 [](uint8_t pixel) { return (pixel & 0x0F) != 0; })) {
361 ImGui::TextWrapped(
362 "The selected sheets contain no visible pixels for this layout. "
363 "Choose the sprite's spriteset or graphics sheets.");
364 }
365 }
366 ImGui::TextWrapped(
367 "Uses the selected sheets and palette. Animation, behavior, and "
368 "runtime graphics changes are not simulated.");
369 }
370
371 if (ImGui::Button(layout ? tr("Edit preview copy")
372 : tr("Create empty sprite template")))
374 ImGui::TextWrapped(
375 layout
376 ? "Creates a detached static pose. Bind any external graphics "
377 "in Custom Sprites > Graphics sources."
378 : "This ID has no decoded static layout. The template starts "
379 "with an empty frame for authoring; game OAM is not imported.");
380
383 }
384 ImGui::EndChild();
385}
386
388 bool use_asset_binding) {
389 if (game_data() == nullptr || spriteset < 0 ||
390 spriteset >= static_cast<int>(zelda3::kNumSpritesets)) {
391 return;
392 }
393 const auto slots =
394 zelda3::SpriteSheetSlots(game_data()->spriteset_ids[spriteset],
396 if (use_asset_binding && current_custom_sprite())
398 std::copy(slots.begin(), slots.end(),
399 use_asset_binding ? current_sheets_ : vanilla_sheets_);
400 gfx_buffer_loaded_ = false;
402 if (use_asset_binding && current_custom_sprite()) {
404 std::copy(slots.begin(), slots.end(), binding.sheets.begin());
406 }
408}
409
411 const auto* sprite = current_custom_sprite();
412 if (!sprite || current_frame_ < 0 ||
413 current_frame_ >= static_cast<int>(sprite->editor.Frames.size())) {
414 return absl::FailedPreconditionError("Select a sprite frame");
415 }
416 if (!rom_ || !rom_->is_loaded() || !game_data()) {
417 return absl::FailedPreconditionError(
418 "Load a ROM before editing sprite pixels");
419 }
420 if (const auto* binding = current_sprite_binding();
421 binding &&
422 std::any_of(binding->graphics_sources.begin(),
423 binding->graphics_sources.end(),
424 [](const auto& source) { return source.kind != "sheet"; }))
425 return absl::FailedPreconditionError(
426 "This asset uses BIN or raw ROM graphics. Edit BIN pixels in Graphics "
427 "Scratch, export the BIN, then Reload graphics sources here. Raw ROM "
428 "bindings are read-only preview ranges.");
432 if (!graphics_binding_status_.ok())
434 if (!palette_binding_status_.ok())
436 std::array<uint8_t, 8> slots;
437 std::copy_n(current_sheets_, 8, slots.begin());
438 const auto frame = sprite->editor.Frames[current_frame_];
439 const auto palettes = sprite_palettes_;
440 const std::string source =
442 ? absl::StrFormat("room %03X CGRAM rows 8-15; sprite slots %02X",
445 ? absl::StrFormat(
446 "sprite asset binding; preview spriteset %02X",
448 : absl::StrFormat("preview spriteset %02X",
451 frame, current_frame_, selected_tile_index_, slots, palettes, game_data(),
452 sprite->sprName, source);
453 if (!context.ok())
454 return context.status();
455 const auto* owner = game_data();
456 context->render_preview = [frame, slots, palettes, owner]() {
457 return sprite_graphics_context::RenderCapturedFrame(frame, slots, palettes,
458 owner);
459 };
460 auto* manager = static_cast<EditorManager*>(dependencies_.custom_data);
461 if (!manager)
462 return absl::FailedPreconditionError("Editor manager unavailable");
463 const int sprite_index = current_custom_sprite_index_;
464 const int frame_index = current_frame_;
465 const int tile_index = selected_tile_index_;
466 context->return_to_source = [this, manager, sprite_index, frame_index,
467 tile_index]() {
468 if (sprite_index >= 0 &&
469 sprite_index < static_cast<int>(custom_sprites_.size())) {
470 current_custom_sprite_index_ = sprite_index;
471 if (frame_index <
472 static_cast<int>(
473 custom_sprites_[sprite_index].editor.Frames.size())) {
474 current_frame_ = frame_index;
475 selected_tile_index_ = tile_index;
476 }
478 gfx_buffer_loaded_ = false;
479 }
480 manager->SwitchToEditor(EditorType::kSprite, true);
481 };
482 auto* editor_set = manager->GetCurrentEditorSet();
483 if (!editor_set || !editor_set->GetGraphicsEditor()) {
484 return absl::FailedPreconditionError("Graphics editor unavailable");
485 }
486 auto status = manager->EnsureEditorAssetsLoaded(EditorType::kGraphics);
487 if (!status.ok())
488 return status;
489 status = editor_set->GetGraphicsEditor()->OpenInContext(std::move(*context));
490 if (!status.ok())
491 return status;
492 manager->SwitchToEditor(EditorType::kGraphics, true);
493 return absl::OkStatus();
494}
495
496void SpriteEditor::DrawSpritesetPicker(bool use_asset_binding) {
497 if (!ImGui::CollapsingHeader(tr("Spriteset preview"),
498 ImGuiTreeNodeFlags_DefaultOpen)) {
499 return;
500 }
501 if (game_data() == nullptr || rom_ == nullptr || !rom_->is_loaded()) {
502 ImGui::TextDisabled(tr("Load a ROM to preview against spritesets."));
503 return;
504 }
505 if (usage_rom_ != rom_ || !usage_areas_.has_value()) {
509 }
510
511 uint8_t set = static_cast<uint8_t>(preview_spriteset_);
512 if (gui::InputHexByte("Spriteset", &set,
513 static_cast<uint8_t>(zelda3::kNumSpritesets - 1))) {
514 preview_spriteset_ = std::min<int>(set, zelda3::kNumSpritesets - 1);
515 }
516 ImGui::SameLine();
517 if (ImGui::Button(ICON_MD_DONE " Apply to sheets")) {
518 ApplySpritesetToSheets(preview_spriteset_, use_asset_binding);
519 }
521 "Slots 0-3 take the static sprite sheets, slots 4-7 this spriteset's "
522 "values + 0x73 (OAM tiles 0x100-0x1FF).");
523
524 const auto& values = game_data()->spriteset_ids[preview_spriteset_];
525 const auto slots = zelda3::SpriteSheetSlots(
527 ImGui::TextDisabled(
528 "Values %02X %02X %02X %02X -> sheets %02X %02X %02X %02X", values[0],
529 values[1], values[2], values[3], slots[4], slots[5], slots[6], slots[7]);
530
533 auto hex_list = [](const std::vector<int>& ids) {
534 if (ids.empty()) {
535 return std::string("-");
536 }
537 std::string out;
538 for (size_t i = 0; i < ids.size() && i < 24; ++i) {
539 out += absl::StrFormat("%s%02X", i == 0 ? "" : " ", ids[i]);
540 }
541 if (ids.size() > 24) {
542 out += absl::StrFormat(" (+%zu)", ids.size() - 24);
543 }
544 return out;
545 };
546 for (int state = 0; state < 3; ++state) {
547 ImGui::TextWrapped("OW areas, state %d: %s", state,
548 hex_list(usage.ow_areas_by_state[state]).c_str());
549 }
550 ImGui::TextWrapped("Rooms: %s", hex_list(usage.rooms).c_str());
551
552 // Room context: its header picks the spriteset and the CGRAM palette.
553 ImGui::SetNextItemWidth(gui::LayoutHelpers::GetHexInputWidth() * 1.5f);
554 ImGui::InputScalar("Room", ImGuiDataType_U16, &preview_room_, nullptr,
555 nullptr, "%03X", ImGuiInputTextFlags_CharsHexadecimal);
557 std::min<uint16_t>(preview_room_, zelda3::kNumDungeonRooms - 1);
558 ImGui::SameLine();
559 if (ImGui::Button(ICON_MD_MEETING_ROOM " Use room")) {
560 if (auto room = usage_rooms_->find(preview_room_);
561 room != usage_rooms_->end()) {
563 std::min<int>(room->second.spriteset + zelda3::kDungeonSpritesetBase,
565 ApplySpritesetToSheets(preview_spriteset_, use_asset_binding);
567 room_palette_cache_.reset();
568 gfx_buffer_loaded_ = false;
569 }
570 }
571 HOVER_HINT("Use the room's header spriteset (+0x40) and its sprite palette");
572 if (ImGui::Checkbox(tr("Room palette (CGRAM rows 8-15)"),
574 room_palette_cache_.reset();
575 gfx_buffer_loaded_ = false;
577 }
579 "Off: palette rows from the sprite binding (Sprite Asset panel). On: "
580 "the rows the game loads for the room above.");
581
582 if (use_asset_binding)
584 ImGui::Separator();
585}
586
588 const auto* sprite = current_custom_sprite();
589 if (sprite == nullptr || current_frame_ < 0 ||
590 current_frame_ >= static_cast<int>(sprite->editor.Frames.size())) {
591 return;
592 }
593 auto tiles = internal::FrameTiles8x8(sprite->editor.Frames[current_frame_]);
594 if (const auto* binding = current_sprite_binding()) {
595 const auto before = tiles.size();
596 tiles.erase(
597 std::remove_if(tiles.begin(), tiles.end(),
598 [&](int tile) {
599 const int slot = zelda3::SpriteSlotForTile(tile);
600 return slot >= 0 && slot < 8 &&
601 binding->graphics_sources[slot].kind != "sheet";
602 }),
603 tiles.end());
604 if (tiles.size() != before)
605 ImGui::TextWrapped(
606 "%zu tiles use BIN/raw ROM sources; ROM sheet usage checks apply "
607 "only to the remaining tiles.",
608 before - tiles.size());
609 }
610 if (tiles.empty())
611 return;
612 std::array<uint8_t, 8> slots;
613 std::copy_n(current_sheets_, 8, slots.begin());
614 const auto options = core::BuildGfxSheetInventoryOptions(project());
615 std::string key =
616 absl::StrFormat("%d:%d:", current_custom_sprite_index_, current_frame_);
617 for (uint8_t sheet : slots) {
618 key += absl::StrFormat("%02X", sheet);
619 }
620 for (int tile : tiles) {
621 key += absl::StrFormat(",%X", tile);
622 }
623 for (uint16_t sheet : options.reserved_sheets) {
624 key += absl::StrFormat("r%X", sheet);
625 }
626 if (key != tile_check_key_) {
627 tile_check_key_ = key;
629 zelda3::CheckSpriteTiles(*rom_, tiles, slots, options.reserved_sheets);
630 tile_check_count_ = tiles.size();
631 }
632
633 if (tile_issues_.empty()) {
634 ImGui::TextColored(gui::GetSuccessColor(),
635 ICON_MD_CHECK " Frame %d: all %zu 8x8 tiles have art",
637 return;
638 }
639 ImGui::TextColored(gui::GetWarningColor(),
641 " Frame %d: %zu of %zu 8x8 tiles need "
642 "attention",
644 for (size_t i = 0; i < tile_issues_.size() && i < 8; ++i) {
645 const auto& issue = tile_issues_[i];
646 const char* what =
648 ? "blank"
650 ? "reserved sheet"
651 : "sheet unreadable");
652 ImGui::BulletText("tile 0x%03X, slot %d (sheet 0x%02X): %s", issue.tile,
653 issue.slot, issue.sheet, what);
654 }
655 if (tile_issues_.size() > 8) {
656 ImGui::TextDisabled("... %zu more", tile_issues_.size() - 8);
657 }
658}
659
660void SpriteEditor::DrawCurrentSheets(bool use_asset_binding) {
661 if (ImGui::BeginChild(gui::GetID("sheet_label"),
662 ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
663 ImGuiWindowFlags_NoDecoration)) {
664 DrawSpritesetPicker(use_asset_binding);
665 auto* sheets = use_asset_binding ? current_sheets_ : vanilla_sheets_;
666 // Track previous sheet values for change detection
667 bool sheets_changed = false;
668 if (use_asset_binding && current_custom_sprite())
670
671 for (int i = 0; i < 8; i++) {
672 std::string sheet_label = absl::StrFormat("Sheet %d", i);
673 if (gui::InputHexByte(sheet_label.c_str(), &sheets[i])) {
674 sheets_changed = true;
675 }
676 if (i % 2 == 0)
677 ImGui::SameLine();
678 }
679
680 // Reload graphics buffer if sheets changed
681 if (sheets_changed) {
682 gfx_buffer_loaded_ = false;
684 if (use_asset_binding && current_custom_sprite()) {
686 std::copy_n(current_sheets_, 8, binding.sheets.begin());
688 }
689 }
691
696 for (int i = 0; i < 8; i++) {
697 const auto* binding =
698 use_asset_binding ? current_sprite_binding() : nullptr;
699 if (binding && binding->graphics_sources[i].kind != "sheet") {
701 auto& sheet = external_sheet_previews_[i];
702 const std::vector<uint8_t> pixels(
703 sprite_gfx_buffer_.begin() + i * 4096,
704 sprite_gfx_buffer_.begin() + (i + 1) * 4096);
705 const bool create = !sheet.is_active();
706 bool palette_changed = false;
707 if (!sprite_palettes_.empty()) {
708 const auto& palette = sprite_palettes_.palette_ref(0);
709 palette_changed = sheet.palette().size() != palette.size();
710 if (!palette_changed)
711 for (size_t color = 0; color < palette.size(); ++color)
712 palette_changed |=
713 sheet.palette()[color].snes() != palette[color].snes();
714 }
715 if (create || sheet.vector() != pixels || palette_changed) {
716 if (create)
717 sheet.Create(128, 32, 8, pixels);
718 else
719 sheet.set_data(pixels);
720 if (!sprite_palettes_.empty())
721 sheet.SetPalette(sprite_palettes_.palette_ref(0));
725 &sheet);
726 }
727 graphics_sheet_canvas_.DrawBitmap(sheet, 1, (i * 0x40) + 1, 2);
728 continue;
729 }
730 if (sheets[i] >= gfx::Arena::Get().gfx_sheets().size())
731 continue;
732 auto& sheet = gfx::Arena::Get().gfx_sheets().at(sheets[i]);
733 if (sheet.is_active() && !sheet.texture())
734 sheet.CreateTexture();
735 graphics_sheet_canvas_.DrawBitmap(sheet, 1, (i * 0x40) + 1, 2);
736 }
739 }
740 ImGui::EndChild();
741}
742
744 if (ImGui::BeginChild(gui::GetID("##SpritesList"),
745 ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
746 ImGuiWindowFlags_NoDecoration)) {
747 int i = 0;
748 for (const auto each_sprite_name : zelda3::kSpriteDefaultNames) {
750 current_sprite_id_ == i, "Sprite Names", util::HexByte(i),
752 if (ImGui::IsItemClicked()) {
754 }
755 i++;
756 }
757 }
758 ImGui::EndChild();
759}
760
761// ============================================================
762// Custom ZSM Sprite Editor
763// ============================================================
764
766 if (BeginTable("##CustomSpritesTable", 3,
767 ImGuiTableFlags_Resizable | ImGuiTableFlags_Borders,
768 ImVec2(0, 0))) {
769 TableSetupColumn("Sprite Data", ImGuiTableColumnFlags_WidthFixed, 300);
770 TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch);
771 TableSetupColumn("Tilesheets", ImGuiTableColumnFlags_WidthFixed, 280);
772
773 TableHeadersRow();
774 TableNextRow();
775 TableNextColumn();
776
777 // Keep the canvas visible while scrolling the longer authoring controls.
778 if (ImGui::BeginChild("##SpriteMetadata", ImVec2(0, 0)))
780 ImGui::EndChild();
781
782 TableNextColumn();
784
785 TableNextColumn();
786 DrawCurrentSheets(true);
787
788 EndTable();
789 }
790}
791
793 if (!asset_load_status_.ok())
794 ImGui::TextWrapped("%s", asset_load_status_.ToString().c_str());
795 // File operations toolbar
796 if (ImGui::Button(ICON_MD_ADD " New")) {
798 }
799 ImGui::SameLine();
800 if (ImGui::Button(ICON_MD_FOLDER_OPEN " Open")) {
801 std::string file_path = util::FileDialogWrapper::ShowOpenFileDialog();
802 if (!file_path.empty()) {
803 status_ = OpenSpriteAsset(file_path);
804 }
805 }
806 ImGui::SameLine();
807 if (ImGui::Button(ICON_MD_SAVE " Save")) {
809 const std::string& zsm_path = GetCurrentZsmPath();
810 if (zsm_path.empty()) {
812 } else {
813 SaveZsmFile(zsm_path);
814 }
815 }
816 }
817 ImGui::SameLine();
818 if (ImGui::Button(ICON_MD_SAVE_AS " Save As")) {
820 }
821
822 Separator();
823
824 // Sprite list
825 Text(tr("Loaded Sprites:"));
826 const float avail_y = std::max(0.0f, ImGui::GetContentRegionAvail().y);
827 const float metadata_reserve = std::min(160.0f, avail_y * 0.45f);
828 const float list_budget = std::max(0.0f, avail_y - metadata_reserve);
829 const float preferred_list = std::clamp(avail_y * 0.35f, 180.0f, 280.0f);
830 const float list_height = std::min(preferred_list, list_budget);
831 if (ImGui::BeginChild("SpriteList", ImVec2(0, list_height), true)) {
832 for (size_t i = 0; i < custom_sprites_.size(); i++) {
833 std::string label = custom_sprites_[i].sprName.empty()
834 ? "Unnamed Sprite"
835 : custom_sprites_[i].sprName;
836 ImGui::PushID(static_cast<int>(i));
837 if (Selectable(label.c_str(), current_custom_sprite_index_ == (int)i)) {
838 current_custom_sprite_index_ = static_cast<int>(i);
839 current_frame_ = custom_sprites_[i].editor.Frames.empty() ? -1 : 0;
841 custom_sprites_[i].animations.empty() ? -1 : 0;
844 animation_playing_ = false;
845 frame_timer_ = 0.0f;
849 }
850 ImGui::PopID();
851 }
852 }
853 ImGui::EndChild();
854
855 Separator();
856
857 // Show properties for selected sprite
862 if (gui::BeginThemedTabBar("SpriteDataTabs")) {
863 if (ImGui::BeginTabItem(tr("Properties"))) {
865 ImGui::EndTabItem();
866 }
867 if (ImGui::BeginTabItem(tr("Animations"))) {
869 ImGui::EndTabItem();
870 }
871 if (ImGui::BeginTabItem(tr("Behavior"))) {
873 ImGui::EndTabItem();
874 }
875 if (ImGui::BeginTabItem(tr("Routines"))) {
877 ImGui::EndTabItem();
878 }
880 }
881 } else {
882 Text(tr("No sprite selected"));
883 }
885}
886
887absl::Status SpriteEditor::Copy() {
889 current_custom_sprite_index_ >= static_cast<int>(custom_sprites_.size()))
890 return absl::FailedPreconditionError(
891 "Select a custom sprite frame to copy");
892 const auto& frames =
894 if (current_frame_ < 0 || current_frame_ >= static_cast<int>(frames.size()))
895 return absl::FailedPreconditionError("Select a frame to copy");
897 return absl::OkStatus();
898}
899
900absl::Status SpriteEditor::Cut() {
903 if (sprite.editor.Frames.size() <= 1)
904 return absl::FailedPreconditionError(
905 "Cannot cut the last frame; copied it instead");
909 static_cast<int>(sprite.editor.Frames.size()) - 1);
913 return absl::OkStatus();
914}
915
916absl::Status SpriteEditor::Paste() {
918 current_custom_sprite_index_ >= static_cast<int>(custom_sprites_.size()))
919 return absl::FailedPreconditionError(
920 "Copy a frame and select a destination sprite");
922 if (sprite.editor.Frames.size() >= sprite_authoring::kMaxFrames)
923 return absl::OutOfRangeError("ZSM animations address at most 256 frames");
925 sprite.editor.Frames.push_back(*frame_clipboard_);
926 current_frame_ = static_cast<int>(sprite.editor.Frames.size()) - 1;
930 return absl::OkStatus();
931}
932
935 zsprite::ZSprite new_sprite;
936 new_sprite.Reset();
937 new_sprite.sprName = "New Sprite";
938
939 // Add default frame
940 new_sprite.editor.Frames.emplace_back();
941
942 // Add default animation
943 new_sprite.animations.emplace_back(0, 0, 1, "Idle");
944
945 custom_sprites_.push_back(std::move(new_sprite));
946 custom_sprite_paths_.push_back(std::string());
948 std::copy_n(current_sheets_, 8, binding.sheets.begin());
949 custom_sprite_bindings_.push_back(std::move(binding));
950 source_checked_ = false;
951 current_custom_sprite_index_ = static_cast<int>(custom_sprites_.size()) - 1;
952 current_frame_ = 0;
956 animation_playing_ = false;
957 frame_timer_ = 0.0f;
958 zsm_dirty_ = true;
961}
962
963void SpriteEditor::LoadZsmFile(const std::string& path) {
964 zsprite::ZSprite sprite;
965 status_ = sprite.Load(path);
966 if (status_.ok()) {
967 custom_sprites_.push_back(std::move(sprite));
968 custom_sprite_paths_.push_back(path);
970 binding.zsm_path = path;
971 std::copy_n(current_sheets_, 8, binding.sheets.begin());
972 if (project()) {
973 for (const auto& saved : project()->sprite_assets) {
974 if (project()->GetAbsolutePath(saved.zsm_path) == path) {
975 binding = saved;
976 break;
977 }
978 }
979 }
980 custom_sprite_bindings_.push_back(std::move(binding));
981 current_custom_sprite_index_ = static_cast<int>(custom_sprites_.size()) - 1;
982 current_frame_ = custom_sprites_.back().editor.Frames.empty() ? -1 : 0;
984 custom_sprites_.back().animations.empty() ? -1 : 0;
987 animation_playing_ = false;
988 frame_timer_ = 0.0f;
993 }
994}
995
996void SpriteEditor::SaveZsmFile(const std::string& path) {
1001 if (status_.ok()) {
1002 SetCurrentZsmPath(path);
1004 binding.zsm_path = path;
1005 if (project()) {
1006 auto& assets = project()->sprite_assets;
1007 auto found =
1008 std::find_if(assets.begin(), assets.end(), [&](const auto& asset) {
1009 return project()->GetAbsolutePath(asset.zsm_path) == path;
1010 });
1011 if (found == assets.end())
1012 assets.push_back(binding);
1013 else
1014 *found = binding;
1016 }
1019 }
1020 }
1021}
1022
1025 std::string path =
1027 if (!path.empty()) {
1028 SaveZsmFile(path);
1029 }
1030 }
1031}
1032
1033// ============================================================
1034// Properties Panel
1035// ============================================================
1036
1039
1040 // Basic info
1041 Text(tr("Sprite Info"));
1042 Separator();
1043
1044 static char name_buf[256];
1045 CopyStringToBuffer(sprite.sprName, name_buf);
1046 if (ImGui::InputText(tr("Name"), name_buf, sizeof(name_buf))) {
1047 sprite.sprName = name_buf;
1048 sprite.property_sprname.Text = name_buf;
1050 }
1051
1052 static char id_buf[32];
1053 CopyStringToBuffer(sprite.property_sprid.Text, id_buf);
1054 if (ImGui::InputText(tr("Sprite ID"), id_buf, sizeof(id_buf))) {
1055 sprite.property_sprid.Text = id_buf;
1057 }
1058
1059 Separator();
1061
1062 Separator();
1064}
1065
1068
1069 Text(tr("Stats"));
1070
1071 // Use InputInt for numeric values
1072 int prize = ParseIntOrDefault(sprite.property_prize.Text);
1073 if (ImGui::InputInt(tr("Prize"), &prize)) {
1074 sprite.property_prize.Text = std::to_string(std::clamp(prize, 0, 255));
1076 }
1077
1078 int palette = ParseIntOrDefault(sprite.property_palette.Text);
1079 if (ImGui::InputInt(tr("Palette"), &palette)) {
1080 sprite.property_palette.Text = std::to_string(std::clamp(palette, 0, 7));
1082 }
1083
1084 int oamnbr = ParseIntOrDefault(sprite.property_oamnbr.Text);
1085 if (ImGui::InputInt(tr("OAM Count"), &oamnbr)) {
1086 sprite.property_oamnbr.Text = std::to_string(std::clamp(oamnbr, 0, 255));
1088 }
1089
1090 int hitbox = ParseIntOrDefault(sprite.property_hitbox.Text);
1091 if (ImGui::InputInt(tr("Hitbox"), &hitbox)) {
1092 sprite.property_hitbox.Text = std::to_string(std::clamp(hitbox, 0, 255));
1094 }
1095
1096 int health = ParseIntOrDefault(sprite.property_health.Text);
1097 if (ImGui::InputInt(tr("Health"), &health)) {
1098 sprite.property_health.Text = std::to_string(std::clamp(health, 0, 255));
1100 }
1101
1102 int damage = ParseIntOrDefault(sprite.property_damage.Text);
1103 if (ImGui::InputInt(tr("Damage"), &damage)) {
1104 sprite.property_damage.Text = std::to_string(std::clamp(damage, 0, 255));
1106 }
1107}
1108
1111
1112 Text(tr("Behavior Flags"));
1113
1114 // Two columns for boolean properties
1115 if (ImGui::BeginTable("BoolProps", 2, ImGuiTableFlags_None)) {
1116 // Column 1
1117 ImGui::TableNextColumn();
1118 if (ImGui::Checkbox(tr("Blockable"), &sprite.property_blockable.IsChecked))
1120 if (ImGui::Checkbox(tr("Can Fall"), &sprite.property_canfall.IsChecked))
1122 if (ImGui::Checkbox(tr("Collision Layer"),
1123 &sprite.property_collisionlayer.IsChecked))
1125 if (ImGui::Checkbox(tr("Custom Death"),
1126 &sprite.property_customdeath.IsChecked))
1128 if (ImGui::Checkbox(tr("Damage Sound"),
1129 &sprite.property_damagesound.IsChecked))
1131 if (ImGui::Checkbox(tr("Deflect Arrows"),
1132 &sprite.property_deflectarrows.IsChecked))
1134 if (ImGui::Checkbox(tr("Deflect Projectiles"),
1135 &sprite.property_deflectprojectiles.IsChecked))
1137 if (ImGui::Checkbox(tr("Fast"), &sprite.property_fast.IsChecked))
1139 if (ImGui::Checkbox(tr("Harmless"), &sprite.property_harmless.IsChecked))
1141 if (ImGui::Checkbox(tr("Impervious"),
1142 &sprite.property_impervious.IsChecked))
1144
1145 // Column 2
1146 ImGui::TableNextColumn();
1147 if (ImGui::Checkbox(tr("Impervious Arrow"),
1148 &sprite.property_imperviousarrow.IsChecked))
1150 if (ImGui::Checkbox(tr("Impervious Melee"),
1151 &sprite.property_imperviousmelee.IsChecked))
1153 if (ImGui::Checkbox(tr("Interaction"),
1154 &sprite.property_interaction.IsChecked))
1156 if (ImGui::Checkbox(tr("Is Boss"), &sprite.property_isboss.IsChecked))
1158 if (ImGui::Checkbox(tr("Persist"), &sprite.property_persist.IsChecked))
1160 if (ImGui::Checkbox(tr("Shadow"), &sprite.property_shadow.IsChecked))
1162 if (ImGui::Checkbox(tr("Small Shadow"),
1163 &sprite.property_smallshadow.IsChecked))
1165 if (ImGui::Checkbox(tr("Stasis"), &sprite.property_statis.IsChecked))
1167 if (ImGui::Checkbox(tr("Statue"), &sprite.property_statue.IsChecked))
1169 if (ImGui::Checkbox(tr("Water Sprite"),
1170 &sprite.property_watersprite.IsChecked))
1172
1173 ImGui::EndTable();
1174 }
1175}
1176
1177// ============================================================
1178// Animation Panel
1179// ============================================================
1180
1183
1184 if (ImGui::Button(tr("Copy draw tables (ASM)"))) {
1185 auto tables = ExportCurrentSpriteDraw();
1186 draw_export_status_ = tables.status();
1187 if (tables.ok())
1188 ImGui::SetClipboardText(tables->c_str());
1189 }
1190 HOVER_HINT(
1191 "Copy a draw-table candidate. Does not register or patch a sprite.");
1192 if (!draw_export_status_.ok())
1193 ImGui::TextWrapped("%s", draw_export_status_.ToString().c_str());
1194
1195 // Playback controls
1196 if (animation_playing_) {
1197 if (ImGui::Button(ICON_MD_STOP " Stop")) {
1198 animation_playing_ = false;
1199 }
1200 } else {
1201 if (ImGui::Button(ICON_MD_PLAY_ARROW " Play")) {
1202 animation_playing_ = true;
1203 frame_timer_ = 0.0f;
1204 }
1205 }
1206 ImGui::SameLine();
1207 if (ImGui::Button(ICON_MD_SKIP_PREVIOUS)) {
1208 if (current_frame_ > 0)
1210 preview_needs_update_ = true;
1211 }
1212 HOVER_HINT("Previous Frame");
1213 ImGui::SameLine();
1214 if (ImGui::Button(ICON_MD_SKIP_NEXT)) {
1215 if (current_frame_ < (int)sprite.editor.Frames.size() - 1)
1217 preview_needs_update_ = true;
1218 }
1219 HOVER_HINT("Next Frame");
1220 ImGui::SameLine();
1221 Text(tr("Frame: %d / %d"), current_frame_,
1222 (int)sprite.editor.Frames.size() - 1);
1223
1224 Separator();
1225
1226 // Animation list
1227 Text(tr("Animations"));
1228 if (ImGui::Button(ICON_MD_ADD " Add Animation")) {
1229 int frame_count = static_cast<int>(sprite.editor.Frames.size());
1230 sprite.animations.emplace_back(0, std::clamp(frame_count - 1, 0, 255), 1,
1231 "New Animation");
1233 }
1234 HOVER_HINT("Add a new animation sequence");
1235
1236 if (ImGui::BeginChild("AnimList", ImVec2(0, 120), true)) {
1237 for (size_t i = 0; i < sprite.animations.size(); i++) {
1238 auto& anim = sprite.animations[i];
1239 std::string label = anim.frame_name.empty() ? "Unnamed" : anim.frame_name;
1240 ImGui::PushID(static_cast<int>(i));
1241 if (Selectable(label.c_str(), current_animation_index_ == (int)i)) {
1242 current_animation_index_ = static_cast<int>(i);
1243 current_frame_ = anim.frame_start;
1244 frame_timer_ = 0;
1245 preview_needs_update_ = true;
1246 }
1247 ImGui::PopID();
1248 }
1249 }
1250 ImGui::EndChild();
1251
1252 // Edit selected animation
1253 if (current_animation_index_ >= 0 &&
1254 current_animation_index_ < (int)sprite.animations.size()) {
1255 auto& anim = sprite.animations[current_animation_index_];
1256
1257 Separator();
1258 Text(tr("Animation Properties"));
1259
1260 static char anim_name[128];
1261 CopyStringToBuffer(anim.frame_name, anim_name);
1262 if (ImGui::InputText(tr("Name##Anim"), anim_name, sizeof(anim_name))) {
1263 anim.frame_name = anim_name;
1265 }
1266
1267 int start = anim.frame_start;
1268 int end = anim.frame_end;
1269 int speed = anim.frame_speed;
1270
1271 if (ImGui::SliderInt(
1272 tr("Start Frame"), &start, 0,
1273 std::clamp((int)sprite.editor.Frames.size() - 1, 0, 255))) {
1274 anim.frame_start = static_cast<uint8_t>(start);
1275 anim.frame_end = std::max(anim.frame_start, anim.frame_end);
1276 end = anim.frame_end;
1278 }
1279 if (ImGui::SliderInt(
1280 tr("End Frame"), &end, 0,
1281 std::clamp((int)sprite.editor.Frames.size() - 1, 0, 255))) {
1282 anim.frame_end = static_cast<uint8_t>(end);
1283 anim.frame_start = std::min(anim.frame_start, anim.frame_end);
1285 }
1286 if (ImGui::SliderInt(tr("Ticks per frame (60 Hz)"), &speed, 1, 255)) {
1287 anim.frame_speed = static_cast<uint8_t>(speed);
1289 }
1290
1291 auto& actions =
1293 bool used_by_action =
1294 std::any_of(actions.begin(), actions.end(), [&](const auto& action) {
1295 return action.animation == current_animation_index_;
1296 });
1297 ImGui::BeginDisabled(used_by_action);
1298 if (ImGui::Button(tr("Delete Animation")) && sprite.animations.size() > 1) {
1299 for (auto& action : actions)
1300 if (action.animation > current_animation_index_)
1301 --action.animation;
1302 sprite.animations.erase(sprite.animations.begin() +
1305 std::min(current_animation_index_, (int)sprite.animations.size() - 1);
1307 }
1308 ImGui::EndDisabled();
1309 if (used_by_action)
1310 ImGui::TextDisabled(
1311 "Assign another animation to referencing actions before deleting.");
1312 HOVER_HINT("Delete the selected animation");
1313 }
1314
1315 Separator();
1317}
1318
1321
1322 Text(tr("Frames"));
1323 if (ImGui::Button(ICON_MD_ADD " Add Frame")) {
1324 if (sprite_authoring::AppendFrame(sprite)) {
1325 current_frame_ = static_cast<int>(sprite.editor.Frames.size()) - 1;
1328 }
1329 }
1330 HOVER_HINT("Add a new animation frame");
1331 ImGui::SameLine();
1332 if (ImGui::Button(ICON_MD_DELETE " Delete Frame") &&
1333 sprite.editor.Frames.size() > 1 && current_frame_ >= 0) {
1336 std::min(current_frame_, (int)sprite.editor.Frames.size() - 1);
1338 frame_timer_ = 0;
1340 }
1341 }
1342 HOVER_HINT("Delete the current frame and repair animation ranges");
1343 if (ImGui::Button(tr("Duplicate Frame")) && current_frame_ >= 0 &&
1345 current_frame_ = static_cast<int>(sprite.editor.Frames.size()) - 1;
1348 }
1349 ImGui::TextDisabled("Up to 256 frames; duplicate appends a frame.");
1350
1351 // Frame selector
1352 if (ImGui::BeginChild("FrameList", ImVec2(0, 80), true,
1353 ImGuiWindowFlags_HorizontalScrollbar)) {
1354 for (size_t i = 0; i < sprite.editor.Frames.size(); i++) {
1355 ImGui::PushID(static_cast<int>(i));
1356 std::string label = absl::StrFormat("F%d", i);
1357 if (Selectable(label.c_str(), current_frame_ == (int)i,
1358 ImGuiSelectableFlags_None, ImVec2(40, 40))) {
1359 current_frame_ = static_cast<int>(i);
1360 preview_needs_update_ = true;
1361 }
1362 ImGui::SameLine();
1363 ImGui::PopID();
1364 }
1365 }
1366 ImGui::EndChild();
1367
1368 // Edit tiles in current frame
1369 if (current_frame_ >= 0 &&
1370 current_frame_ < (int)sprite.editor.Frames.size()) {
1371 auto& frame = sprite.editor.Frames[current_frame_];
1372
1373 Separator();
1374 Text(tr("Tiles in Frame %d"), current_frame_);
1375
1376 if (ImGui::Button(ICON_MD_ADD " Add Tile")) {
1377 frame.Tiles.emplace_back();
1378 frame.Tiles.back().x = sprite_authoring::kOriginX;
1379 frame.Tiles.back().y = sprite_authoring::kOriginY;
1380 selected_tile_index_ = static_cast<int>(frame.Tiles.size()) - 1;
1382 preview_needs_update_ = true;
1383 }
1384 HOVER_HINT("Add a new tile to this frame");
1385
1386 if (ImGui::BeginChild("TileList", ImVec2(0, 100), true)) {
1387 for (size_t i = 0; i < frame.Tiles.size(); i++) {
1388 auto& tile = frame.Tiles[i];
1389 std::string label = absl::StrFormat("Tile %d (ID: %d)", i, tile.id);
1390 if (Selectable(label.c_str(), selected_tile_index_ == (int)i)) {
1391 selected_tile_index_ = static_cast<int>(i);
1392 }
1393 }
1394 }
1395 ImGui::EndChild();
1396
1397 // Edit selected tile
1398 if (selected_tile_index_ >= 0 &&
1399 selected_tile_index_ < (int)frame.Tiles.size()) {
1400 auto& tile = frame.Tiles[selected_tile_index_];
1401
1402 int tile_id = tile.id;
1403 if (ImGui::InputInt(tr("Tile ID"), &tile_id)) {
1404 tile.id = static_cast<uint16_t>(std::clamp(tile_id, 0, 511));
1406 preview_needs_update_ = true;
1407 }
1408
1409 int x = sprite_authoring::OffsetX(tile),
1410 y = sprite_authoring::OffsetY(tile);
1411 if (ImGui::InputInt(tr("X offset"), &x)) {
1412 tile.x = static_cast<uint8_t>(std::clamp(x, -128, 127) +
1415 preview_needs_update_ = true;
1416 }
1417 if (ImGui::InputInt(tr("Y offset"), &y)) {
1418 tile.y = static_cast<uint8_t>(std::clamp(y, -112, 143) +
1421 preview_needs_update_ = true;
1422 }
1423
1424 int pal = tile.palette;
1425 if (ImGui::SliderInt(tr("Palette##Tile"), &pal, 0, 7)) {
1426 tile.palette = static_cast<uint8_t>(pal);
1428 preview_needs_update_ = true;
1429 }
1430
1431 int priority = tile.priority;
1432 if (ImGui::SliderInt(tr("BG priority"), &priority, 0, 3)) {
1433 tile.priority = static_cast<uint8_t>(priority);
1435 }
1436 ImGui::TextDisabled(
1437 "BG priority is stored; preview has no background layers.");
1438 if (ImGui::Checkbox(tr("16x16"), &tile.size)) {
1440 preview_needs_update_ = true;
1441 }
1442 ImGui::SameLine();
1443 if (ImGui::Checkbox(tr("Flip X"), &tile.mirror_x)) {
1445 preview_needs_update_ = true;
1446 }
1447 ImGui::SameLine();
1448 if (ImGui::Checkbox(tr("Flip Y"), &tile.mirror_y)) {
1450 preview_needs_update_ = true;
1451 }
1452
1453 if (ImGui::Button(tr("Edit selected OAM pixels"))) {
1455 }
1456 if (!graphics_context_status_.ok()) {
1457 ImGui::TextWrapped(
1458 "%s", std::string(graphics_context_status_.message()).c_str());
1459 }
1460
1461 if (ImGui::Button(tr("Duplicate Tile"))) {
1462 const auto copy = tile;
1463 frame.Tiles.push_back(copy);
1464 selected_tile_index_ = static_cast<int>(frame.Tiles.size()) - 1;
1466 }
1467 if (ImGui::Button(tr("Delete Tile"))) {
1468 frame.Tiles.erase(frame.Tiles.begin() + selected_tile_index_);
1471 preview_needs_update_ = true;
1472 }
1473 HOVER_HINT("Delete the selected tile");
1474 }
1475 }
1476}
1477
1481 return;
1482 }
1483
1485 if (current_animation_index_ < 0 ||
1486 current_animation_index_ >= (int)sprite.animations.size()) {
1487 return;
1488 }
1489
1490 auto& anim = sprite.animations[current_animation_index_];
1491
1492 if (sprite_authoring::Advance(anim, sprite.editor.Frames.size(), delta_time,
1494 preview_needs_update_ = true;
1495 }
1496}
1497
1498// ============================================================
1499// User Routines Panel
1500// ============================================================
1501
1504
1505 if (ImGui::Button(ICON_MD_ADD " Add Routine")) {
1506 sprite.userRoutines.emplace_back("New Routine", "; ASM code here\n");
1508 }
1509 HOVER_HINT("Add a new ASM routine");
1510
1511 // Routine list
1512 if (ImGui::BeginChild("RoutineList", ImVec2(0, 100), true)) {
1513 for (size_t i = 0; i < sprite.userRoutines.size(); i++) {
1514 auto& routine = sprite.userRoutines[i];
1515 if (Selectable(routine.name.c_str(), selected_routine_index_ == (int)i)) {
1516 selected_routine_index_ = static_cast<int>(i);
1517 }
1518 }
1519 }
1520 ImGui::EndChild();
1521
1522 // Edit selected routine
1523 if (selected_routine_index_ >= 0 &&
1524 selected_routine_index_ < (int)sprite.userRoutines.size()) {
1525 auto& routine = sprite.userRoutines[selected_routine_index_];
1526
1527 Separator();
1528
1529 static char routine_name[128];
1530 CopyStringToBuffer(routine.name, routine_name);
1531 if (ImGui::InputText(tr("Routine Name"), routine_name,
1532 sizeof(routine_name))) {
1533 routine.name = routine_name;
1535 }
1536
1537 Text(tr("ASM Code:"));
1538
1539 // Multiline text input for code
1540 static char code_buffer[16384];
1541 CopyStringToBuffer(routine.code, code_buffer);
1542 if (ImGui::InputTextMultiline("##RoutineCode", code_buffer,
1543 sizeof(code_buffer), ImVec2(-1, 200))) {
1544 routine.code = code_buffer;
1546 }
1547
1548 if (ImGui::Button(tr("Delete Routine"))) {
1549 sprite.userRoutines.erase(sprite.userRoutines.begin() +
1553 }
1554 HOVER_HINT("Delete the selected routine");
1555 }
1556}
1557
1558// ============================================================
1559// Graphics Pipeline
1560// ============================================================
1561
1563 const bool owner_changed = preview_graphics_owner_ != game_data();
1564 const auto palette_revision =
1566 if (owner_changed || preview_palette_revision_ != palette_revision) {
1567 room_palette_cache_.reset();
1568 preview_palette_revision_ = palette_revision;
1570 preview_needs_update_ = true;
1571 }
1572 bool changed = !gfx_buffer_loaded_ || owner_changed ||
1573 preview_uses_asset_graphics_ != use_asset_binding;
1574 const auto* sheets = use_asset_binding ? current_sheets_ : vanilla_sheets_;
1575 for (int slot = 0; slot < 8; ++slot) {
1576 const auto revision =
1577 game_data() ? game_data()->sheet_store.Revision(sheets[slot]) : 0;
1578 changed |= loaded_preview_sheets_[slot] != sheets[slot] ||
1579 loaded_preview_revisions_[slot] != revision;
1580 }
1581 if (changed) {
1582 LoadSpriteGraphicsBuffer(use_asset_binding);
1583 preview_uses_asset_graphics_ = use_asset_binding;
1585 for (int slot = 0; slot < 8; ++slot) {
1586 loaded_preview_sheets_[slot] = sheets[slot];
1588 game_data() ? game_data()->sheet_store.Revision(sheets[slot]) : 0;
1589 }
1591 preview_needs_update_ = true;
1592 }
1593 LoadSpritePalettes(use_asset_binding);
1594}
1595
1596void SpriteEditor::LoadSpriteGraphicsBuffer(bool use_asset_binding) {
1597 // Combine selected sheets (current_sheets_[0-7]) into single 8BPP buffer
1598 // Layout: 16 tiles per row, 8 rows per sheet, 8 sheets total = 64 tile rows
1599 // Buffer size: 0x10000 bytes (65536)
1600
1601 sprite_gfx_buffer_.assign(0x10000, 0);
1602 graphics_binding_status_ = absl::OkStatus();
1603
1604 // Each sheet is 128x32 pixels (128 bytes per row, 32 rows) = 4096 bytes
1605 // We combine 8 sheets vertically: 128x256 pixels total
1606 const auto* binding = use_asset_binding ? current_sprite_binding() : nullptr;
1607 const auto* sheets = use_asset_binding ? current_sheets_ : vanilla_sheets_;
1608 const auto directory =
1609 project() && !project()->filepath.empty()
1610 ? std::filesystem::path(project()->filepath).parent_path()
1611 : std::filesystem::path{};
1612 for (int sheet_idx = 0; sheet_idx < 8; sheet_idx++) {
1613 const auto source = binding ? binding->graphics_sources[sheet_idx]
1615 auto pixels = sprite_graphics_source::Resolve(source, sheets[sheet_idx],
1616 game_data(), rom_, directory);
1617 if (!pixels.ok()) {
1618 if (graphics_binding_status_.ok())
1620 absl::Status(pixels.status().code(),
1621 absl::StrFormat("Graphics sheet/source in slot %d: %s",
1622 sheet_idx, pixels.status().message()));
1623 continue;
1624 }
1625 std::copy(pixels->begin(), pixels->end(),
1626 sprite_gfx_buffer_.begin() + sheet_idx * 4096);
1627 }
1628
1629 // Update drawer with new buffer
1631 gfx_buffer_loaded_ = true;
1632}
1633
1634void SpriteEditor::LoadSpritePalettes(bool use_asset_binding) {
1635 // Load sprite palettes from ROM palette groups
1636 // ALTTP sprites use a combination of palette groups:
1637 // - Rows 0-1: Global sprite palettes (shared by all sprites)
1638 // - Rows 2-7: Aux palettes (vary by sprite type)
1639 //
1640 // For simplicity, we load global_sprites which contains the main
1641 // sprite palettes. More accurate rendering would require looking up
1642 // which aux palette group each sprite type uses.
1643
1644 if (!rom_ || !rom_->is_loaded() || !game_data()) {
1646 palette_binding_status_ = absl::FailedPreconditionError(
1647 "Load ROM graphics and palettes before previewing sprites");
1648 return;
1649 }
1650
1651 // Build combined sprite palette from global + aux groups
1653
1654 // Add global sprite palettes (typically 2 palettes, 16 colors each)
1655 const auto& global = game_data()->palette_groups.global_sprites;
1656 const auto& aux1 = game_data()->palette_groups.sprites_aux1;
1657 const auto& aux2 = game_data()->palette_groups.sprites_aux2;
1658 const auto& aux3 = game_data()->palette_groups.sprites_aux3;
1660 internal::DefaultSpritePreviewPalettes(global, aux1, aux2, aux3);
1661
1662 palette_binding_status_ = absl::OkStatus();
1663 if (global.empty() && aux1.empty() && aux2.empty() && aux3.empty() &&
1665 palette_binding_status_ = absl::FailedPreconditionError(
1666 "Sprite palette colors are unavailable in this ROM session");
1667 }
1668 if (const auto* binding =
1669 use_asset_binding ? current_sprite_binding() : nullptr) {
1670 auto palettes = sprite_authoring::BindPaletteRows(
1671 *binding, sprite_palettes_, global, aux1, aux2, aux3);
1672 palette_binding_status_ = palettes.status();
1673 if (palettes.ok())
1674 sprite_palettes_ = std::move(*palettes);
1675 else
1677 }
1678 if (preview_use_room_palette_ && game_data() != nullptr) {
1679 if (!room_palette_cache_.has_value() ||
1685 }
1687 palette_binding_status_ = absl::OkStatus();
1688 }
1690}
1691
1693 // Ensure graphics buffer is loaded
1695
1696 // Initialize vanilla preview bitmap if needed. The helper also queues a
1697 // CREATE texture command so canvas_rendering doesn't silently skip the
1698 // draw, and stamps the bitmap as kCompositeOutput.
1701
1703 return;
1704 }
1705
1706 // Clear and render
1708
1709 // Origin is center of bitmap
1710 int origin_x = 64;
1711 int origin_y = 64;
1712
1716 origin_x, origin_y);
1717 }
1718
1719 // Build combined 128-color palette (8 sub-palettes × 16 colors)
1720 // and apply to bitmap for proper color rendering
1721 if (sprite_palettes_.size() > 0) {
1722 gfx::SnesPalette combined_palette;
1723 for (size_t pal_idx = 0; pal_idx < 8 && pal_idx < sprite_palettes_.size();
1724 pal_idx++) {
1725 const auto& sub_pal = sprite_palettes_.palette(pal_idx);
1726 for (size_t col_idx = 0; col_idx < 16 && col_idx < sub_pal.size();
1727 col_idx++) {
1728 combined_palette.AddColor(sub_pal[col_idx]);
1729 }
1730 // Pad to 16 if sub-palette is smaller
1731 while (combined_palette.size() < (pal_idx + 1) * 16) {
1732 combined_palette.AddColor(gfx::SnesColor(0));
1733 }
1734 }
1735 vanilla_preview_bitmap_.SetPalette(combined_palette);
1736 }
1737
1738 // Surface pixels and palette were just mutated above; queue an UPDATE so
1739 // the GPU texture reflects the new state on the next frame. Without this,
1740 // the texture stays frozen at first-CREATE state forever.
1742
1744}
1745
1746// ============================================================
1747// Canvas Rendering
1748// ============================================================
1749
1753 return;
1754 }
1755
1757 if (frame_index < 0 || frame_index >= (int)sprite.editor.Frames.size()) {
1758 return;
1759 }
1760
1761 auto& frame = sprite.editor.Frames[frame_index];
1762
1763 // Ensure graphics buffer is loaded
1765
1766 // The sprite_canvas_ displays a post-render composite (pixels come from
1767 // SpriteDrawer, not direct user paint). Declaring the role lets future
1768 // canvas surfaces (cursor hints, context-menu items) default appropriately.
1770
1771 // Initialize preview bitmap if needed. The helper also queues a CREATE
1772 // texture command so canvas_rendering doesn't silently skip the draw, and
1773 // stamps the bitmap as kCompositeOutput.
1776
1777 // Only render if drawer is ready
1779 // Clear and render to preview bitmap
1781
1782 // Origin is center of canvas (128, 128 for 256x256 bitmap).
1785
1786 // Build combined 128-color palette and apply to bitmap
1787 if (sprite_palettes_.size() > 0) {
1788 gfx::SnesPalette combined_palette;
1789 for (size_t pal_idx = 0; pal_idx < 8 && pal_idx < sprite_palettes_.size();
1790 pal_idx++) {
1791 const auto& sub_pal = sprite_palettes_.palette(pal_idx);
1792 for (size_t col_idx = 0; col_idx < 16 && col_idx < sub_pal.size();
1793 col_idx++) {
1794 combined_palette.AddColor(sub_pal[col_idx]);
1795 }
1796 // Pad to 16 if sub-palette is smaller
1797 while (combined_palette.size() < (pal_idx + 1) * 16) {
1798 combined_palette.AddColor(gfx::SnesColor(0));
1799 }
1800 }
1801 sprite_preview_bitmap_.SetPalette(combined_palette);
1802 }
1803
1804 // Surface pixels and palette were just mutated above; queue an UPDATE so
1805 // the GPU texture reflects the new frame on the next paint.
1807
1808 // Mark as updated
1809 preview_needs_update_ = false;
1810 }
1811
1812 // Draw the preview bitmap on canvas
1815 }
1816
1817 // Draw tile outlines for selection (over the bitmap)
1818 if (show_tile_grid_) {
1819 for (size_t i = 0; i < frame.Tiles.size(); i++) {
1820 const auto& tile = frame.Tiles[i];
1821 int tile_size = tile.size ? 16 : 8;
1822
1823 // Convert signed tile position to canvas position
1824 int signed_x = sprite_authoring::OffsetX(tile);
1825 int signed_y = sprite_authoring::OffsetY(tile);
1826
1827 int canvas_x = 128 + signed_x;
1828 int canvas_y = 128 + signed_y;
1829
1830 // Highlight selected tile
1831 ImVec4 color = (selected_tile_index_ == static_cast<int>(i))
1832 ? ImVec4(0.0f, 1.0f, 0.0f, 0.8f) // Green for selected
1833 : ImVec4(1.0f, 1.0f, 0.0f, 0.3f); // Yellow for others
1834
1835 // Match the 2x bitmap scale used above.
1836 sprite_canvas_.DrawRect(canvas_x * 2, canvas_y * 2, tile_size * 2,
1837 tile_size * 2, color);
1838 }
1839 }
1840}
1841
1843 if (ImGui::BeginChild(gui::GetID("##ZSpriteCanvas"),
1844 ImGui::GetContentRegionAvail(), true)) {
1847
1848 // Render current frame if we have a sprite selected
1853 ImGui::SetCursorPos(ImVec2(10, 34));
1854 const auto& error = !graphics_binding_status_.ok()
1857 ImGui::TextWrapped("Preview unavailable: %s",
1858 std::string(error.message()).c_str());
1859 }
1860 } else {
1861 ImGui::SetCursorPos(ImVec2(10, 10));
1862 ImGui::TextWrapped(
1863 "Open a ZSM or import a draw copy to preview its frames.");
1864 }
1865
1868
1869 // Display current frame info
1872 ImGui::SetCursorPos(ImVec2(10, 10));
1873 char label[256];
1874 std::snprintf(label, sizeof(label), tr("Frame: %d | Tiles: %d"),
1876 current_frame_ >= 0 &&
1877 current_frame_ < (int)sprite.editor.Frames.size()
1878 ? (int)sprite.editor.Frames[current_frame_].Tiles.size()
1879 : 0);
1880 const ImVec2 position = ImGui::GetCursorScreenPos();
1881 const ImVec2 size = ImGui::CalcTextSize(label);
1882 // Preview colors come from the ROM; keep status legible on any palette.
1883 ImGui::GetWindowDrawList()->AddRectFilled(
1884 ImVec2(position.x - 3, position.y - 2),
1885 ImVec2(position.x + size.x + 3, position.y + size.y + 2),
1886 IM_COL32(24, 24, 24, 255), 3.0f);
1887 ImGui::TextColored(ImVec4(1, 1, 1, 1), "%s", label);
1888 }
1889 }
1890 ImGui::EndChild();
1891}
1892
1893// ============================================================
1894// Undo/Redo Helpers
1895// ============================================================
1896
1909
1911 if (snapshot.sprite_index < 0 ||
1912 snapshot.sprite_index >= static_cast<int>(custom_sprites_.size())) {
1913 return;
1914 }
1916 current_frame_ = snapshot.current_frame;
1918 custom_sprites_[snapshot.sprite_index] = snapshot.sprite_data;
1919 custom_sprite_bindings_[snapshot.sprite_index] = snapshot.binding;
1921 preview_needs_update_ = true;
1922 zsm_dirty_ = true;
1924}
1925
1928 return; // Already in a transaction
1929 }
1932}
1933
1936 return;
1937 }
1938
1940 // No mutation happened; discard the pending snapshot so we can
1941 // capture a fresh one next frame.
1942 undo_snapshot_pending_ = false;
1943 return;
1944 }
1945
1946 undo_snapshot_pending_ = false;
1948
1949 auto after = CaptureCurrentSpriteSnapshot();
1950 auto restore_fn = [this](const SpriteSnapshot& snapshot) {
1951 RestoreFromSnapshot(snapshot);
1952 };
1953 undo_manager_.Push(std::make_unique<SpriteEditAction>(
1954 std::move(undo_before_snapshot_), std::move(after),
1955 std::move(restore_fn)));
1956}
1957
1965
1967 if (custom_sprite_paths_.size() < custom_sprites_.size()) {
1969 }
1970}
1971
1972const std::string& SpriteEditor::GetCurrentZsmPath() const {
1973 static const std::string kEmptyPath;
1976 static_cast<int>(custom_sprite_paths_.size())) {
1977 return kEmptyPath;
1978 }
1980}
1981
1982void SpriteEditor::SetCurrentZsmPath(const std::string& path) {
1986 static_cast<int>(custom_sprite_paths_.size())) {
1987 return;
1988 }
1990}
1991
1992} // namespace editor
1993} // namespace yaze
project::ResourceLabelManager * resource_label()
Definition rom.h:242
bool is_loaded() const
Definition rom.h:199
The EditorManager controls the main editor window and manages the various editor classes.
EditorContext context() const
Definition editor.h:376
UndoManager undo_manager_
Definition editor.h:383
zelda3::GameData * game_data() const
Definition editor.h:369
EditorDependencies dependencies_
Definition editor.h:382
void SetPalettes(const gfx::PaletteGroup *palettes)
Set the palette group for color mapping.
void ClearBitmap(gfx::Bitmap &bitmap)
Clear the bitmap with transparent color.
void DrawFrame(gfx::Bitmap &bitmap, const zsprite::Frame &frame, int origin_x, int origin_y)
Draw all tiles in a ZSM frame.
bool IsReady() const
Check if drawer is ready to render.
void SetGraphicsBuffer(const uint8_t *buffer)
Set the graphics buffer for tile lookup.
std::array< gfx::Bitmap, 8 > external_sheet_previews_
ImVector< int > active_sprites_
absl::Status OpenSpriteAsset(const std::string &path)
void UpdateAnimationPlayback(float delta_time)
std::vector< project::SpriteAssetBinding > custom_sprite_bindings_
std::vector< zelda3::SpriteTileIssue > tile_issues_
void LoadSpriteGraphicsBuffer(bool use_asset_binding=true)
absl::Status OpenSelectedOamGraphics()
const zsprite::ZSprite * current_custom_sprite() const
std::set< int > dirty_sprite_indices_
void RefreshSpritePreviewGraphics(bool use_asset_binding)
std::array< uint64_t, 8 > loaded_preview_revisions_
void RenderZSpriteFrame(int frame_index)
absl::Status Paste() override
std::array< uint8_t, 8 > loaded_preview_sheets_
absl::StatusOr< std::string > ExportCurrentSpriteDraw()
void LoadSpritePalettes(bool use_asset_binding=true)
std::optional< zsprite::Frame > frame_clipboard_
absl::Status Update() override
gfx::PaletteGroup sprite_palettes_
void LoadZsmFile(const std::string &path)
absl::Status Cut() override
void RenderVanillaSprite(const zelda3::SpriteOamLayout &layout)
absl::Status CreateSpriteAssetFromVanilla(int sprite_id)
absl::Status palette_binding_status_
void DrawCurrentSheets(bool use_asset_binding)
std::optional< std::map< int, zelda3::RoomGfxInfo > > usage_rooms_
const std::string & GetCurrentZsmPath() const
void RestoreFromSnapshot(const SpriteSnapshot &snapshot)
std::vector< zsprite::ZSprite > custom_sprites_
std::vector< uint8_t > sprite_gfx_buffer_
project::YazeProject * project() const
void DrawSpritesetPicker(bool use_asset_binding)
const project::SpriteAssetBinding * current_sprite_binding() const
void SetCurrentZsmPath(const std::string &path)
absl::Status Copy() override
const zelda3::GameData * preview_graphics_owner_
absl::Status Save() override
std::optional< std::map< int, zelda3::OverworldAreaGfxInfo > > usage_areas_
SpriteSnapshot undo_before_snapshot_
void SaveZsmFile(const std::string &path)
void ApplySpritesetToSheets(int spriteset, bool use_asset_binding)
SpriteSnapshot CaptureCurrentSpriteSnapshot() const
absl::Status graphics_binding_status_
absl::Status graphics_context_status_
std::optional< gfx::PaletteGroup > room_palette_cache_
absl::Status Load() override
std::vector< std::string > custom_sprite_paths_
void SelectVanillaSprite(int sprite_id)
const zelda3::SpriteOamLayout * CurrentPreviewLayout() const
void Push(std::unique_ptr< UndoAction > action)
void RegisterWindowContent(std::unique_ptr< WindowContent > window)
Register a WindowContent instance for central drawing.
void QueueTextureCommand(TextureCommandType type, Bitmap *bitmap)
Definition arena.cc:39
GraphicsSheets & gfx_sheets()
Definition arena.h:178
static Arena & Get()
Definition arena.cc:24
const std::vector< uint8_t > & vector() const
Definition bitmap.h:411
bool is_active() const
Definition bitmap.h:414
void SetPalette(const SnesPalette &palette)
Set the palette for the bitmap using SNES palette format.
Definition bitmap.cc:452
uint64_t ColorRevision(const zelda3::GameData *game_data) const
static PaletteManager & Get()
Get the singleton instance.
RAII timer for automatic timing management.
SNES Color container.
Definition snes_color.h:110
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
void AddColor(const SnesColor &color)
RAII scope that enables automatic widget registration.
void DrawBitmap(Bitmap &bitmap, int border_offset, float scale)
Definition canvas.cc:1295
void DrawContextMenu()
Definition canvas.cc:824
bool DrawTileSelector(int size, int size_y=0)
Definition canvas.cc:1231
void DrawRect(int x, int y, int w, int h, ImVec4 color)
Definition canvas.cc:1569
CanvasConfig & GetConfig()
Definition canvas.h:243
void DrawBackground(ImVec2 canvas_size=ImVec2(0, 0), std::optional< ImVec2 > viewport_size=std::nullopt)
Definition canvas.cc:703
void DrawGrid(float grid_step=64.0f, int tile_id_offset=8)
Definition canvas.cc:1627
static float GetHexInputWidth()
static std::string ShowSaveFileDialog(const std::string &default_name="", const std::string &default_extension="")
ShowSaveFileDialog opens a save file dialog and returns the selected filepath. Uses global feature fl...
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath. Uses global feature flag to...
uint64_t Revision(uint16_t sheet) const
static const SpriteOamLayout * GetLayout(uint8_t sprite_id)
Get the OAM layout for a sprite ID.
static const SpriteOamLayout * GetPreviewOverride(uint8_t sprite_id, std::string_view hack_name)
#define ICON_MD_MEETING_ROOM
Definition icons.h:1194
#define ICON_MD_FOLDER_OPEN
Definition icons.h:813
#define ICON_MD_WARNING
Definition icons.h:2123
#define ICON_MD_PLAY_ARROW
Definition icons.h:1479
#define ICON_MD_CHECK
Definition icons.h:397
#define ICON_MD_SAVE_AS
Definition icons.h:1646
#define ICON_MD_STOP
Definition icons.h:1862
#define ICON_MD_ADD
Definition icons.h:86
#define ICON_MD_SKIP_NEXT
Definition icons.h:1773
#define ICON_MD_DONE
Definition icons.h:607
#define ICON_MD_SAVE
Definition icons.h:1644
#define ICON_MD_DELETE
Definition icons.h:530
#define ICON_MD_SKIP_PREVIOUS
Definition icons.h:1774
#define HOVER_HINT(string)
Definition macro.h:24
zelda3::GfxSheetInventoryOptions BuildGfxSheetInventoryOptions(const project::YazeProject *project)
int ParseIntOrDefault(const std::string &text, int fallback=0)
void EnsureSpritePreviewBitmapReady(gfx::Bitmap &bmp, int width, int height, int depth, const std::vector< uint8_t > &gfx_buffer)
int StepFrameIndex(int current, int delta, int frame_count)
void PublishSpritePreviewPixels(gfx::Bitmap &bmp)
std::vector< int > FrameTiles8x8(const zsprite::Frame &frame)
gfx::PaletteGroup SpritePalettesFromCgram(const std::array< SDL_Color, 256 > &cgram)
gfx::PaletteGroup DefaultSpritePreviewPalettes(const gfx::PaletteGroup &global, const gfx::PaletteGroup &aux1, const gfx::PaletteGroup &aux2, const gfx::PaletteGroup &aux3)
int OffsetX(const zsprite::OamTile &tile)
bool Advance(const zsprite::AnimationGroup &animation, size_t frame_count, float delta, int &frame, float &remainder)
absl::StatusOr< gfx::PaletteGroup > BindPaletteRows(const project::SpriteAssetBinding &binding, const gfx::PaletteGroup &defaults, const gfx::PaletteGroup &global, const gfx::PaletteGroup &aux1, const gfx::PaletteGroup &aux2, const gfx::PaletteGroup &aux3)
int OffsetY(const zsprite::OamTile &tile)
bool AppendFrame(zsprite::ZSprite &sprite, int copy_from=-1)
zsprite::Frame CopyVanillaLayout(const zelda3::SpriteOamLayout &layout)
bool DeleteFrame(zsprite::ZSprite &sprite, int index)
absl::StatusOr< GraphicsEditContext > Make(const zsprite::Frame &frame, int frame_index, int oam_index, const std::array< uint8_t, 8 > &slots, const gfx::PaletteGroup &palettes, const zelda3::GameData *owner, const std::string &source_label, const std::string &sheet_source)
absl::StatusOr< usage_preview::PreviewImage > RenderCapturedFrame(const zsprite::Frame &frame, const std::array< uint8_t, 8 > &slots, const gfx::PaletteGroup &palettes, const zelda3::GameData *owner)
absl::StatusOr< std::vector< uint8_t > > Resolve(const project::SpriteGraphicsSource &source, uint16_t sheet, const zelda3::GameData *data, const Rom *rom, const std::filesystem::path &project_directory)
constexpr ImGuiTabItemFlags kSpriteTabFlags
constexpr ImGuiTabBarFlags kSpriteTabBarFlags
ImGuiID GetID(const std::string &id)
Definition input.cc:693
ImVec4 GetSuccessColor()
Definition ui_helpers.cc:49
void AutoRegisterLastItem(const std::string &widget_type, const std::string &explicit_label, const std::string &description)
Automatically register the last ImGui item.
bool BeginThemedTabBar(const char *id, ImGuiTabBarFlags flags)
A stylized tab bar with "Mission Control" branding.
void EndThemedTabBar()
ImVec4 GetWarningColor()
Definition ui_helpers.cc:54
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:483
std::string HexByte(uint8_t byte, HexStringParams params)
Definition hex.cc:33
constexpr int kNumDungeonRooms
GfxGroupUsage FindSpritesetUsage(int spriteset, const std::map< int, OverworldAreaGfxInfo > &areas, const std::map< int, RoomGfxInfo > &rooms)
Room LoadRoomHeaderFromRom(Rom *rom, int room_id)
Definition room.cc:680
std::map< int, OverworldAreaGfxInfo > CollectOverworldAreaGfx(Rom &rom, GameData *game_data)
constexpr uint16_t kDungeonSpritesetBase
std::map< int, RoomGfxInfo > CollectRoomGfx(const Rom &rom)
const std::string kSpriteDefaultNames[256]
Definition sprite.cc:16
constexpr uint32_t kNumSpritesets
Definition game_data.h:34
constexpr bool IsUnderworldSpriteset(int spriteset)
Dungeon rooms use spritesets 0x40-0x8F (room header value + 0x40).
std::array< uint8_t, 8 > SpriteSheetSlots(const std::array< uint8_t, 4 > &spriteset_values, bool underworld)
The eight sheets for a spriteset's four values.
std::array< SDL_Color, 256 > BuildDungeonSpriteRenderPalette(const Room &room, const GameData *game_data)
Definition room.cc:200
std::vector< SpriteTileIssue > CheckSpriteTiles(const Rom &rom, const std::vector< int > &tiles, const std::array< uint8_t, 8 > &slots, const std::set< uint16_t > &reserved_sheets)
#define RETURN_IF_ERROR(expr)
Definition snes.cc:22
WorkspaceWindowManager * window_manager
Definition editor.h:182
Snapshot of a custom ZSprite's editable state for undo/redo.
project::SpriteAssetBinding binding
std::vector< Frame > Frames
Definition zsprite.h:125
void Reset()
Reset all sprite data to defaults.
Definition zsprite.h:405
absl::Status Load(const std::string &filename)
Load a ZSM file from disk.
Definition zsprite.h:139
std::vector< AnimationGroup > animations
Definition zsprite.h:445
auto palette(int i) const
const SnesPalette & palette_ref(int i) const
void SelectableLabelWithNameEdit(bool selected, const std::string &type, const std::string &key, const std::string &defaultValue)
Definition project.cc:3604
std::array< uint8_t, 8 > sheets
std::vector< SpriteAssetBinding > sprite_assets
Definition project.h:336
std::string GetAbsolutePath(const std::string &relative_path) const
Definition project.cc:2700
std::array< std::array< uint8_t, 4 >, kNumSpritesets > spriteset_ids
Definition game_data.h:99
gfx::PaletteGroupMap palette_groups
Definition game_data.h:95
Complete OAM layout for a vanilla sprite.
Automatic widget registration helpers for ImGui Test Engine integration.