From 6ae61bf1fe27c618d06228847bff5c43584bfa19 Mon Sep 17 00:00:00 2001 From: Boshi Lian Date: Sat, 5 Oct 2024 19:25:53 -0700 Subject: [PATCH] add an option button and more options (#68) * add option button * add option to turn clear before import on and off --- gui.lua | 34 ++++++++++++++++++++++++++++++++-- options.lua | 15 ++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/gui.lua b/gui.lua index 027f036..4adc49f 100644 --- a/gui.lua +++ b/gui.lua @@ -55,13 +55,25 @@ end local exportEditbox +-- options +do + local b = CreateFrame("Button", nil, f, "GameMenuButtonTemplate") + b:SetWidth(100) + b:SetHeight(25) + b:SetPoint("BOTTOMRIGHT", -145, 15) + b:SetText(OPTIONS) + b:SetScript("OnClick", function() + Settings.OpenToCategory(MySlot.settingcategory.ID) + end) +end + -- close do local b = CreateFrame("Button", nil, f, "GameMenuButtonTemplate") b:SetWidth(100) b:SetHeight(25) b:SetPoint("BOTTOMRIGHT", -40, 15) - b:SetText(L["Close"]) + b:SetText(CLOSE) b:SetScript("OnClick", function() f:Hide() end) end @@ -396,6 +408,15 @@ do MySlot:Print(L["Starting backup..."]) local backup = MySlot:Export(actionOpt) + + if not backup then + MySlot:Print(L["Backup failed"]) + + if not forceImport then + return + end + end + table.insert(MyslotExports["backups"], backup) while #MyslotExports["backups"] > IMPORT_BACKUP_COUNT do table.remove(MyslotExports["backups"], 1) @@ -437,6 +458,7 @@ do tAppendAll(settings, CreateSettingMenu(actionOpt)) + local clearbegin = #settings + 1 tAppendAll(settings, { { isTitle = true, @@ -447,6 +469,7 @@ do tAppendAll(settings, CreateSettingMenu(clearOpt)) table.remove(settings) -- remove pet action bar clearOpt, will support it later + local clearend = #settings tAppendAll(settings, { { @@ -467,8 +490,15 @@ do } }) + local settingswithoutclear = {} + tAppendAll(settingswithoutclear, settings) + for i = clearend, clearbegin, -1 do + table.remove(settingswithoutclear, i) + end + + ba:SetScript("OnClick", function(self, button) - EasyMenu(settings, menuFrame, "cursor", 0 , 0, "MENU"); + EasyMenu(MyslotSettings.allowclearonimport and settings or settingswithoutclear, menuFrame, "cursor", 0 , 0, "MENU"); end) end diff --git a/options.lua b/options.lua index a20d635..a40e844 100644 --- a/options.lua +++ b/options.lua @@ -35,9 +35,9 @@ RegEvent("ADDON_LOADED", function() end) end + MyslotSettings = MyslotSettings or {} do - MyslotSettings = MyslotSettings or {} MyslotSettings.minimap = MyslotSettings.minimap or { hide = false } local config = MyslotSettings.minimap @@ -99,6 +99,19 @@ RegEvent("ADDON_LOADED", function() StaticPopup_Show("MYSLOT_CONFIRM_CLEAR", "MACRO", nil, "MACRO") end) end + + do + local b = CreateFrame("CheckButton", nil, f, "UICheckButtonTemplate") + b:SetPoint("TOPLEFT", f, 15, doffset - 110) + + b.text = b:CreateFontString(nil, "OVERLAY", "GameFontNormal") + b.text:SetPoint("LEFT", b, "RIGHT", 0, 1) + b.text:SetText(L["Allow"] .. " " .. "|cffff0000" .. L["CLEAR"] .. "|r" .. " " .. L[" before Import"]) + b:SetChecked(MyslotSettings.allowclearonimport) + b:SetScript("OnClick", function() + MyslotSettings.allowclearonimport = b:GetChecked() + end) + end end) StaticPopupDialogs["MYSLOT_CONFIRM_CLEAR"] = {