diff options
Diffstat (limited to 'src/editor.cpp')
| -rw-r--r-- | src/editor.cpp | 91 |
1 files changed, 90 insertions, 1 deletions
diff --git a/src/editor.cpp b/src/editor.cpp index c97f375..985167a 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -119,6 +119,80 @@ namespace silly::editor { } } + void Editor::createSavePackageWindow(const sf::RenderWindow &window) { + sf::Vector2u windowSize = window.getSize(); + + SavePackageState &state = this->savePackageState.value(); + + ImGui::SetNextWindowPos( + ImVec2(windowSize.x / 2.0f - 160, windowSize.y / 2.0f - 70)); + ImGui::SetNextWindowSize(ImVec2(320, 140)); + ImGui::Begin("Export package...", NULL, + ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize); + + std::string text_format, text_description; + + if (state.format == PACKAGE_TXT) { + text_format = "TXT"; + text_description = + "Represent level package as a .txt file\n" + "- File can be read by a human\n" + "- File can be imported to other editor\n" + "- Tileset is NOT embedded\n"; + } else { + text_format = "WTF"; + text_description = "uhhhh please make an issue about this on github"; + } + + if (ImGui::BeginCombo("Format", text_format.c_str())) { + for (int i = 0; i < 1; i++) { + bool is_selected = state.format == (LevelPackageFormat)i; + + std::string text_format; + + if (state.format == PACKAGE_TXT) { + text_format = "TXT"; + } else { + text_format = "WTF"; + } + + if (ImGui::Selectable(text_format.c_str(), is_selected)) { + state.format = (LevelPackageFormat)i; + } + + if (is_selected) ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } + + ImGui::Text(text_description.c_str()); + + if (ImGui::Button("Export")) { + NFD::UniquePath outPath; + + nfdresult_t result; + + if (state.format == PACKAGE_TXT) { + result = NFD::PickFolder(outPath); + } else { + result = NFD::SaveDialog(outPath); + } + + if (result == NFD_OKAY) { + state.path = outPath.get(); + this->package.save(state.format, state.path); + ImGui::SetWindowCollapsed(true); + } + } + + if (ImGui::IsWindowCollapsed()) { + ImGui::SetWindowCollapsed(false); + this->savePackageState = std::nullopt; + } + + ImGui::End(); + } + void Editor::createNewFloor(const sf::RenderWindow &window) { if (!this->newFloorState.has_value()) { this->newFloorState = std::make_optional((NewFloorState){}); @@ -193,6 +267,15 @@ namespace silly::editor { if (ImGui::BeginMainMenuBar()) { if (ImGui::BeginMenu("File")) { + if (!pkg.get_levels().empty() && + !pkg.get_current_level().get_floors().empty()) { + if (ImGui::MenuItem("Export")) { + this->savePackageState = std::make_optional((SavePackageState){}); + } + + ImGui::Separator(); + } + if (ImGui::MenuItem("Quit")) { window.close(); } @@ -320,7 +403,8 @@ namespace silly::editor { ImGui::EndChild(); ImGui::BeginDisabled(this->newLevelState.has_value() || - this->newFloorState.has_value()); + this->newFloorState.has_value() || + this->savePackageState.has_value()); // --- TILE SELECTION --- ImGui::BeginChild("TileSelectionRegion", ImVec2(0, 400), ImGuiChildFlags_Border, @@ -438,6 +522,11 @@ namespace silly::editor { this->createNewFloor(window); return; } + + if (this->savePackageState.has_value()) { + this->createSavePackageWindow(window); + return; + } } const float Editor::get_zoom() const { return this->zoom; } |
