Quantcast

Fixed broker plugin code.

F16Gaming [09-02-12 - 14:22]
Fixed broker plugin code.
Filename
.gitignore
Broker.lua
KillTrack.lua
icon.tga
diff --git a/.gitignore b/.gitignore
index 9f5fe64..8c08967 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+ss_*.png
 /libs/LibStub
 /libs/CallbackHandler-1.0
 /libs/AceGUI-3.0
diff --git a/Broker.lua b/Broker.lua
index 97d8b9d..e9cc639 100644
--- a/Broker.lua
+++ b/Broker.lua
@@ -21,8 +21,8 @@ local KT = KillTrack

 KT.Broker = {
 	Text = {
-		Short = "KPM: %f",
-		Long = "Kills Per Minute: %f",
+		Short = "KPM: %.2f",
+		Long = "Kills Per Minute: %.2f"
 	}
 }

@@ -33,14 +33,57 @@ local t = 0

 local ldb = LibStub:GetLibrary("LibDataBroker-1.1")

+local frame = CreateFrame("Frame")
+
 local data = {
 	type = "data source",
-	label = "KillTrack |cff00FF00(" .. KT.Version .. ")|r",
-	icon = "Interface\\AddOns\\KillTrack\\icon.tga"
+	label = KT.Name,
+	icon = "Interface\\AddOns\\KillTrack\\icon.tga",
+	tocname = KT.Name
 }

 local obj = ldb:NewDataObject("Broker_KillTrack", data)

+function obj.OnTooltipShow(tip)
+	tip:AddLine(("%s |cff00FF00(%s)|r"):format(KT.Name, KT.Version), 1, 1, 1)
+	tip:AddLine(" ")
+	tip:AddLine("Most kills this session:", 1, 1, 0)
+	local added = 0
+	for k,v in pairs(KT.Session.Kills) do
+		tip:AddDoubleLine(k, v)
+		added = added + 1
+	end
+	if added <= 0 then
+		tip:AddLine("No kills this session", 1, 0, 0)
+	end
+	tip:AddLine(" ")
+	tip:AddLine("Most kills total:", 1, 1, 0)
+	local added = 0
+	for _,v in pairs(KT:GetSortedMobTable()) do
+		tip:AddDoubleLine(v.Name, ("%d (%d)"):format(v.cKills, v.gKills))
+		added = added + 1
+		if added >= 3 then break end
+	end
+	if added <= 0 then
+		tip:AddLine("No kills recorded yet", 1, 0, 0)
+	end
+	tip:AddLine(" ")
+	tip:AddDoubleLine("Left Click", "Open mob database", 0, 1, 0, 0, 1, 0)
+	tip:AddDoubleLine("Middle Click", "Toggle short/long text", 0, 1, 0, 0, 1, 0)
+	tip:AddDoubleLine("Right Click", "Reset session statistics", 0, 1, 0, 0, 1, 0)
+	tip:Show()
+end
+
+function obj.OnClick(self, button)
+	if button == "LeftButton" then
+		KT.MobList:ShowGUI()
+	elseif button == "MiddleButton" then
+		KTB:ToggleTextMode()
+	elseif button == "RightButton" then
+		KT:ResetSession()
+	end
+end
+
 function KTB:UpdateText()
 	local text = KT.Global.BROKER.SHORT_TEXT and self.Text.Short or self.Text.Long
 	obj.text = text:format(KT:GetKPM())
@@ -55,13 +98,11 @@ function KTB:OnUpdate(frame, elapsed)
 end

 function KTB:ToggleTextMode()
-	if type(KT.Global.BROKER) ~= "table" then KT.Global.BROKER = {} end
 	KT.Global.BROKER.SHORT_TEXT = not KT.Global.BROKER.SHORT_TEXT
 	self:UpdateText()
 end

-local frame = CreateFrame("Frame")
-
-frame:SetScript("OnUpdate", function(self, elapsed) KTB:OnUpdate(self, elapsed) end)
-
-KTB:UpdateText()
+function KTB:OnLoad()
+	frame:SetScript("OnUpdate", function(self, elapsed) KTB:OnUpdate(self, elapsed) end)
+	self:UpdateText()
+end
diff --git a/KillTrack.lua b/KillTrack.lua
index c9fda7e..4fe1ce8 100644
--- a/KillTrack.lua
+++ b/KillTrack.lua
@@ -79,12 +79,19 @@ function KT.Events.ADDON_LOADED(self, ...)
 	if type(_G["KILLTRACK_CHAR"]) ~= "table" then
 		_G["KILLTRACK_CHAR"] = {}
 	end
+	if type(KT.Global.BROKER) ~= "table" then
+		KT.Global.BROKER = {}
+	end
+	if type(KT.Global.BROKER.SHORT_TEXT) ~= "boolean" then
+		KT.Global.BROKER.SHORT_TEXT = false
+	end
 	self.CharGlobal = _G["KILLTRACK_CHAR"]
 	if type(self.CharGlobal.MOBS) ~= "table" then
 		self.CharGlobal.MOBS = {}
 	end
 	self:Msg("AddOn Loaded!")
-	self.Session.Start = time()
+	self.Session.Start = time() / 60
+	self.Broker:OnLoad()
 end

 function KT.Events.COMBAT_LOG_EVENT_UNFILTERED(self, ...)
@@ -177,7 +184,7 @@ function KT:AddKill(id, name)
 	if self.Global.PRINTKILLS then
 		self:Msg(("Updated %q, new kill count: %d. Kill count on this character: %d"):format(name, self.Global.MOBS[id].Kills, self.CharGlobal.MOBS[id].Kills))
 	end
-	self:AddSessionKill(name, self.Global.MOBS[id].Kills)
+	self:AddSessionKill(name)
 	if type(self.Global.MOBS[id].AchievCount) ~= "number" then
 		self.Global.MOBS[id].AchievCount = floor(self.Global.MOBS[id].Kills / self.Global.ACHIEV_THRESHOLD)
 		if self.Global.MOBS[id].AchievCount >= 1 then
@@ -192,8 +199,12 @@ function KT:AddKill(id, name)
 	end
 end

-function KT:AddSessionKill(name, kills)
-	self.Session.Kills[name] = kills
+function KT:AddSessionKill(name)
+	if self.Session.Kills[name] then
+		self.Session.Kills[name] = self.Session.Kills[name] + 1
+	else
+		self.Session.Kills[name] = 1
+	end
 	table.sort(self.Session.Kills, function(a, b) return a > b end)
 	-- Trim table to only contain 3 entries
 	local trimmed = {}
@@ -207,6 +218,12 @@ function KT:AddSessionKill(name, kills)
 	self.Session.Count = self.Session.Count + 1
 end

+function KT:ResetSession()
+	wipe(self.Session.Kills)
+	self.Session.Count = 0
+	self.Session.Start = time() / 60
+end
+
 function KT:GetKills(id)
 	local gKills, cKills = 0, 0
 	for k,v in pairs(self.Global.MOBS) do
@@ -220,9 +237,9 @@ function KT:GetKills(id)
 	return gKills, cKills
 end

-function GetKPM()
+function KT:GetKPM()
 	if not self.Session.Start then return 0 end
-	return self.Session.Count / (time() - self.Session.Start)
+	return self.Session.Count / (time() / 60 - self.Session.Start)
 end

 function KT:PrintKills(identifier)
diff --git a/icon.tga b/icon.tga
index 8e43c71..d9ccafd 100644
Binary files a/icon.tga and b/icon.tga differ