Add FileDialog data pipeline
This commit is contained in:
36
src/app/core/pipeline.cc
Normal file
36
src/app/core/pipeline.cc
Normal 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
27
src/app/core/pipeline.h
Normal 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
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/status/statusor.h"
|
||||
#include "app/core/pipeline.h"
|
||||
#include "app/editor/palette_editor.h"
|
||||
#include "app/gfx/bitmap.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::SameLine();
|
||||
// Open the file dialog when the user clicks the "Browse" button
|
||||
if (ImGui::Button("Open CGX")) {
|
||||
ImGuiFileDialog::Instance()->OpenDialog("ImportCgxKey", "Choose File",
|
||||
".CGX,.cgx\0", ".");
|
||||
}
|
||||
|
||||
if (ImGuiFileDialog::Instance()->Display("ImportCgxKey")) {
|
||||
if (ImGuiFileDialog::Instance()->IsOk()) {
|
||||
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_));
|
||||
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();
|
||||
}
|
||||
|
||||
core::FileDialogPipeline("ImportCgxKey", ".CGX,.cgx\0", "Open CGX", [&]() {
|
||||
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_));
|
||||
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());
|
||||
is_open_ = true;
|
||||
cgx_loaded_ = true;
|
||||
});
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "app/core/constants.h"
|
||||
#include "app/core/pipeline.h"
|
||||
#include "app/editor/assembly_editor.h"
|
||||
#include "app/editor/dungeon_editor.h"
|
||||
#include "app/editor/music_editor.h"
|
||||
@@ -84,18 +85,17 @@ void MasterEditor::UpdateScreen() {
|
||||
}
|
||||
|
||||
void MasterEditor::DrawFileDialog() {
|
||||
if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey")) {
|
||||
if (ImGuiFileDialog::Instance()->IsOk()) {
|
||||
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
|
||||
status_ = rom_.LoadFromFile(filePathName);
|
||||
overworld_editor_.SetupROM(rom_);
|
||||
graphics_editor_.SetupROM(rom_);
|
||||
screen_editor_.SetupROM(rom_);
|
||||
palette_editor_.SetupROM(rom_);
|
||||
music_editor_.SetupROM(rom_);
|
||||
}
|
||||
ImGuiFileDialog::Instance()->Close();
|
||||
}
|
||||
core::FileDialogPipeline("ChooseFileDlgKey", ".sfc,.smc", std::nullopt,
|
||||
[&]() {
|
||||
std::string filePathName =
|
||||
ImGuiFileDialog::Instance()->GetFilePathName();
|
||||
status_ = rom_.LoadFromFile(filePathName);
|
||||
overworld_editor_.SetupROM(rom_);
|
||||
graphics_editor_.SetupROM(rom_);
|
||||
screen_editor_.SetupROM(rom_);
|
||||
palette_editor_.SetupROM(rom_);
|
||||
music_editor_.SetupROM(rom_);
|
||||
});
|
||||
}
|
||||
|
||||
void MasterEditor::DrawStatusPopup() {
|
||||
|
||||
Reference in New Issue
Block a user