diff --git a/src/imgui_ui.cpp b/src/imgui_ui.cpp index bf3a6571..93dd2673 100644 --- a/src/imgui_ui.cpp +++ b/src/imgui_ui.cpp @@ -111,7 +111,6 @@ struct WindowControl int min; int def; int max; - int step; void* user; void(*onChange)(void* user, int value); } sliderint; @@ -120,7 +119,6 @@ struct WindowControl float min; float def; float max; - float step; void* user; void(*onChange)(void* user, float value); } sliderfloat; @@ -222,7 +220,6 @@ void mcpelauncher_show_window(const char *title, int isModal, void *user, void ( break; case 1: new(&subentries[i].data.sliderint.label) std::string(controls[i].data.sliderint.label ? controls[i].data.sliderint.label : ""); - subentries[i].data.sliderint.step = controls[i].data.sliderint.step; subentries[i].data.sliderint.def = controls[i].data.sliderint.def; subentries[i].data.sliderint.max = controls[i].data.sliderint.max; subentries[i].data.sliderint.min = controls[i].data.sliderint.min; @@ -231,7 +228,6 @@ void mcpelauncher_show_window(const char *title, int isModal, void *user, void ( break; case 2: new(&subentries[i].data.sliderfloat.label) std::string(controls[i].data.sliderfloat.label ? controls[i].data.sliderfloat.label : ""); - subentries[i].data.sliderfloat.step = controls[i].data.sliderfloat.step; subentries[i].data.sliderfloat.def = controls[i].data.sliderfloat.def; subentries[i].data.sliderfloat.max = controls[i].data.sliderfloat.max; subentries[i].data.sliderfloat.min = controls[i].data.sliderfloat.min; @@ -254,13 +250,33 @@ void mcpelauncher_show_window(const char *title, int isModal, void *user, void ( break; } } - activeWindows.push_back(std::make_shared(ActiveWindow{ - .title = title ? title : "Untitled", - .isModal = !!isModal, - .user = user, - .onClose = onClose, - .controls = std::move(subentries), - })); + + if(auto activeWindow = std::find_if(activeWindows.begin(), activeWindows.end(), [title](auto&& wnd) { + return wnd->title == (title ? title : "Untitled"); + }); activeWindow != activeWindows.end()) { + (*activeWindow)->isModal = !!isModal; + (*activeWindow)->user = user; + (*activeWindow)->onClose = onClose; + (*activeWindow)->controls = std::move(subentries); + } else { + activeWindows.push_back(std::make_shared(ActiveWindow{ + .title = title ? title : "Untitled", + .isModal = !!isModal, + .user = user, + .onClose = onClose, + .controls = std::move(subentries), + })); + } + activeWindowsLock.unlock(); +} + +void mcpelauncher_close_window(const char *title) { + activeWindowsLock.lock(); + if(auto activeWindow = std::find_if(activeWindows.begin(), activeWindows.end(), [title](auto&& wnd) { + return wnd->title == (title ? title : "Untitled"); + }); activeWindow != activeWindows.end()) { + activeWindows.erase(activeWindow); + } activeWindowsLock.unlock(); } diff --git a/src/imgui_ui.h b/src/imgui_ui.h index f9d60cdf..58395c02 100644 --- a/src/imgui_ui.h +++ b/src/imgui_ui.h @@ -29,7 +29,6 @@ struct control int min; int def; int max; - int step; void* user; void(*onChange)(void* user, int value); } sliderint; @@ -38,7 +37,6 @@ struct control float min; float def; float max; - float step; void* user; void(*onChange)(void* user, float value); } sliderfloat; @@ -56,3 +54,5 @@ struct control } data; }; void mcpelauncher_show_window(const char* title, int isModal, void* user, void(*onClose)(void* user), int count, control* controls); + +void mcpelauncher_close_window(const char *title); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 6a29206c..05fe91d3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -375,6 +375,7 @@ Hardware : Qualcomm Technologies, Inc MSM8998 linker::load_library("libmcpelauncher_menu.so", { { "mcpelauncher_addmenu", (void*)mcpelauncher_addmenu }, { "mcpelauncher_show_window", (void*)mcpelauncher_show_window }, + { "mcpelauncher_close_window", (void*)mcpelauncher_close_window }, }); ModLoader modLoader;