vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Beastmaster by PoeticDragon
3  
4 Another 'short and sweet' addon, Beastmaster changes the way that
5 beast training abilities are sorted. Rather than displaying in
6 order of rank, they're now grouped by abilities (ie dive, growl, etc).
7 This way it is easier to find the ability you want, or look up what
8 the highest rank known to you.
9  
10 As usual, no configuration needed.
11  
12 Future plans include standard "filter" type button like from trainers
13 for Already Known, Available, and Unavailable skills.
14  
15 ]]--
16  
17 -------------------------------------------------------------------------------
18 -- Constants
19 -------------------------------------------------------------------------------
20  
21 BEASTMASTER_CATG_SKILLS = {
22 [1] = {1, 2, 3, 4, 5, 6, },
23 [2] = {7, 8, 9, 10, 11, 12, 13, 14, },
24 [3] = {15, 16, },
25 [4] = {17, 18, 19, 20, 21, },
26 }
27  
28 BEASTMASTER_SKILLS_REVERSE = {};
29 local i,skill;
30 for i,skill in BEASTMASTER_SKILLS_NAMES do
31 BEASTMASTER_SKILLS_REVERSE[skill] = i;
32 end
33  
34 -------------------------------------------------------------------------------
35 -- Variables
36 -------------------------------------------------------------------------------
37  
38 Beastmaster_Sorted = {};
39 Beastmaster_HeaderIndex = {};
40 Beastmaster_IsExpanded = {true, true, true, true};
41 Beastmaster_Loaded = false;
42 Beastmaster_Selected = nil;
43 Beastmaster_MaxKnown = {};
44  
45 -------------------------------------------------------------------------------
46 -- Functions
47 -------------------------------------------------------------------------------
48 function Beastmaster_OnLoad()
49 this:RegisterEvent("CRAFT_SHOW");
50 this:RegisterEvent("CRAFT_UPDATE");
51 this:RegisterEvent("SKILL_LINES_CHANGED");
52 this:RegisterEvent("UNIT_PET_TRAINING_POINTS");
53  
54 -- Hooks functions
55 Beastmaster_Original_Update = CraftFrame_Update;
56 CraftFrame_Update = Beastmaster_Update;
57  
58 -- Number of crafts
59 Beastmaster_Original_GetNumCrafts = GetNumCrafts;
60 GetNumCrafts = Beastmaster_GetNumCrafts;
61  
62 -- Opening and closing headers
63 Beastmaster_Original_ExpandCraftSkillLine = ExpandCraftSkillLine;
64 ExpandCraftSkillLine = Beastmaster_ExpandCraftSkillLine;
65 Beastmaster_Original_CollapseCraftSkillLine = CollapseCraftSkillLine;
66 CollapseCraftSkillLine = Beastmaster_CollapseCraftSkillLine;
67 Beastmaster_Original_CollapseAll = TradeSkillCollapseAllButton_OnClick;
68 TradeSkillCollapseAllButton_OnClick = Beastmaster_CollapseAll;
69  
70 -- Selecting a skill
71 Beastmaster_Original_SetSelection = CraftFrame_SetSelection;
72 CraftFrame_SetSelection = Beastmaster_SetSelection;
73 Beastmaster_Original_SelectCraft = SelectCraft;
74 SelectCraft = Beastmaster_SelectCraft;
75 Beastmaster_Original_GetCraftSelectionIndex = GetCraftSelectionIndex;
76 GetCraftSelectionIndex = Beastmaster_GetCraftSelectionIndex;
77  
78 -- Skill information
79 Beastmaster_Original_GetCraftInfo = GetCraftInfo;
80 GetCraftInfo = Beastmaster_GetCraftInfo;
81 Beastmaster_Original_GetCraftDescription = GetCraftDescription;
82 GetCraftDescription = Beastmaster_GetCraftDescription;
83 Beastmaster_Original_GetCraftIcon = GetCraftIcon;
84 GetCraftIcon = Beastmaster_GetCraftIcon;
85  
86 -- Skill tooltips
87 Beastmaster_Original_SetCraftItem = GameTooltip.SetCraftItem;
88 GameTooltip.SetCraftItem = Beastmaster_SetCraftItem;
89 Beastmaster_Original_SetCraftSpell = GameTooltip.SetCraftSpell;
90 GameTooltip.SetCraftSpell = Beastmaster_SetCraftSpell;
91  
92 -- Train the skill to the pet
93 Beastmaster_Original_DoCraft = DoCraft;
94 DoCraft = Beastmaster_DoCraft;
95  
96 Beastmaster_Loaded = true;
97 end
98  
99 function Beastmaster_OnEvent(event)
100 if (not Beastmaster_Loaded) then return; end
101 if ( GetCraftName() == BEASTMASTER_TRAINING ) then
102 Beastmaster_SortAbilities();
103 if (CraftFrame:IsVisible()) then
104 if ( GetCraftSelectionIndex() <= 1 ) then
105 CraftFrame_SetSelection(2);
106 FauxScrollFrame_SetOffset(CraftListScrollFrame, 0);
107 CraftListScrollFrameScrollBar:SetValue(0);
108 CraftFrame_Update();
109 end
110 end
111 end
112 end
113  
114 function Beastmaster_Update()
115 Beastmaster_Original_Update();
116 if ( GetCraftName() ~= BEASTMASTER_TRAINING ) then
117 return;
118 end
119  
120 local offset = FauxScrollFrame_GetOffset(CraftListScrollFrame);
121 for i=1,CRAFTS_DISPLAYED do
122 local button = getglobal("Craft"..i);
123 local cost = getglobal("Craft"..i.."Cost");
124 getglobal("Craft"..i.."Text"):SetPoint("TOPLEFT", "Craft"..i, "TOPLEFT", 21, 0);
125 -- getglobal("Craft"..i.."HighlightText"):SetPoint("TOPLEFT", "Craft"..i, "TOPLEFT", 21, 0);
126 -- getglobal("Craft"..i.."DisabledText"):SetPoint("TOPLEFT", "Craft"..i, "TOPLEFT", 21, 0);
127 if (Beastmaster_HeaderIndex[button:GetID()]) then
128 cost:SetText("");
129 elseif (HasPetUI() and not cost:GetText() and button:GetText() and
130 not string.find(button:GetText(), BEASTMASTER_SKILLS_NAMES[6])) then
131 button.r = 0.9;
132 button.g = 0;
133 button.b = 0;
134 button:SetTextColor(button.r, button.g, button.b);
135 getglobal("Craft"..i.."SubText"):SetTextColor(button.r, button.g, button.b);
136 elseif (HasPetUI() and cost:GetText()) then
137 local orig = cost:GetText();
138 local skill, _, _, _, _, points = GetCraftInfo(i + offset);
139 local paid = Beastmaster_MaxKnown[BEASTMASTER_SKILLS_REVERSE[skill]];
140 if ( paid ) then
141 points = points - paid;
142 if ( points > 0 ) then
143 cost:SetText("("..points..") "..orig);
144 end
145 end
146 end
147 end
148 CraftExpandButtonFrame:Hide();
149 end
150  
151 function Beastmaster_SortAbilities()
152 if ( GetCraftName() ~= BEASTMASTER_TRAINING ) then
153 return;
154 end
155  
156 local tempsort = {};
157 local i, orig, skill, rank, heading, index, catg, display;
158 local new = 0;
159  
160 Beastmaster_Sorted = {};
161 Beastmaster_MaxKnown = {};
162 for i=1, Beastmaster_Original_GetNumCrafts() do
163 skill, rank, heading, _, _, points = GetCraftInfo(i);
164 rank = string.gsub(rank, BEASTMASTER_RANK, "");
165 rank = tonumber(rank);
166 if ( heading ~= "header" ) then
167 index = BEASTMASTER_SKILLS_REVERSE[skill];
168 if (index) then
169 if (not tempsort[index]) then
170 tempsort[index] = {};
171 end
172 tempsort[index][rank]=i;
173 if ( heading == "used" ) then
174 if ( not Beastmaster_MaxKnown[index] or Beastmaster_MaxKnown[index] < points ) then
175 Beastmaster_MaxKnown[index] = points;
176 end
177 end
178 end
179 end
180 end
181  
182 Beastmaster_HeaderIndex = {};
183 for heading,catg in BEASTMASTER_CATG_SKILLS do
184 display = false;
185 new = new + 1;
186  
187 for i=1, table.getn(catg) do
188 index = catg[i];
189 if (tempsort[index]) then
190 if (not display) then
191 Beastmaster_Sorted[new] = BEASTMASTER_CATG_NAMES[heading];
192 Beastmaster_HeaderIndex[new] = heading;
193 display = true;
194 end
195  
196 if (not Beastmaster_IsExpanded[heading]) then
197 break;
198 end
199  
200 for _,orig in tempsort[index] do
201 new = new + 1;
202 Beastmaster_Sorted[new] = orig;
203 end
204 end
205 end
206 end
207  
208 Beastmaster_Update();
209 end
210  
211 function Beastmaster_SortedIndex(index)
212 if ( GetCraftName() == BEASTMASTER_TRAINING ) then
213 local sorted = Beastmaster_Sorted[index];
214 if ( sorted ) then
215 index = sorted;
216 end
217 end
218 return index;
219 end
220  
221 function Beastmaster_GetNumCrafts()
222 if ( GetCraftName() == BEASTMASTER_TRAINING ) then
223 return table.getn(Beastmaster_Sorted);
224 end
225 return Beastmaster_Original_GetNumCrafts();
226 end
227  
228 function Beastmaster_SetSelection(index)
229 Beastmaster_Original_SetSelection(index);
230 if ( GetCraftName() ~= BEASTMASTER_TRAINING or not HasPetUI() ) then
231 return;
232 end
233  
234 local skill, _, heading, _, _, points = GetCraftInfo(index);
235 if (heading == "header") then
236 return;
237 end
238  
239 if ( points == 0 and skill ~= BEASTMASTER_SKILLS_NAMES[6]) then
240 CraftHighlight:SetVertexColor(0.9, 0, 0);
241 end
242  
243 local paid = Beastmaster_MaxKnown[BEASTMASTER_SKILLS_REVERSE[skill]];
244 local orig = points;
245 if ( paid ) then
246 points = points - paid;
247 end
248  
249 local total, spent = GetPetTrainingPoints();
250 local usable = total - spent;
251 if ( points > 0 ) then
252 local display = orig;
253 if ( points ~= orig ) then
254 display = "("..points..") "..display;
255 end
256 if ( usable < points ) then
257 display = RED_FONT_COLOR_CODE..display..FONT_COLOR_CODE_CLOSE;
258 end
259 CraftCost:SetText(COSTS_LABEL.." "..display.." "..TRAINING_POINTS_LABEL);
260 CraftCost:Show();
261 else
262 CraftCost:Hide();
263 end
264 end
265  
266 function Beastmaster_SelectCraft(index)
267 if ( GetCraftName() ~= BEASTMASTER_TRAINING or index <= Beastmaster_Original_GetNumCrafts() ) then
268 Beastmaster_Selected = nil;
269 return Beastmaster_Original_SelectCraft(index);
270 end
271 Beastmaster_Selected = index;
272 end
273  
274 function Beastmaster_GetCraftSelectionIndex()
275 if (Beastmaster_Selected) then
276 return Beastmaster_Selected;
277 end
278 return Beastmaster_Original_GetCraftSelectionIndex();
279 end
280  
281 function Beastmaster_ExpandCraftSkillLine(index)
282 if ( GetCraftName() ~= BEASTMASTER_TRAINING ) then
283 return Beastmaster_Original_ExpandCraftSkillLine(index);
284 end
285  
286 if (index ~= 0) then
287 Beastmaster_IsExpanded[Beastmaster_HeaderIndex[index]] = true;
288 Beastmaster_SortAbilities();
289 end
290 end
291  
292 function Beastmaster_CollapseCraftSkillLine(index)
293 if ( GetCraftName() ~= BEASTMASTER_TRAINING ) then
294 return Beastmaster_Original_CollapseCraftSkillLine(index);
295 end
296  
297 if (index ~= 0) then
298 Beastmaster_IsExpanded[Beastmaster_HeaderIndex[index]] = false;
299 Beastmaster_SortAbilities();
300 end
301 end
302  
303 function Beastmaster_CollapseAll()
304 if ( GetCraftName() ~= BEASTMASTER_TRAINING ) then
305 return Beastmaster_Original_CollapseAll();
306 end
307 return CraftCollapseAllButton_OnClick();
308 end
309  
310 function Beastmaster_AdjustPoints(index)
311  
312 end
313  
314 function Beastmaster_Dummy(origfunc, index, ...)
315 local sorted = Beastmaster_SortedIndex(index);
316 if ( type(sorted) == "number" ) then
317 if (origfunc == Beastmaster_Original_SetCraftItem or origfunc == Beastmaster_Original_SetCraftSpell) then
318 return origfunc(arg[1], sorted, arg[2]);
319 else
320 return origfunc(sorted);
321 end
322 else
323 if (origfunc == Beastmaster_Original_GetCraftInfo) then
324 return sorted, "", "header", 0, Beastmaster_IsExpanded[Beastmaster_HeaderIndex[index]], 0;
325 elseif (origfunc == Beastmaster_Original_GetCraftIcon) then
326 return "Interface\Icons\Ability_Hunter_BeastCall02";
327 else
328 return nil;
329 end
330 end
331 end
332  
333 function Beastmaster_GetCraftInfo(index)
334 return Beastmaster_Dummy(Beastmaster_Original_GetCraftInfo, index);
335 end
336  
337 function Beastmaster_GetCraftDescription(index)
338 return Beastmaster_Dummy(Beastmaster_Original_GetCraftDescription, index);
339 end
340  
341 function Beastmaster_GetCraftIcon(index)
342 return Beastmaster_Dummy(Beastmaster_Original_GetCraftIcon, index);
343 end
344  
345 function Beastmaster_SetCraftItem(tooltip, index, reagent)
346 return Beastmaster_Dummy(Beastmaster_Original_SetCraftItem, index, tooltip, reagent);
347 end
348  
349 function Beastmaster_SetCraftSpell(tooltip, index, reagent)
350 return Beastmaster_Dummy(Beastmaster_Original_SetCraftSpell, index, tooltip, reagent);
351 end
352  
353 function Beastmaster_DoCraft(index)
354 Beastmaster_Dummy(Beastmaster_Original_DoCraft, index);
355 Beastmaster_SortAbilities();
356 CraftFrame_Update();
357 end