yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
graphics_editor.cc
Go to the documentation of this file.
1#include "graphics_editor.h"
2
3#include <filesystem>
4
5#include "absl/status/status.h"
6#include "absl/status/statusor.h"
7#include "absl/strings/str_cat.h"
11#include "app/gfx/bitmap.h"
12#include "app/gfx/compression.h"
13#include "app/gfx/scad_format.h"
15#include "app/gfx/snes_tile.h"
16#include "app/gui/canvas.h"
17#include "app/gui/color.h"
18#include "app/gui/icons.h"
19#include "app/gui/input.h"
21#include "app/gui/style.h"
22#include "app/rom.h"
23#include "imgui/imgui.h"
24#include "imgui/misc/cpp/imgui_stdlib.h"
25#include "imgui_memory_editor.h"
26
27namespace yaze {
28namespace editor {
29
30using core::Renderer;
31
33using ImGui::Button;
34using ImGui::InputInt;
35using ImGui::InputText;
36using ImGui::SameLine;
37using ImGui::TableNextColumn;
38
39constexpr ImGuiTableFlags kGfxEditTableFlags =
40 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable |
41 ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable |
42 ImGuiTableFlags_SizingFixedFit;
43
45
46absl::Status GraphicsEditor::Load() { return absl::OkStatus(); }
47
48absl::Status GraphicsEditor::Update() {
49 if (ImGui::BeginTabBar("##TabBar")) {
51 TAB_ITEM("Sheet Browser")
52 if (asset_browser_.Initialized == false) {
53 asset_browser_.Initialize(
55 }
60 ImGui::EndTabBar();
61 }
63 return absl::OkStatus();
64}
65
67 if (ImGui::BeginTabItem("Sheet Editor")) {
68 if (ImGui::BeginTable("##GfxEditTable", 3, kGfxEditTableFlags,
69 ImVec2(0, 0))) {
70 for (const auto& name :
71 {"Tilesheets", "Current Graphics", "Palette Controls"})
72 ImGui::TableSetupColumn(name);
73
74 ImGui::TableHeadersRow();
75
78
80 if (rom()->is_loaded()) {
83 }
84
86 if (rom()->is_loaded()) {
88 }
89 }
90 ImGui::EndTable();
91
92 ImGui::EndTabItem();
93 }
94 return absl::OkStatus();
95}
96
98 if (ImGui::BeginTable("##GfxEditToolset", 9, ImGuiTableFlags_SizingFixedFit,
99 ImVec2(0, 0))) {
100 for (const auto& name :
101 {"Select", "Pencil", "Fill", "Copy Sheet", "Paste Sheet", "Zoom Out",
102 "Zoom In", "Current Color", "Tile Size"})
103 ImGui::TableSetupColumn(name);
104
105 TableNextColumn();
106 if (Button(ICON_MD_SELECT_ALL)) {
108 }
109
110 TableNextColumn();
111 if (Button(ICON_MD_DRAW)) {
113 }
114 HOVER_HINT("Draw with current color");
115
116 TableNextColumn();
117 if (Button(ICON_MD_FORMAT_COLOR_FILL)) {
119 }
120 HOVER_HINT("Fill with current color");
121
122 TableNextColumn();
123 if (Button(ICON_MD_CONTENT_COPY)) {
124 std::vector<uint8_t> png_data = GraphicsSheetManager::GetInstance()
125 .gfx_sheets()
126 .at(current_sheet_)
127 .GetPngData();
129 }
130 HOVER_HINT("Copy to Clipboard");
131
132 TableNextColumn();
133 if (Button(ICON_MD_CONTENT_PASTE)) {
134 std::vector<uint8_t> png_data;
135 int width, height;
136 core::GetImageFromClipboard(png_data, width, height);
137 if (png_data.size() > 0) {
140 ->at(current_sheet_)
141 .Create(width, height, 8, png_data);
143 &GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(
145 }
146 }
147 HOVER_HINT("Paste from Clipboard");
148
149 TableNextColumn();
150 if (Button(ICON_MD_ZOOM_OUT)) {
151 if (current_scale_ >= 0.0f) {
152 current_scale_ -= 1.0f;
153 }
154 }
155
156 TableNextColumn();
157 if (Button(ICON_MD_ZOOM_IN)) {
158 if (current_scale_ <= 16.0f) {
159 current_scale_ += 1.0f;
160 }
161 }
162
163 TableNextColumn();
164 auto bitmap =
166 auto palette = bitmap.palette();
167 for (int i = 0; i < palette.size(); i++) {
168 ImGui::SameLine();
169 auto color =
170 ImVec4(palette[i].rgb().x / 255.0f, palette[i].rgb().y / 255.0f,
171 palette[i].rgb().z / 255.0f, 255.0f);
172 if (ImGui::ColorButton(absl::StrFormat("Palette Color %d", i).c_str(),
173 color)) {
174 current_color_ = color;
175 }
176 }
177
178 TableNextColumn();
179 gui::InputHexByte("Tile Size", &tile_size_);
180
181 ImGui::EndTable();
182 }
183}
184
186 ImGui::BeginChild(
187 "##GfxEditChild", ImVec2(0, 0), true,
188 ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysVerticalScrollbar);
189 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
190 // TODO: Update the interaction for multi select on sheets
191 static ImGuiSelectionBasicStorage selection;
192 ImGuiMultiSelectFlags flags =
193 ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_BoxSelect1d;
194 ImGuiMultiSelectIO* ms_io =
195 ImGui::BeginMultiSelect(flags, selection.Size, kNumGfxSheets);
196 selection.ApplyRequests(ms_io);
197 ImGuiListClipper clipper;
198 clipper.Begin(kNumGfxSheets);
199 if (ms_io->RangeSrcItem != -1)
200 clipper.IncludeItemByIndex(
201 (int)ms_io->RangeSrcItem); // Ensure RangeSrc item is not clipped.
202
203 int key = 0;
204 for (auto& value : GraphicsSheetManager::GetInstance().gfx_sheets()) {
205 ImGui::BeginChild(absl::StrFormat("##GfxSheet%02X", key).c_str(),
206 ImVec2(0x100 + 1, 0x40 + 1), true,
207 ImGuiWindowFlags_NoDecoration);
208 ImGui::PopStyleVar();
209
210 graphics_bin_canvas_.DrawBackground(ImVec2(0x100 + 1, 0x40 + 1));
211 graphics_bin_canvas_.DrawContextMenu();
212 if (value.is_active()) {
213 auto texture = value.texture();
214 graphics_bin_canvas_.draw_list()->AddImage(
215 (ImTextureID)(intptr_t)texture,
216 ImVec2(graphics_bin_canvas_.zero_point().x + 2,
217 graphics_bin_canvas_.zero_point().y + 2),
218 ImVec2(graphics_bin_canvas_.zero_point().x +
219 value.width() * sheet_scale_,
220 graphics_bin_canvas_.zero_point().y +
221 value.height() * sheet_scale_));
222
223 if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
224 current_sheet_ = key;
225 open_sheets_.insert(key);
226 }
227
228 // Add a slightly transparent rectangle behind the text
229 ImVec2 text_pos(graphics_bin_canvas_.zero_point().x + 2,
230 graphics_bin_canvas_.zero_point().y + 2);
231 ImVec2 text_size =
232 ImGui::CalcTextSize(absl::StrFormat("%02X", key).c_str());
233 ImVec2 rent_min(text_pos.x, text_pos.y);
234 ImVec2 rent_max(text_pos.x + text_size.x, text_pos.y + text_size.y);
235
236 graphics_bin_canvas_.draw_list()->AddRectFilled(rent_min, rent_max,
237 IM_COL32(0, 125, 0, 128));
238
239 graphics_bin_canvas_.draw_list()->AddText(
240 text_pos, IM_COL32(125, 255, 125, 255),
241 absl::StrFormat("%02X", key).c_str());
242
243 key++;
244 }
245 graphics_bin_canvas_.DrawGrid(16.0f);
246 graphics_bin_canvas_.DrawOverlay();
247
248 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
249 ImGui::EndChild();
250 }
251 ImGui::PopStyleVar();
252 ms_io = ImGui::EndMultiSelect();
253 selection.ApplyRequests(ms_io);
254 ImGui::EndChild();
255 return absl::OkStatus();
256}
257
259 static int next_tab_id = 0;
260 constexpr ImGuiTabBarFlags kGfxEditTabBarFlags =
261 ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_Reorderable |
262 ImGuiTabBarFlags_FittingPolicyResizeDown |
263 ImGuiTabBarFlags_TabListPopupButton;
264
265 if (ImGui::BeginTabBar("##GfxEditTabBar", kGfxEditTabBarFlags)) {
266 if (ImGui::TabItemButton(ICON_MD_ADD, ImGuiTabItemFlags_Trailing |
267 ImGuiTabItemFlags_NoTooltip)) {
268 open_sheets_.insert(next_tab_id++);
269 }
270
271 for (auto& sheet_id : open_sheets_) {
272 bool open = true;
273 if (ImGui::BeginTabItem(absl::StrFormat("%d", sheet_id).c_str(), &open,
274 ImGuiTabItemFlags_None)) {
275 current_sheet_ = sheet_id;
276 if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
277 release_queue_.push(sheet_id);
278 }
279 if (ImGui::IsItemHovered()) {
280 if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) {
281 release_queue_.push(sheet_id);
282 child_window_sheets_.insert(sheet_id);
283 }
284 }
285
286 const auto child_id =
287 absl::StrFormat("##GfxEditPaletteChildWindow%d", sheet_id);
288 ImGui::BeginChild(child_id.c_str(), ImVec2(0, 0), true,
289 ImGuiWindowFlags_NoDecoration |
290 ImGuiWindowFlags_AlwaysVerticalScrollbar |
291 ImGuiWindowFlags_AlwaysHorizontalScrollbar);
292
293 gfx::Bitmap& current_bitmap =
295 sheet_id);
296
297 auto draw_tile_event = [&]() {
298 current_sheet_canvas_.DrawTileOnBitmap(tile_size_, &current_bitmap,
300 Renderer::GetInstance().UpdateBitmap(&current_bitmap);
301 };
302
303 current_sheet_canvas_.UpdateColorPainter(
304 GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(
305 sheet_id),
306 current_color_, draw_tile_event, tile_size_, current_scale_);
307
308 ImGui::EndChild();
309 ImGui::EndTabItem();
310 }
311
312 if (!open) release_queue_.push(sheet_id);
313 }
314
315 ImGui::EndTabBar();
316 }
317
318 // Release any tabs that were closed
319 while (!release_queue_.empty()) {
320 auto sheet_id = release_queue_.top();
321 open_sheets_.erase(sheet_id);
322 release_queue_.pop();
323 }
324
325 // Draw any child windows that were created
326 if (!child_window_sheets_.empty()) {
327 int id_to_release = -1;
328 for (const auto& id : child_window_sheets_) {
329 bool active = true;
330 ImGui::SetNextWindowPos(ImGui::GetIO().MousePos, ImGuiCond_Once);
331 ImGui::SetNextWindowSize(ImVec2(0x100 + 1 * 16, 0x40 + 1 * 16),
332 ImGuiCond_Once);
333 ImGui::Begin(absl::StrFormat("##GfxEditPaletteChildWindow%d", id).c_str(),
334 &active, ImGuiWindowFlags_AlwaysUseWindowPadding);
335 current_sheet_ = id;
336 // ImVec2(0x100, 0x40),
337 current_sheet_canvas_.UpdateColorPainter(
338 GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(id),
340 [&]() {
341
342 },
344 ImGui::End();
345
346 if (active == false) {
347 id_to_release = id;
348 }
349 }
350 if (id_to_release != -1) {
351 child_window_sheets_.erase(id_to_release);
352 }
353 }
354
355 return absl::OkStatus();
356}
357
359 if (rom()->is_loaded()) {
360 auto palette_group = *rom()->palette_group().get_group(
362 auto palette = palette_group.palette(edit_palette_index_);
363 gui::TextWithSeparators("ROM Palette");
364 ImGui::SetNextItemWidth(100.f);
365 ImGui::Combo("Palette Group", (int*)&edit_palette_group_name_index_,
367 IM_ARRAYSIZE(kPaletteGroupAddressesKeys));
368 ImGui::SetNextItemWidth(100.f);
369 gui::InputHex("Palette Group Index", &edit_palette_index_);
370
372 palette);
373
374 if (refresh_graphics_ && !open_sheets_.empty()) {
377 ->data()[current_sheet_]
378 .SetPaletteWithTransparent(palette, edit_palette_sub_index_);
380 .mutable_gfx_sheets()
381 ->data()[current_sheet_]);
382 refresh_graphics_ = false;
383 }
384 }
385 return absl::OkStatus();
386}
387
389 TAB_ITEM("Player Animations")
390
391 if (ImGui::BeginTable("##PlayerAnimationTable", 3, kGfxEditTableFlags,
392 ImVec2(0, 0))) {
393 for (const auto& name : {"Canvas", "Animation Steps", "Properties"})
394 ImGui::TableSetupColumn(name);
395
396 ImGui::TableHeadersRow();
397
398 NEXT_COLUMN();
399 link_canvas_.DrawBackground();
400 link_canvas_.DrawGrid(16.0f);
401
402 int i = 0;
403 for (auto& link_sheet : link_sheets_) {
404 int x_offset = 0;
405 int y_offset = gfx::kTilesheetHeight * i * 4;
406 link_canvas_.DrawContextMenu();
407 link_canvas_.DrawBitmap(link_sheet, x_offset, y_offset, 4);
408 i++;
409 }
410 link_canvas_.DrawOverlay();
411 link_canvas_.DrawGrid();
412
413 NEXT_COLUMN();
414 ImGui::Text("Placeholder");
415
416 NEXT_COLUMN();
417 if (ImGui::Button("Load Link Graphics (Experimental)")) {
418 if (rom()->is_loaded()) {
419 // Load Links graphics from the ROM
421
422 // Split it into the pose data frames
423 // Create an animation step display for the poses
424 // Allow the user to modify the frames used in an anim step
425 // LinkOAM_AnimationSteps:
426 // #_0D85FB
427 }
428 }
429 }
430 ImGui::EndTable();
431
433 return absl::OkStatus();
434}
435
437 TAB_ITEM("Prototype")
438
440
442 ImGui::Begin("Memory Editor", &open_memory_editor_);
444 ImGui::End();
445 }
446
447 constexpr ImGuiTableFlags kGfxEditFlags = ImGuiTableFlags_Reorderable |
448 ImGuiTableFlags_Resizable |
449 ImGuiTableFlags_SizingStretchSame;
450
451 BEGIN_TABLE("#gfxEditTable", 4, kGfxEditFlags)
452 SETUP_COLUMN("File Import (BIN, CGX, ROM)")
453 SETUP_COLUMN("Palette (COL)")
454 ImGui::TableSetupColumn("Tilemaps and Objects (SCR, PNL, OBJ)",
455 ImGuiTableColumnFlags_WidthFixed);
456 SETUP_COLUMN("Graphics Preview")
458 NEXT_COLUMN() {
463 }
464
466
469 scr_loaded_, false, 0);
471
473 if (super_donkey_) {
474 // TODO: Implement the Super Donkey 1 graphics decompression
475 // if (refresh_graphics_) {
476 // for (int i = 0; i < kNumGfxSheets; i++) {
477 // status_ = graphics_bin_[i].SetPalette(
478 // col_file_palette_group_[current_palette_index_]);
479 // Renderer::GetInstance().UpdateBitmap(&graphics_bin_[i]);
480 // }
481 // refresh_graphics_ = false;
482 // }
483 // Load the full graphics space from `super_donkey_1.bin`
484 // gui::GraphicsBinCanvasPipeline(0x100, 0x40, 0x20, num_sheets_to_load_, 3,
485 // super_donkey_, graphics_bin_);
486 } else if (cgx_loaded_ && col_file_) {
487 // Load the CGX graphics
489 cgx_loaded_, true, 5);
490 } else {
491 // Load the BIN/Clipboard Graphics
493 gfx_loaded_, true, 2);
494 }
495 END_TABLE()
496
498 return absl::OkStatus();
499}
500
502 static constexpr absl::string_view kGfxToolsetColumnNames[] = {
503 "#memoryEditor",
504 };
505
506 if (ImGui::BeginTable("GraphicsToolset", 1, ImGuiTableFlags_SizingFixedFit,
507 ImVec2(0, 0))) {
508 for (const auto& name : kGfxToolsetColumnNames)
509 ImGui::TableSetupColumn(name.data());
510
511 TableNextColumn();
512 if (Button(absl::StrCat(ICON_MD_MEMORY, "Open Memory Editor").c_str())) {
513 if (!open_memory_editor_) {
514 open_memory_editor_ = true;
515 } else {
516 open_memory_editor_ = false;
517 }
518 }
519
520 ImGui::EndTable();
521 }
522 return absl::OkStatus();
523}
524
526 gui::TextWithSeparators("Cgx Import");
527 InputInt("BPP", &current_bpp_);
528
529 InputText("##CGXFile", &cgx_file_name_);
530 SameLine();
531
532 if (ImGui::Button("Open CGX")) {
534 cgx_file_name_ = filename;
535 cgx_file_path_ = std::filesystem::absolute(filename).string();
536 is_open_ = true;
537 cgx_loaded_ = true;
538 }
539
540 if (ImGui::Button("Copy CGX Path")) {
541 ImGui::SetClipboardText(cgx_file_path_.c_str());
542 }
543
544 if (ImGui::Button("Load CGX Data")) {
547
548 cgx_bitmap_.Create(0x80, 0x200, 8, decoded_cgx_);
549 if (col_file_) {
550 cgx_bitmap_.SetPalette(decoded_col_);
552 }
553 }
554
555 return absl::OkStatus();
556}
557
559 InputText("##ScrFile", &scr_file_name_);
560
561 if (ImGui::Button("Open SCR")) {
563 scr_file_name_ = filename;
564 scr_file_path_ = std::filesystem::absolute(filename).string();
565 is_open_ = true;
566 scr_loaded_ = true;
567 }
568
569 InputInt("SCR Mod", &scr_mod_value_);
570
571 if (ImGui::Button("Load Scr Data")) {
573
574 decoded_scr_data_.resize(0x100 * 0x100);
577
578 scr_bitmap_.Create(0x100, 0x100, 8, decoded_scr_data_);
579 if (scr_loaded_) {
580 scr_bitmap_.SetPalette(decoded_col_);
582 }
583 }
584
585 return absl::OkStatus();
586}
587
589 gui::TextWithSeparators("COL Import");
590 InputText("##ColFile", &col_file_name_);
591 SameLine();
592
593 if (ImGui::Button("Open COL")) {
595 col_file_name_ = filename;
596 col_file_path_ = std::filesystem::absolute(filename).string();
597 status_ = temp_rom_.LoadFromFile(col_file_path_,
598 /*z3_load=*/false);
599 auto col_data_ = gfx::GetColFileData(temp_rom_.mutable_data());
600 if (col_file_palette_group_.size() != 0) {
602 }
603 auto col_file_palette_group_status =
605 if (col_file_palette_group_status.ok()) {
606 col_file_palette_group_ = col_file_palette_group_status.value();
607 }
609
610 // gigaleak dev format based code
612 col_file_ = true;
613 is_open_ = true;
614 }
615 HOVER_HINT(".COL, .BAK");
616
617 if (ImGui::Button("Copy Col Path")) {
618 ImGui::SetClipboardText(col_file_path_.c_str());
619 }
620
621 if (rom()->is_loaded()) {
622 gui::TextWithSeparators("ROM Palette");
623 gui::InputHex("Palette Index", &current_palette_index_);
624 ImGui::Combo("Palette", &current_palette_, kPaletteGroupAddressesKeys,
625 IM_ARRAYSIZE(kPaletteGroupAddressesKeys));
626 }
627
628 if (col_file_palette_.size() != 0) {
631 }
632
633 return absl::OkStatus();
634}
635
637 gui::TextWithSeparators("OBJ Import");
638
639 InputText("##ObjFile", &obj_file_path_);
640 SameLine();
641
642 if (ImGui::Button("Open OBJ")) {
644 obj_file_path_ = std::filesystem::absolute(filename).string();
645 status_ = temp_rom_.LoadFromFile(obj_file_path_);
646 is_open_ = true;
647 obj_loaded_ = true;
648 }
649 HOVER_HINT(".OBJ, .BAK");
650
651 return absl::OkStatus();
652}
653
655 gui::TextWithSeparators("Tilemap Import");
656
657 InputText("##TMapFile", &tilemap_file_path_);
658 SameLine();
659
660 if (ImGui::Button("Open Tilemap")) {
662 tilemap_file_path_ = std::filesystem::absolute(filename).string();
665
666 // Extract the high and low bytes from the file.
667 auto decomp_sheet = gfx::lc_lz2::DecompressV2(tilemap_rom_.data(),
669 tilemap_loaded_ = true;
670 is_open_ = true;
671 }
672 HOVER_HINT(".DAT, .BIN, .HEX");
673
674 return absl::OkStatus();
675}
676
678 gui::TextWithSeparators("BIN Import");
679
680 InputText("##ROMFile", &file_path_);
681 SameLine();
682
683 if (ImGui::Button("Open BIN")) {
685 file_path_ = filename;
686 status_ = temp_rom_.LoadFromFile(file_path_);
687 is_open_ = true;
688 }
689 HOVER_HINT(".BIN, .HEX");
690
691 if (Button("Copy File Path")) {
692 ImGui::SetClipboardText(file_path_.c_str());
693 }
694
695 gui::InputHex("BIN Offset", &current_offset_);
696 gui::InputHex("BIN Size", &bin_size_);
697
698 if (Button("Decompress BIN")) {
699 if (file_path_.empty()) {
700 return absl::InvalidArgumentError(
701 "Please select a file before decompressing.");
702 }
704 }
705
706 return absl::OkStatus();
707}
708
710 gui::TextWithSeparators("Clipboard Import");
711 if (Button("Paste From Clipboard")) {
712 const char* text = ImGui::GetClipboardText();
713 if (text) {
714 const auto clipboard_data =
715 std::vector<uint8_t>(text, text + strlen(text));
716 ImGui::MemFree((void*)text);
717 status_ = temp_rom_.LoadFromData(clipboard_data);
718 is_open_ = true;
719 open_memory_editor_ = true;
720 }
721 }
724 gui::InputHex("Num Sheets", &num_sheets_to_load_);
725
726 if (Button("Decompress Clipboard Data")) {
727 if (temp_rom_.is_loaded()) {
728 status_ = DecompressImportData(0x40000);
729 } else {
730 status_ = absl::InvalidArgumentError(
731 "Please paste data into the clipboard before "
732 "decompressing.");
733 }
734 }
735
736 return absl::OkStatus();
737}
738
740 gui::TextWithSeparators("Experimental");
741 if (Button("Decompress Super Donkey Full")) {
742 if (file_path_.empty()) {
743 return absl::InvalidArgumentError(
744 "Please select `super_donkey_1.bin` before "
745 "importing.");
746 }
748 }
749 ImGui::SetItemTooltip(
750 "Requires `super_donkey_1.bin` to be imported under the "
751 "BIN import section.");
752 return absl::OkStatus();
753}
754
756 std::string title = "Memory Editor";
757 if (is_open_) {
758 static MemoryEditor mem_edit;
759 mem_edit.DrawWindow(title.c_str(), temp_rom_.mutable_data(),
760 temp_rom_.size());
761 }
762 return absl::OkStatus();
763}
764
767 temp_rom_.data(), current_offset_, size))
768
769 auto converted_sheet = gfx::SnesTo8bppSheet(import_data_, 3);
771 converted_sheet);
772
773 if (rom()->is_loaded()) {
774 auto palette_group = rom()->palette_group().overworld_animated;
775 z3_rom_palette_ = palette_group[current_palette_];
776 if (col_file_) {
777 bin_bitmap_.SetPalette(col_file_palette_);
778 } else {
779 bin_bitmap_.SetPalette(z3_rom_palette_);
780 }
781 }
782
784 gfx_loaded_ = true;
785
786 return absl::OkStatus();
787}
788
790 int i = 0;
791 for (const auto& offset : kSuperDonkeyTiles) {
792 int offset_value =
793 std::stoi(offset, nullptr, 16); // convert hex string to int
795 auto decompressed_data,
796 gfx::lc_lz2::DecompressV2(temp_rom_.data(), offset_value, 0x1000))
797 auto converted_sheet = gfx::SnesTo8bppSheet(decompressed_data, 3);
799 gfx::kTilesheetDepth, converted_sheet);
800 if (col_file_) {
801 gfx_sheets_[i].SetPalette(
803 } else {
804 // ROM palette
805
806 auto palette_group = rom()->palette_group().get_group(
808 z3_rom_palette_ = *palette_group->mutable_palette(current_palette_index_);
809 gfx_sheets_[i].SetPalette(z3_rom_palette_);
810 }
811
813 i++;
814 }
815
816 for (const auto& offset : kSuperDonkeySprites) {
817 int offset_value =
818 std::stoi(offset, nullptr, 16); // convert hex string to int
820 auto decompressed_data,
821 gfx::lc_lz2::DecompressV2(temp_rom_.data(), offset_value, 0x1000))
822 auto converted_sheet = gfx::SnesTo8bppSheet(decompressed_data, 3);
824 gfx::kTilesheetDepth, converted_sheet);
825 if (col_file_) {
826 gfx_sheets_[i].SetPalette(
828 } else {
829 // ROM palette
830 auto palette_group = rom()->palette_group().get_group(
832 z3_rom_palette_ = *palette_group->mutable_palette(current_palette_index_);
833 gfx_sheets_[i].SetPalette(z3_rom_palette_);
834 }
835
837 i++;
838 }
839 super_donkey_ = true;
841
842 return absl::OkStatus();
843}
844
845} // namespace editor
846} // namespace yaze
static GraphicsSheetManager & GetInstance()
Definition rom.h:272
std::array< gfx::Bitmap, kNumGfxSheets > & gfx_sheets()
Definition rom.h:278
auto palette_group() const
Definition rom.h:174
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath.
void UpdateBitmap(gfx::Bitmap *bitmap)
Used to update a bitmap on the screen.
Definition renderer.h:55
void RenderBitmap(gfx::Bitmap *bitmap)
Used to render a bitmap to the screen.
Definition renderer.h:48
bool * active()
Definition editor.h:87
std::vector< uint8_t > scr_data_
std::array< gfx::Bitmap, kNumLinkSheets > link_sheets_
gfx::PaletteGroup col_file_palette_group_
absl::Status Load() override
std::vector< uint8_t > decoded_cgx_
std::set< uint16_t > child_window_sheets_
std::array< gfx::Bitmap, kNumGfxSheets > gfx_sheets_
std::vector< uint8_t > cgx_data_
std::vector< uint8_t > import_data_
std::vector< SDL_Color > decoded_col_
std::set< uint16_t > open_sheets_
absl::Status Update() override
std::vector< uint8_t > extra_cgx_data_
std::vector< uint8_t > decoded_scr_data_
std::stack< uint16_t > release_queue_
gui::GfxSheetAssetBrowser asset_browser_
absl::Status DecompressImportData(int size)
static Renderer & GetInstance()
Definition renderer.h:26
Represents a bitmap image.
Definition bitmap.h:66
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
#define ICON_MD_MEMORY
Definition icons.h:1193
#define ICON_MD_DRAW
Definition icons.h:623
#define ICON_MD_ZOOM_OUT
Definition icons.h:2191
#define ICON_MD_FORMAT_COLOR_FILL
Definition icons.h:828
#define ICON_MD_CONTENT_PASTE
Definition icons.h:465
#define ICON_MD_ADD
Definition icons.h:84
#define ICON_MD_ZOOM_IN
Definition icons.h:2189
#define ICON_MD_SELECT_ALL
Definition icons.h:1678
#define ICON_MD_CONTENT_COPY
Definition icons.h:463
#define SETUP_COLUMN(l)
Definition macro.h:10
#define END_TABLE()
Definition macro.h:18
#define TABLE_HEADERS()
Definition macro.h:12
#define BEGIN_TABLE(l, n, f)
Definition macro.h:9
#define RETURN_IF_ERROR(expression)
Definition macro.h:51
#define END_TAB_ITEM()
Definition macro.h:5
#define NEXT_COLUMN()
Definition macro.h:16
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition macro.h:59
#define CLEAR_AND_RETURN_STATUS(status)
Definition macro.h:94
#define TAB_ITEM(w)
Definition macro.h:4
#define HOVER_HINT(string)
Definition macro.h:22
void GetImageFromClipboard(std::vector< uint8_t > &data, int &width, int &height)
Definition clipboard.cc:10
void CopyImageToClipboard(const std::vector< uint8_t > &data)
Definition clipboard.cc:9
Editors are the view controllers for the application.
const std::string kSuperDonkeySprites[]
constexpr ImGuiTableFlags kGfxEditTableFlags
const std::string kSuperDonkeyTiles[]
constexpr int kNintendoMode1
Definition compression.h:53
absl::StatusOr< std::vector< uint8_t > > DecompressV2(const uint8_t *data, int offset, int size, int mode)
Decompresses a buffer of data using the LC_LZ2 algorithm.
absl::Status LoadScr(std::string_view filename, uint8_t input_value, std::vector< uint8_t > &map_data)
Load Scr file (screen data)
std::vector< SDL_Color > DecodeColFile(const std::string_view filename)
Decode color file.
constexpr int kTilesheetHeight
Definition snes_tile.h:16
constexpr int kTilesheetWidth
Definition snes_tile.h:15
absl::Status LoadCgx(uint8_t bpp, std::string_view filename, std::vector< uint8_t > &cgx_data, std::vector< uint8_t > &cgx_loaded, std::vector< uint8_t > &cgx_header)
Load Cgx file (graphical content)
constexpr const char * kPaletteGroupAddressesKeys[]
absl::Status DrawScrWithCgx(uint8_t bpp, std::vector< uint8_t > &map_data, std::vector< uint8_t > &map_bitmap_data, std::vector< uint8_t > &cgx_loaded)
Draw screen tilemap with graphical data.
constexpr int kTilesheetDepth
Definition snes_tile.h:17
absl::StatusOr< PaletteGroup > CreatePaletteGroupFromColFile(std::vector< SnesColor > &palette_rows)
std::vector< SnesColor > GetColFileData(uint8_t *data)
Definition snes_color.cc:89
std::vector< uint8_t > SnesTo8bppSheet(const std::vector< uint8_t > &sheet, int bpp, int num_sheets)
Definition snes_tile.cc:139
void BitmapCanvasPipeline(gui::Canvas &canvas, gfx::Bitmap &bitmap, int width, int height, int tile_size, bool is_loaded, bool scrollbar, int canvas_id)
Definition canvas.cc:835
bool InputHex(const char *label, uint64_t *data)
Definition input.cc:142
void SelectablePalettePipeline(uint64_t &palette_id, bool &refresh_graphics, gfx::SnesPalette &palette)
Definition color.cc:127
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:175
void TextWithSeparators(const absl::string_view &text)
Definition style.cc:753
Main namespace for the application.
Definition controller.cc:18
absl::StatusOr< std::array< gfx::Bitmap, kNumLinkSheets > > LoadLinkGraphics(const Rom &rom)
Loads the players 4bpp graphics sheet from Rom data.
Definition rom.cc:58
constexpr uint32_t kNumGfxSheets
Definition rom.h:30