View Single Post
12-07-15, 12:22 PM   #1
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
Show tooltip on the worldmap.

Working on an addon and it displays pins (icons) on the worldmap.
Now I am working to add a tooltip to the pins.

It works when I dont have have the woldmap fully zoomed out.
The tooltips are visible,

But when I have the worldmap fully zoomed out, the toolip is still there but it is displayed underneath the map.
So its visible when I close the map but of course that's not what I want

Anyone have a clue?

Below is the part of the code that handles the placement of the pins and tooltips.

And on a side note, any advice on making my code more effiecient is always welcome.
Lua Code:
  1. --[[    *** Deathcounter ***
  2. Written by      : Yukyuk, EU-Moonglade
  3. --]]
  4.  
  5. --[[    *** Credits ***
  6. Credits go to   : The creators of Gathermate2, Nevcairiel and Xinhuan.
  7.                   If it wasn't for their clear way of coding the displaying
  8.                   of pins would have been a far greater challenge.
  9. --]]
  10.  
  11. -------------------------------------------------------------------------------
  12. --  From _Global to local.
  13. -------------------------------------------------------------------------------
  14. local _G = _G
  15.  
  16. local tinsert   = _G.table.insert
  17. local tremove   = _G.table.remove
  18. local tsort     = _G.table.sort
  19. local twipe     = _G.table.wipe
  20.  
  21. local pairs     = _G.pairs
  22. local ipairs    = _G.ipairs
  23.  
  24. -------------------------------------------------------------------------------
  25. --  AddOn namespace.
  26. -------------------------------------------------------------------------------
  27. local FOLDER_NAME, private = ...
  28. local addon = LibStub("AceAddon-3.0"):GetAddon(private.addon_name)
  29.  
  30. local L         = LibStub("AceLocale-3.0"):GetLocale("Deathcounter")
  31. local LibQTip   = LibStub:GetLibrary("LibQTip-1.0")
  32.  
  33. local worldmapWidth, worldmapHeight
  34. local worldmapStrata, worldmapFrameLevel
  35.  
  36. -- Current worldmap pin set
  37. local worldmapPins = {}
  38.  
  39. -- total number of pins we have created
  40. local pinCount = 0
  41.  
  42. -- The death information fields we store
  43. local Field = {
  44.     Time = 1,
  45.     Zone = 2,
  46.     SubZone = 3,
  47.     Xpos = 4,  
  48.     Ypos = 5,
  49.     Areaid = 6,
  50.     Level = 7,
  51.     isMicro = 8,
  52.     Index = 9,
  53.     isInstance = 10,   
  54.     instanceType = 11  
  55. }
  56.  
  57.  
  58. -------------------------------------------------------------------------------
  59. --  Update the Pin tooltip
  60. -------------------------------------------------------------------------------
  61. local function Pin_OnEnter(self)
  62.     local tooltip = LibQTip:Acquire("DeathcounterPinT", 1, "LEFT")
  63.     tooltip:SmartAnchorTo(self)
  64.     tooltip:SetAutoHideDelay(0.1, self)
  65.  
  66.     if not LibQTip:IsAcquired("DeathcounterPinT") then
  67.         return
  68.     end
  69.    
  70.     --  Add tooltip lines
  71.     tooltip:AddLine("This is a test")  
  72.    
  73.     -- Show the tooltip.
  74.     tooltip:Show() 
  75. end
  76.  
  77.  
  78. local function Pin_OnLeave(self)
  79.     --  Release the tooltip
  80.     LibQTip:Release(self.tooltip)
  81.     self.tooltip = nil
  82. end
  83.  
  84.  
  85. -------------------------------------------------------------------------------
  86. --  Update the world map with pins.
  87. -------------------------------------------------------------------------------
  88. function addon:UpdateWorldMap()
  89.     addon:Debug("UpdateWorldMap")
  90.     --  If the world map is not visible, stop.
  91.         if not WorldMapFrame:IsVisible() then
  92.         return
  93.     end
  94.    
  95.     --  Clear the worldmap pins.   
  96.     addon:clearpins(worldmapPins)      
  97.  
  98.     --  Get map info.
  99.     local zoneid = GetCurrentMapAreaID()
  100.     local mapLevel = GetCurrentMapDungeonLevel()
  101.     local _, _, _, isMicroDungeon, _ = GetMapInfo()
  102.  
  103.     --  Player is not viewing a zone map of a continent
  104.     if not zoneid or zoneid == -1 or isMicroDungeon then
  105.         addon:clearpins(worldmapPins)
  106.         return
  107.     end    
  108.    
  109.     --  Get worldmap data.
  110.     worldmapWidth       = WorldMapButton:GetWidth()
  111.     worldmapHeight      = WorldMapButton:GetHeight()
  112.     worldmapStrata      = WorldMapButton:GetFrameStrata()
  113.     worldmapFrameLevel  = WorldMapButton:GetFrameLevel() + 5
  114.    
  115.     --  Add the relevant pins to the worldmap. 
  116.     for i = 1, #addon.db.realm[private.PLAYER_NAME].deaths do
  117.         local info = addon.db.realm[private.PLAYER_NAME].deaths[i]
  118.         if addon:DetermineToAdd(info[Field.instanceType]) then
  119.             if zoneid == info[Field.Areaid] then
  120.                 if mapLevel == info[Field.Level] then
  121.                     local Xposition = addon:round(info[Field.Xpos], 2)
  122.                     local Yposition = addon:round(info[Field.Ypos], 2)     
  123.                     addon:addWorldPin(Xposition,Yposition,info[Field.Areaid],info[Field.Level],info[Field.Index],info[Field.Time])
  124.                 end
  125.             end
  126.         end
  127.     end
  128. end
  129.  
  130.  
  131. -------------------------------------------------------------------------------
  132. --  Determine wether to add a pin to the worldmap.
  133. -------------------------------------------------------------------------------
  134. function addon:DetermineToAdd(instanceType)
  135.     if instanceType == "none" and not self.db.profile.Pin_None then
  136.         return false
  137.     elseif instanceType == "party" and not self.db.profile.Pin_Party then
  138.         return false
  139.     elseif instanceType == "raid" and not self.db.profile.Pin_Raid then
  140.         return false
  141.     elseif instanceType == "pvp" and not self.db.profile.Pin_Pvp then
  142.         return false
  143.     elseif instanceType == "arena" and not self.db.profile.Pin_Arena then
  144.         return false       
  145.     end
  146.    
  147.     --  Pin can be added.
  148.     return true
  149. end
  150.  
  151.  
  152. -------------------------------------------------------------------------------
  153. --  Add a pin to the worldmap.
  154. -------------------------------------------------------------------------------
  155. function addon:addWorldPin(x, y, id, level, index, Ptime)
  156.     local pin = worldmapPins[index]
  157.    
  158.     if not pin then
  159.         pinCount = pinCount + 1
  160.         pin = CreateFrame("Button", "Deathcounter"..pinCount, WorldMapButton)
  161.         pin:SetPoint("CENTER", WorldMapButton, "CENTER")
  162.        
  163.         local texture = pin:CreateTexture(nil, "OVERLAY")
  164.         pin.texture = texture
  165.         pin.texture:SetAllPoints(pin)
  166.         pin.texture:SetTexture("Interface\\ENCOUNTERJOURNAL\\UI-EJ-HeroicTextIcon")
  167.         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)
  168.        
  169.         pin:SetParent(WorldMapButton)
  170.         pin:SetFrameStrata(worldmapStrata)
  171.         pin:SetFrameLevel(worldmapFrameLevel)
  172.         pin:SetHeight(8)
  173.         pin:SetWidth(12)
  174.         pin:EnableMouse(true)
  175.         pin:SetScript("OnEnter", Pin_OnEnter)
  176.         pin:SetScript("OnLeave", Pin_OnLeave)  
  177.        
  178.         pin.time = Ptime       
  179.         pin:Show()
  180.        
  181.         pin:ClearAllPoints()
  182.         pin:SetPoint("CENTER", WorldMapButton, "TOPLEFT", x *worldmapWidth, -y * worldmapHeight)
  183.  
  184.         worldmapPins[index] = pin
  185.     end
  186.    
  187.     return pin
  188. end
  189.  
  190.  
  191. -------------------------------------------------------------------------------
  192. --  Clear all the pins.
  193. -------------------------------------------------------------------------------
  194. function addon:clearpins(t)
  195.     for k,v in pairs(t) do
  196.         v:Hide()        --  Hide the pin.
  197.         t[k] = nil      --  Remove the pin index from the table.
  198.     end
  199. end
__________________
Better to fail then never have tried at all.
  Reply With Quote