Add FileDialog data pipeline

This commit is contained in:
scawful
2023-08-02 07:15:05 -04:00
parent 09d76f5f5d
commit 1d0419583d
5 changed files with 92 additions and 38 deletions

View File

@@ -3,6 +3,7 @@ set(
YAZE_APP_CORE_SRC YAZE_APP_CORE_SRC
app/core/common.cc app/core/common.cc
app/core/controller.cc app/core/controller.cc
app/core/pipeline.cc
) )
set( set(

36
src/app/core/pipeline.cc Normal file
View File

@@ -0,0 +1,36 @@
#include "pipeline.h"
#include <ImGuiFileDialog/ImGuiFileDialog.h>
#include <imgui/imgui.h>
#include <imgui/misc/cpp/imgui_stdlib.h>
#include <imgui_memory_editor.h>
#include <functional>
#include <optional>
#include "absl/strings/string_view.h"
namespace yaze {
namespace app {
namespace core {
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())) {
if (ImGuiFileDialog::Instance()->IsOk()) {
callback();
}
ImGuiFileDialog::Instance()->Close();
}
}
} // namespace core
} // namespace app
} // namespace yaze

27
src/app/core/pipeline.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef YAZE_APP_CORE_PIPELINE_H
#define YAZE_APP_CORE_PIPELINE_H
#include <ImGuiFileDialog/ImGuiFileDialog.h>
#include <imgui/imgui.h>
#include <imgui/misc/cpp/imgui_stdlib.h>
#include <imgui_memory_editor.h>
#include <functional>
#include <optional>
#include "absl/strings/string_view.h"
namespace yaze {
namespace app {
namespace core {
void FileDialogPipeline(absl::string_view display_key,
absl::string_view file_extensions,
std::optional<absl::string_view> button_text,
std::function<void()> callback);
} // namespace core
} // namespace app
} // namespace yaze
#endif

View File

@@ -7,6 +7,7 @@
#include "absl/status/status.h" #include "absl/status/status.h"
#include "absl/status/statusor.h" #include "absl/status/statusor.h"
#include "app/core/pipeline.h"
#include "app/editor/palette_editor.h" #include "app/editor/palette_editor.h"
#include "app/gfx/bitmap.h" #include "app/gfx/bitmap.h"
#include "app/gfx/compression.h" #include "app/gfx/compression.h"
@@ -80,32 +81,21 @@ absl::Status GraphicsEditor::DrawCgxImport() {
ImGui::InputText("##CGXFile", cgx_file_name_, sizeof(cgx_file_name_)); ImGui::InputText("##CGXFile", cgx_file_name_, sizeof(cgx_file_name_));
ImGui::SameLine(); ImGui::SameLine();
// Open the file dialog when the user clicks the "Browse" button core::FileDialogPipeline("ImportCgxKey", ".CGX,.cgx\0", "Open CGX", [&]() {
if (ImGui::Button("Open CGX")) { strncpy(cgx_file_path_,
ImGuiFileDialog::Instance()->OpenDialog("ImportCgxKey", "Choose File", ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
".CGX,.cgx\0", "."); sizeof(cgx_file_path_));
} strncpy(cgx_file_name_,
ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
if (ImGuiFileDialog::Instance()->Display("ImportCgxKey")) { sizeof(cgx_file_name_));
if (ImGuiFileDialog::Instance()->IsOk()) { RETURN_IF_ERROR(temp_rom_.LoadFromFile(cgx_file_path_, /*z3_load=*/false))
strncpy(cgx_file_path_, cgx_viewer_.LoadCgx(temp_rom_);
ImGuiFileDialog::Instance()->GetFilePathName().c_str(), auto all_tiles_data = cgx_viewer_.GetCgxData();
sizeof(cgx_file_path_)); cgx_bitmap_.Create(core::kTilesheetWidth, 8192, core::kTilesheetDepth,
strncpy(cgx_file_name_, all_tiles_data.data(), all_tiles_data.size());
ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(), is_open_ = true;
sizeof(cgx_file_name_)); cgx_loaded_ = true;
RETURN_IF_ERROR(temp_rom_.LoadFromFile(cgx_file_path_, /*z3_load=*/false)) });
cgx_viewer_.LoadCgx(temp_rom_);
auto all_tiles_data = cgx_viewer_.GetCgxData();
cgx_bitmap_.Create(core::kTilesheetWidth, 8192, core::kTilesheetDepth,
all_tiles_data.data(), all_tiles_data.size());
rom_.RenderBitmap(&cgx_bitmap_);
is_open_ = true;
cgx_loaded_ = true;
}
ImGuiFileDialog::Instance()->Close();
}
return absl::OkStatus(); return absl::OkStatus();
} }

View File

@@ -8,6 +8,7 @@
#include "absl/status/status.h" #include "absl/status/status.h"
#include "app/core/constants.h" #include "app/core/constants.h"
#include "app/core/pipeline.h"
#include "app/editor/assembly_editor.h" #include "app/editor/assembly_editor.h"
#include "app/editor/dungeon_editor.h" #include "app/editor/dungeon_editor.h"
#include "app/editor/music_editor.h" #include "app/editor/music_editor.h"
@@ -84,18 +85,17 @@ void MasterEditor::UpdateScreen() {
} }
void MasterEditor::DrawFileDialog() { void MasterEditor::DrawFileDialog() {
if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey")) { core::FileDialogPipeline("ChooseFileDlgKey", ".sfc,.smc", std::nullopt,
if (ImGuiFileDialog::Instance()->IsOk()) { [&]() {
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); std::string filePathName =
status_ = rom_.LoadFromFile(filePathName); ImGuiFileDialog::Instance()->GetFilePathName();
overworld_editor_.SetupROM(rom_); status_ = rom_.LoadFromFile(filePathName);
graphics_editor_.SetupROM(rom_); overworld_editor_.SetupROM(rom_);
screen_editor_.SetupROM(rom_); graphics_editor_.SetupROM(rom_);
palette_editor_.SetupROM(rom_); screen_editor_.SetupROM(rom_);
music_editor_.SetupROM(rom_); palette_editor_.SetupROM(rom_);
} music_editor_.SetupROM(rom_);
ImGuiFileDialog::Instance()->Close(); });
}
} }
void MasterEditor::DrawStatusPopup() { void MasterEditor::DrawStatusPopup() {