vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[---------------------------------------------------------------------------------
2 AH Favorites
3 Saves searches from the AH in a favorites list
4  
5 $Revision: 1.9 $
6 $Date: 2005/10/26 11:59:43 $
7 ------------------------------------------------------------------------------------]]
8  
9 --[[
10 Globals:
11  
12 --]]
13  
14 local DEFAULT_OPTIONS = {
15 autoQuery = true,
16 FSL = true,
17 };
18  
19 -- Chat commands
20  
21 AHFAV_OPTIONS = {
22 {
23 option = AH_FAV.AUTOQUERY,
24 desc = AH_FAV.AUTOQUERY_DESC,
25 method = "ToggleAutoQuery"
26 },
27 {
28 option = AH_FAV.FSL,
29 desc = AH_FAV.FSL_DESC,
30 method = "ToggleFSL"
31 }
32 };
33  
34 ACE_MAP_ONOFF = {[0]="|cffff5050Off|r",[1]="|cff00ff00On|r"};
35  
36 StaticPopupDialogs["AHF_SAVESEARCH"] = {
37 text = AH_FAV.POPUP_TEXT,
38 button1 = AH_FAV.SAVE,
39 button2 = AH_FAV.CANCEL,
40 hasEditBox = 1,
41 maxLetters = 40,
42 OnAccept = function()
43 local editBox = getglobal(this:GetParent():GetName().."EditBox");
44 AHFav:SaveSearch(editBox:GetText());
45 this:GetParent():Hide();
46 end,
47 OnShow = function()
48 getglobal(this:GetName().."EditBox"):SetFocus();
49 getglobal(this:GetName().."EditBox"):SetText(BrowseName:GetText());
50 end,
51 OnHide = function()
52 if ( ChatFrameEditBox:IsVisible() ) then
53 ChatFrameEditBox:SetFocus();
54 end
55 getglobal(this:GetName().."EditBox"):SetText("");
56 end,
57 EditBoxOnEnterPressed = function()
58 local editBox = getglobal(this:GetParent():GetName().."EditBox");
59 AHFav:SaveSearch(editBox:GetText());
60 this:GetParent():Hide();
61 end,
62 EditBoxOnEscapePressed = function()
63 this:GetParent():Hide();
64 end,
65 timeout = 0,
66 exclusive = 1,
67 whileDead = 1
68 };
69  
70 --[[
71 Class Setup
72  
73 --]]
74  
75 AHFav = AceAddon:new({
76 name = AH_FAV.NAME,
77 description = AH_FAV.DESCRIPTION,
78 version = "1800.2",
79 releaseDate = "10-26-2005",
80 aceCompatible = "102",
81 author = "Narwick",
82 email = "narwick@somewhere.com",
83 website = "http://",
84 category = "others",
85 optionsFrame = nil,
86 db = AceDatabase:new("AHFavDB"),
87 defaults = DEFAULT_OPTIONS,
88 cmd = AceChatCmd:new(AH_FAV.COMMANDS, AHFAV_OPTIONS),
89 })
90  
91 function AHFav:Initialize()
92 self.GetOpt = function(var) local v=self.db:get(self.profilePath,var) return v end
93 self.SetOpt = function(var,val) self.db:set(self.profilePath,var,val) end
94 self.TogOpt = function(var) return self.db:toggle(self.profilePath,var) end
95  
96 if (self.GetOpt("autoQuery") == nil) then
97 self.SetOpt("autoQuery", DEFAULT_OPTIONS.autoQuery);
98 end
99  
100  
101 if (self.GetOpt("FSL") == nil) then
102 self.SetOpt("FSL", DEFAULT_OPTIONS.FSL);
103 end
104  
105 -- setup search accessor/setter
106 self.GetSearch = function(key)
107 local v=self.db:get({self.profilePath, "AHFavSearches"}, key)
108 return v
109 end
110 self.SetSearch = function(key, val) self.db:set({self.profilePath, "AHFavSearches"}, key, val) end;
111 self.AllSearches = function()
112 local v = self.db:get(self.profilePath, "AHFavSearches");
113 if (v == nill) then
114 return {}
115 end
116 return v;
117 end
118  
119 -- register to be notified when AH interface comes up
120 self:RegisterEvent("AUCTION_HOUSE_SHOW", "Position")
121  
122 -- Tell the user we're initialized
123 DEFAULT_CHAT_FRAME:AddMessage(AH_FAV.INITMSG, 0.8, 0.8, 0.2);
124 end
125  
126 -- Enable disable simply show or hide the frame
127 function AHFav:Enable()
128 DEFAULT_CHAT_FRAME:AddMessage(AH_FAV.ENABLE_MSG, 0.8, 0.8, 0.2);
129 AHFavs:Show();
130 end
131  
132 function AHFav:Disable()
133 DEFAULT_CHAT_FRAME:AddMessage(AH_FAV.DISABLE_MSG, 0.8, 0.8, 0.2);
134 AHFavs:Hide();
135 end
136  
137 -- Toggle AutoQuery
138 function AHFav:ToggleAutoQuery()
139 self.TogOpt("autoQuery");
140 if (self.GetOpt("autoQuery")) then
141 DEFAULT_CHAT_FRAME:AddMessage(AH_FAV.AUTOQUERY_ENABLE_MSG, 0.8, 0.8, 0.2);
142 else
143 DEFAULT_CHAT_FRAME:AddMessage(AH_FAV.AUTOQUERY_DISABLE_MSG, 0.8, 0.8, 0.2);
144 end
145 end
146  
147 -- Toggle FSL integration
148 function AHFav:ToggleFSL()
149 self.TogOpt("FSL");
150 if (self.GetOpt("FSL")) then
151 DEFAULT_CHAT_FRAME:AddMessage(AH_FAV.FSL_ENABLE_MSG, 0.8, 0.8, 0.2);
152 else
153 DEFAULT_CHAT_FRAME:AddMessage(AH_FAV.FSL_DISABLE_MSG, 0.8, 0.8, 0.2);
154 end
155 end
156  
157 function AHFav:GetFSL()
158 if (self.GetOpt) then
159 local v = self.GetOpt("FSL")
160 return v
161 else
162 return nil
163 end
164 end
165  
166 -- Save the current search criteria
167 function AHFav:SaveSearch(searchName)
168  
169 -- Gather up the fields
170 local lastSearch = {
171 name = BrowseName:GetText(),
172 minLevel = BrowseMinLevel:GetText(),
173 maxLevel = BrowseMaxLevel:GetText(),
174 invTypeIndex = AuctionFrameBrowse.selectedInvtypeIndex,
175 classIndex = AuctionFrameBrowse.selectedClassIndex,
176 subclassIndex = AuctionFrameBrowse.selectedSubclassIndex,
177 subclass = AuctionFrameBrowse.selectedSubclass,
178 isUsable = IsUsableCheckButton:GetChecked(),
179 showOnPlayer = ShowOnPlayerCheckButton:GetChecked(),
180 qualityIndex = UIDropDownMenu_GetSelectedValue(BrowseDropDown)
181 }
182  
183 -- now save them
184 self.SetSearch(searchName, lastSearch);
185  
186 -- reinitialize the popup to set the new value in the proper place
187 UIDropDownMenu_Initialize(AHFavs, SearchesDropDown_Initialize);
188  
189 -- set the popup list to the newly saved entry
190  
191 -- This is the way to do it looking at the API, but when
192 -- a pseudo dropdown is being used, an internal call
193 -- to SetText in UIDropDown.lua fails because there
194 -- is no currently selected label.
195 -- UIDropDownMenu_SetSelectedName(AHFavs, searchName);
196  
197 -- Instead, set the internal vars directly. This may blow up at
198 -- some point in the future, but oh well.
199 AHFavs.selectedName = searchName;
200 AHFavs.selectedID = nil;
201 AHFavs.selectedValue = nil;
202  
203 end
204  
205 function AHFav:LoadSearch(searchName, clear)
206  
207 -- initialze for a blank search
208 local lastSearch = {
209 name = "",
210 minLevel = "",
211 maxLevel = "",
212 qualityIndex = -1,
213 };
214  
215 -- Get the selected search
216 if (not clear) then
217 lastSearch = self.GetSearch(searchName);
218 end
219  
220 -- Load the fields
221 BrowseName:SetText(lastSearch["name"]);
222 BrowseMinLevel:SetText(lastSearch["minLevel"]);
223 BrowseMaxLevel:SetText(lastSearch["maxLevel"]);
224 AuctionFrameBrowse.selectedInvtypeIndex = lastSearch["invTypeIndex"];
225 AuctionFrameBrowse.selectedClassIndex = lastSearch["classIndex"];
226 AuctionFrameBrowse.selectedClass = CLASS_FILTERS[lastSearch["classIndex"]];
227 AuctionFrameBrowse.selectedSubclassIndex = lastSearch["subclassIndex"];
228 AuctionFrameBrowse.selectedSubclass = lastSearch["subclass"];
229 IsUsableCheckButton:SetChecked(lastSearch["isUsable"]);
230 ShowOnPlayerCheckButton:SetChecked(lastSearch["showOnPlayer"]);
231 UIDropDownMenu_SetSelectedValue(BrowseDropDown, lastSearch["qualityIndex"]);
232  
233 -- Tell the filters to update
234 AuctionFrameFilters_Update();
235  
236 -- Tell the rarity pulldown to update
237 UIDropDownMenu_Refresh(BrowseDropDown, false);
238  
239 -- Update the popup to the current search, or clear it
240 if (not clear) then
241 -- See notes in SaveSearch
242 -- UIDropDownMenu_SetSelectedName(AHFavs, searchName);
243 AHFavs.selectedName = searchName;
244 AHFavs.selectedID = nil;
245 AHFavs.selectedValue = nil;
246 else
247 -- See notes in SaveSearch
248 -- UIDropDownMenu_ClearAll(AHFavs);
249 AHFavs.selectedName = nil;
250 AHFavs.selectedID = nil;
251 AHFavs.selectedValue = nil;
252 end
253  
254 -- auto run the loaded search
255 if ((not clear) and self.GetOpt("autoQuery") and CanSendAuctionQuery()) then
256 AuctionFrameBrowse_Search()
257 end
258  
259 end
260  
261 function AHFav:DeleteSearch(searchName)
262  
263 -- check if nothing is selected, return if so
264 if (searchName == nil) then
265 return
266 end
267  
268 -- Remove the search
269 self.SetSearch(searchName, nil);
270  
271 -- Clear the previously selected search
272 -- See notes in SaveSearch
273 -- UIDropDownMenu_ClearAll(AHFavs);
274 AHFavs.selectedName = nil;
275 AHFavs.selectedID = nil;
276 AHFavs.selectedValue = nil;
277 end
278  
279  
280 -- Ace report
281 function AHFav:Report()
282 self.cmd:report({
283 {text=AH_FAV.AUTOQUERY, val=self.GetOpt("autoQuery"), map=ACE_MAP_ONOFF},
284 {text=AH_FAV.FSL_NAME, val=self.GetOpt("FSL"), map=ACE_MAP_ONOFF},
285 })
286 end
287  
288 -- GUI Functions
289  
290 function AHFav:SearchesDropDown_OnLoad()
291 UIDropDownMenu_Initialize(this:GetParent(), SearchesDropDown_Initialize);
292 UIDropDownMenu_SetAnchor(-124, 0, this:GetParent(), "TOPLEFT", this:GetName(), "BOTTOMRIGHT")
293 end
294  
295 function SearchesDropDown_Initialize()
296  
297 -- Skip everything if AHFav object hasn't loaded yet
298 if (not AHFav) then
299 return
300 end
301  
302 local info = {};
303 local searches = {};
304  
305 -- Add a title item
306 local favoritesTitle = {};
307 favoritesTitle.text = AH_FAV.FAVORITES;
308 favoritesTitle.notClickable = true;
309 favoritesTitle.notCheckable = true;
310  
311 UIDropDownMenu_AddButton(favoritesTitle);
312  
313 -- Add all the saved searches
314 if (AHFav.AllSearches) then
315 searches = AHFav:AllSearches();
316 end
317  
318 for i,v in pairsByKeys(searches) do
319 info.text = i;
320 local staticText = i;
321 info.func = function () AHFav:LoadSearch(staticText); end;
322 info.checked = false;
323 UIDropDownMenu_AddButton(info);
324 end
325  
326 -- Separator
327 local separator = {};
328 separator.text = "--------";
329 separator.notClickable = true;
330 separator.notCheckable = true;
331  
332 UIDropDownMenu_AddButton(separator);
333  
334 -- Save Button
335 info.text = AH_FAV.SAVE;
336 info.func = function () StaticPopup_Show("AHF_SAVESEARCH"); end;
337 info.notCheckable = true;
338 info.checked = false;
339  
340 UIDropDownMenu_AddButton(info);
341  
342 -- Delete Button
343 info.text = AH_FAV.DELETE;
344 info.func = function ()
345 currentSearch = UIDropDownMenu_GetSelectedName(AHFavs);
346 AHFav:DeleteSearch(currentSearch);
347 end;
348 info.notCheckable = true;
349 info.checked = false;
350  
351 UIDropDownMenu_AddButton(info);
352  
353 -- Clear Button
354 info.text = AH_FAV.CLEAR;
355 info.func = function ()
356 AHFav:LoadSearch(nil, true);
357 end;
358 info.notCheckable = true;
359 info.checked = false;
360  
361 UIDropDownMenu_AddButton(info);
362  
363 -- Add ShoppingList if enabled
364  
365 if (AHFav:GetFSL()) then
366 -- check if FSL is enabled
367 if (FSL_Config and FSL_Config.Enabled) then
368  
369 -- Add a separator
370 UIDropDownMenu_AddButton(separator);
371  
372 -- Add ShoppingList Header
373 local SLseparator = {};
374 SLseparator.text = AH_FAV.FSL_SHORT;
375 SLseparator.notClickable = true;
376 SLseparator.notCheckable = true;
377  
378 UIDropDownMenu_AddButton(SLseparator);
379  
380 -- Get the ShoppingList
381 local realm = GetCVar("realmName");
382 local realmList = FSL_ShoppingList[realm];
383  
384 if realmList == nil then return; end
385  
386 -- Loop through and add items
387 for _, itemLink in realmList do
388 -- Get the name
389 local name = GetItemInfo(itemLink);
390 local staticItemLink = itemLink;
391  
392 info.value = itemLink
393 info.func = function () AHFav:LoadSLSearch(staticItemLink) end
394 info.checked = false
395 info.notCheckable = false
396  
397 -- Totally lame that GetItemInfo doesn't return if not in local cache
398 -- do this hack to get the name in that case
399 -- technique stolen from LootLink
400 if (not name) then
401 for litem, lname in string.gfind(itemLink, "|Hitem:(%d+:%d+:%d+:%d+)|h%[(.-)%]|h") do
402 info.text = lname
403 end
404 else
405 info.text = name
406 end
407 UIDropDownMenu_AddButton(info);
408 end
409 end
410 end
411  
412 end
413  
414 function AHFav:LoadSLSearch(itemLink)
415  
416 local name = GetItemInfo(itemLink);
417  
418 if (not name) then
419 for litem, lname in string.gfind(itemLink, "|Hitem:(%d+:%d+:%d+:%d+)|h%[(.-)%]|h") do
420 name = lname
421 end
422 end
423  
424 -- Load the fields
425 BrowseName:SetText(name);
426 BrowseMinLevel:SetText("");
427 BrowseMaxLevel:SetText("");
428 AuctionFrameBrowse.selectedInvtypeIndex = nil;
429 AuctionFrameBrowse.selectedClassIndex = nil;
430 AuctionFrameBrowse.selectedClass = nil;
431 AuctionFrameBrowse.selectedSubclassIndex = nil;
432 AuctionFrameBrowse.selectedSubclass = nil;
433 IsUsableCheckButton:SetChecked(nil);
434 UIDropDownMenu_SetSelectedValue(BrowseDropDown, nil);
435  
436 -- Tell the filters to update
437 AuctionFrameFilters_Update();
438  
439 -- Update the popup to the current search, or clear it
440 -- See notes in SaveSearch
441 -- UIDropDownMenu_SetSelectedName(AHFavs, name);
442  
443 AHFavs.selectedName = name;
444 AHFavs.selectedID = nil;
445 AHFavs.selectedValue = nil;
446  
447 -- auto run the loaded search
448 if (self.GetOpt("autoQuery") and CanSendAuctionQuery()) then
449 AuctionFrameBrowse_Search()
450 end
451  
452 end
453  
454 -- repositions AHFav dropdown with dynamic loaded AH interface
455 function AHFav:Position()
456 AHFavs:ClearAllPoints()
457 AHFavs:SetParent("AuctionFrameBrowse")
458 AHFavs:SetFrameStrata("HIGH")
459 AHFavs:SetPoint("TOPLEFT", "AuctionFrameBrowse", "TOPLEFT", 195, -45)
460 AHFavsButton:Show()
461 AHFavs:Show()
462 end
463  
464 -- Utility function to sort searches
465 -- Lifted from LUA book online
466 function pairsByKeys (t, f)
467 local a = {}
468 for n in pairs(t) do table.insert(a, n) end
469 table.sort(a, f)
470 local i = 0 -- iterator variable
471 local iter = function () -- iterator function
472 i = i + 1
473 if a[i] == nil then return nil
474 else return a[i], t[a[i]]
475 end
476 end
477 return iter
478 end
479  
480 --[[
481 register the class
482  
483 --]]
484  
485 AHFav:RegisterForLoad()
486