Quantcast

changed the class buttons to be automatically generated

U-punta-PC\punta [09-25-09 - 19:35]
changed the class buttons to be automatically generated
Filename
WeightsWatcher.lua
WeightsWatcher.xml
config.lua
diff --git a/WeightsWatcher.lua b/WeightsWatcher.lua
index 1cc313f..d975a31 100644
--- a/WeightsWatcher.lua
+++ b/WeightsWatcher.lua
@@ -25,6 +25,7 @@ function WeightsWatcher:OnInitialize()
 	else
 		-- TODO: disable the addon
 	end
+	initializeConfig()
 end

 currentHooks = {}
diff --git a/WeightsWatcher.xml b/WeightsWatcher.xml
index d703309..cb19e68 100644
--- a/WeightsWatcher.xml
+++ b/WeightsWatcher.xml
@@ -1,6 +1,22 @@
 <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"/>
+	<!--virtual button used to allow for script generated buttons with class names-->
+	<Button name="classButton" virtual="true">
+		<Size>
+			<AbsDimension x="75" y="20"/>
+		</Size>
+		<Scripts>
+			<OnClick>
+				configClassSelect(self:GetName())
+			</OnClick>
+			<OnLoad>
+				local fontString = self:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
+				fontString:SetText(classNames[self:GetName()])
+				self:SetFontString(fontString)
+			</OnLoad>
+		</Scripts>
+	</Button>
 	<!--The Parent Frame Containing all configuration content-->
 	<Frame name="wwConfig" parent="UIParent" hidden="true">
 		<Size>
@@ -38,269 +54,6 @@
 						<AbsInset left="0" right="0" top="5" bottom="5"/>
 					</BackgroundInsets>
 				</Backdrop>
-				<!--List of Class Buttons Found in the Left Config Panel-->
-				<Frames>
-					<Button name="rogueButton">
-						<Size>
-							<AbsDimension x="75" y="20"/>
-						</Size>
-						<Anchors>
-							<Anchor point="TOPLEFT">
-								<Offset>
-									<AbsDimension x="5" y="-5"/>
-								</Offset>
-							</Anchor>
-						</Anchors>
-						<Layers>
-							<Layer level="OVERLAY">
-								<FontString name="rogueText" inherits="GameFontNormalSmall" text="Rogue">
-									<Anchors>
-										<Anchor point="LEFT"/>
-									</Anchors>
-								</FontString>
-							</Layer>
-						</Layers>
-						<Scripts>
-							<OnClick>
-								configClassSelect("ROGUE")
-							</OnClick>
-						</Scripts>
-					</Button>
-					<Button name="mageButton">
-						<Size>
-							<AbsDimension x="75" y="20"/>
-						</Size>
-						<Anchors>
-							<Anchor point="TOPLEFT">
-								<Offset>
-									<AbsDimension x="5" y="-25"/>
-								</Offset>
-							</Anchor>
-						</Anchors>
-						<Layers>
-							<Layer level="OVERLAY">
-								<FontString name="mageText" inherits="GameFontNormalSmall" text="Mage">
-									<Anchors>
-										<Anchor point="LEFT"/>
-									</Anchors>
-								</FontString>
-							</Layer>
-						</Layers>
-						<Scripts>
-							<OnClick>
-								configClassSelect("MAGE")
-							</OnClick>
-						</Scripts>
-					</Button>
-					<Button name="priestButton">
-						<Size>
-							<AbsDimension x="75" y="20"/>
-						</Size>
-						<Anchors>
-							<Anchor point="TOPLEFT">
-								<Offset>
-									<AbsDimension x="5" y="-45"/>
-								</Offset>
-							</Anchor>
-						</Anchors>
-						<Layers>
-							<Layer level="OVERLAY">
-								<FontString name="priestText" inherits="GameFontNormalSmall" text="Priest">
-									<Anchors>
-										<Anchor point="LEFT"/>
-									</Anchors>
-								</FontString>
-							</Layer>
-						</Layers>
-						<Scripts>
-							<OnClick>
-								configClassSelect("PRIEST")
-							</OnClick>
-						</Scripts>
-					</Button>
-					<Button name="warlockButton">
-						<Size>
-							<AbsDimension x="75" y="20"/>
-						</Size>
-						<Anchors>
-							<Anchor point="TOPLEFT">
-								<Offset>
-									<AbsDimension x="5" y="-65"/>
-								</Offset>
-							</Anchor>
-						</Anchors>
-						<Layers>
-							<Layer level="OVERLAY">
-								<FontString name="warlockText" inherits="GameFontNormalSmall" text="Warlock">
-									<Anchors>
-										<Anchor point="LEFT"/>
-									</Anchors>
-								</FontString>
-							</Layer>
-						</Layers>
-						<Scripts>
-							<OnClick>
-								configClassSelect("WARLOCK")
-							</OnClick>
-						</Scripts>
-					</Button>
-					<Button name="paladinButton">
-						<Size>
-							<AbsDimension x="75" y="20"/>
-						</Size>
-						<Anchors>
-							<Anchor point="TOPLEFT">
-								<Offset>
-									<AbsDimension x="5" y="-85"/>
-								</Offset>
-							</Anchor>
-						</Anchors>
-						<Layers>
-							<Layer level="OVERLAY">
-								<FontString name="paladinText" inherits="GameFontNormalSmall" text="Paladin">
-									<Anchors>
-										<Anchor point="LEFT"/>
-									</Anchors>
-								</FontString>
-							</Layer>
-						</Layers>
-						<Scripts>
-							<OnClick>
-								configClassSelect("PALADIN")
-							</OnClick>
-						</Scripts>
-					</Button>
-					<Button name="druidButton">
-						<Size>
-							<AbsDimension x="75" y="20"/>
-						</Size>
-						<Anchors>
-							<Anchor point="TOPLEFT">
-								<Offset>
-									<AbsDimension x="5" y="-105"/>
-								</Offset>
-							</Anchor>
-						</Anchors>
-						<Layers>
-							<Layer level="OVERLAY">
-								<FontString name="druidText" inherits="GameFontNormalSmall" text="Druid">
-									<Anchors>
-										<Anchor point="LEFT"/>
-									</Anchors>
-								</FontString>
-							</Layer>
-						</Layers>
-						<Scripts>
-							<OnClick>
-								configClassSelect("DRUID")
-							</OnClick>
-						</Scripts>
-					</Button>
-					<Button name="shamanButton">
-						<Size>
-							<AbsDimension x="75" y="20"/>
-						</Size>
-						<Anchors>
-							<Anchor point="TOPLEFT">
-								<Offset>
-									<AbsDimension x="5" y="-125"/>
-								</Offset>
-							</Anchor>
-						</Anchors>
-						<Layers>
-							<Layer level="OVERLAY">
-								<FontString name="shamanText" inherits="GameFontNormalSmall" text="Shaman">
-									<Anchors>
-										<Anchor point="LEFT"/>
-									</Anchors>
-								</FontString>
-							</Layer>
-						</Layers>
-						<Scripts>
-							<OnClick>
-								configClassSelect("SHAMAN")
-							</OnClick>
-						</Scripts>
-					</Button>
-					<Button name="warriorButton">
-						<Size>
-							<AbsDimension x="75" y="20"/>
-						</Size>
-						<Anchors>
-							<Anchor point="TOPLEFT">
-								<Offset>
-									<AbsDimension x="5" y="-145"/>
-								</Offset>
-							</Anchor>
-						</Anchors>
-						<Layers>
-							<Layer level="OVERLAY">
-								<FontString name="warriorText" inherits="GameFontNormalSmall" text="Warrior">
-									<Anchors>
-										<Anchor point="LEFT"/>
-									</Anchors>
-								</FontString>
-							</Layer>
-						</Layers>
-						<Scripts>
-							<OnClick>
-								configClassSelect("WARRIOR")
-							</OnClick>
-						</Scripts>
-					</Button>
-					<Button name="dkButton">
-						<Size>
-							<AbsDimension x="75" y="20"/>
-						</Size>
-						<Anchors>
-							<Anchor point="TOPLEFT">
-								<Offset>
-									<AbsDimension x="5" y="-165"/>
-								</Offset>
-							</Anchor>
-						</Anchors>
-						<Layers>
-							<Layer level="OVERLAY">
-								<FontString name="dkText" inherits="GameFontNormalSmall" text="Death Knight">
-									<Anchors>
-										<Anchor point="LEFT"/>
-									</Anchors>
-								</FontString>
-							</Layer>
-						</Layers>
-						<Scripts>
-							<OnClick>
-								configClassSelect("DEATHKNIGHT")
-							</OnClick>
-						</Scripts>
-					</Button>
-					<Button name="hunterButton">
-						<Size>
-							<AbsDimension x="75" y="20"/>
-						</Size>
-						<Anchors>
-							<Anchor point="TOPLEFT">
-								<Offset>
-									<AbsDimension x="5" y="-185"/>
-								</Offset>
-							</Anchor>
-						</Anchors>
-						<Layers>
-							<Layer level="OVERLAY">
-								<FontString name="hunterText" inherits="GameFontNormalSmall" text="Hunter">
-									<Anchors>
-										<Anchor point="LEFT"/>
-									</Anchors>
-								</FontString>
-							</Layer>
-						</Layers>
-						<Scripts>
-							<OnClick>
-								configClassSelect("HUNTER")
-							</OnClick>
-						</Scripts>
-					</Button>
-				</Frames>
 			</Frame>
 			<!--Right Frame for viewing the weights for each class-->
 			<Frame>
diff --git a/config.lua b/config.lua
index 659f9ab..e30a99c 100644
--- a/config.lua
+++ b/config.lua
@@ -6,6 +6,11 @@ function commandHandler(msg)
 	open_config()
 end

+--initializes config variables and frames
+function initializeConfig()
+	loadClassButtons()
+end
+
 --display or hide the frame
 function open_config()
 	if wwConfig:IsVisible() then
@@ -25,6 +30,31 @@ function addWeightScale(name)
 	print(name)
 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, wwConfig.leftPanel, "classButton")
+		newButton:SetPoint("TOPLEFT", 5, 15 - i * 20)
+		i = i + 1
+	end
+end
+
+classNames = {
+	["DEATHKNIGHT"] = "Death Knight",
+	["DRUID"] = "Druid",
+	["HUNTER"] = "Hunter",
+	["MAGE"] = "Mage",
+	["PALADIN"] = "Paladin",
+	["PRIEST"] = "Priest",
+	["ROGUE"] = "Rogue",
+	["SHAMAN"] = "Shaman",
+	["WARLOCK"] = "Warlock",
+	["WARRIOR"] = "Warrior",
+}
+
 defaultVars = {
 	dataMajorVersion = 0,
 	dataMinorVersion = 2,