vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- MetaMapWKB |
2 | -- Written by MetaHawk - aka Urshurak |
||
3 | |||
4 | MetaKB_dbID = "db1.1"; |
||
5 | METAKB_AUTHOR = "MetaMapWKB"; |
||
6 | |||
7 | METAKB_SCROLL_FRAME_BUTTON_HEIGHT = 16; |
||
8 | METAKB_SCROLL_FRAME_BUTTONS_SHOWN = 20; |
||
9 | METAKB_SORTBY_NAME = "name"; |
||
10 | METAKB_SORTBY_DESC = "desc"; |
||
11 | METAKB_SORTBY_LEVEL = "level"; |
||
12 | METAKB_SORTBY_LOCATION = "location"; |
||
13 | |||
14 | MetaKB_Data = {}; |
||
15 | MetaKB_Data[MetaKB_dbID] = {}; |
||
16 | MetaKBOptions = {}; |
||
17 | MetaKB_List = {}; |
||
18 | |||
19 | MetaKB_overRide = false; |
||
20 | MetaKB_ShowAllZones = false; |
||
21 | MetaKB_ScrollFrameButtonID = 0; |
||
22 | MetaKB_VarsLoaded = false; |
||
23 | |||
24 | local MetaKB_LastSearch = ""; |
||
25 | local MetaKB_SearchResults = {}; |
||
26 | local MetaKB_PlayerX = 0; |
||
27 | local MetaKB_PlayerY = 0; |
||
28 | |||
29 | function MetaKB_MainFrame_OnLoad() |
||
30 | this:RegisterEvent("ADDON_LOADED"); |
||
31 | this:RegisterEvent("WORLD_MAP_UPDATE"); |
||
32 | this:RegisterEvent("ZONE_CHANGED_NEW_AREA"); |
||
33 | this:RegisterEvent("UPDATE_MOUSEOVER_UNIT"); |
||
34 | end |
||
35 | function MetaKB_OnEvent(event) |
||
36 | if(event == "ADDON_LOADED" and arg1 == "MetaMapWKB") then |
||
37 | if(MetaKBOptions.ShowUpdates == nil) then MetaKBOptions.ShowUpdates = false; end |
||
38 | if(MetaKBOptions.CreateMapNotesBoundingBox == nil) then MetaKBOptions.CreateMapNotesBoundingBox = true; end |
||
39 | if(MetaKBOptions.AutoTrack == nil) then MetaKBOptions.AutoTrack = false; end |
||
40 | if(MetaKBOptions.KBstate == nil) then MetaKBOptions.KBstate = false; end |
||
41 | if(MetaKBOptions.NewTargetNote == nil) then MetaKBOptions.NewTargetNote = false; end |
||
42 | if(MetaKBOptions.RangeCheck == nil) then MetaKBOptions.RangeCheck = 1; end |
||
43 | if(MetaKBOptions.Dsearch == nil) then MetaKBOptions.Dsearch = true; end |
||
44 | if(MetaKBOptions.EmbedKB == nil) then MetaKBOptions.EmbedKB = true; end |
||
45 | if(MetaKBOptions.SetMapShow == nil) then MetaKBOptions.SetMapShow = false; end |
||
46 | MetaMapWKB_OptionsDialogInit(); |
||
47 | MetaMapWKB_VerifyData(); |
||
48 | MetaKB_InitFrame(); |
||
49 | end |
||
50 | if(event == "INSTANCE_MAP_UPDATE" and WorldMapFrame:IsVisible()) then |
||
51 | if(MetaKB_DisplayFrame:IsVisible() and MetaKBOptions.EmbedKB and not MetaKB_ShowAllZones) then |
||
52 | MetaKB_Search(); |
||
53 | else |
||
54 | MetaMapContainerFrame:Hide(); |
||
55 | end |
||
56 | end |
||
57 | if(event == "WORLD_MAP_UPDATE" and WorldMapFrame:IsVisible()) then |
||
58 | if(MetaKB_DisplayFrame:IsVisible() and MetaKBOptions.EmbedKB and not MetaKB_ShowAllZones) then |
||
59 | MetaKB_Search(); |
||
60 | else |
||
61 | MetaMapContainerFrame:Hide(); |
||
62 | end |
||
63 | end |
||
64 | if(event == "ZONE_CHANGED_NEW_AREA") then |
||
65 | if(MetaKB_DisplayFrame:IsVisible() and not MetaKB_ShowAllZones) then |
||
66 | MetaKB_Search(); |
||
67 | end |
||
68 | end |
||
69 | if(event == "UPDATE_MOUSEOVER_UNIT" and MetaKBOptions.AutoTrack) then |
||
70 | if(UnitIsPlayer("mouseover")~=1 and UnitPlayerControlled("mouseover")~=1 and UnitIsDead("mouseover")~=1) then |
||
71 | MetaKB_AddUnitInfo("mouseover"); |
||
72 | end |
||
73 | end |
||
74 | end |
||
75 | |||
76 | function MetaMapWKB_OptionsDialogInit() |
||
77 | MetaKB_AlwaysOnCheckButton:SetChecked(MetaMapOptions.WKBalwaysOn); |
||
78 | MetaKB_ShowUpdatesCheckButton:SetChecked(MetaKBOptions.ShowUpdates); |
||
79 | MetaKB_BoundingBoxCheckButton:SetChecked(MetaKBOptions.CreateMapNotesBoundingBox); |
||
80 | MetaKB_AutoTrackingCheckButton:SetChecked(MetaKBOptions.AutoTrack); |
||
81 | MetaKB_DsearchCheckButton:SetChecked(MetaKBOptions.Dsearch); |
||
82 | MetaKB_UseKBCheckButton:SetChecked(MetaKBOptions.KBstate); |
||
83 | MetaKB_SetTargetNoteCheckButton:SetChecked(MetaKBOptions.NewTargetNote); |
||
84 | MetaKB_SetMapShowCheckButton:SetChecked(MetaKBOptions.SetMapShow); |
||
85 | MetaKB_EmbedCheckButton:SetChecked(MetaKBOptions.EmbedKB); |
||
86 | MetaKB_ToggleSetRange(MetaKBOptions.RangeCheck); |
||
87 | end |
||
88 | |||
89 | function MetaKB_InitFrame() |
||
90 | if(MetaKBOptions.EmbedKB) then |
||
91 | MetaKB_DisplayFrame:SetParent("MetaMapContainerFrame"); |
||
92 | MetaKB_DisplayFrame:SetPoint("CENTER", "MetaMapContainerFrame", "CENTER", 0, 0); |
||
93 | MetaKB_DisplayFrame:SetWidth(MetaMapContainerFrame:GetWidth()); |
||
94 | MetaKB_DisplayFrame:SetHeight(MetaMapContainerFrame:GetHeight()); |
||
95 | MetaKB_HeaderPanel:SetHeight(40); |
||
96 | MetaKB_FooterPanel:SetHeight(60); |
||
97 | MetaKB_CloseMainFrameButton:Hide(); |
||
98 | METAKB_SCROLL_FRAME_BUTTON_HEIGHT = 18; |
||
99 | METAKB_SCROLL_FRAME_BUTTONS_SHOWN = 30; |
||
100 | else |
||
101 | MetaKB_DisplayFrame:SetParent("MetaKB_OuterFrame"); |
||
102 | MetaKB_DisplayFrame:SetPoint("CENTER", "MetaKB_OuterFrame", "CENTER", 0, 0); |
||
103 | MetaKB_DisplayFrame:SetWidth(710); |
||
104 | MetaKB_DisplayFrame:SetHeight(370); |
||
105 | MetaKB_HeaderPanel:SetHeight(22); |
||
106 | MetaKB_FooterPanel:SetHeight(40); |
||
107 | MetaKB_CloseMainFrameButton:Show(); |
||
108 | METAKB_SCROLL_FRAME_BUTTON_HEIGHT = 16; |
||
109 | METAKB_SCROLL_FRAME_BUTTONS_SHOWN = 20; |
||
110 | end |
||
111 | MetaKB_HeaderPanel:SetWidth(MetaKB_HeaderPanel:GetParent():GetWidth()); |
||
112 | MetaKB_HeaderPanel:SetFrameLevel(MetaKB_HeaderPanel:GetParent():GetFrameLevel()+1); |
||
113 | MetaKB_FooterPanel:SetWidth(MetaKB_FooterPanel:GetParent():GetWidth()); |
||
114 | MetaKB_FooterPanel:SetFrameLevel(MetaKB_FooterPanel:GetParent():GetFrameLevel()+1); |
||
115 | MetaKB_ScrollFrame:SetHeight(MetaKB_ScrollFrame:GetParent():GetHeight() - (MetaKB_HeaderPanel:GetHeight()+MetaKB_FooterPanel:GetHeight())); |
||
116 | MetaKB_ScrollFrame:SetWidth(MetaKB_ScrollFrame:GetParent():GetWidth()-22); |
||
117 | MetaKB_Header1:SetWidth(MetaKB_HeaderPanel:GetWidth()*0.2675); |
||
118 | MetaKB_Header2:SetWidth(MetaKB_HeaderPanel:GetWidth()*0.38); |
||
119 | MetaKB_Header3:SetWidth(MetaKB_HeaderPanel:GetWidth()*0.16); |
||
120 | MetaKB_Header4:SetWidth(MetaKB_HeaderPanel:GetWidth()*0.20); |
||
121 | for i=1, METAKB_SCROLL_FRAME_BUTTONS_SHOWN,1 do |
||
122 | getglobal("MetaKB_ScrollFrameButton"..i.."Name"):SetWidth(MetaKB_Header1:GetWidth()); |
||
123 | getglobal("MetaKB_ScrollFrameButton"..i.."Info1"):SetWidth(MetaKB_Header2:GetWidth()); |
||
124 | getglobal("MetaKB_ScrollFrameButton"..i.."Info2"):SetWidth(MetaKB_Header3:GetWidth()); |
||
125 | getglobal("MetaKB_ScrollFrameButton"..i.."Coords"):SetWidth(MetaKB_Header4:GetWidth()); |
||
126 | end |
||
127 | end |
||
128 | |||
129 | function MetaMapWKB_VerifyData() |
||
130 | local TempData = {} |
||
131 | TempData[MetaKB_dbID] = {}; |
||
132 | for name, continentTable in MetaKB_Data[MetaKB_dbID] do |
||
133 | for continent, zoneTable in continentTable do |
||
134 | if(type(continent) ~= "String") then |
||
135 | for zone, value in zoneTable do |
||
136 | if(zone ~= 0) then |
||
137 | TempData[MetaKB_dbID][name] = {}; |
||
138 | TempData[MetaKB_dbID][name][continent] = {}; |
||
139 | TempData[MetaKB_dbID][name][continent][zone] = {}; |
||
140 | TempData[MetaKB_dbID][name][continent][zone] = value; |
||
141 | end |
||
142 | end |
||
143 | end |
||
144 | end |
||
145 | end |
||
146 | MetaKB_Data = {}; |
||
147 | MetaKB_Data[MetaKB_dbID] = {}; |
||
148 | MetaKB_Data[MetaKB_dbID] = TempData[MetaKB_dbID]; |
||
149 | TempData = nil; |
||
150 | end |
||
151 | |||
152 | function MetaKB_ToggleFrame(mode) |
||
153 | if(MetaKBOptions.EmbedKB) then |
||
154 | if(MetaKB_DisplayFrame:IsVisible()) then |
||
155 | MetaMapContainer_ShowFrame(); |
||
156 | if(mode == 1) then |
||
157 | MetaMap_ToggleFrame(WorldMapFrame); |
||
158 | end |
||
159 | else |
||
160 | if(not WorldMapFrame:IsVisible()) then |
||
161 | MetaMap_ToggleFrame(WorldMapFrame); |
||
162 | end |
||
163 | MetaMapContainer_ShowFrame(MetaKB_DisplayFrame); |
||
164 | end |
||
165 | else |
||
166 | MetaMap_ToggleFrame(MetaKB_DisplayFrame:GetParent()); |
||
167 | end |
||
168 | end |
||
169 | |||
170 | function MetaKB_StripTextColors(textString) |
||
171 | -- this function is designed to replace |
||
172 | -- |cff00AA00Colored Text|r with Colored Text |
||
173 | if(textString ~= nil and textString ~= "") then |
||
174 | return string.gsub(textString, "|c[%dA-Fa-f][%dA-Fa-f][%dA-Fa-f][%dA-Fa-f][%dA-Fa-f]".. |
||
175 | "[%dA-Fa-f][%dA-Fa-f][%dA-Fa-f](.*)|r", "%1"); |
||
176 | else |
||
177 | assert(false, "nil or invalid parameter to StripTextColors"); |
||
178 | end |
||
179 | end |
||
180 | |||
181 | function MetaKB_ToggleSetRange(range) |
||
182 | for i=1, 5 do |
||
183 | if(i == range) then |
||
184 | local checkButton = getglobal("MetaKB_RangeCheck"..i); |
||
185 | checkButton:SetChecked(true); |
||
186 | else |
||
187 | local checkButton = getglobal("MetaKB_RangeCheck"..i); |
||
188 | checkButton:SetChecked(false); |
||
189 | end |
||
190 | end |
||
191 | MetaKBOptions.RangeCheck = range; |
||
192 | end |
||
193 | |||
194 | function MetaKB_UpdateKeySelectedUnit() |
||
195 | if (not UnitExists("target")) then |
||
196 | MetaMap_StatusPrint(METAKB_NOTARGET,MetaKBOptions.ShowUpdates); |
||
197 | return; |
||
198 | else |
||
199 | if(IsControlKeyDown()) then |
||
200 | MetaKB_overRide = true; |
||
201 | end |
||
202 | MetaKB_AddUnitInfo("target"); |
||
203 | MetaKB_overRide = false; |
||
204 | end |
||
205 | end |
||
206 | |||
207 | function MetaKB_AddUnitInfo(UnitSelect) |
||
208 | if( not CheckInteractDistance(UnitSelect, MetaKBOptions.RangeCheck) and MetaKBOptions.RangeCheck ~= 5) then |
||
209 | return; |
||
210 | end |
||
211 | local continent, zone = MetaMap_NameToZoneID(GetRealZoneText()); |
||
212 | if(type(continent) == "string") then |
||
213 | MetaMap_StatusPrint(METAMAPNOTES_INVALIDZONE, MetaKBOptions.ShowUpdates); |
||
214 | return; |
||
215 | end |
||
216 | local icon = 3; --green by default |
||
217 | local unitName = UnitName(UnitSelect); |
||
218 | local ncol = 0; |
||
219 | local desc1 = ""; |
||
220 | local desc2 = ""; |
||
221 | local playerX, playerY = GetPlayerMapPosition("player") |
||
222 | |||
223 | playerX = MetaMap_round(playerX*10000) |
||
224 | playerY = MetaMap_round(playerY*10000) |
||
225 | unitName = MetaKB_StripTextColors(unitName); |
||
226 | |||
227 | if(UnitReaction("player", UnitSelect) < 4) then |
||
228 | if(UnitClassification(UnitSelect) ~= "normal") then |
||
229 | desc1 = UnitClassification(UnitSelect).." "; |
||
230 | end |
||
231 | if(UnitCreatureType(UnitSelect) ~= nil) then |
||
232 | desc1 = desc1..UnitCreatureType(UnitSelect).." " |
||
233 | end |
||
234 | if(UnitClass(UnitSelect) ~= nil) then |
||
235 | desc1 = desc1..UnitClass(UnitSelect); |
||
236 | end |
||
237 | if(UnitLevel(UnitSelect) == "-1") then |
||
238 | desc2 = METAKB_MOB_LEVEL.." ??"; |
||
239 | else |
||
240 | desc2 = METAKB_MOB_LEVEL.." "..UnitLevel(UnitSelect); |
||
241 | end |
||
242 | icon = 1; |
||
243 | elseif(UnitReaction("player", UnitSelect) == 4) then |
||
244 | if(GameTooltipTextLeft2:GetText() ~= nil) then |
||
245 | desc1 = string.sub(GameTooltipTextLeft2:GetText(), 9); |
||
246 | end |
||
247 | desc2 = METAKB_MOB_LEVEL.." "..UnitLevel(UnitSelect); |
||
248 | icon = 0; |
||
249 | elseif(UnitReaction("player", UnitSelect) > 4 and UnitIsPlayer(UnitSelect)) then |
||
250 | unitName = UnitPVPName(UnitSelect); |
||
251 | desc1 = UnitRace(UnitSelect).." "..UnitClass(UnitSelect); |
||
252 | desc2 = METAKB_MOB_LEVEL.." "..UnitLevel(UnitSelect); |
||
253 | icon = 7; |
||
254 | elseif(UnitReaction("player", UnitSelect) < 4 and UnitIsPlayer(UnitSelect)) then |
||
255 | unitName = UnitPVPName(UnitSelect); |
||
256 | desc1 = UnitRace(UnitSelect).." "..UnitClass(UnitSelect); |
||
257 | desc2 = METAKB_MOB_LEVEL.." "..UnitLevel(UnitSelect); |
||
258 | icon = 6; |
||
259 | else |
||
260 | local check = GameTooltipTextLeft2:GetText(); |
||
261 | if (check ~= nil) then |
||
262 | if(string.find(check, METAKB_MOB_LEVEL)) then |
||
263 | if(GameTooltipTextLeft3 ~= "" and GameTooltipTextLeft3 ~= nil) then |
||
264 | desc1 = GameTooltipTextLeft3:GetText(); |
||
265 | desc2 = GameTooltipTextLeft2:GetText(); |
||
266 | end |
||
267 | else |
||
268 | if(GameTooltipTextLeft2 ~= "" and GameTooltipTextLeft2 ~= nil) then |
||
269 | desc1 = GameTooltipTextLeft2:GetText(); |
||
270 | end |
||
271 | if(GameTooltipTextLeft3 ~= "" and GameTooltipTextLeft3 ~= nil) then |
||
272 | desc2 = GameTooltipTextLeft3:GetText(); |
||
273 | end |
||
274 | end |
||
275 | end |
||
276 | icon = 3; |
||
277 | end |
||
278 | if(desc1 == nil) then desc1 = ""; end |
||
279 | if(desc2 == nil) then desc2 = ""; end |
||
280 | |||
281 | local changedSomething = false; |
||
282 | local addedSomething = false; |
||
283 | local updatedSomething = false; |
||
284 | local currentUnit; |
||
285 | |||
286 | if(MetaKB_Data[MetaKB_dbID][unitName] == nil) then |
||
287 | MetaKB_Data[MetaKB_dbID][unitName] = {}; |
||
288 | MetaMap_StatusPrint(format(TEXT(METAKB_DISCOVERED_UNIT), unitName), true); |
||
289 | end |
||
290 | currentUnit = MetaKB_Data[MetaKB_dbID][unitName]; |
||
291 | if(currentUnit[continent] == nil) then |
||
292 | currentUnit[continent] = {}; |
||
293 | end |
||
294 | if(currentUnit[continent][zone] == nil) then |
||
295 | currentUnit[continent][zone] = {}; |
||
296 | currentUnit[continent][zone]["inf1"] = desc1; |
||
297 | currentUnit[continent][zone]["inf2"] = desc2; |
||
298 | currentUnit[continent][zone]["icon"] = icon; |
||
299 | currentUnit[continent][zone][1] = 20000; |
||
300 | currentUnit[continent][zone][2] = -1; |
||
301 | currentUnit[continent][zone][3] = -1; |
||
302 | currentUnit[continent][zone][4] = 20000; |
||
303 | addedSomething = true |
||
304 | else |
||
305 | currentUnit[continent][zone]["icon"] = icon; |
||
306 | if(currentUnit[continent][zone]["inf1"] == "") then |
||
307 | currentUnit[continent][zone]["inf1"] = desc1; |
||
308 | updatedSomething = true; |
||
309 | end |
||
310 | if(currentUnit[continent][zone]["inf2"] == "") then |
||
311 | currentUnit[continent][zone]["inf2"] = desc2; |
||
312 | updatedSomething = true; |
||
313 | end |
||
314 | end |
||
315 | |||
316 | local coords = currentUnit[continent][zone]; |
||
317 | |||
318 | if(playerX < coords[4]) then |
||
319 | currentUnit[continent][zone][4] = playerX; |
||
320 | changedSomething = true; |
||
321 | end |
||
322 | if(playerY < coords[1]) then |
||
323 | currentUnit[continent][zone][1] = playerY; |
||
324 | changedSomething = true; |
||
325 | end |
||
326 | if(playerX > coords[2]) then |
||
327 | currentUnit[continent][zone][2] = playerX; |
||
328 | changedSomething = true; |
||
329 | end |
||
330 | if(playerY > coords[3]) then |
||
331 | currentUnit[continent][zone][3] = playerY; |
||
332 | changedSomething = true; |
||
333 | end |
||
334 | |||
335 | if(MetaKBOptions.NewTargetNote or MetaKB_overRide) then |
||
336 | MetaKB_AddMapNotes(unitName, GetRealZoneText(), 0); |
||
337 | end |
||
338 | if(MetaKBOptions.KBstate) then |
||
339 | if(addedSomething) then |
||
340 | MetaMap_StatusPrint(format(TEXT(METAKB_ADDED_UNIT_IN_ZONE), unitName, GetRealZoneText()), MetaKBOptions.ShowUpdates); |
||
341 | end |
||
342 | if(changedSomething and not addedSomething) then |
||
343 | MetaMap_StatusPrint(format(TEXT(METAKB_UPDATED_MINMAX_XY), unitName, GetRealZoneText()), MetaKBOptions.ShowUpdates); |
||
344 | end |
||
345 | if(updatedSomething) then |
||
346 | MetaMap_StatusPrint(format(TEXT(METAKB_UPDATED_INFO), unitName, GetRealZoneText()), MetaKBOptions.ShowUpdates); |
||
347 | end |
||
348 | else |
||
349 | currentUnit = nil; |
||
350 | end |
||
351 | end |
||
352 | |||
353 | function MetaKB_UpdateScrollFrame() |
||
354 | for iScrollFrameButton = 1, METAKB_SCROLL_FRAME_BUTTONS_SHOWN, 1 do |
||
355 | local buttonIndex = iScrollFrameButton + FauxScrollFrame_GetOffset(MetaKB_ScrollFrame); |
||
356 | local scrollFrameButton = getglobal("MetaKB_ScrollFrameButton"..iScrollFrameButton); |
||
357 | local NameButton = getglobal("MetaKB_ScrollFrameButton"..iScrollFrameButton.."Name"); |
||
358 | local Info1Button = getglobal("MetaKB_ScrollFrameButton"..iScrollFrameButton.."Info1"); |
||
359 | local Info2Button = getglobal("MetaKB_ScrollFrameButton"..iScrollFrameButton.."Info2"); |
||
360 | local CoordsButton = getglobal("MetaKB_ScrollFrameButton"..iScrollFrameButton.."Coords"); |
||
361 | |||
362 | if(buttonIndex < MetaKB_SearchResults.onePastEnd) then |
||
363 | if(MetaKB_SearchResults[buttonIndex]["zoneName"] == GetRealZoneText()) then |
||
364 | -- Unit is in the same zone, show in yellow |
||
365 | NameButton:SetText(MetaKB_SearchResults[buttonIndex]["name"]); |
||
366 | Info1Button:SetText(MetaKB_SearchResults[buttonIndex]["desc"]); |
||
367 | Info2Button:SetText(MetaKB_SearchResults[buttonIndex]["level"]); |
||
368 | CoordsButton:SetText(MetaKB_SearchResults[buttonIndex]["location"]); |
||
369 | if(MetaKB_SearchResults[buttonIndex]["cCode"] == 2) then |
||
370 | CoordsButton:SetTextColor(0,1,0) |
||
371 | else |
||
372 | -- Unit is within range, show in green |
||
373 | CoordsButton:SetTextColor(1,1,0) |
||
374 | end |
||
375 | scrollFrameButton:Show(); |
||
376 | else |
||
377 | if(MetaKB_ShowAllZones or MetaKBOptions.EmbedKB) then |
||
378 | -- Unit is in a different zone, show in red |
||
379 | NameButton:SetText(MetaKB_SearchResults[buttonIndex]["name"]); |
||
380 | Info1Button:SetText(MetaKB_SearchResults[buttonIndex]["desc"]); |
||
381 | Info2Button:SetText(MetaKB_SearchResults[buttonIndex]["level"]); |
||
382 | CoordsButton:SetText(MetaKB_SearchResults[buttonIndex]["zoneName"]); |
||
383 | CoordsButton:SetTextColor(1,0,0) |
||
384 | scrollFrameButton:Show(); |
||
385 | else |
||
386 | scrollFrameButton:Hide(); |
||
387 | end |
||
388 | end |
||
389 | local ncol = MetaKB_SearchResults[buttonIndex]["ncol"]; |
||
390 | NameButton:SetTextColor(MetaMapNotes_Colors[ncol].r,MetaMapNotes_Colors[ncol].g,MetaMapNotes_Colors[ncol].b) |
||
391 | Info1Button:SetTextColor(0.8,0.8,0.8) |
||
392 | Info2Button:SetTextColor(0.5,0.5,0.8) |
||
393 | else |
||
394 | scrollFrameButton:Hide(); |
||
395 | end |
||
396 | end |
||
397 | FauxScrollFrame_Update(MetaKB_ScrollFrame, MetaKB_SearchResults.onePastEnd - 1, |
||
398 | METAKB_SCROLL_FRAME_BUTTONS_SHOWN, METAKB_SCROLL_FRAME_BUTTON_HEIGHT) |
||
399 | end |
||
400 | |||
401 | function MetaKB_BuildSearchResults() |
||
402 | MetaKB_SearchResults = {}; |
||
403 | local nameCount = 0; |
||
404 | local zoneCount = 0; |
||
405 | local tempZones = {}; |
||
406 | local currentContinent, currentZone, _, mapName = MetaMap_GetCurrentMapInfo(); |
||
407 | |||
408 | for name, continentTable in MetaKB_Data[MetaKB_dbID] do |
||
409 | for continent, zoneTable in continentTable do |
||
410 | for zone in zoneTable do |
||
411 | local cCode = 1; |
||
412 | local showAll = false; |
||
413 | local coordString = ""; |
||
414 | if(continent == currentContinent and mapName == "Kalimdor") then showAll = true; end |
||
415 | if(continent == currentContinent and mapName == "Eastern Kingdoms") then showAll = true; end |
||
416 | if(mapName == "World" and continent ~= 0) then showAll = true; end |
||
417 | if(continent == currentContinent and zone == currentZone or MetaKB_ShowAllZones or showAll) then |
||
418 | local zoneName = MetaMap_ZoneNames[continent][zone]; |
||
419 | local selectedData = MetaKB_Data[MetaKB_dbID][name][continent][zone]; |
||
420 | local inf1 = selectedData["inf1"]; |
||
421 | local inf2 = selectedData["inf2"]; |
||
422 | local ncol = selectedData["icon"]; |
||
423 | if(ncol == 1) then ncol = 2; |
||
424 | elseif(ncol == 2) then ncol = 6; |
||
425 | elseif(ncol == 3) then ncol = 4; |
||
426 | elseif(ncol == 6) then ncol = 1; end |
||
427 | if(zoneName ~= GetRealZoneText() or continent == 0) then |
||
428 | coordString = zoneName; |
||
429 | else |
||
430 | coordString, cCode = MetaKB_FormatCoords(selectedData); |
||
431 | end |
||
432 | if(string.find(string.lower(name),string.lower(MetaKB_LastSearch),1,true)~=nil |
||
433 | or string.find(string.lower(inf1),string.lower(MetaKB_LastSearch),1,true)~=nil |
||
434 | or string.find(string.lower(inf2),string.lower(MetaKB_LastSearch),1,true)~=nil |
||
435 | or string.find(string.lower(coordString),string.lower(MetaKB_LastSearch),1,true)~=nil) then |
||
436 | tinsert(MetaKB_SearchResults, {name = name, zoneName = zoneName, desc = inf1, level = inf2, ncol = ncol, location = coordString, cCode = cCode}); |
||
437 | nameCount = nameCount + 1; |
||
438 | if(tempZones[zoneName] == nil and zoneName ~= nil) then |
||
439 | zoneCount = zoneCount + 1; |
||
440 | tempZones[zoneName] = 1; |
||
441 | end |
||
442 | end |
||
443 | end |
||
444 | end |
||
445 | end |
||
446 | end |
||
447 | MetaKB_ResultFontString:SetText("Found "..nameCount.." NPC/MoBs in "..zoneCount.." zones"); |
||
448 | MetaKB_SearchResults.onePastEnd = nameCount +1; |
||
449 | MetaKBList_SortBy(MetaMap_sortType, MetaMap_sortDone) |
||
450 | end |
||
451 | |||
452 | function MetaKB_FormatCoords(dataSet, mode) |
||
453 | local cleanCoords = {}; |
||
454 | local coordString = ""; |
||
455 | for i=1,4 do |
||
456 | cleanCoords[i] = MetaMap_round(dataSet[i]/100, 0); |
||
457 | end |
||
458 | local dx = dataSet[2]/100 - dataSet[4]/100; |
||
459 | local dy = dataSet[3]/100 - dataSet[1]/100; |
||
460 | local centerx = dataSet[4]/100 + dx/2; |
||
461 | local centery = dataSet[1]/100 + dy/2; |
||
462 | -- truncate to two digits after the decimal again |
||
463 | centerx = MetaMap_round(centerx, 0); |
||
464 | centery = MetaMap_round(centery, 0); |
||
465 | if(mode == nil) then |
||
466 | if dx >= 3 or dy >= 3 then |
||
467 | -- if the NPC has a range of 3 map units or greater, show ranges |
||
468 | coordString = " ("..cleanCoords[4].."-"..cleanCoords[2].."),".. |
||
469 | " ("..cleanCoords[1].."-"..cleanCoords[3]..")" |
||
470 | else |
||
471 | -- otherwise just show an averaged point |
||
472 | coordString = " ("..centerx..", "..centery..")" |
||
473 | end |
||
474 | if(centerx > (MetaKB_PlayerX +3) or centerx < (MetaKB_PlayerX -3) and centery > (MetaKB_PlayerY +3) or centery < (MetaKB_PlayerY -3)) then |
||
475 | cCode = 1; |
||
476 | else |
||
477 | cCode = 2; |
||
478 | end |
||
479 | return coordString, cCode; |
||
480 | elseif(mode == 1) then |
||
481 | if(centerx == 0 and centery == 0) then |
||
482 | centerx = 75; |
||
483 | centery = 95; |
||
484 | end |
||
485 | centerx = centerx/100; |
||
486 | centery = centery/100; |
||
487 | return centerx, centery, dx, dy; |
||
488 | end |
||
489 | return centerx, centery; |
||
490 | end |
||
491 | |||
492 | function MetaKBList_SortBy(aSortType, aSortDone) |
||
493 | MetaMap_sortType = aSortType; |
||
494 | MetaMap_sortDone = aSortDone; |
||
495 | table.sort(MetaKB_SearchResults, MetaMap_SortCriteria); |
||
496 | if(not MetaMap_sortDone)then |
||
497 | local count = MetaKB_SearchResults.onePastEnd; |
||
498 | MetaKB_SearchResults = MetaMap_InvertList(MetaKB_SearchResults); |
||
499 | MetaKB_SearchResults.onePastEnd = count; |
||
500 | end |
||
501 | MetaKB_UpdateScrollFrame(); |
||
502 | end |
||
503 | |||
504 | function MetaKB_Search(searchText, suppressErrors) |
||
505 | if(searchText == nil) then searchText = MetaKB_LastSearch; end |
||
506 | if(suppressErrors == nil) then suppressErrors = false; end |
||
507 | |||
508 | MetaKB_LastSearch = searchText; |
||
509 | if(not MetaKBOptions.EmbedKB) then |
||
510 | SetMapToCurrentZone(); |
||
511 | end |
||
512 | MetaKB_PlayerX, MetaKB_PlayerY = GetPlayerMapPosition("player"); |
||
513 | MetaKB_PlayerX = MetaMap_round(MetaKB_PlayerX * 100); |
||
514 | MetaKB_PlayerY = MetaMap_round(MetaKB_PlayerY * 100); |
||
515 | FauxScrollFrame_SetOffset(MetaKB_ScrollFrame, 0); |
||
516 | MetaKB_BuildSearchResults(); |
||
517 | MetaKB_UpdateScrollFrame(); |
||
518 | MetaKB_SearchEditBox:SetText(MetaKB_LastSearch); |
||
519 | end |
||
520 | |||
521 | function MetaKB_ScrollFrameButtonOnClick(button) |
||
522 | if(button == "LeftButton") then |
||
523 | MetaKB_ScrollFrameButtonID = this:GetID(); |
||
524 | local x, y = GetCursorPosition(); |
||
525 | x = x / UIParent:GetEffectiveScale(); |
||
526 | y = y / UIParent:GetEffectiveScale(); |
||
527 | MetaKBMenu:SetPoint("TOP", "UIParent", "BOTTOMLEFT", x , y +10); |
||
528 | MetaKBMenu:Show(); |
||
529 | elseif(button == "RightButton") then |
||
530 | if(IsControlKeyDown()) then |
||
531 | MetaKBMenu_CRBSelect(this:GetID()); |
||
532 | elseif(IsShiftKeyDown()) then |
||
533 | MetaKBMenu_SRBSelect(this:GetID()); |
||
534 | else |
||
535 | MetaMap_LoadBWP(this:GetID(), 1); |
||
536 | end |
||
537 | end |
||
538 | end |
||
539 | |||
540 | function MetaKBMenu_Select(id) |
||
541 | local name = getglobal("MetaKB_ScrollFrameButton"..MetaKB_ScrollFrameButtonID.."Name"):GetText(); |
||
542 | local zoneName = getglobal("MetaKB_ScrollFrameButton"..MetaKB_ScrollFrameButtonID.."Coords"):GetText(); |
||
543 | if(string.find(zoneName, "%(%d+\.?-?%d*%)?, %(?%d+\.?-?%d*%)")) then |
||
544 | zoneName = GetRealZoneText(); |
||
545 | end |
||
546 | local continent, zone = MetaMap_NameToZoneID(zoneName); |
||
547 | local currentZone = MetaMapNotes_Data[continent][zone]; |
||
548 | local tUpdate = MetaKBOptions.ShowUpdates; |
||
549 | |||
550 | if(id == 1) then |
||
551 | MetaKBOptions.ShowUpdates = true; |
||
552 | PlaySound("MapPing"); |
||
553 | MetaKB_AddMapNotes(name, zoneName, 0); |
||
554 | MetaMapNotes_MapUpdate(); |
||
555 | PlaySound("igMiniMapClose"); |
||
556 | elseif(id == 2) then |
||
557 | MetaKBOptions.ShowUpdates = true; |
||
558 | PlaySound("MapPing"); |
||
559 | MetaKB_AddMapNotes(name, zoneName, 2); |
||
560 | PlaySound("igMainMenuOption") |
||
561 | elseif(id == 3) then |
||
562 | MetaKBOptions.ShowUpdates = true; |
||
563 | MetaMap_DeleteNotes(METAKB_AUTHOR, name); |
||
564 | elseif(id == 4) then |
||
565 | MetaKBOptions.ShowUpdates = true; |
||
566 | PlaySound("igQuestLogAbandonQuest"); |
||
567 | MetaMap_DeleteNotes(METAKB_AUTHOR); |
||
568 | elseif(id == 5) then |
||
569 | MetaKB_Data[MetaKB_dbID][name] = nil; |
||
570 | PlaySound("Deathbind Sound"); |
||
571 | MetaMap_StatusPrint(format(TEXT(METAKB_REMOVED_FROM_DATABASE), name, zoneName), true); |
||
572 | MetaKB_Search(MetaKB_LastSearch, true); |
||
573 | elseif(id == 6) then |
||
574 | StaticPopupDialogs["Trim_Dbase"] = { |
||
575 | text = TEXT(METAKB_TRIM_DBASE), |
||
576 | button1 = TEXT(ACCEPT), |
||
577 | button2 = TEXT(DECLINE), |
||
578 | OnAccept = function() |
||
579 | MetaKB_TrimDatabase(); |
||
580 | end, |
||
581 | timeout = 60, |
||
582 | showAlert = 1, |
||
583 | }; |
||
584 | StaticPopup_Show("Trim_Dbase"); |
||
585 | elseif(id == 7 and ChatFrameEditBox:IsVisible()) then |
||
586 | local selectedData = MetaKB_Data[MetaKB_dbID][name][continent][zone]; |
||
587 | local centerx, centery = MetaKB_FormatCoords(selectedData, 2) |
||
588 | local mInfo = " " |
||
589 | if(selectedData.inf1 ~= "") then mInfo = " ["..selectedData.inf1.."] "; end |
||
590 | local coordString = centerx..", "..centery; |
||
591 | ChatFrameEditBox:Insert(name..mInfo.."("..zoneName.." - "..coordString..")"); |
||
592 | elseif(id == 8) then |
||
593 | local noteID = 0; |
||
594 | MetaKBMenu:Hide(); |
||
595 | MetaKB_DisplayFrame:GetParent():Hide(); |
||
596 | ShowUIPanel(WorldMapFrame); |
||
597 | if(continent == 0) then |
||
598 | MetaMapOptions.MetaMapZone = zone; |
||
599 | MetaMap_Toggle(true); |
||
600 | else |
||
601 | SetMapZoom(continent, zone); |
||
602 | end |
||
603 | for index, value in currentZone, 1 do |
||
604 | if(currentZone[index].name == name) then |
||
605 | noteID = index; |
||
606 | break; |
||
607 | end |
||
608 | end |
||
609 | if(noteID == 0 and MetaKBOptions.SetMapShow and not MetaMapFrame:IsVisible()) then |
||
610 | noteID = MetaMapNotes_GetZoneTableSize(currentZone)+1; |
||
611 | MetaKB_AddMapNotes(name, zoneName, 0); |
||
612 | MetaMapNotes_MapUpdate(); |
||
613 | end |
||
614 | if(noteID > 0) then |
||
615 | MetaMapPing_SetPing(currentZone, noteID); |
||
616 | end |
||
617 | end |
||
618 | MetaKBOptions.ShowUpdates = tUpdate; |
||
619 | end |
||
620 | |||
621 | function MetaKBMenu_OnUpdate() |
||
622 | if (MetaKBMenu:IsVisible()) then |
||
623 | if (not MouseIsOver(MetaKBMenu)) then |
||
624 | MetaKBMenu:Hide(); |
||
625 | end |
||
626 | end |
||
627 | end |
||
628 | |||
629 | function MetaKB_TrimDatabase() |
||
630 | local nameCount = 0; |
||
631 | |||
632 | for i=1, table.getn(MetaKB_SearchResults) do |
||
633 | local Name = MetaKB_SearchResults[i].name; |
||
634 | MetaKB_Data[MetaKB_dbID][Name] = nil; |
||
635 | nameCount = nameCount + 1 |
||
636 | end |
||
637 | if(strlen(MetaKB_LastSearch) > 0) then |
||
638 | MetaMap_StatusPrint("Removed "..nameCount.." entries from database linked to '"..MetaKB_LastSearch.."'", true); |
||
639 | else |
||
640 | MetaMap_StatusPrint("Removed ALL entries from database", true); |
||
641 | end |
||
642 | MetaKB_Search(MetaKB_LastSearch, true); |
||
643 | end |
||
644 | |||
645 | function MetaKB_AddMapNotes(name, zoneName, mininote) |
||
646 | if(mininote == nil) then mininote = 0; end |
||
647 | local continent, zone = MetaMap_NameToZoneID(zoneName); |
||
648 | local currentZone = MetaKB_Data[MetaKB_dbID][name][continent][zone]; |
||
649 | local coordSets = { |
||
650 | [1] = { ["n"] = TEXT(METAKB_MAPNOTES_NW_BOUND), ["x"] = 4, ["y"] = 1, }, |
||
651 | [2] = { ["n"] = TEXT(METAKB_MAPNOTES_NE_BOUND), ["x"] = 2, ["y"] = 1, }, |
||
652 | [3] = { ["n"] = TEXT(METAKB_MAPNOTES_SE_BOUND), ["x"] = 2, ["y"] = 3, }, |
||
653 | [4] = { ["n"] = TEXT(METAKB_MAPNOTES_SW_BOUND), ["x"] = 4, ["y"] = 3, }, }; |
||
654 | local infoOne = currentZone["inf1"]; |
||
655 | local infoTwo = currentZone["inf2"]; |
||
656 | local icon = currentZone["icon"]; |
||
657 | local namecol = icon; |
||
658 | if(icon == 1) then namecol = 2; |
||
659 | elseif(icon == 2) then namecol = 6; |
||
660 | elseif(icon == 3) then namecol = 4; |
||
661 | elseif(icon == 6) then namecol = 1; end |
||
662 | local centerx, centery, dx, dy = MetaKB_FormatCoords(currentZone, 1) |
||
663 | local noteAdded, nearNote = MetaMapNotes_AddNewNote(continent, zone, centerx, centery, name, infoOne, infoTwo, METAKB_AUTHOR, icon, namecol, 9, 6, mininote); |
||
664 | if(noteAdded) then |
||
665 | if(mininote ~= 2) then |
||
666 | MetaMap_StatusPrint(format(METAMAPNOTES_ACCEPT_NOTE, MetaMap_ZoneNames[continent][zone]), MetaKBOptions.ShowUpdates); |
||
667 | end |
||
668 | else |
||
669 | MetaMap_StatusPrint(format(METAMAPNOTES_DECLINE_NOTE, MetaMapNotes_Data[continent][zone][nearNote].name, MetaMap_ZoneNames[continent][zone]), MetaKBOptions.ShowUpdates); |
||
670 | end |
||
671 | if(mininote > 0) then |
||
672 | MetaMap_StatusPrint(format(METAMAPNOTES_ACCEPT_MININOTE, GetRealZoneText()), true); |
||
673 | end |
||
674 | if(noteAdded and mininote == 0 and (dx >= 3 or dy >= 3) and MetaKBOptions.CreateMapNotesBoundingBox) then |
||
675 | local x2 = currentZone[coordSets[4].x]/10000 |
||
676 | local y2 = currentZone[coordSets[4].y]/10000 |
||
677 | local skipNext = false |
||
678 | for i in coordSets do |
||
679 | local x1 = currentZone[coordSets[i].x]/10000 |
||
680 | local y1 = currentZone[coordSets[i].y]/10000 |
||
681 | local noteAdded = MetaMapNotes_AddNewNote(continent, zone, x1, y1, name, infoOne, infoTwo, METAKB_AUTHOR, 10, namecol, 9, 6); |
||
682 | if(noteAdded) then |
||
683 | if(not skipNext) then |
||
684 | MetaMapNotes_ToggleLine(continent, zone, x2, y2, x1, y1); |
||
685 | MetaMapNotes_ToggleLine(continent, zone, centerx, centery, x1, y1); |
||
686 | end |
||
687 | skipNext = false; |
||
688 | else |
||
689 | skipNext = true; |
||
690 | end |
||
691 | x2,y2 = x1,y1; |
||
692 | end |
||
693 | end |
||
694 | end |
||
695 | |||
696 | function MetaKB_ToggleAllZones() |
||
697 | MetaKB_ShowAllZones = not MetaKB_ShowAllZones; |
||
698 | if MetaKB_ShowAllZones then |
||
699 | this:SetText(METAKB_SHOW_LOCALZONE); |
||
700 | PlaySound("igMainMenuOptionCheckBoxOn"); |
||
701 | else |
||
702 | this:SetText(METAKB_SHOW_ALLZONES); |
||
703 | PlaySound("igMainMenuOptionCheckBoxOff"); |
||
704 | end |
||
705 | MetaKB_Search(); |
||
706 | end |
||
707 | |||
708 | function MetaKB_ToggleAutoTrack() |
||
709 | MetaKBOptions.AutoTrack = not MetaKBOptions.AutoTrack; |
||
710 | if(MetaKBOptions.AutoTrack) then |
||
711 | PlaySound("igMainMenuOptionCheckBoxOn"); |
||
712 | else |
||
713 | PlaySound("igMainMenuOptionCheckBoxOff"); |
||
714 | end |
||
715 | end |
||
716 | |||
717 | function MetaKB_ToggleShowUpdates() |
||
718 | MetaKBOptions.ShowUpdates = not MetaKBOptions.ShowUpdates |
||
719 | if MetaKBOptions.ShowUpdates then |
||
720 | PlaySound("igMainMenuOptionCheckBoxOn"); |
||
721 | else |
||
722 | PlaySound("igMainMenuOptionCheckBoxOff"); |
||
723 | end |
||
724 | end |
||
725 | |||
726 | function MetaKB_ToggleDbase() |
||
727 | MetaKBOptions.KBstate = not MetaKBOptions.KBstate; |
||
728 | if MetaKBOptions.KBstate then |
||
729 | PlaySound("igMainMenuOptionCheckBoxOn"); |
||
730 | else |
||
731 | PlaySound("igMainMenuOptionCheckBoxOff"); |
||
732 | end |
||
733 | end |
||
734 | |||
735 | function MetaKB_ToggleSetNote() |
||
736 | MetaKBOptions.NewTargetNote = not MetaKBOptions.NewTargetNote |
||
737 | if MetaKBOptions.NewTargetNote then |
||
738 | PlaySound("igMainMenuOptionCheckBoxOn"); |
||
739 | else |
||
740 | PlaySound("igMainMenuOptionCheckBoxOff"); |
||
741 | end |
||
742 | end |
||
743 | |||
744 | function MetaKB_ToggleBoundingBox() |
||
745 | MetaKBOptions.CreateMapNotesBoundingBox = not MetaKBOptions.CreateMapNotesBoundingBox; |
||
746 | if MetaKBOptions.CreateMapNotesBoundingBox then |
||
747 | PlaySound("igMainMenuOptionCheckBoxOn"); |
||
748 | else |
||
749 | PlaySound("igMainMenuOptionCheckBoxOff"); |
||
750 | end |
||
751 | end |
||
752 |