-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoptions.lua
214 lines (205 loc) · 7.29 KB
/
options.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
local GetCurrentBuild, StaticPopup
TalentsaverFu = AceLibrary("AceAddon-2.0"):new("AceConsole-2.0", "AceDB-2.0", "FuBarPlugin-2.0");
local Tablet = AceLibrary("Tablet-2.0");
TalentsaverFu:RegisterDB("TalentsaverFuDB");
TalentsaverFu.hasIcon = "Interface\\AddOns\\Talentsaver\\icons\\default"
TalentsaverFu.clickableTooltip = true
function TalentsaverFu:OnTextUpdate()
if (self:IsTextShown()) then
self:ShowText();
local name, icon = GetCurrentTalentSpec()
self:SetIcon(icon)
if GetCurrentBuild() then
self:SetText("|cff3be7edTalentsaver|r ("..GetCurrentBuild()..")");
else
self:SetText("|cff3be7edTalentsaver|r ("..name..")");
end
else
self:HideText();
end
end
function TalentsaverFu:OnTooltipUpdate()
Tablet:SetHint("You can delete builds by using |cffeda55f/ts delete <name>|r")
-- new build
cat = Tablet:AddCategory(
'columns', 1,
'child_textR', 1,
'child_textG', 1,
'child_textB', 1
)
cat:AddLine()
cat:AddLine('text', "|cffeda55f< save current Build >|r", 'func', function() StaticPopup() end, 'justify', "CENTER")
-- saved builds
cat = Tablet:AddCategory(
'columns', 3,
'child_textR', 1,
'child_textG', 1,
'child_textB', 1
)
cat:AddLine()
cat:AddLine()
if table.getn(TALENTS_SAVED["LIST"]) == 0 then
cat:AddLine('text2', "NO SAVED BUILDS FOUND")
else
if GetUnspentTalentPoints() == 0 or TALENTSAVER_IsLoading() then
for b=1, table.getn(TALENTS_SAVED["LIST"]) do
if TALENTS_SAVED["LIST"][b] == "" then return end
local name = TALENTS_SAVED["LIST"][b];
local buildinfo = TALENTS_SAVED["INFO"][name][1].."/"..TALENTS_SAVED["INFO"][name][2].."/"..TALENTS_SAVED["INFO"][name][3];
if name == GetCurrentBuild() then
cat:AddLine(
'text', "|cff3be7ed"..b..".|r",
'text2', "|cff3be7ed"..buildinfo.."|r",
'text3', "|cff3be7ed"..name.."|r"
)
else
cat:AddLine(
'text', b..".",
'text2', buildinfo,
'text3', name,
'text2R', 1,'text2G', 1,'text2B', 1,
'text3R', 1,'text3G', 1,'text3B', 1
)
end
end
else -- there are unspent points
for b=1, table.getn(TALENTS_SAVED["LIST"]) do
if TALENTS_SAVED["LIST"][b] == "" then return end
local name = TALENTS_SAVED["LIST"][b];
local buildinfo = TALENTS_SAVED["INFO"][name][1].."/"..TALENTS_SAVED["INFO"][name][2].."/"..TALENTS_SAVED["INFO"][name][3];
cat:AddLine(
'text', b..".",
'text2', buildinfo,
'text3', name,
'text2R', 1,'text2G', 1,'text2B', 1,
'text3R', 1,'text3G', 1,'text3B', 1,
'func', function() TALENTSAVER_LOAD(name) end
)
end
end
end
end
function StaticPopup()
local first, second, third = GetTalentPointsSpent()
local spec = GetCurrentTalentSpec()
StaticPopupDialogs["SAVE_BUILD"] = {
text = "|cff3be7edName|r of the Build: ("..first.."/"..second.."/"..third..") ",
button1 = "Save",
button2 = "Cancel",
hasEditBox = 1,
OnShow = function()
StaticPopup1EditBox:SetText(spec)
end,
OnAccept = function()
TALENTSAVER_SAVE(StaticPopup1EditBox:GetText())
end,
OnHide = function() end,
OnCancel = function() end,
EditBoxOnEscapePressed = function() this:GetParent():Hide(); end,
timeout = 0,
whileDead = 1,
hideOnEscape = 1
};
StaticPopup_Show("SAVE_BUILD")
end
function TalentsaverFu:OnClick()
end
-- ====== API ====== --
function GetCurrentBuild()
local build
if TALENTS_SAVED.CURRENTBUILD ~= "" then
local first, second, third = GetTalentPointsSpent()
if first ~= TALENTS_SAVED["INFO"][TALENTS_SAVED.CURRENTBUILD][1]
or second ~= TALENTS_SAVED["INFO"][TALENTS_SAVED.CURRENTBUILD][2]
or third ~= TALENTS_SAVED["INFO"][TALENTS_SAVED.CURRENTBUILD][3] then
-- seems like the player has a build which was not loaded via the addon
build = GetCurrentTalentSpec()
else
build = TALENTS_SAVED.CURRENTBUILD
end
else
-- if no build is selected display the current spec
build = GetCurrentTalentSpec()
end
return build
end
function GetCurrentTalentSpec()
local name = ""
local icon = ""
local points = {}
for i=1,3 do
local _, _, spent = GetTalentTabInfo(i)
points[i] = spent;
end
local specInit = {
["Warrior"] = {"Arms","Fury","Protection"},
["Paladin"] = {"Holy","Protection","Retribution"},
["Rogue"] = {"Assassination","Combat","Subtlety"},
["Druid"] = {"Balance","Feral","Restoration"},
["Shaman"] = {"Elemental","Enhancement","Restoration"},
["Priest"] = {"Disci","Holy","Shadow"},
["Warlock"] = {"Affliction","Demonology","Destruction"},
["Mage"] = {"Arcane","Fire","Frost"},
["Hunter"] = {"Beastmaster","Marksmanship","Survival"},
}
if points[1] == 0 and points[2] == 0 and points[3] == 0 then
return "unskilled", "Interface\\AddOns\\Talentsaver\\icons\\default"
elseif points[1] >= points[2] and points[1] >= points[3] then
name = specInit[UnitClass('player')][1]
elseif points[2] >= points[1] and points[2] >= points[3] then
name = specInit[UnitClass('player')][2]
elseif points[3] >= points[1] and points[3] >= points[2] then
name = specInit[UnitClass('player')][3]
end
icon = GetTalentSpecIcon(UnitClass('player'),name)
return name, icon
end
function GetTalentSpecIcon(class,spec)
local iconpath = "Interface\\AddOns\\Talentsaver\\icons\\";
if class == "Shaman" then
if spec == "Restoration" then
return iconpath.."restoShamy";
else
return iconpath..spec;
end
elseif class == "Druid" then
if spec == "Restoration" then
return iconpath.."restoDruid";
else
return iconpath..spec;
end
elseif class == "Paladin" then
if spec == "Protection" then
return iconpath.."protPally";
else
return iconpath..spec;
end
elseif class == "Hunter" then
if spec == "Marksmanship" then
return iconpath.."default";
else
return iconpath..spec;
end
elseif class == "Warrior" then
if spec == "Protection" then
return iconpath.."protWarr";
else
return iconpath..spec;
end
else
return iconpath..spec;
end
end
function GetTalentPointsSpent()
local points = {}
for i=1,3 do
local _, _, spent = GetTalentTabInfo(i)
points[i] = spent;
end
return points[1], points[2], points[3]
end
function GetUnspentTalentPoints()
local first, second, third = GetTalentPointsSpent()
local unspent = (UnitLevel("player")-9) - (first + second + third)
return unspent
end