local ADDON = ...
local playerName = UnitName("player")
local realmName = GetRealmName()
local string_format = string.format
GMKEYSTONE_NAMES = GMKEYSTONE_NAMES or {}
local short = {
[244] = "AD",
[245] = "Free",
[246] = "TD",
[247] = "MOTHER",
[248] = "WM",
[249] = "KR",
[250] = "ToS",
[251] = "Under",
[252] = "SotS",
[353] = "SoB",
}
-- Get a reference to the lib
local LibQTip = LibStub('LibQTip-1.0')
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local dataobj = ldb:NewDataObject(ADDON, {
type = "data source",
icon = "Interface\\Addons\\"..ADDON.."\\icon.tga",
text = "none",
})
local function UpdatePg()
if UnitLevel("player") == GetMaxPlayerLevel() then
-- Refresh the current player in the array
GMKEYSTONE_NAMES[realmName.."-"..playerName] = {}
GMKEYSTONE_NAMES[realmName.."-"..playerName]["NAME"] = realmName.."-"..playerName
GMKEYSTONE_NAMES[realmName.."-"..playerName]["CLASS"] = select(2,UnitClass("player"))
GMKEYSTONE_NAMES[realmName.."-"..playerName]["WEEKLYKEY"] = "-"
GMKEYSTONE_NAMES[realmName.."-"..playerName]["MYKEY"] = "-"
if C_MythicPlus.GetOwnedKeystoneChallengeMapID() then
-- you have a keystone
GMKEYSTONE_NAMES[realmName.."-"..playerName]["MYKEY"] = C_ChallengeMode.GetMapUIInfo(C_MythicPlus.GetOwnedKeystoneChallengeMapID()) .. " (" .. C_MythicPlus.GetOwnedKeystoneLevel() ..")"
dataobj.text = short[C_MythicPlus.GetOwnedKeystoneChallengeMapID()] .. ":" .. C_MythicPlus.GetOwnedKeystoneLevel()
-- you have done a dungeon+
if C_MythicPlus.GetWeeklyChestRewardLevel() ~= 0 then
GMKEYSTONE_NAMES[realmName.."-"..playerName]["WEEKLYKEY"], _ = C_MythicPlus.GetWeeklyChestRewardLevel()
end
else -- you don't have a keystone
-- but you have a reward ready
if C_MythicPlus.IsWeeklyRewardAvailable() then
GMKEYSTONE_NAMES[realmName.."-"..playerName]["WEEKLYKEY"] = "*"
dataobj.text = "chest ready"
end
-- if you don't have a reward ready, MYKEY is already defined = "-" as default
end
end
end
local function anchor_OnEnter(self)
-- build pg data
UpdatePg()
-- Acquire a tooltip with 3 columns, respectively aligned to left, center and right
local tooltip = LibQTip:Acquire(ADDON, 3, "LEFT", "CENTER", "CENTER")
self.tooltip = tooltip
-- Clear
tooltip:Clear()
-- Use this instead of dataobj.OnLeave(frame) if you want to delay.
--
-- tooltip:SetAutoHideDelay(0.25, self)
-- function tooltip.OnRelease()
-- self.tooltip = nil
-- end
local line, column = tooltip:AddHeader()
tooltip:SetCell(line, 1, "gmKeyStone")
-- Add an empty line, using all columns
tooltip:AddLine()
local line, column = tooltip:AddLine('','Mythic key','Reward Lvl')
tooltip:SetLineTextColor(line,0,1,0)
tooltip:AddSeparator()
-- Show all Keys
for name in pairs(GMKEYSTONE_NAMES) do
line, column = tooltip:AddLine()
tooltip:SetCell(line, 1, GMKEYSTONE_NAMES[name]["NAME"])
tooltip:SetCell(line, 2, GMKEYSTONE_NAMES[name]["MYKEY"])
tooltip:SetCell(line, 3, GMKEYSTONE_NAMES[name]["WEEKLYKEY"])
local r = _G["RAID_CLASS_COLORS"][GMKEYSTONE_NAMES[name]["CLASS"]].r
local g = _G["RAID_CLASS_COLORS"][GMKEYSTONE_NAMES[name]["CLASS"]].g
local b = _G["RAID_CLASS_COLORS"][GMKEYSTONE_NAMES[name]["CLASS"]].b
tooltip:SetCellTextColor(line, 1, r, g, b)
end
tooltip:AddSeparator()
local line, column = tooltip:AddLine('','','')
local line, column = tooltip:AddLine('','','')
local line, column = tooltip:AddLine('Left Btn','','Open Group Finder')
tooltip:SetLineTextColor(line,0,1,0)
local line, column = tooltip:AddLine('Shift + Left Btn','','Reset PG')
tooltip:SetLineTextColor(line,0,1,0)
local line, column = tooltip:AddLine('Shift + Right Btn','','Reset data')
tooltip:SetLineTextColor(line,0,1,0)
-- Use smart anchoring code to anchor the tooltip to our frame
tooltip:SmartAnchorTo(self)
-- Show it, et voilą !
tooltip:Show()
end
local function anchor_OnLeave(self)
-- Release the tooltip
LibQTip:Release(self.tooltip)
self.tooltip = nil
end
function dataobj.OnClick(frame, button)
if button == "RightButton" and IsShiftKeyDown() then
GMKEYSTONE_NAMES = {}
ReloadUI()
end
if button == "LeftButton" and IsShiftKeyDown() then
GMKEYSTONE_NAMES[realmName.."-"..playerName] = {}
ReloadUI()
end
if button == "LeftButton" then
PVEFrame_ToggleFrame()
end
end
function dataobj.OnEnter(frame)
anchor_OnEnter(frame)
end
function dataobj.OnLeave(frame)
anchor_OnLeave(frame)
end
local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent", function(self, event, arg1)
UpdatePg()
end)