From ab6e92b6ee0594f4703b33a13e145adea5b446d0 Mon Sep 17 00:00:00 2001 From: Kevin Lyles Date: Tue, 13 Oct 2009 04:49:34 -0500 Subject: [PATCH] Adding new weights works --- WeightsWatcher.xml | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++- config.lua | 81 ++++++++++++++++++++++++++ 2 files changed, 241 insertions(+), 1 deletion(-) diff --git a/WeightsWatcher.xml b/WeightsWatcher.xml index f4fa9ea..074ed9d 100644 --- a/WeightsWatcher.xml +++ b/WeightsWatcher.xml @@ -339,7 +339,166 @@ - print("New weight not yet implemented") + configNewWeight() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + self:SetTextInsets(5, 5, 0, 0) + + + if self:GetText() == "" then + self:GetParent().createButton:Disable() + else + self:GetParent().createButton:Enable() + end + + + + + diff --git a/config.lua b/config.lua index dd930b5..9b78534 100644 --- a/config.lua +++ b/config.lua @@ -21,6 +21,16 @@ StaticPopupDialogs["WW_CONFIRM_WEIGHT_DELETE"] = { hideOnEscape = true, } +StaticPopupDialogs["WW_WEIGHT_EXISTS"] = { + text = "The %s weight named \"%s\" already exists. Pick a different name.", + button1 = "Okay", + enterClicksFirstButton = true, + showAlert = true, + timeout = 0, + whileDead = true, + hideOnEscape = true, +} + function commandHandler(msg) open_config() end @@ -170,6 +180,54 @@ function deleteWeight(weight) ww_config.leftPanel.scrollFrame:GetScript("OnShow")(ww_config.leftPanel.scrollFrame) end +function configNewWeight(class, weight) + if class then + UIDropDownMenu_SetSelectedValue(ww_newWeight.dropdown, class, false) + end + ww_newWeight.editBox:SetText("") + if weight then + ww_newWeight.editBox:SetText(weight) + end + ww_newWeight:Show() +end + +function setWeight(class, weight, statList) + local weightFrame, position + + if not ww_vars.weightsList[class][weight] then + for _, classFrame in ipairs(ww_classFrameTable) do + if classFrame.class == class then + position = classFrame.length + weightFrame = CreateFrame("Frame", weight, classFrame, "ww_elementFrame") + weightFrame.position = position + weightFrame.category = classFrame + weightFrame.text:SetText(weight) + weightFrame.name = weight + weightFrame:SetPoint("TOPLEFT", 0, -20 * position) + classFrame.length = classFrame.length + 1 + weightFrame.text:SetScript("OnClick", + function(self) + configSelectWeight(weightFrame) + end) + if classFrame.collapsed then + weightFrame:Hide() + else + classFrame:SetHeight(20 * classFrame.length) + table.insert(ww_weightFrameTable, classFrame.position + position, weightFrame) + for _, class in ipairs(ww_classFrameTable) do + if class.position > classFrame.position then + class.position = class.position + 1 + end + end + end + break + end + end + ww_config.leftPanel.scrollFrame:GetScript("OnShow")(ww_config.leftPanel.scrollFrame) + end + ww_vars.weightsList[class][weight] = deepTableCopy(statList) +end + --loads the various class buttons onto the config frame function loadClassButtons() local classes, revClassLookup = {}, {} @@ -303,6 +361,29 @@ function toggleCollapse(categoryFrame, categoryTable, elementTable, elementHeigh scrollBarUpdateFunction() end +function ClassDropDownInitialize(dropdown) + local info = {} + + info.func = DropDownOnClick + info.arg1 = dropdown + for class, name in pairs(classNames) do + info.text = name + info.value = class + info.checked = nil + UIDropDownMenu_AddButton(info) + end +end + +function ClassDropDownOnShow(dropdown) + local _, class = UnitClass("player") + UIDropDownMenu_Initialize(dropdown, ClassDropDownInitialize); + UIDropDownMenu_SetSelectedValue(dropdown, class) +end + +function DropDownOnClick(choice, dropdown) + UIDropDownMenu_SetSelectedValue(dropdown, choice.value, false) +end + trackedStats = { ["General"] = { "Stamina", -- 1.7.9.5