forked from TylerR909/Talented
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TalentedLDB.lua
105 lines (92 loc) · 2.94 KB
/
TalentedLDB.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
local addonName, addon = ...
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local dataobj = ldb:NewDataObject(addonName, {
type = "data source",
text = 'Talented'
})
function dataobj:RefreshText()
-- Sub-lvl 15 have no talents
if not C_SpecializationInfo.CanPlayerUseTalentUI() then return end;
local activePvEBuilds = Talented:GetActiveBuilds("PvE")
local buildNamesString = nil
-- If Build Names is Enabled
if Talented.db.global.config.ldb.build then
for _,build in ipairs(activePvEBuilds) do
if buildNamesString == nil then
buildNamesString = build.name
else
buildNamesString = buildNamesString..', '..build.name
end
end
end
-- If Title is Enabled
if Talented.db.global.config.ldb.title then
if buildNamesString then
buildNamesString = "Talented: "..buildNamesString
else
buildNamesString = "Talented"
end
end
self.text = buildNamesString
end
function dataobj:UpdateIcon()
self.icon = select(4, GetSpecializationInfo(GetSpecialization()))
end
function dataobj:Refresh()
dataobj:UpdateIcon()
dataobj:RefreshText()
end
function dataobj:OnClick(button)
if InCombatLockdown() then return end
local shift = IsShiftKeyDown()
local left = button == "LeftButton"
local right = button == "RightButton"
if shift and left then
ToggleTalentFrame(2)
return
end
-- Sub-level 15 chars can't use talents
if not C_SpecializationInfo.CanPlayerUseTalentUI() then return end;
if not shift and left then
Talented:InitPvEDropdown()
elseif not shift and right then
Talented:InitPvPDropdown()
end
end
function dataobj:OnTooltipShow()
-- Sub-level 15 chars can't use talents
if not C_SpecializationInfo.CanPlayerUseTalentUI() then return end;
self:AddLine("Talented")
local tt = function(l, r)
self:AddDoubleLine(l, r, 1,1,1, 0,1,0)
end
local addList = function(list, key)
for i,b in ipairs(list) do
if i == 1 then
tt(key, b.name)
else
tt(" ", b.name)
end
end
end
addList(Talented:GetActiveBuilds("PvE"), "PvE")
addList(Talented:GetActiveBuilds("PvP"), "PvP")
self:AddLine(" ")
tt("Left Click", "PvE Talents")
tt("Right Click", "PvP Talents")
tt("Shift + Left", "Open Talents")
end
function dataobj:Init()
local r = function() dataobj:Refresh() end
hooksecurefunc(Talented, "CommitBuild", r)
hooksecurefunc(Talented, "DeleteMatchingBuilds", r)
-- Event is firing multiple times on log-in before some data has
-- settled/initialized, causing errors. Delay registering for 1sec
-- to avoid
C_Timer.After(1, function()
Talented:RegisterEvent("PLAYER_TALENT_UPDATE", function()
C_Timer.After(0.25, r)
end)
end)
end
Talented.ldb = dataobj