Quantcast

Added GUI to put all mob entries in a scrollable list.

F16Gaming [11-02-11 - 07:19]
Added GUI to put all mob entries in a scrollable list.

NOTE: Ace library is still not added, MobList will not function without it.

ADDED: GUI window for scrollable list.
ADDED: /kt list command to open the list.
CHANGED: Moved the GetSortedMobTable method into KillTrack.lua-
FIXED: Purge and Reset should now remove/disable mob entries properly.
Filename
Command.lua
Dialogs.lua
KillTrack.lua
KillTrack.toc
MobList.lua
Tools.lua
diff --git a/Command.lua b/Command.lua
index 33197c9..b04b3ce 100644
--- a/Command.lua
+++ b/Command.lua
@@ -69,6 +69,7 @@ C:Register("__DEFAULT__", function(args)
 	KT:Msg("/kt target - Display number of kills on target mob.")
 	KT:Msg("/kt lookup <name> - Display number of kills on <name>, <name> can also be NPC ID.")
 	KT:Msg("/kt print - Toggle printing kill updates to chat.")
+	KT:Msg("/kt list - Display a list of all mobs entries.")
 	KT:Msg("/kt purge [treshold] - Open dialog to purge entries, specifiying a treshold here is optional.")
 	KT:Msg("/kt reset - Clear the mob database.")
 	KT:Msg("/kt - Displays this help message.")
@@ -108,6 +109,10 @@ C:Register({"lookup", "lo", "check"}, function(args)
 	KT:PrintKills(name)
 end)

+C:Register({"list", "moblist", "mobs"}, function(args)
+	KT.MobList:ShowGUI()
+end)
+
 for i,v in ipairs(C.Slash) do
 	_G["SLASH_" .. KT.Name:upper() .. i] = "/" .. v
 end
diff --git a/Dialogs.lua b/Dialogs.lua
index 7f32624..03b9f23 100644
--- a/Dialogs.lua
+++ b/Dialogs.lua
@@ -23,15 +23,15 @@ local Treshold

 local function Purge(treshold)
 	local count = 0
-	for i,v in ipairs(KT.Global.MOBS) do
-		if v.Kills < treshold then
-			table.remove(KT.Global.MOBS, i)
+	for k,v in pairs(KT.Global.MOBS) do
+		if type(v) == "table" and v.Kills < treshold then
+			KT.Global.MOBS[k] = nil
 			count = count + 1
 		end
 	end
-	for i,v in pairs(KT.CharGlobal.MOBS) do
-		if v.Kills < treshold then
-			table.remove(KT.CharGlobal.MOBS, i)
+	for k,v in pairs(KT.CharGlobal.MOBS) do
+		if type(v) == "table" and v.Kills < treshold then
+			KT.CharGlobal.MOBS[k] = nil
 			count = count + 1
 		end
 	end
diff --git a/KillTrack.lua b/KillTrack.lua
index 9949cd6..d0e76cf 100644
--- a/KillTrack.lua
+++ b/KillTrack.lua
@@ -22,7 +22,17 @@ KillTrack = {
 	Version = GetAddOnMetadata("KillTrack", "Version"),
 	Events = {},
 	Global = {},
-	CharGlobal = {}
+	CharGlobal = {},
+	Sort = {
+		Desc = 0,
+		Asc = 1,
+		CharDesc = 2,
+		CharAsc = 3,
+		AlphaD = 4,
+		AlphaA = 5,
+		IdDesc = 6,
+		IdAsc = 7
+	}
 }

 local KT = KillTrack
@@ -96,7 +106,7 @@ end
 function KT:GetKills(id)
 	local gKills, cKills = 0, 0
 	for k,v in pairs(self.Global.MOBS) do
-		if k == id then
+		if k == id and type(v) == "table" then
 			gKills = v.Kills
 			if self.CharGlobal.MOBS[k] then
 				cKills = self.CharGlobal.MOBS[k].Kills
@@ -113,7 +123,7 @@ function KT:PrintKills(identifier)
 	local cKills = 0
 	if type(identifier) ~= "string" and type(identifier) ~= "number" then identifier = "<No Name>" end
 	for k,v in pairs(self.Global.MOBS) do
-		if tostring(k) == tostring(identifier) or v.Name == identifier then
+		if type(v) == "table" and (tostring(k) == tostring(identifier) or v.Name == identifier) then
 			name = v.Name
 			gKills = v.Kills
 			if self.CharGlobal.MOBS[k] then
@@ -136,6 +146,41 @@ function KT:Msg(msg)
 	DEFAULT_CHAT_FRAME:AddMessage("\124cff00FF00[KillTrack]\124r " .. msg)
 end

+function KT:GetSortedMobTable(mode)
+	if not tonumber(mode) then mode = self.Sort.Desc end
+	if mode < 0 or mode > 7 then mode = self.Sort.Desc end
+	local t = {}
+	for k,v in pairs(self.Global.MOBS) do
+		local cKills = 0
+		if self.CharGlobal.MOBS[k] and type(v) == "table" then cKills = self.CharGlobal.MOBS[k].Kills end
+		if type(v) == "table" then
+			local entry = {Id = k, Name = v.Name, gKills = v.Kills, cKills = cKills}
+			table.insert(t, entry)
+		end
+	end
+	local function compare(a, b)
+		if mode == self.Sort.Asc then
+			return a.gKills < b.gKills
+		elseif mode == self.Sort.CharDesc then
+			return a.cKills > b.cKills
+		elseif mode == self.Sort.CharAsc then
+			return a.cKills < b.cKills
+		elseif mode == self.Sort.AlphaD then
+			return a.Name > b.Name
+		elseif mode == self.Sort.AlphaA then
+			return a.Name < b.Name
+		elseif mode == self.Sort.IdDesc then
+			return a.Id > b.Id
+		elseif mode == self.Sort.IdAsc then
+			return a.Id < b.Id
+		else
+			return a.gKills > b.gKills -- Descending
+		end
+	end
+	table.sort(t, compare)
+	return t
+end
+
 KT.Frame = CreateFrame("Frame")

 for k,_ in pairs(KT.Events) do
diff --git a/KillTrack.toc b/KillTrack.toc
index 1ad62bd..a842642 100644
--- a/KillTrack.toc
+++ b/KillTrack.toc
@@ -10,3 +10,5 @@ Tools.lua
 KillTrack.lua
 Dialogs.lua
 Command.lua
+MobList.lua
+#MobList.xml
diff --git a/MobList.lua b/MobList.lua
new file mode 100644
index 0000000..8aa04cd
--- /dev/null
+++ b/MobList.lua
@@ -0,0 +1,183 @@
+--[[
+	* Copyright (c) 2011 by Adam Hellberg.
+	*
+	* This file is part of KillTrack.
+	*
+	* KillTrack is free software: you can redistribute it and/or modify
+	* it under the terms of the GNU General Public License as published by
+	* the Free Software Foundation, either version 3 of the License, or
+	* (at your option) any later version.
+	*
+	* KillTrack is distributed in the hope that it will be useful,
+	* but WITHOUT ANY WARRANTY; without even the implied warranty of
+	* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	* GNU General Public License for more details.
+	*
+	* You should have received a copy of the GNU General Public License
+	* along with KillTrack. If not, see <http://www.gnu.org/licenses/>.
+--]]
+
+KillTrack.MobList = {}
+
+local KT = KillTrack
+local ML = KT.MobList
+
+local Sort = KT.Sort.Desc
+
+local GUI = LibStub("AceGUI-3.0")
+
+local frame, scrollHeader, idHeader, nameHeader, cKillsHeader, gKillsHeader, scrollContainer, scroll
+
+function ML:ShowGUI()
+	frame = GUI:Create("Frame")
+	frame:SetHeight(600)
+	frame:SetWidth(560)
+	frame:SetLayout("Flow")
+	frame:SetTitle("KillTrack - Mob List")
+	frame:SetCallback("OnClose", function(frame) frame:Release() end)
+
+	scrollHeader = GUI:Create("SimpleGroup")
+	scrollHeader:SetFullWidth(true)
+	scrollHeader:SetLayout("Flow")
+	idHeader = GUI:Create("InteractiveLabel")
+	idHeader:SetWidth(100)
+	idHeader:SetFont("Fonts\\FRIZQT__.TTF", 12)
+	idHeader:SetText("NPC ID")
+	idHeader:SetColor(1, 1, 0)
+	idHeader:SetHighlight(0.1, 0.1, 0.1)
+	idHeader:SetCallback("OnClick", function()
+		if Sort == KT.Sort.IdAsc then
+			Sort = KT.Sort.IdDesc
+		else
+			Sort = KT.Sort.IdAsc
+		end
+		ML:UpdateList()
+	end)
+	nameHeader = GUI:Create("InteractiveLabel")
+	nameHeader:SetWidth(200)
+	nameHeader:SetFont("Fonts\\FRIZQT__.TTF", 12)
+	nameHeader:SetText("Name")
+	nameHeader:SetColor(1, 1, 0)
+	nameHeader:SetHighlight(0.1, 0.1, 0.1)
+	nameHeader:SetCallback("OnClick", function()
+		if Sort == KT.Sort.AlphaA then
+			Sort = KT.Sort.AlphaD
+		else
+			Sort = KT.Sort.AlphaA
+		end
+		ML:UpdateList()
+	end)
+	cKillsHeader = GUI:Create("InteractiveLabel")
+	cKillsHeader:SetWidth(100)
+	cKillsHeader:SetFont("Fonts\\FRIZQT__.TTF", 12)
+	cKillsHeader:SetText("Character")
+	cKillsHeader:SetColor(1, 1, 0)
+	cKillsHeader:SetHighlight(0.1, 0.1, 0.1)
+	cKillsHeader:SetCallback("OnClick", function()
+		if Sort == KT.Sort.CharDesc then
+			Sort = KT.Sort.CharAsc
+		else
+			Sort = KT.Sort.CharDesc
+		end
+		ML:UpdateList()
+	end)
+	gKillsHeader = GUI:Create("InteractiveLabel")
+	gKillsHeader:SetWidth(100)
+	gKillsHeader:SetFont("Fonts\\FRIZQT__.TTF", 12)
+	gKillsHeader:SetText("Global")
+	gKillsHeader:SetColor(1, 1, 0)
+	gKillsHeader:SetHighlight(0.1, 0.1, 0.1)
+	gKillsHeader:SetCallback("OnClick", function()
+		if Sort == KT.Sort.Desc then
+			Sort = KT.Sort.Asc
+		else
+			Sort = KT.Sort.Desc
+		end
+		ML:UpdateList()
+	end)
+
+	scrollHeader:AddChild(idHeader)
+	scrollHeader:AddChild(nameHeader)
+	scrollHeader:AddChild(cKillsHeader)
+	scrollHeader:AddChild(gKillsHeader)
+
+	scrollContainer = GUI:Create("SimpleGroup")
+	scrollContainer:SetFullWidth(true)
+	scrollContainer:SetFullHeight(true)
+	scrollContainer:SetLayout("Fill")
+	scroll = GUI:Create("ScrollFrame")
+	scroll:SetLayout("List")
+
+	scrollContainer:AddChild(scroll)
+
+	frame:AddChild(scrollHeader)
+	frame:AddChild(scrollContainer)
+
+	self:UpdateList()
+end
+
+function ML:HideGUI()
+	frame:Release()
+end
+
+function ML:UpdateList()
+	if Sort == KT.Sort.IdDesc or Sort == KT.Sort.IdAsc then
+		idHeader:SetColor(1, 0, 0)
+		nameHeader:SetColor(1, 1, 0)
+		cKillsHeader:SetColor(1, 1, 0)
+		gKillsHeader:SetColor(1, 1, 0)
+	elseif Sort == KT.Sort.AlphaD or Sort == KT.Sort.AlphaA then
+		idHeader:SetColor(1, 1, 0)
+		nameHeader:SetColor(1, 0, 0)
+		cKillsHeader:SetColor(1, 1, 0)
+		gKillsHeader:SetColor(1, 1, 0)
+	elseif Sort == KT.Sort.CharDesc or Sort == KT.Sort.CharAsc then
+		idHeader:SetColor(1, 1, 0)
+		nameHeader:SetColor(1, 1, 0)
+		cKillsHeader:SetColor(1, 0, 0)
+		gKillsHeader:SetColor(1, 1, 0)
+	else
+		idHeader:SetColor(1, 1, 0)
+		nameHeader:SetColor(1, 1, 0)
+		cKillsHeader:SetColor(1, 1, 0)
+		gKillsHeader:SetColor(1, 0, 0)
+	end
+
+	scroll:ReleaseChildren()
+
+	local entries = KT:GetSortedMobTable(Sort)
+
+	for i,v in ipairs(entries) do
+		local container = GUI:Create("SimpleGroup")
+		container:SetFullWidth(true)
+		container:SetLayout("Flow")
+		local id = GUI:Create("InteractiveLabel")
+		id:SetWidth(100)
+		id:SetFont("Fonts\\FRIZQT__.TTF", 12)
+		id:SetText(tostring(v.Id))
+		id:SetColor(1, 1, 1)
+		id:SetHighlight(0.1, 0.1, 0.1)
+		local name = GUI:Create("Label")
+		name:SetWidth(200)
+		name:SetFont("Fonts\\FRIZQT__.TTF", 12)
+		name:SetText(v.Name)
+		name:SetColor(1, 1, 1)
+		local cKills = GUI:Create("Label")
+		cKills:SetWidth(100)
+		cKills:SetFont("Fonts\\FRIZQT__.TTF", 12)
+		cKills:SetText(v.cKills)
+		cKills:SetColor(1, 1, 1)
+		local gKills = GUI:Create("Label")
+		gKills:SetWidth(100)
+		gKills:SetFont("FRIZQT__.TTF", 12)
+		gKills:SetText(v.gKills)
+		gKills:SetColor(1, 1, 1)
+		container:AddChild(id)
+		container:AddChild(name)
+		container:AddChild(cKills)
+		container:AddChild(gKills)
+		scroll:AddChild(container)
+	end
+
+	frame:SetStatusText(("%d mob entries loaded."):format(#entries))
+end
diff --git a/Tools.lua b/Tools.lua
index f82bfcb..1488b29 100644
--- a/Tools.lua
+++ b/Tools.lua
@@ -60,31 +60,6 @@ function KTT:TableCopy(tbl, cache)
 	return copy
 end

-KTT.SortMode = {
-	Descending = 0,
-	Ascending = 1
-}
-
-function KTT:GetSortedMobTable(tbl, mode)
-	local t = {}
-	for k,v in pairs(tbl) do
-		local entry = {Id = k, Name = v.Name, Kills = v.Kills}
-		table.insert(t, entry)
-	end
-	if not mode or (mode < 0 or mode > 1) then
-		mode = self.SortMode.Descending
-	end
-	local function compare(a, b)
-		if mode == self.SortMode.Descending then
-			return a.Kills > b.Kills
-		else
-			return a.Kills < b.Kills
-		end
-	end
-	table.sort(t, compare)
-	return t
-end
-
 -----------------
 -- OTHER TOOLS --
 -----------------