Quantcast

Added paging controls to the skill list, since it was the main performance bottleneck when the skill window first opens. This should eliminate the last of the performance issues.

Paul Schifferer [12-16-10 - 06:37]
Added paging controls to the skill list, since it was the main performance bottleneck when the skill window first opens.  This should eliminate the last of the performance issues.
Filename
CauldronMain.lua
CauldronMain.xml
CauldronMainUI.lua
CauldronTradeskill.lua
Locale/Cauldron-enUS.lua
diff --git a/CauldronMain.lua b/CauldronMain.lua
index cf0097e..54d6334 100644
--- a/CauldronMain.lua
+++ b/CauldronMain.lua
@@ -962,6 +962,51 @@ function Cauldron:IncreaseItemCount(name)
 	CauldronQueue:AdjustItemCount(Cauldron:GetQueue(), name, 1);
 end

+function Cauldron:PrevPage()
+
+	local skillName = CURRENT_TRADESKILL;
+	if skillName == "UNKNOWN" then
+		return;
+	end
+	if IsTradeSkillLinked() then
+		skillName = "Linked-"..skillName;
+	end
+	if IsTradeSkillGuild() then
+		skillName = "Guild-"..skillName;
+	end
+
+	local offset = self.db.realm.userdata[self.vars.playername].skills[skillName].window.offset;
+	if not offset then
+		self.db.realm.userdata[self.vars.playername].skills[skillName].window.offset = 0;
+	else
+		self.db.realm.userdata[self.vars.playername].skills[skillName].window.offset = math.max(0, offset - CAULDRON_SKILL_LIST_MAX);
+	end
+end
+
+function Cauldron:NextPage()
+
+	local skillName = CURRENT_TRADESKILL;
+	if skillName == "UNKNOWN" then
+		return;
+	end
+	if IsTradeSkillLinked() then
+		skillName = "Linked-"..skillName;
+	end
+	if IsTradeSkillGuild() then
+		skillName = "Guild-"..skillName;
+	end
+
+	local offset = self.db.realm.userdata[self.vars.playername].skills[skillName].window.offset;
+	local numSkills = self.db.realm.userdata[self.vars.playername].skills[skillName].skillCount or 0;
+	if not offset then
+		self.db.realm.userdata[self.vars.playername].skills[skillName].window.offset = CAULDRON_SKILL_LIST_MAX;
+	else
+		if (offset + CAULDRON_SKILL_LIST_MAX) <= numSkills then
+			self.db.realm.userdata[self.vars.playername].skills[skillName].window.offset = offset + CAULDRON_SKILL_LIST_MAX;
+		end
+	end
+end
+
 function Cauldron:GetQueue(player)

 	if not player then
@@ -1175,6 +1220,7 @@ function filterSkillups(skillList)
 end

 function Cauldron:SetTradeSkillItem(tooltip, itemIndex, reagentIndex)
+--[[
 	local link;
 	local name;
 	if reagentIndex then
@@ -1194,7 +1240,7 @@ function Cauldron:SetTradeSkillItem(tooltip, itemIndex, reagentIndex)
 --		link = GetTradeSkillItemLink(itemIndex);
 --		name = Cauldron:GetIdFromLink(link);
 	end
-
+--]]
 	tooltip:Show();
 end

diff --git a/CauldronMain.xml b/CauldronMain.xml
index beef364..f0a1aef 100755
--- a/CauldronMain.xml
+++ b/CauldronMain.xml
@@ -412,7 +412,7 @@
 			<Layer level="BACKGROUND">
 			</Layer>
 			<Layer level="OVERLAY">
-				<Texture name="CauldronHorizontalBarLeft" urgency="5" file="Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar">
+				<Texture name="CauldronHorizontalTopBarLeft" urgency="5" file="Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar">
 					<Size x="100" y="16"/> <!-- x="256" -->
 					<Anchors>
 						<Anchor point="TOPLEFT">
@@ -427,7 +427,28 @@
 				<Texture urgency="5" file="Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar">
 					<Size x="256" y="16"/>
 					<Anchors>
-						<Anchor point="LEFT" relativeTo="CauldronHorizontalBarLeft" relativePoint="RIGHT">
+						<Anchor point="LEFT" relativeTo="CauldronHorizontalTopBarLeft" relativePoint="RIGHT">
+							<Offset x="0" y="0"/>
+						</Anchor>
+					</Anchors>
+					<TexCoords left="0" right="1.0" top="0.25" bottom="0.5"/>
+				</Texture>
+				<Texture name="CauldronHorizontalBottomBarLeft" urgency="5" file="Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar">
+					<Size x="100" y="16"/> <!-- x="256" -->
+					<Anchors>
+						<Anchor point="TOPLEFT">
+							<Offset x="2" y="-462"/>
+						</Anchor>
+						<Anchor point="RIGHT">
+							<Offset x="-80" y="0"/>
+						</Anchor>
+					</Anchors>
+					<TexCoords left="0" right="1.0" top="0" bottom="0.25"/>
+				</Texture>
+				<Texture urgency="5" file="Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar">
+					<Size x="256" y="16"/>
+					<Anchors>
+						<Anchor point="LEFT" relativeTo="CauldronHorizontalBottomBarLeft" relativePoint="RIGHT">
 							<Offset x="0" y="0"/>
 						</Anchor>
 					</Anchors>
@@ -780,7 +801,7 @@

 			<!-- Skill list -->
 			<ScrollFrame name="CauldronSkillListScrollFrame" inherits="UIPanelScrollFrameTemplate">
-				<Size x="505" y="385" />
+				<Size x="505" y="355" />
 				<Anchors>
 					<Anchor point="TOPLEFT" relativeTo="CauldronFrame" relativePoint="TOPLEFT">
 						<Offset x="10" y="-110"/>
@@ -811,7 +832,7 @@
 				</Layers>
 				<ScrollChild>
 					<Frame name="CauldronSkillListScrollFrameScrollChild">
-						<Size x="505" y="385" />
+						<Size x="505" y="355" />
 						<Anchors>
 							<Anchor point="TOPLEFT">
 								<Offset x="0" y="0"/>
@@ -823,6 +844,88 @@
 				</ScrollChild>
 			</ScrollFrame>

+			<!-- Paging info and controls -->
+			<Frame name="CauldronPagingFrame">
+				<Size x="535" y="18" />
+				<Anchors>
+					<Anchor point="BOTTOMLEFT" relativeTo="CauldronFrame">
+						<Offset x="10" y="31" />
+					</Anchor>
+				</Anchors>
+				<Layers>
+					<Layer level="OVERLAY">
+						<FontString name="CauldronPageInfoText" inherits="GameFontNormal" justifyH="LEFT" text="(page info)">
+							<Size x="250" y="18" />
+							<Color r="0.7" g="0.7" b="0.7" />
+						</FontString>
+					</Layer>
+				</Layers>
+				<Frames>
+					<Button name="CauldronBrowsePrevPageButton">
+						<Size x="32" y="32"/>
+						<Anchors>
+							<Anchor point="RIGHT">
+								<Offset x="-100" y="0"/>
+							</Anchor>
+						</Anchors>
+						<Layers>
+							<Layer level="BACKGROUND">
+								<FontString inherits="GameFontHighlightSmall" justifyH="LEFT" text="PREV">
+									<Size x="60" y="10"/>
+									<Anchors>
+										<Anchor point="LEFT" relativePoint="RIGHT"/>
+									</Anchors>
+								</FontString>
+							</Layer>
+						</Layers>
+						<Scripts>
+							<OnClick>
+								PlaySound("igMainMenuOptionCheckBoxOn");
+								Cauldron:PrevPage();
+								Cauldron:UpdateSkillList();
+								Cauldron:UpdatePageInfo();
+							</OnClick>
+						</Scripts>
+						<NormalTexture urgency="5" file="Interface\Buttons\UI-SpellbookIcon-PrevPage-Up"/>
+						<PushedTexture urgency="5" file="Interface\Buttons\UI-SpellbookIcon-PrevPage-Down"/>
+						<DisabledTexture urgency="5" file="Interface\Buttons\UI-SpellbookIcon-PrevPage-Disabled"/>
+						<HighlightTexture file="Interface\Buttons\UI-Common-MouseHilight" alphaMode="ADD"/>
+					</Button>
+					<Button name="CauldronBrowseNextPageButton">
+						<Size x="32" y="32"/>
+						<Anchors>
+							<Anchor point="RIGHT">
+								<Offset x="-5" y="0"/>
+							</Anchor>
+						</Anchors>
+						<Layers>
+							<Layer level="BACKGROUND">
+								<FontString inherits="GameFontHighlightSmall" justifyH="RIGHT" text="NEXT">
+									<Size x="60" y="10"/>
+									<Anchors>
+										<Anchor point="RIGHT" relativePoint="LEFT"/>
+									</Anchors>
+								</FontString>
+							</Layer>
+						</Layers>
+						<Scripts>
+							<OnClick>
+								PlaySound("igMainMenuOptionCheckBoxOn");
+								Cauldron:NextPage();
+								Cauldron:UpdateSkillList();
+								Cauldron:UpdatePageInfo();
+							</OnClick>
+						</Scripts>
+						<NormalTexture urgency="5" file="Interface\Buttons\UI-SpellbookIcon-NextPage-Up"/>
+						<PushedTexture urgency="5" file="Interface\Buttons\UI-SpellbookIcon-NextPage-Down"/>
+						<DisabledTexture urgency="5" file="Interface\Buttons\UI-SpellbookIcon-NextPage-Disabled"/>
+						<HighlightTexture file="Interface\Buttons\UI-Common-MouseHilight" alphaMode="ADD"/>
+					</Button>
+				</Frames>
+				<Scripts>
+				</Scripts>
+			</Frame>
+
 			<!-- Queue All button -->
 			<Button name="CauldronQueueAllButton" inherits="CauldronButtonTemplate" text="Queue All">
 				<Anchors>
diff --git a/CauldronMainUI.lua b/CauldronMainUI.lua
index a942c8e..0e74d1a 100644
--- a/CauldronMainUI.lua
+++ b/CauldronMainUI.lua
@@ -3,6 +3,7 @@

 CAULDRON_SKILLITEM_COLLAPSED_HEIGHT = 37;
 CAULDRON_SKILLITEM_EXPANDED_HEIGHT = 100;
+CAULDRON_SKILL_LIST_MAX = 50;

 CAULDRON_TRADESKILL_NAME = CURRENT_TRADESKILL;

@@ -141,6 +142,9 @@ function Cauldron:Frame_Update()

 	-- update buttons
 	self:UpdateButtons();
+
+	-- update page info
+	self:UpdatePageInfo();

 end

@@ -277,6 +281,9 @@ function Cauldron:UpdateSkillList()
 	end

 	local skillName = CURRENT_TRADESKILL;
+	if skillName == "UNKNOWN" then
+		return;
+	end
 	if IsTradeSkillLinked() then
 		skillName = "Linked-"..skillName;
 	end
@@ -293,9 +300,19 @@ function Cauldron:UpdateSkillList()

 	Cauldron.updatingSkillList = true;

+local startTime = GetTime();
+	local offset = self.db.realm.userdata[self.vars.playername].skills[skillName].window.offset or 0;
+	local lastFrameIndex = 0;
+
 	-- iterate over the list of skills
-	for i, skillInfo in ipairs(skillList) do
-
+--	for i, skillInfo in ipairs(skillList) do
+	for i=1,CAULDRON_SKILL_LIST_MAX do
+
+		local skillInfo = skillList[i + offset];
+		if not skillInfo then
+			break;
+		end
+
 		local skillFrame = _G["CauldronSkillItem"..i];

 		-- check if we have a frame for this position
@@ -314,36 +331,36 @@ function Cauldron:UpdateSkillList()

 		--[[
 		if self.db.realm.userdata[self.vars.playername].options.compactView then
-		    -- set the height of frame
-		    skillFrame:SetHeight(25);
-		    _G["CauldronSkillItem"..i.."SkillCooldown"]:SetHeight(25);
+			-- set the height of frame
+			skillFrame:SetHeight(25);
+			_G["CauldronSkillItem"..i.."SkillCooldown"]:SetHeight(25);

-		    -- rescale the icon frame
-		    _G["CauldronSkillItem"..i.."SkillIcon"]:SetWidth(18);
-		    _G["CauldronSkillItem"..i.."SkillIcon"]:SetHeight(18);
+			-- rescale the icon frame
+			_G["CauldronSkillItem"..i.."SkillIcon"]:SetWidth(18);
+			_G["CauldronSkillItem"..i.."SkillIcon"]:SetHeight(18);

-		    -- reposition the name
-		    _G["CauldronSkillItem"..i.."SkillName"]:SetPoint("TOPLEFT", 43, -4);
+			-- reposition the name
+			_G["CauldronSkillItem"..i.."SkillName"]:SetPoint("TOPLEFT", 43, -4);

-		    -- hide the category info
-		    _G["CauldronSkillItem"..i.."SkillCategory"]:Hide();
+			-- hide the category info
+			_G["CauldronSkillItem"..i.."SkillCategory"]:Hide();
 		else
 		--]]
-		    -- set the height of frame
-		    skillFrame:SetHeight(CAULDRON_SKILLITEM_COLLAPSED_HEIGHT);
-		    -- TODO: set height if expanded
+			-- set the height of frame
+			skillFrame:SetHeight(CAULDRON_SKILLITEM_COLLAPSED_HEIGHT);
+			-- TODO: set height if expanded
 		--[[
-		    _G["CauldronSkillItem"..i.."SkillCooldown"]:SetHeight(50);
+			_G["CauldronSkillItem"..i.."SkillCooldown"]:SetHeight(50);

-		    -- rescale the icon frame
-		    _G["CauldronSkillItem"..i.."SkillIcon"]:SetWidth(37);
-		    _G["CauldronSkillItem"..i.."SkillIcon"]:SetHeight(37);
+			-- rescale the icon frame
+			_G["CauldronSkillItem"..i.."SkillIcon"]:SetWidth(37);
+			_G["CauldronSkillItem"..i.."SkillIcon"]:SetHeight(37);

-		    -- reposition the name
-		    _G["CauldronSkillItem"..i.."SkillName"]:SetPoint("TOPLEFT", 62, -4);
+			-- reposition the name
+			_G["CauldronSkillItem"..i.."SkillName"]:SetPoint("TOPLEFT", 62, -4);

-		    -- show the category info
-		    _G["CauldronSkillItem"..i.."SkillCategory"]:Show();
+			-- show the category info
+			_G["CauldronSkillItem"..i.."SkillCategory"]:Show();
 		end
 		--]]

@@ -594,11 +611,13 @@ function Cauldron:UpdateSkillList()

 		-- show the frame
 		skillFrame:Show();
+
+		lastFrameIndex = i;
 	end

 	-- hide any remaining frames
-	local j = #skillList + 1;
-	while true do
+--	local j = lastFrameIndex + 1;
+	for j=lastFrameIndex+1,CAULDRON_SKILL_LIST_MAX do
 		local frame = _G["CauldronSkillItem"..j];
 		if not frame then
 			break;
@@ -607,9 +626,12 @@ function Cauldron:UpdateSkillList()
 		frame:Hide();
 		frame:SetHeight(0);

-		j = j + 1;
+--		j = j + 1;
 	end

+local endTime = GetTime();
+-- Cauldron:info("draw skill list: "..tostring(endTime-startTime).."ms");
+
 	Cauldron.updatingSkillList = false;

 end
@@ -692,6 +714,31 @@ function Cauldron:UpdateButtons()

 end

+function Cauldron:UpdatePageInfo()
+
+	local skillName = CURRENT_TRADESKILL;
+	if skillName == "UNKNOWN" then
+		return;
+	end
+	if IsTradeSkillLinked() then
+		skillName = "Linked-"..skillName;
+	end
+	if IsTradeSkillGuild() then
+		skillName = "Guild-"..skillName;
+	end
+
+	local offset = self.db.realm.userdata[self.vars.playername].skills[skillName].window.offset or 0;
+	local firstIndex = 1 + offset;
+	local numSkills = self.db.realm.userdata[self.vars.playername].skills[skillName].skillCount or 0;
+	local lastIndex = math.min(50 + offset, numSkills);
+
+	local pageInfo = string.format(L["Showing %1$d - %2$d of %3$d items."], firstIndex, lastIndex, numSkills);
+	CauldronPageInfoText:SetText(pageInfo);
+
+	-- enable/disable navigation buttons
+	-- TODO
+end
+
 function Cauldron:OnCauldronUpdate()

 	--[[
@@ -735,6 +782,18 @@ function CauldronFrame_Show()
 	Cauldron:Frame_Show();
 end

+function CauldronFrameIncrement_OnClick()
+	if ( CauldronInputBox:GetNumber() < 100 ) then
+		CauldronInputBox:SetNumber(CauldronInputBox:GetNumber() + 1);
+	end
+end
+
+function CauldronFrameDecrement_OnClick()
+	if ( CauldronInputBox:GetNumber() > 0 ) then
+		CauldronInputBox:SetNumber(CauldronInputBox:GetNumber() - 1);
+	end
+end
+
 function CauldronFilterDropDown_OnLoad(self)
 	UIDropDownMenu_Initialize(self, CauldronFilterDropDown_Initialize, "MENU");
 	CauldronFilterDropDownText:SetJustifyH("CENTER");
@@ -2392,6 +2451,8 @@ function Cauldron:SkillItem_OnClick(frame, button, down)
 	-- select this frame
 	if frame.skillIndex then
     	Cauldron.db.realm.userdata[Cauldron.vars.playername].skills[skillName].window.selected = frame.skillIndex;
+    	CauldronFrame.selectedSkill = frame.skillIndex;
+    	CauldronFrame.numAvailable = 1;
     end

 	-- update the UI
diff --git a/CauldronTradeskill.lua b/CauldronTradeskill.lua
index 156612d..89981e1 100644
--- a/CauldronTradeskill.lua
+++ b/CauldronTradeskill.lua
@@ -62,7 +62,7 @@ function Cauldron:NeedsSkillUpdate()
 	return false;
 end

-function Cauldron:UpdateSkills()
+function Cauldron:UpdateSkills(firstIndex, lastIndex)
 	self:debug("UpdateSkills enter");

 --	self:info("updating skills: "..debugstack());
@@ -73,21 +73,40 @@ function Cauldron:UpdateSkills()
 		return;
 	end

-	local numTradeSkills = GetNumTradeSkills();
 	local skillName, rank, maxRank = GetTradeSkillLine();
-	local baseSkillName = skillName;
-	self:debug("UpdateSkills: skillName="..skillName);

 	if skillName == "UNKNOWN" then
 		return;
 	end
+
+	local numTradeSkills = GetNumTradeSkills();
+	Cauldron.vars.numSkills = numTradeSkills;
+	local baseSkillName = skillName;
+	self:debug("UpdateSkills: skillName="..skillName);

 --	Cauldron:info("scanningSkills="..tostring(self.scanningSkills));
 	if not Cauldron.scanningSkills then

+local startTime = GetTime();
+
 		Cauldron.scanningSkills = true;
-		Cauldron:Print("Scanning recipes...");
+		Cauldron:Print("Scanning recipes..."); -- TODO: remove
+
+		-- make sure we're getting a full list
+		SetTradeSkillItemNameFilter(nil);
+		SetTradeSkillItemLevelFilter(0, 0);
+		TradeSkillOnlyShowSkillUps(false);
+		TradeSkillOnlyShowMakeable(false);
+
+		-- make sure the list is fully expanded
+		for i=GetNumTradeSkills(),1,-1 do
+			local name = GetTradeSkillInfo(i);
+			if name == "header" then
+				ExpandTradeSkillSubClass(i);
+			end
+		end

+		-- check for linked or guild lists
 		if IsTradeSkillLinked() then
 			skillName = "Linked-"..skillName;
 		end
@@ -147,11 +166,6 @@ function Cauldron:UpdateSkills()
 			};
 		end

-		-- make sure we're getting a full list
-		SetTradeSkillItemNameFilter(nil);
-		SetTradeSkillItemLevelFilter(0, 0);
-		TradeSkillOnlyShowSkillUps(false);
-		TradeSkillOnlyShowMakeable(false);
 		--[[
 		local slots = { GetTradeSkillSubClassFilteredSlots(0) };
 		for i,slot in pairs(slots) do
@@ -165,7 +179,7 @@ function Cauldron:UpdateSkills()

 		local category = "";
 		local rescanCount = 0;
-
+
 		for i=1,GetNumTradeSkills() do
 	--		self:info("i="..tostring(i));
 			local name, difficulty, avail, expanded, verb, numSkillUps = GetTradeSkillInfo(i);
@@ -347,9 +361,12 @@ function Cauldron:UpdateSkills()
 				end
 			end
 		end
-
+
 		Cauldron.scanningSkills = false;

+local endTime = GetTime();
+-- Cauldron:info("scan time: "..tostring(endTime-startTime).."ms");
+
 		if rescanCount > 0 then
 			Cauldron:Print(rescanCount.." recipes marked for rescan.");
 		end
@@ -447,6 +464,22 @@ function Cauldron:GetSkillCount(skillName)
 	return skillCount;
 end

+function Cauldron:GetSkillNumAvailable(skillInfo)
+	if not skillInfo then
+		return 0;
+	end
+	if skillInfo.tradeskill ~= CURRENT_TRADESKILL then
+		return 0;
+	end
+
+	local _, _, avail, _, _, _ = GetTradeSkillInfo(skillInfo.index);
+
+	return avail or 0;
+end
+
+function Cauldron:LearnSkill()
+end
+
 function Cauldron:GetSkillList(playername, skillName)
 	self:debug("GetSkillList enter");

@@ -462,6 +495,8 @@ function Cauldron:GetSkillList(playername, skillName)

 	local skills = {};

+local startTime = GetTime();
+
 	for name, recipe in pairs(self.db.realm.userdata[playername].skills[skillName].recipes) do
 		self:debug("GetSkillList: name="..name);

@@ -596,6 +631,11 @@ function Cauldron:GetSkillList(playername, skillName)
 		end
 	end

+local endTime = GetTime();
+-- Cauldron:info("get skill list: "..tostring(endTime-startTime).."ms");
+
+startTime = GetTime();
+
 	-- sort the list
 	table.sort(skills, function(r1, r2)
 			if (not r1) or (not r2) then
@@ -680,6 +720,9 @@ function Cauldron:GetSkillList(playername, skillName)
 			return true;
 		end);

+local endTime = GetTime();
+-- Cauldron:info("sort skill list: "..tostring(endTime-startTime).."ms");
+
 	--@alpha@
 	self:debug("GetSkillList exit");

diff --git a/Locale/Cauldron-enUS.lua b/Locale/Cauldron-enUS.lua
index de3eb62..cab7117 100644
--- a/Locale/Cauldron-enUS.lua
+++ b/Locale/Cauldron-enUS.lua
@@ -166,6 +166,8 @@ L["Needed for favorites:"] = true
 L["Needed for %1$d skills for leveling"] = true
 L["Needed for leveling:"] = true

+L["Showing %1$d - %2$d of %3$d items."] = true
+
 L["Oh. Smells like barbecued dog hair."] = true

 -- LSW strings