forked from aim2kill/FishingBuddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFishingLocationsFrame.lua
executable file
·526 lines (492 loc) · 16.6 KB
/
FishingLocationsFrame.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
-- Handle displaying all the fish in their habitats
FishingBuddy.Locations = {};
local NUM_THINGIES_DISPLAYED = 20;
FishingBuddy.Locations.FRAME_THINGIEHEIGHT = 16;
local Collapsed = false;
local LocationLineSelected = 0;
local LocationLines = {};
local LocationLastLine = 1;
local function MakeInfo(line, level, collapsible, expanded, hasicon, text, extra, index, id)
if ( not LocationLines[line] ) then
LocationLines[line] = {};
end
LocationLines[line].level = level;
LocationLines[line].collapsible = collapsible;
LocationLines[line].expanded = expanded;
LocationLines[line].hasicon = hasicon;
LocationLines[line].text = text;
LocationLines[line].extra = extra;
if ( index ) then
LocationLines[line].index = index;
else
LocationLines[line].index = text;
end
LocationLines[line].id = id;
LocationLines[line].valid = true;
end
local function CountLocationLines()
local linecount = 0;
local j = 1;
local limit = LocationLastLine;
while ( j <= limit ) do
local info = LocationLines[j];
j = j + 1;
if ( info and info.valid ) then
linecount = linecount + 1;
if ( info.collapsible and not info.expanded ) then
local i2 = LocationLines[j];
while ( i2 and (i2.level > info.level) ) do
j = j + 1;
i2 = LocationLines[j];
end
end
end
end
-- there's a zero-based vs. one-based bug here, somewhere
if ( linecount > NUM_THINGIES_DISPLAYED and
limit >= table.getn(LocationLines)) then
linecount = linecount + 1;
end
-- FishingBuddy.Debug("Count "..linecount.." limit "..limit);
return linecount;
end
local function FishiesChanged()
local fh = FishingBuddy_Info["FishingHoles"];
local ff = FishingBuddy_Info["Fishies"];
local line = 1
local fishcount = table.getn(FishingBuddy.SortedFishies);
local zonetotals = {};
for i=1,fishcount,1 do
local fishid = FishingBuddy.SortedFishies[i].id;
local fishname = ff[fishid].name;
local locsort = {};
local total = 0;
for zone in FishingBuddy.ByFishie[fishid] do
if ( not zonetotals[zone] ) then
local fi = nil;
for z in fh do
if ( fh[z][zone] ) then
fi = fh[z][zone];
break;
end
end
if ( fi ) then
local tot = 0;
for f in fi do
tot = tot + fi[f];
end
zonetotals[zone] = tot;
end
end
local count = FishingBuddy.ByFishie[fishid][zone];
local info = {};
info.text = zone;
info.count = count;
info.total = zonetotals[zone];
if ( not info.total or info.total == 0) then
info.total = 1;
end
tinsert(locsort, info);
total = total + count;
end
local extra = " ("..total.." total";
if ( ff[fishid].level ) then
extra = extra..", "..ff[fishid].level;
end
extra = extra..")";
MakeInfo(line, 0, true, true, true, fishname, extra, nil, fishid);
line = line + 1;
FishingBuddy.FishSort(locsort);
for j=1,table.getn(locsort),1 do
local zone = locsort[j].text;
local amount = locsort[j].count;
local total = locsort[j].total;
local percent = format("%.1f", ( amount / total ) * 100);
MakeInfo(line, 1, false, false, false, zone, " ("..amount..", "..percent.."%)");
line = line + 1;
end
end
LocationLastLine = line;
end
local function BothLocationsChanged()
local fh = FishingBuddy_Info["FishingHoles"];
local ff = FishingBuddy_Info["Fishies"];
local sorted = FishingBuddy.SortedZones;
local line = 1;
local zonecount = table.getn(sorted);
for i=1,zonecount,1 do
local zone = sorted[i];
local where = zone;
MakeInfo(line, 0, true, true, false, zone, nil, where);
line = line + 1;
local subsorted = FishingBuddy.SortedByZone[zone];
local subcount = table.getn(subsorted);
for s=1,subcount,1 do
local subzone = subsorted[s];
local count, total = FishingBuddy.FishCount(zone, subzone);
where = zone.."."..subzone;
local extra = " ("..count.." types, "..total.." total)";
if ( FishingBuddy_Info["FishingSkill"][zone] and FishingBuddy_Info["FishingSkill"][zone][subzone] ) then
extra = extra.." ["..FishingBuddy_Info["FishingSkill"][zone][subzone].."]";
end
if ( fh[zone][subzone] ) then
MakeInfo(line, 1, true, true, false, subzone, extra, where);
line = line + 1;
local fishsort = {};
for fishid in fh[zone][subzone] do
local info = {};
info.id = fishid;
info.text = ff[fishid].name;
info.count = fh[zone][subzone][fishid];
tinsert(fishsort, info);
end
FishingBuddy.FishSort(fishsort);
for j=1,table.getn(fishsort),1 do
local fishie = fishsort[j].text;
local id = fishsort[j].id;
local amount = fishsort[j].count;
local percent = format("%.1f", ( amount / total ) * 100);
MakeInfo(line, 2, false, false, true, fishie, " ("..percent.."%)", nil, id);
line = line + 1;
end
end
end
end
LocationLastLine = line;
end
local function SubZonesChanged()
local fh = FishingBuddy_Info["FishingHoles"];
local ff = FishingBuddy_Info["Fishies"];
local mapping = {};
for zone in fh do
for subzone in fh[zone] do
mapping[subzone] = zone;
end
end
local line = 1;
local zonecount = table.getn(FishingBuddy.SortedSubZones);
for i=1,zonecount,1 do
local subzone = FishingBuddy.SortedSubZones[i];
local zone = mapping[subzone];
local extra = nil;
if ( FishingBuddy_Info["FishingSkill"][zone] and FishingBuddy_Info["FishingSkill"][zone][subzone] ) then
extra = " ["..FishingBuddy_Info["FishingSkill"][zone][subzone].."]";
end
MakeInfo(line, 0, true, true, false, subzone, extra);
line = line + 1;
local zone = mapping[subzone];
local count, total = FishingBuddy.FishCount(zone, subzone);
local fishsort = {};
for fishid in fh[zone][subzone] do
local info = {};
info.id = fishid;
info.text = ff[fishid].name;
info.count = fh[zone][subzone][fishid];
tinsert(fishsort, info);
end
FishingBuddy.FishSort(fishsort);
for j=1,table.getn(fishsort),1 do
local id = fishsort[j].id;
local fishie = fishsort[j].text;
local amount = fishsort[j].count;
local percent = format("%.1f", ( amount / total ) * 100);
MakeInfo(line, 1, false, false, true, fishie, " ("..percent.."%)", nil, id);
line = line + 1;
end
end
LocationLastLine = line;
end
local function LinesChanged()
if ( FishingBuddy.GetSetting("GroupByLocation") == 1 ) then
if ( FishingBuddy.GetSetting("ShowLocationZones") == 1 ) then
BothLocationsChanged();
else
SubZonesChanged();
end
else
FishiesChanged();
end
for i=LocationLastLine,table.getn(LocationLines) do
local info = LocationLines[i];
if ( info ) then
info.valid = false;
end
end
FishingLocationsFrame.valid = true;
end
-- local MOUSEWHEEL_DELAY = 0.1;
-- local lastScrollTime = nil;
-- function FishingLocationsFrame_OnMouseWheel(value)
-- local now = GetTime();
-- if ( not lastScrollTime ) then
-- lastScrollTime = now - 0.2;
-- end
-- if ( (now - lastScrollTime) > MOUSEWHEEL_DELAY ) then
-- -- call the old mouse wheel function somehow?
-- end
-- end
function FishingLocationsFrame_SetSelection(id, line)
local info = LocationLines[line];
FishingLocationHighlightFrame:Hide();
if info then
if ( info.collapsible ) then
info.expanded = not info.expanded;
else
LocationLineSelected = line;
FishingLocationHighlightFrame:SetPoint ( "TOPLEFT" , getglobal("FishingLocations"..id):GetName() , "TOPLEFT" , 5 , 0 )
FishingLocationHighlightFrame:Show()
end
end
end
function FishingLocationsFrame_MoveButtonText(i, what)
local relativeTo = "FishingLocations"..i..what;
local textfield = getglobal("FishingLocations"..i.."Text");
textfield:SetPoint("LEFT", relativeTo, "RIGHT", 2, 0);
textfield = getglobal("FishingLocations"..i.."HighlightText");
end
FishingBuddy.Locations.Update = function(forced)
if ( not FishingLocationsFrame:IsVisible() ) then
return;
end
if ( forced or not FishingLocationsFrame.valid ) then
LinesChanged();
end
local offset = FauxScrollFrame_GetOffset(FishingLocsScrollFrame);
FauxScrollFrame_Update( FishingLocsScrollFrame, CountLocationLines(),
NUM_THINGIES_DISPLAYED,
FishingBuddy.Locations.FRAME_THINGIEHEIGHT );
local lastlevel = 0;
FishingLocationHighlightFrame:Hide();
local j = 1;
local o = 1;
while ( o < offset ) do
local info = LocationLines[j];
if ( info ) then
j = j + 1;
o = o + 1;
if ( info.collapsible and not info.expanded ) then
local i2 = LocationLines[j];
while ( i2 and i2.level > info.level ) do
j = j + 1;
i2 = LocationLines[j];
end
end
end
end
for i = 1,NUM_THINGIES_DISPLAYED,1 do
local locButton = getglobal ( "FishingLocations"..i );
if ( LocationLines[j] ) then
local icon = getglobal("FishingLocations"..i.."Icon");
local icontex = getglobal("FishingLocations"..i.."IconTexture");
local info = LocationLines[j];
locButton.id = i;
locButton.line = j;
local leveloffset = (info.level - lastlevel)*16;
if ( i == 1 ) then
locButton:SetPoint("TOPRIGHT", "FishingLocsScrollFrame", "TOPLEFT", leveloffset, 0);
else
local t = i - 1;
locButton:SetPoint("TOPLEFT", "FishingLocations"..t, "BOTTOMLEFT", leveloffset, 0);
end
lastlevel = info.level;
local text = info.text;
if text and info.extra then
text = text .. info.extra;
end
locButton:SetText( text );
icon:ClearAllPoints();
if ( info.collapsible ) then
icon:SetPoint("LEFT", "FishingLocations"..i, "LEFT", 21, 0);
locButton:SetTextColor( 1, 0.82, 0 );
if ( info.expanded ) then
locButton:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Up");
else
locButton:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up");
end
getglobal("FishingLocations"..i.."Highlight"):SetTexture("Interface\\Buttons\\UI-PlusButton-Hilight");
getglobal("FishingLocations"..i):UnlockHighlight();
else
icon:SetPoint("LEFT", "FishingLocations"..i, "LEFT", 3, 0);
locButton:SetTextColor( .5, .5, .5 );
locButton:SetNormalTexture("");
getglobal("FishingLocations"..i.."Highlight"):SetTexture("");
-- Place the highlight and lock the highlight state
if ( LocationLineSelected == j ) then
FishingLocationHighlightFrame:SetPoint("TOPLEFT", "FishingLocations"..i, "TOPLEFT", 21, 0);
FishingLocationHighlightFrame:Show();
locButton:LockHighlight();
else
locButton:UnlockHighlight();
end
end
locButton.tooltip = nil;
if ( info.hasicon ) then
local item, texture, _, _, _ = FishingBuddy.GetFishie(info.id);
locButton.item = item;
locButton.name = info.text;
if( texture ) then
icontex:SetTexture(texture);
icon:Show();
icontex:Show();
end
FishingLocationsFrame_MoveButtonText(i, "Icon");
else
locButton.item = nil;
locButton.name = nil;
icontex:SetTexture("");
icontex:Hide();
icon:Hide();
FishingLocationsFrame_MoveButtonText(i, "Highlight");
end
locButton:Show();
j = j + 1;
if ( info.collapsible and not info.expanded ) then
local i2 = LocationLines[j];
while ( i2 and (i2.level > info.level) ) do
j = j + 1;
i2 = LocationLines[j];
end
end
else
locButton:Hide();
locButton.id = nil;
locButton.line = nil;
end
end
if LocationLines then
-- Set the expand/collapse all button texture
local numHeaders = 0;
local notExpanded = 0;
for i=1,table.getn(LocationLines),1 do
local j = i + offset;
local info = LocationLines[j];
if ( info and info.collapsible ) then
numHeaders = numHeaders + 1;
if ( not info.expanded ) then
notExpanded = notExpanded + 1;
end
end
end
FishingLocationsCollapseAllButton:Show();
-- If all headers are not expanded then show collapse button, otherwise show the expand button
if ( notExpanded ~= numHeaders ) then
Collapsed = false;
FishingLocationsCollapseAllButton:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Up");
else
Collapsed = true;
FishingLocationsCollapseAllButton:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up");
end
else
FishingLocationsCollapseAllButton:Hide();
end
end
FishingBuddy.Locations.Button_OnClick = function(button)
if ( button == "LeftButton" ) then
if( IsShiftKeyDown() and this.item ) then
FishingBuddy.ChatLink(this.item, this.name, this.color);
elseif ( this.id and this.line ) then
FishingLocationsFrame_SetSelection(this.id, this.line);
FishingBuddy.Locations.Update();
end
end
end
function FishingLocationsCollapseAllButton_OnClick()
if not Collapsed then
FishingLocsScrollFrameScrollBar:SetValue(0);
LocationLineSelected = 1;
end
for _,info in LocationLines do
info.expanded = Collapsed;
end
Collapsed = not Collapsed;
FishingBuddy.Locations.Update();
end
FishingBuddy.Locations.Button_OnEnter = function()
if( GameTooltip.finished ) then
return;
end
if( this.item or this.tooltip ) then
GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
if ( this.item and this.item ~= "" ) then
local link = "item:"..this.item;
local n,l,_,_,_,_,_,_ = GetItemInfo(link);
if ( n and l ) then
GameTooltip:SetHyperlink(link);
else
this.tooltip = {}
this.tooltip[1] = { ["text"] = this.name };
this.tooltip[2] = { ["text"] = FishingBuddy.NOTLINKABLE, ["r"] = 1.0, ["g"] = 0, ["b"] = 0 };
FishingBuddy.AddTooltip(this.tooltip);
this.item = nil;
end
elseif ( this.tooltip ) then
FishingBuddy.AddTooltip(this.tooltip, 1, 1, 1);
end
GameTooltip.finished = 1;
GameTooltip:Show();
end
end
FishingBuddy.Locations.Button_OnLeave = function()
GameTooltip.finished = nil;
if( this.item or this.tooltip ) then
GameTooltip:Hide();
end
end
FishingBuddy.Locations.DisplayChanged = function()
FishingLocsScrollFrameScrollBar:SetValue(0);
LocationLineSelected = 1;
FishingBuddy.Locations.Update(true);
end
FishingBuddy.Locations.SwitchDisplay = function()
-- backwards logic check, we're about to change...
if ( FishingBuddy.GetSetting("GroupByLocation") == 1 ) then
FishingLocationsSwitchButton:SetText(FishingBuddy.SHOWLOCATIONS);
FishingBuddyOptionSLZ:Hide();
FishingBuddy.SetSetting("GroupByLocation", 0);
else
FishingLocationsSwitchButton:SetText(FishingBuddy.SHOWFISHIES);
FishingBuddyOptionSLZ:Show();
FishingBuddy.SetSetting("GroupByLocation", 1);
end
FishingBuddy.Locations.DisplayChanged();
end
FishingBuddy.Locations.SwitchButton_OnEnter = function()
if ( FishingBuddy.GetSetting("GroupByLocation") == 1 ) then
GameTooltip:SetText(FishingBuddy.SHOWFISHIES_INFO);
else
GameTooltip:SetText(FishingBuddy.SHOWLOCATIONS_INFO);
end
GameTooltip:Show();
end
FishingBuddy.Locations.OnLoad = function()
this:RegisterEvent("VARIABLES_LOADED");
FishingLocationsSwitchButton:SetText(FishingBuddy.SHOWFISHIES);
-- Set up checkbox
FishingBuddyOptionSLZ.name = "ShowLocationZones";
FishingBuddyOptionSLZ.text = FishingBuddy.CONFIG_SHOWLOCATIONZONES_ONOFF;
FishingBuddyOptionSLZ.tooltip = FishingBuddy.CONFIG_SHOWLOCATIONZONES_INFO;
end
FishingBuddy.Locations.OnShow = function()
if ( FishingBuddy.IsLoaded() ) then
FishingBuddy.Locations.Update();
end
end
FishingBuddy.Locations.OnEvent = function()
-- this crashes the client when enabled
-- this:EnableMouseWheel(0);
end
FishingBuddy.FishCount = function(zone, subzone)
local count = 0;
local total = 0;
local fh = FishingBuddy_Info["FishingHoles"];
if( fh[zone] and fh[zone][subzone] ) then
for fishie in fh[zone][subzone] do
count = count + 1;
total = total + fh[zone][subzone][fishie];
end
end
return count, total;
end
FishingBuddy.Locations.DataChanged = function(zone, subzone, fishie)
FishingLocationsFrame.valid = false;
end