add debug start screen ui + can load plugins

This commit is contained in:
Green Sky 2023-08-03 13:05:19 +02:00
parent 5547ff6d2b
commit c9672bf352
No known key found for this signature in database
4 changed files with 74 additions and 4 deletions

View File

@ -6,7 +6,7 @@
#include <memory> #include <memory>
MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path) : MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::vector<std::string> plugins) :
renderer(renderer_), renderer(renderer_),
rmm(cr), rmm(cr),
mts(rmm), mts(rmm),
@ -42,6 +42,7 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path) :
g_provideInstance<ToxI>("ToxI", "host", &tc); g_provideInstance<ToxI>("ToxI", "host", &tc);
g_provideInstance<ToxEventProviderI>("ToxEventProviderI", "host", &tc); g_provideInstance<ToxEventProviderI>("ToxEventProviderI", "host", &tc);
g_provideInstance<ToxContactModel2>("ToxContactModel2", "host", &tcm);
// TODO: pm? // TODO: pm?
@ -50,6 +51,14 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path) :
g_provideInstance<TextureUploaderI>("TextureUploaderI", "host", &sdlrtu); g_provideInstance<TextureUploaderI>("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(); conf.dump();
} }

View File

@ -56,7 +56,7 @@ struct MainScreen final : public Screen {
ChatGui4 cg; ChatGui4 cg;
MainScreen(SDL_Renderer* renderer_, std::string save_path); MainScreen(SDL_Renderer* renderer_, std::string save_path, std::vector<std::string> plugins);
~MainScreen(void); ~MainScreen(void);
bool handleEvent(SDL_Event& e) override; bool handleEvent(SDL_Event& e) override;

View File

@ -2,7 +2,10 @@
#include "./main_screen.hpp" #include "./main_screen.hpp"
#include <imgui/imgui.h>
#include <memory> #include <memory>
#include <filesystem>
StartScreen::StartScreen(SDL_Renderer* renderer) : _renderer(renderer) { StartScreen::StartScreen(SDL_Renderer* renderer) : _renderer(renderer) {
} }
@ -10,6 +13,7 @@ StartScreen::StartScreen(SDL_Renderer* renderer) : _renderer(renderer) {
Screen* StartScreen::poll(bool&) { Screen* StartScreen::poll(bool&) {
// TODO: imgui tox profile selector? // TODO: imgui tox profile selector?
// +---------------------------- // +----------------------------
// | |*tox profile*| plugins | // | |*tox profile*| plugins |
// | +------+ +-------- // | +------+ +--------
@ -18,7 +22,56 @@ Screen* StartScreen::poll(bool&) {
// | +------+ +-------- // | +------+ +--------
// +---------------------------- // +----------------------------
auto new_screen = std::make_unique<MainScreen>(_renderer, "tomato.tox"); if (ImGui::BeginTabBar("view")) {
return new_screen.release(); 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<MainScreen>(_renderer, "tomato.tox", queued_plugin_paths);
return new_screen.release();
}
_fss.render();
return nullptr;
} }

View File

@ -2,6 +2,11 @@
#include "./screen.hpp" #include "./screen.hpp"
#include "./file_selector.hpp"
#include <vector>
#include <string>
// fwd // fwd
extern "C" { extern "C" {
struct SDL_Renderer; struct SDL_Renderer;
@ -9,6 +14,9 @@ extern "C" {
struct StartScreen final : public Screen { struct StartScreen final : public Screen {
SDL_Renderer* _renderer; SDL_Renderer* _renderer;
FileSelector _fss;
std::vector<std::string> queued_plugin_paths;
StartScreen(void) = delete; StartScreen(void) = delete;
StartScreen(SDL_Renderer* renderer); StartScreen(SDL_Renderer* renderer);