vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Handle displaying all the fish in their habitats
2  
3 FishingBuddy.Locations = {};
4  
5 local NUM_THINGIES_DISPLAYED = 20;
6 FishingBuddy.Locations.FRAME_THINGIEHEIGHT = 16;
7  
8 local Collapsed = false;
9 local LocationLineSelected = 0;
10 local LocationLines = {};
11 local LocationLastLine = 1;
12  
13 local function MakeInfo(line, level, collapsible, expanded, hasicon, text, extra, index, id)
14 if ( not LocationLines[line] ) then
15 LocationLines[line] = {};
16 end
17 LocationLines[line].level = level;
18 LocationLines[line].collapsible = collapsible;
19 LocationLines[line].expanded = expanded;
20 LocationLines[line].hasicon = hasicon;
21 LocationLines[line].text = text;
22 LocationLines[line].extra = extra;
23 if ( index ) then
24 LocationLines[line].index = index;
25 else
26 LocationLines[line].index = text;
27 end
28 LocationLines[line].id = id;
29 LocationLines[line].valid = true;
30 end
31  
32 local function CountLocationLines()
33 local linecount = 0;
34 local j = 1;
35 local limit = LocationLastLine;
36 while ( j <= limit ) do
37 local info = LocationLines[j];
38 j = j + 1;
39 if ( info and info.valid ) then
40 linecount = linecount + 1;
41 if ( info.collapsible and not info.expanded ) then
42 local i2 = LocationLines[j];
43 while ( i2 and (i2.level > info.level) ) do
44 j = j + 1;
45 i2 = LocationLines[j];
46 end
47 end
48 end
49 end
50 -- there's a zero-based vs. one-based bug here, somewhere
51 if ( linecount > NUM_THINGIES_DISPLAYED and
52 limit >= table.getn(LocationLines)) then
53 linecount = linecount + 1;
54 end
55 -- FishingBuddy.Debug("Count "..linecount.." limit "..limit);
56 return linecount;
57 end
58  
59 local function FishiesChanged()
60 local fh = FishingBuddy_Info["FishingHoles"];
61 local ff = FishingBuddy_Info["Fishies"];
62 local line = 1
63 local fishcount = table.getn(FishingBuddy.SortedFishies);
64 local zonetotals = {};
65  
66 for i=1,fishcount,1 do
67 local fishid = FishingBuddy.SortedFishies[i].id;
68 local fishname = ff[fishid].name;
69 local locsort = {};
70 local total = 0;
71 for zone in FishingBuddy.ByFishie[fishid] do
72 if ( not zonetotals[zone] ) then
73 local fi = nil;
74 for z in fh do
75 if ( fh[z][zone] ) then
76 fi = fh[z][zone];
77 break;
78 end
79 end
80 if ( fi ) then
81 local tot = 0;
82 for f in fi do
83 tot = tot + fi[f];
84 end
85 zonetotals[zone] = tot;
86 end
87 end
88 local count = FishingBuddy.ByFishie[fishid][zone];
89 local info = {};
90 info.text = zone;
91 info.count = count;
92 info.total = zonetotals[zone];
93 if ( not info.total or info.total == 0) then
94 info.total = 1;
95 end
96 tinsert(locsort, info);
97 total = total + count;
98 end
99 local extra = " ("..total.." total";
100 if ( ff[fishid].level ) then
101 extra = extra..", "..ff[fishid].level;
102 end
103 extra = extra..")";
104 MakeInfo(line, 0, true, true, true, fishname, extra, nil, fishid);
105 line = line + 1;
106 FishingBuddy.FishSort(locsort);
107 for j=1,table.getn(locsort),1 do
108 local zone = locsort[j].text;
109 local amount = locsort[j].count;
110 local total = locsort[j].total;
111 local percent = format("%.1f", ( amount / total ) * 100);
112 MakeInfo(line, 1, false, false, false, zone, " ("..amount..", "..percent.."%)");
113 line = line + 1;
114 end
115 end
116 LocationLastLine = line;
117 end
118  
119 local function BothLocationsChanged()
120 local fh = FishingBuddy_Info["FishingHoles"];
121 local ff = FishingBuddy_Info["Fishies"];
122 local sorted = FishingBuddy.SortedZones;
123 local line = 1;
124 local zonecount = table.getn(sorted);
125 for i=1,zonecount,1 do
126 local zone = sorted[i];
127 local where = zone;
128 MakeInfo(line, 0, true, true, false, zone, nil, where);
129 line = line + 1;
130 local subsorted = FishingBuddy.SortedByZone[zone];
131 local subcount = table.getn(subsorted);
132 for s=1,subcount,1 do
133 local subzone = subsorted[s];
134 local count, total = FishingBuddy.FishCount(zone, subzone);
135 where = zone.."."..subzone;
136 local extra = " ("..count.." types, "..total.." total)";
137 if ( FishingBuddy_Info["FishingSkill"][zone] and FishingBuddy_Info["FishingSkill"][zone][subzone] ) then
138 extra = extra.." ["..FishingBuddy_Info["FishingSkill"][zone][subzone].."]";
139 end
140 if ( fh[zone][subzone] ) then
141 MakeInfo(line, 1, true, true, false, subzone, extra, where);
142 line = line + 1;
143 local fishsort = {};
144 for fishid in fh[zone][subzone] do
145 local info = {};
146 info.id = fishid;
147 info.text = ff[fishid].name;
148 info.count = fh[zone][subzone][fishid];
149 tinsert(fishsort, info);
150 end
151 FishingBuddy.FishSort(fishsort);
152 for j=1,table.getn(fishsort),1 do
153 local fishie = fishsort[j].text;
154 local id = fishsort[j].id;
155 local amount = fishsort[j].count;
156 local percent = format("%.1f", ( amount / total ) * 100);
157 MakeInfo(line, 2, false, false, true, fishie, " ("..percent.."%)", nil, id);
158 line = line + 1;
159 end
160 end
161 end
162 end
163 LocationLastLine = line;
164 end
165  
166 local function SubZonesChanged()
167 local fh = FishingBuddy_Info["FishingHoles"];
168 local ff = FishingBuddy_Info["Fishies"];
169 local mapping = {};
170 for zone in fh do
171 for subzone in fh[zone] do
172 mapping[subzone] = zone;
173 end
174 end
175 local line = 1;
176 local zonecount = table.getn(FishingBuddy.SortedSubZones);
177 for i=1,zonecount,1 do
178 local subzone = FishingBuddy.SortedSubZones[i];
179 local zone = mapping[subzone];
180 local extra = nil;
181 if ( FishingBuddy_Info["FishingSkill"][zone] and FishingBuddy_Info["FishingSkill"][zone][subzone] ) then
182 extra = " ["..FishingBuddy_Info["FishingSkill"][zone][subzone].."]";
183 end
184 MakeInfo(line, 0, true, true, false, subzone, extra);
185 line = line + 1;
186 local zone = mapping[subzone];
187 local count, total = FishingBuddy.FishCount(zone, subzone);
188 local fishsort = {};
189 for fishid in fh[zone][subzone] do
190 local info = {};
191 info.id = fishid;
192 info.text = ff[fishid].name;
193 info.count = fh[zone][subzone][fishid];
194 tinsert(fishsort, info);
195 end
196 FishingBuddy.FishSort(fishsort);
197 for j=1,table.getn(fishsort),1 do
198 local id = fishsort[j].id;
199 local fishie = fishsort[j].text;
200 local amount = fishsort[j].count;
201 local percent = format("%.1f", ( amount / total ) * 100);
202 MakeInfo(line, 1, false, false, true, fishie, " ("..percent.."%)", nil, id);
203 line = line + 1;
204 end
205 end
206 LocationLastLine = line;
207 end
208  
209 local function LinesChanged()
210 if ( FishingBuddy.GetSetting("GroupByLocation") == 1 ) then
211 if ( FishingBuddy.GetSetting("ShowLocationZones") == 1 ) then
212 BothLocationsChanged();
213 else
214 SubZonesChanged();
215 end
216 else
217 FishiesChanged();
218 end
219 for i=LocationLastLine,table.getn(LocationLines) do
220 local info = LocationLines[i];
221 if ( info ) then
222 info.valid = false;
223 end
224 end
225 FishingLocationsFrame.valid = true;
226 end
227  
228 -- local MOUSEWHEEL_DELAY = 0.1;
229 -- local lastScrollTime = nil;
230 -- function FishingLocationsFrame_OnMouseWheel(value)
231 -- local now = GetTime();
232 -- if ( not lastScrollTime ) then
233 -- lastScrollTime = now - 0.2;
234 -- end
235 -- if ( (now - lastScrollTime) > MOUSEWHEEL_DELAY ) then
236 -- -- call the old mouse wheel function somehow?
237 -- end
238 -- end
239  
240 function FishingLocationsFrame_SetSelection(id, line)
241 local info = LocationLines[line];
242 FishingLocationHighlightFrame:Hide();
243 if info then
244 if ( info.collapsible ) then
245 info.expanded = not info.expanded;
246 else
247 LocationLineSelected = line;
248 FishingLocationHighlightFrame:SetPoint ( "TOPLEFT" , getglobal("FishingLocations"..id):GetName() , "TOPLEFT" , 5 , 0 )
249 FishingLocationHighlightFrame:Show()
250 end
251 end
252 end
253  
254 function FishingLocationsFrame_MoveButtonText(i, what)
255 local relativeTo = "FishingLocations"..i..what;
256 local textfield = getglobal("FishingLocations"..i.."Text");
257 textfield:SetPoint("LEFT", relativeTo, "RIGHT", 2, 0);
258 textfield = getglobal("FishingLocations"..i.."HighlightText");
259 textfield:SetPoint("LEFT", relativeTo, "RIGHT", 2, 0);
260 end
261  
262 FishingBuddy.Locations.Update = function(forced)
263 if ( not FishingLocationsFrame:IsVisible() ) then
264 return;
265 end
266  
267 if ( forced or not FishingLocationsFrame.valid ) then
268 LinesChanged();
269 end
270  
271 local offset = FauxScrollFrame_GetOffset(FishingLocsScrollFrame);
272 FauxScrollFrame_Update( FishingLocsScrollFrame, CountLocationLines(),
273 NUM_THINGIES_DISPLAYED,
274 FishingBuddy.Locations.FRAME_THINGIEHEIGHT );
275  
276 local lastlevel = 0;
277 FishingLocationHighlightFrame:Hide();
278 local j = 1;
279 local o = 1;
280 while ( o < offset ) do
281 local info = LocationLines[j];
282 if ( info ) then
283 j = j + 1;
284 o = o + 1;
285 if ( info.collapsible and not info.expanded ) then
286 local i2 = LocationLines[j];
287 while ( i2 and i2.level > info.level ) do
288 j = j + 1;
289 i2 = LocationLines[j];
290 end
291 end
292 end
293 end
294 for i = 1,NUM_THINGIES_DISPLAYED,1 do
295 local locButton = getglobal ( "FishingLocations"..i );
296 if ( LocationLines[j] ) then
297 local icon = getglobal("FishingLocations"..i.."Icon");
298 local icontex = getglobal("FishingLocations"..i.."IconTexture");
299 local info = LocationLines[j];
300 locButton.id = i;
301 locButton.line = j;
302  
303 local leveloffset = (info.level - lastlevel)*16;
304 if ( i == 1 ) then
305 locButton:SetPoint("TOPRIGHT", "FishingLocsScrollFrame", "TOPLEFT", leveloffset, 0);
306 else
307 local t = i - 1;
308 locButton:SetPoint("TOPLEFT", "FishingLocations"..t, "BOTTOMLEFT", leveloffset, 0);
309 end
310 lastlevel = info.level;
311  
312 local text = info.text;
313 if text and info.extra then
314 text = text .. info.extra;
315 end
316  
317 locButton:SetText( text );
318 icon:ClearAllPoints();
319 if ( info.collapsible ) then
320 icon:SetPoint("LEFT", "FishingLocations"..i, "LEFT", 21, 0);
321 locButton:SetTextColor( 1, 0.82, 0 );
322 if ( info.expanded ) then
323 locButton:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Up");
324 else
325 locButton:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up");
326 end
327 getglobal("FishingLocations"..i.."Highlight"):SetTexture("Interface\\Buttons\\UI-PlusButton-Hilight");
328 getglobal("FishingLocations"..i):UnlockHighlight();
329 else
330 icon:SetPoint("LEFT", "FishingLocations"..i, "LEFT", 3, 0);
331 locButton:SetTextColor( .5, .5, .5 );
332 locButton:SetNormalTexture("");
333 getglobal("FishingLocations"..i.."Highlight"):SetTexture("");
334 -- Place the highlight and lock the highlight state
335 if ( LocationLineSelected == j ) then
336 FishingLocationHighlightFrame:SetPoint("TOPLEFT", "FishingLocations"..i, "TOPLEFT", 21, 0);
337 FishingLocationHighlightFrame:Show();
338 locButton:LockHighlight();
339 else
340 locButton:UnlockHighlight();
341 end
342 end
343  
344 locButton.tooltip = nil;
345 if ( info.hasicon ) then
346 local item, texture, _, _, _ = FishingBuddy.GetFishie(info.id);
347 locButton.item = item;
348 locButton.name = info.text;
349 if( texture ) then
350 icontex:SetTexture(texture);
351 icon:Show();
352 icontex:Show();
353 end
354 FishingLocationsFrame_MoveButtonText(i, "Icon");
355 else
356 locButton.item = nil;
357 locButton.name = nil;
358 icontex:SetTexture("");
359 icontex:Hide();
360 icon:Hide();
361 FishingLocationsFrame_MoveButtonText(i, "Highlight");
362 end
363 locButton:Show();
364 j = j + 1;
365 if ( info.collapsible and not info.expanded ) then
366 local i2 = LocationLines[j];
367 while ( i2 and (i2.level > info.level) ) do
368 j = j + 1;
369 i2 = LocationLines[j];
370 end
371 end
372 else
373 locButton:Hide();
374 locButton.id = nil;
375 locButton.line = nil;
376 end
377 end
378  
379 if LocationLines then
380 -- Set the expand/collapse all button texture
381 local numHeaders = 0;
382 local notExpanded = 0;
383 for i=1,table.getn(LocationLines),1 do
384 local j = i + offset;
385 local info = LocationLines[j];
386 if ( info and info.collapsible ) then
387 numHeaders = numHeaders + 1;
388 if ( not info.expanded ) then
389 notExpanded = notExpanded + 1;
390 end
391 end
392 end
393 FishingLocationsCollapseAllButton:Show();
394 -- If all headers are not expanded then show collapse button, otherwise show the expand button
395 if ( notExpanded ~= numHeaders ) then
396 Collapsed = false;
397 FishingLocationsCollapseAllButton:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Up");
398 else
399 Collapsed = true;
400 FishingLocationsCollapseAllButton:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up");
401 end
402 else
403 FishingLocationsCollapseAllButton:Hide();
404 end
405 end
406  
407 FishingBuddy.Locations.Button_OnClick = function(button)
408 if ( button == "LeftButton" ) then
409 if( IsShiftKeyDown() and this.item ) then
410 FishingBuddy.ChatLink(this.item, this.name, this.color);
411 elseif ( this.id and this.line ) then
412 FishingLocationsFrame_SetSelection(this.id, this.line);
413 FishingBuddy.Locations.Update();
414 end
415 end
416 end
417  
418 function FishingLocationsCollapseAllButton_OnClick()
419 if not Collapsed then
420 FishingLocsScrollFrameScrollBar:SetValue(0);
421 LocationLineSelected = 1;
422 end
423 for _,info in LocationLines do
424 info.expanded = Collapsed;
425 end
426 Collapsed = not Collapsed;
427 FishingBuddy.Locations.Update();
428 end
429  
430 FishingBuddy.Locations.Button_OnEnter = function()
431 if( GameTooltip.finished ) then
432 return;
433 end
434 if( this.item or this.tooltip ) then
435 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
436 if ( this.item and this.item ~= "" ) then
437 local link = "item:"..this.item;
438 local n,l,_,_,_,_,_,_ = GetItemInfo(link);
439 if ( n and l ) then
440 GameTooltip:SetHyperlink(link);
441 else
442 this.tooltip = {}
443 this.tooltip[1] = { ["text"] = this.name };
444 this.tooltip[2] = { ["text"] = FishingBuddy.NOTLINKABLE, ["r"] = 1.0, ["g"] = 0, ["b"] = 0 };
445 FishingBuddy.AddTooltip(this.tooltip);
446 this.item = nil;
447 end
448 elseif ( this.tooltip ) then
449 FishingBuddy.AddTooltip(this.tooltip, 1, 1, 1);
450 end
451 GameTooltip.finished = 1;
452 GameTooltip:Show();
453 end
454 end
455  
456 FishingBuddy.Locations.Button_OnLeave = function()
457 GameTooltip.finished = nil;
458 if( this.item or this.tooltip ) then
459 GameTooltip:Hide();
460 end
461 end
462  
463 FishingBuddy.Locations.DisplayChanged = function()
464 FishingLocsScrollFrameScrollBar:SetValue(0);
465 LocationLineSelected = 1;
466 FishingBuddy.Locations.Update(true);
467 end
468  
469 FishingBuddy.Locations.SwitchDisplay = function()
470 -- backwards logic check, we're about to change...
471 if ( FishingBuddy.GetSetting("GroupByLocation") == 1 ) then
472 FishingLocationsSwitchButton:SetText(FishingBuddy.SHOWLOCATIONS);
473 FishingBuddyOptionSLZ:Hide();
474 FishingBuddy.SetSetting("GroupByLocation", 0);
475 else
476 FishingLocationsSwitchButton:SetText(FishingBuddy.SHOWFISHIES);
477 FishingBuddyOptionSLZ:Show();
478 FishingBuddy.SetSetting("GroupByLocation", 1);
479 end
480 FishingBuddy.Locations.DisplayChanged();
481 end
482  
483 FishingBuddy.Locations.SwitchButton_OnEnter = function()
484 if ( FishingBuddy.GetSetting("GroupByLocation") == 1 ) then
485 GameTooltip:SetText(FishingBuddy.SHOWFISHIES_INFO);
486 else
487 GameTooltip:SetText(FishingBuddy.SHOWLOCATIONS_INFO);
488 end
489 GameTooltip:Show();
490 end
491  
492 FishingBuddy.Locations.OnLoad = function()
493 this:RegisterEvent("VARIABLES_LOADED");
494 FishingLocationsSwitchButton:SetText(FishingBuddy.SHOWFISHIES);
495 -- Set up checkbox
496 FishingBuddyOptionSLZ.name = "ShowLocationZones";
497 FishingBuddyOptionSLZ.text = FishingBuddy.CONFIG_SHOWLOCATIONZONES_ONOFF;
498 FishingBuddyOptionSLZ.tooltip = FishingBuddy.CONFIG_SHOWLOCATIONZONES_INFO;
499 end
500  
501 FishingBuddy.Locations.OnShow = function()
502 if ( FishingBuddy.IsLoaded() ) then
503 FishingBuddy.Locations.Update();
504 end
505 end
506  
507 FishingBuddy.Locations.OnEvent = function()
508 -- this crashes the client when enabled
509 -- this:EnableMouseWheel(0);
510 end
511  
512 FishingBuddy.FishCount = function(zone, subzone)
513 local count = 0;
514 local total = 0;
515 local fh = FishingBuddy_Info["FishingHoles"];
516 if( fh[zone] and fh[zone][subzone] ) then
517 for fishie in fh[zone][subzone] do
518 count = count + 1;
519 total = total + fh[zone][subzone][fishie];
520 end
521 end
522 return count, total;
523 end
524  
525 FishingBuddy.Locations.DataChanged = function(zone, subzone, fishie)
526 FishingLocationsFrame.valid = false;
527 end