vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2 local pre = "textures\\Minimap\\";
3  
4 local MINI2BIGX = 533.3333;
5 local MINI2BIGY = 533.3333;
6  
7 YatlasOptions = {}
8  
9 YA_FRAME_OPTION_DEFAULTS = {
10 ["Locked"] = true,
11 ["Map"] = "Kalimdor",
12 ["Location"] = {31.0625, 33.250},
13 ["Alpha"] = 1,
14 ["IconSize"] = 14,
15 ["PointCfg"] = {},
16 ["Zoom"] = 256,
17 };
18  
19 local dummyv = {nil, {0,256}};
20 local nilfunc = function() end
21  
22 YatlasFrameTemplate = {};
23  
24 function YatlasFrame_Bootstrap(frame)
25 if(frame == nil) then
26 frame = this;
27 end
28  
29 for h,v in pairs(YatlasFrameTemplate) do
30 if(frame[h]) then
31 frame["old_"..h] = frame[h];
32 end
33  
34 frame[h] = v;
35 end
36 frame:OnLoad();
37 end
38  
39 function YatlasFrameTemplate:OnLoad()
40 local lm = self:GetName();
41 local viewframe = getglobal(lm.."ViewFrame");
42  
43 self.texturelayout = {};
44 self.wzoom = 3;
45 self.hzoom = 3;
46 self.wzoom_real = 3;
47 self.hzoom_real = 3;
48 self.points = {};
49 self.pointframes = {};
50  
51 self:RegisterForDrag("LeftButton");
52 self:RegisterEvent("VARIABLES_LOADED");
53 self:RegisterEvent("ADDON_LOADED");
54 self:RegisterEvent("WORLD_MAP_UPDATE");
55 viewframe:RegisterForDrag("RightButton","LeftButton");
56 viewframe:EnableMouseWheel(true);
57  
58 YAPoints_RegisterFrame(self:GetName());
59  
60 self.update_time = 0;
61 end
62  
63 function YatlasFrame_OnLoadExtra()
64 YatlasFrame.OnEventExtra = YatlasFrame_OnEventExtra;
65 YatlasFrame.YA_PD_allocText = "YA_PD_allocText";
66 YatlasFrame.YA_PD_ResetList = "YA_PD_ResetList";
67  
68 SLASH_YATLAS1 = "/yatlas";
69 SlashCmdList["YATLAS"] = function() YatlasFrame:Toggle() end
70  
71 YatlasFrame.hoverTooltip = "YatlasTooltip";
72  
73 -- initalize zones
74 for h,v in pairs(Yatlas_WorldMapIds) do
75 Yatlas_PaperZoneNames[h] = {Yatlas_GetMapZones(h)};
76 end
77  
78 -- wrap mapnotes for updates
79 if(MapNotes_DeleteNote) then
80 YA_old_MapNotes_DeleteNote = MapNotes_DeleteNote;
81 MapNotes_DeleteNote = function(...)
82 local v = YA_old_MapNotes_DeleteNote(unpack(arg))
83 YAPoints_ForceUpdate();
84 return v;
85 end
86 YA_old_MapNotes_WriteNote = MapNotes_WriteNote;
87 MapNotes_WriteNote = function(...)
88 local v = YA_old_MapNotes_WriteNote(unpack(arg));
89 YAPoints_ForceUpdate();
90 return v;
91 end
92 end
93  
94 -- wrap gatherer
95 if(Gatherer_AddGatherHere) then
96 YA_old_Gatherer_AddGatherHere = Gatherer_AddGatherHere;
97 Gatherer_AddGatherHere = function(...)
98 local v = YA_old_Gatherer_AddGatherHere(unpack(arg))
99 YAPoints_ForceUpdate();
100 return v;
101 end
102 end
103  
104 -- myaddons support
105 YatlasDetails = {
106 name = YATLAS_TITLE,
107 version = YATLAS_VERSION,
108 releaseDate = YATLAS_RELEASE_DATE,
109 author = YATLAS_AUTHOR,
110 website = YATLAS_WEBSITE,
111 email = YATLAS_AUTHOR_EMAIL,
112 category = MYADDONS_CATEGORY_MAP,
113 };
114 YatlasMAHelp = YATLAS_HELP_TEXT;
115 end
116  
117 function BigYatlasFrame_OnLoadExtra()
118 UIPanelWindows["BigYatlasFrame"] = { area = "full", pushable = 0, whileDead = 1 };
119  
120 SLASH_BIGYATLAS1 = "/bigyatlas";
121 SlashCmdList["BIGYATLAS"] = function() BigYatlasFrame:Toggle() end
122  
123 BigYatlasFrame.RawBigShow = BigYatlasFrame.Show;
124 BigYatlasFrame.Show = function(self)
125 SetupFullscreenScale(self);
126 return self:RawBigShow();
127 end
128  
129 BigYatlasFrame.hoverTooltip = "BigYatlasTooltip";
130 end
131  
132 function YatlasFrameTemplate:OnEvent(event)
133 local framename = self:GetName();
134  
135 if(event == "VARIABLES_LOADED") then
136 if(YatlasOptions == nil) then
137 YatlasOptions = {};
138 end
139  
140 if(YatlasOptions.ShowButton == nil) then
141 YatlasOptions.ShowButton = true;
142 end
143 if(YatlasOptions.ButtonLocation == nil) then
144 YatlasOptions.ButtonLocation = 0;
145 end
146  
147 self:EnsureExistingOptions();
148  
149 self.opt = YatlasOptions.Frames[framename];
150 self:SetZoom(self.opt.Zoom);
151 self:SetMap(self.opt.Map);
152  
153 self:UpdateLock();
154 self:SetAlpha(self.opt.Alpha);
155  
156 if(self.opt.track) then
157 YatlasFramePlayerJumpButton_Seek(this, self.opt.track);
158 end
159 elseif(event == "WORLD_MAP_UPDATE") then
160 self:OnWorldMapUpdate();
161 end
162  
163 if(self.OnEventExtra) then
164 self:OnEventExtra(event);
165 end
166 end
167  
168 function YatlasFrame_OnEventExtra(self, event)
169 local framename = self:GetName();
170  
171 if(event == "ADDON_LOADED" and arg1 == "Yatlas") then
172 if(myAddOnsFrame_Register) then
173 myAddOnsFrame_Register(YatlasDetails, YatlasMAHelp);
174 end
175 end
176 end
177  
178 function YatlasFrameTemplate:EnsureExistingOptions()
179 if(YatlasOptions.Frames == nil) then
180 YatlasOptions.Frames = {};
181 end
182  
183 local name = self:GetName();
184  
185 if(YatlasOptions.Frames[name] == nil) then
186 YatlasOptions.Frames[name] = {};
187 end
188  
189 for h,v in pairs(YA_FRAME_OPTION_DEFAULTS) do
190 if(YatlasOptions.Frames[name][h] ~= nil) then
191 -- don't do anything!
192 elseif(YatlasOptions[h] ~= nil) then
193 YatlasOptions.Frames[name][h] = YatlasOptions[h];
194 YatlasOptions[h] = nil;
195 elseif(type(v) == "table") then
196 -- don't copy reference. copy value...unfortunately, we only
197 -- copy one level deep, which seems good enough...
198 YatlasOptions.Frames[name][h] = {};
199 for x,k in pairs(v) do
200 YatlasOptions.Frames[name][h][x] = k;
201 end
202 else
203 YatlasOptions.Frames[name][h] = v;
204 end
205 end
206 end
207  
208 function YatlasFrameTemplate:Toggle()
209 local lm = self:GetName();
210  
211 if(UIPanelWindows[lm] == nil) then
212 if(self:IsShown()) then
213 self:Hide();
214 else
215 self:Show();
216 end
217 else
218 if (self:IsVisible() ) then
219 HideUIPanel(self);
220 else
221 -- SetupWorldMapScale();
222 ShowUIPanel(self);
223 end
224 end
225 end
226  
227 function YatlasFrameDropDown_OnLoad()
228 this:RegisterEvent("VARIABLES_LOADED");
229 end
230  
231 function YatlasFrameDropDown_OnEvent(event)
232 if(event == "VARIABLES_LOADED") then
233 UIDropDownMenu_Initialize(this, YatlasFrameDropDown_Initialize);
234 UIDropDownMenu_SetSelectedID(this, 1);
235 UIDropDownMenu_SetWidth(150);
236 end
237 end
238  
239 function YatlasFrameDropDown_Initialize()
240 local i = 1;
241 local info;
242 for h,v in pairs(YA_MAPS) do
243 info = {
244 text = h;
245 func = YatlasFrameDropDownButton_OnClick;
246 value = getglobal(UIDROPDOWNMENU_INIT_MENU):GetParent();
247 };
248 UIDropDownMenu_AddButton(info);
249 i = i + 1;
250 end
251 end
252  
253 function YatlasFrameDropDownButton_OnClick()
254 local d = 1;
255 i = this:GetID();
256 for h,v in pairs(YA_MAPS) do
257 if(d == i) then
258 return this.value:SetMap(v[1]);
259 end
260 d = d + 1;
261 end
262 end
263  
264 function YatlasFrameTemplate:ToggleLock()
265 if(self.opt.Locked) then
266 self.opt.Locked = false;
267 else
268 self.opt.Locked = true;
269 end
270 self:UpdateLock();
271 end
272  
273 function YatlasFrameTemplate:UpdateLock()
274 local fm = self:GetName();
275 local norm = getglobal(fm.."LockButtonNorm");
276 local push = getglobal(fm.."LockButtonPush");
277  
278 if(norm and push) then
279 if(self.opt.Locked) then
280 norm:SetTexture("Interface\\AddOns\\Yatlas\\images\\LockButton-Locked-Up");
281 push:SetTexture("Interface\\AddOns\\Yatlas\\images\\LockButton-Locked-Down");
282 else
283 norm:SetTexture("Interface\\AddOns\\Yatlas\\images\\LockButton-Unlocked-Up");
284 push:SetTexture("Interface\\AddOns\\Yatlas\\images\\LockButton-Unlocked-Down");
285 end
286 end
287 end
288  
289 function YatlasFrameTemplate:SetMap(mapname)
290 local lm = self:GetName();
291  
292 self.opt.Map = mapname;
293  
294 local mapdropdown = getglobal(lm.."DropDown");
295 if(mapdropdown) then
296 local i = 1;
297 for h,v in pairs(YA_MAPS) do
298 if(v[1] == mapname) then
299 UIDropDownMenu_SetSelectedID(mapdropdown, i);
300 UIDropDownMenu_SetText(h,mapdropdown);
301 end
302 i = i + 1;
303 end
304 end
305  
306 -- initialize zone pulldown
307 local mapdropdown2 = getglobal(lm.."DropDown2");
308 if(mapdropdown2) then
309 UIDropDownMenu_ClearAll(mapdropdown2);
310 UIDropDownMenu_Initialize(mapdropdown2, YatlasFrameDropDown2_Initialize);
311 end
312  
313 self:AdjustLocation(0,0,true);
314 YAPoints_OnMapChange(self);
315 self.lastmap = self.opt.Map;
316 end
317  
318 function YatlasFrameDropDown2_OnLoad()
319 this:RegisterEvent("VARIABLES_LOADED");
320 end
321  
322 function YatlasFrameDropDown2_OnEvent(event)
323 if(event == "VARIABLES_LOADED") then
324 UIDropDownMenu_SetWidth(150);
325 end
326 end
327  
328 function YatlasFrameDropDown2_Initialize()
329 local lm = string.gsub(UIDROPDOWNMENU_INIT_MENU,"DropDown2","");
330  
331 local frame = getglobal(lm);
332 frame.zonepulldowns = {};
333 local info;
334  
335 if(Yatlas_mapareas[frame.opt.Map] ~= nil) then
336 for h,v in pairs(Yatlas_mapareas[frame.opt.Map]) do
337 if(Yatlas_areadb[h]) then
338 tinsert(frame.zonepulldowns, h);
339 end
340 end
341 end
342  
343 table.sort(frame.zonepulldowns,
344 function (a,b) return Yatlas_areadb[a][2] < Yatlas_areadb[b][2]; end);
345 for j,v in ipairs(frame.zonepulldowns) do
346 info = {
347 text = Yatlas_areadb[v][2];
348 value = frame;
349 func = YatlasFrameDropDownButton2_OnClick;
350 };
351 UIDropDownMenu_AddButton(info);
352 end
353  
354 end
355  
356 function YatlasFrameDropDownButton2_OnClick()
357 local frame = this.value;
358 local lm = frame:GetName();
359 local z = frame.zonepulldowns[this:GetID()];
360 local map = frame.opt.Map;
361 local zoom = frame:GetZoom();
362  
363 if(not z or not Yatlas_mapareas[map]) then return; end
364  
365 if(type(Yatlas_mapareas[map][z]) == "table") then
366 local x, y, mx, my;
367  
368 x = (Yatlas_mapareas[map][z][1]+
369 Yatlas_mapareas[map][z][2])/2;
370 y = (Yatlas_mapareas[map][z][3]+
371 Yatlas_mapareas[map][z][4])/2;
372  
373 mx, my = Yatlas_Big2Mini_Coord(x,y);
374  
375 if(Yatlas_mapareas_adjust[z]) then
376 mx = Yatlas_mapareas_adjust[z][1] + mx;
377 my = Yatlas_mapareas_adjust[z][2] + my;
378 end
379  
380 frame:SetLocation(mx-(512/2)/zoom, my-(512/2)/zoom);
381 end
382 end
383  
384 function YatlasFrameTemplate:UpdateDropDown2()
385 local framename = self:GetName();
386 local vfname = framename.."ViewFrame";
387 local vf = getglobal(vfname);
388 local zoom = self.opt.Zoom;
389 local dd2 = getglobal(framename.."DropDown2");
390  
391 if(dd2 and self.zonepulldowns) then
392 -- FIXME this isn't quite right somehow!! (besides height/width being flipped)
393 local zid = self:GetZoneIDs((vf:GetHeight()/zoom/2),(vf:GetWidth()/zoom/2));
394 for i,v in ipairs(self.zonepulldowns) do
395 if(v == zid) then
396 UIDropDownMenu_SetSelectedID(dd2, i);
397 UIDropDownMenu_SetText(Yatlas_areadb[zid][2], dd2);
398 break;
399 end
400 end
401 end
402 end
403  
404 --
405  
406 function YatlasFramePlayerJumpButton_Toggle(btn)
407 local f = btn:GetParent();
408 local o = f.opt;
409 if(o.track) then
410 o.track = nil;
411 else
412 o.track = "player";
413 YatlasFramePlayerJumpButton_Seek(f, "player");
414 end
415  
416 YatlasFramePlayerJumpButton_Update(btn)
417 end
418  
419 function YatlasFramePlayerJumpButton_Jump(btn)
420 local f = btn:GetParent();
421 local o = f.opt;
422  
423 o.track = nil;
424 YatlasFramePlayerJumpButton_Seek(f, "player");
425  
426 YatlasFramePlayerJumpButton_Update(btn)
427 end
428  
429 function YatlasFramePlayerJumpButton_Seek(frame, unit)
430  
431 local i,v = next(Yatlas_WorldMapIds);
432  
433 frame.trackseek = unit;
434 frame.trackseek_state = i;
435  
436 if(GetMapInfo() == i) then
437 frame:OnWorldMapUpdate();
438 else
439 SetMapZoom(v);
440 end
441 end
442  
443 function YatlasFramePlayerJumpButton_Update(btn)
444 if(btn:GetParent() and btn:GetParent().opt) then
445 local t = btn:GetParent().opt.track;
446  
447 if(t) then
448 tex = "Interface\\Buttons\\UI-Panel-Button-Down";
449 else
450 tex = "Interface\\Buttons\\UI-Panel-Button-Up";
451 end
452 getglobal(btn:GetName().."Left"):SetTexture(tex);
453 getglobal(btn:GetName().."Middle"):SetTexture(tex);
454 getglobal(btn:GetName().."Right"):SetTexture(tex);
455 end
456 end
457  
458 function YatlasFrameTemplate:GetMap()
459 return self.opt.Map;
460 end
461  
462 function YatlasFrameTemplate:SetZoom(z, nocenter)
463 local textureno = 1;
464 local lm = self:GetName();
465 local vf = getglobal(lm.."ViewFrame");
466  
467 self.wzoom = math.floor(vf:GetWidth()/z)+1;
468 self.hzoom = math.floor(vf:GetHeight()/z)+1;
469 self.wzoom_real = math.ceil(vf:GetWidth()/z)+1;
470 self.hzoom_real = math.ceil(vf:GetHeight()/z)+1;
471  
472 if(getglobal(lm.."MapTexture"..(self.wzoom_real*self.hzoom_real)) == nil) then
473 return self:SetZoom(z+4);
474 elseif(z > vf:GetHeight() or z > vf:GetWidth()) then
475 return self:SetZoom(z-4);
476 end
477 local lastzoom = self.opt.Zoom;
478 self.opt.Zoom = z;
479  
480 -- allocate textures
481 self.texturelayout = {};
482 for hw = 1,self.wzoom_real do
483 self.texturelayout[hw] = {};
484 for hh = 1,self.hzoom_real do
485 self.texturelayout[hw][hh] = getglobal(lm.."MapTexture"..textureno);
486 self.texturelayout[hw][hh].hx = hw;
487 self.texturelayout[hw][hh].hy = hh;
488 textureno = textureno + 1;
489 end
490 end
491 while(getglobal(lm.."MapTexture"..textureno)) do
492 getglobal(lm.."MapTexture"..textureno):Hide();
493 textureno = textureno + 1;
494 end
495  
496 -- unclip all textures now, ESPECIALLY the middle textures
497 for hw = 1,self.wzoom_real do
498 for hh = 1,self.hzoom_real do
499 self.texturelayout[hw][hh]:Show();
500 self.texturelayout[hw][hh]:SetTexCoord(0, 1, 0, 1);
501 self.texturelayout[hw][hh]:SetHeight(z);
502 self.texturelayout[hw][hh]:SetWidth(z);
503 self.texturelayout[hw][hh].areaids = {};
504 end
505 end
506  
507 if(nocenter or lastzoom == z) then
508 self:AdjustLocation(0,0,true)
509 else
510 local oldcx, oldcy;
511 local newcx, newcy;
512  
513 oldcy = (vf:GetHeight()/2)/lastzoom;
514 oldcx = (vf:GetWidth()/2)/lastzoom;
515 newcy = (vf:GetHeight()/2)/z;
516 newcx = (vf:GetWidth()/2)/z;
517  
518 self:AdjustLocation(oldcx-newcx,-oldcy+newcy,true)
519 end
520 end
521  
522 function YatlasFrameTemplate:GetZoom()
523 return self.opt and self.opt.Zoom or 256;
524 end
525  
526 function YatlasFrameTemplate:SetLocation(x,y,forceupdate)
527 local zx, zy, mymap;
528 local framename = self:GetName();
529 local vfname = framename.."ViewFrame";
530 local vf = getglobal(vfname);
531 local texturelayout = self.texturelayout;
532 local zoom = self.opt.Zoom;
533 local wzoom, hzoom = self.wzoom,self.hzoom;
534 local wzoom_real,hzoom_real = self.wzoom_real, self.hzoom_real;
535  
536 zx = math.floor(x);
537 zy = math.floor(y);
538 mymap = self.opt.Map;
539  
540 -- offset calc
541 local px, py;
542 px = math.floor((x-zx)*zoom);
543 py = math.floor((y-zy)*zoom);
544  
545 if(zx ~= math.floor(self.opt.Location[1]) or forceupdate or
546 zy ~= math.floor(self.opt.Location[2]) or mymap ~= self.lastmap) then
547 local v = {};
548 local jx, jy, nsv;
549  
550 for hx = 1,wzoom_real do
551 v[hx] = {};
552 for hy = 1,hzoom_real do
553 local tex = texturelayout[hx][hy];
554  
555 -- get info
556 v[hx][hy] = Yatlas_mapdb1[mymap][format("%.2dx%.2d",zx+hx-1,zy+hy-1)];
557 if(v[hx][hy] == nil) then
558 v[hx][hy] = dummyv;
559 end
560  
561 -- save area info
562 tex.areaids = v[hx][hy][2];
563  
564 -- set textures
565 if(v[hx][hy][1]) then
566 tex:SetTexture(pre..v[hx][hy][1]);
567 tex:SetVertexColor(1,1,1,1);
568 else
569 tex:SetTexture("Interface\\Buttons\\WHITE8X8");
570 tex:SetVertexColor(0,0,0,1);
571 end
572 end
573 end
574 end
575  
576 -- Do offset and clipping (:SetTexCoord and :SetHeight/Width)
577 -- We do the most thinking about border textures
578  
579 local bottomh = vf:GetHeight()-zoom*(hzoom-2)-(zoom-py);
580 local rightw = vf:GetWidth()-zoom*(wzoom-2)-(zoom-px);
581 local needbottom_extra = false;
582 local needright_extra = false;
583 local old_bottomh, old_rightw;
584 if(bottomh > zoom) then
585 needbottom_extra = true;
586 old_bottomh = bottomh;
587 bottomh = zoom;
588 end
589 if(rightw > zoom) then
590 needright_extra = true;
591 old_rightw = rightw;
592 rightw = zoom;
593 end
594  
595 -- center textures (easy)
596 for w = 2,wzoom-1 do
597 for h = 2,hzoom-1 do
598 ya_raw_setoff(texturelayout[w][h],vfname,px,py);
599 end
600 end
601  
602 -- Upper left corner
603 texturelayout[1][1]:SetTexCoord( (x-zx), 1, (y-zy), 1);
604 texturelayout[1][1]:SetHeight( zoom-py);
605 texturelayout[1][1]:SetWidth( zoom-px);
606 ya_raw_setoff(texturelayout[1][1],vfname,0,0);
607  
608 -- Upper right corner
609 if(px ~= 0 or wzoom ~= wzoom_real) then
610 texturelayout[wzoom][1]:Show();
611 texturelayout[wzoom][1]:SetTexCoord( 0, rightw/zoom, (y-zy), 1);
612 texturelayout[wzoom][1]:SetHeight( zoom-py);
613 texturelayout[wzoom][1]:SetWidth(rightw);
614 ya_raw_setoff(texturelayout[wzoom][1],vfname,px,0);
615 else
616 texturelayout[wzoom][1]:Hide();
617 end
618  
619 -- Lower left corner
620 if(py ~= 0 or wzoom ~= wzoom_real) then
621 texturelayout[1][hzoom]:Show();
622 texturelayout[1][hzoom]:SetTexCoord( (x-zx), 1, 0, bottomh/zoom);
623 texturelayout[1][hzoom]:SetWidth( zoom-px);
624 texturelayout[1][hzoom]:SetHeight(bottomh);
625 ya_raw_setoff(texturelayout[1][hzoom],vfname,0,py);
626 else
627 texturelayout[1][hzoom]:Hide();
628 end
629  
630 -- lower right corner
631 if((py ~= 0 and px ~= 0) or wzoom ~= wzoom_real) then
632 texturelayout[wzoom][hzoom]:Show();
633 texturelayout[wzoom][hzoom]:SetTexCoord( 0, rightw/zoom, 0, bottomh/zoom);
634 texturelayout[wzoom][hzoom]:SetHeight(bottomh);
635 texturelayout[wzoom][hzoom]:SetWidth(rightw);
636 ya_raw_setoff(texturelayout[wzoom][hzoom],vfname,px,py);
637 else
638 texturelayout[wzoom][hzoom]:Hide();
639 end
640  
641 -- top line
642 for h = 2,wzoom-1 do
643 texturelayout[h][1]:SetTexCoord( 0, 1, (y-zy), 1);
644 texturelayout[h][1]:SetHeight( zoom-py);
645 ya_raw_setoff(texturelayout[h][1],vfname,px,0);
646 end
647  
648 -- bottom line
649 if(py ~= 0 or wzoom ~= wzoom_real) then
650 for h = 2,wzoom-1 do
651 texturelayout[h][hzoom]:Show();
652 texturelayout[h][hzoom]:SetTexCoord( 0, 1, 0, bottomh/zoom);
653 texturelayout[h][hzoom]:SetHeight(bottomh);
654 ya_raw_setoff(texturelayout[h][hzoom],vfname, px,py);
655 end
656 else
657 for h = 2,wzoom-1 do
658 texturelayout[h][hzoom]:Hide();
659 end
660 end
661  
662 -- left line
663 for h = 2,hzoom-1 do
664 texturelayout[1][h]:SetTexCoord( (x-zx), 1, 0, 1);
665 texturelayout[1][h]:SetWidth( zoom-px);
666 ya_raw_setoff(texturelayout[1][h],vfname,0,py);
667 end
668  
669 -- right line
670 if(px ~= 0 or wzoom ~= wzoom_real) then
671 for h = 2,hzoom-1 do
672 texturelayout[wzoom][h]:Show();
673 texturelayout[wzoom][h]:SetTexCoord( 0, rightw/zoom, 0, 1);
674 texturelayout[wzoom][h]:SetWidth(rightw);
675 ya_raw_setoff(texturelayout[wzoom][h],vfname,px,py);
676 end
677 else
678 for h = 2,hzoom-1 do
679 texturelayout[wzoom][h]:Hide();
680 end
681 end
682  
683 -- if our zoom is not a multiple of our size, we have a little extra we
684 -- need to worry about :X
685 if(wzoom_real ~= wzoom) then
686 if(needright_extra) then
687 rightw = (old_rightw-zoom);
688 end
689  
690 if(needbottom_extra) then
691 bottomh = (old_bottomh-zoom);
692  
693 for h = 1,wzoom_real-1 do
694 texturelayout[h][hzoom_real]:SetHeight(bottomh);
695 if(h == 1) then
696 texturelayout[h][hzoom_real]:SetTexCoord( (x-zx), 1, 0, bottomh/zoom);
697 texturelayout[h][hzoom_real]:SetWidth(zoom-px);
698 ya_raw_setoff(texturelayout[h][hzoom_real],vfname,0,py);
699 elseif(not needright_extra and h == wzoom_real-1) then
700 texturelayout[h][hzoom_real]:SetWidth(rightw);
701 texturelayout[h][hzoom_real]:SetTexCoord( 0, rightw/zoom, 0, bottomh/zoom);
702 ya_raw_setoff(texturelayout[h][hzoom_real],vfname,px,py);
703 else
704 texturelayout[h][hzoom_real]:SetWidth(zoom);
705 texturelayout[h][hzoom_real]:SetTexCoord( 0, 1, 0, bottomh/zoom);
706 ya_raw_setoff(texturelayout[h][hzoom_real],vfname,px,py);
707 end
708 texturelayout[h][hzoom_real]:Show();
709 end
710  
711 else
712 for h = 1,wzoom_real-1 do
713 texturelayout[h][hzoom_real]:Hide();
714 end
715 end
716  
717 if(needright_extra) then
718 for h = 1,hzoom_real do
719 texturelayout[wzoom_real][h]:SetWidth(rightw);
720 texturelayout[wzoom_real][h]:Show();
721 if(h == 1) then
722 texturelayout[wzoom_real][h]:SetTexCoord( 0, rightw/zoom, (y-zy), 1);
723 texturelayout[wzoom_real][h]:SetHeight(zoom-py);
724 ya_raw_setoff(texturelayout[wzoom_real][h],vfname,px,0);
725 elseif(not needbottom_extra and h == hzoom_real-1) then
726 texturelayout[wzoom_real][h]:SetHeight(bottomh);
727 texturelayout[wzoom_real][h]:SetTexCoord( 0, rightw/zoom, 0, bottomh/zoom);
728 ya_raw_setoff(texturelayout[wzoom_real][h],vfname,px,py);
729 elseif(h == hzoom_real) then
730 if(needbottom_extra) then
731 texturelayout[wzoom_real][h]:SetHeight(bottomh);
732 texturelayout[wzoom_real][h]:SetTexCoord( 0, rightw/zoom, 0, bottomh/zoom);
733 ya_raw_setoff(texturelayout[wzoom_real][h],vfname,px,py);
734 else
735 texturelayout[wzoom_real][h]:Hide();
736 end
737 else
738 texturelayout[wzoom_real][h]:SetHeight(zoom);
739 texturelayout[wzoom_real][h]:SetTexCoord( 0, rightw/zoom, 0, 1);
740 ya_raw_setoff(texturelayout[wzoom_real][h],vfname,px,py);
741 end
742  
743 end
744 else
745 for h = 1,hzoom_real do
746 texturelayout[wzoom_real][h]:Hide();
747 end
748 end
749  
750 end
751  
752 -- set zone text
753 if(not vf.dragme) then
754 self:UpdateDropDown2();
755 end
756  
757 self.opt.Location[1] = x;
758 self.opt.Location[2] = y;
759  
760 YAPoints_OnMove(self, x,y);
761 end
762  
763 function YatlasFrameTemplate:GetLocation()
764 local fm = self:GetName();
765  
766 return self.opt.Location[1],
767 self.opt.Location[2];
768 end
769  
770 function YatlasFrameTemplate:AdjustLocation(dx,dy,forceupdate)
771 local fm = self:GetName();
772  
773 if(self.opt == nil) then
774 -- we aren't ready yet!
775 return;
776 end
777  
778 self:SetLocation(
779 self.opt.Location[1] + dx,
780 self.opt.Location[2] - dy,
781 forceupdate);
782 end
783  
784 function YatlasFrameTemplate:GetZoneText(offx, offy)
785 -- untested?
786 local f = {YF_GetZoneIDs(self, offx, offy)};
787  
788 if(getn(f) < 1) then
789 return YATLAS_UNKNOWN_ZONE;
790 end
791  
792 local r = {};
793 for h,v in pairs(f) do
794 r[h] = Yatlas_areadb[v][1];
795 end
796  
797 return unpack(r);
798 end
799  
800 function YatlasFrameTemplate:GetZoneIDs(offx, offy)
801 local fm = self:GetName();
802 local x, y = unpack(self.opt.Location);
803 local zoom = self:GetZoom();
804  
805 if(offx == nil) then offx = 0 end
806 if(offy == nil) then offy = 0 end
807  
808 local roffx = math.floor((x+offx-math.floor(x))*16);
809 local roffy = math.floor((y+offx-math.floor(y))*16);
810  
811 local cv = (math.mod(roffx,16)+1)+(math.mod(roffy,16)+1)*16;
812 local v = self.texturelayout[math.floor(offx)+1][math.floor(offy)+1].areaids;
813 local nsv = getn(v)/2 - 1;
814 local id;
815 local jbase = 1;
816  
817 for i = 0,nsv do
818 local joff = v[2*i+2];
819  
820 if(cv <= jbase + joff) then
821 id = v[2*i+1];
822 break;
823 end
824 jbase = jbase + joff;
825 end
826  
827 local wd = 0;
828 if(id == nil or Yatlas_areadb[id] == nil) then
829 return nil;
830 end
831  
832 local r = {id};
833  
834 while(id ~= nil and Yatlas_areadb[id] ~= nil and wd < 100) do
835 id = Yatlas_areadb[id][1];
836 if(id ~= nil and Yatlas_areadb[id] ~= nil) then
837 tinsert(r, 1, id);
838 end
839 wd = wd + 1;
840 end
841  
842 return unpack(r);
843 end
844  
845 function YatlasFrameTemplate:OnWorldMapUpdate()
846 -- update landmarks
847 local mapname, mapszx, mapszy = GetMapInfo();
848 if(mapname and Yatlas_Landmarks[mapname] == nil and Yatlas_mapareas[mapname]) then
849 local x1,x2,y1,y2;
850 if(Yatlas_mapareas[mapname][0] ~= nil) then
851 x1 = Yatlas_mapareas[mapname][0][1];
852 x2 = Yatlas_mapareas[mapname][0][2];
853 y1 = Yatlas_mapareas[mapname][0][3];
854 y2 = Yatlas_mapareas[mapname][0][4];
855 else
856 local _,va = next(Yatlas_mapareas[mapname]);
857 x1 = va[1];
858 x2 = va[2];
859 y1 = va[3];
860 y2 = va[4];
861 end
862  
863 local n = GetNumMapLandmarks();
864 Yatlas_Landmarks[mapname] = {};
865 for h = 1,n do
866 local name, description, text, x, y =
867 GetMapLandmarkInfo(h);
868 x = (-x*(x1-x2) + x1);
869 y = (-y*(y1-y2) + y1);
870 tinsert(Yatlas_Landmarks[mapname],
871 {x,y, name, description, text});
872 end
873  
874 YAPoints_ForceUpdate();
875 end
876  
877 if(self.trackseek or (self.opt and self.opt.track)) then
878 self:OnWorldMapUpdateU(self.trackseek or self.opt.track)
879 end
880  
881 -- zooming to a unit?
882 if(self.trackseek_state ~= nil) then
883 local i,v = next(Yatlas_WorldMapIds, self.trackseek_state);
884 if(v == nil) then
885 self.trackseek_state = nil;
886 else
887 self.trackseek_state = i;
888 SetMapZoom(v);
889 end
890 end
891 end
892  
893 function YatlasFrameTemplate:OnWorldMapUpdateU(u)
894 local map = GetMapInfo();
895 local x,y = GetPlayerMapPosition(u);
896 local lm = self:GetName();
897 local viewframe = getglobal(lm.."ViewFrame");
898 local zoom = self.opt.Zoom
899  
900 if(Yatlas_mapareas[map] == nil or (x == 0 and y == 0)) then
901 return;
902 end
903  
904 local x1,x2,y1,y2;
905 if(Yatlas_mapareas[map][0] ~= nil) then
906 x1 = Yatlas_mapareas[map][0][1];
907 x2 = Yatlas_mapareas[map][0][2];
908 y1 = Yatlas_mapareas[map][0][3];
909 y2 = Yatlas_mapareas[map][0][4];
910 else
911 local _,va = next(Yatlas_mapareas[map]);
912 x1 = va[1];
913 x2 = va[2];
914 y1 = va[3];
915 y2 = va[4];
916 end
917  
918 local unitx, unity = (-x*(x1-x2) + x1), (-y*(y1-y2) + y1);
919  
920 if(u == self.trackseek) then
921 local zx,zy = Yatlas_Big2Mini_Coord(unitx, unity);
922  
923 self:SetMap(map);
924 self:SetLocation(zx-(viewframe:GetWidth()/2)/zoom,
925 zy-(viewframe:GetHeight()/2)/zoom);
926  
927 self.trackseek = nil;
928 self.trackseek_state = nil;
929 self.resetmapzoom = true;
930 elseif(u == self.opt.track) then
931 local rx,ry = self:GetLocation();
932 local zx,zy = Yatlas_Big2Mini_Coord(unitx, unity);
933 local whaffzoom = (viewframe:GetWidth()/2)/zoom;
934 local hhaffzoom = (viewframe:GetHeight()/2)/zoom;
935  
936 rx = rx+whaffzoom;
937 ry = ry+hhaffzoom;
938  
939 zx = zx-whaffzoom;
940 zy = zy-hhaffzoom;
941  
942 if(zx > rx or zx + whaffzoom*2 < rx or
943 zy > ry or zy + hhaffzoom*2 < ry) then
944 self:SetMap(map);
945 self:SetLocation(zx, zy);
946 end
947 self.resetmapzoom = true;
948 end
949 end
950  
951 function ya_raw_setoff(texture, parent, px, py)
952 local zoom = getglobal(parent):GetParent().opt.Zoom
953 texture:ClearAllPoints();
954 texture:SetPoint("TOPLEFT", parent,
955 "TOPLEFT", (zoom)*(texture.hx-1) - px,
956 -(zoom)*(texture.hy-1) + py);
957 end
958  
959 ya_lastdragx, ya_lastdragy = nil, nil;
960 function YatlasFrameViewFrame_OnDrag()
961 local x,y = GetCursorPosition();
962 local fx, fy;
963 local zoom = this:GetParent().opt.Zoom;
964  
965 x = x / this:GetEffectiveScale();
966 y = y / this:GetEffectiveScale();
967  
968 fx = math.floor(x - this:GetLeft())/(zoom);
969 fy = math.floor(y - this:GetBottom())/(zoom);
970 if(ya_lastdragx ~= nil) then
971 this:GetParent():AdjustLocation(ya_lastdragx - fx, ya_lastdragy - fy);
972 end
973  
974 ya_lastdragx = fx;
975 ya_lastdragy = fy;
976 end
977  
978 function YatlasFrameViewFrame_UpdateCursorCoord()
979 local x, y = GetCursorPosition();
980 local rx, ry = unpack(YatlasFrame.opt.Location);
981 local top = this:GetTop();
982 local zoom = YatlasFrame.opt.Zoom;
983  
984 if(this.lastoux == x and this.lastouy == y) then
985 return;
986 end
987 this.lastoux = x;
988 this.lastouy = y;
989  
990 x = x / this:GetEffectiveScale();
991 y = y / this:GetEffectiveScale();
992  
993 rx = rx + math.floor(x - this:GetLeft())/zoom;
994 ry = ry + 512/zoom-math.floor(y - this:GetBottom())/zoom;
995 local bigx, bigy = Yatlas_Mini2Big_Coord(rx,ry);
996 end
997  
998 function YatlasFrameTemplate:OnUpdate(elapsed)
999 self.update_time = self.update_time + elapsed;
1000  
1001 if(self.update_time > 0.5) then
1002 YAPoints_OnUpdate(self, self.update_time);
1003  
1004 if(GetMapInfo() ~= self.opt.Map) then
1005 self.resetmapzoom = 1;
1006 SetMapZoom(Yatlas_WorldMapIds[self.opt.Map]);
1007 else
1008 self:OnWorldMapUpdate()
1009 end
1010 self.update_time = 0;
1011  
1012 if(self.resetmapzoom) then
1013 self.resetmapzoom = nil;
1014 SetMapToCurrentZone()
1015 end
1016 end
1017 end
1018  
1019 function Yatlas_Mini2Big_Coord(x,y)
1020 return (x - 32)*-MINI2BIGX,(y-32)*-MINI2BIGY;
1021 end
1022  
1023 function Yatlas_Big2Mini_Coord(x,y)
1024 return (x/-MINI2BIGX + 32),(y/-MINI2BIGY + 32);
1025 end
1026  
1027 function Yatlas_GetMapZones(map)
1028 -- map zone ids to name
1029 local ret = {};
1030 if(Yatlas_ZoneIds[map]) then
1031 for h,v in ipairs(Yatlas_ZoneIds[map]) do
1032 tinsert(ret, Yatlas_areadb[v][2]);
1033 end
1034 end
1035 table.sort(ret);
1036  
1037 return unpack(ret);
1038 end
1039  
1040 -- YatlasOptionsFrame
1041  
1042 function YatlasOptionsFrameSelect_Initialize()
1043 local i = 1;
1044 local info;
1045 for h,v in pairs(YatlasOptions.Frames) do
1046 info = {
1047 text = h;
1048 func = YatlasOptionsFrameSelect_OnClick;
1049 value = getglobal(h);
1050 };
1051 UIDropDownMenu_AddButton(info);
1052 if(i == 1 and YatlasOptionsFrameSelect.currFrame == nil) then
1053 YatlasOptionsFrameSelect.currFrame = getglobal(h);
1054 end
1055 i = i + 1;
1056 end
1057 end
1058  
1059 function YatlasOptionsFrameSelect_OnClick()
1060 UIDropDownMenu_SetSelectedID(YatlasOptionsFrameSelect, this:GetID());
1061 YatlasOptionsFrameSelect.currFrame = this.value;
1062 YatlasOptionsFrame_Update();
1063 end
1064  
1065 function YatlasOptionsFrame_Update()
1066 local frame = YatlasOptionsFrameSelect.currFrame;
1067 if(frame) then
1068 local lm = frame:GetName();
1069 local opt = YatlasOptions.Frames[lm];
1070  
1071 YatlasOptionsAlphaSlider:SetValue(opt.Alpha);
1072 YatlasOptionsIconSizeSlider:SetValue(opt.IconSize);
1073  
1074 if(frame == YatlasFrame) then
1075 YatlasOptionsCoordBEnable:Show();
1076 YatlasOptionsCoordBEnable:SetChecked(YatlasOptions.ShowCursorCoords);
1077 else
1078 YatlasOptionsCoordBEnable:Hide();
1079 end
1080 end
1081 end
1082  
1083 -- YatlasTooltip
1084 YatlasTooltipTemplate = {};
1085  
1086 function YatlasTooltipTemplate:OnLoad()
1087 self:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r,
1088 TOOLTIP_DEFAULT_COLOR.g,
1089 TOOLTIP_DEFAULT_COLOR.b);
1090 self:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r,
1091 TOOLTIP_DEFAULT_BACKGROUND_COLOR.g,
1092 TOOLTIP_DEFAULT_BACKGROUND_COLOR.b);
1093 self.lines = {};
1094 self.nextnew = 1;
1095 self.nextfree = 1;
1096 end
1097  
1098 function YatlasTooltipTemplate:Show()
1099 local r = getmetatable(self).__index(self, "Show")(self);
1100 self:FixSize();
1101 return r;
1102 end
1103  
1104 function YatlasTooltipTemplate:GetNext()
1105 if(self.nextfree < self.nextnew) then
1106 self.nextfree = self.nextfree + 1;
1107 return self.lines[self.nextfree-1];
1108 end
1109  
1110 if(self.nextnew > 32) then
1111 return;
1112 end
1113  
1114 local f = CreateFrame("Button");
1115  
1116 f:SetHeight(16);
1117 f:SetWidth(16);
1118 f:SetParent(self);
1119 f:EnableMouse(true);
1120  
1121 f.Icon = f:CreateTexture(nil, "OVERLAY");
1122 f.Icon:SetPoint("TOPLEFT", f);
1123  
1124 f.Foreground = f:CreateFontString(nil, "ARTWORK");
1125 f.Foreground:SetFontObject(GameFontHighlight);
1126 f.Foreground:SetTextColor(0, 0, 0);
1127 f.Foreground:SetShadowOffset(-1, 0);
1128 f.Foreground:SetPoint("TOPLEFT", f);
1129  
1130 f:SetFrameLevel(f:GetFrameLevel() + 4);
1131 f.Clear = YP_Clear;
1132 f.SetOffset = nilfunc;
1133  
1134 f.Text = f:CreateFontString(nil, "ARTWORK");
1135 f.Text:SetFontObject(GameFontHighlight);
1136 f.Text:SetPoint("TOPLEFT", f.Icon, 24, 0);
1137  
1138 if(self.nextnew == 1) then
1139 f:SetPoint("TOPLEFT", self, "TOPLEFT", 8, -8);
1140 else
1141 f:SetPoint("TOPLEFT", self.lines[self.nextnew-1], "BOTTOMLEFT", 0, -2);
1142 end
1143  
1144 tinsert(self.lines, f);
1145 self.nextnew = self.nextnew + 1;
1146 self.nextfree = self.nextfree + 1;
1147 return f;
1148 end
1149  
1150 function YatlasTooltipTemplate:FixSize()
1151 local hei = 16;
1152 local wid = 4;
1153  
1154 for h = 1,(self.nextfree-1) do
1155 hei = hei + self.lines[h]:GetHeight() + 2;
1156 if(self.lines[h].Text:GetWidth() > wid) then
1157 wid = self.lines[h].Text:GetWidth();
1158 end
1159 end
1160 self:SetHeight(hei);
1161 self:SetWidth(wid+64);
1162 end
1163  
1164  
1165 function YatlasTooltipTemplate:Clear()
1166 for h = 1,(self.nextfree-1) do
1167 self.lines[h]:Hide();
1168 end
1169 self.nextfree = 1;
1170 self:FixSize();
1171 self:Hide();
1172 end
1173  
1174