From ff43c3503070eb53d858c91cbedbb023dcdaa0a5 Mon Sep 17 00:00:00 2001 From: Boshi Lian Date: Sat, 13 Jul 2024 22:39:27 -0700 Subject: [PATCH] Refactor GUI.lua to improve menu creation and handling --- gui.lua | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/gui.lua b/gui.lua index e917754..c3c6e9a 100644 --- a/gui.lua +++ b/gui.lua @@ -318,6 +318,40 @@ local function CreateSettingMenu(opt) } end +local function DrawMenu(root, menuData) + for _, m in ipairs(menuData) do + if m.isTitle then + root:CreateTitle(m.text) + else + local c = root:CreateCheckbox(m.text, m.checked, function () + + end, { + arg1 = m.arg1, + arg2 = m.arg2, + }) + c:SetResponder(function(data, menuInputData, menu) + m.func({ + arg1 = m.arg1, + arg2 = m.arg2, + }) + -- Your handler here... + return MenuResponse.Refresh; + end) + + if m.menuList then + DrawMenu(c, m.menuList) + end + end + end + +end + +local EasyMenu = _G.EasyMenu or function (settings) + MenuUtil.CreateContextMenu(UIParent, function(ownerRegion, rootDescription) + DrawMenu(rootDescription, settings) + end) +end + -- import do @@ -408,10 +442,6 @@ do } }) - if not EasyMenu then - ba:Hide() - end - ba:SetScript("OnClick", function(self, button) EasyMenu(settings, menuFrame, "cursor", 0 , 0, "MENU"); end) @@ -457,10 +487,6 @@ do tAppendAll(settings, CreateSettingMenu(actionOpt)) - if not EasyMenu then - ba:Hide() - end - ba:SetScript("OnClick", function(self, button) EasyMenu(settings, menuFrame, "cursor", 0 , 0, "MENU"); end)