diff --git a/WeightsWatcher.toc b/WeightsWatcher.toc index b33f1c0..75c8f95 100644 --- a/WeightsWatcher.toc +++ b/WeightsWatcher.toc @@ -16,9 +16,12 @@ Libs\AceHook-2.1\AceHook-2.1.lua GemIds.lua config.lua +config.xml +weights.lua +weights.xml Regexps.lua Upgrade.lua defaults.lua HiddenTooltip.xml -WeightsWatcher.lua WeightsWatcher.xml +WeightsWatcher.lua diff --git a/WeightsWatcher.xml b/WeightsWatcher.xml index 9ca6f9c..23f52fc 100644 --- a/WeightsWatcher.xml +++ b/WeightsWatcher.xml @@ -1,808 +1,3 @@ <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd"> - <Script file="config.lua"/> - <!--Default String used to allow for simpler left alignment in script generated fontstrings--> - <FontString name="ww_defaultString" inherits="GameFontNormalSmall" virtual="true"> - <Anchors> - <Anchor point="LEFT"/> - </Anchors> - </FontString> - <!-- Adds a border that can be hidden/shown as a unit --> - <Frame name="ww_highlightedFrame" virtual="true" hidden="true"> - <Layers> - <Layer level="BACKGROUND"> - <Texture file="Interface\Buttons\UI-Panel-Button-Glow" alphaMode="ADD"> - <Size> - <AbsDimension y="22" x="16"/> - </Size> - <Anchors> - <Anchor point="LEFT"/> - </Anchors> - <TexCoords left="0.03125" right="0.25" top=".0625" bottom=".5625"/> - </Texture> - <Texture file="Interface\Buttons\UI-Panel-Button-Glow" alphaMode="ADD"> - <Size> - <AbsDimension y="22"/> - </Size> - <Anchors> - <Anchor point="LEFT"> - <Offset> - <AbsDimension x="16"/> - </Offset> - </Anchor> - <Anchor point="RIGHT"> - <Offset> - <AbsDimension x="-16"/> - </Offset> - </Anchor> - </Anchors> - <TexCoords left="0.25" right="0.5" top=".0625" bottom=".5625"/> - </Texture> - <Texture file="Interface\Buttons\UI-Panel-Button-Glow" alphaMode="ADD"> - <Size> - <AbsDimension y="22" x="16"/> - </Size> - <Anchors> - <Anchor point="RIGHT"/> - </Anchors> - <TexCoords left=".5" right=".6875" top=".0625" bottom=".5625"/> - </Texture> - </Layer> - </Layers> - </Frame> - <!-- virtual frame used for categories in tiered lists --> - <Frame name="ww_categoryFrame" virtual="true"> - <Size> - <AbsDimension y="22"/> - </Size> - <Anchors> - <Anchor point="RIGHT"/> - </Anchors> - <Frames> - <Button name="$parentText" parentKey="text"> - <Size> - <AbsDimension y="20"/> - </Size> - <Anchors> - <Anchor point="TOPLEFT"> - <Offset> - <AbsDimension x="5" y="-1"/> - </Offset> - </Anchor> - <Anchor point="RIGHT"/> - </Anchors> - <NormalTexture file="Interface\Buttons\UI-MinusButton-UP"> - <Size> - <AbsDimension x="16" y="16"/> - </Size> - <Anchors> - <Anchor point="LEFT"/> - </Anchors> - </NormalTexture> - <PushedTexture file="Interface\Buttons\UI-MinusButton-DOWN"> - <Size> - <AbsDimension x="16" y="16"/> - </Size> - <Anchors> - <Anchor point="LEFT"/> - </Anchors> - </PushedTexture> - <HighlightTexture file="Interface\Buttons\UI-PlusButton-Hilight" alphaMode="ADD"> - <Size> - <AbsDimension x="16" y="16"/> - </Size> - <Anchors> - <Anchor point="LEFT"/> - </Anchors> - </HighlightTexture> - <Scripts> - <OnLoad> - local fontString = self:CreateFontString(nil, "OVERLAY", "GameFontNormal") - fontString:SetPoint("LEFT", 20, 0) - self:SetFontString(fontString) - </OnLoad> - <OnClick> - toggleCollapse(self:GetParent(), self:GetParent():GetParent():GetParent().scrollFrame) - if self:GetParent().collapsed then - self:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-UP") - self:SetPushedTexture("Interface\\Buttons\\UI-PlusButton-DOWN") - else - self:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-UP") - self:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-DOWN") - end - </OnClick> - </Scripts> - </Button> - </Frames> - </Frame> - <!--virtual frame used to allow for script generated frames with stat information--> - <Frame name="ww_statFrame" virtual="true"> - <Size> - <AbsDimension y="22"/> - </Size> - <Anchors> - <Anchor point="RIGHT"> - <Offset> - <AbsDimension x="-5"/> - </Offset> - </Anchor> - </Anchors> - <Layers> - <Layer level="OVERLAY"> - <FontString name="$parentText" parentKey="text" inherits="GameFontNormal"> - <Size> - <AbsDimension y="20"/> - </Size> - <Anchors> - <Anchor point="LEFT"> - <Offset> - <AbsDimension x="20"/> - </Offset> - </Anchor> - </Anchors> - </FontString> - </Layer> - </Layers> - <Frames> - <Frame name="$parentHighlightFrame" parentKey="highlightFrame" inherits="ww_highlightedFrame"> - <Anchors> - <Anchor point="TOPLEFT"> - <Offset> - <AbsDimension x="15" y="-1"/> - </Offset> - </Anchor> - <Anchor point="BOTTOMRIGHT"> - <Offset> - <AbsDimension x="-132" y="-1"/> - </Offset> - </Anchor> - </Anchors> - </Frame> - <EditBox letters="16" name="$parentStatValue" parentKey="statValue" autoFocus="false"> - <Size> - <AbsDimension x="130" y="22"/> - </Size> - <Anchors> - <Anchor point="RIGHT"/> - </Anchors> - <Backdrop edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true"> - <EdgeSize> - <AbsValue val="10"/> - </EdgeSize> - <TileSize> - <AbsValue val="10"/> - </TileSize> - <BackgroundInsets> - <AbsInset left="0" right="0" top="5" bottom="5"/> - </BackgroundInsets> - </Backdrop> - <FontString inherits="GameFontNormal"> - <Anchors> - <Anchor point="LEFT"/> - </Anchors> - </FontString> - <Scripts> - <OnLoad> - self:SetTextInsets(5, 5, 0, 0) - </OnLoad> - <OnTextChanged> - local text = self:GetText() - if self:GetNumber() ~= 0 or text:match("^[0.]+$") or text == "" then - self.number = text - end - if self:GetNumber() == ww_weights.rightPanel.statList[self:GetParent().statName] or (self:GetNumber() == 0 and not ww_weights.rightPanel.statList[self:GetParent().statName]) then - ww_weights.rightPanel.changedStats[self] = nil - local changed = false - for _ in pairs(ww_weights.rightPanel.changedStats) do - changed = true - break - end - if not changed then - ww_weights.rightPanel.saveButton:Disable() - ww_weights.rightPanel.resetButton:Disable() - end - else - ww_weights.rightPanel.changedStats[self] = self:GetParent().statName - ww_weights.rightPanel.saveButton:Enable() - ww_weights.rightPanel.resetButton:Enable() - end - </OnTextChanged> - <OnChar> - if validateNumber(text, self:GetText()) then - self.number = self:GetText() - else - local cursorPosition = self:GetCursorPosition() - 1 - self:SetText(self.number) - self:SetCursorPosition(cursorPosition) - end - </OnChar> - <OnEditFocusGained> - self:GetParent().highlightFrame:Show() - self:HighlightText() - </OnEditFocusGained> - <OnEditFocusLost> - self:GetParent().highlightFrame:Hide() - self:HighlightText(0,0) - </OnEditFocusLost> - <OnTabPressed> - changeFocus(self:GetParent()) - </OnTabPressed> - <OnEscapePressed> - self:ClearFocus() - </OnEscapePressed> - </Scripts> - </EditBox> - </Frames> - </Frame> - <!--virtual frame used to allow for script generated frames with stat information--> - <Frame name="ww_weightFrame" virtual="true"> - <Size> - <AbsDimension y="22"/> - </Size> - <Anchors> - <Anchor point="RIGHT"/> - </Anchors> - <Frames> - <CheckButton name="$parentCheckButton" parentKey="checkButton" inherits="UICheckButtonTemplate" text="Watch this Weight"> - <Size> - <AbsDimension x="20" y="20"/> - </Size> - <Anchors> - <Anchor point="LEFT"> - <Offset> - <AbsDimension x="10"/> - </Offset> - </Anchor> - </Anchors> - <Scripts> - <OnClick> - local parent = self:GetParent() - local class = parent.category.class - - if not ww_charVars.activeWeights[class] then - ww_charVars.activeWeights[class] = {} - table.insert(ww_charVars.activeWeights, class) - end - if self:GetChecked() then - table.insert(ww_charVars.activeWeights[class], parent.name) - else - for i, weight in ipairs(ww_charVars.activeWeights[class]) do - if weight == parent.name then - table.remove(ww_charVars.activeWeights[class], i) - break - end - end - end - </OnClick> - <OnEnter> - GameTooltip:SetOwner(self,"ANCHOR_RIGHT") - GameTooltip:AddLine("Watch this weight?", 1, 1, 1) - GameTooltip:Show() - </OnEnter> - <OnLeave> - GameTooltip:Hide() - </OnLeave> - </Scripts> - </CheckButton> - <Button name="$parentText" parentKey="text"> - <Size> - <AbsDimension y="20"/> - </Size> - <Anchors> - <Anchor point="LEFT"> - <Offset> - <AbsDimension x="40"/> - </Offset> - </Anchor> - <Anchor point="RIGHT"/> - </Anchors> - <HighlightTexture file="Interface\Buttons\UI-Listbox-Highlight2" alphaMode="ADD"> - <Anchors> - <Anchor point="TOPLEFT"> - <Offset> - <AbsDimension x="-3" y="-2"/> - </Offset> - </Anchor> - <Anchor point="BOTTOMRIGHT"> - <Offset> - <AbsDimension x="-7"/> - </Offset> - </Anchor> - </Anchors> - </HighlightTexture> - <Frames> - <Frame name="$parentHighlightFrame" parentKey="highlightFrame" inherits="ww_highlightedFrame"> - <Anchors> - <Anchor point="TOPLEFT"> - <Offset> - <AbsDimension x="-5" y="-1"/> - </Offset> - </Anchor> - <Anchor point="BOTTOMRIGHT"> - <Offset> - <AbsDimension x="-5" y="-1"/> - </Offset> - </Anchor> - </Anchors> - </Frame> - </Frames> - <Scripts> - <OnClick> - configDiscardChanges(function() - configSelectWeight(self:GetParent()) - end) - </OnClick> - <OnLoad> - self:SetFontString(self:CreateFontString(nil, "OVERLAY", "ww_defaultString")) - </OnLoad> - </Scripts> - </Button> - </Frames> - </Frame> - <!-- The frame containing all weight-related content --> - <Frame name="ww_weights" parent="UIParent" hidden="true" frameStrata="HIGH"> - <Size> - <AbsDimension x="600" y="600"/> - </Size> - <Anchors> - <Anchor point="CENTER"/> - </Anchors> - <Layers> - <Layer level="BACKGROUND"> - <Texture setAllPoints="true"> - <!--Plain black background with 50% alpha--> - <Color r="0" g="0" b="0" a="0.8"/> - </Texture> - </Layer> - </Layers> - <!--list of objects within the configuartion window--> - <Frames> - <!--The Class Selection Frame--> - <Frame name="$parentLeftPanel" parentKey="leftPanel"> - <Size> - <AbsDimension x="150"/> - </Size> - <Anchors> - <Anchor point="TOP"> - <Offset> - <AbsDimension y="-25"/> - </Offset> - </Anchor> - <Anchor point="LEFT"/> - <Anchor point="BOTTOM"> - <Offset> - <AbsDimension y="25"/> - </Offset> - </Anchor> - </Anchors> - <Backdrop edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true"> - <EdgeSize> - <AbsValue val="10"/> - </EdgeSize> - <TileSize> - <AbsValue val="10"/> - </TileSize> - <BackgroundInsets> - <AbsInset left="0" right="0" top="5" bottom="5"/> - </BackgroundInsets> - </Backdrop> - <Frames> - <!--used to hold a series of stat frames to maintain absolute position when scrolling--> - <Frame name="$parentScrollContainer" parentKey="scrollContainer"> - <Anchors> - <Anchor point="LEFT"/> - <Anchor point="RIGHT"/> - </Anchors> - </Frame> - <!--Invisible frame with scroll bar that does the scrolling--> - <ScrollFrame name="$parentScrollFrame" parentKey="scrollFrame" inherits="FauxScrollFrameTemplate"> - <Anchors> - <Anchor point="TOPLEFT"/> - <Anchor point="BOTTOMRIGHT"> - <Offset> - <AbsDimension x="-5"/> - </Offset> - </Anchor> - </Anchors> - <Scripts> - <OnShow> - scrollBarUpdate(self, ww_weights.leftPanel.scrollContainer, 22, 0, 25) - </OnShow> - <OnVerticalScroll> - FauxScrollFrame_OnVerticalScroll(self, offset, 22, self:GetScript("OnShow")) - </OnVerticalScroll> - </Scripts> - </ScrollFrame> - </Frames> - </Frame> - <!--Right Frame for viewing the weights for each class--> - <Frame name="$parentRightPanel" parentKey="rightPanel" hidden="true"> - <Anchors> - <Anchor point="TOPLEFT" relativeTo="$parentLeftPanel" relativePoint="TOPRIGHT"> - <Offset> - <AbsDimension x="20"/> - </Offset> - </Anchor> - <Anchor point="BOTTOM" relativeTo="$parentLeftPanel"/> - <Anchor point="RIGHT"> - <Offset> - <AbsDimension x="-20"/> - </Offset> - </Anchor> - </Anchors> - <Layers> - <Layer level="OVERLAY"> - <FontString name="$parentHeader" parentKey="header" inherits="GameFontNormal"> - <Anchors> - <Anchor point="TOP"> - <Offset> - <AbsDimension y="-5"/> - </Offset> - </Anchor> - </Anchors> - </FontString> - </Layer> - </Layers> - <Backdrop edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true"> - <EdgeSize> - <AbsValue val="10"/> - </EdgeSize> - <TileSize> - <AbsValue val="10"/> - </TileSize> - <BackgroundInsets> - <AbsInset left="0" right="0" top="5" bottom="5"/> - </BackgroundInsets> - </Backdrop> - <Frames> - <!--Save button--> - <Button name="$parentSaveButton" parentKey="saveButton" inherits="UIPanelButtonTemplate" text="Save"> - <Size> - <AbsDimension x="80" y="22"/> - </Size> - <Anchors> - <Anchor point="BOTTOMLEFT"> - <Offset> - <AbsDimension x="5" y="5"/> - </Offset> - </Anchor> - </Anchors> - <Scripts> - <OnClick> - configSaveWeight() - </OnClick> - </Scripts> - </Button> - <!--Copy button--> - <Button name="$parentCopyButton" parentKey="copyButton" inherits="UIPanelButtonTemplate" text="Copy"> - <Size> - <AbsDimension x="80" y="22"/> - </Size> - <Anchors> - <Anchor point="LEFT" relativePoint="RIGHT" relativeTo="$parentSaveButton"> - <Offset> - <AbsDimension x="27"/> - </Offset> - </Anchor> - </Anchors> - <Scripts> - <OnClick> - configNewWeight(self:GetParent().weightFrame.category.class, "Copy of " .. self:GetParent().weightFrame.name, self:GetParent().statList) - </OnClick> - </Scripts> - </Button> - <!--Reset button--> - <Button name="$parentResetButton" parentKey="resetButton" inherits="UIPanelButtonTemplate" text="Reset"> - <Size> - <AbsDimension x="80" y="22"/> - </Size> - <Anchors> - <Anchor point="BOTTOMRIGHT"> - <Offset> - <AbsDimension x="-5" y="5"/> - </Offset> - </Anchor> - </Anchors> - <Scripts> - <OnClick> - configResetWeight() - </OnClick> - </Scripts> - </Button> - <!--Delete button--> - <Button name="$parentDeleteButton" parentKey="deleteButton" inherits="UIPanelButtonTemplate" text="Delete"> - <Size> - <AbsDimension x="80" y="22"/> - </Size> - <Anchors> - <Anchor point="RIGHT" relativePoint="LEFT" relativeTo="$parentResetButton"> - <Offset> - <AbsDimension x="-27"/> - </Offset> - </Anchor> - </Anchors> - <Scripts> - <OnClick> - configDeleteWeight() - </OnClick> - </Scripts> - </Button> - <!--used to hold a series of stat frames to maintain absolute position when scrolling--> - <Frame name="$parentScrollContainer" parentKey="scrollContainer"> - <Anchors> - <Anchor point="LEFT"/> - <Anchor point="RIGHT"/> - </Anchors> - </Frame> - <!--Invisible frame with scroll bar that does the scrolling--> - <ScrollFrame name="$parentScrollFrame" parentKey="scrollFrame" inherits="FauxScrollFrameTemplate"> - <Anchors> - <Anchor point="TOPLEFT"/> - <Anchor point="BOTTOMRIGHT"> - <Offset> - <AbsDimension x="-5"/> - </Offset> - </Anchor> - </Anchors> - <Scripts> - <OnShow> - scrollBarUpdate(self, ww_weights.rightPanel.scrollContainer, 22, -30, 22) - </OnShow> - <OnVerticalScroll> - FauxScrollFrame_OnVerticalScroll(self, offset, 22, self:GetScript("OnShow")) - </OnVerticalScroll> - </Scripts> - </ScrollFrame> - </Frames> - <Scripts> - <OnShow> - if not ww_weights.popup then - changeFocus(self.scrollFrame.stats[#(self.scrollFrame.stats)]) - end - </OnShow> - </Scripts> - </Frame> - <!--Close Button for the configuration window--> - <Button name="$parentCloseButton" parentKey="closeButton" inherits="UIPanelCloseButton"> - <Anchors> - <Anchor point="TOPRIGHT"/> - </Anchors> - </Button> - <!--restore default button--> - <Button name="$parentDefaultsButton" parentKey="defaultsButton" inherits="UIPanelButtonTemplate" text="Restore Defaults"> - <Size> - <AbsDimension x="150" y="22"/> - </Size> - <Anchors> - <Anchor point="BOTTOMLEFT"/> - </Anchors> - <Scripts> - <OnClick> - if ww_weights.rightPanel.weightFrame and defaultVars.weightsList[ww_weights.rightPanel.weightFrame.category.class][ww_weights.rightPanel.weightFrame.name] then - StaticPopup_Show("WW_CONFIRM_RESTORE_DEFAULTS") - else - configDiscardChanges(function() - StaticPopup_Show("WW_CONFIRM_RESTORE_DEFAULTS") - end) - end - </OnClick> - </Scripts> - </Button> - <!--Create new weight button--> - <Button name="$parentNewWeightButton" parentKey="newWeightButton" inherits="UIPanelButtonTemplate" text="New Weight"> - <Size> - <AbsDimension x="100" y="22"/> - </Size> - <Anchors> - <Anchor point="BOTTOMRIGHT"/> - </Anchors> - <Scripts> - <OnClick> - configNewWeight() - </OnClick> - </Scripts> - </Button> - </Frames> - <Scripts> - <OnLoad> - table.insert(UISpecialFrames, self:GetName()); - </OnLoad> - <OnHide> - if self.reallyClose then - self.reallyClose = nil - else - self.popup = true - self:Show() - configDiscardChanges(function() - self.reallyClose = true - <!-- Safe because configDiscardChanges will save the weight first --> - if self.rightPanel:IsShown() then - configResetWeight() - end - self:Hide() - end) - self.popup = nil - end - </OnHide> - </Scripts> - </Frame> - <Frame name="ww_newWeight" parent="UIParent" hidden="true" frameStrata="DIALOG"> - <Size> - <AbsDimension x="420" y="120"/> - </Size> - <Anchors> - <Anchor point="CENTER"/> - </Anchors> - <Layers> - <Layer level="ARTWORK"> - <FontString name="$parentText" parentKey="text" inherits="GameFontHighlight" text="Please choose a class and name for your new weight:"> - <Size> - <AbsDimension x="380" y="0"/> - </Size> - <Anchors> - <Anchor point="TOP"> - <Offset> - <AbsDimension x="0" y="-16"/> - </Offset> - </Anchor> - </Anchors> - </FontString> - </Layer> - <Layer level="BACKGROUND"> - <Texture setAllPoints="true"> - <!--Plain black background with 50% alpha--> - <Color r="0" g="0" b="0" a="0.5"/> - </Texture> - </Layer> - </Layers> - <Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true"> - <BackgroundInsets> - <AbsInset left="11" right="12" top="12" bottom="11"/> - </BackgroundInsets> - <TileSize> - <AbsValue val="32"/> - </TileSize> - <EdgeSize> - <AbsValue val="32"/> - </EdgeSize> - </Backdrop> - <Frames> - <Button name="$parentDropDown" parentKey="dropdown" inherits="UIDropDownMenuTemplate"> - <Anchors> - <Anchor point="LEFT"/> - </Anchors> - <Scripts> - <OnShow> - ClassDropDownOnShow(self); - </OnShow> - </Scripts> - </Button> - <EditBox letters="50" name="$parentEditBox" parentKey="editBox"> - <Size> - <AbsDimension y="32"/> - </Size> - <Anchors> - <Anchor point="BOTTOM" > - <Offset> - <AbsDimension x="0" y="45"/> - </Offset> - </Anchor> - <Anchor point="RIGHT"> - <Offset> - <AbsDimension x="-25"/> - </Offset> - </Anchor> - <Anchor point="LEFT" relativeTo="$parentDropDown" relativePoint="RIGHT"> - <Offset> - <AbsDimension x="125"/> - </Offset> - </Anchor> - </Anchors> - <FontString inherits="ChatFontNormal"/> - <Layers> - <Layer level="BACKGROUND"> - <Texture file="Interface\ChatFrame\UI-ChatInputBorder-Left"> - <Size> - <AbsDimension x="128" y="32"/> - </Size> - <Anchors> - <Anchor point="LEFT"> - <Offset> - <AbsDimension x="-10" y="0"/> - </Offset> - </Anchor> - </Anchors> - <TexCoords left="0" right="0.5" top="0" bottom="1.0"/> - </Texture> - <Texture file="Interface\ChatFrame\UI-ChatInputBorder-Right"> - <Size> - <AbsDimension x="128" y="32"/> - </Size> - <Anchors> - <Anchor point="RIGHT"> - <Offset> - <AbsDimension x="10" y="0"/> - </Offset> - </Anchor> - </Anchors> - <TexCoords left="0.5" right="1.0" top="0" bottom="1.0"/> - </Texture> - </Layer> - </Layers> - <Scripts> - <OnLoad> - self:SetTextInsets(5, 5, 0, 0) - </OnLoad> - <OnTextChanged> - if self:GetText() == "" then - self:GetParent().createButton:Disable() - else - self:GetParent().createButton:Enable() - end - </OnTextChanged> - <OnEnterPressed> - if StaticPopup_Visible("WW_WEIGHT_EXISTS") then - StaticPopup_Hide("WW_WEIGHT_EXISTS") - else - self:GetParent().createButton:Click() - end - </OnEnterPressed> - <OnEscapePressed> - if StaticPopup_Visible("WW_WEIGHT_EXISTS") then - StaticPopup_Hide("WW_WEIGHT_EXISTS") - else - self:GetParent().cancelButton:Click() - end - </OnEscapePressed> - </Scripts> - </EditBox> - <Button name="$parentCreateButton" parentKey="createButton" inherits="UIPanelButtonTemplate" text="Create"> - <Size> - <AbsDimension x="128" y="20"/> - </Size> - <Anchors> - <Anchor point="BOTTOMRIGHT" relativePoint="BOTTOM"> - <Offset> - <AbsDimension x="-6" y="16"/> - </Offset> - </Anchor> - </Anchors> - <Scripts> - <OnClick> - local class = UIDropDownMenu_GetSelectedValue(self:GetParent().dropdown) - local name = self:GetParent().editBox:GetText() - if ww_vars.weightsList[class][name] then - local error = StaticPopup_Show("WW_WEIGHT_EXISTS", classNames[class], name) - else - setWeight(class, name, self:GetParent().statList) - selectWeight(class, name) - self:GetParent():Hide() - end - </OnClick> - </Scripts> - </Button> - <Button name="$parentCancelButton" parentKey="cancelButton" inherits="UIPanelButtonTemplate" text="Cancel"> - <Size> - <AbsDimension x="128" y="20"/> - </Size> - <Anchors> - <Anchor point="BOTTOMLEFT" relativePoint="BOTTOM"> - <Offset> - <AbsDimension x="6" y="16"/> - </Offset> - </Anchor> - </Anchors> - <Scripts> - <OnClick> - self:GetParent():Hide() - </OnClick> - </Scripts> - </Button> - </Frames> - <Scripts> - <OnShow> - self.editBox:SetFocus() - </OnShow> - </Scripts> - </Frame> </Ui> diff --git a/config.lua b/config.lua index 40a8c61..1a09f08 100644 --- a/config.lua +++ b/config.lua @@ -2,562 +2,28 @@ if not WeightsWatcher then WeightsWatcher = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceHook-2.1") end -StaticPopupDialogs["WW_CONFIRM_DISCARD_CHANGES"] = { - text = "You have unsaved changes for this weight.", - button1 = "Discard", - button3 = "Save", - button2 = "Cancel", - OnAccept = function(self, func) - func() - end, - OnAlt = function(self, func) - configSaveWeight() - func() - end, - showAlert = true, - timeout = 0, - whileDead = true, - hideOnEscape = true, -} - -StaticPopupDialogs["WW_CONFIRM_WEIGHT_DELETE"] = { - text = "Are you sure you want to delete the %s weight named \"%s\"?", - button1 = "Delete", - button2 = "Cancel", - OnAccept = function() - deleteWeight() - end, - showAlert = true, - timeout = 0, - whileDead = true, - hideOnEscape = true, -} - -StaticPopupDialogs["WW_CONFIRM_RESTORE_DEFAULTS"] = { - text = "Are you sure you want to restore default weights? This will overwrite any weights with the default names (but leave others alone).", - button1 = "Restore Defaults", - button2 = "Cancel", - OnAccept = function() - for _, class in ipairs(defaultVars.weightsList) do - for _, weight in ipairs(defaultVars.weightsList[class]) do - setWeight(class, weight, defaultVars.weightsList[class][weight]) - if ww_weightCache[class] then - ww_weightCache[class][weight] = {} - end - if ww_weightIdealCache[class] then - ww_weightIdealCache[class][weight] = {} - end - end - end - if ww_weights.rightPanel:IsShown() then - configSelectWeight(ww_weights.rightPanel.weightFrame) - end - end, - showAlert = true, - timeout = 0, - whileDead = true, - 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 - --- initializes weights config frames and variables -function initializeWeightsConfig() - loadClassButtons() - loadStatButtons() -end - ---display or hide the frame -function open_config() - if ww_weights:IsVisible() then - ww_weights:Hide() - else - ww_weights:Show() - end -end - -function validateNumber(newChar, newText) - if string.find(newChar, "^[0-9]$") then - return true - elseif newChar == '.' then - local first = newText:find(".", 1, true) - local second = newText:find(".", first + 1, true) - if not second then - return true - end - elseif newChar == '-' then - if not string.find(newText, "-", 2) then - return true - end - end - return false -end - -function scrollBarUpdate(scrollFrame, scrolledFrame, buttonHeight, initialOffset, numShown) - local i - local offset = FauxScrollFrame_GetOffset(scrollFrame) - offset = offset / 5 - if numShown > #(scrollFrame.shown) then - numShown = #(scrollFrame.shown) - end - if offset > #(scrollFrame.shown) - numShown then - offset = #(scrollFrame.shown) - numShown - end - if offset < 0 then - offset = 0 - end - FauxScrollFrame_Update(scrollFrame, #(scrollFrame.shown), numShown, buttonHeight * 5) - scrolledFrame:SetPoint("TOPLEFT", 0, initialOffset + buttonHeight * offset) - for i = 1, offset do - scrollFrame.shown[i]:Hide() - end - for i = offset + 1, offset + numShown do - scrollFrame.shown[i]:Show() - end - for i = offset + numShown + 1, #(scrollFrame.shown) do - scrollFrame.shown[i]:Hide() - end -end - ---moves the editbox focus to the next available edit box -function changeFocus(currentStatFrame) - local frame, offset - local timesLooped = 0 - local elements = ww_weights.rightPanel.scrollFrame.shown - local position = currentStatFrame.category.position + currentStatFrame.position - - if IsShiftKeyDown() then - direction = -1 - else - direction = 1 - end - repeat - position = position + direction - if not elements[position] then - if direction < 0 then - position = #(elements) - else - position = 1 - end - timesLooped = timesLooped + 1 - end - until timesLooped == 2 or elements[position].statName - - if timesLooped == 2 then - return - end - - frame = elements[position] - if frame then - if not frame:IsShown() then - if direction < 0 then - offset = (position - 1) * 5 - else - offset = (position - 22) * 5 - end - FauxScrollFrame_SetOffset(ww_weights.rightPanel.scrollFrame, offset) - ww_weights.rightPanel.scrollFrame:GetScript("OnVerticalScroll")(ww_weights.rightPanel.scrollFrame, offset * 22) - end - frame.statValue:SetFocus() - end -end - -function configDiscardChanges(func) - if ww_weights.rightPanel:IsShown() and ww_weights.rightPanel.changedStats then - for _, _ in pairs(ww_weights.rightPanel.changedStats) do - local popup = StaticPopup_Show("WW_CONFIRM_DISCARD_CHANGES") - popup.data = func - return - end - end - func() -end - -function selectWeight(class, name) - for _, classFrame in ipairs(ww_weights.leftPanel.scrollFrame.categories) do - if classFrame.class == class then - local children = {classFrame:GetChildren()} - configSelectWeight(children[classFrame:GetNumChildren()]) - break - end - end -end - ---opens a new config pane to edit stat weights -function configSelectWeight(weightFrame) - local empty - - if ww_weights.rightPanel.weightFrame then - ww_weights.rightPanel.weightFrame.text.highlightFrame:Hide() - end - weightFrame.text.highlightFrame:Show() - - ww_weights.rightPanel.weightFrame = weightFrame - ww_weights.rightPanel.statList = ww_vars.weightsList[weightFrame.category.class][weightFrame.name] - ww_weights.rightPanel.changedStats = {} - - -- Fills the right panel with the current weight's stats - configResetWeight() - - for _, categoryFrame in ipairs(ww_weights.rightPanel.scrollFrame.categories) do - empty = true - for _, statFrame in ipairs({categoryFrame:GetChildren()}) do - if statFrame.statName then - if statFrame.statValue:GetText() ~= "" then - empty = false - break - end - end - end - if (categoryFrame.collapsed and not empty) or (not categoryFrame.collapsed and empty) then - categoryFrame.text:Click() - end - end - - ww_weights.rightPanel.header:SetText(weightFrame.category.name .. " - " .. weightFrame.name) - ww_weights.rightPanel:Show() -end - -function configResetWeight() - local value - local changed = false - - if ww_weights.rightPanel.changedStats then - for statValue, statName in pairs(ww_weights.rightPanel.changedStats) do - changed = true - value = ww_weights.rightPanel.statList[statName] - if not value then - value = "" - end - statValue:SetText(value) - end - end - if not changed then - for _, frame in pairs(ww_weights.rightPanel.scrollFrame.stats) do - if frame.statName then - value = ww_weights.rightPanel.statList[frame.statName] - if not value then - value = "" - end - frame.statValue:SetText(value) - end - end - end - - ww_weights.rightPanel.changedStats = {} - ww_weights.rightPanel.saveButton:Disable() - ww_weights.rightPanel.resetButton:Disable() -end - -function configDeleteWeight() - StaticPopup_Show("WW_CONFIRM_WEIGHT_DELETE", ww_weights.rightPanel.weightFrame.category.name, ww_weights.rightPanel.weightFrame.name) -end - -function configSaveWeight() - local number - local weightFrame = ww_weights.rightPanel.weightFrame - - -- The weight is changing, clear any cached info - if ww_weightCache[weightFrame.category.class] then - ww_weightCache[weightFrame.category.class][weightFrame.name] = {} - end - if ww_weightIdealCache[weightFrame.category.class] then - ww_weightIdealCache[weightFrame.category.class][weightFrame.name] = {} - end - - for statValue, statName in pairs(ww_weights.rightPanel.changedStats) do - number = statValue:GetNumber() - if number == 0 then - number = nil - end - ww_weights.rightPanel.statList[statName] = number - end - - ww_weights.rightPanel.changedStats = {} - ww_weights.rightPanel.saveButton:Disable() - ww_weights.rightPanel.resetButton:Disable() -end - -function deleteWeight() - local point, relativeTo, relativePoint, xOffset, yOffset, removed - local weight = ww_weights.rightPanel.weightFrame - - -- The weight is being deleted, clear any cached info - if ww_weightCache[weight.category.class] then - ww_weightCache[weight.category.class][weight.name] = nil - end - if ww_weightIdealCache[weight.category.class] then - ww_weightIdealCache[weight.category.class][weight.name] = nil - end - - 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 + 22) - break - end - end - end - end - if not weight.category.collapsed then - for _, classFrame in ipairs(ww_weights.leftPanel.scrollFrame.categories) do - if classFrame.position > weight.category.position then - classFrame.position = classFrame.position - 1 - end - end - table.remove(ww_weights.leftPanel.scrollFrame.shown, weight.category.position + weight.position) - weight.category:SetHeight(22 * weight.category.length) - end - weight:Hide() - weight:SetParent(nil) - - removed = false - for i, name in ipairs(ww_vars.weightsList[weight.category.class]) do - if removed then - ww_vars.weightsList[weight.category.class][i - 1] = ww_vars.weightsList[weight.category.class][i] - ww_vars.weightsList[weight.category.class][i] = nil - elseif name == weight.name then - ww_vars.weightsList[weight.category.class][i] = nil - removed = true - end - end - ww_vars.weightsList[weight.category.class][weight.name] = nil - removed = false - if ww_charVars.activeWeights[weight.category.class] then - for i, name in ipairs(ww_charVars.activeWeights[weight.category.class]) do - if removed then - ww_charVars.activeWeights[weight.category.class][i - 1] = ww_charVars.activeWeights[weight.category.class][i] - ww_charVars.activeWeights[weight.category.class][i] = nil - elseif name == weight.name then - ww_charVars.activeWeights[weight.category.class][i] = nil - removed = true - end - end - end - ww_weights.rightPanel:Hide() - ww_weights.leftPanel.scrollFrame:GetScript("OnShow")(ww_weights.leftPanel.scrollFrame) -end - -function configNewWeight(class, weight, statList) - configDiscardChanges(function() - -- Need to call show first to re-initialize the dropdown - ww_newWeight:Show() - if class then - UIDropDownMenu_SetSelectedValue(ww_newWeight.dropdown, class, false) - end - ww_newWeight.editBox:SetText("") - if weight then - ww_newWeight.editBox:SetText(weight) - end - if not statList then - statList = {} - end - ww_newWeight.statList = statList - end) -end - -function setWeight(class, weight, statList) - local weightFrame, position - - if not ww_vars.weightsList[class][weight] then - for _, classFrame in ipairs(ww_weights.leftPanel.scrollFrame.categories) do - if classFrame.class == class then - position = classFrame.length - weightFrame = CreateFrame("Frame", weight, classFrame, "ww_weightFrame") - weightFrame.position = position - weightFrame.category = classFrame - weightFrame.text:SetText(weight) - weightFrame.name = weight - weightFrame:SetPoint("TOPLEFT", 0, -22 * position) - classFrame.length = classFrame.length + 1 - if classFrame.collapsed then - weightFrame:Hide() - else - classFrame:SetHeight(22 * classFrame.length) - table.insert(ww_weights.leftPanel.scrollFrame.shown, classFrame.position + position, weightFrame) - for _, class in ipairs(ww_weights.leftPanel.scrollFrame.categories) do - if class.position > classFrame.position then - class.position = class.position + 1 - end - end - end - break - end - end - table.insert(ww_vars.weightsList[class], weight) - ww_weights.leftPanel.scrollFrame:GetScript("OnShow")(ww_weights.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, newClass = {}, {} - - for i, class in ipairs(ww_vars.weightsList) do - newClass = classNames[class] - revClassLookup[newClass] = class - classes[i] = newClass - classes[newClass] = {} - for j, name in ipairs(ww_vars.weightsList[class]) do - classes[newClass][j] = name - end - end - - createScrollableTieredList(classes, ww_weights.leftPanel.scrollFrame, ww_weights.leftPanel.scrollContainer, "ww_weightFrame", 22) - - local _, class = UnitClass("player") - for _, classFrame in ipairs(ww_weights.leftPanel.scrollFrame.categories) do - classFrame.class = revClassLookup[classFrame.text:GetText()] - if classFrame.class ~= class then - classFrame.text:Click() - end - for i, weightFrame in ipairs({classFrame:GetChildren()}) do - if weightFrame.name then - if ww_charVars.activeWeights[classFrame.class] then - for _, weight in ipairs(ww_charVars.activeWeights[classFrame.class]) do - if weight == weightFrame.name then - weightFrame.checkButton:SetChecked(true) - break - end - end - end - end - end - end -end - -function loadStatButtons() - local stats = {} - - createScrollableTieredList(trackedStats, ww_weights.rightPanel.scrollFrame, ww_weights.rightPanel.scrollContainer, "ww_statFrame", 22) - - for _, categoryFrame in ipairs(ww_weights.rightPanel.scrollFrame.categories) do - local children = {categoryFrame:GetChildren()} - for i, statFrame in ipairs(children) do - if statFrame.name then - table.insert(stats, statFrame) - statFrame.statName = string.lower(statFrame.name) - end - end - end - - ww_weights.rightPanel.scrollFrame.stats = stats -end - --- Creates a tiered list that can be scrolled --- template is a table of key-value pairs with keys as the categories and values as a table of elements --- scrollFrame is the scrollframe that controls scrolledFrame --- NOTE: scrollFrame must have an OnShow handler that updates the scrollbar --- scrolledFrame is the frame that will hold everything --- elementType is the element template type --- elementHeight is the height of each element -function createScrollableTieredList(template, scrollFrame, scrolledFrame, elementType, elementHeight) - local categoryFrame, elementFrame - - scrollFrame.categories = {} - scrollFrame.shown = {} - scrollFrame.elementHeight = elementHeight - for i, category in ipairs(template) do - --for each category print the header and then the print the list of stats - categoryFrame = CreateFrame("Frame", category, scrolledFrame, "ww_categoryFrame") - categoryFrame.text:SetText(category) - categoryFrame.name = category - categoryFrame.length = 1 - if i == 1 then - categoryFrame:SetPoint("TOPLEFT") + if msg == "config" then + if ww_config:IsVisible() then + ww_config:Hide() else - categoryFrame:SetPoint("TOPLEFT", scrollFrame.categories[i - 1], "BOTTOMLEFT") + ww_config:Show() end - table.insert(scrollFrame.categories, categoryFrame) - table.insert(scrollFrame.shown, categoryFrame.text) - categoryFrame.position = #(scrollFrame.shown) - for j, element in ipairs(template[category]) do - elementFrame = CreateFrame("Frame", element, scrollFrame.categories[i], elementType) - elementFrame.position = j - elementFrame.category = categoryFrame - elementFrame.text:SetText(element) - elementFrame.name = element - elementFrame:SetPoint("TOPLEFT", 0, -elementHeight * j) - table.insert(scrollFrame.shown, elementFrame) - categoryFrame.length = categoryFrame.length + 1 - end - - categoryFrame:SetHeight(elementHeight * categoryFrame.length) - categoryFrame.collapsed = false - end -end - -function toggleCollapse(categoryFrame, scrollFrame) - if categoryFrame.length == 1 then - return - end - if categoryFrame.collapsed then - for i, stat in ipairs({categoryFrame:GetChildren()}) do - if stat.name then - table.insert(scrollFrame.shown, categoryFrame.position + i - 1, stat) - end - end - for _, category in ipairs(scrollFrame.categories) do - if category.position > categoryFrame.position then - category.position = category.position + categoryFrame.length - 1 - end + elseif msg == "weights" then + if ww_weights:IsVisible() then + ww_weights:Hide() + else + ww_weights:Show() end - categoryFrame.collapsed = false - categoryFrame:SetHeight(scrollFrame.elementHeight * categoryFrame.length) else - for _, stat in ipairs({categoryFrame:GetChildren()}) do - if stat.name then - stat:Hide() - table.remove(scrollFrame.shown, categoryFrame.position + 1) - end - end - for _, category in ipairs(scrollFrame.categories) do - if category.position > categoryFrame.position then - category.position = category.position - categoryFrame.length + 1 - end - end - categoryFrame.collapsed = true - categoryFrame:SetHeight(scrollFrame.elementHeight) - end - scrollFrame:GetScript("OnShow")(scrollFrame) -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) + printHelp() 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) +function printHelp() + print("WeightsWatcher help:") + print("Type /weightswatcher <arg> (or /ww <arg>)") + print(" config opens the main configuration window") + print(" weights opens the weights configuration window") + print(" help displays this message") end diff --git a/config.xml b/config.xml new file mode 100644 index 0000000..7a0d195 --- /dev/null +++ b/config.xml @@ -0,0 +1,4 @@ +<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd"> + <Frame name="ww_config" parent="UIParent" hidden="true" frameStrata="HIGH"/> +</Ui> diff --git a/weights.lua b/weights.lua new file mode 100644 index 0000000..a1bf9af --- /dev/null +++ b/weights.lua @@ -0,0 +1,550 @@ +if not WeightsWatcher then + WeightsWatcher = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceHook-2.1") +end + +StaticPopupDialogs["WW_CONFIRM_DISCARD_CHANGES"] = { + text = "You have unsaved changes for this weight.", + button1 = "Discard", + button3 = "Save", + button2 = "Cancel", + OnAccept = function(self, func) + func() + end, + OnAlt = function(self, func) + configSaveWeight() + func() + end, + showAlert = true, + timeout = 0, + whileDead = true, + hideOnEscape = true, +} + +StaticPopupDialogs["WW_CONFIRM_WEIGHT_DELETE"] = { + text = "Are you sure you want to delete the %s weight named \"%s\"?", + button1 = "Delete", + button2 = "Cancel", + OnAccept = function() + deleteWeight() + end, + showAlert = true, + timeout = 0, + whileDead = true, + hideOnEscape = true, +} + +StaticPopupDialogs["WW_CONFIRM_RESTORE_DEFAULTS"] = { + text = "Are you sure you want to restore default weights? This will overwrite any weights with the default names (but leave others alone).", + button1 = "Restore Defaults", + button2 = "Cancel", + OnAccept = function() + for _, class in ipairs(defaultVars.weightsList) do + for _, weight in ipairs(defaultVars.weightsList[class]) do + setWeight(class, weight, defaultVars.weightsList[class][weight]) + if ww_weightCache[class] then + ww_weightCache[class][weight] = {} + end + if ww_weightIdealCache[class] then + ww_weightIdealCache[class][weight] = {} + end + end + end + if ww_weights.rightPanel:IsShown() then + configSelectWeight(ww_weights.rightPanel.weightFrame) + end + end, + showAlert = true, + timeout = 0, + whileDead = true, + 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, +} + +-- initializes weights config frames and variables +function initializeWeightsConfig() + loadClassButtons() + loadStatButtons() +end + +function validateNumber(newChar, newText) + if string.find(newChar, "^[0-9]$") then + return true + elseif newChar == '.' then + local first = newText:find(".", 1, true) + local second = newText:find(".", first + 1, true) + if not second then + return true + end + elseif newChar == '-' then + if not string.find(newText, "-", 2) then + return true + end + end + return false +end + +function scrollBarUpdate(scrollFrame, scrolledFrame, buttonHeight, initialOffset, numShown) + local i + local offset = FauxScrollFrame_GetOffset(scrollFrame) + offset = offset / 5 + if numShown > #(scrollFrame.shown) then + numShown = #(scrollFrame.shown) + end + if offset > #(scrollFrame.shown) - numShown then + offset = #(scrollFrame.shown) - numShown + end + if offset < 0 then + offset = 0 + end + FauxScrollFrame_Update(scrollFrame, #(scrollFrame.shown), numShown, buttonHeight * 5) + scrolledFrame:SetPoint("TOPLEFT", 0, initialOffset + buttonHeight * offset) + for i = 1, offset do + scrollFrame.shown[i]:Hide() + end + for i = offset + 1, offset + numShown do + scrollFrame.shown[i]:Show() + end + for i = offset + numShown + 1, #(scrollFrame.shown) do + scrollFrame.shown[i]:Hide() + end +end + +--moves the editbox focus to the next available edit box +function changeFocus(currentStatFrame) + local frame, offset + local timesLooped = 0 + local elements = ww_weights.rightPanel.scrollFrame.shown + local position = currentStatFrame.category.position + currentStatFrame.position + + if IsShiftKeyDown() then + direction = -1 + else + direction = 1 + end + repeat + position = position + direction + if not elements[position] then + if direction < 0 then + position = #(elements) + else + position = 1 + end + timesLooped = timesLooped + 1 + end + until timesLooped == 2 or elements[position].statName + + if timesLooped == 2 then + return + end + + frame = elements[position] + if frame then + if not frame:IsShown() then + if direction < 0 then + offset = (position - 1) * 5 + else + offset = (position - 22) * 5 + end + FauxScrollFrame_SetOffset(ww_weights.rightPanel.scrollFrame, offset) + ww_weights.rightPanel.scrollFrame:GetScript("OnVerticalScroll")(ww_weights.rightPanel.scrollFrame, offset * 22) + end + frame.statValue:SetFocus() + end +end + +function configDiscardChanges(func) + if ww_weights.rightPanel:IsShown() and ww_weights.rightPanel.changedStats then + for _, _ in pairs(ww_weights.rightPanel.changedStats) do + local popup = StaticPopup_Show("WW_CONFIRM_DISCARD_CHANGES") + popup.data = func + return + end + end + func() +end + +function selectWeight(class, name) + for _, classFrame in ipairs(ww_weights.leftPanel.scrollFrame.categories) do + if classFrame.class == class then + local children = {classFrame:GetChildren()} + configSelectWeight(children[classFrame:GetNumChildren()]) + break + end + end +end + +--opens a new config pane to edit stat weights +function configSelectWeight(weightFrame) + local empty + + if ww_weights.rightPanel.weightFrame then + ww_weights.rightPanel.weightFrame.text.highlightFrame:Hide() + end + weightFrame.text.highlightFrame:Show() + + ww_weights.rightPanel.weightFrame = weightFrame + ww_weights.rightPanel.statList = ww_vars.weightsList[weightFrame.category.class][weightFrame.name] + ww_weights.rightPanel.changedStats = {} + + -- Fills the right panel with the current weight's stats + configResetWeight() + + for _, categoryFrame in ipairs(ww_weights.rightPanel.scrollFrame.categories) do + empty = true + for _, statFrame in ipairs({categoryFrame:GetChildren()}) do + if statFrame.statName then + if statFrame.statValue:GetText() ~= "" then + empty = false + break + end + end + end + if (categoryFrame.collapsed and not empty) or (not categoryFrame.collapsed and empty) then + categoryFrame.text:Click() + end + end + + ww_weights.rightPanel.header:SetText(weightFrame.category.name .. " - " .. weightFrame.name) + ww_weights.rightPanel:Show() +end + +function configResetWeight() + local value + local changed = false + + if ww_weights.rightPanel.changedStats then + for statValue, statName in pairs(ww_weights.rightPanel.changedStats) do + changed = true + value = ww_weights.rightPanel.statList[statName] + if not value then + value = "" + end + statValue:SetText(value) + end + end + if not changed then + for _, frame in pairs(ww_weights.rightPanel.scrollFrame.stats) do + if frame.statName then + value = ww_weights.rightPanel.statList[frame.statName] + if not value then + value = "" + end + frame.statValue:SetText(value) + end + end + end + + ww_weights.rightPanel.changedStats = {} + ww_weights.rightPanel.saveButton:Disable() + ww_weights.rightPanel.resetButton:Disable() +end + +function configDeleteWeight() + StaticPopup_Show("WW_CONFIRM_WEIGHT_DELETE", ww_weights.rightPanel.weightFrame.category.name, ww_weights.rightPanel.weightFrame.name) +end + +function configSaveWeight() + local number + local weightFrame = ww_weights.rightPanel.weightFrame + + -- The weight is changing, clear any cached info + if ww_weightCache[weightFrame.category.class] then + ww_weightCache[weightFrame.category.class][weightFrame.name] = {} + end + if ww_weightIdealCache[weightFrame.category.class] then + ww_weightIdealCache[weightFrame.category.class][weightFrame.name] = {} + end + + for statValue, statName in pairs(ww_weights.rightPanel.changedStats) do + number = statValue:GetNumber() + if number == 0 then + number = nil + end + ww_weights.rightPanel.statList[statName] = number + end + + ww_weights.rightPanel.changedStats = {} + ww_weights.rightPanel.saveButton:Disable() + ww_weights.rightPanel.resetButton:Disable() +end + +function deleteWeight() + local point, relativeTo, relativePoint, xOffset, yOffset, removed + local weight = ww_weights.rightPanel.weightFrame + + -- The weight is being deleted, clear any cached info + if ww_weightCache[weight.category.class] then + ww_weightCache[weight.category.class][weight.name] = nil + end + if ww_weightIdealCache[weight.category.class] then + ww_weightIdealCache[weight.category.class][weight.name] = nil + end + + 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 + 22) + break + end + end + end + end + if not weight.category.collapsed then + for _, classFrame in ipairs(ww_weights.leftPanel.scrollFrame.categories) do + if classFrame.position > weight.category.position then + classFrame.position = classFrame.position - 1 + end + end + table.remove(ww_weights.leftPanel.scrollFrame.shown, weight.category.position + weight.position) + weight.category:SetHeight(22 * weight.category.length) + end + weight:Hide() + weight:SetParent(nil) + + removed = false + for i, name in ipairs(ww_vars.weightsList[weight.category.class]) do + if removed then + ww_vars.weightsList[weight.category.class][i - 1] = ww_vars.weightsList[weight.category.class][i] + ww_vars.weightsList[weight.category.class][i] = nil + elseif name == weight.name then + ww_vars.weightsList[weight.category.class][i] = nil + removed = true + end + end + ww_vars.weightsList[weight.category.class][weight.name] = nil + removed = false + if ww_charVars.activeWeights[weight.category.class] then + for i, name in ipairs(ww_charVars.activeWeights[weight.category.class]) do + if removed then + ww_charVars.activeWeights[weight.category.class][i - 1] = ww_charVars.activeWeights[weight.category.class][i] + ww_charVars.activeWeights[weight.category.class][i] = nil + elseif name == weight.name then + ww_charVars.activeWeights[weight.category.class][i] = nil + removed = true + end + end + end + ww_weights.rightPanel:Hide() + ww_weights.leftPanel.scrollFrame:GetScript("OnShow")(ww_weights.leftPanel.scrollFrame) +end + +function configNewWeight(class, weight, statList) + configDiscardChanges(function() + -- Need to call show first to re-initialize the dropdown + ww_newWeight:Show() + if class then + UIDropDownMenu_SetSelectedValue(ww_newWeight.dropdown, class, false) + end + ww_newWeight.editBox:SetText("") + if weight then + ww_newWeight.editBox:SetText(weight) + end + if not statList then + statList = {} + end + ww_newWeight.statList = statList + end) +end + +function setWeight(class, weight, statList) + local weightFrame, position + + if not ww_vars.weightsList[class][weight] then + for _, classFrame in ipairs(ww_weights.leftPanel.scrollFrame.categories) do + if classFrame.class == class then + position = classFrame.length + weightFrame = CreateFrame("Frame", weight, classFrame, "ww_weightFrame") + weightFrame.position = position + weightFrame.category = classFrame + weightFrame.text:SetText(weight) + weightFrame.name = weight + weightFrame:SetPoint("TOPLEFT", 0, -22 * position) + classFrame.length = classFrame.length + 1 + if classFrame.collapsed then + weightFrame:Hide() + else + classFrame:SetHeight(22 * classFrame.length) + table.insert(ww_weights.leftPanel.scrollFrame.shown, classFrame.position + position, weightFrame) + for _, class in ipairs(ww_weights.leftPanel.scrollFrame.categories) do + if class.position > classFrame.position then + class.position = class.position + 1 + end + end + end + break + end + end + table.insert(ww_vars.weightsList[class], weight) + ww_weights.leftPanel.scrollFrame:GetScript("OnShow")(ww_weights.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, newClass = {}, {} + + for i, class in ipairs(ww_vars.weightsList) do + newClass = classNames[class] + revClassLookup[newClass] = class + classes[i] = newClass + classes[newClass] = {} + for j, name in ipairs(ww_vars.weightsList[class]) do + classes[newClass][j] = name + end + end + + createScrollableTieredList(classes, ww_weights.leftPanel.scrollFrame, ww_weights.leftPanel.scrollContainer, "ww_weightFrame", 22) + + local _, class = UnitClass("player") + for _, classFrame in ipairs(ww_weights.leftPanel.scrollFrame.categories) do + classFrame.class = revClassLookup[classFrame.text:GetText()] + if classFrame.class ~= class then + classFrame.text:Click() + end + for i, weightFrame in ipairs({classFrame:GetChildren()}) do + if weightFrame.name then + if ww_charVars.activeWeights[classFrame.class] then + for _, weight in ipairs(ww_charVars.activeWeights[classFrame.class]) do + if weight == weightFrame.name then + weightFrame.checkButton:SetChecked(true) + break + end + end + end + end + end + end +end + +function loadStatButtons() + local stats = {} + + createScrollableTieredList(trackedStats, ww_weights.rightPanel.scrollFrame, ww_weights.rightPanel.scrollContainer, "ww_statFrame", 22) + + for _, categoryFrame in ipairs(ww_weights.rightPanel.scrollFrame.categories) do + local children = {categoryFrame:GetChildren()} + for i, statFrame in ipairs(children) do + if statFrame.name then + table.insert(stats, statFrame) + statFrame.statName = string.lower(statFrame.name) + end + end + end + + ww_weights.rightPanel.scrollFrame.stats = stats +end + +-- Creates a tiered list that can be scrolled +-- template is a table of key-value pairs with keys as the categories and values as a table of elements +-- scrollFrame is the scrollframe that controls scrolledFrame +-- NOTE: scrollFrame must have an OnShow handler that updates the scrollbar +-- scrolledFrame is the frame that will hold everything +-- elementType is the element template type +-- elementHeight is the height of each element +function createScrollableTieredList(template, scrollFrame, scrolledFrame, elementType, elementHeight) + local categoryFrame, elementFrame + + scrollFrame.categories = {} + scrollFrame.shown = {} + scrollFrame.elementHeight = elementHeight + for i, category in ipairs(template) do + --for each category print the header and then the print the list of stats + categoryFrame = CreateFrame("Frame", category, scrolledFrame, "ww_categoryFrame") + categoryFrame.text:SetText(category) + categoryFrame.name = category + categoryFrame.length = 1 + if i == 1 then + categoryFrame:SetPoint("TOPLEFT") + else + categoryFrame:SetPoint("TOPLEFT", scrollFrame.categories[i - 1], "BOTTOMLEFT") + end + table.insert(scrollFrame.categories, categoryFrame) + table.insert(scrollFrame.shown, categoryFrame.text) + categoryFrame.position = #(scrollFrame.shown) + for j, element in ipairs(template[category]) do + elementFrame = CreateFrame("Frame", element, scrollFrame.categories[i], elementType) + elementFrame.position = j + elementFrame.category = categoryFrame + elementFrame.text:SetText(element) + elementFrame.name = element + elementFrame:SetPoint("TOPLEFT", 0, -elementHeight * j) + table.insert(scrollFrame.shown, elementFrame) + categoryFrame.length = categoryFrame.length + 1 + end + + categoryFrame:SetHeight(elementHeight * categoryFrame.length) + categoryFrame.collapsed = false + end +end + +function toggleCollapse(categoryFrame, scrollFrame) + if categoryFrame.length == 1 then + return + end + if categoryFrame.collapsed then + for i, stat in ipairs({categoryFrame:GetChildren()}) do + if stat.name then + table.insert(scrollFrame.shown, categoryFrame.position + i - 1, stat) + end + end + for _, category in ipairs(scrollFrame.categories) do + if category.position > categoryFrame.position then + category.position = category.position + categoryFrame.length - 1 + end + end + categoryFrame.collapsed = false + categoryFrame:SetHeight(scrollFrame.elementHeight * categoryFrame.length) + else + for _, stat in ipairs({categoryFrame:GetChildren()}) do + if stat.name then + stat:Hide() + table.remove(scrollFrame.shown, categoryFrame.position + 1) + end + end + for _, category in ipairs(scrollFrame.categories) do + if category.position > categoryFrame.position then + category.position = category.position - categoryFrame.length + 1 + end + end + categoryFrame.collapsed = true + categoryFrame:SetHeight(scrollFrame.elementHeight) + end + scrollFrame:GetScript("OnShow")(scrollFrame) +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 diff --git a/weights.xml b/weights.xml new file mode 100644 index 0000000..725e243 --- /dev/null +++ b/weights.xml @@ -0,0 +1,808 @@ +<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd"> + <Script file="weights.lua"/> + <!--Default String used to allow for simpler left alignment in script generated fontstrings--> + <FontString name="ww_defaultString" inherits="GameFontNormalSmall" virtual="true"> + <Anchors> + <Anchor point="LEFT"/> + </Anchors> + </FontString> + <!-- Adds a border that can be hidden/shown as a unit --> + <Frame name="ww_highlightedFrame" virtual="true" hidden="true"> + <Layers> + <Layer level="BACKGROUND"> + <Texture file="Interface\Buttons\UI-Panel-Button-Glow" alphaMode="ADD"> + <Size> + <AbsDimension y="22" x="16"/> + </Size> + <Anchors> + <Anchor point="LEFT"/> + </Anchors> + <TexCoords left="0.03125" right="0.25" top=".0625" bottom=".5625"/> + </Texture> + <Texture file="Interface\Buttons\UI-Panel-Button-Glow" alphaMode="ADD"> + <Size> + <AbsDimension y="22"/> + </Size> + <Anchors> + <Anchor point="LEFT"> + <Offset> + <AbsDimension x="16"/> + </Offset> + </Anchor> + <Anchor point="RIGHT"> + <Offset> + <AbsDimension x="-16"/> + </Offset> + </Anchor> + </Anchors> + <TexCoords left="0.25" right="0.5" top=".0625" bottom=".5625"/> + </Texture> + <Texture file="Interface\Buttons\UI-Panel-Button-Glow" alphaMode="ADD"> + <Size> + <AbsDimension y="22" x="16"/> + </Size> + <Anchors> + <Anchor point="RIGHT"/> + </Anchors> + <TexCoords left=".5" right=".6875" top=".0625" bottom=".5625"/> + </Texture> + </Layer> + </Layers> + </Frame> + <!-- virtual frame used for categories in tiered lists --> + <Frame name="ww_categoryFrame" virtual="true"> + <Size> + <AbsDimension y="22"/> + </Size> + <Anchors> + <Anchor point="RIGHT"/> + </Anchors> + <Frames> + <Button name="$parentText" parentKey="text"> + <Size> + <AbsDimension y="20"/> + </Size> + <Anchors> + <Anchor point="TOPLEFT"> + <Offset> + <AbsDimension x="5" y="-1"/> + </Offset> + </Anchor> + <Anchor point="RIGHT"/> + </Anchors> + <NormalTexture file="Interface\Buttons\UI-MinusButton-UP"> + <Size> + <AbsDimension x="16" y="16"/> + </Size> + <Anchors> + <Anchor point="LEFT"/> + </Anchors> + </NormalTexture> + <PushedTexture file="Interface\Buttons\UI-MinusButton-DOWN"> + <Size> + <AbsDimension x="16" y="16"/> + </Size> + <Anchors> + <Anchor point="LEFT"/> + </Anchors> + </PushedTexture> + <HighlightTexture file="Interface\Buttons\UI-PlusButton-Hilight" alphaMode="ADD"> + <Size> + <AbsDimension x="16" y="16"/> + </Size> + <Anchors> + <Anchor point="LEFT"/> + </Anchors> + </HighlightTexture> + <Scripts> + <OnLoad> + local fontString = self:CreateFontString(nil, "OVERLAY", "GameFontNormal") + fontString:SetPoint("LEFT", 20, 0) + self:SetFontString(fontString) + </OnLoad> + <OnClick> + toggleCollapse(self:GetParent(), self:GetParent():GetParent():GetParent().scrollFrame) + if self:GetParent().collapsed then + self:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-UP") + self:SetPushedTexture("Interface\\Buttons\\UI-PlusButton-DOWN") + else + self:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-UP") + self:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-DOWN") + end + </OnClick> + </Scripts> + </Button> + </Frames> + </Frame> + <!--virtual frame used to allow for script generated frames with stat information--> + <Frame name="ww_statFrame" virtual="true"> + <Size> + <AbsDimension y="22"/> + </Size> + <Anchors> + <Anchor point="RIGHT"> + <Offset> + <AbsDimension x="-5"/> + </Offset> + </Anchor> + </Anchors> + <Layers> + <Layer level="OVERLAY"> + <FontString name="$parentText" parentKey="text" inherits="GameFontNormal"> + <Size> + <AbsDimension y="20"/> + </Size> + <Anchors> + <Anchor point="LEFT"> + <Offset> + <AbsDimension x="20"/> + </Offset> + </Anchor> + </Anchors> + </FontString> + </Layer> + </Layers> + <Frames> + <Frame name="$parentHighlightFrame" parentKey="highlightFrame" inherits="ww_highlightedFrame"> + <Anchors> + <Anchor point="TOPLEFT"> + <Offset> + <AbsDimension x="15" y="-1"/> + </Offset> + </Anchor> + <Anchor point="BOTTOMRIGHT"> + <Offset> + <AbsDimension x="-132" y="-1"/> + </Offset> + </Anchor> + </Anchors> + </Frame> + <EditBox letters="16" name="$parentStatValue" parentKey="statValue" autoFocus="false"> + <Size> + <AbsDimension x="130" y="22"/> + </Size> + <Anchors> + <Anchor point="RIGHT"/> + </Anchors> + <Backdrop edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true"> + <EdgeSize> + <AbsValue val="10"/> + </EdgeSize> + <TileSize> + <AbsValue val="10"/> + </TileSize> + <BackgroundInsets> + <AbsInset left="0" right="0" top="5" bottom="5"/> + </BackgroundInsets> + </Backdrop> + <FontString inherits="GameFontNormal"> + <Anchors> + <Anchor point="LEFT"/> + </Anchors> + </FontString> + <Scripts> + <OnLoad> + self:SetTextInsets(5, 5, 0, 0) + </OnLoad> + <OnTextChanged> + local text = self:GetText() + if self:GetNumber() ~= 0 or text:match("^[0.]+$") or text == "" then + self.number = text + end + if self:GetNumber() == ww_weights.rightPanel.statList[self:GetParent().statName] or (self:GetNumber() == 0 and not ww_weights.rightPanel.statList[self:GetParent().statName]) then + ww_weights.rightPanel.changedStats[self] = nil + local changed = false + for _ in pairs(ww_weights.rightPanel.changedStats) do + changed = true + break + end + if not changed then + ww_weights.rightPanel.saveButton:Disable() + ww_weights.rightPanel.resetButton:Disable() + end + else + ww_weights.rightPanel.changedStats[self] = self:GetParent().statName + ww_weights.rightPanel.saveButton:Enable() + ww_weights.rightPanel.resetButton:Enable() + end + </OnTextChanged> + <OnChar> + if validateNumber(text, self:GetText()) then + self.number = self:GetText() + else + local cursorPosition = self:GetCursorPosition() - 1 + self:SetText(self.number) + self:SetCursorPosition(cursorPosition) + end + </OnChar> + <OnEditFocusGained> + self:GetParent().highlightFrame:Show() + self:HighlightText() + </OnEditFocusGained> + <OnEditFocusLost> + self:GetParent().highlightFrame:Hide() + self:HighlightText(0,0) + </OnEditFocusLost> + <OnTabPressed> + changeFocus(self:GetParent()) + </OnTabPressed> + <OnEscapePressed> + self:ClearFocus() + </OnEscapePressed> + </Scripts> + </EditBox> + </Frames> + </Frame> + <!--virtual frame used to allow for script generated frames with stat information--> + <Frame name="ww_weightFrame" virtual="true"> + <Size> + <AbsDimension y="22"/> + </Size> + <Anchors> + <Anchor point="RIGHT"/> + </Anchors> + <Frames> + <CheckButton name="$parentCheckButton" parentKey="checkButton" inherits="UICheckButtonTemplate" text="Watch this Weight"> + <Size> + <AbsDimension x="20" y="20"/> + </Size> + <Anchors> + <Anchor point="LEFT"> + <Offset> + <AbsDimension x="10"/> + </Offset> + </Anchor> + </Anchors> + <Scripts> + <OnClick> + local parent = self:GetParent() + local class = parent.category.class + + if not ww_charVars.activeWeights[class] then + ww_charVars.activeWeights[class] = {} + table.insert(ww_charVars.activeWeights, class) + end + if self:GetChecked() then + table.insert(ww_charVars.activeWeights[class], parent.name) + else + for i, weight in ipairs(ww_charVars.activeWeights[class]) do + if weight == parent.name then + table.remove(ww_charVars.activeWeights[class], i) + break + end + end + end + </OnClick> + <OnEnter> + GameTooltip:SetOwner(self,"ANCHOR_RIGHT") + GameTooltip:AddLine("Watch this weight?", 1, 1, 1) + GameTooltip:Show() + </OnEnter> + <OnLeave> + GameTooltip:Hide() + </OnLeave> + </Scripts> + </CheckButton> + <Button name="$parentText" parentKey="text"> + <Size> + <AbsDimension y="20"/> + </Size> + <Anchors> + <Anchor point="LEFT"> + <Offset> + <AbsDimension x="40"/> + </Offset> + </Anchor> + <Anchor point="RIGHT"/> + </Anchors> + <HighlightTexture file="Interface\Buttons\UI-Listbox-Highlight2" alphaMode="ADD"> + <Anchors> + <Anchor point="TOPLEFT"> + <Offset> + <AbsDimension x="-3" y="-2"/> + </Offset> + </Anchor> + <Anchor point="BOTTOMRIGHT"> + <Offset> + <AbsDimension x="-7"/> + </Offset> + </Anchor> + </Anchors> + </HighlightTexture> + <Frames> + <Frame name="$parentHighlightFrame" parentKey="highlightFrame" inherits="ww_highlightedFrame"> + <Anchors> + <Anchor point="TOPLEFT"> + <Offset> + <AbsDimension x="-5" y="-1"/> + </Offset> + </Anchor> + <Anchor point="BOTTOMRIGHT"> + <Offset> + <AbsDimension x="-5" y="-1"/> + </Offset> + </Anchor> + </Anchors> + </Frame> + </Frames> + <Scripts> + <OnClick> + configDiscardChanges(function() + configSelectWeight(self:GetParent()) + end) + </OnClick> + <OnLoad> + self:SetFontString(self:CreateFontString(nil, "OVERLAY", "ww_defaultString")) + </OnLoad> + </Scripts> + </Button> + </Frames> + </Frame> + <!-- The frame containing all weight-related content --> + <Frame name="ww_weights" parent="UIParent" hidden="true" frameStrata="HIGH"> + <Size> + <AbsDimension x="600" y="600"/> + </Size> + <Anchors> + <Anchor point="CENTER"/> + </Anchors> + <Layers> + <Layer level="BACKGROUND"> + <Texture setAllPoints="true"> + <!--Plain black background with 50% alpha--> + <Color r="0" g="0" b="0" a="0.8"/> + </Texture> + </Layer> + </Layers> + <!--list of objects within the configuartion window--> + <Frames> + <!--The Class Selection Frame--> + <Frame name="$parentLeftPanel" parentKey="leftPanel"> + <Size> + <AbsDimension x="150"/> + </Size> + <Anchors> + <Anchor point="TOP"> + <Offset> + <AbsDimension y="-25"/> + </Offset> + </Anchor> + <Anchor point="LEFT"/> + <Anchor point="BOTTOM"> + <Offset> + <AbsDimension y="25"/> + </Offset> + </Anchor> + </Anchors> + <Backdrop edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true"> + <EdgeSize> + <AbsValue val="10"/> + </EdgeSize> + <TileSize> + <AbsValue val="10"/> + </TileSize> + <BackgroundInsets> + <AbsInset left="0" right="0" top="5" bottom="5"/> + </BackgroundInsets> + </Backdrop> + <Frames> + <!--used to hold a series of stat frames to maintain absolute position when scrolling--> + <Frame name="$parentScrollContainer" parentKey="scrollContainer"> + <Anchors> + <Anchor point="LEFT"/> + <Anchor point="RIGHT"/> + </Anchors> + </Frame> + <!--Invisible frame with scroll bar that does the scrolling--> + <ScrollFrame name="$parentScrollFrame" parentKey="scrollFrame" inherits="FauxScrollFrameTemplate"> + <Anchors> + <Anchor point="TOPLEFT"/> + <Anchor point="BOTTOMRIGHT"> + <Offset> + <AbsDimension x="-5"/> + </Offset> + </Anchor> + </Anchors> + <Scripts> + <OnShow> + scrollBarUpdate(self, ww_weights.leftPanel.scrollContainer, 22, 0, 25) + </OnShow> + <OnVerticalScroll> + FauxScrollFrame_OnVerticalScroll(self, offset, 22, self:GetScript("OnShow")) + </OnVerticalScroll> + </Scripts> + </ScrollFrame> + </Frames> + </Frame> + <!--Right Frame for viewing the weights for each class--> + <Frame name="$parentRightPanel" parentKey="rightPanel" hidden="true"> + <Anchors> + <Anchor point="TOPLEFT" relativeTo="$parentLeftPanel" relativePoint="TOPRIGHT"> + <Offset> + <AbsDimension x="20"/> + </Offset> + </Anchor> + <Anchor point="BOTTOM" relativeTo="$parentLeftPanel"/> + <Anchor point="RIGHT"> + <Offset> + <AbsDimension x="-20"/> + </Offset> + </Anchor> + </Anchors> + <Layers> + <Layer level="OVERLAY"> + <FontString name="$parentHeader" parentKey="header" inherits="GameFontNormal"> + <Anchors> + <Anchor point="TOP"> + <Offset> + <AbsDimension y="-5"/> + </Offset> + </Anchor> + </Anchors> + </FontString> + </Layer> + </Layers> + <Backdrop edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true"> + <EdgeSize> + <AbsValue val="10"/> + </EdgeSize> + <TileSize> + <AbsValue val="10"/> + </TileSize> + <BackgroundInsets> + <AbsInset left="0" right="0" top="5" bottom="5"/> + </BackgroundInsets> + </Backdrop> + <Frames> + <!--Save button--> + <Button name="$parentSaveButton" parentKey="saveButton" inherits="UIPanelButtonTemplate" text="Save"> + <Size> + <AbsDimension x="80" y="22"/> + </Size> + <Anchors> + <Anchor point="BOTTOMLEFT"> + <Offset> + <AbsDimension x="5" y="5"/> + </Offset> + </Anchor> + </Anchors> + <Scripts> + <OnClick> + configSaveWeight() + </OnClick> + </Scripts> + </Button> + <!--Copy button--> + <Button name="$parentCopyButton" parentKey="copyButton" inherits="UIPanelButtonTemplate" text="Copy"> + <Size> + <AbsDimension x="80" y="22"/> + </Size> + <Anchors> + <Anchor point="LEFT" relativePoint="RIGHT" relativeTo="$parentSaveButton"> + <Offset> + <AbsDimension x="27"/> + </Offset> + </Anchor> + </Anchors> + <Scripts> + <OnClick> + configNewWeight(self:GetParent().weightFrame.category.class, "Copy of " .. self:GetParent().weightFrame.name, self:GetParent().statList) + </OnClick> + </Scripts> + </Button> + <!--Reset button--> + <Button name="$parentResetButton" parentKey="resetButton" inherits="UIPanelButtonTemplate" text="Reset"> + <Size> + <AbsDimension x="80" y="22"/> + </Size> + <Anchors> + <Anchor point="BOTTOMRIGHT"> + <Offset> + <AbsDimension x="-5" y="5"/> + </Offset> + </Anchor> + </Anchors> + <Scripts> + <OnClick> + configResetWeight() + </OnClick> + </Scripts> + </Button> + <!--Delete button--> + <Button name="$parentDeleteButton" parentKey="deleteButton" inherits="UIPanelButtonTemplate" text="Delete"> + <Size> + <AbsDimension x="80" y="22"/> + </Size> + <Anchors> + <Anchor point="RIGHT" relativePoint="LEFT" relativeTo="$parentResetButton"> + <Offset> + <AbsDimension x="-27"/> + </Offset> + </Anchor> + </Anchors> + <Scripts> + <OnClick> + configDeleteWeight() + </OnClick> + </Scripts> + </Button> + <!--used to hold a series of stat frames to maintain absolute position when scrolling--> + <Frame name="$parentScrollContainer" parentKey="scrollContainer"> + <Anchors> + <Anchor point="LEFT"/> + <Anchor point="RIGHT"/> + </Anchors> + </Frame> + <!--Invisible frame with scroll bar that does the scrolling--> + <ScrollFrame name="$parentScrollFrame" parentKey="scrollFrame" inherits="FauxScrollFrameTemplate"> + <Anchors> + <Anchor point="TOPLEFT"/> + <Anchor point="BOTTOMRIGHT"> + <Offset> + <AbsDimension x="-5"/> + </Offset> + </Anchor> + </Anchors> + <Scripts> + <OnShow> + scrollBarUpdate(self, ww_weights.rightPanel.scrollContainer, 22, -30, 22) + </OnShow> + <OnVerticalScroll> + FauxScrollFrame_OnVerticalScroll(self, offset, 22, self:GetScript("OnShow")) + </OnVerticalScroll> + </Scripts> + </ScrollFrame> + </Frames> + <Scripts> + <OnShow> + if not ww_weights.popup then + changeFocus(self.scrollFrame.stats[#(self.scrollFrame.stats)]) + end + </OnShow> + </Scripts> + </Frame> + <!--Close Button for the configuration window--> + <Button name="$parentCloseButton" parentKey="closeButton" inherits="UIPanelCloseButton"> + <Anchors> + <Anchor point="TOPRIGHT"/> + </Anchors> + </Button> + <!--restore default button--> + <Button name="$parentDefaultsButton" parentKey="defaultsButton" inherits="UIPanelButtonTemplate" text="Restore Defaults"> + <Size> + <AbsDimension x="150" y="22"/> + </Size> + <Anchors> + <Anchor point="BOTTOMLEFT"/> + </Anchors> + <Scripts> + <OnClick> + if ww_weights.rightPanel.weightFrame and defaultVars.weightsList[ww_weights.rightPanel.weightFrame.category.class][ww_weights.rightPanel.weightFrame.name] then + StaticPopup_Show("WW_CONFIRM_RESTORE_DEFAULTS") + else + configDiscardChanges(function() + StaticPopup_Show("WW_CONFIRM_RESTORE_DEFAULTS") + end) + end + </OnClick> + </Scripts> + </Button> + <!--Create new weight button--> + <Button name="$parentNewWeightButton" parentKey="newWeightButton" inherits="UIPanelButtonTemplate" text="New Weight"> + <Size> + <AbsDimension x="100" y="22"/> + </Size> + <Anchors> + <Anchor point="BOTTOMRIGHT"/> + </Anchors> + <Scripts> + <OnClick> + configNewWeight() + </OnClick> + </Scripts> + </Button> + </Frames> + <Scripts> + <OnLoad> + table.insert(UISpecialFrames, self:GetName()); + </OnLoad> + <OnHide> + if self.reallyClose then + self.reallyClose = nil + else + self.popup = true + self:Show() + configDiscardChanges(function() + self.reallyClose = true + <!-- Safe because configDiscardChanges will save the weight first --> + if self.rightPanel:IsShown() then + configResetWeight() + end + self:Hide() + end) + self.popup = nil + end + </OnHide> + </Scripts> + </Frame> + <Frame name="ww_newWeight" parent="UIParent" hidden="true" frameStrata="DIALOG"> + <Size> + <AbsDimension x="420" y="120"/> + </Size> + <Anchors> + <Anchor point="CENTER"/> + </Anchors> + <Layers> + <Layer level="ARTWORK"> + <FontString name="$parentText" parentKey="text" inherits="GameFontHighlight" text="Please choose a class and name for your new weight:"> + <Size> + <AbsDimension x="380" y="0"/> + </Size> + <Anchors> + <Anchor point="TOP"> + <Offset> + <AbsDimension x="0" y="-16"/> + </Offset> + </Anchor> + </Anchors> + </FontString> + </Layer> + <Layer level="BACKGROUND"> + <Texture setAllPoints="true"> + <!--Plain black background with 50% alpha--> + <Color r="0" g="0" b="0" a="0.5"/> + </Texture> + </Layer> + </Layers> + <Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true"> + <BackgroundInsets> + <AbsInset left="11" right="12" top="12" bottom="11"/> + </BackgroundInsets> + <TileSize> + <AbsValue val="32"/> + </TileSize> + <EdgeSize> + <AbsValue val="32"/> + </EdgeSize> + </Backdrop> + <Frames> + <Button name="$parentDropDown" parentKey="dropdown" inherits="UIDropDownMenuTemplate"> + <Anchors> + <Anchor point="LEFT"/> + </Anchors> + <Scripts> + <OnShow> + ClassDropDownOnShow(self); + </OnShow> + </Scripts> + </Button> + <EditBox letters="50" name="$parentEditBox" parentKey="editBox"> + <Size> + <AbsDimension y="32"/> + </Size> + <Anchors> + <Anchor point="BOTTOM" > + <Offset> + <AbsDimension x="0" y="45"/> + </Offset> + </Anchor> + <Anchor point="RIGHT"> + <Offset> + <AbsDimension x="-25"/> + </Offset> + </Anchor> + <Anchor point="LEFT" relativeTo="$parentDropDown" relativePoint="RIGHT"> + <Offset> + <AbsDimension x="125"/> + </Offset> + </Anchor> + </Anchors> + <FontString inherits="ChatFontNormal"/> + <Layers> + <Layer level="BACKGROUND"> + <Texture file="Interface\ChatFrame\UI-ChatInputBorder-Left"> + <Size> + <AbsDimension x="128" y="32"/> + </Size> + <Anchors> + <Anchor point="LEFT"> + <Offset> + <AbsDimension x="-10" y="0"/> + </Offset> + </Anchor> + </Anchors> + <TexCoords left="0" right="0.5" top="0" bottom="1.0"/> + </Texture> + <Texture file="Interface\ChatFrame\UI-ChatInputBorder-Right"> + <Size> + <AbsDimension x="128" y="32"/> + </Size> + <Anchors> + <Anchor point="RIGHT"> + <Offset> + <AbsDimension x="10" y="0"/> + </Offset> + </Anchor> + </Anchors> + <TexCoords left="0.5" right="1.0" top="0" bottom="1.0"/> + </Texture> + </Layer> + </Layers> + <Scripts> + <OnLoad> + self:SetTextInsets(5, 5, 0, 0) + </OnLoad> + <OnTextChanged> + if self:GetText() == "" then + self:GetParent().createButton:Disable() + else + self:GetParent().createButton:Enable() + end + </OnTextChanged> + <OnEnterPressed> + if StaticPopup_Visible("WW_WEIGHT_EXISTS") then + StaticPopup_Hide("WW_WEIGHT_EXISTS") + else + self:GetParent().createButton:Click() + end + </OnEnterPressed> + <OnEscapePressed> + if StaticPopup_Visible("WW_WEIGHT_EXISTS") then + StaticPopup_Hide("WW_WEIGHT_EXISTS") + else + self:GetParent().cancelButton:Click() + end + </OnEscapePressed> + </Scripts> + </EditBox> + <Button name="$parentCreateButton" parentKey="createButton" inherits="UIPanelButtonTemplate" text="Create"> + <Size> + <AbsDimension x="128" y="20"/> + </Size> + <Anchors> + <Anchor point="BOTTOMRIGHT" relativePoint="BOTTOM"> + <Offset> + <AbsDimension x="-6" y="16"/> + </Offset> + </Anchor> + </Anchors> + <Scripts> + <OnClick> + local class = UIDropDownMenu_GetSelectedValue(self:GetParent().dropdown) + local name = self:GetParent().editBox:GetText() + if ww_vars.weightsList[class][name] then + local error = StaticPopup_Show("WW_WEIGHT_EXISTS", classNames[class], name) + else + setWeight(class, name, self:GetParent().statList) + selectWeight(class, name) + self:GetParent():Hide() + end + </OnClick> + </Scripts> + </Button> + <Button name="$parentCancelButton" parentKey="cancelButton" inherits="UIPanelButtonTemplate" text="Cancel"> + <Size> + <AbsDimension x="128" y="20"/> + </Size> + <Anchors> + <Anchor point="BOTTOMLEFT" relativePoint="BOTTOM"> + <Offset> + <AbsDimension x="6" y="16"/> + </Offset> + </Anchor> + </Anchors> + <Scripts> + <OnClick> + self:GetParent():Hide() + </OnClick> + </Scripts> + </Button> + </Frames> + <Scripts> + <OnShow> + self.editBox:SetFocus() + </OnShow> + </Scripts> + </Frame> +</Ui>