Quantcast

Shows classes/weights as a tiered list on the left panel

Kevin Lyles [10-12-09 - 19:06]
Shows classes/weights as a tiered list on the left panel
Shows categories/stats as tiered list on the right panel
Filename
WeightsWatcher.xml
config.lua
diff --git a/WeightsWatcher.xml b/WeightsWatcher.xml
index 7a7f888..663b8a5 100644
--- a/WeightsWatcher.xml
+++ b/WeightsWatcher.xml
@@ -7,17 +7,6 @@
 			<Anchor point="LEFT"/>
 		</Anchors>
 	</FontString>
-	<!--virtual button used to allow for script generated buttons-->
-	<Button name="ww_genericButton" virtual="true">
-		<Size>
-			<AbsDimension x="75" y="20"/>
-		</Size>
-		<Scripts>
-			<OnLoad>
-				self:SetFontString(self:CreateFontString(nil, "OVERLAY", "ww_defaultString"))
-			</OnLoad>
-		</Scripts>
-	</Button>
 	<!--virtual frame used to allow for script generated frames with stat information-->
 	<Frame name="ww_categoryFrame" virtual="true">
 		<Size>
@@ -50,7 +39,7 @@
 		</Frames>
 	</Frame>
 	<!--virtual frame used to allow for script generated frames with stat information-->
-	<Frame name="ww_elementFrame" virtual="true">
+	<Frame name="ww_statFrame" virtual="true">
 		<Size>
 			<AbsDimension y="20"/>
 		</Size>
@@ -60,6 +49,9 @@
 		<Layers>
 			<Layer level="OVERLAY">
 				<FontString name="$parentText" parentKey="text" inherits="GameFontNormal">
+					<Size>
+						<AbsDimension y="20"/>
+					</Size>
 					<Anchors>
 						<Anchor point="LEFT">
 							<Offset>
@@ -71,61 +63,39 @@
 			</Layer>
 		</Layers>
 	</Frame>
-	<!--weight edit frame-->
-	<Frame name="ww_editWeight" hidden="true" parent="UIParent" frameStrata="DIALOG">
+	<!--virtual frame used to allow for script generated frames with stat information-->
+	<Frame name="ww_elementFrame" virtual="true">
 		<Size>
-			<AbsDimension x="400" y="600"/>
+			<AbsDimension y="20"/>
 		</Size>
 		<Anchors>
-			<Anchor point="CENTER"/>
+			<Anchor point="RIGHT"/>
 		</Anchors>
-		<Layers>
-			<Layer level="BACKGROUND">
-				<Texture setAllPoints="true">
-					<!--Plain black background-->
-					<Color r="0" g="0" b="0" a="1"/>
-				</Texture>
-			</Layer>
-		</Layers>
 		<Frames>
-			<Button name="$parentCloseButton" parentKey="closeButton" inherits="UIPanelCloseButton">
-				<Anchors>
-					<Anchor point="TOPRIGHT"/>
-				</Anchors>
-			</Button>
-			<!--used to hold a series of stat frames to maintain absolute position when scrolling-->
-			<Frame name="$parentScrollContainer" parentKey="scrollContainer">
-				<Size>
-					<AbsDimension x="400" y="600"/>
-				</Size>
-			</Frame>
-			<!--Invisible frame with scroll bar that does the scrolling-->
-			<ScrollFrame name="$parentScrollFrame" parentKey="scrollFrame" inherits="FauxScrollFrameTemplate">
+			<Button name="$parentText" parentKey="text">
 				<Size>
-					<AbsDimension x="400" y="600"/>
+					<AbsDimension y="20"/>
 				</Size>
 				<Anchors>
-					<Anchor point="TOPLEFT" relativeTo="ww_editWeight">
+					<Anchor point="LEFT">
 						<Offset>
-							<AbsDimension x="-5"/>
+							<AbsDimension x="20"/>
 						</Offset>
 					</Anchor>
+					<Anchor point="RIGHT"/>
 				</Anchors>
 				<Scripts>
-					<OnShow>
-						scrollBarUpdate(self, ww_editWeight.scrollContainer, ww_statFrameTable, 20, -30, 28)
-					</OnShow>
-					<OnVerticalScroll>
-						FauxScrollFrame_OnVerticalScroll(self, offset, 20, self:GetScript("OnShow"))
-					</OnVerticalScroll>
+					<OnLoad>
+						self:SetFontString(self:CreateFontString(nil, "OVERLAY", "ww_defaultString"))
+					</OnLoad>
 				</Scripts>
-			</ScrollFrame>
+			</Button>
 		</Frames>
 	</Frame>
 	<!--The Parent Frame Containing all configuration content-->
 	<Frame name="ww_config" parent="UIParent" hidden="true" frameStrata="HIGH">
 		<Size>
-			<AbsDimension x="400" y="400"/>
+			<AbsDimension x="600" y="600"/>
 		</Size>
 		<Anchors>
 			<Anchor point="CENTER"/>
@@ -143,7 +113,7 @@
 			<!--The Class Selection Frame-->
 			<Frame name="$parentLeftPanel" parentKey="leftPanel">
 				<Size>
-					<AbsDimension x="100"/>
+					<AbsDimension x="150"/>
 				</Size>
 				<Anchors>
 					<Anchor point="TOP">
@@ -169,6 +139,34 @@
 						<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_config.leftPanel.scrollContainer, ww_weightFrameTable, 20, 0, 27)
+							</OnShow>
+							<OnVerticalScroll>
+								FauxScrollFrame_OnVerticalScroll(self, offset, 20, self:GetScript("OnShow"))
+							</OnVerticalScroll>
+						</Scripts>
+					</ScrollFrame>
+				</Frames>
 			</Frame>
 			<!--Right Frame for viewing the weights for each class-->
 			<Frame name="$parentRightPanel" parentKey="rightPanel" hidden="true">
@@ -209,6 +207,34 @@
 						<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_config.rightPanel.scrollContainer, ww_statFrameTable, 20, -30, 26)
+							</OnShow>
+							<OnVerticalScroll>
+								FauxScrollFrame_OnVerticalScroll(self, offset, 20, self:GetScript("OnShow"))
+							</OnVerticalScroll>
+						</Scripts>
+					</ScrollFrame>
+				</Frames>
 			</Frame>
 			<!--Close Button for the configuration window-->
 			<Button name="$parentCloseButton" parentKey="closeButton" inherits="UIPanelCloseButton">
diff --git a/config.lua b/config.lua
index 3bc518c..110c1ec 100644
--- a/config.lua
+++ b/config.lua
@@ -5,6 +5,8 @@ end
 ww_weightButtonTable = {}
 ww_categoryFrameTable = {}
 ww_statFrameTable = {}
+ww_classFrameTable = {}
+ww_weightFrameTable = {}

 function commandHandler(msg)
 	open_config()
@@ -13,7 +15,7 @@ end
 --initializes config variables and frames
 function initializeConfig()
 	loadClassButtons()
-	createScrollableTieredList(trackedStats, ww_editWeight.scrollFrame, ww_editWeight.scrollContainer, ww_categoryFrameTable, ww_statFrameTable, "ww_elementFrame", 20)
+	createScrollableTieredList(trackedStats, ww_config.rightPanel.scrollFrame, ww_config.rightPanel.scrollContainer, ww_categoryFrameTable, ww_statFrameTable, "ww_statFrame", 20)
 end

 --display or hide the frame
@@ -48,53 +50,42 @@ function scrollBarUpdate(scrollFrame, scrolledFrame, buttonTable, buttonHeight,
 	end
 end

---opens the right panel and loads the appropriate buttons
-function configClassSelect(classType)
-	local counter = 1
-	--retrieve the list of weights and update any visible buttons to reflect the changes
-	--NOTE: this approach is used to minimize memory leakage
-	for weightName, _ in pairs(ww_vars.weightsList[classType]) do
-		--if our previously created button table isn't big enough, add new buttons
-		if #(ww_weightButtonTable) < counter then
-			table.insert(ww_weightButtonTable, CreateFrame("Button", nil, ww_config.rightPanel, "ww_genericButton"))
-			ww_weightButtonTable[counter]:SetPoint("TOPLEFT", 5, -5 - 20 * counter)
-		end
-		ww_weightButtonTable[counter]:SetText(weightName)
-		ww_weightButtonTable[counter]:SetScript("OnClick",
-			function()
-				configWeightSelect(weightName)
-			end)
-		ww_weightButtonTable[counter]:Show()
-		counter = counter + 1
-	end
-	--if we have any remaining buttons, hide them
-	while counter <= #(ww_weightButtonTable) do
-		ww_weightButtonTable[counter]:Hide()
-		counter = counter + 1
-	end
-	ww_config.rightPanel.header:SetText(classNames[classType] .. " weights")
+function configSelectWeight(weight)
+	ww_config.rightPanel.header:SetText(weight:GetName())
 	ww_config.rightPanel:Show()
 end

---opens a new config pane to edit stat weights
-function configWeightSelect(selectedWeight)
-	ww_editWeight:Show()
-end
-
 --loads the various class buttons onto the config frame
 function loadClassButtons()
-	--starting offset values for the button
-	local i = 1
-	--creates a button for each class available in weightsList
-	for class, _ in pairs(ww_vars.weightsList) do
-		local newButton = CreateFrame("Button", class, ww_config.leftPanel, "ww_genericButton")
-		newButton:SetPoint("TOPLEFT", 5, 15 - i * 20)
-		newButton:SetText(classNames[class])
-		newButton:SetScript("OnClick",
-			function()
-				configClassSelect(class)
-			end)
-		i = i + 1
+	local classes = {}
+
+	for class, weights in pairs(ww_vars.weightsList) do
+		class = classNames[class]
+		classes[class] = {}
+		for name, _ in pairs(weights) do
+			table.insert(classes[class], name)
+		end
+	end
+
+	createScrollableTieredList(classes, ww_config.leftPanel.scrollFrame, ww_config.leftPanel.scrollContainer, ww_classFrameTable, ww_weightFrameTable, "ww_elementFrame", 20)
+
+	local _, class = UnitClass("player")
+	class = classNames[class]
+	for _, classFrame in ipairs(ww_classFrameTable) do
+		if classFrame.text:GetText() ~= class then
+			toggleCollapse(classFrame, ww_classFrameTable, ww_weightFrameTable, 20,
+				function()
+					ww_config.leftPanel.scrollFrame:GetScript("OnShow")(ww_config.leftPanel.scrollFrame)
+				end)
+		end
+		for i, weightFrame in ipairs({classFrame:GetChildren()}) do
+			if i > 1 then
+				weightFrame.text:SetScript("OnClick",
+					function()
+						configSelectWeight(weightFrame)
+					end)
+			end
+		end
 	end
 end