diff --git a/shared/library_manager.cpp b/shared/library_manager.cpp index ca9af62..3703663 100644 --- a/shared/library_manager.cpp +++ b/shared/library_manager.cpp @@ -1,6 +1,7 @@ #include "library_manager.h" #include "tlv.h" #include +#include #include "json.hpp" #include "story_project.h" @@ -102,13 +103,16 @@ void LibraryManager::Save() tlv.add_array(m_projectsList.size()); for (auto &p : m_projectsList) { - tlv.add_object(6); - tlv.add_string(p->GetUuid()); - tlv.add_string(p->GetTitleImage()); - tlv.add_string(p->GetTitleSound()); - tlv.add_string(p->GetName()); - tlv.add_string(p->GetDescription()); - tlv.add_integer(p->GetVersion()); + if (p->IsSelected()) + { + tlv.add_object(6); + tlv.add_string(p->GetUuid()); + tlv.add_string(p->GetTitleImage()); + tlv.add_string(p->GetTitleSound()); + tlv.add_string(p->GetName()); + tlv.add_string(p->GetDescription()); + tlv.add_integer(p->GetVersion()); + } } /* @@ -123,6 +127,14 @@ void LibraryManager::Save() */ } + +void LibraryManager::CopyToDevice(const std::string &outputDir) +{ + std::thread myThread([&]() { + myThread.detach(); + }); +} + bool LibraryManager::IsInitialized() const { return m_library_path.size() > 0; diff --git a/shared/library_manager.h b/shared/library_manager.h index 830e7a2..9786607 100644 --- a/shared/library_manager.h +++ b/shared/library_manager.h @@ -20,9 +20,15 @@ public: std::vector>::const_iterator begin() const { return m_projectsList.begin(); } std::vector>::const_iterator end() const { return m_projectsList.end(); } + uint32_t ProjectsCount() const { return m_projectsList.size(); }; + void Save(); void Scan(); + // Copie toutes les histoires sélectionnées vers un répertoire + // On va ne copier que les fichiers de sortie au format désiré + void CopyToDevice(const std::string &outputDir); + std::shared_ptr NewProject(); void CheckDirectories(); diff --git a/shared/story_project.h b/shared/story_project.h index f641fda..47d5631 100644 --- a/shared/story_project.h +++ b/shared/story_project.h @@ -67,6 +67,9 @@ public: void CreateTree(); void Clear(); + + void Select(bool selected) { m_selected = selected; } + bool IsSelected() const { return m_selected; } void SetImageFormat(ImageFormat format); void SetSoundFormat(SoundFormat format); @@ -105,8 +108,6 @@ public: static void EraseString(std::string &theString, const std::string &toErase); static std::string ToUpper(const std::string &input); - - bool ParseStoryInformation(nlohmann::json &j); private: // Project properties and location @@ -116,6 +117,7 @@ private: std::string m_titleSound; std::string m_description; int m_version; + bool m_selected{false}; std::filesystem::path m_assetsPath; diff --git a/story-editor/CMakeLists.txt b/story-editor/CMakeLists.txt index 229f62f..77c6317 100644 --- a/story-editor/CMakeLists.txt +++ b/story-editor/CMakeLists.txt @@ -322,7 +322,7 @@ if(UNIX) SDL3::SDL3 SDL3_image::SDL3_image libcurl_static - OpenSSL::SSL OpenSSL::Crypto + # OpenSSL::SSL OpenSSL::Crypto ) elseif(WIN32) target_link_libraries(${STORY_EDITOR_PROJECT} diff --git a/story-editor/src/library_window.cpp b/story-editor/src/library_window.cpp index 3663dbe..cfcab78 100644 --- a/story-editor/src/library_window.cpp +++ b/story-editor/src/library_window.cpp @@ -17,27 +17,30 @@ void download_file(CURL *curl, std::function finished_callback) { FILE *fp; - CURLcode res; + CURLcode res = CURLE_FAILED_INIT; if (curl) { //SetConsoleTextAttribute(hConsole, 11); fp = fopen(output_file.c_str(),"wb"); - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); - std::cout<<" Start download"<OpenDialog("ChooseLibraryDirDialog", "Choose a library directory", nullptr, config); } + if (ImGui::Button(ICON_MDI_FOLDER " Export to device")) + { + IGFD::FileDialogConfig config; + config.path = "."; + config.countSelectionMax = 1; + config.flags = ImGuiFileDialogFlags_Modal; + + ImGuiFileDialog::Instance()->OpenDialog("ChooseOutputDirDialog", "Choose an output directory", nullptr, config); + } + if (!m_libraryManager.IsInitialized()) { ImGui::SameLine(); @@ -425,38 +438,40 @@ void LibraryWindow::Draw() ); } - if (ImGui::BeginTable("library_table", 3, tableFlags)) { ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed); ImGui::TableSetupColumn("Select", ImGuiTableColumnFlags_WidthFixed); ImGui::TableSetupColumn("Actions", ImGuiTableColumnFlags_WidthFixed); - ImGui::TableNextRow(ImGuiTableRowFlags_Headers); - ImGui::TableSetColumnIndex(0); - ImGui::TableHeader(ImGui::TableGetColumnName(0)); - - - static bool column_selected = false; + ImGui::TableSetColumnIndex(0); + ImGui::TableHeader(ImGui::TableGetColumnName(0)); + static bool select_all = false; + ImGui::TableSetColumnIndex(1); const char* column_name = ImGui::TableGetColumnName(1); // Retrieve name passed to TableSetupColumn() ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); - ImGui::Checkbox("##checkall", &column_selected); + if (ImGui::Checkbox("##checkall", &select_all)) + { + // Mettre à jour tous les checkboxes des lignes en fonction de l'état du checkbox de l'en-tête + for (auto &p : m_libraryManager) + { + p->Select(select_all); + } + } ImGui::PopStyleVar(); ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x); ImGui::TableHeader(column_name); - ImGui::TableSetColumnIndex(2); - ImGui::TableHeader(ImGui::TableGetColumnName(2)); + ImGui::TableHeader(ImGui::TableGetColumnName(2)); - - - int internal_id = 1; + int internal_id = 1; + uint32_t row = 0; for (auto &p : m_libraryManager) { ImGui::TableNextColumn(); @@ -465,16 +480,23 @@ void LibraryWindow::Draw() ImGui::PushID(internal_id++); // Select + ImGui::TableNextColumn(); - ImGui::Checkbox("", &column_selected); + bool state = p->IsSelected(); + ImGui::Checkbox("", &state); + if (!state && select_all) + { + select_all = false; // Désélectionner "Select All" si un des items est désélectionné + } + + row++; ImGui::TableNextColumn(); if (ImGui::SmallButton("Load")) { m_storyManager.OpenProject(p->GetUuid()); } - ImGui::SameLine(); if (ImGui::SmallButton("Remove")) @@ -599,7 +621,8 @@ void LibraryWindow::Draw() // ---------------- CHOOSE LIBRARY DIR - if (ImGuiFileDialog::Instance()->Display("ChooseLibraryDirDialog")) + static ImGuiWindowFlags window_flags = 0; + if (ImGuiFileDialog::Instance()->Display("ChooseLibraryDirDialog", window_flags, ImVec2(300, 200))) { // action if OK if (ImGuiFileDialog::Instance()->IsOk()) @@ -617,6 +640,30 @@ void LibraryWindow::Draw() ImGuiFileDialog::Instance()->Close(); } + // ---------------- EXPORT SELECTED STORIES TO SPECIFIED DIRECTORY + static ImGuiWindowFlags choose_output_window_flags = 0; + if (ImGuiFileDialog::Instance()->Display("ChooseOutputDirDialog", choose_output_window_flags, ImVec2(300, 200))) + { + // action if OK + if (ImGuiFileDialog::Instance()->IsOk()) + { + std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); + std::string outputDir = ImGuiFileDialog::Instance()->GetCurrentPath(); + + if (std::filesystem::is_directory(outputDir)) + { + // Generate TLV file (index of all stories) + m_libraryManager.Save(); + + // Copy all files to device + m_libraryManager.CopyToDevice(outputDir); + } + } + + // close + ImGuiFileDialog::Instance()->Close(); + } + WindowBase::EndDraw(); }