From 001034db61d7a197949f7ff35b0fb078cd98a305 Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 26 Mar 2024 17:45:21 +0100 Subject: [PATCH] (WIP library store manager) --- .github/workflows/story_editor.yml | 2 +- .gitignore | 2 + story-editor/CMakeLists.txt | 21 ++- story-editor/src/connection.h | 9 + story-editor/src/gui.cpp | 3 +- story-editor/src/library_window.cpp | 230 ++++++++++++++++++++---- story-editor/src/library_window.h | 9 + story-editor/src/node_editor_window.cpp | 8 + story-editor/src/node_editor_window.h | 2 + 9 files changed, 244 insertions(+), 42 deletions(-) diff --git a/.github/workflows/story_editor.yml b/.github/workflows/story_editor.yml index b235bfe..333a190 100644 --- a/.github/workflows/story_editor.yml +++ b/.github/workflows/story_editor.yml @@ -1,4 +1,4 @@ -name: BuildStoryEditor-Linux +name: build-story-editor on: workflow_dispatch: {} diff --git a/.gitignore b/.gitignore index d68d976..42f5f32 100644 --- a/.gitignore +++ b/.gitignore @@ -79,3 +79,5 @@ story-editor/buildxcode/ story-editor/cmake-build-debug/ story-editor/build-win32/ + +build-story-editor-Desktop_Qt_GCC_64bit-Debug/ diff --git a/story-editor/CMakeLists.txt b/story-editor/CMakeLists.txt index 39332e6..31c7b53 100644 --- a/story-editor/CMakeLists.txt +++ b/story-editor/CMakeLists.txt @@ -21,10 +21,24 @@ endif() find_package(OpenGL REQUIRED) +find_package(OpenSSL REQUIRED) + set(IMGUI_VERSION 1.90) include(FetchContent) +# ========================================================================================================================= +# CURL +# ========================================================================================================================= +FetchContent_Declare(curl + URL https://github.com/curl/curl/archive/refs/tags/curl-8_6_0.zip +) + + +set(BUILD_CURL_EXE FALSE) +set(BUILD_STATIC_LIBS TRUE) +FetchContent_MakeAvailable(curl) + # ========================================================================================================================= # IMGUI and plugins # ========================================================================================================================= @@ -183,7 +197,6 @@ else() add_executable(${STORY_EDITOR_PROJECT} ${SRCS} - ) endif() @@ -195,6 +208,8 @@ target_include_directories(${STORY_EDITOR_PROJECT} PUBLIC libs/ImGuiFileDialog libs/imgui-node-editor + ${curl_INCLUDE_DIR} + ../software/library/ ../software/chip32/ ../software/common @@ -228,7 +243,7 @@ target_compile_definitions(${STORY_EDITOR_PROJECT} PUBLIC cimg_display=0) target_compile_definitions(${STORY_EDITOR_PROJECT} PUBLIC "$<$:DEBUG>") -target_link_directories(${STORY_EDITOR_PROJECT} PUBLIC ${sdl2_BINARY_DIR}) +target_link_directories(${STORY_EDITOR_PROJECT} PUBLIC ${sdl2_BINARY_DIR} ${curl_BINARY_DIR}) message(${sdl2_BINARY_DIR}) set(SDL2_BIN_DIR ${sdl2_BINARY_DIR}) @@ -238,6 +253,8 @@ if(UNIX) OpenGL::GL dl SDL2 + libcurl_static + OpenSSL::SSL OpenSSL::Crypto ) elseif(WIN32) target_link_libraries(${STORY_EDITOR_PROJECT} diff --git a/story-editor/src/connection.h b/story-editor/src/connection.h index 12ccfff..b515b61 100644 --- a/story-editor/src/connection.h +++ b/story-editor/src/connection.h @@ -13,11 +13,20 @@ struct Connection { } + + ~Connection() { + + } + unsigned int outNodeId{0}; unsigned int outPortIndex{0}; unsigned int inNodeId{0}; unsigned int inPortIndex{0}; + Connection(const Connection &other){ + *this = other; + } + Connection& operator=(const Connection& other) { this->outNodeId = other.outNodeId; this->outPortIndex = other.outPortIndex; diff --git a/story-editor/src/gui.cpp b/story-editor/src/gui.cpp index 7885d65..a6bd109 100644 --- a/story-editor/src/gui.cpp +++ b/story-editor/src/gui.cpp @@ -9,6 +9,7 @@ your use of the corresponding standard functions. #include #include +#include #include "imgui_impl_sdl2.h" #include "imgui_impl_sdlrenderer2.h" @@ -121,7 +122,7 @@ std::string GetDirectory (const std::string& path) Gui::Gui() { - m_executablePath = GetDirectory(pf::getExecutablePath()); + m_executablePath = std::filesystem::current_path(); std::cout << "PATH: " << m_executablePath << std::endl; } diff --git a/story-editor/src/library_window.cpp b/story-editor/src/library_window.cpp index c6eac2d..12ea18d 100644 --- a/story-editor/src/library_window.cpp +++ b/story-editor/src/library_window.cpp @@ -4,6 +4,62 @@ #include #include "IconsMaterialDesignIcons.h" +#define CPPHTTPLIB_OPENSSL_SUPPORT +#include "httplib.h" +#define CA_CERT_FILE "./ca-bundle.crt" + +#include + +int xfer_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, + curl_off_t ultotal, curl_off_t ulnow) +{ + return 0; +} + +void download_file(const std::string &output_file = "pi.txt") +{ + + CURL *curl_download; + FILE *fp; + CURLcode res; + std::string url = "http://www.gecif.net/articles/mathematiques/pi/pi_1_million.txt"; + + curl_download = curl_easy_init(); + + if (curl_download) + { + //SetConsoleTextAttribute(hConsole, 11); + fp = fopen(output_file.c_str(),"wb"); + + curl_easy_setopt(curl_download, CURLOPT_URL, url.c_str()); + curl_easy_setopt(curl_download, CURLOPT_WRITEFUNCTION, NULL); + curl_easy_setopt(curl_download, CURLOPT_WRITEDATA, fp); + curl_easy_setopt(curl_download, CURLOPT_NOPROGRESS, 0); + //progress_bar : the fonction for the progress bar + curl_easy_setopt(curl_download, CURLOPT_XFERINFOFUNCTION, xfer_callback); + + + std::cout<<" Start download"<status << std::endl; + std::cout << res->get_header_value("Content-Type") << std::endl; + m_storeRawJson = res->body; + ParseStoreData(); + //std::cout << res->body << std::endl; + } else { + std::cout << "error code: " << res.error() << std::endl; + + auto result = cli.get_openssl_verify_result(); + if (result) { + std::cout << "verify error: " << X509_verify_cert_error_string(result) <(); + s.age = obj["age"].get(); + + m_store.push_back(s); + } + } + catch(std::exception &e) + { + std::cout << e.what() << std::endl; + } } void LibraryWindow::Initialize() @@ -42,74 +143,127 @@ void LibraryWindow::Draw() WindowBase::BeginDraw(); ImGui::SetWindowSize(ImVec2(626, 744), ImGuiCond_FirstUseEver); + + if (ImGui::Button( ICON_MDI_FOLDER " Select directory")) { ImGuiFileDialog::Instance()->OpenDialog("ChooseLibraryDirDialog", "Choose a library directory", nullptr, ".", 1, nullptr, ImGuiFileDialogFlags_Modal); } - ImGui::SameLine(); - if (!m_libraryManager.IsInitialized()) { + ImGui::SameLine(); ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255,0,0,255)); ImGui::Text("No any library directory set. Please select one where stories will be located."); ImGui::PopStyleColor(); } else { + ImGui::SameLine(); ImGui::Text("Library path: %s", m_libraryManager.LibraryPath().c_str()); - } - if (ImGui::Button("Scan library")) - { - m_libraryManager.Scan(); - } - ImGui::SameLine(); - - if (ImGui::Button("Import story")) - { - ImGuiFileDialog::Instance()->OpenDialogWithPane("ImportStoryDlgKey", "Import story", "", "", InfosPane); - } - - if (m_libraryManager.IsInitialized()) - { - static ImGuiTableFlags tableFlags = - ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable - | ImGuiTableFlags_Sortable | ImGuiTableFlags_SortMulti - | ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders | ImGuiTableFlags_NoBordersInBody - | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY - | ImGuiTableFlags_SizingFixedFit; - - if (ImGui::BeginTable("library_table", 2, tableFlags)) + static ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_Reorderable; + if (ImGui::BeginTabBar("LibraryTabBar", tab_bar_flags)) { - ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed); + static ImGuiTableFlags tableFlags = + ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable + | ImGuiTableFlags_Sortable | ImGuiTableFlags_SortMulti + | ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders | ImGuiTableFlags_NoBordersInBody + | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY + | ImGuiTableFlags_SizingFixedFit; - ImGui::TableSetupColumn("Actions", ImGuiTableColumnFlags_WidthFixed); - - ImGui::TableHeadersRow(); - - for (auto &p : m_libraryManager) + // ============================================================================ + // LOCAL TABLE + // ============================================================================ + if (ImGui::BeginTabItem("Local library ##LocalTabBar", nullptr, ImGuiTabItemFlags_None)) { - ImGui::TableNextColumn(); - ImGui::Text("%s", p->GetName().c_str()); - ImGui::TableNextColumn(); - if (ImGui::SmallButton("Load")) + if (ImGui::Button("Scan library")) { - m_storyManager.OpenProject(p->GetUuid()); + m_libraryManager.Scan(); } ImGui::SameLine(); - if (ImGui::SmallButton("Remove")) + if (ImGui::Button("Import story")) { - + ImGuiFileDialog::Instance()->OpenDialogWithPane("ImportStoryDlgKey", "Import story", "", "", InfosPane); } + + + if (ImGui::BeginTable("library_table", 2, tableFlags)) + { + ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed); + + ImGui::TableSetupColumn("Actions", ImGuiTableColumnFlags_WidthFixed); + + ImGui::TableHeadersRow(); + + for (auto &p : m_libraryManager) + { + ImGui::TableNextColumn(); + ImGui::Text("%s", p->GetName().c_str()); + + ImGui::TableNextColumn(); + + if (ImGui::SmallButton("Load")) + { + m_storyManager.OpenProject(p->GetUuid()); + } + + ImGui::SameLine(); + + if (ImGui::SmallButton("Remove")) + { + + } + } + + ImGui::EndTable(); + } + + ImGui::EndTabItem(); } - ImGui::EndTable(); + // ============================================================================ + // LOCAL TABLE + // ============================================================================ + if (ImGui::BeginTabItem("Remote Store##StoreTabBar", nullptr, ImGuiTabItemFlags_None)) + { + if (ImGui::BeginTable("store_table", 3, tableFlags)) + { + ImGui::TableSetupColumn("Title", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("Age", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("Download", ImGuiTableColumnFlags_WidthFixed); + + ImGui::TableHeadersRow(); + + for (const auto &obj : m_store) + { + ImGui::TableNextColumn(); + ImGui::Text("%s", obj.title.c_str()); + + ImGui::TableNextColumn(); + ImGui::Text("%d", obj.age); + + ImGui::TableNextColumn(); + if (ImGui::SmallButton("Download")) + { + + } + } + + ImGui::EndTable(); + } + + + + ImGui::EndTabItem(); + } + + ImGui::EndTabBar(); } } diff --git a/story-editor/src/library_window.h b/story-editor/src/library_window.h index 0101a3f..e480dc2 100644 --- a/story-editor/src/library_window.h +++ b/story-editor/src/library_window.h @@ -4,6 +4,11 @@ #include "library_manager.h" #include "i_story_manager.h" +struct StoryInf { + int age; + std::string title; +}; + class LibraryWindow : public WindowBase { public: @@ -16,5 +21,9 @@ private: IStoryManager &m_storyManager; LibraryManager &m_libraryManager; + std::vector m_store; + + std::string m_storeRawJson; + void ParseStoreData(); }; diff --git a/story-editor/src/node_editor_window.cpp b/story-editor/src/node_editor_window.cpp index f2bd969..fdc5537 100644 --- a/story-editor/src/node_editor_window.cpp +++ b/story-editor/src/node_editor_window.cpp @@ -158,6 +158,8 @@ void NodeEditorWindow::Load(const nlohmann::json &model) GetInputPin(model.inNodeId, model.inPortIndex), GetOutputPin(model.outNodeId, model.outPortIndex)); } + + m_loaded = true; } @@ -485,6 +487,12 @@ void NodeEditorWindow::Draw() ImGui::EndPopup(); } + if (m_loaded) + { + ed::NavigateToContent(); + m_loaded = false; + } + ed::Resume(); diff --git a/story-editor/src/node_editor_window.h b/story-editor/src/node_editor_window.h index de98a67..40efe66 100644 --- a/story-editor/src/node_editor_window.h +++ b/story-editor/src/node_editor_window.h @@ -65,6 +65,8 @@ private: ed::EditorContext* m_context = nullptr; + bool m_loaded{false}; + // key: Id std::list> m_nodes; std::list> m_links; // List of live links. It is dynamic unless you want to create read-only view over nodes.