From d0573a106fd433d321733c133770d5b7d804db4c Mon Sep 17 00:00:00 2001 From: Kevin Lyles Date: Fri, 27 Nov 2009 01:57:39 -0600 Subject: [PATCH] deleting weights works --- WeightsWatcher.xml | 9 +++++++++ config.lua | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/WeightsWatcher.xml b/WeightsWatcher.xml index 376a15c..f4fa9ea 100644 --- a/WeightsWatcher.xml +++ b/WeightsWatcher.xml @@ -272,6 +272,15 @@ + + diff --git a/config.lua b/config.lua index bbc4cd9..dd930b5 100644 --- a/config.lua +++ b/config.lua @@ -8,6 +8,19 @@ ww_statFrameTable = {} ww_classFrameTable = {} ww_weightFrameTable = {} +StaticPopupDialogs["WW_CONFIRM_WEIGHT_DELETE"] = { + text = "Are you sure you want to delete the %s weight named \"%s\"?", + button1 = "Delete", + button2 = "Cancel", + OnAccept = function(self, weight) + deleteWeight(weight) + end, + showAlert = true, + timeout = 0, + whileDead = true, + hideOnEscape = true, +} + function commandHandler(msg) open_config() end @@ -79,6 +92,10 @@ function configSelectWeight(weightFrame) function() configSaveWeight(weightFrame) end) + ww_config.rightPanel.deleteButton:SetScript("OnClick", + function() + configDeleteWeight(weightFrame) + end) ww_config.rightPanel.resetButton:SetScript("OnClick", function() configResetWeight(weightFrame) @@ -100,6 +117,12 @@ function configResetWeight(weight) end end +function configDeleteWeight(weight) + local confirm = StaticPopup_Show("WW_CONFIRM_WEIGHT_DELETE", weight.category.name, weight.name) + -- Pass the things to delete, has to be done after the show call + confirm.data = weight +end + function configSaveWeight(weight) local number @@ -114,6 +137,39 @@ function configSaveWeight(weight) end end +function deleteWeight(weight) + local point, relativeTo, relativePoint, xOffset, yOffset + + weight.category.length = weight.category.length - 1 + for _, weightFrame in ipairs({weight.category:GetChildren()}) do + if weightFrame.position and weightFrame.position > weight.position then + weightFrame.position = weightFrame.position - 1 + for i = 1, weightFrame:GetNumPoints() do + point, relativeTo, relativePoint, xOffset, yOffset = weightFrame:GetPoint(1) + if point == "TOPLEFT" then + weightFrame:SetPoint(point, relativeTo, relativePoint, xOffset, yOffset + 20) + break + end + end + end + end + if not weight.category.collapsed then + for _, classFrame in ipairs(ww_classFrameTable) do + if classFrame.position > weight.category.position then + classFrame.position = classFrame.position - 1 + end + end + table.remove(ww_weightFrameTable, weight.category.position + weight.position) + weight.category:SetHeight(20 * weight.category.length) + end + weight:Hide() + weight:SetParent(nil) + + ww_vars.weightsList[weight.category.class][weight.name] = nil + ww_config.rightPanel:Hide() + ww_config.leftPanel.scrollFrame:GetScript("OnShow")(ww_config.leftPanel.scrollFrame) +end + --loads the various class buttons onto the config frame function loadClassButtons() local classes, revClassLookup = {}, {} -- 1.7.9.5