vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Display the fish you're catching and/or have caught in a live display
2  
3 FishingBuddy.WatchFrame = {};
4  
5 local MAX_FISHINGWATCH_LINES = 20;
6 local WATCHDRAGGER_SHOW_DELAY = 0.2;
7  
8 local WATCHDRAGGER_FADE_TIME = 0.15;
9  
10 local DRAGFRAME_TEXTURES = {
11 "Background",
12 "TopLeft",
13 "TopRight",
14 "BottomLeft",
15 "BottomRight",
16 "Top",
17 "Bottom",
18 "Left",
19 "Right"
20 };
21  
22 local function ShowDraggerFrame()
23 if ( not FishingWatchDragFrame:IsVisible() ) then
24 local width = FishingWatchFrame:GetWidth();
25 local height = FishingWatchFrame:GetHeight();
26 FishingWatchDragFrame:SetHeight(height);
27 FishingWatchDragFrame:SetWidth(width);
28 FishingWatchDragFrame:Show();
29 for index, value in DRAGFRAME_TEXTURES do
30 UIFrameFadeIn(getglobal("FishingWatchDragFrame"..value), WATCHDRAGGER_FADE_TIME, 0, 0.25);
31 end
32 end
33 end
34  
35 local function HideDraggerFrame()
36 if ( FishingWatchDragFrame:IsVisible() ) then
37 for index, value in DRAGFRAME_TEXTURES do
38 UIFrameFadeOut(getglobal("FishingWatchDragFrame"..value), WATCHDRAGGER_FADE_TIME, 0.25, 0);
39 end
40 FishingWatchDragFrame:Hide();
41 local qx, qy = UIParent:GetCenter();
42 local wx, wy = FishingWatchDragFrame:GetCenter();
43 local where = {};
44 where.x = qx - wx;
45 where.y = wy - qy;
46 FishingBuddy.SetSetting("WatcherLocation", where);
47 end
48 end
49  
50 FishingBuddy.Commands[FishingBuddy.WATCHER] = {};
51 FishingBuddy.Commands[FishingBuddy.WATCHER].help = FishingBuddy.WATCHER_HELP;
52 FishingBuddy.Commands[FishingBuddy.WATCHER].func =
53 function(what)
54 if ( what and ( what == FishingBuddy.RESET ) ) then
55 FishingWatchDragFrame:ClearAllPoints();
56 FishingWatchDragFrame:SetPoint("CENTER", "UIParent",
57 "CENTER", 0, 0);
58 FishingWatchDragFrame:Hide();
59 FishingBuddy.SetSetting("WatcherLocation", nil);
60 return true;
61 end
62 end;
63  
64 -- handle really old versions
65 local function UpdateUnknownZones(zone, subzone)
66 if ( FishingBuddy_Info["FishingHoles"][FishingBuddy.UNKNOWN] ) then
67 if ( FishingBuddy_Info["FishingHoles"][FishingBuddy.UNKNOWN][subzone] ) then
68 if ( not FishingBuddy_Info["FishingHoles"][zone] ) then
69 FishingBuddy_Info["FishingHoles"][zone] = { };
70 tinsert(FishingBuddy.SortedZones, zone);
71 table.sort(FishingBuddy.SortedZones);
72 end
73 if ( not FishingBuddy_Info["FishingHoles"][zone][subzone] ) then
74 FishingBuddy_Info["FishingHoles"][zone][subzone] = { };
75 end
76 for k,v in FishingBuddy_Info["FishingHoles"][FishingBuddy.UNKNOWN][subzone] do
77 FishingBuddy_Info["FishingHoles"][zone][subzone][k] = v;
78 end
79 FishingBuddy_Info["FishingHoles"][FishingBuddy.UNKNOWN][subzone] = nil;
80 end
81 FishingBuddy.Locations.DataChanged(zone, subzone);
82 -- Duh, table.getn doesn't work because there aren't any integer
83 -- keys in this table
84 if ( next(FishingBuddy_Info["FishingHoles"][FishingBuddy.UNKNOWN]) == nil ) then
85 FishingBuddy_Info["FishingHoles"][FishingBuddy.UNKNOWN] = nil;
86 local pos;
87 while ( pos < table.getn(FishingBuddy.SortedZones) ) do
88 if ( FishingBuddy.SortedZones[pos] == FishingBuddy.UNKNOWN ) then
89 break;
90 end
91 pos = pos + 1;
92 end
93 tremove(FishingBuddy.SortedZones, pos);
94 end
95 end
96 end
97  
98 -- fix a bug where we were recording 'GetZoneText' instead
99 -- of 'GetRealZoneText'
100 local function UpdateRealZones(zone, subzone)
101 local oldzone = GetZoneText();
102 if ( FishingBuddy_Info["FishingHoles"][oldzone] and oldzone ~= zone ) then
103 if ( not FishingBuddy_Info["FishingHoles"][zone] ) then
104 FishingBuddy_Info["FishingHoles"][zone] = { };
105 end
106 for oldsubzone in FishingBuddy_Info["FishingHoles"][oldzone] do
107 local sub = oldsubzone;
108 if ( oldsubzone == oldzone ) then
109 sub = subzone;
110 end
111 if ( not FishingBuddy_Info["FishingHoles"][zone][sub] ) then
112 FishingBuddy_Info["FishingHoles"][zone][sub] = {};
113 end
114 for k,v in FishingBuddy_Info["FishingHoles"][oldzone][oldsubzone] do
115 FishingBuddy_Info["FishingHoles"][zone][sub][k] = v;
116 end
117 end
118 FishingBuddy_Info["FishingHoles"][oldzone] = nil;
119 end
120 end
121  
122 -- Fish watcher functions
123 FishingBuddy.WatchUpdate = function()
124 if ( FishingWatchFrame:IsVisible() ) then
125 FishingWatchFrame:Hide();
126 for i=1, MAX_FISHINGWATCH_LINES, 1 do
127 local line = getglobal("FishingWatchLine"..i);
128 line:Hide();
129 end
130 end
131  
132 local zone, subzone = FishingBuddy.GetZoneInfo();
133  
134 UpdateUnknownZones(zone, subzone);
135 UpdateRealZones(zone, subzone);
136  
137 local fz = FishingBuddy_Info["FishingHoles"][zone];
138 if ( FishingBuddy.GetSetting("WatchFishies") == 0 or
139 not fz or not fz[subzone] ) then
140 return;
141 end
142  
143 if ( FishingBuddy.GetSetting("WatchOnlyWhenFishing") == 1 and
144 not FishingBuddy.IsFishingPole() ) then
145 return;
146 end
147  
148 local current = FishingBuddy.currentFishies;
149 local ff = FishingBuddy_Info["Fishies"];
150 local fishsort = {};
151 local totalCount = 0;
152 local totalCurrent = 0;
153 local gotDiffs = false;
154 for fishid in fz[subzone] do
155 local info = {};
156 info.text = ff[fishid].name;
157 info.count = fz[subzone][fishid];
158 totalCount = totalCount + info.count;
159 if ( current[subzone] ) then
160 info.current = current[subzone][fishid] or 0;
161 else
162 info.current = 0;
163 end
164 if ( info.current > 0 and info.current ~= info.count ) then
165 gotDiffs = true;
166 end
167 totalCurrent = totalCurrent + info.current;
168 tinsert(fishsort, info);
169 end
170  
171 if ( totalCount == 0 ) then
172 return;
173 end
174  
175 FishingBuddy.FishSort(fishsort);
176  
177 local fishingWatchMaxWidth = 0;
178 local tempWidth;
179 local index = 1;
180 local start = 1;
181 local dopercent = FishingBuddy.GetSetting("WatchFishPercent");
182  
183 if ( FishingBuddy.GetSetting("WatchCurrentZone") == 1 ) then
184 local entry = getglobal("FishingWatchLine"..index);
185 local line = zone.." : "..subzone;
186 entry:SetText(line);
187 local tempWidth = entry:GetWidth();
188 if ( tempWidth > fishingWatchMaxWidth ) then
189 fishingWatchMaxWidth = tempWidth;
190 end
191 entry:Show();
192 index = index + 1;
193 end
194 if ( FishingBuddy.GetSetting("WatchCurrentSkill") == 1 ) then
195 local entry = getglobal("FishingWatchLine"..index);
196 local skill, mods = FishingBuddy.GetCurrentSkill();
197 local line = "Skill: |cff00ff00"..skill.."+"..mods.."|r";
198 if ( StartedFishing ) then
199 local elapsed = GetTime() - StartedFishing;
200 local t = math.floor(elapsed);
201 local seconds = math.mod(t, 60);
202 t = math.floor(t / 60);
203 local minutes = math.mod(t, 60);
204 local hours = math.floor(t / 60);
205 line = line.." Elapsed: ";
206 if ( hours < 10 ) then
207 line = line.."0";
208 end
209 line = line..hours..":";
210 if ( minutes < 10 ) then
211 line = line.."0";
212 end
213 line = line..minutes..":";
214 if ( seconds < 10 ) then
215 line = line.."0";
216 end
217 line = line..seconds;
218 end
219  
220 entry:SetText(line);
221 local tempWidth = entry:GetWidth();
222 if ( tempWidth > fishingWatchMaxWidth ) then
223 fishingWatchMaxWidth = tempWidth;
224 end
225 entry:Show();
226 index = index + 1;
227 end
228  
229 for j=1,table.getn(fishsort),1 do
230 local info = fishsort[j];
231 if( index <= MAX_FISHINGWATCH_LINES ) then
232 local entry = getglobal("FishingWatchLine"..index);
233 local fishie = info.text;
234 local amount = info.count;
235 local s,e = string.find(fishie, FishingBuddy.RAW.." ");
236 if ( s ) then
237 if ( s > 1 ) then
238 fishie = string.sub(fishie, 1, s-1)..string.sub(fishie, e+1);
239 else
240 fishie = string.sub(fishie, e+1);
241 end
242 else
243 s,e = string.find(fishie, " "..FishingBuddy.RAW);
244 if ( s ) then
245 fishie = string.sub(fishie, 1, s-1)..string.sub(fishie, e+1);
246 end
247 end
248 local fishietext = fishie.." ("..amount;
249 if ( dopercent == 1 ) then
250 local percent = format("%.1f", ( amount / totalCount ) * 100);
251 fishietext = fishietext.." : "..percent.."%";
252 end
253 if ( gotDiffs ) then
254 amount = info.current;
255 local color;
256 fishietext = fishietext..", |c"..FishingBuddy.Colors.GREEN..amount;
257 if ( dopercent == 1 ) then
258 local percent = format("%.1f", ( amount / totalCurrent ) * 100);
259 fishietext = fishietext.." : "..percent.."%";
260 end
261 fishietext = fishietext.."|r";
262 end
263 fishietext = fishietext..")";
264 entry:SetText(fishietext);
265 tempWidth = entry:GetWidth();
266 entry:Show();
267 if ( tempWidth > fishingWatchMaxWidth ) then
268 fishingWatchMaxWidth = tempWidth;
269 end
270 end
271 index = index + 1;
272 end
273  
274 FishingWatchFrame:SetHeight(index * 13);
275 FishingWatchFrame:SetWidth(fishingWatchMaxWidth + 10);
276 FishingWatchFrame:Show();
277 end
278  
279 FishingBuddy.WatchFrame.OnLoad = function()
280 local where = FishingBuddy.GetSetting("WatcherLocation");
281 if ( not where ) then
282 where = {};
283 where.x = 0;
284 where.y = 0;
285 end
286 FishingWatchDragFrame:ClearAllPoints();
287 FishingWatchDragFrame:SetPoint("CENTER", "UIParent", "CENTER",
288 where.x, where.y);
289 FishingWatchDragFrame:Hide();
290  
291 this:ClearAllPoints();
292 this:SetPoint("TOPRIGHT", "FishingWatchDragFrame", "TOPRIGHT", 0, 0);
293 end
294  
295 local hover;
296 FishingBuddy.WatchFrame.OnUpdate = function(elapsed)
297 if ( FishingWatchFrame:IsVisible() ) then
298 if ( MouseIsOver(FishingWatchFrame) ) then
299 local xPos, yPos = GetCursorPosition();
300 if ( hover ) then
301 if ( hover.xPos == xPos and hover.yPos == yPos ) then
302 hover.hoverTime = hover.hoverTime + elapsed;
303 else
304 hover.hoverTime = 0;
305 hover.xPos = xPos;
306 hover.yPos = yPos;
307 end
308 else
309 hover = {};
310 hover.hoverTime = 0;
311 hover.xPos = xPos;
312 hover.yPos = yPos;
313 end
314 if ( hover.hoverTime > WATCHDRAGGER_SHOW_DELAY ) then
315 ShowDraggerFrame();
316 end
317 else
318 HideDraggerFrame();
319 hover = nil;
320 end
321 elseif ( hover ) then
322 HideDraggerFrame();
323 hover = nil;
324 end
325 end
326