Added error dialog to module manager and fixed typo

This commit is contained in:
AlexandreRouma
2021-12-16 16:49:19 +01:00
parent 6c7e952be3
commit 5483268f8f
5 changed files with 39 additions and 20 deletions

View File

@ -4,9 +4,12 @@
#include <string>
#include <gui/gui.h>
#define GENERIC_DIALOG_BUTTONS_OK "Ok\0"
#define GENERIC_DIALOG_BUTTONS_YES_NO "Yes\0No\0"
#define GENERIC_DIALOG_BUTTONS_APPLY_CANCEL "Apply\0Cancel\0"
#define GENERIC_DIALOG_BUTTONS_OK_CANCEL "Ok\0Cancel\0"
#define GENERIC_DIALOG_BUTTON_OK 0
#define GENERIC_DIALOG_BUTTON_YES 0
#define GENERIC_DIALOG_BUTTON_NO 1
#define GENERIC_DIALOG_BUTTON_APPLY 0

View File

@ -10,8 +10,10 @@ namespace module_manager_menu {
std::vector<std::string> modTypes;
std::string toBeRemoved;
std::string modTypesTxt;
std::string errorMessage;
int modTypeId;
bool confirmOpened = false;
bool errorOpen = false;
void init() {
modName[0] = 0;
@ -66,6 +68,10 @@ namespace module_manager_menu {
modified = true;
}
ImGui::GenericDialog("module_mgr_error_", errorOpen, GENERIC_DIALOG_BUTTONS_OK, [](){
ImGui::Text(errorMessage.c_str());
});
// Add module row with slightly different settings
ImGui::BeginTable("Module Manager Add Table", 3);
ImGui::TableSetupColumn("Name");
@ -84,9 +90,14 @@ namespace module_manager_menu {
ImGui::TableSetColumnIndex(2);
if (strlen(modName) == 0) { style::beginDisabled(); }
if (ImGui::Button("+##module_mgr_add_btn", ImVec2(16,0))) {
core::moduleManager.createInstance(modName, modTypes[modTypeId]);
core::moduleManager.postInit(modName);
modified = true;
if (!core::moduleManager.createInstance(modName, modTypes[modTypeId])) {
core::moduleManager.postInit(modName);
modified = true;
}
else {
errorMessage = "Could not create new instance of " + modTypes[modTypeId];
errorOpen = true;
}
}
if (strlen(modName) == 0) { style::endDisabled(); }
ImGui::EndTable();