From 08b83ea16bd0714f3a6c63398718c438f2d41fd6 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Sun, 11 Aug 2024 14:00:33 +0200 Subject: [PATCH 1/4] allow updates to show window --- src/imgui_ui.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/imgui_ui.cpp b/src/imgui_ui.cpp index bf3a6571..fe089b0e 100644 --- a/src/imgui_ui.cpp +++ b/src/imgui_ui.cpp @@ -210,6 +210,59 @@ void mcpelauncher_addmenu(size_t length, MenuEntryABI* entries) { void mcpelauncher_show_window(const char *title, int isModal, void *user, void (*onClose)(void *user), int count, control *controls) { activeWindowsLock.lock(); + if(auto activeWindow = std::find_if(activeWindows.begin(), activeWindows.end(), [](auto&& wnd) { + return wnd.title == (title ? title : "Untitled"); + }); activeWindow != activeWindows.end()) { + std::vector subentries(count); + for(int i = 0; i < count; i++) { + subentries[i].type = controls[i].type; + switch (controls[i].type) + { + case 0: + subentries[i].data.button.label = controls[i].data.button.label ? controls[i].data.button.label : ""; + subentries[i].data.button.user = controls[i].data.button.user; + subentries[i].data.button.onClick = controls[i].data.button.onClick; + break; + case 1: + subentries[i].data.sliderint.label = 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; + subentries[i].data.sliderint.user = controls[i].data.sliderint.user; + subentries[i].data.sliderint.onChange = controls[i].data.sliderint.onChange; + break; + case 2: + subentries[i].data.sliderfloat.label = 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; + subentries[i].data.sliderfloat.user = controls[i].data.sliderfloat.user; + subentries[i].data.sliderfloat.onChange = controls[i].data.sliderfloat.onChange; + break; + case 3: + subentries[i].data.text.label = controls[i].data.text.label ? controls[i].data.text.label : ""; + subentries[i].data.text.size = controls[i].data.text.size; + break; + case 4: + subentries[i].data.textinput.label = controls[i].data.textinput.label ? controls[i].data.textinput.label : ""; subentries[i].data.textinput.def = controls[i].data.textinput.def ? controls[i].data.textinput.def : ""; + subentries[i].data.textinput.placeholder = controls[i].data.textinput.placeholder ? controls[i].data.textinput.placeholder : ""; + subentries[i].data.textinput.user = controls[i].data.textinput.user; + subentries[i].data.textinput.onChange = controls[i].data.textinput.onChange; + break; + + default: + break; + } + } + activeWindow->isModal = !!isModal; + activeWindow->user = user; + activeWindow->onClose = onClose; + activeWindow->controls = std::move(subentries); + return; + } + std::vector subentries(count); for(int i = 0; i < count; i++) { subentries[i].type = controls[i].type; From 0c17a011cdd057f750ea013a569e2f1186639e1a Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Sun, 11 Aug 2024 14:10:13 +0200 Subject: [PATCH 2/4] Update imgui_ui.cpp --- src/imgui_ui.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/imgui_ui.cpp b/src/imgui_ui.cpp index fe089b0e..c1b2cee0 100644 --- a/src/imgui_ui.cpp +++ b/src/imgui_ui.cpp @@ -210,7 +210,7 @@ void mcpelauncher_addmenu(size_t length, MenuEntryABI* entries) { void mcpelauncher_show_window(const char *title, int isModal, void *user, void (*onClose)(void *user), int count, control *controls) { activeWindowsLock.lock(); - if(auto activeWindow = std::find_if(activeWindows.begin(), activeWindows.end(), [](auto&& wnd) { + if(auto activeWindow = std::find_if(activeWindows.begin(), activeWindows.end(), [title](auto&& wnd) { return wnd.title == (title ? title : "Untitled"); }); activeWindow != activeWindows.end()) { std::vector subentries(count); @@ -256,10 +256,10 @@ void mcpelauncher_show_window(const char *title, int isModal, void *user, void ( break; } } - activeWindow->isModal = !!isModal; - activeWindow->user = user; - activeWindow->onClose = onClose; - activeWindow->controls = std::move(subentries); + (*activeWindow)->isModal = !!isModal; + (*activeWindow)->user = user; + (*activeWindow)->onClose = onClose; + (*activeWindow)->controls = std::move(subentries); return; } From 450c30f69a404ca08b2282e4e164a0f41732faf2 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Sun, 11 Aug 2024 14:24:17 +0200 Subject: [PATCH 3/4] Update imgui_ui.cpp --- src/imgui_ui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/imgui_ui.cpp b/src/imgui_ui.cpp index c1b2cee0..5151e697 100644 --- a/src/imgui_ui.cpp +++ b/src/imgui_ui.cpp @@ -211,7 +211,7 @@ void mcpelauncher_addmenu(size_t length, MenuEntryABI* entries) { void mcpelauncher_show_window(const char *title, int isModal, void *user, void (*onClose)(void *user), int count, control *controls) { activeWindowsLock.lock(); if(auto activeWindow = std::find_if(activeWindows.begin(), activeWindows.end(), [title](auto&& wnd) { - return wnd.title == (title ? title : "Untitled"); + return wnd->title == (title ? title : "Untitled"); }); activeWindow != activeWindows.end()) { std::vector subentries(count); for(int i = 0; i < count; i++) { From b9085d20683a49a60e0257ccc35c9fd2d7725f7e Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Sun, 11 Aug 2024 15:01:15 +0200 Subject: [PATCH 4/4] remove step / fix update / close window --- src/imgui_ui.cpp | 91 ++++++++++++++---------------------------------- src/imgui_ui.h | 4 +-- src/main.cpp | 1 + 3 files changed, 30 insertions(+), 66 deletions(-) diff --git a/src/imgui_ui.cpp b/src/imgui_ui.cpp index 5151e697..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; @@ -210,59 +208,6 @@ void mcpelauncher_addmenu(size_t length, MenuEntryABI* entries) { void mcpelauncher_show_window(const char *title, int isModal, void *user, void (*onClose)(void *user), int count, control *controls) { activeWindowsLock.lock(); - if(auto activeWindow = std::find_if(activeWindows.begin(), activeWindows.end(), [title](auto&& wnd) { - return wnd->title == (title ? title : "Untitled"); - }); activeWindow != activeWindows.end()) { - std::vector subentries(count); - for(int i = 0; i < count; i++) { - subentries[i].type = controls[i].type; - switch (controls[i].type) - { - case 0: - subentries[i].data.button.label = controls[i].data.button.label ? controls[i].data.button.label : ""; - subentries[i].data.button.user = controls[i].data.button.user; - subentries[i].data.button.onClick = controls[i].data.button.onClick; - break; - case 1: - subentries[i].data.sliderint.label = 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; - subentries[i].data.sliderint.user = controls[i].data.sliderint.user; - subentries[i].data.sliderint.onChange = controls[i].data.sliderint.onChange; - break; - case 2: - subentries[i].data.sliderfloat.label = 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; - subentries[i].data.sliderfloat.user = controls[i].data.sliderfloat.user; - subentries[i].data.sliderfloat.onChange = controls[i].data.sliderfloat.onChange; - break; - case 3: - subentries[i].data.text.label = controls[i].data.text.label ? controls[i].data.text.label : ""; - subentries[i].data.text.size = controls[i].data.text.size; - break; - case 4: - subentries[i].data.textinput.label = controls[i].data.textinput.label ? controls[i].data.textinput.label : ""; subentries[i].data.textinput.def = controls[i].data.textinput.def ? controls[i].data.textinput.def : ""; - subentries[i].data.textinput.placeholder = controls[i].data.textinput.placeholder ? controls[i].data.textinput.placeholder : ""; - subentries[i].data.textinput.user = controls[i].data.textinput.user; - subentries[i].data.textinput.onChange = controls[i].data.textinput.onChange; - break; - - default: - break; - } - } - (*activeWindow)->isModal = !!isModal; - (*activeWindow)->user = user; - (*activeWindow)->onClose = onClose; - (*activeWindow)->controls = std::move(subentries); - return; - } - std::vector subentries(count); for(int i = 0; i < count; i++) { subentries[i].type = controls[i].type; @@ -275,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; @@ -284,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; @@ -307,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;