changeset 23:819bfdc5d73c

More debug messages and added the ability to scroll the debug window.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Thu, 08 Jul 2010 23:55:05 -0700
parents 66b7c3f5937e
children 554b30908b33
files CHANGELOG.txt Core.lua ItemAuditor.xml Modules/Events.lua Modules/QuickAuctions.lua
diffstat 5 files changed, 110 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGELOG.txt	Thu Jul 08 19:30:30 2010 -0700
+++ b/CHANGELOG.txt	Thu Jul 08 23:55:05 2010 -0700
@@ -3,6 +3,8 @@
 - Added a (hopefully) more readable changelog.
 - I have removed the ability to show debug messages in the chat window and have replaced it with a new debug frame. /ia debug will show all of the debug messages and everything that IA has printed.
 - Fix a small bug so that if you sell something for your exact cost you don't get a message that says you made a profit of 0c.
+- Added more debug messages
+- The debug window will scroll with the scroll wheel
 
 2010-07-06  Asa Ayers  <Asa.Ayers@Gmail.com>
 
--- a/Core.lua	Thu Jul 08 19:30:30 2010 -0700
+++ b/Core.lua	Thu Jul 08 23:55:05 2010 -0700
@@ -26,7 +26,9 @@
 			messages = {
 				cost_updates = true,
 				queue_skip = false,
-			}
+			},
+			-- This is for development, so I have no plans to turn it into an option.
+			show_debug_frame_on_startup = false,
 		},
 		factionrealm = {
 			item_account = {},
@@ -40,6 +42,11 @@
 	self:RegisterOptions()
 	
 	self:RegisterEvent("PLAYER_ENTERING_WORLD")
+	
+	-- /run ItemAuditor.db.profile.show_debug_frame_on_startup = true
+	if self.db.profile.show_debug_frame_on_startup then
+		ItemAuditor_DebugFrame:Show()
+	end
 end
 
 function addon:ConvertItems()
@@ -97,24 +104,27 @@
 	for link, count in pairs(current.items) do
 		if pastInventory.items[link] == nil then
 			diff[link] = count
-			-- self:Debug("1 diff[" .. name .. "]=" .. diff[name])
+			self:Debug("1 diff[" .. link .. "]=" .. diff[link])
 		elseif count - pastInventory.items[link] ~= 0 then
 			diff[link] = count - pastInventory.items[link]
-			-- self:Debug("2 diff[" .. name .. "]=" .. diff[name])        
+			self:Debug("2 diff[" .. link .. "]=" .. diff[link])        
 		end    
 	end
 
 	for link, count in pairs(pastInventory.items) do
 		if current.items[link] == nil then
 			diff[link] = -count
-			-- self:Debug("3 diff[" .. name .. "]=" .. diff[name])                
+			self:Debug("3 diff[" .. link .. "]=" .. diff[link])                
 		elseif current.items[link] - count ~= 0 then
 			diff[link] = current.items[link] - pastInventory.items[link]
-			-- self:Debug("4 diff[" .. name .. "]=" .. diff[name])        
+			self:Debug("4 diff[" .. link .. "]=" .. diff[link])        
 		end
 	end
 
 	local moneyDiff = current.money - pastInventory.money
+	if abs(moneyDiff) > 0 then
+		self:Debug("moneyDiff: " .. moneyDiff)
+	end
 
 	return {items = diff, money = moneyDiff}
 end
@@ -172,6 +182,13 @@
 		end
 
 	end
+	
+	for mailType, collection in pairs(results) do
+		for item, total in pairs(collection) do
+			self:Debug(format("|cFF00FF00MailScan|r: %s - %s - %s", mailType, item, total))
+		end
+	end
+	
 	return results   
 end
 
@@ -229,14 +246,17 @@
 end
 
 function addon:SaveValue(link, value)
+	self:Debug(format("SaveValue(%s, %s)", tostring(link), value))
 	local item = nil
 	local realLink = self:GetSafeLink(link)
 	local itemName = nil
 	if realLink == nil then
+		self:Debug('SaveValue: GetSafeLink failed, falling back to storing by name: ' .. tostring(itemName))
 		itemName = link
 		self.db.factionrealm.item_account[itemName] = (self.db.factionrealm.item_account[itemName] or 0) + value
 		item = {invested = self.db.factionrealm.item_account[itemName], count = 1}
 	else
+		
 		item = self:GetItem(realLink)
 		item.invested = item.invested + value
 		itemName = GetItemInfo(realLink)
@@ -267,19 +287,10 @@
 end
 
 
-local defaultBagDelay = 0.2
-
-function addon:WatchBags(delay)
-	delay = delay or defaultBagDelay
-	if delay ~= self.currentBagDelay  then
-		self:UnwatchBags()
-	end
-
+function addon:WatchBags()
 	if self.watch_handle == nil then
-		self.currentBagDelay = delay
-		self:Debug("currentBagDelay = " .. delay)
 		addon:UpdateCurrentInventory()
-		self.watch_handle = self:RegisterBucketEvent({"BAG_UPDATE", "PLAYER_MONEY"}, self.currentBagDelay, "UpdateAudit")
+		self.watch_handle = self:RegisterBucketEvent({"BAG_UPDATE", "PLAYER_MONEY"}, 0.3, "UpdateAudit")
 	end
 end
 
--- a/ItemAuditor.xml	Thu Jul 08 19:30:30 2010 -0700
+++ b/ItemAuditor.xml	Thu Jul 08 23:55:05 2010 -0700
@@ -1,7 +1,7 @@
 <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/
 	../UI.xsd">
 	
-	<Frame name="ItemAuditor_DebugFrame" toplevel="true" movable="false" parent="UIParent" enableMouse="true" resizable="false" frameStrata="MEDIUM"  hidden="true">
+	<Frame name="ItemAuditor_DebugFrame" toplevel="true" movable="true" parent="UIParent" enableMouse="true" resizable="false" frameStrata="MEDIUM"  hidden="true">
 		<Size x="640" y="512"/>
 		<Anchors>
 			<Anchor point="CENTER"/>
@@ -69,7 +69,7 @@
 			
 		</Layers>
 		<Frames>
-			<ScrollingMessageFrame name="$parentTxt" maxLines="100" fade="false" enableMouse="true">
+			<ScrollingMessageFrame name="$parentTxt" maxLines="999" fade="false" enableMouse="true">
 				<Anchors>
 					<Anchor point="TOPLEFT" relativePoint="TOPLEFT">
 						<Offset x="25" y="-45"/>
@@ -81,6 +81,21 @@
 				<FontString font="Interface\AddOns\WowLua\fonts\VeraMono.ttf" justifyH="LEFT">
 					<FontHeight val="14"/>
 				</FontString>
+				<Scripts>
+					<OnMouseWheel>
+						local direction;
+						if delta > 0 then
+							direction = "up";
+							self:ScrollUp()
+						else
+							direction = "down";
+							self:ScrollDown()
+						end
+						
+						-- WowLua:ScrollingMessageFrameScroll(self, direction, type);
+					</OnMouseWheel>
+					
+				</Scripts>
 			</ScrollingMessageFrame>
 			<Button name="ItemAuditorButton_Close" inherits="UIPanelCloseButton">
 				<Anchors>
@@ -94,7 +109,38 @@
 					</OnClick>
 				</Scripts>
 			</Button>
+			<Button name="$parentDragHeader">
+				<Size y="60"/>
+				<Anchors>
+					<Anchor point="TOPLEFT">
+						<Offset x="0" y="-13"/>
+					</Anchor>
+					<Anchor point="TOPRIGHT">
+						<Offset x="0" y="0"/>
+					</Anchor>
+				</Anchors>
+				<Layer level="BACKGROUND"> 
+					<Texture name="$parent_Background" setAllPoints="true">
+						<Color r="0" g="0" b="1" a="0.5" /> 
+					</Texture> 
+				</Layer>
+				<Scripts>
+					<OnMouseDown>
+						local parent = self:GetParent()
+						if parent:IsMovable() then
+						parent:StartMoving()
+						end
+					</OnMouseDown>
+					<OnMouseUp>
+						local parent = self:GetParent()
+						parent:StopMovingOrSizing()
+					</OnMouseUp>
+				</Scripts>
+			</Button>
 		</Frames>
+		<Scripts>
+		
+		</Scripts>
 	</Frame>
 	<Scripts>
 		ItemAuditor_DebugFrame:Hide()
--- a/Modules/Events.lua	Thu Jul 08 19:30:30 2010 -0700
+++ b/Modules/Events.lua	Thu Jul 08 23:55:05 2010 -0700
@@ -18,10 +18,10 @@
 	self:UnregisterEvent("MAIL_SHOW")
 	self:RegisterEvent("MAIL_CLOSED")
 	self:RegisterEvent("MAIL_INBOX_UPDATE")
-	self:Debug("MAIL_SHOW complete")
 end
 
 function addon:MAIL_CLOSED()
+	self:Debug("MAIL_CLOSED")
 	addon:UnregisterEvent("MAIL_CLOSED")
 	self:MAIL_INBOX_UPDATE()
 	self:UnregisterEvent("MAIL_INBOX_UPDATE")
@@ -29,6 +29,7 @@
 end
 
 function addon:MAIL_INBOX_UPDATE()
+	self:Debug("MAIL_INBOX_UPDATE")
 	local newScan = addon:ScanMail()
 	local diff
 	for mailType, collection in pairs(self.lastMailScan) do
@@ -48,6 +49,7 @@
 
 function addon:UNIT_SPELLCAST_START(event, target, spell)
 	if target == "player" and spell == "Milling" or spell == "Prospecting" or spell == "Disenchanting" then
+		self:Debug(event .. " " .. spell)
 		self:UnwatchBags()
 		self:UpdateCurrentInventory()
 		self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
@@ -60,6 +62,7 @@
 	needs to be kept so it can be combined with the up coming loot.
  ]]
 function addon:LOOT_CLOSED()
+	self:Debug("LOOT_CLOSED")
 	self:UnregisterEvent("LOOT_CLOSED")
 	self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED")
 	local inventory = self.lastInventory
@@ -69,6 +72,7 @@
 
 function addon:UNIT_SPELLCAST_INTERRUPTED(event, target, spell)
 	if target == "player" and spell == "Milling" or spell == "Prospecting" or spell == "Disenchanting" then
+		self:Debug(event .. " " .. spell)
 		self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED")
 		self:UnregisterEvent("LOOT_CLOSED")
 		self:WatchBags()
@@ -80,11 +84,9 @@
 end
 
 function addon:UpdateAudit()
-	-- self:Debug("UpdateAudit")
+	-- self:Debug("UpdateAudit " .. event)
 	local currentInventory = self:GetCurrentInventory()
 	local diff =  addon:GetInventoryDiff(self.lastInventory, currentInventory)
-	-- this is only here for debugging
-	self.lastdiff = diff
 	
 	local positive, negative = {}, {}
 	local positiveCount, negativeCount = 0, 0
@@ -98,6 +100,10 @@
 		end
 	end
 	
+	if positiveCount + negativeCount == 0 then
+		return
+	end
+	
 	if diff.money > 0 and self:tcount(positive) > 0 and self:tcount(negative) == 0 then
 		self:Debug("loot")
 	elseif abs(diff.money) > 0 and self:tcount(diff.items) == 1 then
@@ -106,26 +112,25 @@
 		for link, count in pairs(diff.items) do
 			self:SaveValue(link, 0 - diff.money)
 		end
-	elseif self:tcount(diff.items) > 1 then
+	elseif self:tcount(diff.items) > 1 and self:tcount(positive) > 0 and self:tcount(negative) > 0 then
+		-- we must have created/converted something
+		self:Debug("conversion")
 		
-		if self:tcount(positive) > 0 and self:tcount(negative) > 0 then
-			-- we must have created/converted something
-			self:Debug("conversion")
+		local totalChange = 0
+		for link, change in pairs(negative) do
+			local _, itemCost, count = self:GetItemCost(link, change)
+			self:SaveValue(link, itemCost * change)
 			
-			local totalChange = 0
-			for link, change in pairs(negative) do
-				local _, itemCost, count = self:GetItemCost(link, change)
-				self:SaveValue(link, itemCost * change)
-				
-				totalChange = totalChange + (itemCost * abs(change))
-			end
-			
-			local valuePerItem = totalChange / positiveCount
-			
-			for link, change in pairs(positive) do
-				self:SaveValue(link, valuePerItem * change)
-			end
+			totalChange = totalChange + (itemCost * abs(change))
 		end
+		
+		local valuePerItem = totalChange / positiveCount
+		
+		for link, change in pairs(positive) do
+			self:SaveValue(link, valuePerItem * change)
+		end
+	else
+		self:Debug("No match in UpdateAudit.")
 	end
 	
 	self.lastInventory = currentInventory
--- a/Modules/QuickAuctions.lua	Thu Jul 08 19:30:30 2010 -0700
+++ b/Modules/QuickAuctions.lua	Thu Jul 08 23:55:05 2010 -0700
@@ -169,8 +169,13 @@
 						profit = (currentPrice - newCost) * toQueue
 					}
 					profitableIndex = profitableIndex + 1
-				elseif ItemAuditor.db.profile.messages.queue_skip then
-					self:Print(format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, addon:FormatMoney(currentPrice - newCost)))
+				else
+					local skipMessage = format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, addon:FormatMoney(currentPrice - newCost))
+					if ItemAuditor.db.profile.messages.queue_skip then
+						self:Print(skipMessage)
+					else
+						self:Debug(format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, addon:FormatMoney(currentPrice - newCost)))
+					end
 				end
 			end
 		end