--[[ *** Deathcounter ***
Written by : Yukyuk, EU-Moonglade
--]]
--[[ *** Credits ***
Credits go to : The creators of Gathermate2, Nevcairiel and Xinhuan.
If it wasn't for their clear way of coding the displaying
of pins would have been a far greater challenge.
--]]
-------------------------------------------------------------------------------
-- From _Global to local.
-------------------------------------------------------------------------------
local _G = _G
local tinsert = _G.table.insert
local tremove = _G.table.remove
local tsort = _G.table.sort
local twipe = _G.table.wipe
local pairs = _G.pairs
local ipairs = _G.ipairs
-------------------------------------------------------------------------------
-- AddOn namespace.
-------------------------------------------------------------------------------
local FOLDER_NAME, private = ...
local addon = LibStub("AceAddon-3.0"):GetAddon(private.addon_name)
local L = LibStub("AceLocale-3.0"):GetLocale("Deathcounter")
local LibQTip = LibStub:GetLibrary("LibQTip-1.0")
local worldmapWidth, worldmapHeight
local worldmapStrata, worldmapFrameLevel
-- Current worldmap pin set
local worldmapPins = {}
-- total number of pins we have created
local pinCount = 0
-- The death information fields we store
local Field = {
Time = 1,
Zone = 2,
SubZone = 3,
Xpos = 4,
Ypos = 5,
Areaid = 6,
Level = 7,
isMicro = 8,
Index = 9,
isInstance = 10,
instanceType = 11
}
-------------------------------------------------------------------------------
-- Update the Pin tooltip
-------------------------------------------------------------------------------
local function Pin_OnEnter(self)
local tooltip = LibQTip:Acquire("DeathcounterPinT", 1, "LEFT")
tooltip:SmartAnchorTo(self)
tooltip:SetAutoHideDelay(0.1, self)
if not LibQTip:IsAcquired("DeathcounterPinT") then
return
end
-- Add tooltip lines
tooltip:AddLine("This is a test")
-- Show the tooltip.
tooltip:Show()
end
local function Pin_OnLeave(self)
-- Release the tooltip
LibQTip:Release(self.tooltip)
self.tooltip = nil
end
-------------------------------------------------------------------------------
-- Update the world map with pins.
-------------------------------------------------------------------------------
function addon:UpdateWorldMap()
addon:Debug("UpdateWorldMap")
-- If the world map is not visible, stop.
if not WorldMapFrame:IsVisible() then
return
end
-- Clear the worldmap pins.
addon:clearpins(worldmapPins)
-- Get map info.
local zoneid = GetCurrentMapAreaID()
local mapLevel = GetCurrentMapDungeonLevel()
local _, _, _, isMicroDungeon, _ = GetMapInfo()
-- Player is not viewing a zone map of a continent
if not zoneid or zoneid == -1 or isMicroDungeon then
addon:clearpins(worldmapPins)
return
end
-- Get worldmap data.
worldmapWidth = WorldMapButton:GetWidth()
worldmapHeight = WorldMapButton:GetHeight()
worldmapStrata = WorldMapButton:GetFrameStrata()
worldmapFrameLevel = WorldMapButton:GetFrameLevel() + 5
-- Add the relevant pins to the worldmap.
for i = 1, #addon.db.realm[private.PLAYER_NAME].deaths do
local info = addon.db.realm[private.PLAYER_NAME].deaths[i]
if addon:DetermineToAdd(info[Field.instanceType]) then
if zoneid == info[Field.Areaid] then
if mapLevel == info[Field.Level] then
local Xposition = addon:round(info[Field.Xpos], 2)
local Yposition = addon:round(info[Field.Ypos], 2)
addon:addWorldPin(Xposition,Yposition,info[Field.Areaid],info[Field.Level],info[Field.Index],info[Field.Time])
end
end
end
end
end
-------------------------------------------------------------------------------
-- Determine wether to add a pin to the worldmap.
-------------------------------------------------------------------------------
function addon:DetermineToAdd(instanceType)
if instanceType == "none" and not self.db.profile.Pin_None then
return false
elseif instanceType == "party" and not self.db.profile.Pin_Party then
return false
elseif instanceType == "raid" and not self.db.profile.Pin_Raid then
return false
elseif instanceType == "pvp" and not self.db.profile.Pin_Pvp then
return false
elseif instanceType == "arena" and not self.db.profile.Pin_Arena then
return false
end
-- Pin can be added.
return true
end
-------------------------------------------------------------------------------
-- Add a pin to the worldmap.
-------------------------------------------------------------------------------
function addon:addWorldPin(x, y, id, level, index, Ptime)
local pin = worldmapPins[index]
if not pin then
pinCount = pinCount + 1
pin = CreateFrame("Button", "Deathcounter"..pinCount, WorldMapButton)
pin:SetPoint("CENTER", WorldMapButton, "CENTER")
local texture = pin:CreateTexture(nil, "OVERLAY")
pin.texture = texture
pin.texture:SetAllPoints(pin)
pin.texture:SetTexture("Interface\\ENCOUNTERJOURNAL\\UI-EJ-HeroicTextIcon")
pin.texture:SetVertexColor(self.db.profile.Pin_Color_R, self.db.profile.Pin_Color_G, self.db.profile.Pin_Color_B, self.db.profile.Pin_Alpha)
pin:SetParent(WorldMapButton)
pin:SetFrameStrata(worldmapStrata)
pin:SetFrameLevel(worldmapFrameLevel)
pin:SetHeight(8)
pin:SetWidth(12)
pin:EnableMouse(true)
pin:SetScript("OnEnter", Pin_OnEnter)
pin:SetScript("OnLeave", Pin_OnLeave)
pin.time = Ptime
pin:Show()
pin:ClearAllPoints()
pin:SetPoint("CENTER", WorldMapButton, "TOPLEFT", x *worldmapWidth, -y * worldmapHeight)
worldmapPins[index] = pin
end
return pin
end
-------------------------------------------------------------------------------
-- Clear all the pins.
-------------------------------------------------------------------------------
function addon:clearpins(t)
for k,v in pairs(t) do
v:Hide() -- Hide the pin.
t[k] = nil -- Remove the pin index from the table.
end
end