GraphicsEditor supports clipboard input
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
#include "app/gfx/snes_tile.h"
|
#include "app/gfx/snes_tile.h"
|
||||||
#include "app/gui/canvas.h"
|
#include "app/gui/canvas.h"
|
||||||
#include "app/gui/input.h"
|
#include "app/gui/input.h"
|
||||||
|
#include "app/gui/style.h"
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
@@ -20,37 +21,36 @@ namespace app {
|
|||||||
namespace editor {
|
namespace editor {
|
||||||
|
|
||||||
absl::Status GraphicsEditor::Update() {
|
absl::Status GraphicsEditor::Update() {
|
||||||
BEGIN_TABLE("#gfxEditTable", 3, gfx_edit_flags)
|
BEGIN_TABLE("#gfxEditTable", 3, kGfxEditFlags)
|
||||||
SETUP_COLUMN("Graphics Manager")
|
SETUP_COLUMN("Graphics Manager")
|
||||||
SETUP_COLUMN("Memory Editor")
|
SETUP_COLUMN("Memory Editor")
|
||||||
SETUP_COLUMN("Preview")
|
SETUP_COLUMN("Preview")
|
||||||
TABLE_HEADERS()
|
TABLE_HEADERS()
|
||||||
NEXT_COLUMN()
|
NEXT_COLUMN()
|
||||||
|
|
||||||
TAB_BAR("##GfxTabBar")
|
status_ = DrawFileImport();
|
||||||
TAB_ITEM("File Import")
|
status_ = DrawPaletteControls();
|
||||||
RETURN_IF_ERROR(DrawFileImport())
|
|
||||||
END_TAB_ITEM()
|
|
||||||
TAB_ITEM("Clipboard Import")
|
|
||||||
RETURN_IF_ERROR(DrawClipboardImport())
|
|
||||||
END_TAB_ITEM()
|
|
||||||
END_TAB_BAR()
|
|
||||||
RETURN_IF_ERROR(DrawPaletteControls())
|
|
||||||
|
|
||||||
NEXT_COLUMN()
|
NEXT_COLUMN()
|
||||||
RETURN_IF_ERROR(DrawMemoryEditor())
|
RETURN_IF_ERROR(DrawMemoryEditor())
|
||||||
|
|
||||||
NEXT_COLUMN()
|
NEXT_COLUMN()
|
||||||
RETURN_IF_ERROR(DrawDecompressedData())
|
if (super_donkey_) {
|
||||||
|
status_ = DrawGraphicsBin();
|
||||||
|
} else {
|
||||||
|
status_ = DrawDecompressedData();
|
||||||
|
}
|
||||||
END_TABLE()
|
END_TABLE()
|
||||||
|
|
||||||
|
CLEAR_AND_RETURN_STATUS(status_)
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status GraphicsEditor::DrawFileImport() {
|
absl::Status GraphicsEditor::DrawFileImport() {
|
||||||
static int size = 0;
|
static int size = 0;
|
||||||
|
|
||||||
|
gui::TextWithSeparators("File Import");
|
||||||
|
|
||||||
ImGui::InputText("File", file_path_, sizeof(file_path_));
|
ImGui::InputText("File", file_path_, sizeof(file_path_));
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
// Open the file dialog when the user clicks the "Browse" button
|
// Open the file dialog when the user clicks the "Browse" button
|
||||||
@@ -76,32 +76,34 @@ absl::Status GraphicsEditor::DrawFileImport() {
|
|||||||
|
|
||||||
gui::InputHex("Offset", ¤t_offset_);
|
gui::InputHex("Offset", ¤t_offset_);
|
||||||
gui::InputHex("Size ", &size);
|
gui::InputHex("Size ", &size);
|
||||||
gui::InputHex("Palette ", ¤t_palette_);
|
|
||||||
|
|
||||||
if (ImGui::Button("Super Donkey Offsets")) {
|
|
||||||
current_offset_ = 0x98219;
|
|
||||||
size = 0x30000;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
|
|
||||||
if (ImGui::Button("Import")) {
|
if (ImGui::Button("Import")) {
|
||||||
if (strlen(file_path_) > 0) {
|
if (strlen(file_path_) > 0) {
|
||||||
// Add your importing code here, using file_path_ and offset as parameters
|
|
||||||
RETURN_IF_ERROR(DecompressImportData(size))
|
RETURN_IF_ERROR(DecompressImportData(size))
|
||||||
} else {
|
} else {
|
||||||
// Show an error message if no file has been selected
|
return absl::InvalidArgumentError(
|
||||||
ImGui::Text("Please select a file before importing.");
|
"Please select a file before importing.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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())
|
||||||
|
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status GraphicsEditor::DrawPaletteControls() {
|
absl::Status GraphicsEditor::DrawPaletteControls() {
|
||||||
ImGui::Separator();
|
gui::TextWithSeparators("Palette");
|
||||||
ImGui::Text("Palette");
|
gui::InputHex("Palette Index", ¤t_palette_index_);
|
||||||
ImGui::Separator();
|
|
||||||
|
|
||||||
ImGui::Combo("Palette", ¤t_palette_, kPaletteGroupAddressesKeys,
|
ImGui::Combo("Palette", ¤t_palette_, kPaletteGroupAddressesKeys,
|
||||||
IM_ARRAYSIZE(kPaletteGroupAddressesKeys));
|
IM_ARRAYSIZE(kPaletteGroupAddressesKeys));
|
||||||
@@ -125,8 +127,6 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
|
|||||||
col_file_ = true;
|
col_file_ = true;
|
||||||
is_open_ = true;
|
is_open_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the modal
|
|
||||||
ImGuiFileDialog::Instance()->Close();
|
ImGuiFileDialog::Instance()->Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,13 +140,14 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
|
|||||||
absl::Status GraphicsEditor::DrawClipboardImport() {
|
absl::Status GraphicsEditor::DrawClipboardImport() {
|
||||||
static Bytes clipboard_data;
|
static Bytes clipboard_data;
|
||||||
|
|
||||||
ImGui::Button("Paste");
|
if (ImGui::Button("Paste from Clipboard")) {
|
||||||
|
const char* text = ImGui::GetClipboardText();
|
||||||
if (!is_open_) {
|
if (text) {
|
||||||
clipboard_data.resize(0x1000);
|
clipboard_data = Bytes(text, text + strlen(text));
|
||||||
for (int i = 0; i < 0x1000; i++) clipboard_data.push_back(0x00);
|
ImGui::MemFree((void*)text);
|
||||||
RETURN_IF_ERROR(temp_rom_.LoadFromBytes(clipboard_data))
|
RETURN_IF_ERROR(temp_rom_.LoadFromBytes(clipboard_data))
|
||||||
is_open_ = true;
|
is_open_ = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
@@ -201,20 +202,76 @@ absl::Status GraphicsEditor::DecompressImportData(int size) {
|
|||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
absl::Status GraphicsEditor::DrawGraphicsBin() {
|
||||||
|
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)3);
|
||||||
|
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
|
||||||
|
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
|
||||||
|
super_donkey_canvas_.DrawBackground(
|
||||||
|
ImVec2(0x100 + 1, num_sheets_to_load_ * 0x40 + 1));
|
||||||
|
super_donkey_canvas_.DrawContextMenu();
|
||||||
|
if (super_donkey_) {
|
||||||
|
for (const auto& [key, value] : graphics_bin_) {
|
||||||
|
int offset = 0x40 * (key + 1);
|
||||||
|
int top_left_y = super_donkey_canvas_.GetZeroPoint().y + 2;
|
||||||
|
if (key >= 1) {
|
||||||
|
top_left_y = super_donkey_canvas_.GetZeroPoint().y + 0x40 * key;
|
||||||
|
}
|
||||||
|
super_donkey_canvas_.GetDrawList()->AddImage(
|
||||||
|
(void*)value.GetTexture(),
|
||||||
|
ImVec2(super_donkey_canvas_.GetZeroPoint().x + 2, top_left_y),
|
||||||
|
ImVec2(super_donkey_canvas_.GetZeroPoint().x + 0x100,
|
||||||
|
super_donkey_canvas_.GetZeroPoint().y + offset));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super_donkey_canvas_.DrawGrid(16.0f);
|
||||||
|
super_donkey_canvas_.DrawOverlay();
|
||||||
|
}
|
||||||
|
ImGui::EndChild();
|
||||||
|
return absl::OkStatus();
|
||||||
|
}
|
||||||
|
|
||||||
absl::Status GraphicsEditor::DecompressSuperDonkey() {
|
absl::Status GraphicsEditor::DecompressSuperDonkey() {
|
||||||
|
if (rom_.isLoaded()) {
|
||||||
|
auto palette_group =
|
||||||
|
rom_.GetPaletteGroup(kPaletteGroupAddressesKeys[current_palette_]);
|
||||||
|
palette_ = palette_group.palettes[current_palette_index_];
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
for (const auto& offset : kSuperDonkeyTiles) {
|
for (const auto& offset : kSuperDonkeyTiles) {
|
||||||
int offset_value =
|
int offset_value =
|
||||||
std::stoi(offset, nullptr, 16); // convert hex string to int
|
std::stoi(offset, nullptr, 16); // convert hex string to int
|
||||||
ASSIGN_OR_RETURN(auto decompressed_data,
|
ASSIGN_OR_RETURN(
|
||||||
temp_rom_.Decompress(offset_value, 0x1000))
|
auto decompressed_data,
|
||||||
|
gfx::lc_lz2::DecompressV2(temp_rom_.data(), offset_value, 0x1000))
|
||||||
|
auto converted_sheet = gfx::SnesTo8bppSheet(decompressed_data, 3);
|
||||||
|
graphics_bin_[i] =
|
||||||
|
gfx::Bitmap(core::kTilesheetWidth, core::kTilesheetHeight,
|
||||||
|
core::kTilesheetDepth, converted_sheet.data(), 0x1000);
|
||||||
|
graphics_bin_[i].ApplyPalette(palette_);
|
||||||
|
|
||||||
|
rom_.RenderBitmap(&graphics_bin_[i]);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& offset : kSuperDonkeySprites) {
|
for (const auto& offset : kSuperDonkeySprites) {
|
||||||
int offset_value =
|
int offset_value =
|
||||||
std::stoi(offset, nullptr, 16); // convert hex string to int
|
std::stoi(offset, nullptr, 16); // convert hex string to int
|
||||||
ASSIGN_OR_RETURN(auto decompressed_data,
|
ASSIGN_OR_RETURN(
|
||||||
temp_rom_.Decompress(offset_value, 0x1000))
|
auto decompressed_data,
|
||||||
|
gfx::lc_lz2::DecompressV2(temp_rom_.data(), offset_value, 0x1000))
|
||||||
|
auto converted_sheet = gfx::SnesTo8bppSheet(decompressed_data, 3);
|
||||||
|
graphics_bin_[i] =
|
||||||
|
gfx::Bitmap(core::kTilesheetWidth, core::kTilesheetHeight,
|
||||||
|
core::kTilesheetDepth, converted_sheet.data(), 0x1000);
|
||||||
|
graphics_bin_[i].ApplyPalette(palette_);
|
||||||
|
|
||||||
|
rom_.RenderBitmap(&graphics_bin_[i]);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
super_donkey_ = true;
|
||||||
|
num_sheets_to_load_ = i;
|
||||||
|
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ constexpr char* kPaletteGroupAddressesKeys[] = {
|
|||||||
"grass", "3d_object", "ow_mini_map",
|
"grass", "3d_object", "ow_mini_map",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr ImGuiTableFlags kGfxEditFlags = ImGuiTableFlags_Reorderable |
|
||||||
|
ImGuiTableFlags_Resizable |
|
||||||
|
ImGuiTableFlags_SizingStretchSame;
|
||||||
|
|
||||||
class GraphicsEditor {
|
class GraphicsEditor {
|
||||||
public:
|
public:
|
||||||
absl::Status Update();
|
absl::Status Update();
|
||||||
@@ -61,36 +65,40 @@ class GraphicsEditor {
|
|||||||
|
|
||||||
absl::Status DecompressImportData(int size);
|
absl::Status DecompressImportData(int size);
|
||||||
|
|
||||||
|
absl::Status DrawGraphicsBin();
|
||||||
|
|
||||||
absl::Status DecompressSuperDonkey();
|
absl::Status DecompressSuperDonkey();
|
||||||
|
|
||||||
int current_offset_ = 0;
|
int current_offset_ = 0;
|
||||||
int current_size_ = 0;
|
int current_size_ = 0;
|
||||||
int current_palette_ = 0;
|
int current_palette_ = 0;
|
||||||
|
int current_palette_index_ = 0;
|
||||||
|
int num_sheets_to_load_ = 1;
|
||||||
bool gfx_loaded_ = false;
|
bool gfx_loaded_ = false;
|
||||||
bool is_open_ = false;
|
bool is_open_ = false;
|
||||||
bool super_donkey_ = false;
|
bool super_donkey_ = false;
|
||||||
bool col_file_ = false;
|
bool col_file_ = false;
|
||||||
char file_path_[256];
|
char file_path_[256] = "";
|
||||||
char col_file_path_[256];
|
char col_file_path_[256] = "";
|
||||||
|
|
||||||
ROM rom_;
|
ROM rom_;
|
||||||
ROM temp_rom_;
|
ROM temp_rom_;
|
||||||
Bytes import_data_;
|
Bytes import_data_;
|
||||||
Bytes graphics_buffer_;
|
Bytes graphics_buffer_;
|
||||||
|
|
||||||
|
MemoryEditor memory_editor_;
|
||||||
|
PaletteEditor palette_editor_;
|
||||||
|
|
||||||
gfx::Bitmap bitmap_;
|
gfx::Bitmap bitmap_;
|
||||||
gui::Canvas import_canvas_;
|
gui::Canvas import_canvas_;
|
||||||
gfx::BitmapTable graphics_bin_;
|
|
||||||
|
|
||||||
PaletteEditor palette_editor_;
|
gui::Canvas super_donkey_canvas_;
|
||||||
MemoryEditor memory_editor_;
|
gfx::BitmapTable graphics_bin_;
|
||||||
|
|
||||||
gfx::SNESPalette palette_;
|
gfx::SNESPalette palette_;
|
||||||
gfx::SNESPalette col_file_palette_;
|
gfx::SNESPalette col_file_palette_;
|
||||||
|
|
||||||
ImGuiTableFlags gfx_edit_flags = ImGuiTableFlags_Reorderable |
|
absl::Status status_;
|
||||||
ImGuiTableFlags_Resizable |
|
|
||||||
ImGuiTableFlags_SizingStretchSame;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace editor
|
} // namespace editor
|
||||||
|
|||||||
Reference in New Issue
Block a user