vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2 local sets = {};
3 local frames = {};
4  
5 -- state function
6 local current_locx_xact, current_locy_xact;
7 local current_frame, current_viewframe;
8 local binsert;
9  
10 local nilfunc = function () end
11 local emptylist = {};
12  
13 function YAPoints_RegisterSet(set)
14 sets[set.name] = set;
15 end
16  
17 function YAPoints_RegisterFrame(...)
18 frames[arg[1]] = 0;
19 end
20  
21 function YAPoints_ForceUpdate(frame)
22 if( not frame) then
23 for h,v in pairs(frames) do
24 YAPoints_OnMapChange(getglobal(h));
25 end
26 else
27 YAPoints_OnMapChange(frame);
28 end
29 end
30  
31 function YAPoints_OnMapChange(frame)
32 local lm = frame:GetName();
33  
34 -- clear all points
35 local h = 1;
36 while h > 0 do
37 local point = getglobal(lm.."Point"..h);
38 if(point) then
39 point:Clear();
40 h = h + 1;
41 else
42 h = 0;
43 end
44 end
45  
46 local pd_resetlist = getglobal(frame.YA_PD_ResetList);
47 if(pd_resetlist) then pd_resetlist(); end
48  
49 -- store all points for this map
50 frame.points = {};
51 current_frame = frame;
52 for h,v in pairs(sets) do
53 if(v.getpoints) then
54 v.getpoints(h, YatlasOptions.Frames[lm].Map);
55 end
56 end
57  
58 -- handle mobile points here to.
59 -- Keep in mind, mobile points shouldn't be updated here specifically,
60 -- but it gets the job done.
61 frame.mobilepoints = {};
62 frame.nextmobilepoint = 1;
63 if(frame.mobilepointframes == nil) then frame.mobilepointframes = {} end
64 for h,v in pairs(sets) do
65 if(v.getmobilepoints) then
66 v.getmobilepoints(h);
67 end
68 end
69  
70 for id,mp in pairs(frame.mobilepoints) do
71 if(mp.locMap ~= map or not mp.locMap) then
72 mp:Hide();
73 end
74 end
75  
76 -- force update
77 frame.yap_lastx = nil;
78 YAPoints_OnMove(frame, unpack(YatlasOptions.Frames[lm].Location));
79 end
80  
81 function YAPoints_OnMove(frame, x, y)
82 local lm = frame:GetName();
83  
84 if(frames[lm] == 0) then
85 frames[lm] = 1;
86 return YAPoints_OnMapChange(frame);
87 end
88  
89 -- if we have run at this x, y coord recently, don't do it again
90 if(frame.yap_lastx == x and frame.yap_lasty == y) then
91 -- no change
92 return;
93 end
94  
95 -- update normal points and unit points
96 YAPoints_Update(frame, x, y);
97 -- YAPoints_UpdateP(frame);
98  
99 -- hide/update mobile points as needed
100 for id,mp in pairs(frame.mobilepoints) do
101 if(mp:IsShown()) then
102 mp:Update(frame);
103 end
104 end
105  
106 frame.yap_lasty = y;
107 frame.yap_lastx = x;
108 end
109  
110 function YAPoints_OnUpdate(frame, ela)
111 local lm = frame:GetName();
112  
113 for h,v in pairs(sets) do
114 if(v.OnUpdate) then
115 v.OnUpdate(h, frame, ela);
116 end
117 end
118 end
119  
120 function YAPoints_Update(frame, x, y)
121 local lm = frame:GetName();
122 local flr,cei=math.floor,math.ceil;
123 local z = frame:GetZoom();
124 local hpoint = 1;
125 local legend = {};
126  
127 if(x == nil) then
128 x = YatlasOptions.Frames[lm].Location[1];
129 y = YatlasOptions.Frames[lm].Location[2];
130 end
131 current_locx_xact = x;
132 current_locy_xact = y;
133  
134 current_frame = frame;
135 current_viewframe = getglobal(lm.."ViewFrame");
136  
137 -- ensure that we have loaded the points already
138 if(frame.points == nil) then
139 return YAPoints_OnMapChange(frame);
140 end
141  
142 -- clear all points
143 for h, point in ipairs(frame.pointframes) do
144 if(point and point:IsShown()) then
145 point:Clear();
146 end
147 end
148  
149 -- init vispoints
150 frame.vispoints = {};
151 for h,v in pairs(sets) do
152 frame.vispoints[h] = {};
153 end
154  
155 -- fill vispoints
156 for xv = flr(x),cei(x+current_viewframe:GetWidth()/z),1 do
157 if(frame.points[xv] ~= nil) then
158 for yv = flr(y),cei(y+current_viewframe:GetHeight()/z),1 do
159 if(frame.points[xv][yv] ~= nil) then
160 for k,vv in pairs(frame.points[xv][yv]) do
161 if(vv.x > x and vv.y > y and
162 vv.x < x+current_viewframe:GetWidth()/z and
163 vv.y < y+current_viewframe:GetHeight()/z) then
164 binsert(frame.vispoints[vv.setname], vv);
165 end
166 end
167 end
168 end
169 end
170 end
171  
172 local env = {
173 current_lm = lm,
174 current_frame = current_frame,
175 zoom = z,
176 iconsize = YatlasOptions.Frames[lm].IconSize
177 };
178  
179 -- draw visible points
180 frame._common_pd = {};
181 local id = 1;
182 for hset,set in pairs(frame.vispoints) do
183 local showornotfunc = sets[hset].showme;
184 local pointfunc = sets[hset].setuppoint;
185 local legendfunc = sets[hset].setuplegend;
186  
187 for hval,val in pairs(set) do
188 local point = YAPoints_GetPoint(frame, hpoint);
189 local showmemaybe =
190 (not showornotfunc and not YatlasOptions.Frames[lm].PointCfg[val.setsubname]) or
191 (showornotfunc and showornotfunc(val, lm) );
192  
193  
194 if(point and showmemaybe) then
195  
196 if(not val.options.commonpd) then
197 val.id = id;
198 id = id + 1;
199 end
200  
201 point:Clear();
202 point:Show();
203  
204 -- this gets changed around a lot
205 env.iconsize = YatlasOptions.Frames[lm].IconSize;
206  
207 -- call functions
208 point.dat = val;
209 if(pointfunc) then
210 pointfunc(point, env, val);
211 end
212 elseif(point) then
213 hpoint = hpoint-1;
214 end
215  
216 hpoint = hpoint + 1;
217 end
218 end
219 end
220  
221 function YAPoints_GetPoint(frame, id)
222 -- does point exist??
223 if(frame.pointframes[id]) then
224 return frame.pointframes[id];
225 end
226  
227 if(id > 4096) then
228 -- this is too big by far
229 return;
230 end
231  
232 -- create
233 local viewframe = getglobal(frame:GetName().."ViewFrame");
234 local f = CreateFrame("Button");
235  
236 f:SetHeight(16);
237 f:SetWidth(16);
238 f:SetParent(viewframe);
239 f:EnableMouse(true);
240  
241 f.Icon = f:CreateTexture(nil, "OVERLAY");
242 f.Icon:SetPoint("TOPLEFT", f);
243  
244 f.Foreground = f:CreateFontString(nil, "ARTWORK");
245 f.Foreground:SetFontObject(GameFontHighlight);
246 f.Foreground:SetTextColor(0, 0, 0);
247 f.Foreground:SetShadowOffset(-1, 0);
248 f.Foreground:SetPoint("TOPLEFT", f);
249  
250 f:SetFrameLevel(f:GetFrameLevel() + 4);
251 f.Clear = YP_Clear;
252 f.SetOffset = YP_SetOffset;
253  
254 f:SetScript("OnEnter", YP_OnEnter);
255  
256 frame.pointframes[id] = f;
257 return f;
258 end
259  
260 function YAPoints_AllocMobilePoint(frame, id)
261 -- does point exist??
262 if(frame.mobilepointframes[id]) then
263 return frame.mobilepointframes[id];
264 end
265  
266 if(id > 1024) then
267 -- this is too big by far
268 return;
269 end
270  
271 -- create
272 local viewframe = getglobal(frame:GetName().."ViewFrame");
273 local f = CreateFrame("Button");
274  
275 f:SetHeight(16);
276 f:SetWidth(16);
277 f:SetParent(viewframe);
278 f:EnableMouse(true);
279  
280 f.Icon = f:CreateTexture(nil, "OVERLAY");
281 f.Icon:SetPoint("TOPLEFT", f);
282  
283 f.Foreground = f:CreateFontString(nil, "ARTWORK");
284 f.Foreground:SetFontObject(GameFontHighlight);
285 f.Foreground:SetTextColor(0, 0, 0);
286 f.Foreground:SetShadowOffset(-1, 0);
287 f.Foreground:SetPoint("TOPLEFT", f);
288  
289 f:SetFrameLevel(f:GetFrameLevel() + 4);
290 f.Clear = YP_Clear;
291 f.SetOffset = YP_SetOffset;
292 f.Update = YMP_Update;
293  
294 f:SetScript("OnEnter", YP_OnEnter);
295  
296 frame.mobilepointframes[id] = f;
297 return f;
298 end
299  
300 function YAPoints_UpdateTooltip(frame, tooltip, point, op)
301 local dat = point.dat;
302 local lm = frame:GetName();
303  
304 if(not tooltip.points) then
305 tooltip.points = {};
306 end
307  
308 if(op == "add") then
309 if(point.intooltip == nil) then
310 tinsert(tooltip.points, point);
311  
312 point.intooltip = 1;
313 end
314 elseif(op == "remove") then
315 for h,v in ipairs(tooltip.points) do
316 if(v == point) then
317 tremove(tooltip.points, h);
318 break;
319 end
320 end
321  
322 point.intooltip = nil;
323 else
324 -- ???
325 end
326  
327 local env = {
328 current_lm = lm,
329 current_frame = frame,
330 zoom = frame:GetZoom(),
331 iconsize = 14,
332 islegend = true,
333 };
334  
335 if(tooltip.points[1]) then
336 local vf = getglobal(lm.."ViewFrame");
337 tooltip:Clear();
338 for h,point in ipairs(tooltip.points) do
339 local legendfunc = sets[point.dat.setname].setuplegend;
340 if(legendfunc) then
341 local legend = tooltip:GetNext();
342 legendfunc(legend, env, point.dat);
343 end
344 -- tooltip:AddDataPoint(point.dat.name);
345 end
346 tooltip:Show();
347 else
348 tooltip:Hide();
349 end
350 end
351  
352 function YAPoints_showmeornot(frame, val)
353 local showornotfunc = sets[val.setname].showme;
354  
355 if(type(frame) ~= "string") then
356 frame = frame:GetName();
357 end
358  
359 return
360 (not showornotfunc and not YatlasOptions.Frames[frame].PointCfg[val.setsubname]) or
361 (showornotfunc and showornotfunc(val, frame) );
362 end
363  
364 ---
365 --- point OO implementation
366 ---
367  
368 function YP_Clear(point)
369 point:Hide();
370 point:ClearAllPoints();
371 point:SetPoint("TOPLEFT", point:GetParent());
372 point.Icon:SetTexture(nil);
373 point.Icon:SetTexCoord(0, 1, 0, 1);
374 point.Foreground:SetText("");
375 end
376  
377 function YP_SetOffset(point, x, y)
378 local z = current_frame:GetZoom();
379 local lm = current_frame:GetName();
380 local iconsz = YatlasOptions.Frames[lm].IconSize;
381  
382 point:ClearAllPoints();
383 point:SetPoint("TOPLEFT", current_viewframe, "TOPLEFT",
384 -(current_locx_xact - x)*z - iconsz/2,
385 (current_locy_xact - y)*z + iconsz/2);
386 end
387  
388 function YP_OnEnter()
389 local vf = this:GetParent();
390 local f = vf:GetParent();
391 local tp = getglobal(f.hoverTooltip);
392  
393 vf.inpoint = true;
394 if(tp and tp.knownshownlines == nil) then
395 tp.knownshownlines = 0;
396 end
397  
398 end
399  
400  
401 function YatlasFrameViewFrame_UpdatePointTooltip()
402 local f = this:GetParent();
403 local tp = getglobal(f.hoverTooltip);
404  
405 for h,v in pairs(f.pointframes) do
406 if(v.intooltip and not MouseIsOver(v)) then
407 YAPoints_UpdateTooltip(f, tp, v, "remove");
408 tp.knownshownlines = tp.knownshownlines - 1;
409 elseif(not v.intooltip and MouseIsOver(v)) then
410 YAPoints_UpdateTooltip(f, tp, v, "add");
411 tp.knownshownlines = tp.knownshownlines + 1;
412 end
413 end
414  
415 for h,v in pairs(f.mobilepointframes) do
416 if(v.intooltip and not MouseIsOver(v)) then
417 YAPoints_UpdateTooltip(f, tp, v, "remove");
418 tp.knownshownlines = tp.knownshownlines - 1;
419 elseif(not v.intooltip and MouseIsOver(v) and v:IsShown()) then
420 YAPoints_UpdateTooltip(f, tp, v, "add");
421 tp.knownshownlines = tp.knownshownlines + 1;
422 end
423 end
424  
425 if(tp.knownshownlines == 0) then
426 this.inpoint = nil;
427 end
428 end
429  
430 ---
431 ---
432 ---
433  
434 function YAPoints_AddPoint(frame, setname, name, x, y, options, userdat)
435 local tab = {
436 setname = setname,
437 name = name,
438 x = x, y = y,
439 options = options,
440 userdat = userdat
441 };
442  
443 if(tab.options == nil) then
444 tab.options = emptylist;
445 end
446  
447 if(options and options.setsubname) then
448 tab.setsubname = options.setsubname;
449 else
450 tab.setsubname = tab.setname;
451 end
452  
453 if(type(frame) ~= "table") then
454 frame = current_frame;
455 end
456  
457 local fx = math.floor(x);
458 local fy = math.floor(y);
459  
460 if(frame.points[fx] == nil) then frame.points[fx] = {}; end
461 if(frame.points[fx][fy] == nil) then frame.points[fx][fy] = {}; end
462  
463 tinsert(frame.points[fx][fy], tab);
464 end
465  
466 function YAPoints_AddMobilePoint(frame, setname, name, opt, userdat)
467 local tab = {
468 setname = setname,
469 name = name,
470 options = opt,
471 userdat = userdat
472 };
473  
474 if(tab.options == nil) then
475 tab.options = emptylist;
476 end
477  
478 if(options and options.setsubname) then
479 tab.setsubname = options.setsubname;
480 else
481 tab.setsubname = tab.setname;
482 end
483  
484 if(type(frame) ~= "table") then
485 frame = current_frame;
486 end
487  
488 point = YAPoints_AllocMobilePoint(frame, frame.nextmobilepoint);
489 point.dat = tab;
490 frame.nextmobilepoint = frame.nextmobilepoint + 1;
491  
492 frame.mobilepoints[setname..":"..name] = point;
493 return getn(frame.mobilepoints);
494 end
495  
496 function YAPoints_Mobile_SetLocation(setname, name, map, x, y)
497 for framename,v in pairs(frames) do
498 local frame = getglobal(framename);
499 if(frame:IsVisible()) then
500 local d = frame.mobilepoints[setname..":"..name];
501 d.locx = x;
502 d.locy = y;
503 d.locmap = map;
504 d:Update(frame);
505 end
506 end
507 end
508  
509 function YAPoints_SetupMobilePoint(setname, name, itahm, prop, ...)
510 local whut;
511  
512 for framename,v in pairs(frames) do
513 local frame = getglobal(framename);
514 whut = frame.mobilepoints[setname..":"..name][itahm];
515 whut[prop](whut, unpack(arg));
516 end
517 end
518  
519 function YAPoints_SetupMobilePointF(frame, setname, name, itahm, prop, ...)
520 local whut;
521  
522 if(type(frame) ~= "table") then
523 frame = current_frame;
524 end
525  
526 whut = frame.mobilepoints[setname..":"..name][itahm];
527 whut[prop](whut, unpack(arg));
528 end
529  
530 function YAPoints_HideMobile(setname, name)
531 for framename,v in pairs(frames) do
532 local frame = getglobal(framename);
533 if(frame:IsVisible()) then
534 local d = frame.mobilepoints[setname..":"..name];
535 d.locmap = nil;
536 d:Update(frame);
537 end
538 end
539 end
540  
541 function YMP_Update(point, frame)
542 local zoom = frame:GetZoom();
543 local vf = getglobal(frame:GetName().."ViewFrame")
544 local map = frame:GetMap();
545 local minx, miny = frame:GetLocation();
546 local maxx, maxy = minx + vf:GetWidth()/zoom, miny + vf:GetHeight()/zoom;
547  
548 if(map == point.locmap and
549 point.locx > minx and point.locx < maxx and
550 point.locy > miny and point.locy < maxy) then
551 point:SetOffset(point.locx, point.locy);
552 point:Show();
553 else
554 point:Hide();
555 end
556 end
557  
558  
559 ---
560 --- YFOO: pulldown to control what points are shown. name has some
561 --- historical significance
562 ---
563  
564 function YFOO_Init(frame)
565 if(not frame) then
566 frame = this;
567 end
568  
569 UIDropDownMenu_Initialize(frame, YFOODropDown_Initialize, "MENU");
570 UIDropDownMenu_SetButtonWidth(50,frame);
571 UIDropDownMenu_SetWidth(50,frame);
572 end
573  
574 function YFOODropDown_Initialize()
575 local func;
576  
577 if(current_frame == nil) then
578 return;
579 end
580  
581 local lm = current_frame:GetName();
582  
583 if(UIDROPDOWNMENU_MENU_LEVEL == 1) then
584 local info = {};
585 info.text = YATLAS_POINTS_SHOWPOINTS_TITLE;
586 info.notClickable = 1;
587 info.isTitle = 1;
588 info.notCheckable = 1;
589 UIDropDownMenu_AddButton(info);
590 end
591  
592 if(YatlasOptions.Frames and YatlasOptions.Frames[lm]) then
593 for h,v in pairs(sets) do
594 func = v.configmenu;
595 if(func) then
596 func(h, lm);
597 end
598 end
599 end
600 end
601  
602 function YFOO_OnClick()
603 current_frame = this;
604 while(current_frame and not current_frame.SetLocation) do
605 current_frame = current_frame:GetParent()
606 end
607  
608 if(current_frame:GetName() == "BigYatlasFrame") then
609 BigYatlasTooltip:Hide();
610 end
611  
612 ToggleDropDownMenu(1, nil, getglobal(this:GetName().."DropDown"), this:GetName(), 0, 0);
613 end
614  
615 function YFOODropDown_do_toggle_normal()
616 YatlasOptions.Frames[current_frame:GetName()].PointCfg[this.value] = UIDropDownMenuButton_GetChecked()
617 YAPoints_ForceUpdate(current_frame)
618 end
619  
620 ---
621 --- misc
622 ---
623  
624 -- based on code by ???
625 binsert = function( t, val)
626 local iStart, iEnd, iMid, iState = 1, table.getn( t ), 1, 0
627  
628 -- Get Insertposition
629 while iStart <= iEnd do
630  
631 -- calculate middle
632 iMid = math.floor( ( iStart + iEnd )/2 )
633  
634 -- compare
635 if val.name <= t[iMid].name then
636 iEnd = iMid - 1
637 iState = 0
638 else
639 iStart = iMid + 1
640 iState = 1
641 end
642 end
643  
644 table.insert( t, ( iMid+iState ), val )
645 end