vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- [ constants ] ---------------------------------------------
2 local KALENTED_TALENT_OFFSET_X = 16;
3 local KALENTED_TALENT_OFFSET_Y = 20;
4  
5  
6 -- [ variables ] ---------------------------------------------
7 -- Saved Variables
8 XKalented_TabData = {};
9  
10 -- Local Variables
11 local fnTalentFrame_Update = nil;
12 local iTalentPoints = 0;
13 local iPointsSpent = 0;
14 local strName = "";
15  
16  
17 -- [ XML Functions ] -----------------------------------------
18 -- OnLoad
19 function Kalented_OnLoad()
20 -- [ register slash commands ]
21 SlashCmdList["KALENTED"] = Kalented_SlashCommand;
22 SLASH_KALENTED1 = "/kalented";
23  
24 -- Set Tab Texture and Username
25 Kalented_Texture:SetTexture("Interface\\AddOns\\Kalented\\images\\calculator-" .. GetLocale());
26 strName = UnitName("player");
27  
28 -- Load AddOn
29 LoadAddOn("Blizzard_TalentUI");
30  
31 -- Register Events
32 this:RegisterEvent("VARIABLES_LOADED");
33 end
34  
35 -- OnEvents
36 function Kalented_OnEvent(event, arg1)
37 if ( event == "VARIABLES_LOADED" ) then
38 -- If First Time, create tables
39 if ( not XKalented_TabData[strName] ) then
40 Kalented_SlashCommand("clear");
41 end
42  
43 -- Subclass Talent Window
44 fnTalentFrame_Update = TalentFrame_Update;
45 TalentFrame_Update = NewTalentFrame_Update;
46  
47 -- Show Success Load Message
48 Kalented_Debug_Message("Loaded! More Info: /kalented help");
49 end
50 end
51  
52 -- OnUnload
53 function Kalented_OnUnload()
54 if ( fnTalentFrame_Update ) then
55 TalentFrame_Update = fnTalentFrame_Update;
56 fnTalentFrame_Update = nil;
57 end
58 end
59  
60  
61 -- [ WoW Subclassing ] ---------------------------------------
62 function NewTalentFrame_Update()
63 fnTalentFrame_Update();
64 Kalented_Update();
65 end
66  
67  
68 -- [ WoW commands ] ------------------------------------------
69 function Kalented_SlashCommand(msg)
70 local _, _, cmd, arg1 = string.find(msg, "%s*(%S*)%s*(.*)");
71 cmd = string.lower(cmd);
72  
73 -- List of Commands
74 if ( cmd == "help" ) then
75 Kalented_Debug_Message("Created by Kaluriel <kaluriel@gmail.com>");
76 Kalented_Debug_Message("Translations by Filougarou, J.W and sy2451.");
77 Kalented_Debug_Message("Configure: /kalented config");
78 Kalented_Debug_Message("Join Channel: /kalented join");
79 Kalented_Debug_Message("Leave Channel: /kalented leave");
80 Kalented_Debug_Message("Clear db: /kalented clear");
81  
82 -- Configure Kalented
83 elseif ( cmd == "config" ) then
84  
85 -- Join Kalented Channel
86 elseif ( cmd == "join" ) then
87  
88 -- Leave Kalented Channel
89 elseif ( cmd == "leave" ) then
90  
91 -- Clear Database
92 elseif ( cmd == "clear" ) then
93 XKalented_TabData = {};
94 Kalented_ResetPoints_OnClick(false);
95 Kalented_Debug_Message("Database cleared.");
96  
97 -- No Command
98 else
99 Kalented_Debug_Message("Invalid command entered.");
100 end
101 end
102  
103  
104 -- [ WoW events ] --------------------------------------------
105 -- Reset Points
106 function Kalented_Reset_OnClick(bTransfer)
107 XKalented_TabData[strName] = {};
108  
109 for i=1, MAX_TALENT_TABS, 1 do
110 XKalented_TabData[strName][i] = {};
111 for j=1, MAX_NUM_TALENTS, 1 do
112 if ( bTransfer ) then
113 local _, _, _, _, rank, _, _, _ = GetTalentInfo(i, j);
114 XKalented_TabData[strName][i][j] = rank;
115 else
116 XKalented_TabData[strName][i][j] = 0;
117 end
118 end
119 end
120  
121 Kalented_Update();
122 end
123  
124 -- Learn Talent
125 function Kalented_Button_OnClick(arg1)
126 if ( arg1 == "LeftButton" ) then
127 if ( Kalented_CanIncrease(this:GetID()) ) then
128 XKalented_TabData[strName][PanelTemplates_GetSelectedTab(TalentFrame)][this:GetID()] = XKalented_TabData[strName][PanelTemplates_GetSelectedTab(TalentFrame)][this:GetID()] + 1;
129 end
130 elseif ( arg1 == "RightButton" ) then
131 if ( Kalented_CanDecrease(this:GetID()) ) then
132 XKalented_TabData[strName][PanelTemplates_GetSelectedTab(TalentFrame)][this:GetID()] = XKalented_TabData[strName][PanelTemplates_GetSelectedTab(TalentFrame)][this:GetID()] - 1;
133 end
134 end
135 Kalented_Update();
136  
137 if ( GameTooltip:IsOwned(this) ) then
138 Kalented_SetTalentTip();
139 end
140 end
141  
142 -- Update Talents
143 function Kalented_Update()
144 -- Calculate Remaining Points and display
145 iTalentPoints = 51;
146 iPointsSpent = 0;
147  
148 for i=1, MAX_TALENT_TABS, 1 do
149 for j=1, MAX_NUM_TALENTS, 1 do
150 if ( PanelTemplates_GetSelectedTab(TalentFrame) == i ) then
151 iPointsSpent = iPointsSpent + XKalented_TabData[strName][i][j];
152 end
153 iTalentPoints = iTalentPoints - XKalented_TabData[strName][i][j];
154 end
155 end
156 Kalented_Text_Points:SetText(KALENTED_TEXT_POINTS .. " |cffffffff" .. iTalentPoints);
157 Kalented_Text_Spent:SetText(KALENTED_TEXT_SPENT .. " |cffffffff" .. iPointsSpent);
158  
159  
160 -- Setup Background Image
161 local _, _, _, strFilename = GetTalentTabInfo(PanelTemplates_GetSelectedTab(TalentFrame));
162 local base = "Interface\\TalentFrame\\";
163 if ( GetTalentTabInfo(PanelTemplates_GetSelectedTab(TalentFrame)) ) then
164 base = base .. strFilename;
165 else
166 base = base .. "MageFire";
167 end
168  
169 Kalented_Background_TopLeft:SetTexture(base .. "-TopLeft");
170 Kalented_Background_TopRight:SetTexture(base .. "-TopRight");
171 Kalented_Background_BottomLeft:SetTexture(base .. "-BottomLeft");
172 Kalented_Background_BottomRight:SetTexture(base .. "-BottomRight");
173  
174  
175 -- Setup Talent Buttons
176 for i=1, MAX_NUM_TALENTS, 1 do
177 pButton = getglobal("Kalented_Scroll_Talent" .. i);
178  
179 if ( i <= GetNumTalents(PanelTemplates_GetSelectedTab(TalentFrame)) ) then
180 -- Get Talent Info
181 local _, iconTexture, tier, column, _, maxRank, _, _ = GetTalentInfo(PanelTemplates_GetSelectedTab(TalentFrame), i);
182 local rank = XKalented_TabData[strName][PanelTemplates_GetSelectedTab(TalentFrame)][i];
183 local bForceDesaturated, bTierUnlocked = false, false;
184  
185 -- Set Rank and Position Button
186 getglobal("Kalented_Scroll_Talent" .. i .. "Rank"):SetText(rank);
187 pButton:SetPoint("TOPLEFT", pButton:GetParent():GetName(), "TOPLEFT", 63 * (column - 1) + KALENTED_TALENT_OFFSET_X, -63 * (tier - 1) - KALENTED_TALENT_OFFSET_Y);
188  
189  
190 -- If no talent points left and rank 0, grey out button
191 if ( ( iTalentPoints + rank ) == 0 ) then
192 bForceDesaturated = true;
193 end
194  
195 -- If 5+ points were spent in the previous tier, highlight button
196 if ( iPointsSpent >= (tier - 1) * 5 ) then
197 bTierUnlocked = true;
198 end
199 SetItemButtonTexture(pButton, iconTexture);
200  
201  
202 -- Check if Talent meets prereqs
203 if ( Kalented_SetPrereqs(tier, column, bForceDesaturated, bTierUnlocked, GetTalentPrereqs(PanelTemplates_GetSelectedTab(TalentFrame), i)) ) then
204 if ( rank < maxRank ) then
205 -- Rank is green
206 getglobal("Kalented_Scroll_Talent" .. i .. "Slot"):SetVertexColor(0.1, 1.0, 0.1);
207 getglobal("Kalented_Scroll_Talent" .. i .. "Rank"):SetTextColor(GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b);
208 else
209 -- Rank if yellow (max)
210 getglobal("Kalented_Scroll_Talent" .. i .. "Slot"):SetVertexColor(1.0, 0.82, 0);
211 getglobal("Kalented_Scroll_Talent" .. i .. "Rank"):SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
212 end
213 getglobal("Kalented_Scroll_Talent" .. i .. "RankBorder"):Show();
214 getglobal("Kalented_Scroll_Talent" .. i .. "Rank"):Show();
215  
216 SetItemButtonDesaturated(pButton, nil);
217 else
218 if ( rank == 0 ) then
219 -- Talent not available
220 getglobal("Kalented_Scroll_Talent" .. i .. "RankBorder"):Hide();
221 getglobal("Kalented_Scroll_Talent" .. i .. "Rank"):Hide();
222 else
223 -- Rank is grey
224 getglobal("Kalented_Scroll_Talent" .. i .. "RankBorder"):SetVertexColor(0.5, 0.5, 0.5);
225 getglobal("Kalented_Scroll_Talent" .. i .. "Rank"):SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b);
226 end
227 getglobal("Kalented_Scroll_Talent" .. i .. "Slot"):SetVertexColor(0.5, 0.5, 0.5);
228  
229 SetItemButtonDesaturated(pButton, 1, 0.65, 0.65, 0.65);
230 end
231  
232 pButton:Show();
233  
234 else
235 -- Button is unused so hide
236 pButton:Hide();
237 end
238 end
239  
240  
241 -- Draw the prerq branches and Variable that decides whether or not to ignore drawing pieces
242 local ignoreUp;
243  
244 TalentFrame_ResetBranchTextureCount();
245 TalentFrame_ResetArrowTextureCount();
246  
247 for i=1, MAX_NUM_TALENT_TIERS do
248 for j=1, NUM_TALENT_COLUMNS do
249 local node = TALENT_BRANCH_ARRAY[i][j];
250  
251 -- Setup offsets
252 local xOffset = 63 * (j - 1) + KALENTED_TALENT_OFFSET_X + 2;
253 local yOffset = -63 * (i - 1) - KALENTED_TALENT_OFFSET_Y - 2;
254  
255 if ( node.id ) then
256 -- Has talent
257 if ( node.up ~= 0 ) then
258 if ( not ignoreUp ) then
259 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["up"][node.up], xOffset, yOffset + TALENT_BUTTON_SIZE);
260 else
261 ignoreUp = nil;
262 end
263 end
264  
265 if ( node.down ~= 0 ) then
266 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["down"][node.down], xOffset, yOffset - TALENT_BUTTON_SIZE + 1);
267 end
268  
269 if ( node.left ~= 0 ) then
270 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["left"][node.left], xOffset - TALENT_BUTTON_SIZE, yOffset);
271 end
272  
273 if ( node.right ~= 0 ) then
274 -- See if any connecting branches are gray and if so color them gray
275 local tempNode = TALENT_BRANCH_ARRAY[i][j+1];
276 if ( tempNode.left ~= 0 and tempNode.down < 0 ) then
277 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["right"][tempNode.down], xOffset + TALENT_BUTTON_SIZE, yOffset);
278 else
279 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["right"][node.right], xOffset + TALENT_BUTTON_SIZE + 1, yOffset);
280 end
281 end
282  
283 -- Draw arrows
284 if ( node.rightArrow ~= 0 ) then
285 Kalented_SetArrowTexture(TALENT_ARROW_TEXTURECOORDS["right"][node.rightArrow], xOffset + TALENT_BUTTON_SIZE/2 + 5, yOffset);
286 end
287  
288 if ( node.leftArrow ~= 0 ) then
289 Kalented_SetArrowTexture(TALENT_ARROW_TEXTURECOORDS["left"][node.leftArrow], xOffset - TALENT_BUTTON_SIZE/2 - 5, yOffset);
290 end
291  
292 if ( node.topArrow ~= 0 ) then
293 Kalented_SetArrowTexture(TALENT_ARROW_TEXTURECOORDS["top"][node.topArrow], xOffset, yOffset + TALENT_BUTTON_SIZE/2 + 5);
294 end
295 else
296 -- Doesn't have a talent
297 if ( node.up ~= 0 and node.left ~= 0 and node.right ~= 0 ) then
298 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["tup"][node.up], xOffset , yOffset);
299 elseif ( node.down ~= 0 and node.left ~= 0 and node.right ~= 0 ) then
300 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["tdown"][node.down], xOffset , yOffset);
301 elseif ( node.left ~= 0 and node.down ~= 0 ) then
302 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["topright"][node.left], xOffset , yOffset);
303 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["down"][node.down], xOffset , yOffset - 32);
304 elseif ( node.left ~= 0 and node.up ~= 0 ) then
305 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["bottomright"][node.left], xOffset , yOffset);
306 elseif ( node.left ~= 0 and node.right ~= 0 ) then
307 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["right"][node.right], xOffset + TALENT_BUTTON_SIZE, yOffset);
308 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["left"][node.left], xOffset + 1, yOffset);
309 elseif ( node.right ~= 0 and node.down ~= 0 ) then
310 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["topleft"][node.right], xOffset , yOffset);
311 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["down"][node.down], xOffset , yOffset - 32);
312 elseif ( node.right ~= 0 and node.up ~= 0 ) then
313 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["bottomleft"][node.right], xOffset , yOffset);
314 elseif ( node.up ~= 0 and node.down ~= 0 ) then
315 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["up"][node.up], xOffset , yOffset);
316 Kalented_SetBranchTexture(TALENT_BRANCH_TEXTURECOORDS["down"][node.down], xOffset , yOffset - 32);
317 ignoreUp = 1;
318 end
319 end
320 end
321  
322 Kalented_Scroll_Frame:UpdateScrollChildRect();
323 end
324  
325 -- Hide any unused branch textures
326 for i=TalentFrame_GetBranchTextureCount(), MAX_NUM_BRANCH_TEXTURES, 1 do
327 getglobal("Kalented_Scroll_Branch" .. i):Hide();
328 end
329  
330 -- Hide and unused arrowl textures
331 for i=TalentFrame_GetArrowTextureCount(), MAX_NUM_ARROW_TEXTURES, 1 do
332 getglobal("Kalented_Scroll_Arrow" .. i):Hide();
333 end
334 end
335  
336  
337 -- [ WoW functions ] -----------------------------------------
338 function Kalented_SetPrereqs(iTier, iColumn, bForceDesaturated, bTierUnlocked, ...)
339 local bLearnable, bPrereqsMet = false, false;
340  
341 if ( bTierUnlocked and not bForceDesaturated ) then
342 bPrereqsMet = true;
343 end
344  
345 for i=1, arg.n, 3 do
346 local x, y = arg[i + 1], arg[i];
347  
348 bLearnable = false;
349 for j=1, MAX_NUM_TALENTS, 1 do
350 local _, _, tier, column, _, maxRank, _, _ = GetTalentInfo(PanelTemplates_GetSelectedTab(TalentFrame), j);
351 if ( column == x and tier == y ) then
352 if ( XKalented_TabData[strName][PanelTemplates_GetSelectedTab(TalentFrame)][j] == maxRank ) then
353 bLearnable = true;
354 end
355 end
356 end
357  
358 if ( not bLearnable or bForceDesaturated ) then
359 bPrereqsMet = false;
360 end
361  
362 TalentFrame_DrawLines(iTier, iColumn, y, x, bPrereqsMet);
363 end
364  
365 return bPrereqsMet;
366 end
367  
368 function Kalented_SetTalentTip()
369 local _, _, _, _, _, maxRank, _, _ = GetTalentInfo(PanelTemplates_GetSelectedTab(TalentFrame), this:GetID());
370 GameTooltip:SetTalent(PanelTemplates_GetSelectedTab(TalentFrame), this:GetID());
371 GameTooltipTextLeft2:SetText("Rank " .. XKalented_TabData[strName][PanelTemplates_GetSelectedTab(TalentFrame)][this:GetID()] .. "/" .. maxRank);
372 end
373  
374 function Kalented_CanIncrease(id)
375 local _, _, tier, column, _, maxRank, _, _ = GetTalentInfo(PanelTemplates_GetSelectedTab(TalentFrame), id);
376  
377 -- Check there is enough talents, and the talent isn't at max, and there is enough points to active this field
378 if( iTalentPoints > 0 and XKalented_TabData[strName][PanelTemplates_GetSelectedTab(TalentFrame)][id] < maxRank and iPointsSpent >= (tier - 1) * 5 ) then
379 -- If there are prereqs, check they are filled
380 if ( GetTalentPrereqs(PanelTemplates_GetSelectedTab(TalentFrame), id) ) then
381 local arg = {GetTalentPrereqs(PanelTemplates_GetSelectedTab(TalentFrame), id)};
382 for i=1, table.getn(arg), 3 do
383 for j=1, MAX_NUM_TALENTS, 1 do
384 local _, _, pTier, pColumn, _, pMaxRank, _, _ = GetTalentInfo(PanelTemplates_GetSelectedTab(TalentFrame), j);
385 if ( pColumn == arg[i + 1] and pTier == arg[i] ) then
386 if ( XKalented_TabData[strName][PanelTemplates_GetSelectedTab(TalentFrame)][j] == pMaxRank ) then
387 return true;
388 else
389 return false;
390 end
391 end
392 end
393 end
394  
395 return false;
396 end
397  
398 return true;
399 end
400  
401 return false;
402 end
403  
404 function Kalented_CanDecrease(id)
405 -- Check to see if it has 0 points left in talent
406 if ( XKalented_TabData[strName][PanelTemplates_GetSelectedTab(TalentFrame)][id] == 0 ) then
407 return false;
408 end
409  
410 -- Check to see if there are any talents in the next tier
411 local _, _, tier, _, _, _, _, _ = GetTalentInfo(PanelTemplates_GetSelectedTab(TalentFrame), id);
412 for i=id, GetNumTalents(PanelTemplates_GetSelectedTab(TalentFrame)), 1 do
413 local _, _, pTier, _, _, _, _, _ = GetTalentInfo(PanelTemplates_GetSelectedTab(TalentFrame), i);
414 if ( pTier > tier and XKalented_TabData[strName][PanelTemplates_GetSelectedTab(TalentFrame)][i] > 0 ) then
415 return false;
416 end
417 end
418  
419 -- Check for Prereqs
420 local _, _, pTier, pColumn, _, pMaxRank, _, _ = GetTalentInfo(PanelTemplates_GetSelectedTab(TalentFrame), id);
421 if ( GetTalentPrereqs(PanelTemplates_GetSelectedTab(TalentFrame), id + 1) and XKalented_TabData[strName][PanelTemplates_GetSelectedTab(TalentFrame)][id] == pMaxRank ) then
422 local arg = {GetTalentPrereqs(PanelTemplates_GetSelectedTab(TalentFrame), id + 1)};
423  
424 for i=1, table.getn(arg), 3 do
425 if ( pColumn == arg[i + 1] and pTier == arg[i] ) then
426 if ( XKalented_TabData[strName][PanelTemplates_GetSelectedTab(TalentFrame)][id + 1] > 0 ) then
427 return false;
428 end
429 end
430 end
431 end
432  
433 return true;
434 end
435  
436 function Kalented_SetArrowTexture(texCoords, xOffset, yOffset)
437 local pArrow = getglobal("Kalented_Scroll_Arrow" .. TalentFrame.arrowIndex);
438 if ( pArrow ) then
439 pArrow:SetTexCoord(texCoords[1], texCoords[2], texCoords[3], texCoords[4]);
440 pArrow:SetPoint("TOPLEFT", "Kalented_Scroll_ArrowFrame", "TOPLEFT", xOffset, yOffset);
441 pArrow:Show();
442 end
443  
444 TalentFrame.arrowIndex = TalentFrame.arrowIndex + 1;
445 end
446  
447 function Kalented_SetBranchTexture(texCoords, xOffset, yOffset)
448 local pBranch = getglobal("Kalented_Scroll_Branch" .. TalentFrame.textureIndex);
449 if ( pBranch ) then
450 pBranch:SetTexCoord(texCoords[1], texCoords[2], texCoords[3], texCoords[4]);
451 pBranch:SetPoint("TOPLEFT", "Kalented_Scroll_ChildFrame", "TOPLEFT", xOffset, yOffset);
452 pBranch:Show();
453 end
454  
455 TalentFrame.textureIndex = TalentFrame.textureIndex + 1;
456 end
457  
458  
459 -- [ Debug functions ] ---------------------------------------
460 function Kalented_Debug_Message(strMessage)
461 DEFAULT_CHAT_FRAME:AddMessage("::Kalented:: " .. strMessage, 1.0, 0.25, 0.25);
462 end