Remove ImGuiFileDialog integration and replace with FileDialogWrapper in assembly and tile editors

This commit is contained in:
scawful
2024-12-31 15:47:51 -05:00
parent c505c2f94c
commit 398ba36811
6 changed files with 95 additions and 142 deletions

View File

@@ -1,6 +1,5 @@
#include "assembly_editor.h"
#include "ImGuiFileDialog/ImGuiFileDialog.h"
#include "absl/strings/str_cat.h"
#include "app/core/platform/file_dialog.h"
#include "app/gui/icons.h"
@@ -277,21 +276,14 @@ void AssemblyEditor::DrawFileTabView() {
void AssemblyEditor::DrawFileMenu() {
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("Open", "Ctrl+O")) {
ImGuiFileDialog::Instance()->OpenDialog(
"ChooseASMFileDlg", "Open ASM file", ".asm,.txt", ".");
auto filename = core::FileDialogWrapper::ShowOpenFileDialog();
ChangeActiveFile(filename);
}
if (ImGui::MenuItem("Save", "Ctrl+S")) {
// TODO: Implement this
}
ImGui::EndMenu();
}
if (ImGuiFileDialog::Instance()->Display("ChooseASMFileDlg")) {
if (ImGuiFileDialog::Instance()->IsOk()) {
ChangeActiveFile(ImGuiFileDialog::Instance()->GetFilePathName());
}
ImGuiFileDialog::Instance()->Close();
}
}
void AssemblyEditor::DrawEditMenu() {

View File

@@ -1,9 +1,11 @@
#include "graphics_editor.h"
#include "ImGuiFileDialog/ImGuiFileDialog.h"
#include <filesystem>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "app/core/platform/clipboard.h"
#include "app/core/platform/file_dialog.h"
#include "app/core/platform/renderer.h"
#include "app/editor/graphics/palette_editor.h"
#include "app/gfx/bitmap.h"
@@ -514,22 +516,19 @@ absl::Status GraphicsEditor::DrawCgxImport() {
gui::TextWithSeparators("Cgx Import");
InputInt("BPP", &current_bpp_);
InputText("##CGXFile", cgx_file_name_, sizeof(cgx_file_name_));
InputText("##CGXFile", &cgx_file_name_);
SameLine();
gui::FileDialogPipeline("ImportCgxKey", ".CGX,.cgx\0", "Open CGX", [this]() {
strncpy(cgx_file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(cgx_file_path_));
strncpy(cgx_file_name_,
ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
sizeof(cgx_file_name_));
if (ImGui::Button("Open CGX")) {
auto filename = core::FileDialogWrapper::ShowOpenFileDialog();
cgx_file_name_ = filename;
cgx_file_path_ = std::filesystem::absolute(filename).string();
is_open_ = true;
cgx_loaded_ = true;
});
}
if (ImGui::Button("Copy CGX Path")) {
ImGui::SetClipboardText(cgx_file_path_);
ImGui::SetClipboardText(cgx_file_path_.c_str());
}
if (ImGui::Button("Load CGX Data")) {
@@ -547,19 +546,15 @@ absl::Status GraphicsEditor::DrawCgxImport() {
}
absl::Status GraphicsEditor::DrawScrImport() {
InputText("##ScrFile", scr_file_name_, sizeof(scr_file_name_));
InputText("##ScrFile", &scr_file_name_);
gui::FileDialogPipeline(
"ImportScrKey", ".SCR,.scr,.BAK\0", "Open SCR", [this]() {
strncpy(scr_file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(scr_file_path_));
strncpy(scr_file_name_,
ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
sizeof(scr_file_name_));
is_open_ = true;
scr_loaded_ = true;
});
if (ImGui::Button("Open SCR")) {
auto filename = core::FileDialogWrapper::ShowOpenFileDialog();
scr_file_name_ = filename;
scr_file_path_ = std::filesystem::absolute(filename).string();
is_open_ = true;
scr_loaded_ = true;
}
InputInt("SCR Mod", &scr_mod_value_);
@@ -583,38 +578,35 @@ absl::Status GraphicsEditor::DrawScrImport() {
absl::Status GraphicsEditor::DrawPaletteControls() {
gui::TextWithSeparators("COL Import");
InputText("##ColFile", col_file_name_, sizeof(col_file_name_));
InputText("##ColFile", &col_file_name_);
SameLine();
gui::FileDialogPipeline(
"ImportColKey", ".COL,.col,.BAK,.bak\0", "Open COL", [this]() {
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_));
status_ = temp_rom_.LoadFromFile(col_file_path_,
/*z3_load=*/false);
auto col_data_ = gfx::GetColFileData(temp_rom_.mutable_data());
if (col_file_palette_group_.size() != 0) {
col_file_palette_group_.clear();
}
auto col_file_palette_group_status =
gfx::CreatePaletteGroupFromColFile(col_data_);
if (col_file_palette_group_status.ok()) {
col_file_palette_group_ = col_file_palette_group_status.value();
}
col_file_palette_ = gfx::SnesPalette(col_data_);
if (ImGui::Button("Open COL")) {
auto filename = core::FileDialogWrapper::ShowOpenFileDialog();
col_file_name_ = filename;
col_file_path_ = std::filesystem::absolute(filename).string();
status_ = temp_rom_.LoadFromFile(col_file_path_,
/*z3_load=*/false);
auto col_data_ = gfx::GetColFileData(temp_rom_.mutable_data());
if (col_file_palette_group_.size() != 0) {
col_file_palette_group_.clear();
}
auto col_file_palette_group_status =
gfx::CreatePaletteGroupFromColFile(col_data_);
if (col_file_palette_group_status.ok()) {
col_file_palette_group_ = col_file_palette_group_status.value();
}
col_file_palette_ = gfx::SnesPalette(col_data_);
// gigaleak dev format based code
decoded_col_ = gfx::scad_format::DecodeColFile(col_file_path_);
col_file_ = true;
is_open_ = true;
});
// gigaleak dev format based code
decoded_col_ = gfx::scad_format::DecodeColFile(col_file_path_);
col_file_ = true;
is_open_ = true;
}
HOVER_HINT(".COL, .BAK");
if (ImGui::Button("Copy Col Path")) {
ImGui::SetClipboardText(col_file_path_);
ImGui::SetClipboardText(col_file_path_.c_str());
}
if (rom()->is_loaded()) {
@@ -635,17 +627,17 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
absl::Status GraphicsEditor::DrawObjImport() {
gui::TextWithSeparators("OBJ Import");
InputText("##ObjFile", obj_file_path_, sizeof(obj_file_path_));
InputText("##ObjFile", &obj_file_path_);
SameLine();
gui::FileDialogPipeline(
"ImportObjKey", ".obj,.OBJ,.bak,.BAK\0", "Open OBJ", [this]() {
strncpy(file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(file_path_));
status_ = temp_rom_.LoadFromFile(file_path_);
is_open_ = true;
});
if (ImGui::Button("Open OBJ")) {
auto filename = core::FileDialogWrapper::ShowOpenFileDialog();
obj_file_path_ = std::filesystem::absolute(filename).string();
status_ = temp_rom_.LoadFromFile(obj_file_path_);
is_open_ = true;
obj_loaded_ = true;
}
HOVER_HINT(".OBJ, .BAK");
return absl::OkStatus();
}
@@ -653,23 +645,22 @@ absl::Status GraphicsEditor::DrawObjImport() {
absl::Status GraphicsEditor::DrawTilemapImport() {
gui::TextWithSeparators("Tilemap Import");
InputText("##TMapFile", tilemap_file_path_, sizeof(tilemap_file_path_));
InputText("##TMapFile", &tilemap_file_path_);
SameLine();
gui::FileDialogPipeline(
"ImportTilemapKey", ".DAT,.dat,.BIN,.bin,.hex,.HEX\0", "Open Tilemap",
[this]() {
strncpy(tilemap_file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(tilemap_file_path_));
status_ = tilemap_rom_.LoadFromFile(tilemap_file_path_);
if (ImGui::Button("Open Tilemap")) {
auto filename = core::FileDialogWrapper::ShowOpenFileDialog();
tilemap_file_path_ = std::filesystem::absolute(filename).string();
status_ = tilemap_rom_.LoadFromFile(tilemap_file_path_);
status_ = tilemap_rom_.LoadFromFile(tilemap_file_path_);
// Extract the high and low bytes from the file.
auto decomp_sheet = gfx::lc_lz2::DecompressV2(
tilemap_rom_.data(), gfx::lc_lz2::kNintendoMode1);
tilemap_loaded_ = true;
is_open_ = true;
});
// Extract the high and low bytes from the file.
auto decomp_sheet = gfx::lc_lz2::DecompressV2(tilemap_rom_.data(),
gfx::lc_lz2::kNintendoMode1);
tilemap_loaded_ = true;
is_open_ = true;
}
HOVER_HINT(".DAT, .BIN, .HEX");
return absl::OkStatus();
}
@@ -677,30 +668,30 @@ absl::Status GraphicsEditor::DrawTilemapImport() {
absl::Status GraphicsEditor::DrawFileImport() {
gui::TextWithSeparators("BIN Import");
InputText("##ROMFile", file_path_, sizeof(file_path_));
InputText("##ROMFile", &file_path_);
SameLine();
gui::FileDialogPipeline("ImportDlgKey", ".bin,.hex\0", "Open BIN", [this]() {
strncpy(file_path_, ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(file_path_));
if (ImGui::Button("Open BIN")) {
auto filename = core::FileDialogWrapper::ShowOpenFileDialog();
file_path_ = filename;
status_ = temp_rom_.LoadFromFile(file_path_);
is_open_ = true;
});
}
HOVER_HINT(".BIN, .HEX");
if (Button("Copy File Path")) {
ImGui::SetClipboardText(file_path_);
ImGui::SetClipboardText(file_path_.c_str());
}
gui::InputHex("BIN Offset", &current_offset_);
gui::InputHex("BIN Size", &bin_size_);
if (Button("Decompress BIN")) {
if (strlen(file_path_) > 0) {
RETURN_IF_ERROR(DecompressImportData(bin_size_))
} else {
if (file_path_.empty()) {
return absl::InvalidArgumentError(
"Please select a file before importing.");
"Please select a file before decompressing.");
}
RETURN_IF_ERROR(DecompressImportData(bin_size_))
}
return absl::OkStatus();
@@ -739,13 +730,12 @@ absl::Status GraphicsEditor::DrawClipboardImport() {
absl::Status GraphicsEditor::DrawExperimentalFeatures() {
gui::TextWithSeparators("Experimental");
if (Button("Decompress Super Donkey Full")) {
if (strlen(file_path_) > 0) {
RETURN_IF_ERROR(DecompressSuperDonkey())
} else {
if (file_path_.empty()) {
return absl::InvalidArgumentError(
"Please select `super_donkey_1.bin` before "
"importing.");
}
RETURN_IF_ERROR(DecompressSuperDonkey())
}
ImGui::SetItemTooltip(
"Requires `super_donkey_1.bin` to be imported under the "

View File

@@ -4,12 +4,12 @@
#include <stack>
#include "absl/status/status.h"
#include "app/editor/graphics/palette_editor.h"
#include "app/editor/editor.h"
#include "app/editor/graphics/palette_editor.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_tile.h"
#include "app/gui/modules/asset_browser.h"
#include "app/gui/canvas.h"
#include "app/gui/modules/asset_browser.h"
#include "app/rom.h"
#include "app/zelda3/overworld/overworld.h"
#include "imgui/imgui.h"
@@ -142,16 +142,16 @@ class GraphicsEditor : public SharedRom, public Editor {
bool obj_loaded_ = false;
bool tilemap_loaded_ = false;
char file_path_[256] = "";
char col_file_path_[256] = "";
char col_file_name_[256] = "";
char cgx_file_path_[256] = "";
char cgx_file_name_[256] = "";
char scr_file_path_[256] = "";
char scr_file_name_[256] = "";
char obj_file_path_[256] = "";
char tilemap_file_path_[256] = "";
char tilemap_file_name_[256] = "";
std::string file_path_ = "";
std::string col_file_path_ = "";
std::string col_file_name_ = "";
std::string cgx_file_path_ = "";
std::string cgx_file_name_ = "";
std::string scr_file_path_ = "";
std::string scr_file_name_ = "";
std::string obj_file_path_ = "";
std::string tilemap_file_path_ = "";
std::string tilemap_file_name_ = "";
gui::GfxSheetAssetBrowser asset_browser_;

View File

@@ -2,12 +2,12 @@
#include <cmath>
#include "ImGuiFileDialog/ImGuiFileDialog.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "app/core/platform/file_dialog.h"
#include "app/core/platform/renderer.h"
#include "app/editor/graphics/palette_editor.h"
#include "app/editor/editor.h"
#include "app/editor/graphics/palette_editor.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h"
@@ -363,16 +363,10 @@ absl::Status Tile16Editor::UpdateTile16Transfer() {
absl::Status Tile16Editor::UpdateTransferTileCanvas() {
// Create a button for loading another ROM
if (Button("Load ROM")) {
ImGuiFileDialog::Instance()->OpenDialog(
"ChooseTransferFileDlgKey", "Open Transfer ROM", ".sfc,.smc", ".");
auto file_name = core::FileDialogWrapper::ShowOpenFileDialog();
transfer_status_ = transfer_rom_.LoadFromFile(file_name);
transfer_started_ = true;
}
gui::FileDialogPipeline(
"ChooseTransferFileDlgKey", ".sfc,.smc", std::nullopt, [&]() {
std::string filePathName =
ImGuiFileDialog::Instance()->GetFilePathName();
transfer_status_ = transfer_rom_.LoadFromFile(filePathName);
transfer_started_ = true;
});
// TODO: Implement tile16 transfer
if (transfer_started_ && !transfer_blockset_loaded_) {

View File

@@ -4,7 +4,6 @@
#include <optional>
#include <string>
#include "ImGuiFileDialog/ImGuiFileDialog.h"
#include "absl/strings/string_view.h"
#include "app/gfx/snes_tile.h"
#include "imgui/imgui.h"
@@ -257,23 +256,6 @@ bool InputTileInfo(const char* label, gfx::TileInfo* tile_info) {
ImGuiID GetID(const std::string& id) { return ImGui::GetID(id.c_str()); }
void FileDialogPipeline(absl::string_view display_key,
absl::string_view file_extensions,
std::optional<absl::string_view> button_text,
std::function<void()> callback) {
if (button_text.has_value() && ImGui::Button(button_text->data())) {
ImGuiFileDialog::Instance()->OpenDialog(display_key.data(), "Choose File",
file_extensions.data(), ".");
}
if (ImGuiFileDialog::Instance()->Display(
display_key.data(), ImGuiWindowFlags_NoCollapse, ImVec2(600, 400))) {
if (ImGuiFileDialog::Instance()->IsOk()) {
callback();
}
ImGuiFileDialog::Instance()->Close();
}
}
void AddTableColumn(Table &table, const std::string &label, GuiElement element) {
table.column_labels.push_back(label);
table.column_contents.push_back(element);

View File

@@ -52,11 +52,6 @@ IMGUI_API void ItemLabel(absl::string_view title, ItemLabelFlags flags);
IMGUI_API ImGuiID GetID(const std::string &id);
void FileDialogPipeline(absl::string_view display_key,
absl::string_view file_extensions,
std::optional<absl::string_view> button_text,
std::function<void()> callback);
using GuiElement = std::variant<std::function<void()>, std::string>;
struct Table {