Fixed module manager not saving

This commit is contained in:
Ryzerth 2021-07-26 17:33:41 +02:00
parent ce448d6852
commit 14813aa962

View File

@ -25,6 +25,7 @@ namespace module_manager_menu {
} }
void draw(void* ctx) { void draw(void* ctx) {
bool modified = false;
if (ImGui::BeginTable("Module Manager Table", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, ImVec2(0, 200))) { if (ImGui::BeginTable("Module Manager Table", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, ImVec2(0, 200))) {
ImGui::TableSetupColumn("Name"); ImGui::TableSetupColumn("Name");
ImGui::TableSetupColumn("Type"); ImGui::TableSetupColumn("Type");
@ -49,6 +50,7 @@ namespace module_manager_menu {
ImGui::SetCursorPos(ImVec2(origPos.x - 3, origPos.y)); ImGui::SetCursorPos(ImVec2(origPos.x - 3, origPos.y));
if (ImGui::Button(("##module_mgr_"+name).c_str(), ImVec2(height,height))) { if (ImGui::Button(("##module_mgr_"+name).c_str(), ImVec2(height,height))) {
toBeRemoved.push_back(name); toBeRemoved.push_back(name);
modified = true;
} }
ImGui::SetCursorPos(ImVec2(origPos.x + 2, origPos.y - 5)); ImGui::SetCursorPos(ImVec2(origPos.x + 2, origPos.y - 5));
ImGui::Text("_"); ImGui::Text("_");
@ -81,8 +83,21 @@ namespace module_manager_menu {
if (ImGui::Button("+##module_mgr_add_btn", ImVec2(16,0))) { if (ImGui::Button("+##module_mgr_add_btn", ImVec2(16,0))) {
core::moduleManager.createInstance(modName, modTypes[modTypeId]); core::moduleManager.createInstance(modName, modTypes[modTypeId]);
core::moduleManager.postInit(modName); core::moduleManager.postInit(modName);
modified = true;
} }
if (strlen(modName) == 0) { style::endDisabled(); } if (strlen(modName) == 0) { style::endDisabled(); }
ImGui::EndTable(); ImGui::EndTable();
if (modified) {
// Update enabled and disabled modules
core::configManager.acquire();
json instances;
for (auto [_name, inst] : core::moduleManager.instances) {
instances[_name]["module"] = inst.module.info->name;
instances[_name]["enabled"] = inst.instance->isEnabled();
}
core::configManager.conf["moduleInstances"] = instances;
core::configManager.release(true);
}
} }
} }