diff --git a/src/main_screen.cpp b/src/main_screen.cpp index a4d7d3f7..fcb26558 100644 --- a/src/main_screen.cpp +++ b/src/main_screen.cpp @@ -6,7 +6,7 @@ #include -MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path) : +MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::vector plugins) : renderer(renderer_), rmm(cr), mts(rmm), @@ -42,6 +42,7 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path) : g_provideInstance("ToxI", "host", &tc); g_provideInstance("ToxEventProviderI", "host", &tc); + g_provideInstance("ToxContactModel2", "host", &tcm); // TODO: pm? @@ -50,6 +51,14 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path) : g_provideInstance("TextureUploaderI", "host", &sdlrtu); } + for (const auto& ppath : plugins) { + if (!pm.add(ppath)) { + std::cerr << "MS error: loading plugin '" << ppath << "' failed!\n"; + // thow? + assert(false && "failed to load plugin"); + } + } + conf.dump(); } diff --git a/src/main_screen.hpp b/src/main_screen.hpp index ad081a4a..7fc3b9fb 100644 --- a/src/main_screen.hpp +++ b/src/main_screen.hpp @@ -56,7 +56,7 @@ struct MainScreen final : public Screen { ChatGui4 cg; - MainScreen(SDL_Renderer* renderer_, std::string save_path); + MainScreen(SDL_Renderer* renderer_, std::string save_path, std::vector plugins); ~MainScreen(void); bool handleEvent(SDL_Event& e) override; diff --git a/src/start_screen.cpp b/src/start_screen.cpp index 3fbcaa13..da1498e2 100644 --- a/src/start_screen.cpp +++ b/src/start_screen.cpp @@ -2,7 +2,10 @@ #include "./main_screen.hpp" +#include + #include +#include StartScreen::StartScreen(SDL_Renderer* renderer) : _renderer(renderer) { } @@ -10,6 +13,7 @@ StartScreen::StartScreen(SDL_Renderer* renderer) : _renderer(renderer) { Screen* StartScreen::poll(bool&) { // TODO: imgui tox profile selector? + // +---------------------------- // | |*tox profile*| plugins | // | +------+ +-------- @@ -18,7 +22,56 @@ Screen* StartScreen::poll(bool&) { // | +------+ +-------- // +---------------------------- - auto new_screen = std::make_unique(_renderer, "tomato.tox"); - return new_screen.release(); + if (ImGui::BeginTabBar("view")) { + if (ImGui::BeginTabItem("load profile")) { + ImGui::Text("TODO: profile path"); + ImGui::Text("TODO: profile password"); + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("create profile")) { + ImGui::Text("TODO: profile path"); + ImGui::Text("TODO: profile name"); + ImGui::Text("TODO: profile password"); + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("plugins")) { + // list of selected plugins (in order) + for (auto it = queued_plugin_paths.begin(); it != queued_plugin_paths.end();) { + if (ImGui::SmallButton("-")) { + it = queued_plugin_paths.erase(it); + continue; + } + ImGui::SameLine(); + + ImGui::TextUnformatted(it->c_str()); + + it++; + } + + if (ImGui::Button("+")) { + _fss.requestFile( + [](const auto& path) -> bool { return std::filesystem::is_regular_file(path); }, + [this](const auto& path) { + queued_plugin_paths.push_back(path.string()); + }, + [](){} + ); + } + + ImGui::EndTabItem(); + } + ImGui::EndTabBar(); + } + + ImGui::Separator(); + + if (ImGui::Button("load", {60, 25})) { + auto new_screen = std::make_unique(_renderer, "tomato.tox", queued_plugin_paths); + return new_screen.release(); + } + + _fss.render(); + + return nullptr; } diff --git a/src/start_screen.hpp b/src/start_screen.hpp index c36e3402..e628e584 100644 --- a/src/start_screen.hpp +++ b/src/start_screen.hpp @@ -2,6 +2,11 @@ #include "./screen.hpp" +#include "./file_selector.hpp" + +#include +#include + // fwd extern "C" { struct SDL_Renderer; @@ -9,6 +14,9 @@ extern "C" { struct StartScreen final : public Screen { SDL_Renderer* _renderer; + FileSelector _fss; + + std::vector queued_plugin_paths; StartScreen(void) = delete; StartScreen(SDL_Renderer* renderer);