-
Notifications
You must be signed in to change notification settings - Fork 0
/
LootSpec.lua
69 lines (63 loc) · 1.77 KB
/
LootSpec.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
local _, core = ...
local function onClick(self, specID)
SetLootSpecialization(specID)
end
local dropdown = core:CreateDropdown("Menu")
dropdown.initialize = function(self, level)
local specIndex = GetSpecialization()
if specIndex then
local specID, specName = GetSpecializationInfo(specIndex)
if specName then
local info = UIDropDownMenu_CreateInfo()
info.text = format(LOOT_SPECIALIZATION_DEFAULT, specName)
info.func = onClick
info.arg1 = 0
info.checked = GetLootSpecialization() == 0
self:AddButton(info)
end
end
for i = 1, GetNumSpecializations() do
local id, name, _, icon = GetSpecializationInfo(i)
local info = UIDropDownMenu_CreateInfo()
info.text = name
info.func = onClick
info.arg1 = id
info.checked = GetLootSpecialization() == id
self:AddButton(info)
end
end
local module = core:NewModule("LootSpec", {
type = "data source",
label = "LootSpec",
OnClick = function(self)
dropdown:ToggleMenu(nil, self)
end,
})
function module:OnInitialize()
self:RegisterEvent("PLAYER_LOGIN")
end
function module:PLAYER_LOGIN()
self:RegisterEvent("PLAYER_LOOT_SPEC_UPDATED", "Update")
self:RegisterEvent("PLAYER_TALENT_UPDATE", "Update")
self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED", "Update")
self:Update()
end
function module:Update()
local lootSpec = GetLootSpecialization()
local spec = GetSpecialization()
if lootSpec and spec then
if lootSpec == 0 then
lootSpec = GetSpecializationInfo(spec)
end
-- sometimes nil after loading screens
if lootSpec == nil then
return
end
local _, name, _, icon = GetSpecializationInfoByID(lootSpec)
self.text = name
self.icon = icon
else
self.text = NONE
self.icon = [[Interface\Icons\Ability_Marksmanship]]
end
end