CgxViewer updates

This commit is contained in:
scawful
2023-08-01 20:15:15 -04:00
parent fd3a61a437
commit 952ce1e3dc
5 changed files with 81 additions and 95 deletions

View File

@@ -29,6 +29,7 @@ absl::Status GraphicsEditor::Update() {
NEXT_COLUMN()
status_ = DrawFileImport();
status_ = DrawExperimentalFeatures();
status_ = DrawPaletteControls();
NEXT_COLUMN()
@@ -51,10 +52,10 @@ absl::Status GraphicsEditor::DrawFileImport() {
gui::TextWithSeparators("File Import");
ImGui::InputText("File", file_path_, sizeof(file_path_));
ImGui::InputText("##ROMFile", file_path_, sizeof(file_path_));
ImGui::SameLine();
// Open the file dialog when the user clicks the "Browse" button
if (ImGui::Button("Browse")) {
if (ImGui::Button("Open BIN")) {
ImGuiFileDialog::Instance()->OpenDialog("ImportDlgKey", "Choose File",
".bin\0.hex\0", ".");
}
@@ -86,15 +87,6 @@ absl::Status GraphicsEditor::DrawFileImport() {
}
}
if (ImGui::Button("Import Super Donkey Full")) {
if (strlen(file_path_) > 0) {
RETURN_IF_ERROR(DecompressSuperDonkey())
} else {
return absl::InvalidArgumentError(
"Please select `super_donkey_1.bin` before importing.");
}
}
gui::TextWithSeparators("Clipboard Import");
RETURN_IF_ERROR(DrawClipboardImport())
@@ -108,12 +100,12 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
ImGui::Combo("Palette", &current_palette_, kPaletteGroupAddressesKeys,
IM_ARRAYSIZE(kPaletteGroupAddressesKeys));
ImGui::InputText("COL File", col_file_path_, sizeof(col_file_path_));
ImGui::InputText("##ColFile", col_file_name_, sizeof(col_file_name_));
ImGui::SameLine();
// Open the file dialog when the user clicks the "Browse" button
if (ImGui::Button("Browse")) {
if (ImGui::Button("Open COL")) {
ImGuiFileDialog::Instance()->OpenDialog("ImportColKey", "Choose File",
".col\0", ".");
".col", ".");
}
if (ImGuiFileDialog::Instance()->Display("ImportColKey")) {
@@ -121,6 +113,9 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
strncpy(col_file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(col_file_path_));
strncpy(col_file_name_,
ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
sizeof(col_file_name_));
RETURN_IF_ERROR(temp_rom_.LoadFromFile(col_file_path_, /*z3_load=*/false))
auto col_data_ = gfx::GetColFileData(temp_rom_.data());
col_file_palette_ = gfx::SNESPalette(col_data_);
@@ -131,6 +126,7 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
}
if (col_file_palette_.size() != 0) {
ImGuiFileDialog::Instance()->prDrawFileListView(ImVec2(0, 200));
palette_editor_.DrawPortablePalette(col_file_palette_);
}
@@ -153,11 +149,24 @@ absl::Status GraphicsEditor::DrawClipboardImport() {
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawExperimentalFeatures() {
gui::TextWithSeparators("Experimental");
if (ImGui::Button("Import Super Donkey Full")) {
if (strlen(file_path_) > 0) {
RETURN_IF_ERROR(DecompressSuperDonkey())
} else {
return absl::InvalidArgumentError(
"Please select `super_donkey_1.bin` before importing.");
}
}
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawMemoryEditor() {
std::string title = "Memory Editor";
if (is_open_) {
static MemoryEditor mem_edit;
mem_edit.DrawContents(temp_rom_.data(), temp_rom_.size());
mem_edit.DrawWindow(title.c_str(), temp_rom_.data(), temp_rom_.size());
}
return absl::OkStatus();
}
@@ -177,31 +186,6 @@ absl::Status GraphicsEditor::DrawDecompressedData() {
return absl::OkStatus();
}
absl::Status GraphicsEditor::DecompressImportData(int size) {
ASSIGN_OR_RETURN(import_data_, gfx::lc_lz2::DecompressV2(
temp_rom_.data(), current_offset_, size))
std::cout << "Size of import data " << import_data_.size() << std::endl;
auto converted_sheet = gfx::SnesTo8bppSheet(import_data_, 3);
bitmap_.Create(core::kTilesheetWidth, 0x2000, core::kTilesheetDepth,
converted_sheet.data(), size);
if (rom_.isLoaded()) {
auto palette_group = rom_.GetPaletteGroup("ow_main");
palette_ = palette_group.palettes[current_palette_];
if (col_file_) {
bitmap_.ApplyPalette(col_file_palette_);
} else {
bitmap_.ApplyPalette(palette_);
}
}
rom_.RenderBitmap(&bitmap_);
gfx_loaded_ = true;
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawGraphicsBin() {
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)3);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
@@ -230,6 +214,30 @@ absl::Status GraphicsEditor::DrawGraphicsBin() {
return absl::OkStatus();
}
absl::Status GraphicsEditor::DecompressImportData(int size) {
ASSIGN_OR_RETURN(import_data_, gfx::lc_lz2::DecompressV2(
temp_rom_.data(), current_offset_, size))
auto converted_sheet = gfx::SnesTo8bppSheet(import_data_, 3);
bitmap_.Create(core::kTilesheetWidth, 0x2000, core::kTilesheetDepth,
converted_sheet.data(), size);
if (rom_.isLoaded()) {
auto palette_group = rom_.GetPaletteGroup("ow_main");
palette_ = palette_group.palettes[current_palette_];
if (col_file_) {
bitmap_.ApplyPalette(col_file_palette_);
} else {
bitmap_.ApplyPalette(palette_);
}
}
rom_.RenderBitmap(&bitmap_);
gfx_loaded_ = true;
return absl::OkStatus();
}
absl::Status GraphicsEditor::DecompressSuperDonkey() {
if (rom_.isLoaded()) {
auto palette_group =

View File

@@ -14,6 +14,7 @@
#include "app/gui/canvas.h"
#include "app/gui/input.h"
#include "app/rom.h"
#include "app/viewer/cgx_viewer.h"
namespace yaze {
namespace app {
@@ -60,13 +61,13 @@ class GraphicsEditor {
absl::Status DrawFileImport();
absl::Status DrawPaletteControls();
absl::Status DrawClipboardImport();
absl::Status DrawExperimentalFeatures();
absl::Status DrawMemoryEditor();
absl::Status DrawDecompressedData();
absl::Status DrawGraphicsBin();
absl::Status DecompressImportData(int size);
absl::Status DrawGraphicsBin();
absl::Status DecompressSuperDonkey();
int current_offset_ = 0;
@@ -80,6 +81,7 @@ class GraphicsEditor {
bool col_file_ = false;
char file_path_[256] = "";
char col_file_path_[256] = "";
char col_file_name_[256] = "";
ROM rom_;
ROM temp_rom_;
@@ -98,6 +100,8 @@ class GraphicsEditor {
gfx::SNESPalette palette_;
gfx::SNESPalette col_file_palette_;
viewer::CgxViewer cgx_viewer_;
absl::Status status_;
};

View File

@@ -202,7 +202,7 @@ void PaletteEditor::DrawPortablePalette(gfx::SNESPalette& palette) {
init = true;
}
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)3);
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)100);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
ImGui::BeginGroup(); // Lock X position