Quantcast

Added "(# skills)" to the skill name in the progress bar, so people can see how many skills they have.

pschifferer [10-16-09 - 03:40]
Added "(# skills)" to the skill name in the progress bar, so people can see how many skills they have.
Really fixed the skill learner code.  Turns out that it was being called many times even during a simple thing
like opening the window.  Now the activity is flagged to truly update the list when something changes, like
skill level.  Window opening for my personal Blacksmithing skill with 300 items now takes only a few seconds,
so it should be orders of magnitude faster than it was before.
Added some checks to various functions to handle situations where certain data structures aren't initialized.
Filename
CauldronMain.lua
CauldronMainUI.lua
CauldronTradeskill.lua
Locale/Cauldron-enUS.lua
diff --git a/CauldronMain.lua b/CauldronMain.lua
index 599768c..1c1db22 100644
--- a/CauldronMain.lua
+++ b/CauldronMain.lua
@@ -266,9 +266,13 @@ function Cauldron:OnTradeShow()

 	-- update our known skills
 	self:debug("OnTradeShow: update known skills");
-	self:ScheduleTimer(self.UpdateSkills,1,self);
--- self:UpdateSkills();
-
+--	self:ScheduleTimer(self.UpdateSkills,1,self);
+	if not Cauldron.updatingSkills then
+		self.updatingSkills = true;
+		self:UpdateSkills();
+		self.updatingSkills = false;
+	end
+
 	-- show the UI frame
 	self:debug("OnTradeShow: show the UI");
 	self:Frame_Show();
@@ -318,7 +322,11 @@ function Cauldron:OnSkillUpdate()
 		-- TODO check if the skill rank has changed, and unselect
 		-- Cauldron.db.realm.userdata[Cauldron.vars.playername].skills[CURRENT_TRADESKILL].window.selected = 0;

-		Cauldron:UpdateSkills();
+		if not Cauldron.updatingSkills then
+			Cauldron.updatingSkills = true;
+			Cauldron:UpdateSkills();
+			Cauldron.updatingSkills = false;
+		end
 		CauldronQueue:CalculateAllRequiredItems(Cauldron.db.realm.userdata[Cauldron.vars.playername].queue);
 	end

@@ -511,6 +519,11 @@ function Cauldron:GetSelectedSkill()
 		skillName = "Linked-"..skillName;
 	end

+	if (not self.db.realm.userdata[self.vars.playername]) or
+	   (not self.db.realm.userdata[self.vars.playername].skills[skillName]) then
+		return;
+	end
+
 	local selected = self.db.realm.userdata[self.vars.playername].skills[skillName].window.selected;

 	for name, info in pairs(self.db.realm.userdata[self.vars.playername].skills[skillName].recipes) do
diff --git a/CauldronMainUI.lua b/CauldronMainUI.lua
index 6f66cf4..2d17fd5 100644
--- a/CauldronMainUI.lua
+++ b/CauldronMainUI.lua
@@ -37,7 +37,7 @@ function Cauldron:Frame_Show()
 			TradeSkillFrame:SetPoint("TOPLEFT", 0, 900);
 			TradeSkillFrame:SetFrameStrata("BACKGROUND");
 			TradeSkillFrame:SetFrameLevel(1);
-	end
+		end

 	 	self:RegisterMessage("Cauldron_Update", "OnCauldronUpdate");

@@ -62,8 +62,8 @@ function Cauldron:Frame_Hide()

  	if TradeSkillFrame then
  		TradeSkillFrame:SetAlpha(1.0);
- 		TradeSkillFrame:SetFrameStrata(Cauldron.vars.origFrameStrata);
- 		TradeSkillFrame:SetFrameLevel(Cauldron.vars.origFrameLevel);
+ 		TradeSkillFrame:SetFrameStrata(Cauldron.vars.origFrameStrata or "BACKGROUND");
+ 		TradeSkillFrame:SetFrameLevel(Cauldron.vars.origFrameLevel or 1);
  	end

 	--@alpha@
@@ -171,7 +171,14 @@ function Cauldron:UpdateSkillInfo(skillName, rank, maxRank)
 	self:debug("UpdateSkillInfo enter");
 	--@end-alpha@

-	CauldronRankFrameSkillName:SetText(skillName);
+	local skillCount = 0;
+	if (self.db.realm.userdata[self.vars.playername]) and
+	   (self.db.realm.userdata[self.vars.playername].skills[skillName]) then
+		for _, _ in pairs(self.db.realm.userdata[self.vars.playername].skills[skillName].recipes) do
+			skillCount = skillCount + 1;
+		end
+	end
+	CauldronRankFrameSkillName:SetText(skillName.." ("..skillCount.." "..L["skills"]..")");

 	CauldronRankFrame:SetStatusBarColor(0.0, 0.0, 1.0, 0.5);
 	CauldronRankFrameBackground:SetVertexColor(0.0, 0.0, 0.75, 0.5);
@@ -193,6 +200,13 @@ function Cauldron:UpdateSearchText()
 	if IsTradeSkillLinked() then
 		skillName = "Linked-"..skillName;
 	end
+
+	if (not skillName or skillName == "UNKNOWN") or
+	   (not self.vars.playername) or
+	   (not self.db.realm.userdata[self.vars.playername]) or
+	   (not self.db.realm.userdata[self.vars.playername].skills[skillName]) then
+		return;
+	end

 	local searchText = self.db.realm.userdata[self.vars.playername].skills[skillName].window.search or "";
 	if searchText == "" then
@@ -226,6 +240,9 @@ function Cauldron:UpdateSkillList()
 	end

 	local skillList = Cauldron:GetSkillList(self.vars.playername, skillName);
+	if not skillList then
+		return;
+	end
 --@alpha@
 	self:debug("UpdateSkillList: skillList="..#skillList);
 --@end-alpha@
@@ -2008,6 +2025,13 @@ function Cauldron:TradeSkillFilter_OnTextChanged(frame)
 		skillName = "Linked-"..skillName;
 	end

+	if (not skillName or skillName == "UNKNOWN") or
+	   (not self.vars.playername) or
+	   (not self.db.realm.userdata[self.vars.playername]) or
+	   (not self.db.realm.userdata[self.vars.playername].skills[skillName]) then
+		return;
+	end
+
 	local text = frame:GetText();
 	if text == SEARCH then
 		text = "";
diff --git a/CauldronTradeskill.lua b/CauldronTradeskill.lua
index 10bb100..b43056e 100644
--- a/CauldronTradeskill.lua
+++ b/CauldronTradeskill.lua
@@ -4,6 +4,14 @@
 function Cauldron:UpdateSkills()
 	self:debug("UpdateSkills enter");

+--	self:info("updating skills: "..debugstack());
+
+--	self:info("updatingSkills="..tostring(self.updatingSkills));
+	if not self.updatingSkills then
+		self:debug("not updating skills; return");
+		return;
+	end
+
 	local skillName = GetTradeSkillLine();
 	local baseSkillName = skillName;
 	self:debug("UpdateSkills: skillName="..skillName);
@@ -56,24 +64,38 @@ function Cauldron:UpdateSkills()
 	SetTradeSkillItemNameFilter(nil);
 	SetTradeSkillItemLevelFilter(0, 0);

-	local category = self.skillCategory;
+
+	local category --[[ = self.skillCategory;
+	self:info("category="..tostring(category));
 	if not category then
-		category = "";
+		self:info("initialize category");
+		category --]] = "";
+	--[[
 	end

 	local first = self.skillStart;
+	self:info("first="..tostring(first));
 	if not first then
+		self:info("initialize first to 1");
 		first = 1;
 	end
 	local last = self.skillEnd;
+	self:info("last="..tostring(last));
 	local total = GetNumTradeSkills();
+	self:info("total="..tostring(total));
 	local increment = 25;
+	self:info("increment="..tostring(increment));
 	if not last then
+		self:info("initialize last value");
 		last = math.min(increment, total);
+		self:info("last="..tostring(last));
 	end
+	--]]

---	for i=1,GetNumTradeSkills() do
-	for i=first,last do
+--	self:info("iterate over skills");
+	for i=1,GetNumTradeSkills() do
+--	for i=first,last do
+--		self:info("i="..tostring(i));
 		local name, difficulty, avail, expanded, verb = GetTradeSkillInfo(i);
 --		self:debug("UpdateSkills: name="..name.."; difficulty="..difficulty.."; avail="..avail);

@@ -205,20 +227,27 @@ function Cauldron:UpdateSkills()
 		end
 	end

+	--[[
 	-- increment the counters
+	self:info("increment counters");
 	first = first + increment;
+	self:info("first="..tostring(first));
 	last = last + increment;
+	self:info("last="..tostring(last));
 	-- check if we need to queue the next batch
 	if first < total then
+		self:info("first < total");
 		-- update the counter storage variables
 		self.skillStart = first;
 		self.skillEnd = last;
 		self.skillCategory = category;

 		-- set the timer
+		self:info("schedule timer for next run");
 		self:ScheduleTimer(self.UpdateSkills,1,self);
 --		self:UpdateSkillList();
 	end
+	--]]

 	self:debug("UpdateSkills exit");
 end
@@ -284,11 +313,16 @@ end
 function Cauldron:GetSkillList(playername, skillName)
 	self:debug("GetSkillList enter");

-	if (not playername) or (not skillName) then
+	if (not playername) or
+	   (not skillName) then
 		self:warn("GetSkillList: playername ("..tostring(playername)..") or skillName ("..tostring(skillName)..") not set!");
 		return;
 	end
-
+	if (not self.db.realm.userdata[playername]) or
+	   (not self.db.realm.userdata[playername].skills[skillName]) then
+		return;
+	end
+
 	local skills = {};

 	for name, recipe in pairs(self.db.realm.userdata[playername].skills[skillName].recipes) do
diff --git a/Locale/Cauldron-enUS.lua b/Locale/Cauldron-enUS.lua
index ac5578c..78866c0 100644
--- a/Locale/Cauldron-enUS.lua
+++ b/Locale/Cauldron-enUS.lua
@@ -31,6 +31,7 @@ L["Normal logging of warnings and errors"] = true
 L["Debug logging (very verbose)"] = true
 L["enabled"] = true
 L["disabled"] = true
+L["skills"] = true

 L["Auto-buy?"] = true
 L["If this option is checked, then any item that is in the list will be automatically purchased when a vendor window is opened, if that vendor has the items."] = true