Guest User

Auc-Util-ScanButton/ScanButton.lua

a guest
Jul 20th, 2016
1,368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 24.22 KB | None | 0 0
  1. --[[
  2.     Auctioneer - Scan Button module
  3.     Version: 5.21f.5579 (SanctimoniousSwamprat)
  4.     Revision: $Id: ScanButton.lua 5403 2013-04-03 16:50:32Z brykrys $
  5.     URL: http://auctioneeraddon.com/
  6.  
  7.     This is an Auctioneer module that adds a textual scan progress
  8.     indicator to the Auction House UI.
  9.  
  10.     License:
  11.         This program is free software; you can redistribute it and/or
  12.         modify it under the terms of the GNU General Public License
  13.         as published by the Free Software Foundation; either version 2
  14.         of the License, or (at your option) any later version.
  15.  
  16.         This program is distributed in the hope that it will be useful,
  17.         but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.         GNU General Public License for more details.
  20.  
  21.         You should have received a copy of the GNU General Public License
  22.         along with this program(see GPL.txt); if not, write to the Free Software
  23.         Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  24.  
  25.     Note:
  26.         This AddOn's source code is specifically designed to work with
  27.         World of Warcraft's interpreted AddOn system.
  28.         You have an implicit license to use this AddOn with these facilities
  29.         since that is its designated purpose as per:
  30.         http://www.fsf.org/licensing/licenses/gpl-faq.html#InterpreterIncompat
  31. --]]
  32. if not AucAdvanced then return end
  33.  
  34. local libType, libName = "Util", "ScanButton"
  35. local lib,parent,private = AucAdvanced.NewModule(libType, libName)
  36. if not lib then return end
  37. local print,decode,_,_,replicate,empty,get,set,default,debugPrint,fill,_TRANS = AucAdvanced.GetModuleLocals()
  38.  
  39. function lib.Processor(callbackType, ...)
  40.     if (callbackType == "scanprogress") then
  41.         private.UpdateScanProgress(...)
  42.     elseif (callbackType == "auctionui") then
  43.         private.HookAH(...)
  44.     elseif (callbackType == "config") then
  45.         private.SetupConfigGui(...)
  46.     elseif (callbackType == "configchanged") then
  47.         private.ConfigChanged(...)
  48.     end
  49. end
  50.  
  51. lib.Processors = {}
  52. function lib.Processors.scanprogress(callbackType, ...)
  53.     private.UpdateScanProgress(...)
  54. end
  55.  
  56. function lib.Processors.auctionui(callbackType, ...)
  57.     private.HookAH(...)
  58. end
  59.  
  60. function lib.Processors.config(callbackType, ...)
  61.     private.SetupConfigGui(...)
  62. end
  63.  
  64. function lib.Processors.configchanged(callbackType, ...)
  65.     private.ConfigChanged(...)
  66. end
  67.  
  68.  
  69.  
  70. function lib.OnLoad()
  71.     AucAdvanced.Settings.SetDefault("util.scanbutton.enabled", true)
  72.     AucAdvanced.Settings.SetDefault("util.scanbutton.message", true)
  73.     AucAdvanced.Settings.SetDefault("util.scanbutton.getall", false)
  74. end
  75.  
  76. -- /run local t = AucAdvanced.Modules.Util.ScanButton.Private.buttons.stop.tex t:SetPoint("TOPLEFT", t:GetParent() "TOPLEFT", 3,-3) t:SetPoint("BOTTOMRIGHT", t:GetParent(), "BOTTOMRIGHT", -3,3)
  77. -- /run local t = AucAdvanced.Modules.Util.ScanButton.Private.buttons.stop.tex t:SetTexture("Interface\\AddOns\\Auc-Advanced\\Textures\\NavButtons") t:SetTexCoord(0.25, 0.5, 0, 1) t:SetVertexColor(1.0, 0.9, 0.1)
  78.  
  79. function private.HookAH()
  80.     private.buttons = CreateFrame("Frame", nil, AuctionFrameBrowse)
  81.     private.buttons:SetPoint("TOPLEFT", AuctionFrameBrowse, "TOPLEFT", 180,-15)
  82.     private.buttons:SetWidth(22*4 + 4)
  83.     private.buttons:SetHeight(18)
  84.     private.buttons:SetScript("OnUpdate", private.OnUpdate)
  85.  
  86.     private.buttons.stop = CreateFrame("Button", nil, private.buttons, "OptionsButtonTemplate")
  87.     private.buttons.stop:SetPoint("TOPLEFT", private.buttons, "TOPLEFT", 0,0)
  88.     private.buttons.stop:SetWidth(22)
  89.     private.buttons.stop:SetHeight(18)
  90.     private.buttons.stop:SetScript("OnClick", private.stop)
  91.     private.buttons.stop.tex = private.buttons.stop:CreateTexture(nil, "OVERLAY")
  92.     private.buttons.stop.tex:SetPoint("TOPLEFT", private.buttons.stop, "TOPLEFT", 4,-2)
  93.     private.buttons.stop.tex:SetPoint("BOTTOMRIGHT", private.buttons.stop, "BOTTOMRIGHT", -4,2)
  94.     private.buttons.stop:SetScript("OnEnter", function()
  95.             GameTooltip:SetOwner(private.buttons.stop, "ANCHOR_TOPRIGHT")
  96.             GameTooltip:SetText("Click to stop the current scan")
  97.         end)
  98.     private.buttons.stop:SetScript("OnLeave", function()
  99.             GameTooltip:Hide()
  100.         end)
  101.     private.buttons.stop.tex:SetTexture("Interface\\AddOns\\Auc-Advanced\\Textures\\NavButtons")
  102.     private.buttons.stop.tex:SetTexCoord(0.25, 0.5, 0, 1)
  103.     private.buttons.stop.tex:SetVertexColor(1.0, 0.9, 0.1)
  104.     --displays remaining # of scans queued
  105.     private.buttons.stop.count = private.buttons.stop:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
  106.     private.buttons.stop.count:ClearAllPoints()
  107.     private.buttons.stop.count:SetPoint("RIGHT", private.buttons.stop, "LEFT", -5, 0)
  108.     private.buttons.stop.count:SetTextColor(1, 0.8, 0)
  109.     private.buttons.stop.count:SetText("0")
  110.     private.buttons.stop.count:SetJustifyH("RIGHT")
  111.  
  112.     private.buttons.play = CreateFrame("Button", nil, private.buttons, "OptionsButtonTemplate")
  113.     private.buttons.play:SetPoint("TOPLEFT", private.buttons.stop, "TOPRIGHT", 2,0)
  114.     private.buttons.play:SetWidth(22)
  115.     private.buttons.play:SetHeight(18)
  116.     private.buttons.play:SetScript("OnClick", private.play)
  117.     private.buttons.play.tex = private.buttons.play:CreateTexture(nil, "OVERLAY")
  118.     private.buttons.play.tex:SetPoint("TOPLEFT", private.buttons.play, "TOPLEFT", 4,-2)
  119.     private.buttons.play.tex:SetPoint("BOTTOMRIGHT", private.buttons.play, "BOTTOMRIGHT", -4,2)
  120.     private.buttons.play:SetScript("OnEnter", function()
  121.             GameTooltip:SetOwner(private.buttons.play, "ANCHOR_TOPRIGHT")
  122.             GameTooltip:SetText("Click here to start/resume a scan of the auction house")
  123.         end)
  124.     private.buttons.play:SetScript("OnLeave", function()
  125.             GameTooltip:Hide()
  126.         end)
  127.     private.buttons.play.tex:SetTexture("Interface\\AddOns\\Auc-Advanced\\Textures\\NavButtons")
  128.     private.buttons.play.tex:SetTexCoord(0, 0.25, 0, 1)
  129.     private.buttons.play.tex:SetVertexColor(1.0, 0.9, 0.1)
  130.  
  131.     private.buttons.pause = CreateFrame("Button", nil, private.buttons, "OptionsButtonTemplate")
  132.     private.buttons.pause:SetPoint("TOPLEFT", private.buttons.play, "TOPRIGHT", 2,0)
  133.     private.buttons.pause:SetWidth(22)
  134.     private.buttons.pause:SetHeight(18)
  135.     private.buttons.pause:SetScript("OnClick", private.pause)
  136.     private.buttons.pause.tex = private.buttons.pause:CreateTexture(nil, "OVERLAY")
  137.     private.buttons.pause.tex:SetPoint("TOPLEFT", private.buttons.pause, "TOPLEFT", 4,-2)
  138.     private.buttons.pause.tex:SetPoint("BOTTOMRIGHT", private.buttons.pause, "BOTTOMRIGHT", -4,2)
  139.     private.buttons.pause:SetScript("OnEnter", function()
  140.             GameTooltip:SetOwner(private.buttons.pause, "ANCHOR_TOPRIGHT")
  141.             GameTooltip:SetText("Click here to pause the current scan")
  142.         end)
  143.     private.buttons.pause:SetScript("OnLeave", function()
  144.             GameTooltip:Hide()
  145.         end)
  146.     private.buttons.pause.tex:SetTexture("Interface\\AddOns\\Auc-Advanced\\Textures\\NavButtons")
  147.     private.buttons.pause.tex:SetTexCoord(0.5, 0.75, 0, 1)
  148.     private.buttons.pause.tex:SetVertexColor(1.0, 0.9, 0.1)
  149.  
  150.     private.buttons.getall = CreateFrame("Button", nil, private.buttons, "OptionsButtonTemplate")
  151.     private.buttons.getall:SetPoint("TOPLEFT", private.buttons.pause, "TOPRIGHT", 2,0)
  152.     private.buttons.getall:SetWidth(22)
  153.     private.buttons.getall:SetHeight(18)
  154.     private.buttons.getall:SetScript("OnClick", private.getall)
  155.     private.buttons.getall.tex = private.buttons.getall:CreateTexture(nil, "OVERLAY")
  156.     private.buttons.getall.tex:SetPoint("TOPLEFT", private.buttons.getall, "TOPLEFT", 4,-2)
  157.     private.buttons.getall.tex:SetPoint("BOTTOMRIGHT", private.buttons.getall, "BOTTOMRIGHT", -4,2)
  158.     private.buttons.getall:SetScript("OnEnter", function()
  159.             GameTooltip:SetOwner(private.buttons.getall, "ANCHOR_TOPRIGHT")
  160.             GameTooltip:SetText("Click here to do a fast getall scan of the auction house")
  161.         end)
  162.     private.buttons.getall:SetScript("OnLeave", function()
  163.             GameTooltip:Hide()
  164.         end)
  165.     private.buttons.getall.tex:SetTexture("Interface\\AddOns\\Auc-Advanced\\Textures\\NavButtons")
  166.     private.buttons.getall.tex:SetTexCoord(0.75, 1, 0, 1)
  167.     private.buttons.getall.tex:SetVertexColor(0.3, 0.7, 1.0)
  168.  
  169.     local msg = CreateFrame("Frame", nil, UIParent)
  170.     private.message = msg
  171.     msg:Hide()
  172.     msg:SetPoint("CENTER", "UIParent", "CENTER")
  173.     msg:SetFrameStrata("DIALOG")
  174.     msg:SetHeight(280)
  175.     msg:SetWidth(500)
  176.     msg:SetBackdrop({
  177.         bgFile = "Interface/Tooltips/UI-Tooltip-Background",
  178.         edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
  179.         tile = true, tileSize = 32, edgeSize = 32,
  180.         insets = { left = 9, right = 9, top = 9, bottom = 9 }
  181.     })
  182.     msg:SetBackdropColor(0,0,0, 1)
  183.  
  184.     msg.Done = CreateFrame("Button", "", msg, "OptionsButtonTemplate")
  185.     msg.Done:SetText("Done")
  186.     msg.Done:SetPoint("BOTTOMRIGHT", msg, "BOTTOMRIGHT", -10, 10)
  187.     msg.Done:SetScript("OnClick", function() msg:Hide() end)
  188.  
  189.     msg.Text = msg:CreateFontString(nil, "HIGH")
  190.     msg.Text:SetPoint("TOPLEFT", msg, "TOPLEFT", 20, -20)
  191.     msg.Text:SetPoint("BOTTOMRIGHT", msg.Done, "TOPRIGHT", -10, 10)
  192.     msg.Text:SetFont(STANDARD_TEXT_FONT,14)
  193.     msg.Text:SetJustifyH("LEFT")
  194.     msg.Text:SetJustifyV("TOP")
  195.     msg.Text:SetShadowColor(0,0,0)
  196.     msg.Text:SetShadowOffset(3,-3)
  197.  
  198.     msg.Text:SetText("|c00ff4400Important note about the GetAll scan option:|r\n\nUtilizing this feature can result in a very fast scan once every 15 minutes, however it requires a fast computer, low latency/ping times to the server, and for the servers to be running in optimum conditions. If any one of these three things are lagging, you may be disconnected from the server during the scan process.\n\nIf you wish to continue click the button again.\n\n|c00444444If you wish, you can disable this warning message via the Scan Button configuration settings.|r")
  199.  
  200.     private.UpdateScanProgress()
  201. end
  202. local progressBarOptions = {barColor = {0,0.6,0}}
  203. function private.UpdateScanProgress(state, _, _, _, _, _, _, scansQueued)
  204.     local scanning, paused = false, false
  205.     if AucAdvanced and AucAdvanced.Scan then
  206.         scanning, paused = AucAdvanced.Scan.IsScanning(), AucAdvanced.Scan.IsPaused()
  207.     end
  208.  
  209.     private.ConfigChanged()
  210.  
  211.     if scanning or paused then
  212.         private.buttons.stop:Enable()
  213.         private.buttons.stop.tex:SetVertexColor(1.0, 0.9, 0.1)
  214.     else
  215.         private.buttons.stop:Disable()
  216.         private.buttons.stop.tex:SetVertexColor(0.3,0.3,0.3)
  217.     end
  218.     local pending = 0
  219.     if scansQueued then
  220.         pending = scansQueued
  221.         if scanning then
  222.             pending = pending + 1
  223.         end
  224.         if pending ~= private.lastpending then
  225.             private.lastpending = pending
  226.             private.buttons.stop.count:SetText(pending)
  227.             --store highest pending
  228.             if not progressBarOptions.pending or progressBarOptions.pending < pending then
  229.                 progressBarOptions.pending = pending or 0
  230.             end
  231.             local value = 0
  232.             if progressBarOptions.pending >= 1 then -- avoid Div0
  233.                 value = (100 - pending * 100 / progressBarOptions.pending)
  234.             end
  235.             AucAdvanced.API.ProgressBars("ScanButtonLuaStopCount", value, true, pending.." scans remaining", progressBarOptions)
  236.         end
  237.     end
  238.     --handle when we are on the last scan and no more queued when that scan completes set remaining to 0
  239.     if scansQueued == 0 and state == false then
  240.         private.buttons.stop.count:SetText(pending)
  241.         progressBarOptions.pending = 0
  242.         AucAdvanced.API.ProgressBars("ScanButtonLuaStopCount")--hide progress bar
  243.     end
  244.  
  245.     private.blink = nil
  246.     if scanning and not paused then
  247.         private.buttons.pause:Enable()
  248.         private.buttons.pause.tex:SetVertexColor(1.0, 0.9, 0.1)
  249.         private.buttons.play:Disable()
  250.         private.buttons.play.tex:SetVertexColor(0.3,0.3,0.3)
  251.     else
  252.         private.buttons.play:Enable()
  253.         private.buttons.play.tex:SetVertexColor(1.0, 0.9, 0.1)
  254.         private.buttons.pause:Disable()
  255.         private.buttons.pause.tex:SetVertexColor(0.3,0.3,0.3)
  256.         if paused then
  257.             private.blink = 1
  258.         end
  259.     end
  260. end
  261.  
  262. local queue, queueFinished = {}, false
  263. function private:OnUpdate(delay)
  264.     if private.blink then
  265.         private.timer = (private.timer or 0) - delay
  266.         if private.timer < 0 then
  267.             if not AucAdvanced.Scan.IsPaused() then
  268.                 private.UpdateScanProgress()
  269.                 return
  270.             end
  271.             if private.blink == 1 then
  272.                 private.buttons.pause.tex:SetVertexColor(0.1, 0.3, 1.0)
  273.                 private.blink = 2
  274.             else
  275.                 private.buttons.pause.tex:SetVertexColor(0.3, 0.3, 0.3)
  276.                 private.blink = 1
  277.             end
  278.             private.timer = 0.75
  279.         end
  280.     end
  281.     --Create the overlay filter buttons the (callbackType == "auctionui") is too early.
  282.     if not AuctioneerFilterButton1 and AuctionFilterButton1 then
  283.         private.CreateSecondaryFilterButtons()
  284.         hooksecurefunc("AuctionFrameFilters_Update", private.AuctionFrameFilters_UpdateClasses)--used to respond to scrollframe
  285.     end
  286.     --if we still have filters pending process it, unless a scan is in progress or paused
  287.     if #queue > 0 and not AucAdvanced.Scan.IsScanning() and not AucAdvanced.Scan.IsPaused() then
  288.         private.play()
  289.     end
  290.     --Used to clear the selected filters/highlights AFTER the last queued scan has completed
  291.     if queueFinished and not AucAdvanced.Scan.IsScanning() and not AucAdvanced.Scan.IsPaused() then
  292.         queueFinished = false
  293.         if AucAdvanced.Settings.GetSetting("util.scanbutton.message") then print("|CFFFFFF00 Last queued Auction Filter completed") end
  294.         private.AuctionFrameFilters_ClearSelection()
  295.         private.AuctionFrameFilters_ClearHighlight()
  296.     end
  297.  
  298.     local canSend, canSendAll = CanSendAuctionQuery()
  299.     if canSendAll and not AucAdvanced.Scan.IsScanning() and private.buttons.play:IsEnabled() then
  300.         private.buttons.getall:Enable()
  301.         if AucAdvanced.Settings.GetSetting("util.scanbutton.getall") or private.warned then
  302.             private.buttons.getall.tex:SetVertexColor(1.0, 0.9, 0.1)
  303.             private.buttons.getall.warn = nil
  304.         else
  305.             private.buttons.getall.tex:SetVertexColor(0.3, 0.7, 1.0)
  306.             private.buttons.getall.warn = not private.warned
  307.         end
  308.     else
  309.         private.buttons.getall:Disable()
  310.         private.buttons.getall.tex:SetVertexColor(0.3,0.3,0.3)
  311.     end
  312. end
  313.  
  314. function private.SetupConfigGui(gui)
  315.     -- The defaults for the following settings are set in the lib.OnLoad function
  316.     local id = gui:AddTab(libName, libType.." Modules")
  317.     gui:AddControl(id, "Header",     0,    libName.._TRANS('SBTN_Interface_Options')) --" Options"
  318.  
  319.     gui:AddHelp(id, "what scanbutton",
  320.         _TRANS('SBTN_Help_WhatScanButton'), --"What are the scan buttons?
  321.         _TRANS('SBTN_Help_WhatScanButtonAnswer')) --"The scan buttons are the Stop/Play/Pause buttons in the titlebar of the Auction House frame."
  322.  
  323.     gui:AddControl(id, "Checkbox",   0, 1, "util.scanbutton.enabled", _TRANS('SBTN_Interface_Enabled')) --"Show scan buttons in the Auction House"
  324.     gui:AddTip(id, _TRANS('SBTN_HelpTooltip_Enabled')) --"Toggles the display of the Stop/Play/Pause/Fast Forward scan buttons in the title bar of the Auction House."
  325.  
  326.     gui:AddControl(id, "Checkbox",   0, 1, "util.scanbutton.message", _TRANS('SBTN_Interface_Message')) --"Show messages about which category selections have been queued"
  327.     gui:AddTip(id, _TRANS('SBTN_HelpTooltip_Message')) --"Toggles the display of the starting search of filtered messages when using the ctr+click to select specific categories of the AH to scan."
  328.  
  329.     gui:AddControl(id, "Checkbox",   0, 1, "util.scanbutton.getall", _TRANS('SBTN_Interface_Getall')) --"Don't warn about GetAll scanning"
  330.     gui:AddTip(id, _TRANS('SBTN_HelpTooltip_Getall')) --"Disable the warning that you get when you click the GetAll button."
  331. end
  332.  
  333. function private.ConfigChanged()
  334.     if not private.buttons then return end
  335.     if AucAdvanced.Settings.GetSetting("util.scanbutton.enabled") then
  336.         private.buttons:Show()
  337.     else
  338.         private.buttons:Hide()
  339.     end
  340. end
  341.  
  342. function private.stop()
  343.     --this just makes the scan queue count decrease by 1 until the next processor event  sets it to a proper # helpfull if user is spamming stop button
  344.     local count = tonumber(private.buttons.stop.count:GetText() )
  345.     if count > 0 then
  346.         count = count -1
  347.         AucAdvanced.API.ProgressBars("ScanButtonLuaStopCount", 100, true, count.." scans remaining", progressBarOptions)
  348.     else
  349.         AucAdvanced.API.ProgressBars("ScanButtonLuaStopCount")
  350.     end
  351.     private.buttons.stop.count:SetText(count)
  352.  
  353.  
  354.     AucAdvanced.Scan.SetPaused(false)
  355.     AucAdvanced.Scan.Cancel()
  356.     private.UpdateScanProgress()
  357.     queue = {}
  358.     queueFinished = true --Will clear currently selected scan filters with the Next Onupdate event.
  359. end
  360.  
  361. function private.play()
  362.     if AucAdvanced.Scan.IsPaused() then
  363.         AucAdvanced.Scan.SetPaused(false)
  364.     elseif not AucAdvanced.Scan.IsScanning() then
  365.         if #queue == 0 then queue = private.checkedFrames() end --check for user selected frames
  366.         --debugPrint(("play: queue count=%i"):format(#queue), "ScanButton", "play", 0, "Debug")
  367.         if #queue > 0  then
  368.             if AucAdvanced.Settings.GetSetting("util.scanbutton.message") then print("Starting search on filter: |CFFFFFF00", CLASS_FILTERS[queue[1]]) end
  369.             AucAdvanced.Scan.StartScan("", "", "", nil, queue[1], nil, nil, nil)
  370.             table.remove(queue, 1)
  371.             if #queue == 0 then
  372.                 queueFinished = true --Used to clear the selected filters/highlights AFTER the last queued scan has completed
  373.             end
  374.         else
  375.             AucAdvanced.Scan.StartScan("", "", "", AuctionFrameBrowse.selectedInvtypeIndex, AuctionFrameBrowse.selectedClassIndex, AuctionFrameBrowse.selectedSubclassIndex,  nil, nil)
  376.         end
  377.     end
  378.     private.UpdateScanProgress()
  379. end
  380.  
  381. function private.getall()
  382.     if not AucAdvanced.Scan.IsScanning() then
  383.         if (private.buttons.getall.warn) then
  384.             private.message:Show()
  385.             private.warned = true
  386.             return
  387.         end
  388.  
  389.         AucAdvanced.Scan.StartScan(nil, nil, nil, nil, nil, nil, nil, nil, true)
  390.     end
  391.     private.UpdateScanProgress()
  392. end
  393.  
  394. function private.pause()
  395.     if not AucAdvanced.Scan.IsPaused() then
  396.         AucAdvanced.Scan.SetPaused(true)
  397.     end
  398.     private.UpdateScanProgress()
  399. end
  400.  
  401. --[[
  402. This adds a transparent replica of the AH filters on the browse frame, we have scripts on this frame to select catagories a user chooses to scan
  403. This means we do not have to directly modify blizzards filter frame
  404. ]]
  405. --store the primary AH filter categories, this is a copy of the global table the AH uses CLASS_FILTERS generated via GetAuctionItemClasses()
  406. --Resets the selections table to 0 if an alt click is not used, or after a scan has been implemented
  407. private.Filters = {}
  408. function private.AuctionFrameFilters_ClearSelection()
  409.     for i,v in pairs(CLASS_FILTERS) do
  410.         private.Filters[v] = {0,i} --store cleared table of selections
  411.     end
  412. end
  413. --clear any current highlighting from a prev search
  414. function private.AuctionFrameFilters_ClearHighlight()
  415.     for i in pairs(CLASS_FILTERS) do
  416.         _G["AuctionFilterButton"..i]:UnlockHighlight()
  417.     end
  418. end
  419.  
  420. function private.checkedFrames()
  421.     queue = {}
  422.     for i,v in pairs(private.Filters) do
  423.         if v[1] == 1 then
  424.             table.insert(queue, v[2])
  425.         end
  426.     end
  427.  
  428.     return queue
  429. end
  430.  
  431. function private.CreateSecondaryFilterButtons()
  432. local base, frame, prev = AuctionFrameBrowse, nil, nil
  433.     private.AuctionFrameFilters_ClearSelection() --create the filter selection table
  434.     for i = 1,15 do
  435.         frame = "AuctioneerFilterButton"..i
  436.         prev = "AuctioneerFilterButton"..(i - 1)
  437.         if i == 1 then
  438.             base[frame] = CreateFrame("Button", frame, AuctionFilterButton1, "AuctionClassButtonTemplate")
  439.             base[frame]:SetText("TICK-"..i)
  440.             base[frame]:SetPoint("LEFT",0,0)
  441.             base[frame]:SetWidth(156)
  442.             base[frame]:SetAlpha(0)
  443.             base[frame]:SetScript("OnClick", function()
  444.                                     if IsControlKeyDown() then
  445. -- Test patch to clear AH settings when CTRL click is used just like we clear ours when non-ctrl is used
  446. if (AuctionFrameBrowse.selectedClassIndex) then
  447.     AuctionFrameBrowse.selectedClass = nil
  448.     AuctionFrameBrowse.selectedClassIndex = nil
  449.     AuctionFrameBrowse.selectedSubclass = nil
  450.     AuctionFrameBrowse.selectedSubclassIndex = nil
  451.     AuctionFrameBrowse.selectedInvtype = nil
  452.     AuctionFrameBrowse.selectedInvtypeIndex = nil
  453.     AuctionFrameFilters_Update()
  454. end
  455.                                         if private.Filters[ _G["AuctionFilterButton"..i]:GetText()][1] then
  456.                                             if  private.Filters[ _G["AuctionFilterButton"..i]:GetText()][1] == 1 then
  457.                                                 private.Filters[ _G["AuctionFilterButton"..i]:GetText()][1] = 0
  458.                                                  _G["AuctionFilterButton"..i]:UnlockHighlight()
  459.                                             else
  460.                                                 private.Filters[ _G["AuctionFilterButton"..i]:GetText()][1] = 1
  461.                                                  _G["AuctionFilterButton"..i]:LockHighlight()
  462.                                             end
  463.                                         end
  464.                                     else
  465.                                         private.AuctionFrameFilters_ClearSelection()
  466.                                         AuctionFrameFilter_OnClick(_G["AuctionFilterButton"..i])
  467.                                     end
  468.                                 end)
  469.         else
  470.             base[frame] = CreateFrame("Button", frame, AuctionFilterButton1, "AuctionClassButtonTemplate")
  471.             base[frame]:SetText("TICK-"..i)
  472.             base[frame]:ClearAllPoints()
  473.             base[frame]:SetPoint("TOPLEFT", base[prev],"BOTTOMLEFT",0,0)
  474.             base[frame]:SetWidth(156)
  475.             base[frame]:SetAlpha(0)
  476.             base[frame]:SetScript("OnClick", function()
  477.                                     if IsControlKeyDown() then
  478. -- Test patch to clear AH settings when CTRL click is used just like we clear ours when non-ctrl is used
  479. if (AuctionFrameBrowse.selectedClassIndex) then
  480.     AuctionFrameBrowse.selectedClass = nil
  481.     AuctionFrameBrowse.selectedClassIndex = nil
  482.     AuctionFrameBrowse.selectedSubclass = nil
  483.     AuctionFrameBrowse.selectedSubclassIndex = nil
  484.     AuctionFrameFilters_Update()
  485. end
  486.                                         if private.Filters[ _G["AuctionFilterButton"..i]:GetText()] then
  487.                                             if  private.Filters[ _G["AuctionFilterButton"..i]:GetText()][1] == 1 then
  488.                                                 private.Filters[ _G["AuctionFilterButton"..i]:GetText()][1] = 0
  489.                                                  _G["AuctionFilterButton"..i]:UnlockHighlight()
  490.                                             else
  491.                                                 private.Filters[ _G["AuctionFilterButton"..i]:GetText()][1] = 1
  492.                                                  _G["AuctionFilterButton"..i]:LockHighlight()
  493.                                             end
  494.                                         end
  495.                                     else
  496.                                         private.AuctionFrameFilters_ClearSelection()
  497.                                         AuctionFrameFilter_OnClick(_G["AuctionFilterButton"..i])
  498.                                     end
  499.                                 end)
  500.         end
  501.     end
  502.     private.AuctionFrameFilters_UpdateClasses() --Changes the frame to match current filter frame, needed for 1 refresh after frame creation.
  503. end
  504.  
  505. --Blizzard code base, used to generate a replica of the default filter frame
  506. function private.AuctionFrameFilters_UpdateClasses()
  507.     -- Display the list of open filters
  508.     local button, index, info, isLast
  509.     local offset = FauxScrollFrame_GetOffset(BrowseFilterScrollFrame)
  510.     index = offset
  511.     for i=1, NUM_FILTERS_TO_DISPLAY do
  512.         button = _G["AuctioneerFilterButton"..i]
  513.  
  514.         if ( getn(OPEN_FILTER_LIST) > NUM_FILTERS_TO_DISPLAY ) then
  515.             button:SetWidth(126)
  516.         else
  517.             button:SetWidth(126)
  518.         end
  519.         index = index + 1
  520.         if ( index <= getn(OPEN_FILTER_LIST) ) then
  521.             info = OPEN_FILTER_LIST[index]
  522.             while ((info[2] == "invtype") and (not info[6])) do
  523.                 index = index + 1
  524.                 if ( index <= getn(OPEN_FILTER_LIST) ) then
  525.                     info = OPEN_FILTER_LIST[index]
  526.                 else
  527.                     info = nil
  528.                     button:Hide()
  529.                     break
  530.                 end
  531.             end
  532.             if ( info ) then
  533.             -- Taken from Blizzard_AuctionUI 6.2.4
  534.             -- function FilterButton_SetType(button, type, text, isLast)
  535.                 local type = info[2]
  536.                 local text = info[1]
  537.                 local isLast = info[5]
  538.                 local normalText = _G[button:GetName().."NormalText"];
  539.                 local normalTexture = _G[button:GetName().."NormalTexture"];
  540.                 local line = _G[button:GetName().."Lines"];
  541.                 local tex = button:GetNormalTexture();
  542.                 if (text == TOKEN_FILTER_LABEL) then
  543.                     tex:SetTexCoord(0, 1, 0, 1);
  544.                     tex:SetAtlas("token-button-category");
  545.                 else
  546.                     tex:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-FilterBg");
  547.                     tex:SetTexCoord(0, 0.53125, 0, 0.625);
  548.                 end
  549.                 if ( type == "class" ) then
  550.                     button:SetText(text);
  551.                     normalText:SetPoint("LEFT", button, "LEFT", 4, 0);
  552.                     normalTexture:SetAlpha(1.0);   
  553.                     line:Hide();
  554.                 elseif ( type == "subclass" ) then
  555.                     button:SetText(HIGHLIGHT_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE);
  556.                     normalText:SetPoint("LEFT", button, "LEFT", 12, 0);
  557.                     normalTexture:SetAlpha(0.4);
  558.                     line:Hide();
  559.                 elseif ( type == "invtype" ) then
  560.                     button:SetText(HIGHLIGHT_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE);
  561.                     normalText:SetPoint("LEFT", button, "LEFT", 20, 0);
  562.                     normalTexture:SetAlpha(0.0);   
  563.                     if ( isLast ) then
  564.                         line:SetTexCoord(0.4375, 0.875, 0, 0.625);
  565.                     else
  566.                         line:SetTexCoord(0, 0.4375, 0, 0.625);
  567.                     end
  568.                     line:Show();
  569.                 end
  570.                 button.type = type;
  571.                 -- FilterButton_SetType(button, info[2], info[1], info[5])
  572.                 button.index = info[3]
  573.                 if ( info[4] ) then
  574.                     button:LockHighlight()
  575.                 else
  576.                     button:UnlockHighlight()
  577.                 end
  578.                 button:Show()
  579.             end
  580.         else
  581.             button:Hide()
  582.         end
  583.  
  584.     end
  585. end
  586.  
  587. AucAdvanced.RegisterRevision("$URL: http://svn.norganna.org/auctioneer/branches/5.21f/Auc-Util-ScanButton/ScanButton.lua $", "$Rev: 5403 $")
Add Comment
Please, Sign In to add comment