Quantcast

Scrollable, collapsable, tiered list working for categories/stats in ww_editWeight

Kevin Lyles [10-11-09 - 09:24]
Scrollable, collapsable, tiered list working for categories/stats in ww_editWeight
Filename
WeightsWatcher.xml
config.lua
diff --git a/WeightsWatcher.xml b/WeightsWatcher.xml
index e0d8d34..8826f6a 100644
--- a/WeightsWatcher.xml
+++ b/WeightsWatcher.xml
@@ -23,19 +23,30 @@
 		<Size>
 			<AbsDimension x="400"/>
 		</Size>
-		<Layers>
-			<Layer level="OVERLAY">
-				<FontString inherits="GameFontNormal" parentKey="text">
-					<Anchors>
-						<Anchor point="TOPLEFT">
-							<Offset>
-								<AbsDimension x="5" y="-5"/>
-							</Offset>
-						</Anchor>
-					</Anchors>
-				</FontString>
-			</Layer>
-		</Layers>
+		<Frames>
+			<Button name="$parentText" parentKey="text">
+				<Size>
+					<AbsDimension x="395" y="20"/>
+				</Size>
+				<Anchors>
+					<Anchor point="TOPLEFT">
+						<Offset>
+							<AbsDimension x="5"/>
+						</Offset>
+					</Anchor>
+				</Anchors>
+				<Scripts>
+					<OnLoad>
+						local fontString = self:CreateFontString(nil, "OVERLAY", "GameFontNormal")
+						fontString:SetPoint("LEFT")
+						self:SetFontString(fontString)
+					</OnLoad>
+					<OnClick>
+						toggleCollapse(self:GetParent())
+					</OnClick>
+				</Scripts>
+			</Button>
+		</Frames>
 	</Frame>
 	<!--virtual frame used to allow for script generated frames with stat information-->
 	<Frame name="ww_elementFrame" virtual="true">
diff --git a/config.lua b/config.lua
index 6b3228d..5e13642 100644
--- a/config.lua
+++ b/config.lua
@@ -123,19 +123,57 @@ function createStatFontStrings()
 		end
 		table.insert(ww_categoryFrameTable, newCategoryFrame)
 		table.insert(ww_statFrameTable, newCategoryFrame.text)
+		newCategoryFrame.position = #(ww_statFrameTable)
 		for j, stat in ipairs(stats) do
 			newElementFrame = CreateFrame("Frame", nil, ww_categoryFrameTable[i], "ww_elementFrame")
 			newElementFrame.text:SetText(stat)
+			newElementFrame.name = stat
 			newElementFrame:SetPoint("TOPLEFT", 0, -20 * j)
 			table.insert(ww_statFrameTable, newElementFrame)
 			newCategoryFrame.length = newCategoryFrame.length + 1
 		end

 		newCategoryFrame:SetHeight(20 * newCategoryFrame.length)
+		newCategoryFrame.collapsed = false
 		i = i + 1
 	end
 end

+function toggleCollapse(categoryFrame)
+	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(ww_statFrameTable, categoryFrame.position + i - 1, stat)
+			end
+		end
+		for _, category in ipairs(ww_categoryFrameTable) do
+			if category.position > categoryFrame.position then
+				category.position = category.position + categoryFrame.length - 1
+			end
+		end
+		categoryFrame.collapsed = false
+		categoryFrame:SetHeight(20 * categoryFrame.length)
+	else
+		for _, stat in ipairs({categoryFrame:GetChildren()}) do
+			if stat.name then
+				stat:Hide()
+				table.remove(ww_statFrameTable, categoryFrame.position + 1)
+			end
+		end
+		for _, category in ipairs(ww_categoryFrameTable) do
+			if category.position > categoryFrame.position then
+				category.position = category.position - categoryFrame.length + 1
+			end
+		end
+		categoryFrame.collapsed = true
+		categoryFrame:SetHeight(20)
+	end
+	scrollBarUpdate()
+end
+
 trackedStats = {
 	["General"] = {
 		"Stamina",