Advertisement
Guest User

Auc-Util-SearchUI/SearcherGeneral.lua

a guest
Jul 20th, 2016
1,392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.18 KB | None | 0 0
  1. --[[
  2.     Auctioneer - Search UI - Searcher General
  3.     Version: 5.21f.5579 (SanctimoniousSwamprat)
  4.     Revision: $Id: SearcherGeneral.lua 5498 2014-10-18 13:24:18Z brykrys $
  5.     URL: http://auctioneeraddon.com/
  6.  
  7.     This is a plugin module for the SearchUI that assists in searching by refined paramaters
  8.  
  9.     License:
  10.         This program is free software; you can redistribute it and/or
  11.         modify it under the terms of the GNU General Public License
  12.         as published by the Free Software Foundation; either version 2
  13.         of the License, or (at your option) any later version.
  14.  
  15.         This program is distributed in the hope that it will be useful,
  16.         but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.         GNU General Public License for more details.
  19.  
  20.         You should have received a copy of the GNU General Public License
  21.         along with this program(see GPL.txt); if not, write to the Free Software
  22.         Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  23.  
  24.     Note:
  25.         This AddOn's source code is specifically designed to work with
  26.         World of Warcraft's interpreted AddOn system.
  27.         You have an implicit license to use this AddOn with these facilities
  28.         since that is its designated purpose as per:
  29.         http://www.fsf.org/licensing/licenses/gpl-faq.html#InterpreterIncompat
  30. --]]
  31. -- Create a new instance of our lib with our parent
  32. if not AucSearchUI then return end
  33. local lib, parent, private = AucSearchUI.NewSearcher("General")
  34. if not lib then return end
  35. local print,decode,_,_,replicate,empty,_,_,_,debugPrint,fill = AucAdvanced.GetModuleLocals()
  36. local get,set,default,Const = AucSearchUI.GetSearchLocals()
  37. lib.tabname = "General"
  38.  
  39. function private.getTypes()
  40.     if not private.typetable then
  41.         -- private.typetable = {GetAuctionItemClasses()}
  42.         private.typetable = (AucAdvanced and AucAdvanced.Const and AucAdvanced.Const.CLASSES) or {
  43.             AUCTION_CATEGORY_WEAPONS,
  44.             AUCTION_CATEGORY_ARMOR,
  45.             AUCTION_CATEGORY_CONTAINERS,
  46.             AUCTION_CATEGORY_GEMS,
  47.             AUCTION_CATEGORY_ITEM_ENHANCEMENT,
  48.             AUCTION_CATEGORY_CONSUMABLES,
  49.             AUCTION_CATEGORY_GLYPHS,
  50.             AUCTION_CATEGORY_TRADE_GOODS,
  51.             AUCTION_CATEGORY_RECIPES,
  52.             AUCTION_CATEGORY_BATTLE_PETS,
  53.             AUCTION_CATEGORY_QUEST_ITEMS,
  54.             AUCTION_CATEGORY_MISCELLANEOUS
  55.             -- TOKEN_FILTER_LABEL
  56.         }
  57.         table.insert(private.typetable,1, "All")
  58.     end
  59.     return private.typetable
  60. end
  61.  
  62. function private.getSubTypes()
  63.     local subtypetable, typenumber
  64.     local typename = get("general.type")
  65.     local typetable = private.getTypes()
  66.     if typename ~= "All" then
  67.         for i, j in pairs(typetable) do
  68.             if j == typename then
  69.                 typenumber = i
  70.                 break
  71.             end
  72.         end
  73.     end
  74.     if typenumber then
  75.         subtypetable = {GetAuctionItemSubClasses(typenumber-1)}-- subtract 1 because 1 is the "All" category
  76.         table.insert(subtypetable, 1, "All")
  77.     else
  78.         subtypetable = {[1]="All"}
  79.     end
  80.     return subtypetable
  81. end
  82.  
  83. function private.getQuality()
  84.     return {
  85.             {-1, "All"},
  86.             {0, "Poor"},
  87.             {1, "Common"},
  88.             {2, "Uncommon"},
  89.             {3, "Rare"},
  90.             {4, "Epic"},
  91.             {5, "Legendary"},
  92.             {6, "Artifact"},
  93.         }
  94. end
  95.  
  96. function private.getTimeLeft()
  97.     return {
  98.             {0, "Any"},
  99.             {1, "less than 30 min"},
  100.             {2, "2 hours"},
  101.             {3, "12 hours"},
  102.             {4, "48 hours"},
  103.         }
  104. end
  105.  
  106. -- Set our defaults
  107. default("general.name", "")
  108. default("general.name.exact", false)
  109. default("general.name.regexp", false)
  110. default("general.name.invert", false)
  111. default("general.type", "All")
  112. default("general.subtype", "All")
  113. default("general.quality", -1)
  114. default("general.timeleft", 0)
  115. default("general.ilevel.min", 0)
  116. default("general.ilevel.max", Const.MAXITEMLEVEL)
  117. default("general.ulevel.min", 0)
  118. default("general.ulevel.max", Const.MAXUSERLEVEL)
  119. default("general.seller", "")
  120. default("general.seller.exact", false)
  121. default("general.seller.regexp", false)
  122. default("general.seller.invert", false)
  123. default("general.minbid", 0)
  124. default("general.minbuy", 0)
  125. default("general.maxbid", Const.MAXBIDPRICE)
  126. default("general.maxbuy", Const.MAXBIDPRICE)
  127.  
  128. -- This function is automatically called when we need to create our search generals
  129. function lib:MakeGuiConfig(gui)
  130.     -- Get our tab and populate it with our controls
  131.     local id = gui:AddTab(lib.tabname, "Searchers")
  132.  
  133.     -- Add the help
  134.     gui:AddSearcher("General", "Search for items by general properties such as name, level etc", 100)
  135.     gui:AddHelp(id, "general searcher",
  136.         "What does this searcher do?",
  137.         "This searcher provides the ability to search for specific items that are in the scan database by name, level, type, subtype, seller, price, timeleft and other similar generals.")
  138.  
  139.     gui:MakeScrollable(id)
  140.     gui:AddControl(id, "Header",     0,      "Search criteria")
  141.  
  142.     local last = gui:GetLast(id)
  143.     gui:SetControlWidth(0.35)
  144.     local nameEdit = gui:AddControl(id, "Text",       0,   1, "general.name", "Item name")
  145.     nameEdit:SetScript("OnTextChanged", function(...) gui:ChangeSetting(...) end) --have the edit box update as user types, default box only updates on escape or enter
  146.  
  147.     local cont = gui:GetLast(id)
  148.     gui:SetLast(id, last)
  149.     gui:AddControl(id, "Checkbox",   0.11, 0, "general.name.exact", "Exact")
  150.     gui:SetLast(id, last)
  151.     gui:AddControl(id, "Checkbox",   0.21, 0, "general.name.regexp", "Lua Pattern")
  152.     gui:SetLast(id, last)
  153.     gui:AddControl(id, "Checkbox",   0.35, 0, "general.name.invert", "Invert")
  154.  
  155.     gui:SetLast(id, cont)
  156.     last = cont
  157.  
  158.     gui:AddControl(id, "Note",       0.0, 1, 100, 14, "Type:")
  159.     gui:AddControl(id, "Selectbox",   0.0, 1, private.getTypes, "general.type")
  160.     gui:SetLast(id, last)
  161.     gui:AddControl(id, "Note",       0.3, 1, 100, 14, "SubType:")
  162.     gui:AddControl(id, "Selectbox",   0.3, 1, private.getSubTypes, "general.subtype")
  163.     gui:SetLast(id, last)
  164.     gui:AddControl(id, "Note",       0.7, 1, 100, 14, "TimeLeft:")
  165.     gui:AddControl(id, "Selectbox",  0.7, 1, private.getTimeLeft(), "general.timeleft")
  166.  
  167.     gui:AddControl(id, "Note",       0.0, 1, 100, 14, "Quality:")
  168.     gui:AddControl(id, "Selectbox",   0.0, 1, private.getQuality(), "general.quality")
  169.  
  170.     last = gui:GetLast(id)
  171.     gui:SetControlWidth(0.37)
  172.     gui:AddControl(id, "NumeriSlider",     0,   1, "general.ilevel.min", 0, Const.MAXITEMLEVEL, 1, "Min item level")
  173.     gui:SetControlWidth(0.37)
  174.     gui:AddControl(id, "NumeriSlider",     0,   1, "general.ilevel.max", 0, Const.MAXITEMLEVEL, 1, "Max item level")
  175.     cont = gui:GetLast(id)
  176.  
  177.     gui:SetLast(id, last)
  178.     gui:SetControlWidth(0.17)
  179.     gui:AddControl(id, "NumeriSlider",     0.6, 0, "general.ulevel.min", 0, Const.MAXUSERLEVEL, 1, "Min user level")
  180.     gui:SetControlWidth(0.17)
  181.     gui:AddControl(id, "NumeriSlider",     0.6, 0, "general.ulevel.max", 0, Const.MAXUSERLEVEL, 1, "Max user level")
  182.  
  183.     gui:SetLast(id, cont)
  184.  
  185.     last = gui:GetLast(id)
  186.     gui:SetControlWidth(0.35)
  187.     gui:AddControl(id, "Text",       0,   1, "general.seller", "Seller name")
  188.     cont = gui:GetLast(id)
  189.     gui:SetLast(id, last)
  190.     gui:AddControl(id, "Checkbox",   0.13, 0, "general.seller.exact", "Exact")
  191.     gui:SetLast(id, last)
  192.     gui:AddControl(id, "Checkbox",   0.23, 0, "general.seller.regexp", "Lua Pattern")
  193.     gui:SetLast(id, last)
  194.     gui:AddControl(id, "Checkbox",   0.37, 0, "general.seller.invert", "Invert")
  195.  
  196.     gui:SetLast(id, cont)
  197.     gui:AddControl(id, "MoneyFramePinned", 0, 1, "general.minbid", 0, Const.MAXBIDPRICE, "Minimum Bid")
  198.     gui:SetLast(id, cont)
  199.     gui:AddControl(id, "MoneyFramePinned", 0.5, 1, "general.minbuy", 0, Const.MAXBIDPRICE, "Minimum Buyout")
  200.     last = gui:GetLast(id)
  201.     gui:AddControl(id, "MoneyFramePinned", 0, 1, "general.maxbid", 0, Const.MAXBIDPRICE, "Maximum Bid")
  202.     gui:SetLast(id, last)
  203.     gui:AddControl(id, "MoneyFramePinned", 0.5, 1, "general.maxbuy", 0, Const.MAXBIDPRICE, "Maximum Buyout")
  204. end
  205.  
  206. function lib.Search(item)
  207.     private.debug = ""
  208.     if private.NameSearch("name", item[Const.NAME])
  209.             and private.TypeSearch(item[Const.ITYPE], item[Const.ISUB])
  210.             and private.TimeSearch(item[Const.TLEFT])
  211.             and private.QualitySearch(item[Const.QUALITY])
  212.             and private.LevelSearch("ilevel", item[Const.ILEVEL])
  213.             and private.LevelSearch("ulevel", item[Const.ULEVEL])
  214.             and private.NameSearch("seller", item[Const.SELLER])
  215.             and private.PriceSearch("Bid", item[Const.PRICE])
  216.             and private.PriceSearch("Buy", item[Const.BUYOUT]) then
  217.         return true
  218.     else
  219.         return false, private.debug
  220.     end
  221. end
  222.  
  223. --Rescan is an optional method a searcher can implement that allows it to queue a rescan of teh ah
  224. --Just pass any item you want rescaned
  225. function lib.Rescan()
  226.     local name = get("general.name")
  227.     local min = get("general.ulevel.min")
  228.     local max = get("general.ulevel.max")
  229.     local quality = get("general.quality")
  230.  
  231.     --convert these to the AH API index #
  232.     local searchtype = get("general.type")
  233.     local searchsubtype = get("general.subtype")
  234.  
  235.     local classIndex = AucAdvanced.Const.CLASSESREV[searchtype]
  236.     local subclassIndex
  237.     if classIndex then
  238.         subclassIndex = AucAdvanced.Const.SUBCLASSESREV[searchtype][searchsubtype]
  239.     end
  240.  
  241.     if name then
  242.         --print(name, min, max, nil, classIndex, subclassIndex, nil, quality)
  243.         AucSearchUI.RescanAuctionHouse(name, min, max, nil, classIndex, subclassIndex, nil, quality )
  244.     end
  245. end
  246.  
  247.  
  248. function private.LevelSearch(levelType, itemLevel)
  249.     local min = get("general."..levelType..".min")
  250.     local max = get("general."..levelType..".max")
  251.  
  252.     if itemLevel < min then
  253.         private.debug = levelType.." too low"
  254.         return false
  255.     end
  256.     if itemLevel > max then
  257.         private.debug = levelType.." too high"
  258.         return false
  259.     end
  260.     return true
  261. end
  262.  
  263. function private.NameSearch(nametype,itemName)
  264.     local name = get("general."..nametype)
  265.  
  266.     -- If there's no name, then this matches
  267.     if not name or name == "" then
  268.         return true
  269.     end
  270.  
  271.     -- Lowercase the input
  272.     name = name:lower()
  273.     itemName = itemName:lower()
  274.  
  275.     -- Get the matching options
  276.     local nameExact = get("general."..nametype..".exact")
  277.     local nameRegexp = get("general."..nametype..".regexp")
  278.     local nameInvert = get("general."..nametype..".invert")
  279.  
  280.     -- if we need to make a non-regexp, exact match:
  281.     if nameExact and not nameRegexp then
  282.         -- If the name matches or we are inverted
  283.         if name == itemName and not nameInvert then
  284.             return true
  285.         elseif name ~= itemName and nameInvert then
  286.             return true
  287.         end
  288.         private.debug = nametype.." is not exact match"
  289.         return false
  290.     end
  291.  
  292.     local plain, text
  293.     text = name
  294.     if not nameRegexp then
  295.         plain = 1
  296.     elseif nameExact then
  297.         text = "^"..name.."$"
  298.     end
  299.  
  300.     local matches = itemName:find(text, 1, plain)
  301.     if matches and not nameInvert then
  302.         return true
  303.     elseif not matches and nameInvert then
  304.         return true
  305.     end
  306.     private.debug = nametype.." does not match critia"
  307.     return false
  308. end
  309.  
  310. function private.TypeSearch(itype, isubtype)
  311.     local searchtype = get("general.type")
  312.     if searchtype == "All" then
  313.         return true
  314.     elseif searchtype == itype then
  315.         local searchsubtype = get("general.subtype")
  316.         if searchsubtype == "All" then
  317.             return true
  318.         elseif searchsubtype == isubtype then
  319.             return true
  320.         else
  321.             private.debug = "Wrong Subtype"
  322.             return false
  323.         end
  324.     else
  325.         private.debug = "Wrong Type"
  326.         return false
  327.     end
  328. end
  329.  
  330. function private.TimeSearch(iTleft)
  331.     local tleft = get("general.timeleft")
  332.     if tleft == 0 then
  333.         return true
  334.     elseif tleft == iTleft then
  335.         return true
  336.     else
  337.         private.debug = "Time left wrong"
  338.         return false
  339.     end
  340. end
  341.  
  342. function private.QualitySearch(iqual)
  343.     local quality = get("general.quality")
  344.     if quality == -1 then
  345.         return true
  346.     elseif quality == iqual then
  347.         return true
  348.     else
  349.         private.debug = "Wrong Quality"
  350.         return false
  351.     end
  352. end
  353.  
  354. function private.PriceSearch(buybid, price)
  355.     local minprice, maxprice
  356.     if buybid == "Bid" then
  357.         minprice = get("general.minbid")
  358.         maxprice = get("general.maxbid")
  359.     else
  360.         minprice = get("general.minbuy")
  361.         maxprice = get("general.maxbuy")
  362.     end
  363.     -- disregard maxprice if it is 0, or if it is less then minprice
  364.     if maxprice == 0 or maxprice < minprice then
  365.         maxprice = nil
  366.     end
  367.     if price >= minprice and (not maxprice or price <= maxprice) then
  368.         return true
  369.     elseif price < minprice then
  370.         private.debug = buybid.." price too low"
  371.     else
  372.         private.debug = buybid.." price too high"
  373.     end
  374.     return false
  375. end
  376. AucAdvanced.RegisterRevision("$URL: http://svn.norganna.org/auctioneer/branches/5.21f/Auc-Util-SearchUI/SearcherGeneral.lua $", "$Rev: 5498 $")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement