View Single Post
05-10-19, 12:12 AM   #4
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Hi,
because it is always better to check the entire code and because it is a small addon I paste it here.

Lua Code:
  1. local ADDON = ...
  2. local playerName = UnitName("player")
  3. local realmName = GetRealmName()
  4.  
  5. local string_format = string.format
  6. GMKEYSTONE_NAMES = GMKEYSTONE_NAMES or {}
  7.  
  8. local short = {
  9.   [244] = "AD",
  10.   [245] = "Free",
  11.   [246] = "TD",
  12.   [247] = "MOTHER",
  13.   [248] = "WM",
  14.   [249] = "KR",
  15.   [250] = "ToS",
  16.   [251] = "Under",
  17.   [252] = "SotS",
  18.   [353] = "SoB",
  19. }
  20.  
  21.  -- Get a reference to the lib
  22.  local LibQTip = LibStub('LibQTip-1.0')
  23.  local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
  24. local dataobj = ldb:NewDataObject(ADDON, {
  25.     type = "data source",
  26.     icon = "Interface\\Addons\\"..ADDON.."\\icon.tga",
  27.     text = "none",
  28. })
  29.  
  30. local function UpdatePg()
  31.  
  32.     if UnitLevel("player") == GetMaxPlayerLevel() then             
  33.    
  34.         -- Refresh the current player in the array
  35.         GMKEYSTONE_NAMES[realmName.."-"..playerName] = {}
  36.         GMKEYSTONE_NAMES[realmName.."-"..playerName]["NAME"] = realmName.."-"..playerName
  37.         GMKEYSTONE_NAMES[realmName.."-"..playerName]["CLASS"] = select(2,UnitClass("player"))
  38.         GMKEYSTONE_NAMES[realmName.."-"..playerName]["WEEKLYKEY"] = "-"
  39.         GMKEYSTONE_NAMES[realmName.."-"..playerName]["MYKEY"] = "-"
  40.        
  41.         if C_MythicPlus.GetOwnedKeystoneChallengeMapID() then
  42.             -- you have a keystone
  43.             GMKEYSTONE_NAMES[realmName.."-"..playerName]["MYKEY"] = C_ChallengeMode.GetMapUIInfo(C_MythicPlus.GetOwnedKeystoneChallengeMapID()) .. " (" .. C_MythicPlus.GetOwnedKeystoneLevel() ..")"
  44.             dataobj.text = short[C_MythicPlus.GetOwnedKeystoneChallengeMapID()] .. ":" .. C_MythicPlus.GetOwnedKeystoneLevel()
  45.            
  46.             -- you have done a dungeon+
  47.             if C_MythicPlus.GetWeeklyChestRewardLevel() ~= 0 then
  48.                 GMKEYSTONE_NAMES[realmName.."-"..playerName]["WEEKLYKEY"], _ = C_MythicPlus.GetWeeklyChestRewardLevel()
  49.             end
  50.  
  51.         else -- you don't have a keystone
  52.  
  53.             -- but you have a reward ready
  54.             if C_MythicPlus.IsWeeklyRewardAvailable() then
  55.                 GMKEYSTONE_NAMES[realmName.."-"..playerName]["WEEKLYKEY"] = "*"
  56.                 dataobj.text = "chest ready"           
  57.             end
  58.             -- if you don't have a reward ready, MYKEY is already defined = "-" as default
  59.         end
  60.     end
  61. end
  62.  
  63.  
  64. local function anchor_OnEnter(self)
  65.  
  66.     -- build pg data
  67.     UpdatePg()
  68.    
  69.     -- Acquire a tooltip with 3 columns, respectively aligned to left, center and right
  70.     local tooltip = LibQTip:Acquire(ADDON, 3, "LEFT", "CENTER", "CENTER")
  71.     self.tooltip = tooltip
  72.  
  73.     -- Clear
  74.     tooltip:Clear()
  75.    
  76.     -- Use this instead of dataobj.OnLeave(frame) if you want to delay.
  77.     --
  78.     -- tooltip:SetAutoHideDelay(0.25, self)
  79.     -- function tooltip.OnRelease()
  80.     --  self.tooltip = nil
  81.     -- end
  82.  
  83.     local line, column = tooltip:AddHeader()
  84.     tooltip:SetCell(line, 1, "gmKeyStone")
  85.  
  86.     -- Add an empty line, using all columns
  87.     tooltip:AddLine()
  88.  
  89.  
  90.     local line, column = tooltip:AddLine('','Mythic key','Reward Lvl')
  91.     tooltip:SetLineTextColor(line,0,1,0)
  92.    
  93.     tooltip:AddSeparator()
  94.    
  95.     -- Show all Keys
  96.     for name in pairs(GMKEYSTONE_NAMES) do 
  97.         line, column = tooltip:AddLine()
  98.         tooltip:SetCell(line, 1, GMKEYSTONE_NAMES[name]["NAME"])
  99.         tooltip:SetCell(line, 2, GMKEYSTONE_NAMES[name]["MYKEY"])
  100.         tooltip:SetCell(line, 3, GMKEYSTONE_NAMES[name]["WEEKLYKEY"])      
  101.         local r = _G["RAID_CLASS_COLORS"][GMKEYSTONE_NAMES[name]["CLASS"]].r
  102.         local g = _G["RAID_CLASS_COLORS"][GMKEYSTONE_NAMES[name]["CLASS"]].g
  103.         local b = _G["RAID_CLASS_COLORS"][GMKEYSTONE_NAMES[name]["CLASS"]].b
  104.         tooltip:SetCellTextColor(line, 1, r, g, b)
  105.     end
  106.     tooltip:AddSeparator()
  107.     local line, column = tooltip:AddLine('','','')
  108.     local line, column = tooltip:AddLine('','','')
  109.     local line, column = tooltip:AddLine('Left Btn','','Open Group Finder')
  110.     tooltip:SetLineTextColor(line,0,1,0)
  111.     local line, column = tooltip:AddLine('Shift + Left Btn','','Reset PG')
  112.     tooltip:SetLineTextColor(line,0,1,0)
  113.     local line, column = tooltip:AddLine('Shift + Right Btn','','Reset data')
  114.     tooltip:SetLineTextColor(line,0,1,0)
  115.  
  116.     -- Use smart anchoring code to anchor the tooltip to our frame
  117.     tooltip:SmartAnchorTo(self)
  118.  
  119.     -- Show it, et voilą !
  120.     tooltip:Show()
  121.    
  122. end
  123.  
  124. local function anchor_OnLeave(self)
  125.    -- Release the tooltip
  126.    LibQTip:Release(self.tooltip)
  127.    self.tooltip = nil
  128. end
  129.  
  130. function dataobj.OnClick(frame, button)  
  131.    
  132.     if button == "RightButton" and IsShiftKeyDown() then
  133.         GMKEYSTONE_NAMES = {}
  134.         ReloadUI()
  135.     end
  136.     if button == "LeftButton" and IsShiftKeyDown() then
  137.         GMKEYSTONE_NAMES[realmName.."-"..playerName] = {}
  138.         ReloadUI()
  139.     end
  140.    
  141.     if button == "LeftButton" then
  142.         PVEFrame_ToggleFrame()
  143.     end
  144.    
  145. end
  146.  
  147. function dataobj.OnEnter(frame)
  148.     anchor_OnEnter(frame)
  149. end
  150.  
  151. function dataobj.OnLeave(frame)
  152.     anchor_OnLeave(frame)
  153. end
  154.  
  155. local frame = CreateFrame("Frame")
  156. frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  157. frame:SetScript("OnEvent", function(self, event, arg1)
  158.     UpdatePg()
  159. end)

Thanks all.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote