Advertisement
j311yf1sh

Auctionator.lua

Mar 27th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 127.69 KB | None | 0 0
  1.  
  2. AuctionatorVersion = "???";     -- set from toc upon loading
  3. AuctionatorAuthor  = "Zirco";
  4.  
  5. AuctionatorLoaded = false;
  6. AuctionatorInited = false;
  7.  
  8. local addonName, addonTable = ...;
  9. local zc = addonTable.zc;
  10. local zz = zc.md;
  11. local _
  12.  
  13. gAtrZC = addonTable.zc;     -- share with AuctionatorDev
  14.  
  15.  
  16. -----------------------------------------
  17.  
  18. local WEAPON = 1;
  19. local ARMOR  = 2;
  20.  
  21. local recommendElements         = {};
  22.  
  23. AUCTIONATOR_ENABLE_ALT      = 1;
  24. AUCTIONATOR_OPEN_ALL_BAGS   = 1;
  25. AUCTIONATOR_SHOW_ST_PRICE   = 0;
  26. AUCTIONATOR_SHOW_TIPS       = 1;
  27. AUCTIONATOR_DEF_DURATION    = "N";      -- none
  28. AUCTIONATOR_V_TIPS          = 1;
  29. AUCTIONATOR_A_TIPS          = 1;
  30. AUCTIONATOR_D_TIPS          = 1;
  31. AUCTIONATOR_SHIFT_TIPS      = 1;
  32. AUCTIONATOR_DE_DETAILS_TIPS = 4;        -- off by default
  33. AUCTIONATOR_DEFTAB          = 1;
  34.  
  35. AUCTIONATOR_DB_MAXITEM_AGE  = 180;
  36. AUCTIONATOR_DB_MAXHIST_AGE  = 21;       -- obsolete - just needed for migration
  37. AUCTIONATOR_DB_MAXHIST_DAYS = 5;
  38.  
  39. AUCTIONATOR_OPEN_FIRST      = 0;    -- obsolete - just needed for migration
  40. AUCTIONATOR_OPEN_BUY        = 0;    -- obsolete - just needed for migration
  41.  
  42. local SELL_TAB      = 1;
  43. local MORE_TAB      = 2;
  44. local BUY_TAB       = 3;
  45.  
  46.  
  47. -- saved variables - amounts to undercut
  48.  
  49. local auctionator_savedvars_defaults =
  50.     {
  51.     ["_5000000"]            = 10000;    -- amount to undercut buyouts over 500 gold
  52.     ["_1000000"]            = 2500;
  53.     ["_200000"]             = 1000;
  54.     ["_50000"]              = 500;
  55.     ["_10000"]              = 200;
  56.     ["_2000"]               = 100;
  57.     ["_500"]                = 5;
  58.     ["STARTING_DISCOUNT"]   = 5;    -- PERCENT
  59.     ["LOG_DE_DATA"]         = nil;  -- obsolete
  60.     ["LOG_DE_DATA_X"]       = true;
  61.     };
  62.  
  63.  
  64. -----------------------------------------
  65.  
  66. local auctionator_orig_AuctionFrameTab_OnClick;
  67. local auctionator_orig_ContainerFrameItemButton_OnModifiedClick;
  68. local auctionator_orig_AuctionFrameAuctions_Update;
  69. local auctionator_orig_CanShowRightUIPanel;
  70. local auctionator_orig_ChatEdit_InsertLink;
  71. local auctionator_orig_ChatFrame_OnEvent;
  72.  
  73. local gForceMsgAreaUpdate = true;
  74. local gAtr_ClickAuctionSell = false;
  75. local gAtr_echoAddonChat = false
  76.  
  77. local gOpenAllBags      = AUCTIONATOR_OPEN_ALL_BAGS;
  78. local gTimeZero;
  79. local gTimeTightZero;
  80.  
  81. local cslots = {};
  82. local gEmptyBScached = nil;
  83.  
  84. local gAutoSingleton = 0;
  85. local gTradeSkillFrameModded = false
  86.  
  87. -- set to the last item posted, even after the posting so that message and icon can be displayed
  88. local gJustPosted = { ItemName=nil, ItemLink=nil, BuyoutPrice=0, StackSize=0, NumStacks=0 }
  89.  
  90. local auctionator_pending_message = nil;
  91.  
  92. local kBagIDs = {};
  93.  
  94. local Atr_Confirm_Proc_Yes = nil;
  95.  
  96. local gStartingTime         = time();
  97. local gHentryTryAgain       = nil;
  98. local gCondensedThisSession = {};
  99.  
  100. local gAtr_Owner_Item_Indices = {};
  101.  
  102. local ITEM_HIST_NUM_LINES = 20;
  103.  
  104. local gActiveAuctions = {};
  105.  
  106. local gHlistNeedsUpdate = false;
  107. local gAtr_SellTriggeredByAuctionator = false;
  108.  
  109. local gSellPane;
  110. local gMorePane;
  111. local gActivePane;
  112. local gShopPane;
  113.  
  114. local gCurrentPane;
  115.  
  116. local gHistoryItemList = {};
  117.  
  118. local ATR_CACT_NULL                         = 0;
  119. local ATR_CACT_READY                        = 1;
  120. local ATR_CACT_PROCESSING                   = 2;
  121. local ATR_CACT_WAITING_ON_CANCEL_CONFIRM    = 3;
  122.  
  123. local gBattlePetIconCache = {};
  124.  
  125. local gItemPostingInProgress = false;
  126.  
  127. gAtr_ptime = nil;       -- a more precise timer but may not be updated very frequently
  128.  
  129. gAtr_ScanDB         = nil;
  130. gAtr_PriceHistDB    = nil;
  131.  
  132. -----------------------------------------
  133.  
  134. ATR_SK_GLYPHS       = "*_glyphs";
  135. ATR_SK_GEMS_CUT     = "*_gemscut";
  136. ATR_SK_GEMS_UNCUT   = "*_gemsuncut";
  137. ATR_SK_ITEM_ENH     = "*_itemenh";
  138. ATR_SK_POT_ELIX     = "*_potelix";
  139. ATR_SK_FLASKS       = "*_flasks";
  140. ATR_SK_HERBS        = "*_herbs";
  141.  
  142. -----------------------------------------
  143.  
  144. local roundPriceDown, ToTightTime, FromTightTime, monthDay;
  145.  
  146. -----------------------------------------
  147.  
  148. function Atr_RegisterEvents(self)
  149.  
  150.     self:RegisterEvent("VARIABLES_LOADED");
  151.     self:RegisterEvent("ADDON_LOADED");
  152.  
  153.     self:RegisterEvent("AUCTION_ITEM_LIST_UPDATE");
  154.     self:RegisterEvent("AUCTION_OWNED_LIST_UPDATE");
  155.  
  156.     self:RegisterEvent("AUCTION_MULTISELL_START");
  157.     self:RegisterEvent("AUCTION_MULTISELL_UPDATE");
  158.     self:RegisterEvent("AUCTION_MULTISELL_FAILURE");
  159.  
  160.     self:RegisterEvent("AUCTION_HOUSE_SHOW");
  161.     self:RegisterEvent("AUCTION_HOUSE_CLOSED");
  162.  
  163.     self:RegisterEvent("NEW_AUCTION_UPDATE");
  164.     self:RegisterEvent("CHAT_MSG_ADDON");
  165.     self:RegisterEvent("PLAYER_ENTERING_WORLD");
  166.  
  167. end
  168.  
  169. -----------------------------------------
  170.  
  171. function Atr_EventHandler(self, event, ...)
  172.  
  173.     --if (zc.StringStartsWith (event, "UNIT", "BAG")) then
  174.     --if (true) then
  175.     --  zz (event, ...);
  176.     --end
  177.  
  178.     if (event == "VARIABLES_LOADED")            then    Atr_OnLoad();                       end;
  179.     if (event == "ADDON_LOADED")                then    Atr_OnAddonLoaded(...);             end;
  180.     if (event == "AUCTION_ITEM_LIST_UPDATE")    then    Atr_OnAuctionUpdate(...);           end;
  181.     if (event == "AUCTION_OWNED_LIST_UPDATE")   then    Atr_OnAuctionOwnedUpdate();         end;
  182.  
  183.     if (event == "AUCTION_MULTISELL_START")     then    Atr_OnAuctionMultiSellStart();      end;
  184.     if (event == "AUCTION_MULTISELL_UPDATE")    then    Atr_OnAuctionMultiSellUpdate(...); end;
  185.     if (event == "AUCTION_MULTISELL_FAILURE")   then    Atr_OnAuctionMultiSellFailure();     end;
  186.  
  187.     if (event == "AUCTION_HOUSE_SHOW")          then    Atr_OnAuctionHouseShow();           end;
  188.     if (event == "AUCTION_HOUSE_CLOSED")        then    Atr_OnAuctionHouseClosed();         end;
  189.     if (event == "NEW_AUCTION_UPDATE")          then    Atr_OnNewAuctionUpdate();           end;
  190.     if (event == "CHAT_MSG_ADDON")              then    Atr_OnChatMsgAddon(...);            end;
  191.     if (event == "PLAYER_ENTERING_WORLD")       then    Atr_OnPlayerEnteringWorld();        end;
  192.  
  193.     if (event == "UNIT_SPELLCAST_SENT")         then    Atr_OnSpellCastSent(...);       end;
  194.     if (event == "UNIT_SPELLCAST_SUCCEEDED")    then    Atr_OnSpellCastSucess(...);         end;
  195.     if (event == "BAG_UPDATE")                  then    Atr_OnBagUpdate(...);       end;
  196.  
  197. end
  198.  
  199.  
  200. -----------------------------------------
  201.  
  202. function Atr_SetupHookFunctionsEarly ()
  203.  
  204.     if (Atr_Dev_SetupEarlyHooks) then
  205.         Atr_Dev_SetupEarlyHooks();
  206.     end
  207.  
  208.     Atr_Hook_OnTooltipAddMoney ();
  209.  
  210. end
  211.  
  212.  
  213. -----------------------------------------
  214.  
  215. local auctionator_orig_GetAuctionItemInfo;
  216.  
  217. function Atr_SetupHookFunctions ()
  218.  
  219.     auctionator_orig_AuctionFrameTab_OnClick = AuctionFrameTab_OnClick;
  220.     AuctionFrameTab_OnClick = Atr_AuctionFrameTab_OnClick;
  221.  
  222.     auctionator_orig_ContainerFrameItemButton_OnModifiedClick = ContainerFrameItemButton_OnModifiedClick;
  223.     ContainerFrameItemButton_OnModifiedClick = Atr_ContainerFrameItemButton_OnModifiedClick;
  224.  
  225.     auctionator_orig_AuctionFrameAuctions_Update = AuctionFrameAuctions_Update;
  226.     AuctionFrameAuctions_Update = Atr_AuctionFrameAuctions_Update;
  227.  
  228.     auctionator_orig_CanShowRightUIPanel = CanShowRightUIPanel;
  229.     CanShowRightUIPanel = auctionator_CanShowRightUIPanel;
  230.  
  231.     auctionator_orig_ChatEdit_InsertLink = ChatEdit_InsertLink;
  232.     ChatEdit_InsertLink = auctionator_ChatEdit_InsertLink;
  233.  
  234.     auctionator_orig_ChatFrame_OnEvent = ChatFrame_OnEvent;
  235.     ChatFrame_OnEvent = auctionator_ChatFrame_OnEvent;
  236.  
  237. end
  238.  
  239. -----------------------------------------
  240.  
  241. function GetRealmFacInfoString()
  242.  
  243.     local   realm_fac, data
  244.     local   rf_string = ""
  245.     if (AUCTIONATOR_PRICE_DATABASE) then
  246.         for realm_fac, data in pairs (AUCTIONATOR_PRICE_DATABASE) do
  247.             if (realm_fac and not zc.StringStartsWith (realm_fac, "__")) then
  248.                 rf_string = rf_string..", "..realm_fac
  249.                 local c = 0;
  250.                 if (data) then
  251.                     for n, v in pairs (data) do
  252.                         c = c + 1;
  253.                     end
  254.                 end
  255.                 rf_string = rf_string.." ("..c..")"
  256.             end
  257.         end
  258.     end
  259.  
  260.     return rf_string
  261. end
  262.  
  263. -----------------------------------------
  264.  
  265. local function IsCataEnchanting (prof)
  266.  
  267.     if (prof) then
  268.         local profname, _, skillLevel = GetProfessionInfo (prof)
  269.  
  270.         if (zc.StringSame ("enchanting", profname) and skillLevel >= 450) then
  271.             return true
  272.         end
  273.     end
  274.  
  275.     return false
  276.  
  277. end
  278.  
  279. -----------------------------------------
  280.  
  281. local function IsCataEnchanter()
  282.  
  283.     local prof1, prof2 = GetProfessions()
  284.  
  285.     if (IsCataEnchanting (prof1) or IsCataEnchanting (prof2)) then
  286.         return true
  287.     end
  288.  
  289.     return false
  290. end
  291.  
  292.  
  293. -----------------------------------------
  294.  
  295. local checkVerString        = nil;
  296. local versionReminderCalled = false;    -- make sure we don't bug user more than once
  297.  
  298. -----------------------------------------
  299.  
  300. local function CheckVersion (verString)
  301.  
  302.     if (checkVerString == nil) then
  303.         checkVerString = AuctionatorVersion;
  304.     end
  305.  
  306.     local a,b,c = strsplit (".", verString);
  307.  
  308.     if (tonumber(a) == nil or tonumber(b) == nil or tonumber(c) == nil) then
  309.         return false;
  310.     end
  311.  
  312.     if (verString > checkVerString) then
  313.         checkVerString = verString;
  314.         return true;    -- out of date
  315.     end
  316.  
  317.     return false;
  318. end
  319.  
  320. -----------------------------------------
  321.  
  322. function Atr_VersionReminder ()
  323.     if (not versionReminderCalled) then
  324.         versionReminderCalled = true;
  325.  
  326.         zc.msg_anm (ZT("There is a more recent version of Auctionator: VERSION").." "..checkVerString);
  327.     end
  328. end
  329.  
  330.  
  331.  
  332. -----------------------------------------
  333.  
  334. local VREQ_sent = 0;
  335.  
  336. -----------------------------------------
  337.  
  338. function Atr_SendAddon_VREQ (type, target)
  339.  
  340.     VREQ_sent = time();
  341.  
  342.     if (not zc.StringSame (type, "WHISPER")) then
  343.         zz ("sending vreq to", type)
  344.     end
  345.  
  346.     SendAddonMessage ("ATR", "VREQ_"..AuctionatorVersion, type, target);
  347.  
  348. end
  349.  
  350. -----------------------------------------
  351.  
  352. function Atr_OnChatMsgAddon (...)
  353.  
  354.     local   prefix, msg, distribution, sender = ...;
  355.  
  356.  
  357.     if (prefix == "ATR") then
  358.  
  359.         local s = string.format ("%s %s |cff88ffff %s |cffffffaa %s|r", prefix, distribution, sender, msg);
  360.  
  361.         if (gAtr_echoAddonChat) then
  362.             zz (s);
  363.         end
  364.  
  365.         if (zc.StringStartsWith (msg, "VREQ_")) then
  366.             SendAddonMessage ("ATR", "V_"..AuctionatorVersion, "WHISPER", sender);
  367.         end
  368.  
  369.         if (zc.StringStartsWith (msg, "IREQ_")) then
  370.             collectgarbage  ("collect");
  371.             UpdateAddOnMemoryUsage();
  372.             local mem  = math.floor(GetAddOnMemoryUsage("Auctionator"));
  373.             SendAddonMessage ("ATR", "I_"..Atr_GetDBsize().."_"..mem.."_"..#AUCTIONATOR_SHOPPING_LISTS.."_"..GetRealmFacInfoString(), "WHISPER", sender)
  374.         end
  375.  
  376.         if (zc.StringStartsWith (msg, "V_") and time() - VREQ_sent < 5) then
  377.  
  378.             local herVerString = string.sub (msg, 3);
  379.         --  zc.md ("version found:", herVerString, "   ", sender, "     response time:", time() - VREQ_sent);
  380.             local outOfDate = CheckVersion (herVerString);
  381.             if (outOfDate) then
  382.                 zc.AddDeferredCall (3, "Atr_VersionReminder", nil, nil, "VR");
  383.             end
  384.         end
  385.     end
  386.  
  387.     Atr_OnChatMsgAddon_ShoppingListCmds (prefix, msg, distribution, sender)
  388.  
  389.     if (Atr_OnChatMsgAddon_Dev) then
  390.         Atr_OnChatMsgAddon_Dev (prefix, msg, distribution, sender);
  391.     end
  392.  
  393. end
  394.  
  395.  
  396. -----------------------------------------
  397.  
  398. function Atr_GetAuctionatorMemString(msg)
  399.  
  400.     collectgarbage  ("collect");
  401.  
  402.     UpdateAddOnMemoryUsage();
  403.  
  404.     local mem  = GetAddOnMemoryUsage("Auctionator");
  405.     return string.format ("%6i KB", math.floor(mem));
  406. end
  407.  
  408. -----------------------------------------
  409.  
  410. local function Atr_RestoreDElog()
  411.  
  412.     if (AUCTIONATOR_DE_DATA_BAK and #AUCTIONATOR_DE_DATA_BAK > 0) then
  413.  
  414.         AUCTIONATOR_DE_DATA = {}
  415.  
  416.         zc.CopyDeep (AUCTIONATOR_DE_DATA, AUCTIONATOR_DE_DATA_BAK)
  417.         zc.msg_anm ("Disenchant data restored.  Number of entries:", #AUCTIONATOR_DE_DATA_BAK);
  418.     else
  419.         zc.msg_anm ("No data available to be restored");
  420.     end
  421.  
  422. end
  423.  
  424. -----------------------------------------
  425.  
  426. local function Atr_DumpDElog()
  427.  
  428.     if (AUCTIONATOR_DE_DATA == nil or #AUCTIONATOR_DE_DATA == 0) then
  429.         zc.msg_anm ("no data has been collected");
  430.         return
  431.     end
  432.  
  433.     AUCTIONATOR_DE_DATA_BAK = {}
  434.  
  435.     zc.CopyDeep (AUCTIONATOR_DE_DATA_BAK, AUCTIONATOR_DE_DATA)
  436.  
  437.     AUCTIONATOR_DE_DATA = {}
  438.  
  439.     zc.msg_anm ("Disenchant data cleared.");
  440.  
  441.     Atr_LUA_explanation:SetText ("");
  442.  
  443.  
  444.     local n
  445.     local x = 0;
  446.     for n = 1,#AUCTIONATOR_DE_DATA_BAK do
  447.         local a, b = strsplit ("_", AUCTIONATOR_DE_DATA_BAK[n])
  448.         x = x + tonumber (a) + tonumber (b)
  449.     end
  450.  
  451.  
  452.     local msg = "DISENCHANT "..time().." "..x.." "..UnitName("player").."\n"
  453.  
  454.     for n = 1,#AUCTIONATOR_DE_DATA_BAK do
  455.         msg = msg..AUCTIONATOR_DE_DATA_BAK[n].."\n"
  456.     end
  457.  
  458.     Atr_LUA_ErrorMsg:SetText (msg)
  459.  
  460.     Atr_LUA_Error:Show()
  461.  
  462. end
  463.  
  464. -----------------------------------------
  465.  
  466. function Atr_ClearItemStackingPrefs ()
  467.  
  468.     local text, spinfo;
  469.  
  470.     for text, spinfo in pairs (AUCTIONATOR_STACKING_PREFS) do
  471.         if (not zc.StringContains (text, "_")) then
  472.             AUCTIONATOR_STACKING_PREFS[text] = nil
  473.         end
  474.     end
  475.  
  476.  
  477. end
  478.  
  479. -----------------------------------------
  480.  
  481. local function Atr_ClearPostHistory ()
  482.  
  483.     AUCTIONATOR_PRICING_HISTORY = {};
  484.     zc.msg_anm (ZT("posting history cleared"));
  485. end
  486.  
  487. -----------------------------------------
  488.  
  489. local function Atr_ClearFullScanDB ()
  490.  
  491.     gAtr_ScanDB = nil;
  492.     AUCTIONATOR_PRICE_DATABASE = nil;
  493.     Atr_InitScanDB();
  494.     zc.msg_anm (ZT("full scan database cleared"));
  495. end
  496.  
  497. -----------------------------------------
  498.  
  499. local function Atr_SlashCmdFunction(msg)
  500.  
  501.     local cmd, param1u, param2u, param3u = zc.words (msg);
  502.  
  503.     if (cmd == nil or type (cmd) ~= "string") then
  504.         return;
  505.     end
  506.  
  507.           cmd    = cmd     and cmd:lower()    or nil;
  508.     local param1 = param1u and param1u:lower() or nil;
  509.     local param2 = param2u and param2u:lower() or nil;
  510.     local param3 = param3u and param3u:lower() or nil;
  511.  
  512.     if (cmd == "mem") then
  513.  
  514.         UpdateAddOnMemoryUsage();
  515.  
  516.         for i = 1, GetNumAddOns() do
  517.             local mem  = GetAddOnMemoryUsage(i);
  518.             local name = GetAddOnInfo(i);
  519.             if (mem > 0) then
  520.                 local s = string.format ("%6i KB   %s", math.floor(mem), name);
  521.                 zc.msg_yellow (s);
  522.             end
  523.         end
  524.  
  525.     elseif (cmd == "share" and param1 == "lists") then
  526.         Atr_Send_ShareShoppingListRequest(param2)
  527.  
  528.     elseif (cmd == "locale") then
  529.         Atr_PickLocalizationTable (param1u);
  530.  
  531.     elseif (cmd == "dcp") then
  532.  
  533.         if (param1) then
  534.             AUCTIONATOR_DC_PAUSE = tonumber(param1);
  535.         end
  536.  
  537.         zc.msg_anm ("dcp set to: ", AUCTIONATOR_DC_PAUSE);
  538.  
  539.     elseif (cmd == "generr") then
  540.  
  541.         local y = 5 + nil;
  542.  
  543.     elseif (cmd == "vsl") then
  544.  
  545.         Atr_ShpList_Validate()
  546.  
  547.     elseif (cmd == "eac") then
  548.         gAtr_echoAddonChat = not gAtr_echoAddonChat
  549.         zz ("gAtr_echoAddonChat is now", gAtr_echoAddonChat)
  550.  
  551.     elseif (cmd == "showdi") then
  552.  
  553.         Atr_Error_Handler ("xxx");
  554.  
  555.     elseif (cmd == "delog") then
  556.  
  557.         AUCTIONATOR_SAVEDVARS.LOG_DE_DATA_X = zc.Negate (AUCTIONATOR_SAVEDVARS.LOG_DE_DATA_X)
  558.  
  559.         EnableDisableDElogging ()
  560.  
  561.     elseif (cmd == "dedump") then
  562.  
  563.         Atr_DumpDElog()
  564.  
  565.     elseif (cmd == "derestore") then
  566.  
  567.         Atr_RestoreDElog()
  568.  
  569.         elseif (cmd == "declear") then
  570.  
  571.         AUCTIONATOR_DE_DATA     = nil
  572.         AUCTIONATOR_DE_DATA_BAK = nil
  573.  
  574.         zc.msg_anm ("Disenchant data cleared");
  575.  
  576.     elseif (cmd == "clear") then
  577.  
  578.         zc.msg_anm ("memory usage: "..Atr_GetAuctionatorMemString());
  579.  
  580.         if      (param1 == "fullscandb") then       Atr_ClearFullScanDB()
  581.         elseif  (param1 == "posthistory") then      Atr_ClearPostHistory()
  582.         elseif  (param1 == "ssprefs") then
  583.             Atr_ClearItemStackingPrefs()
  584.             zc.msg_anm (ZT("selling preferences cleared"))
  585.         end
  586.  
  587.         collectgarbage  ("collect");
  588.  
  589.         zc.msg_anm ("memory usage: "..Atr_GetAuctionatorMemString());
  590.     elseif (Atr_HandleDevCommands and Atr_HandleDevCommands (cmd, param1, param2)) then
  591.         -- do nothing
  592.  
  593.     elseif (cmd == "switch") then
  594.         local NumOf = Atr_Batch_NumAuctions:GetNumber()
  595.         local StackSize = Atr_Batch_Stacksize:GetNumber()
  596.         Atr_Batch_NumAuctions:SetNumber(StackSize)
  597.         Atr_Batch_Stacksize:SetNumber(NumOf)
  598.  
  599.         --print(NumOf,StackSize) ----------------------------------------------------------------------------------------------
  600.     else
  601.         zc.msg_anm (ZT("unrecognized command"));
  602.     end
  603.  
  604. end
  605.  
  606.  
  607. -----------------------------------------
  608.  
  609. function EnableDisableDElogging ()
  610.  
  611.     if (not IsCataEnchanter()) then
  612.         return
  613.     end
  614.  
  615.     if (AUCTIONATOR_SAVEDVARS and (AUCTIONATOR_SAVEDVARS.LOG_DE_DATA_X or AUCTIONATOR_SAVEDVARS.LOG_DE_DATA_X == nil)) then
  616.  
  617.         Atr_core:RegisterEvent("UNIT_SPELLCAST_START");
  618.         Atr_core:RegisterEvent("UNIT_SPELLCAST_SENT");
  619.         Atr_core:RegisterEvent("UNIT_SPELLCAST_STOP");
  620.         Atr_core:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
  621.         Atr_core:RegisterEvent("BAG_UPDATE");
  622.  
  623.         local num = AUCTIONATOR_DE_DATA and #AUCTIONATOR_DE_DATA or 0
  624.  
  625.         zz ("Disenchanting info is being logged.  Current number of entries:", num)
  626.  
  627.     else
  628.  
  629.         Atr_core:UnregisterEvent("UNIT_SPELLCAST_START");
  630.         Atr_core:UnregisterEvent("UNIT_SPELLCAST_SENT");
  631.         Atr_core:UnregisterEvent("UNIT_SPELLCAST_STOP");
  632.         Atr_core:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED");
  633.         Atr_core:UnregisterEvent("BAG_UPDATE");
  634.  
  635.         zz ("disenchanting info is NOT being logged")
  636.     end
  637. end
  638.  
  639. -----------------------------------------
  640.  
  641. local function Atr_OnClickTradeSkillBut()
  642.  
  643.     if (not AuctionFrame or not AuctionFrame:IsShown()) then
  644.         Atr_Error_Display (ZT("When the Auction House is open\nclicking this button tells Auctionator\nto scan for the item and all its reagents."))
  645.         return
  646.     end
  647.  
  648.     Atr_SelectPane (BUY_TAB);
  649.  
  650.     local index = GetTradeSkillSelectionIndex()
  651.     local link = GetTradeSkillItemLink(index)
  652.  
  653.     local numReagents = GetTradeSkillNumReagents (index)
  654.     local reagentId
  655.  
  656.     local shoppingListName = GetItemInfo (link)
  657.     if (shoppingListName == nil) then
  658.         shoppingListName = GetTradeSkillInfo (index)
  659.     end
  660.  
  661.     local items = {}
  662.  
  663.     if (shoppingListName) then
  664.         table.insert (items, shoppingListName)
  665.     end
  666.  
  667. --  zz (shoppingListName)
  668.  
  669.     for reagentId = 1, numReagents do
  670.         local reagentName = GetTradeSkillReagentInfo(index, reagentId)
  671.         if (reagentName and not zc.StringSame(reagentName, "Crystal Vial")) then
  672.             table.insert (items, reagentName)
  673.         end
  674.     end
  675.  
  676.     Atr_SearchAH (shoppingListName, items)
  677. end
  678.  
  679. -----------------------------------------
  680.  
  681. local function Atr_ModTradeSkillFrame()
  682.  
  683.     if (gTradeSkillFrameModded) then
  684.         return
  685.     end
  686.  
  687.     if (TradeSkillFrame) then
  688.         gTradeSkillFrameModded = true
  689. --      local button = CreateFrame("BUTTON", "Auctionator_Search", TradeSkillFrame, "UIPanelButtonTemplate");
  690. --      button:SetPoint("TOPRIGHT", "TradeSkillFrameCloseButton", "TOPLEFT", 0, -8);
  691.         local button = CreateFrame("BUTTON", "Auctionator_Search", TradeSkillDetailScrollChildFrame, "UIPanelButtonTemplate");
  692.         button:SetPoint("TOPRIGHT", "TradeSkillDetailScrollChildFrame", "TOPRIGHT", -1, -24);
  693.         button:SetHeight (16)
  694.         button:SetText("AH")
  695.         button:SetNormalFontObject(_G["GameFontNormalSmall"])
  696.         button:SetHighlightFontObject(_G["GameFontNormalSmall"])
  697.         button:SetDisabledFontObject(_G["GameFontNormalSmall"])
  698.         button:SetScript ("OnClick", Atr_OnClickTradeSkillBut)
  699.         zz ("TradeSkillFrame modded")
  700.     else
  701.         zz ("TradeSkillFrame not loaded")
  702.     end
  703.  
  704.  
  705.  
  706. end
  707.  
  708. -----------------------------------------
  709.  
  710. function Atr_InitScanDB()
  711.  
  712.     local realm_Faction = GetRealmName().."_"..UnitFactionGroup ("player");
  713.  
  714.     if (AUCTIONATOR_PRICE_DATABASE and AUCTIONATOR_PRICE_DATABASE["__dbversion"] == nil) then   -- migrate version 1 to version 2
  715.  
  716.         local temp = {};
  717.  
  718.         zc.CopyDeep (temp, AUCTIONATOR_PRICE_DATABASE);
  719.  
  720.         AUCTIONATOR_PRICE_DATABASE = {};
  721.         AUCTIONATOR_PRICE_DATABASE["__dbversion"] = 2;
  722.  
  723.         AUCTIONATOR_PRICE_DATABASE[realm_Faction] = {};
  724.         zc.CopyDeep (AUCTIONATOR_PRICE_DATABASE[realm_Faction], temp);
  725.  
  726.         temp = {};
  727.     end
  728.  
  729.  
  730.  
  731.  
  732.     if (AUCTIONATOR_PRICE_DATABASE and AUCTIONATOR_PRICE_DATABASE["__dbversion"] == 2) then     -- migrate version 2 to version 3
  733.  
  734.         local temp_price_db = {};
  735.  
  736.         for realm_fac, data in pairs (AUCTIONATOR_PRICE_DATABASE) do
  737.  
  738.             if (type(data) == "table") then
  739.  
  740.                 temp_price_db[realm_fac] = {};
  741.  
  742.                 zc.md ("migrating Auctionator db to version 3 for:", realm_fac);
  743.  
  744.                 local name, price;
  745.                 local count = 0;
  746.  
  747.                 for name, price in pairs (data) do
  748.  
  749.                     if (type(price) == "table") then        -- this is to fix the bug where I didn't set the dbversion correctly for NEW dbs
  750.                         temp_price_db[realm_fac][name] = price;
  751.                     else
  752.                         Atr_UpdateScanDBprice (name, price, temp_price_db[realm_fac]);
  753.                     end
  754.                     count = count + 1;
  755.                 end
  756.  
  757.                 zc.md (count, "entries migrated");
  758.             end
  759.         end
  760.  
  761.         AUCTIONATOR_PRICE_DATABASE = temp_price_db;
  762.         AUCTIONATOR_PRICE_DATABASE["__dbversion"] = 3;
  763.     end
  764.  
  765.     -- migrate version 3 to version 4
  766.  
  767.     if (AUCTIONATOR_PRICE_DATABASE and AUCTIONATOR_PRICE_DATABASE["__dbversion"] == 3) then
  768.         for realm_fac, data in pairs (AUCTIONATOR_PRICE_DATABASE) do
  769.             if (type(data) == "table") then
  770.                 zc.md ("migrating Auctionator db to version 4 for:", realm_fac);
  771.                 local name, itemInfo;
  772.                 for name, itemInfo in pairs (data) do
  773.                     if (type(itemInfo) == "table") then
  774.                         itemInfo["po"] = 1;     -- flag for deletion after the first full scan
  775.                     end
  776.                 end
  777.             end
  778.         end
  779.         AUCTIONATOR_PRICE_DATABASE["__dbversion"] = 4;
  780.     end
  781.  
  782.     if (AUCTIONATOR_PRICE_DATABASE == nil) then
  783.         AUCTIONATOR_PRICE_DATABASE = {};
  784.         AUCTIONATOR_PRICE_DATABASE["__dbversion"] = 4;
  785.     end
  786.  
  787.     if (AUCTIONATOR_PRICE_DATABASE[realm_Faction] == nil) then
  788.         AUCTIONATOR_PRICE_DATABASE[realm_Faction] = {};
  789.     end
  790.  
  791.     gAtr_ScanDB = AUCTIONATOR_PRICE_DATABASE[realm_Faction];
  792.  
  793.     Atr_PruneScanDB ();
  794.     Atr_PrunePostDB ();
  795.  
  796.     Atr_Broadcast_DBupdated (#gAtr_ScanDB, "dbinited");
  797.  
  798. end
  799.  
  800.  
  801. -----------------------------------------
  802.  
  803. function Atr_OnLoad()
  804.  
  805.     AuctionatorVersion = GetAddOnMetadata("Auctionator", "Version");
  806.  
  807.     gTimeZero       = time({year=2000, month=1, day=1, hour=0});
  808.     gTimeTightZero  = time({year=2008, month=8, day=1, hour=0});
  809.  
  810.     local x;
  811.     for x = 0, NUM_BAG_SLOTS do
  812.         kBagIDs[x+1] = x;
  813.     end
  814.  
  815.     kBagIDs[NUM_BAG_SLOTS+2] = KEYRING_CONTAINER;
  816.  
  817.     AuctionatorLoaded = true;
  818.  
  819.     SlashCmdList["Auctionator"] = Atr_SlashCmdFunction;
  820.  
  821.     SLASH_Auctionator1 = "/auctionator";
  822.     SLASH_Auctionator2 = "/atr";
  823.  
  824.     Atr_InitScanDB ();
  825.  
  826.     if (AUCTIONATOR_PRICING_HISTORY == nil) then    -- the old history of postings
  827.         AUCTIONATOR_PRICING_HISTORY = {};
  828.     end
  829.  
  830.     if (AUCTIONATOR_TOONS == nil) then
  831.         AUCTIONATOR_TOONS = {};
  832.     end
  833.  
  834.     if (AUCTIONATOR_STACKING_PREFS == nil) then
  835.         Atr_StackingPrefs_Init();
  836.     end
  837.  
  838.     if (AUCTIONATOR_SAVEDVARS == nil) then
  839.         Atr_ResetSavedVars()
  840.     end
  841.  
  842.     local playerName = UnitName("player");
  843.  
  844.     if (not AUCTIONATOR_TOONS[playerName]) then
  845.         AUCTIONATOR_TOONS[playerName] = {};
  846.         AUCTIONATOR_TOONS[playerName].firstSeen     = time();
  847.         AUCTIONATOR_TOONS[playerName].firstVersion  = AuctionatorVersion;
  848.     end
  849.  
  850.     AUCTIONATOR_TOONS[playerName].guid = UnitGUID ("player");
  851.  
  852.     if (AUCTIONATOR_SCAN_MINLEVEL == nil) then
  853.         AUCTIONATOR_SCAN_MINLEVEL = 1;          -- poor (all) items
  854.     end
  855.  
  856.     if (AUCTIONATOR_SHOW_TIPS == 0) then        -- migrate old option to new ones
  857.         AUCTIONATOR_V_TIPS = 0;
  858.         AUCTIONATOR_A_TIPS = 0;
  859.         AUCTIONATOR_D_TIPS = 0;
  860.  
  861.         AUCTIONATOR_SHOW_TIPS = 2;
  862.     end
  863.  
  864.     if (AUCTIONATOR_OPEN_FIRST < 2) then    -- set to 2 to indicate it's been migrated
  865.         if      (AUCTIONATOR_OPEN_FIRST == 1)   then AUCTIONATOR_DEFTAB = 1;
  866.         elseif  (AUCTIONATOR_OPEN_BUY == 1)     then AUCTIONATOR_DEFTAB = 2;
  867.         else                                         AUCTIONATOR_DEFTAB = 0; end;
  868.  
  869.         AUCTIONATOR_OPEN_FIRST = 2;
  870.     end
  871.  
  872.  
  873.     Atr_SetupHookFunctionsEarly();
  874.  
  875.     ------------------
  876.  
  877.     local atrtt1 = CreateFrame( "GameTooltip", "AtrScanningTooltip", nil, "GameTooltipTemplate" ); -- Tooltip name cannot be nil
  878.     if (atrtt1 == nil) then
  879.         zc.msg_anm ("Unable to create AtrScanningTooltip");
  880.     end
  881.     AtrScanningTooltip:SetOwner( WorldFrame, "ANCHOR_NONE" );
  882.     -- Allow tooltip SetX() methods to dynamically add new lines based on these
  883. --  AtrScanningTooltip:AddFontStrings(
  884. --  AtrScanningTooltip:CreateFontString( "$parentTextLeft1", nil, "GameTooltipText" ),
  885. --  AtrScanningTooltip:CreateFontString( "$parentTextRight1", nil, "GameTooltipText" ) );
  886.  
  887.     -- a second scanning tooltip for use by zc.PullItemIntoMemory
  888.     -- fixed a bug to separate this out from the original one (above)
  889.  
  890.     local atrtt2 = CreateFrame( "GameTooltip", "AtrScanningTooltip2", nil, "GameTooltipTemplate" ); -- Tooltip name cannot be nil
  891.     if (atrtt2 == nil) then
  892.         zc.msg_anm ("Unable to create AtrScanningTooltip2");
  893.     end
  894.     AtrScanningTooltip2:SetOwner( WorldFrame, "ANCHOR_NONE" );
  895.     -- Allow tooltip SetX() methods to dynamically add new lines based on these
  896. --  AtrScanningTooltip2:AddFontStrings(
  897. --  AtrScanningTooltip2:CreateFontString( "$parentTextLeft1", nil, "GameTooltipText" ),
  898. --  AtrScanningTooltip2:CreateFontString( "$parentTextRight1", nil, "GameTooltipText" ) );
  899.  
  900.     ------------------
  901.  
  902.     Atr_CheckClassMappings()
  903.  
  904.     Atr_InitDETable()
  905.  
  906.     Atr_ShoppingListsInit();
  907.  
  908.     zc.msg_anm ("Read the FAQ at |cFF4499FFhttp://auctionatoraddon.com/faq")
  909.  
  910.     EnableDisableDElogging ()
  911.  
  912.     if ( IsAddOnLoaded("Blizzard_AuctionUI") ) then     -- need this for AH_QuickSearch since that mod forces Blizzard_AuctionUI to load at a startup
  913.         Atr_Init();
  914.     end
  915.  
  916.     Atr_ModTradeSkillFrame()
  917. end
  918.  
  919. -----------------------------------------
  920.  
  921. local gPrevTime = 0;
  922.  
  923. function Atr_OnAddonLoaded(...)
  924.  
  925.     local addonName = select (1, ...);
  926.  
  927.     if (zc.StringSame (addonName, "blizzard_auctionui")) then
  928.         Atr_Init();
  929.     end
  930.  
  931.     Atr_Check_For_Conflicts (addonName);
  932.  
  933.     local now = time();
  934.  
  935. --  zz (addonName.."   time: "..now - gStartingTime);
  936.  
  937.     gPrevTime = now;
  938.  
  939.     if (zc.StringSame (addonName, "blizzard_tradeskillui")) then
  940.         Atr_ModTradeSkillFrame();
  941.     end
  942.  
  943. end
  944.  
  945.  
  946.  
  947.  
  948. -----------------------------------------
  949. function Atr_OnPlayerEnteringWorld()
  950.  
  951.     Atr_InitOptionsPanels();
  952.     Atr_Install_Error_Handler()
  953.  
  954.     if (RegisterAddonMessagePrefix) then
  955.         RegisterAddonMessagePrefix ("ATR")
  956.     end
  957.  
  958. --  Atr_MakeOptionsFrameOpaque();
  959. end
  960.  
  961. -----------------------------------------
  962.  
  963. local preDEmats;
  964. local preDEgear;
  965. local gDisenchantTime = 0;
  966.  
  967. -----------------------------------------
  968.  
  969. function Atr_ScanBags (mats, gear)
  970.  
  971.     local bagID, slotID, numslots;
  972.  
  973.     for bagID = 0, NUM_BAG_SLOTS do
  974.  
  975.         local numslots = GetContainerNumSlots (bagID);
  976.  
  977.         for slotID = 1,numslots do
  978.  
  979.             local itemLink = GetContainerItemLink(bagID, slotID);
  980.  
  981.             if (itemLink) then
  982.                 local texture, itemCount, locked, quality   = GetContainerItemInfo(bagID, slotID);
  983.  
  984.                 local itemName, _, itemRarity, itemLevel, _, itemType, itemSubType = GetItemInfo (itemLink);
  985.  
  986.                 if ((itemType == "Armor" or itemType == "Weapon") and itemLevel > 271) then
  987.                     local key = itemType.."_"..itemSubType.."_"..itemRarity.."_"..itemLevel;
  988.                     if (gear[key]) then
  989.                         gear[key].count = gear[key].count + 1;
  990.                     else
  991.                         local q = "X";
  992.  
  993.                         if (itemRarity == 2) then q = "G"; end
  994.                         if (itemRarity == 3) then q = "B"; end
  995.                         if (itemRarity == 4) then q = "P"; end
  996.  
  997.                         gear[key] = { t=itemType, s=itemSubType, q=q, lev=itemLevel, count=itemCount };
  998.                     end
  999.                 end
  1000.  
  1001.                 if (zc.StringContains (itemName, "Celestial Essence", "Heavenly Shard", "Hypnotic Dust", "Maelstrom Crystal")) then
  1002.                     local key = itemName;
  1003.                     if (mats[key]) then
  1004.                         mats[key].count = mats[key].count + itemCount;
  1005.                     else
  1006.                         mats[key] = { count=itemCount };
  1007.                     end
  1008.                 end
  1009.             end
  1010.  
  1011.         end
  1012.     end
  1013.  
  1014. end
  1015.  
  1016. -----------------------------------------
  1017.  
  1018. function Atr_OnSpellCastSent (...)
  1019.  
  1020.     if (select (2,...) ~= "Disenchant") then
  1021.         return;
  1022.     end
  1023.  
  1024.     preDEmats = {};
  1025.     preDEgear = {};
  1026.  
  1027.     Atr_ScanBags (preDEmats, preDEgear);
  1028.  
  1029. end
  1030.  
  1031. -----------------------------------------
  1032.  
  1033. function Atr_OnSpellCastSucess (...)
  1034.  
  1035.     if (select (2,...) ~= "Disenchant") then
  1036.         return;
  1037.     end
  1038.  
  1039.     gDisenchantTime = time();
  1040.  
  1041. --[[    local k, m, g;
  1042.  
  1043.     zz ("-----")
  1044.     for k, g in pairs (preDEgear) do
  1045.         zz (g.t, g.s, g.q, g.lev, g.count)
  1046.     end
  1047.  
  1048.     zz ("-----")
  1049.     for k, m in pairs (preDEmats) do
  1050.         zz (k, m.count)
  1051.     end
  1052. ]]--
  1053. end
  1054.  
  1055. -----------------------------------------
  1056.  
  1057. function Atr_OnBagUpdate (...)
  1058.  
  1059.     if (time() - gDisenchantTime > 5) then
  1060.         return;
  1061.     end
  1062.  
  1063.     local postMats = {};
  1064.     local postGear = {};
  1065.  
  1066.     Atr_ScanBags (postMats, postGear);
  1067.  
  1068.     local k, m, g;
  1069.  
  1070.     local preMats = {}
  1071.     local preGear = {};
  1072.  
  1073.     zc.CopyDeep (preMats, preDEmats)
  1074.     zc.CopyDeep (preGear, preDEgear)
  1075.  
  1076.     for k, g in pairs (postGear) do
  1077.         if (preGear[k]) then
  1078.             preGear[k].count = preGear[k].count - g.count
  1079.         end
  1080.     end
  1081.  
  1082.     for k, m in pairs (postMats) do
  1083.         if (preMats[k]) then
  1084.             preMats[k].count = preMats[k].count - m.count
  1085.         else
  1086.             preMats[k] = {};
  1087.             zc.CopyDeep (preMats[k], m)
  1088.             preMats[k].count = 0 - m.count
  1089.         end
  1090.     end
  1091.  
  1092.     local result = {};
  1093.     local numG = 0;
  1094.     local numM = 0;
  1095.  
  1096.     for k, g in pairs (preGear) do
  1097.         if (g.count ~= 0) then
  1098.             numG = numG + 1;
  1099.             zc.CopyDeep (result, g)
  1100.         end
  1101.     end
  1102.  
  1103.     for k, m in pairs (preMats) do
  1104.         if (m.count ~= 0) then
  1105.             numM = numM + 1;
  1106.             result.matname = k;
  1107.             result.matcount = -m.count;
  1108.         end
  1109.     end
  1110.  
  1111.     if (numG == 1 and numM == 1) then
  1112.         local matname = result.matname;
  1113.  
  1114.         if     (zc.StringSame (result.matname, "Hypnotic Dust"))                then matname = "HDU";
  1115.         elseif (zc.StringSame (result.matname, "Greater Celestial Essence"))    then matname = "GCE";
  1116.         elseif (zc.StringSame (result.matname, "Lesser Celestial Essence"))     then matname = "LCE";
  1117.         elseif (zc.StringSame (result.matname, "Heavenly Shard"))               then matname = "NHV";
  1118.         elseif (zc.StringSame (result.matname, "Small Heavenly Shard"))         then matname = "SHV";
  1119.         elseif (zc.StringSame (result.matname, "Maelstrom Crystal"))            then matname = "MAC";  end
  1120.  
  1121.         local itemClass     = Atr_ItemType2AuctionClass   (result.t)
  1122.         local itemSubclass  = Atr_SubType2AuctionSubclass (itemClass, result.s)
  1123.  
  1124.         local itemClassAbbrev = "A"
  1125.         if (Atr_IsWeaponType (result.t)) then
  1126.             itemClassAbbrev = "W"
  1127.         end
  1128.  
  1129.         local reftime = time({year=2010, month=12, day=1, hour=0})
  1130.         local dec13   = time({year=2010, month=12, day=13, hour=0})
  1131.  
  1132.         local tm = time() - reftime;
  1133.         tm = math.floor (tm / 3600)
  1134.  
  1135.         local s = tm.."_"..result.matcount.."_"..matname.."_"..itemClassAbbrev.."_"..itemSubclass.."_"..result.q.."_"..result.lev;
  1136. --      zz (s);
  1137.  
  1138.         gDisenchantTime = 0;
  1139.  
  1140.         if (AUCTIONATOR_DE_DATA == nil) then
  1141.             AUCTIONATOR_DE_DATA = {}
  1142.         end
  1143.  
  1144.         table.insert (AUCTIONATOR_DE_DATA, s);
  1145.  
  1146.         AUCTIONATOR_DE_DATA_BAK = nil
  1147.     end
  1148.  
  1149.  
  1150.  
  1151. end
  1152.  
  1153. -----------------------------------------
  1154.  
  1155. function Atr_Init()
  1156.  
  1157.     if (AuctionatorInited) then
  1158.         return;
  1159.     end
  1160.  
  1161.     AuctionatorInited = true;
  1162.  
  1163.     if (AUCTIONATOR_SAVEDVARS == nil) then
  1164.         Atr_ResetSavedVars()
  1165.     end
  1166.  
  1167.     --Bump_MaxButton_Hack();
  1168.  
  1169.  
  1170.     gShopPane   = Atr_AddSellTab (ZT("Buy"),            BUY_TAB);
  1171.     gSellPane   = Atr_AddSellTab (ZT("Sell"),           SELL_TAB);
  1172.     gMorePane   = Atr_AddSellTab (ZT("More").."...",    MORE_TAB);
  1173.  
  1174.     Atr_AddMainPanel ();
  1175.  
  1176.     Atr_SetupHookFunctions ();
  1177.  
  1178.     recommendElements[1] = _G["Atr_Recommend_Text"];
  1179.     recommendElements[2] = _G["Atr_RecommendPerItem_Text"];
  1180.     recommendElements[3] = _G["Atr_RecommendPerItem_Price"];
  1181.     recommendElements[4] = _G["Atr_RecommendPerStack_Text"];
  1182.     recommendElements[5] = _G["Atr_RecommendPerStack_Price"];
  1183.     recommendElements[6] = _G["Atr_Recommend_Basis_Text"];
  1184.     recommendElements[7] = _G["Atr_RecommendItem_Tex"];
  1185.  
  1186.     -- create the lines that appear in the item history scroll pane
  1187.  
  1188.     local line, n;
  1189.  
  1190.     for n = 1, ITEM_HIST_NUM_LINES do
  1191.         local y = -5 - ((n-1)*16);
  1192.         line = CreateFrame("BUTTON", "AuctionatorHEntry"..n, Atr_Hlist, "Atr_HEntryTemplate");
  1193.         line:SetPoint("TOPLEFT", 0, y);
  1194.     end
  1195.  
  1196.     Atr_ShowHide_StartingPrice();
  1197.  
  1198.     Atr_LocalizeFrames();
  1199.  
  1200. end
  1201.  
  1202. -----------------------------------------
  1203.  
  1204. function Atr_ShowHide_StartingPrice()
  1205.  
  1206.     if (AUCTIONATOR_SHOW_ST_PRICE == 1) then
  1207.         Atr_StartingPriceText:Show();
  1208.         Atr_StartingPrice:Show();
  1209.         Atr_StartingPriceDiscountText:Hide();
  1210.         Atr_Duration_Text:SetPoint ("TOPLEFT", 10, -307);
  1211.     else
  1212.         Atr_StartingPriceText:Hide();
  1213.         Atr_StartingPrice:Hide();
  1214.         Atr_StartingPriceDiscountText:Show();
  1215.         Atr_Duration_Text:SetPoint ("TOPLEFT", 10, -304);
  1216.     end
  1217. end
  1218.  
  1219.  
  1220. -----------------------------------------
  1221.  
  1222. function Atr_GetSellItemInfo ()
  1223.  
  1224.     local auctionItemName, auctionTexture, auctionCount, auctionQuality = GetAuctionSellItemInfo();
  1225.  
  1226. --zz ("GetAuctionSellItemInfo: ", GetAuctionSellItemInfo());
  1227.  
  1228.     if (auctionItemName == nil) then
  1229.         auctionItemName = "";
  1230.         auctionCount    = 0;
  1231.     end
  1232.  
  1233.     local auctionItemLink = nil;
  1234.  
  1235.     -- only way to get sell itemlink that I can figure
  1236.  
  1237.     if (auctionItemName ~= "") then
  1238.  
  1239.         -- in 5.0 GameTooltip:SetAuctionSellItem was changed to RETURN values if the auction item is a Battle Pet.  Go figure.
  1240.  
  1241.         local hasCooldown, speciesID, level, breedQuality, maxHealth, power, speed, name = GameTooltip:SetAuctionSellItem();
  1242.  
  1243.         if (speciesID and speciesID > 0) then       -- if it's a battle pet, construct a fake battlepet link
  1244.  
  1245.             local battlePetID = 0       -- unofortunately we don't know it
  1246.  
  1247.             auctionItemLink = "|cffcccccc|Hbattlepet:"..speciesID..":"..level..":"..breedQuality..":"..maxHealth..":"..power..":"..speed..":"..battlePetID.."|h["..name.."]|h|r";
  1248.  
  1249.             gBattlePetIconCache[auctionItemLink] = auctionTexture;
  1250.  
  1251.             --zz ((auctionItemLink));
  1252.  
  1253.         else
  1254.             AtrScanningTooltip:SetAuctionSellItem();
  1255.  
  1256.             local name;
  1257.             name, auctionItemLink = AtrScanningTooltip:GetItem();
  1258.  
  1259.             if (auctionItemLink == nil) then
  1260.                 return "",0,nil;
  1261.             end
  1262.         end
  1263.  
  1264.     end
  1265.  
  1266. --zz (auctionItemName, auctionCount, auctionItemLink);
  1267. --zz ("-----------------------------");
  1268.  
  1269.     return auctionItemName, auctionCount, auctionItemLink;
  1270.  
  1271. end
  1272.  
  1273.  
  1274. -----------------------------------------
  1275.  
  1276. function Atr_ResetSavedVars ()
  1277.     AUCTIONATOR_SAVEDVARS = {};
  1278.     zc.CopyDeep (AUCTIONATOR_SAVEDVARS, auctionator_savedvars_defaults);
  1279. end
  1280.  
  1281.  
  1282. --------------------------------------------------------------------------------
  1283.  
  1284. function Atr_FindTabIndex (whichTab)
  1285.  
  1286.     local i;
  1287.     for i = 4,20  do
  1288.         local tab = _G['AuctionFrameTab'..i];
  1289.  
  1290.         if (tab and tab.auctionatorTab and tab.auctionatorTab == whichTab) then
  1291.             return i
  1292.         end
  1293.     end
  1294.  
  1295.     return 0
  1296. end
  1297.  
  1298.  
  1299.  
  1300. -----------------------------------------
  1301.  
  1302.  
  1303. function Atr_AuctionFrameTab_OnClick (self, index, down)
  1304.  
  1305.     if ( index == nil or type(index) == "string") then
  1306.         index = self:GetID();
  1307.     end
  1308.  
  1309.     _G["Atr_Main_Panel"]:Hide();
  1310.  
  1311.     gBuyState = ATR_BUY_NULL;           -- just in case
  1312.     gItemPostingInProgress = false;     -- just in case
  1313.  
  1314.     auctionator_orig_AuctionFrameTab_OnClick (self, index, down);
  1315.  
  1316.     if (not Atr_IsAuctionatorTab(index)) then
  1317.         gForceMsgAreaUpdate = true;
  1318.         Atr_HideAllDialogs();
  1319.  
  1320.         if (index >= 1 and index <= 3) then     -- if it's one of Blizzard's tabs
  1321.             AuctionFrameMoneyFrame:Show();
  1322.         end
  1323.  
  1324.         if (AP_Bid_MoneyFrame) then     -- for the addon 'Auction Profit'
  1325.             if (AP_ShowBid) then    AP_ShowHide_Bid_Button(1);  end;
  1326.             if (AP_ShowBO)  then    AP_ShowHide_BO_Button(1);   end;
  1327.         end
  1328.  
  1329.  
  1330.     elseif (Atr_IsAuctionatorTab(index)) then
  1331.  
  1332.         AuctionFrameAuctions:Hide();
  1333.         AuctionFrameBrowse:Hide();
  1334.         AuctionFrameBid:Hide();
  1335.         PlaySound("igCharacterInfoTab");
  1336.  
  1337.         PanelTemplates_SetTab(AuctionFrame, index);
  1338.  
  1339.         AuctionFrameTopLeft:SetTexture  ("Interface\\AddOns\\Auctionator\\Images\\Atr_topleft");
  1340.         AuctionFrameBotLeft:SetTexture  ("Interface\\AddOns\\Auctionator\\Images\\Atr_botleft");
  1341.         AuctionFrameTop:SetTexture      ("Interface\\AddOns\\Auctionator\\Images\\Atr_top");
  1342.         AuctionFrameTopRight:SetTexture ("Interface\\AddOns\\Auctionator\\Images\\Atr_topright");
  1343.         AuctionFrameBot:SetTexture      ("Interface\\AddOns\\Auctionator\\Images\\Atr_bot");
  1344.         AuctionFrameBotRight:SetTexture ("Interface\\AddOns\\Auctionator\\Images\\Atr_botright");
  1345.  
  1346.         if (index == Atr_FindTabIndex(SELL_TAB))    then gCurrentPane = gSellPane; end;
  1347.         if (index == Atr_FindTabIndex(BUY_TAB))     then gCurrentPane = gShopPane; end;
  1348.         if (index == Atr_FindTabIndex(MORE_TAB))    then gCurrentPane = gMorePane; end;
  1349.  
  1350.         if (index == Atr_FindTabIndex(SELL_TAB))    then AuctionatorTitle:SetText ("Auctionator - "..ZT("Sell"));           end;
  1351.         if (index == Atr_FindTabIndex(BUY_TAB))     then AuctionatorTitle:SetText ("Auctionator - "..ZT("Buy"));            end;
  1352.         if (index == Atr_FindTabIndex(MORE_TAB))    then AuctionatorTitle:SetText ("Auctionator - "..ZT("More").."...");    end;
  1353.  
  1354.         Atr_ClearHlist();
  1355.         Atr_SellControls:Hide();
  1356.         Atr_Hlist:Hide();
  1357.         Atr_Hlist_ScrollFrame:Hide();
  1358.         Atr_Search_Box:Hide();
  1359.         Atr_Search_Button:Hide();
  1360.         Atr_Adv_Search_Button:Hide();
  1361.         Atr_AddToSListButton:Hide();
  1362.         Atr_RemFromSListButton:Hide();
  1363.         Atr_NewSListButton:Hide();
  1364.         Atr_MngSListsButton:Hide();
  1365.         Atr_SrchSListButton:Hide()
  1366.         Atr_ActiveItems_Text:Hide();
  1367.         Atr_DropDownSL:Hide();
  1368.         Atr_CheckActiveButton:Hide();
  1369.         Atr_Back_Button:Hide()
  1370.         Atr_SaveThisList_Button:Hide()
  1371.  
  1372.         AuctionFrameMoneyFrame:Hide();
  1373.  
  1374.         if (index == Atr_FindTabIndex(SELL_TAB)) then
  1375.             Atr_SellControls:Show();
  1376.         else
  1377.             Atr_Hlist:Show();
  1378.             Atr_Hlist_ScrollFrame:Show();
  1379.             if (gJustPosted.ItemName) then
  1380.                 gJustPosted.ItemName = nil;
  1381.                 gSellPane:ClearSearch ();
  1382.             end
  1383.         end
  1384.  
  1385.  
  1386.         if (index == Atr_FindTabIndex(MORE_TAB)) then
  1387.             FauxScrollFrame_SetOffset (Atr_Hlist_ScrollFrame, gCurrentPane.hlistScrollOffset);
  1388.             Atr_DisplayHlist();
  1389.             Atr_ActiveItems_Text:Show();
  1390.             Atr_CheckActiveButton:Show();
  1391.         end
  1392.  
  1393.  
  1394.         if (index == Atr_FindTabIndex(BUY_TAB)) then
  1395.             Atr_Search_Box:Show();
  1396.             Atr_Search_Button:Show();
  1397.             Atr_Adv_Search_Button:Show();
  1398.             AuctionFrameMoneyFrame:Show();
  1399. --          Atr_BuildGlobalHistoryList(true);
  1400.             Atr_AddToSListButton:Show();
  1401.             Atr_RemFromSListButton:Show();
  1402.             Atr_NewSListButton:Show();
  1403.             Atr_MngSListsButton:Show();
  1404.             Atr_SrchSListButton:Show()
  1405.             Atr_DropDownSL:Show();
  1406.             Atr_Hlist:SetHeight (252);
  1407.             Atr_Hlist_ScrollFrame:SetHeight (252);
  1408.         else
  1409.             Atr_Hlist:SetHeight (335);
  1410.             Atr_Hlist_ScrollFrame:SetHeight (335);
  1411.         end
  1412.  
  1413.         if (index == Atr_FindTabIndex(BUY_TAB) or index == Atr_FindTabIndex(SELL_TAB)) then
  1414.             Atr_Buy1_Button:Show();
  1415.             Atr_Buy1_Button:Disable();
  1416.         end
  1417.  
  1418.         Atr_HideElems (recommendElements);
  1419.  
  1420.         _G["Atr_Main_Panel"]:Show();
  1421.  
  1422.         gCurrentPane.UINeedsUpdate = true;
  1423.  
  1424.         if (gOpenAllBags == 1) then
  1425.             OpenAllBags();
  1426.             gOpenAllBags = 0;
  1427.         end
  1428.  
  1429.     end
  1430.  
  1431. end
  1432.  
  1433. -----------------------------------------
  1434.  
  1435. function Atr_StackSize ()
  1436.     return Atr_Batch_Stacksize:GetNumber();
  1437. end
  1438.  
  1439. -----------------------------------------
  1440.  
  1441. function Atr_SetStackSize (n)
  1442.     return Atr_Batch_Stacksize:SetText(n);
  1443. end
  1444.  
  1445. -----------------------------------------
  1446.  
  1447. function Atr_SelectPane (whichTab)
  1448.  
  1449.     local index = Atr_FindTabIndex(whichTab);
  1450.     local tab   = _G['AuctionFrameTab'..index];
  1451.  
  1452.     Atr_AuctionFrameTab_OnClick (tab, index);
  1453.  
  1454. end
  1455.  
  1456. -----------------------------------------
  1457.  
  1458. function Atr_IsModeCreateAuction ()
  1459.     return (Atr_IsTabSelected(SELL_TAB));
  1460. end
  1461.  
  1462.  
  1463. -----------------------------------------
  1464.  
  1465. function Atr_IsModeBuy ()
  1466.     return (Atr_IsTabSelected(BUY_TAB));
  1467. end
  1468.  
  1469. -----------------------------------------
  1470.  
  1471. function Atr_IsModeActiveAuctions ()
  1472.     return (Atr_IsTabSelected(MORE_TAB));
  1473. end
  1474.  
  1475. -----------------------------------------
  1476.  
  1477. function Atr_ClickAuctionSellItemButton (self, button)
  1478.  
  1479. -- zc.printstack();
  1480.  
  1481.     if (AuctionFrameAuctions.duration == nil) then      -- blizz attempts to calculate deposit below and in some cases, duration has yet to be set
  1482.         AuctionFrameAuctions.duration = 1;
  1483.     end
  1484.  
  1485.     gAtr_ClickAuctionSell = true;
  1486.     ClickAuctionSellItemButton(self, button);
  1487. end
  1488.  
  1489.  
  1490. -----------------------------------------
  1491.  
  1492. function Atr_OnDropItem (self, button)
  1493.  
  1494.     if (GetCursorInfo() ~= "item") then
  1495.         return;
  1496.     end
  1497.  
  1498.     if (not Atr_IsTabSelected(SELL_TAB)) then
  1499.         Atr_SelectPane (SELL_TAB);      -- then fall through
  1500.     end
  1501.  
  1502.     Atr_ClickAuctionSellItemButton (self, button);
  1503.     ClearCursor();
  1504. end
  1505.  
  1506. -----------------------------------------
  1507.  
  1508. function Atr_SellItemButton_OnClick (self, button, ...)
  1509.  
  1510.     Atr_ClickAuctionSellItemButton (self, button);
  1511. end
  1512.  
  1513. -----------------------------------------
  1514.  
  1515. function Atr_SellItemButton_OnEvent (self, event, ...)
  1516.  
  1517.     if ( event == "NEW_AUCTION_UPDATE") then
  1518.         local name, texture, count, quality, canUse, price = GetAuctionSellItemInfo();
  1519.         Atr_SellControls_Tex:SetNormalTexture(texture);
  1520.     end
  1521.  
  1522. end
  1523.  
  1524. -----------------------------------------
  1525.  
  1526. local function Atr_LoadContainerItemToSellPane(slot)
  1527.  
  1528.     local bagID  = slot:GetParent():GetID();
  1529.     local slotID = slot:GetID();
  1530.  
  1531.     if (not Atr_IsTabSelected(SELL_TAB)) then
  1532.         Atr_SelectPane (SELL_TAB);
  1533.     end
  1534.  
  1535.     if (IsControlKeyDown()) then
  1536.         gAutoSingleton = time();
  1537.     end
  1538.  
  1539.     PickupContainerItem(bagID, slotID);
  1540.  
  1541.     local infoType = GetCursorInfo()
  1542.  
  1543.     if (infoType == "item") then
  1544.         Atr_ClearAll();
  1545.         Atr_ClickAuctionSellItemButton ();
  1546.         ClearCursor();
  1547.     end
  1548.  
  1549. end
  1550.  
  1551. -----------------------------------------
  1552.  
  1553. function Atr_ContainerFrameItemButton_OnClick (self, button)
  1554.  
  1555.     if (AuctionFrame and AuctionFrame:IsShown() and zc.StringSame (button, "RightButton")) then
  1556.  
  1557.         local selectedTab = PanelTemplates_GetSelectedTab (AuctionFrame);
  1558.  
  1559.         if (selectedTab == 1 or selectedTab == 2 or Atr_IsAuctionatorTab(selectedTab)) then
  1560.             Atr_LoadContainerItemToSellPane (self);
  1561.         end
  1562.     end
  1563.  
  1564. end
  1565.  
  1566. -----------------------------------------
  1567.  
  1568. function Atr_ContainerFrameItemButton_OnModifiedClick (self, button)
  1569.  
  1570.     if (AUCTIONATOR_ENABLE_ALT ~= 0 and AuctionFrame:IsShown() and IsAltKeyDown()) then
  1571.  
  1572.         Atr_LoadContainerItemToSellPane(self);
  1573.         return;
  1574.     end
  1575.  
  1576.     return auctionator_orig_ContainerFrameItemButton_OnModifiedClick (self, button);
  1577. end
  1578.  
  1579.  
  1580.  
  1581.  
  1582. -----------------------------------------
  1583.  
  1584. function Atr_CreateAuction_OnClick ()
  1585.  
  1586.     gAtr_SellTriggeredByAuctionator = true;
  1587.  
  1588.     gJustPosted.ItemName            = gCurrentPane.activeScan.itemName;
  1589.     gJustPosted.ItemLink            = gCurrentPane.activeScan.itemLink;
  1590.     gJustPosted.BuyoutPrice         = MoneyInputFrame_GetCopper(Atr_StackPrice);
  1591.  
  1592.     if (zc.IsBattlePetLink (gJustPosted.ItemLink)) then
  1593.         gJustPosted.StackSize           = 1;
  1594.         gJustPosted.NumStacks           = 1;
  1595.     else
  1596.         gJustPosted.StackSize           = Atr_StackSize();
  1597.         gJustPosted.NumStacks           = Atr_Batch_NumAuctions:GetNumber();
  1598.     end
  1599.  
  1600.     local duration              = UIDropDownMenu_GetSelectedValue(Atr_Duration);
  1601.     local stackStartingPrice    = MoneyInputFrame_GetCopper(Atr_StartingPrice);
  1602.     local stackBuyoutPrice      = MoneyInputFrame_GetCopper(Atr_StackPrice);
  1603.  
  1604.     Atr_Memorize_Stacking_If();
  1605.  
  1606.     StartAuction (stackStartingPrice, stackBuyoutPrice, duration, gJustPosted.StackSize, gJustPosted.NumStacks);
  1607.  
  1608.     Atr_SetToShowCurrent();
  1609. end
  1610.  
  1611.  
  1612. -----------------------------------------
  1613.  
  1614. local gMS_stacksPrev;
  1615.  
  1616. -----------------------------------------
  1617.  
  1618. function Atr_OnAuctionMultiSellStart()
  1619.  
  1620.     gMS_stacksPrev = 0;
  1621. end
  1622.  
  1623. -----------------------------------------
  1624.  
  1625. function Atr_OnAuctionMultiSellUpdate(...)
  1626.  
  1627.     if (not gAtr_SellTriggeredByAuctionator) then
  1628.         zc.md ("skipping.  gAtr_SellTriggeredByAuctionator is false");
  1629.         return;
  1630.     end
  1631.  
  1632.     local stacksSoFar, stacksTotal = ...;
  1633.  
  1634.     --zc.md ("stacksSoFar: ", stacksSoFar, "stacksTotal: ", stacksTotal);
  1635.  
  1636.     local delta = stacksSoFar - gMS_stacksPrev;
  1637.  
  1638.     gMS_stacksPrev = stacksSoFar;
  1639.  
  1640.     Atr_AddToScan (gJustPosted.ItemLink, gJustPosted.ItemName, gJustPosted.StackSize, gJustPosted.BuyoutPrice, delta);
  1641.  
  1642.     if (stacksSoFar == stacksTotal) then
  1643.         Atr_LogMsg (gJustPosted.ItemLink, gJustPosted.StackSize, gJustPosted.BuyoutPrice, stacksTotal);
  1644.         Atr_AddHistoricalPrice (gJustPosted.ItemName, gJustPosted.BuyoutPrice / gJustPosted.StackSize, gJustPosted.StackSize, gJustPosted.ItemLink);
  1645.         gAtr_SellTriggeredByAuctionator = false;     -- reset
  1646.     end
  1647.  
  1648. end
  1649.  
  1650. -----------------------------------------
  1651.  
  1652. function Atr_OnAuctionMultiSellFailure()
  1653.  
  1654.     if (not gAtr_SellTriggeredByAuctionator) then
  1655.         zc.md ("skipping.  gAtr_SellTriggeredByAuctionator is false");
  1656.         return;
  1657.     end
  1658.  
  1659.     -- add one more.  no good reason other than it just seems to work
  1660.     Atr_AddToScan (gJustPosted.ItemLink, gJustPosted.ItemName, gJustPosted.StackSize, gJustPosted.BuyoutPrice, 1);
  1661.  
  1662.     Atr_LogMsg (gJustPosted.ItemLink, gJustPosted.StackSize, gJustPosted.BuyoutPrice, gMS_stacksPrev + 1);
  1663.     Atr_AddHistoricalPrice (gJustPosted.ItemName, gJustPosted.BuyoutPrice / gJustPosted.StackSize, gJustPosted.StackSize, gJustPosted.ItemLink);
  1664.  
  1665.     gAtr_SellTriggeredByAuctionator = false;     -- reset
  1666.  
  1667.     if (gCurrentPane.activeScan) then
  1668.         gCurrentPane.activeScan.whenScanned = 0;
  1669.     end
  1670. end
  1671.  
  1672.  
  1673. -----------------------------------------
  1674.  
  1675. function Atr_AuctionFrameAuctions_Update()
  1676.  
  1677.     auctionator_orig_AuctionFrameAuctions_Update();
  1678.  
  1679. end
  1680.  
  1681.  
  1682. -----------------------------------------
  1683.  
  1684. function Atr_LogMsg (itemlink, itemcount, price, numstacks)
  1685.  
  1686.     if (itemlink == nil) then
  1687.         itemlink = "<nil>";
  1688.     end
  1689.  
  1690.     local logmsg = string.format (ZT("Auction created for %s"), itemlink);
  1691.  
  1692.     if (numstacks > 1) then
  1693.         logmsg = string.format (ZT("%d auctions created for %s"), numstacks, itemlink);
  1694.     end
  1695.  
  1696.  
  1697.     if (itemcount > 1) then
  1698.         logmsg = logmsg.."|cff00ddddx"..itemcount.."|r";
  1699.     end
  1700.  
  1701.     logmsg = logmsg.."   "..zc.priceToString(price);
  1702.  
  1703.     if (numstacks > 1 and itemcount > 1) then
  1704.         logmsg = logmsg.."  per stack";
  1705.     end
  1706.  
  1707.  
  1708.     zc.msg_yellow (logmsg);
  1709.  
  1710. end
  1711.  
  1712. -----------------------------------------
  1713.  
  1714. function Atr_OnAuctionOwnedUpdate ()
  1715.  
  1716.     gItemPostingInProgress = false;
  1717.  
  1718.     if (Atr_IsModeActiveAuctions()) then
  1719.         gHlistNeedsUpdate = true;
  1720.     end
  1721.  
  1722.     if (not Atr_IsTabSelected()) then
  1723.         Atr_ClearScanCache();       -- if not our tab, we have no idea what happened so must flush all caches
  1724.         return;
  1725.     end;
  1726.  
  1727.     gActiveAuctions = {};       -- always flush this cache
  1728.  
  1729.     if (gAtr_SellTriggeredByAuctionator) then
  1730.  
  1731.         if (gJustPosted.ItemName) then
  1732.  
  1733.             if (gJustPosted.NumStacks == 1) then
  1734.                 Atr_LogMsg (gJustPosted.ItemLink, gJustPosted.StackSize, gJustPosted.BuyoutPrice, 1);
  1735.                 Atr_AddHistoricalPrice (gJustPosted.ItemName, gJustPosted.BuyoutPrice / gJustPosted.StackSize, gJustPosted.StackSize, gJustPosted.ItemLink);
  1736.                 Atr_AddToScan (gJustPosted.ItemLink, gJustPosted.ItemName, gJustPosted.StackSize, gJustPosted.BuyoutPrice, 1);
  1737.  
  1738.                 gAtr_SellTriggeredByAuctionator = false;     -- reset
  1739.             end
  1740.         end
  1741.     end
  1742.  
  1743. end
  1744.  
  1745. -----------------------------------------
  1746.  
  1747. function Atr_ResetDuration()
  1748.  
  1749.     local durMenu = _G["Atr_Duration"]
  1750.  
  1751.     UIDropDownMenu_Initialize (durMenu, Atr_Duration_Initialize);
  1752.  
  1753.     if (AUCTIONATOR_DEF_DURATION == "S") then UIDropDownMenu_SetSelectedValue(durMenu, 1); end;
  1754.     if (AUCTIONATOR_DEF_DURATION == "M") then UIDropDownMenu_SetSelectedValue(durMenu, 2); end;
  1755.     if (AUCTIONATOR_DEF_DURATION == "L") then UIDropDownMenu_SetSelectedValue(durMenu, 3); end;
  1756.  
  1757. end
  1758.  
  1759. -----------------------------------------
  1760.  
  1761. function Atr_AddToScan (itemLink, itemName, stackSize, buyoutPrice, numAuctions)
  1762.  
  1763.     local IDstring = zc.ItemIDStrfromLink (itemLink);
  1764.  
  1765.     local scan = Atr_FindScan (IDstring, itemName);
  1766.  
  1767.     if (scan) then
  1768.         scan:AddScanItem (stackSize, buyoutPrice, UnitName("player"), numAuctions);
  1769.         scan:CondenseAndSort ();
  1770.     end
  1771.  
  1772.     gCurrentPane.UINeedsUpdate = true;
  1773. end
  1774.  
  1775. -----------------------------------------
  1776.  
  1777. function AuctionatorSubtractFromScan (itemLink, stackSize, buyoutPrice, howMany)
  1778.  
  1779.     if (howMany == nil) then
  1780.         howMany = 1;
  1781.     end
  1782.  
  1783.     local IDstring = zc.ItemIDStrfromLink (itemLink);
  1784.  
  1785.     local scan = Atr_FindScan (IDstring);
  1786.  
  1787.     if (scan) then
  1788.         local x;
  1789.         for x = 1, howMany do
  1790.             scan:SubtractScanItem (stackSize, buyoutPrice);
  1791.         end
  1792.  
  1793.         scan:CondenseAndSort ();
  1794.     end
  1795.  
  1796.     gCurrentPane.UINeedsUpdate = true;
  1797. end
  1798.  
  1799.  
  1800. -----------------------------------------
  1801.  
  1802. function auctionator_ChatEdit_InsertLink(text)
  1803.  
  1804.     if (text and AuctionFrame:IsShown() and IsShiftKeyDown() and Atr_IsTabSelected(BUY_TAB)) then
  1805.         local item;
  1806.         if ( strfind(text, "item:", 1, true) ) then
  1807.             item = GetItemInfo(text);
  1808.         end
  1809.         if ( item ) then
  1810.             Atr_SetSearchText (item);
  1811.             Atr_Search_Onclick ();
  1812.             return true;
  1813.         end
  1814.     end
  1815.  
  1816.     return auctionator_orig_ChatEdit_InsertLink(text);
  1817.  
  1818. end
  1819.  
  1820. -----------------------------------------
  1821.  
  1822. function auctionator_ChatFrame_OnEvent(self, event, ...)
  1823.  
  1824.     local msg = select (1, ...);
  1825.  
  1826.     if (event == "CHAT_MSG_SYSTEM") then
  1827.         if (msg == ERR_AUCTION_STARTED) then        -- absorb the Auction Created message
  1828.             return;
  1829.         end
  1830.         if (msg == ERR_AUCTION_REMOVED) then        -- absorb the Auction Cancelled message
  1831.             return;
  1832.         end
  1833.     end
  1834.  
  1835.     return auctionator_orig_ChatFrame_OnEvent (self, event, ...);
  1836.  
  1837. end
  1838.  
  1839.  
  1840.  
  1841.  
  1842. -----------------------------------------
  1843.  
  1844. function auctionator_CanShowRightUIPanel(frame)
  1845.  
  1846.     if (zc.StringSame (frame:GetName(), "TradeSkillFrame")) then
  1847.         return 1;
  1848.     end;
  1849.  
  1850.     return auctionator_orig_CanShowRightUIPanel(frame);
  1851.  
  1852. end
  1853.  
  1854. -----------------------------------------
  1855.  
  1856. function Atr_AddMainPanel ()
  1857.  
  1858.     local frame = CreateFrame("FRAME", "Atr_Main_Panel", AuctionFrame, "Atr_Sell_Template");
  1859.     frame:Hide();
  1860.  
  1861.     UIDropDownMenu_SetWidth (Atr_Duration, 95);
  1862.  
  1863. end
  1864.  
  1865. -----------------------------------------
  1866.  
  1867. function Atr_AddSellTab (tabtext, whichTab)
  1868.  
  1869.     local n = AuctionFrame.numTabs+1;
  1870.  
  1871.     local framename = "AuctionFrameTab"..n;
  1872.  
  1873.     local frame = CreateFrame("Button", framename, AuctionFrame, "AuctionTabTemplate");
  1874.  
  1875.     frame:SetID(n);
  1876.     frame:SetText(tabtext);
  1877.  
  1878.     frame:SetNormalFontObject(_G["AtrFontOrange"]);
  1879.  
  1880.     frame.auctionatorTab = whichTab;
  1881.  
  1882.     frame:SetPoint("LEFT", _G["AuctionFrameTab"..n-1], "RIGHT", -8, 0);
  1883.  
  1884.     PanelTemplates_SetNumTabs (AuctionFrame, n);
  1885.     PanelTemplates_EnableTab  (AuctionFrame, n);
  1886.  
  1887.     return AtrPane.create (whichTab);
  1888. end
  1889.  
  1890. -----------------------------------------
  1891.  
  1892. function Atr_HideElems (tt)
  1893.  
  1894.     if (not tt) then
  1895.         return;
  1896.     end
  1897.  
  1898.     for i,x in ipairs(tt) do
  1899.         x:Hide();
  1900.     end
  1901. end
  1902.  
  1903. -----------------------------------------
  1904.  
  1905. function Atr_ShowElems (tt)
  1906.  
  1907.     for i,x in ipairs(tt) do
  1908.         x:Show();
  1909.     end
  1910. end
  1911.  
  1912.  
  1913.  
  1914.  
  1915. -----------------------------------------
  1916.  
  1917. local aoa_count = 0
  1918.  
  1919. function Atr_OnAuctionUpdate (...)
  1920.  
  1921.     local numBatchAuctions, totalAuctions = Atr_GetNumAuctionItems("list");
  1922.  
  1923.     --local name, texture, count;
  1924.     --if (numBatchAuctions > 0) then
  1925.     --  name, texture, count = GetAuctionItemInfo("list", 1);
  1926.     --end
  1927.  
  1928.     --zz (aoa_count, "Atr_OnAuctionUpdate", numBatchAuctions, totalAuctions, name, count, ...);
  1929.     aoa_count = aoa_count + 1
  1930.  
  1931.     if (gAtr_FullScanState == ATR_FS_STARTED) then
  1932.         gAtr_FullScanState = ATR_FS_ANALYZING       -- handle in idle loop to slow down
  1933.         return
  1934.     end
  1935.  
  1936.     if (gAtr_FullScanState == ATR_FS_SLOW_QUERY_SENT) then
  1937.         Atr_FullScanAnalyze()                       -- handle here since it's just one page
  1938.         return
  1939.     end
  1940.  
  1941.  
  1942.  
  1943.     if (not Atr_IsTabSelected()) then
  1944.         Atr_ClearScanCache()        -- if not our tab, we have no idea what happened so must flush all caches
  1945.         return;
  1946.     end;
  1947.  
  1948.     if (Atr_Buy_OnAuctionUpdate()) then
  1949.         return
  1950.     end
  1951.  
  1952.     if (gCurrentPane.activeSearch and gCurrentPane.activeSearch.processing_state == KM_POSTQUERY) then
  1953.  
  1954.         local isDup = gCurrentPane.activeSearch:CheckForDuplicatePage ();
  1955.  
  1956.         if (not isDup) then
  1957.  
  1958.             local done = gCurrentPane.activeSearch:AnalyzeResultsPage();
  1959.  
  1960.             if (done) then
  1961.                 gCurrentPane.activeSearch:Finish();
  1962.                 Atr_OnSearchComplete ();
  1963.             end
  1964.         end
  1965.     end
  1966.  
  1967. end
  1968.  
  1969. -----------------------------------------
  1970.  
  1971. function Atr_OnSearchComplete ()
  1972.  
  1973.     gCurrentPane.sortedHist = nil;
  1974.  
  1975.     Atr_Clear_Owner_Item_Indices();
  1976.  
  1977.     local count = gCurrentPane.activeSearch:NumScans();
  1978.     if (count == 1) then
  1979.         gCurrentPane.activeScan = gCurrentPane.activeSearch:GetFirstScan();
  1980.     end
  1981.  
  1982.     if (Atr_IsModeCreateAuction()) then
  1983.  
  1984.         Atr_SetToShowCurrent();
  1985.  
  1986.         if (#gCurrentPane.activeScan.scanData == 0) then
  1987.             if (gAtr_ScanDB[gCurrentPane.activeScan.itemName]) then
  1988.                 Atr_SetToShowHistory();
  1989.                 Atr_BuildSortedScanHistoryList(gCurrentPane.activeScan.itemName);
  1990.                 gCurrentPane.histIndex = 1;
  1991.             else
  1992.                 local hints = Atr_BuildHints (gCurrentPane.activeScan.itemName, gCurrentPane.activeScan.itemLink);      -- just to get the count
  1993.                 if (#hints > 0) then
  1994.                     Atr_SetToShowHints();
  1995.                     Atr_Build_PostingsList ();
  1996.                     gCurrentPane.histIndex = 1;
  1997.                 end
  1998.             end
  1999.  
  2000.         end
  2001.  
  2002.         if (Atr_IsSelectedTab_Current()) then
  2003.             Atr_FindBestCurrentAuction ();
  2004.         end
  2005.  
  2006.         Atr_UpdateRecommendation(true);
  2007.     else
  2008.         if (Atr_IsModeActiveAuctions()) then
  2009.             Atr_DisplayHlist();
  2010.         end
  2011.  
  2012.         Atr_FindBestCurrentAuction ();
  2013.     end
  2014.  
  2015.     if (Atr_IsModeBuy()) then
  2016.         Atr_Shop_OnFinishScan ();
  2017.     end
  2018.  
  2019.     Atr_CheckingActive_OnSearchComplete();
  2020.  
  2021.     gCurrentPane.UINeedsUpdate = true;
  2022.  
  2023. end
  2024.  
  2025. -----------------------------------------
  2026.  
  2027. function Atr_ClearTop ()
  2028.     Atr_HideElems (recommendElements);
  2029.  
  2030.     if (AuctionatorMessageFrame) then
  2031.         AuctionatorMessageFrame:Hide();
  2032.         AuctionatorMessage2Frame:Hide();
  2033.     end
  2034. end
  2035.  
  2036. -----------------------------------------
  2037.  
  2038. function Atr_ClearList ()
  2039.  
  2040.     Atr_Col1_Heading:Hide();
  2041.     Atr_Col3_Heading:Hide();
  2042.     Atr_Col4_Heading:Hide();
  2043.  
  2044.     Atr_Col1_Heading_Button:Hide();
  2045.     Atr_Col3_Heading_Button:Hide();
  2046.  
  2047.     local line;                         -- 1 through 12 of our window to scroll
  2048.  
  2049.     FauxScrollFrame_Update (AuctionatorScrollFrame, 0, 12, 16);
  2050.  
  2051.     for line = 1,12 do
  2052.         local lineEntry = _G["AuctionatorEntry"..line];
  2053.         lineEntry:Hide();
  2054.     end
  2055.  
  2056. end
  2057.  
  2058. -----------------------------------------
  2059.  
  2060. function Atr_ClearAll ()
  2061.  
  2062.     if (AuctionatorMessageFrame) then   -- just to make sure xml has been loaded
  2063.  
  2064.         Atr_ClearTop();
  2065.         Atr_ClearList();
  2066.     end
  2067. end
  2068.  
  2069. -----------------------------------------
  2070.  
  2071. function Atr_SetMessage (msg)
  2072.     Atr_HideElems (recommendElements);
  2073.  
  2074.     if (gCurrentPane.activeSearch.searchText) then
  2075.  
  2076.         Atr_ShowItemNameAndTexture (gCurrentPane.activeSearch.searchText);
  2077.  
  2078.         AuctionatorMessage2Frame:SetText (msg);
  2079.         AuctionatorMessage2Frame:Show();
  2080.  
  2081.     else
  2082.         AuctionatorMessageFrame:SetText (msg);
  2083.         AuctionatorMessageFrame:Show();
  2084.         AuctionatorMessage2Frame:Hide();
  2085.     end
  2086. end
  2087.  
  2088. -----------------------------------------
  2089.  
  2090. function Atr_ShowItemNameAndTexture(itemName)
  2091.  
  2092.     AuctionatorMessageFrame:Hide();
  2093.     AuctionatorMessage2Frame:Hide();
  2094.  
  2095.     local scn = gCurrentPane.activeScan;
  2096.  
  2097.     local color = "";
  2098.     if (scn and not scn:IsNil()) then
  2099.         color = "|cff"..zc.RGBtoHEX (scn.itemTextColor[1], scn.itemTextColor[2], scn.itemTextColor[3]);
  2100.         itemName = scn.itemName;
  2101.     end
  2102.  
  2103.     Atr_Recommend_Text:Show ()
  2104.     Atr_Recommend_Text:SetText (color..itemName)
  2105.  
  2106.     if (scn and not scn:IsNil()) then
  2107.         Atr_SetTextureButton ("Atr_RecommendItem_Tex", 1, scn.itemLink)
  2108.     end
  2109. end
  2110.  
  2111.  
  2112.  
  2113. -----------------------------------------
  2114.  
  2115. function Atr_SortHistoryData (x, y)
  2116.  
  2117.     return x.when > y.when;
  2118.  
  2119. end
  2120.  
  2121. -----------------------------------------
  2122.  
  2123. function BuildHtag (type, y, m, d)
  2124.  
  2125.     local t = time({year=y, month=m, day=d, hour=0});
  2126.  
  2127.     return tostring (ToTightTime(t))..":"..type;
  2128. end
  2129.  
  2130. -----------------------------------------
  2131.  
  2132. function ParseHtag (tag)
  2133.     local when, type = strsplit(":", tag);
  2134.  
  2135.     if (type == nil) then
  2136.         type = "hx";
  2137.     end
  2138.  
  2139.     when = FromTightTime (tonumber (when));
  2140.  
  2141.     return when, type;
  2142. end
  2143.  
  2144. -----------------------------------------
  2145.  
  2146. function ParseHist (tag, hist)
  2147.  
  2148.     local when, type = ParseHtag(tag);
  2149.  
  2150.     local price, count  = strsplit(":", hist);
  2151.  
  2152.     price = tonumber (price);
  2153.  
  2154.     local stacksize, numauctions;
  2155.  
  2156.     if (type == "hx") then
  2157.         stacksize   = tonumber (count);
  2158.         numauctions = 1;
  2159.     else
  2160.         stacksize = 0;
  2161.         numauctions = tonumber (count);
  2162.     end
  2163.  
  2164.     return when, type, price, stacksize, numauctions;
  2165.  
  2166. end
  2167.  
  2168. -----------------------------------------
  2169.  
  2170. function CalcAbsTimes (when, whent)
  2171.  
  2172.     local absYear   = whent.year - 2000;
  2173.     local absMonth  = (absYear * 12) + whent.month;
  2174.     local absDay    = floor ((when - gTimeZero) / (60*60*24));
  2175.  
  2176.     return absYear, absMonth, absDay;
  2177.  
  2178. end
  2179.  
  2180. -----------------------------------------
  2181.  
  2182. function Atr_Condense_History (itemname)
  2183.  
  2184.     if (AUCTIONATOR_PRICING_HISTORY[itemname] == nil) then
  2185.         return;
  2186.     end
  2187.  
  2188.     local tempHistory = {};
  2189.  
  2190.     local now           = time();
  2191.     local nowt          = date("*t", now);
  2192.  
  2193.     local absNowYear, absNowMonth, absNowDay = CalcAbsTimes (now, nowt);
  2194.  
  2195.     local n = 1;
  2196.     local tag, hist, newtag, stacksize, numauctions;
  2197.     for tag, hist in pairs (AUCTIONATOR_PRICING_HISTORY[itemname]) do
  2198.         if (tag ~= "is") then
  2199.  
  2200.             local when, type, price, stacksize, numauctions = ParseHist (tag, hist);
  2201.  
  2202.             local whnt = date("*t", when);
  2203.  
  2204.             local absYear, absMonth, absDay = CalcAbsTimes (when, whnt);
  2205.  
  2206.             if (absNowYear - absYear >= 3) then
  2207.                 newtag = BuildHtag ("hy", whnt.year, 1, 1);
  2208.             elseif (absNowMonth - absMonth >= 2) then
  2209.                 newtag = BuildHtag ("hm", whnt.year, whnt.month, 1);
  2210.             elseif (absNowDay - absDay >= 2) then
  2211.                 newtag = BuildHtag ("hd", whnt.year, whnt.month, whnt.day);
  2212.             else
  2213.                 newtag = tag;
  2214.             end
  2215.  
  2216.             tempHistory[n] = {};
  2217.             tempHistory[n].price        = price;
  2218.             tempHistory[n].numauctions  = numauctions;
  2219.             tempHistory[n].stacksize    = stacksize;
  2220.             tempHistory[n].when         = when;
  2221.             tempHistory[n].newtag       = newtag;
  2222.             n = n + 1;
  2223.         end
  2224.     end
  2225.  
  2226.     -- clear all the existing history
  2227.  
  2228.     local is = AUCTIONATOR_PRICING_HISTORY[itemname]["is"];
  2229.  
  2230.     AUCTIONATOR_PRICING_HISTORY[itemname] = {};
  2231.     AUCTIONATOR_PRICING_HISTORY[itemname]["is"] = is;
  2232.  
  2233.     -- repopulate the history
  2234.  
  2235.     local x;
  2236.  
  2237.     for x = 1,#tempHistory do
  2238.  
  2239.         local thist     = tempHistory[x];
  2240.         local newtag    = thist.newtag;
  2241.  
  2242.         if (AUCTIONATOR_PRICING_HISTORY[itemname][newtag] == nil) then
  2243.  
  2244.             local when, type = ParseHtag (newtag);
  2245.  
  2246.             local count = thist.numauctions;
  2247.             if (type == "hx") then
  2248.                 count = thist.stacksize;
  2249.             end
  2250.  
  2251.             AUCTIONATOR_PRICING_HISTORY[itemname][newtag] = tostring(thist.price)..":"..tostring(count);
  2252.  
  2253.         else
  2254.  
  2255.             local hist = AUCTIONATOR_PRICING_HISTORY[itemname][newtag];
  2256.  
  2257.             local when, type, price, stacksize, numauctions = ParseHist (newtag, hist);
  2258.  
  2259.             local newNumAuctions = numauctions + thist.numauctions;
  2260.             local newPrice       = ((price * numauctions) + (thist.price * thist.numauctions)) / newNumAuctions;
  2261.  
  2262.             AUCTIONATOR_PRICING_HISTORY[itemname][newtag] = tostring(newPrice)..":"..tostring(newNumAuctions);
  2263.         end
  2264.     end
  2265.  
  2266. end
  2267.  
  2268. -----------------------------------------
  2269.  
  2270. function Atr_Build_PostingsList ()
  2271.  
  2272.     -- Condense the data if needed - only once per session for each item
  2273.  
  2274.     if (gCurrentPane:IsScanNil()) then
  2275.         return;
  2276.     end
  2277.  
  2278.     local itemName = gCurrentPane.activeScan.itemName;
  2279.  
  2280.     if (gCondensedThisSession[itemName] == nil) then
  2281.  
  2282.         gCondensedThisSession[itemName] = true;
  2283.  
  2284.         Atr_Condense_History(itemName);
  2285.     end
  2286.  
  2287.     -- build the sorted history list
  2288.  
  2289.     gCurrentPane.sortedHist = {};
  2290.  
  2291.     -- add any external information
  2292.  
  2293.     local hints = Atr_BuildHints (gCurrentPane.activeScan.itemName, gCurrentPane.activeScan.itemLink);
  2294.  
  2295.     local n;
  2296.     for n = 1, #hints do
  2297.  
  2298.         local entry = {};
  2299.  
  2300.         entry.when          = time();
  2301.         entry.whenText      = hints[n].text;
  2302.         entry.itemPrice     = hints[n].price;
  2303.         entry.yours         = true;     -- so doesn't undercut
  2304.  
  2305.         table.insert (gCurrentPane.sortedHist, entry)
  2306.     end
  2307.  
  2308.     -- now add all the posting history
  2309.  
  2310.     if (AUCTIONATOR_PRICING_HISTORY[itemName]) then
  2311.         local tag, hist;
  2312.         for tag, hist in pairs (AUCTIONATOR_PRICING_HISTORY[itemName]) do
  2313.             if (tag ~= "is") then
  2314.                 local when, type, price = ParseHist (tag, hist);
  2315.                 local entry = {};
  2316.  
  2317.                 entry.itemPrice     = price;
  2318.                 entry.type          = type;
  2319.                 entry.when          = when;
  2320.                 entry.yours         = true;
  2321.                 entry.whenText      = Atr_BuildPostHistText (entry);
  2322.  
  2323.                 table.insert (gCurrentPane.sortedHist, entry)
  2324.             end
  2325.         end
  2326.     end
  2327.  
  2328.     table.sort (gCurrentPane.sortedHist, Atr_SortHistoryData);
  2329.  
  2330.     if (#gCurrentPane.sortedHist > 0) then
  2331.         return gCurrentPane.sortedHist[1].itemPrice;
  2332.     end
  2333.  
  2334. end
  2335.  
  2336. -----------------------------------------
  2337.  
  2338. function Atr_GetMostRecentSale (itemName)
  2339.  
  2340.     local recentPrice;
  2341.     local recentWhen = 0;
  2342.  
  2343.     if (AUCTIONATOR_PRICING_HISTORY and AUCTIONATOR_PRICING_HISTORY[itemName]) then
  2344.         local n = 1;
  2345.         local tag, hist;
  2346.         for tag, hist in pairs (AUCTIONATOR_PRICING_HISTORY[itemName]) do
  2347.             if (tag ~= "is") then
  2348.                 local when, type, price = ParseHist (tag, hist);
  2349.  
  2350.                 if (when > recentWhen) then
  2351.                     recentPrice = price;
  2352.                     recentWhen  = when;
  2353.                 end
  2354.             end
  2355.         end
  2356.     end
  2357.  
  2358.     return recentPrice;
  2359.  
  2360. end
  2361.  
  2362.  
  2363.  
  2364.  
  2365. -----------------------------------------
  2366.  
  2367. function Atr_UpdateRecommendation (updatePrices)
  2368.  
  2369.     if (gCurrentPane == gSellPane and gJustPosted.ItemLink and GetAuctionSellItemInfo() == nil) then
  2370.         return;
  2371.     end
  2372.  
  2373.     local scn = gCurrentPane.activeScan
  2374.     if (scn == nil) then
  2375.         scn = Atr_FindScan (nil)
  2376.     end
  2377.  
  2378.     local basedata;
  2379.  
  2380.     if (Atr_ShowingSearchSummary()) then
  2381.  
  2382.     elseif (Atr_IsSelectedTab_Current()) then
  2383.  
  2384.         if (gCurrentPane:GetProcessingState() ~= KM_NULL_STATE) then
  2385.             return;
  2386.         end
  2387.  
  2388.         if (#scn.sortedData == 0) then
  2389.             Atr_SetMessage (ZT("No current auctions found"));
  2390.             return;
  2391.         end
  2392.  
  2393.         if (not gCurrentPane.currIndex) then
  2394.             if (scn.numMatches == 0) then
  2395.                 Atr_SetMessage (ZT("No current auctions found\n\n(related auctions shown)"));
  2396.             elseif (scn.numMatchesWithBuyout == 0) then
  2397.                 Atr_SetMessage (ZT("No current auctions with buyouts found"));
  2398.             else
  2399.                 Atr_SetMessage ("");
  2400.             end
  2401.             return;
  2402.         end
  2403.  
  2404.         basedata = scn.sortedData[gCurrentPane.currIndex];
  2405.  
  2406.     else
  2407.  
  2408.         basedata = zc.GetArrayElemOrFirst (gCurrentPane.sortedHist, gCurrentPane.histIndex);
  2409.         if (basedata == nil) then
  2410.             Atr_SetMessage (ZT("Auctionator has yet to record any auctions for this item"));
  2411.             return;
  2412.         end
  2413.     end
  2414.  
  2415.     if (Atr_StackSize() == 0) then
  2416.         return;
  2417.     end
  2418.  
  2419.     local new_Item_BuyoutPrice;
  2420.  
  2421.     if (gItemPostingInProgress and gCurrentPane.itemLink == gJustPosted.ItemLink) then  -- handle the unusual case where server is still in the process of creating the last auction
  2422.  
  2423.         new_Item_BuyoutPrice = gJustPosted.BuyoutPrice / gJustPosted.StackSize;
  2424.  
  2425.     elseif (basedata) then          -- the normal case
  2426.  
  2427.         new_Item_BuyoutPrice = basedata.itemPrice;
  2428.  
  2429.         if (not basedata.yours and not basedata.altname) then
  2430.             new_Item_BuyoutPrice = Atr_CalcUndercutPrice (new_Item_BuyoutPrice);
  2431.         end
  2432.     end
  2433.  
  2434.     if (new_Item_BuyoutPrice == nil) then
  2435.         return;
  2436.     end
  2437.  
  2438.     local new_Item_StartPrice = Atr_CalcStartPrice (new_Item_BuyoutPrice);
  2439.  
  2440.     Atr_ShowElems (recommendElements);
  2441.     AuctionatorMessageFrame:Hide();
  2442.     AuctionatorMessage2Frame:Hide();
  2443.  
  2444.     Atr_Recommend_Text:SetText (ZT("Recommended Buyout Price"));
  2445.     Atr_RecommendPerStack_Text:SetText (string.format (ZT("for your stack of %d"), Atr_StackSize()));
  2446.  
  2447.     Atr_SetTextureButton ("Atr_RecommendItem_Tex", Atr_StackSize(), scn.itemLink);
  2448.  
  2449.     MoneyFrame_Update ("Atr_RecommendPerItem_Price",  zc.round(new_Item_BuyoutPrice));
  2450.     MoneyFrame_Update ("Atr_RecommendPerStack_Price", zc.round(new_Item_BuyoutPrice * Atr_StackSize()));
  2451.  
  2452.     if (updatePrices) then
  2453.         MoneyInputFrame_SetCopper (Atr_StackPrice,      new_Item_BuyoutPrice * Atr_StackSize());
  2454.         MoneyInputFrame_SetCopper (Atr_StartingPrice,   new_Item_StartPrice * Atr_StackSize());
  2455.         MoneyInputFrame_SetCopper (Atr_ItemPrice,       new_Item_BuyoutPrice);
  2456.     end
  2457.  
  2458.     local cheapestStack = scn.bestPrices[Atr_StackSize()];
  2459.  
  2460.     Atr_Recommend_Basis_Text:SetTextColor (1,1,1);
  2461.  
  2462.     if (Atr_IsSelectedTab_Hints()) then
  2463.         Atr_Recommend_Basis_Text:SetTextColor (.8,.8,1);
  2464.         Atr_Recommend_Basis_Text:SetText ("("..ZT("based on").." "..basedata.whenText..")");
  2465.     elseif (scn.absoluteBest and basedata.stackSize == scn.absoluteBest.stackSize and basedata.buyoutPrice == scn.absoluteBest.buyoutPrice) then
  2466.         Atr_Recommend_Basis_Text:SetText ("("..ZT("based on cheapest current auction")..")");
  2467.     elseif (cheapestStack and basedata.stackSize == cheapestStack.stackSize and basedata.buyoutPrice == cheapestStack.buyoutPrice) then
  2468.         Atr_Recommend_Basis_Text:SetText ("("..ZT("based on cheapest stack of the same size")..")");
  2469.     else
  2470.         Atr_Recommend_Basis_Text:SetText ("("..ZT("based on selected auction")..")");
  2471.     end
  2472.  
  2473. end
  2474.  
  2475.  
  2476. -----------------------------------------
  2477.  
  2478. function Atr_StackPriceChangedFunc ()
  2479.  
  2480.     local new_Stack_BuyoutPrice = MoneyInputFrame_GetCopper (Atr_StackPrice);
  2481.     local new_Item_BuyoutPrice  = math.floor (new_Stack_BuyoutPrice / Atr_StackSize());
  2482.     local new_Item_StartPrice   = Atr_CalcStartPrice (new_Item_BuyoutPrice);
  2483.  
  2484.     local calculatedStackPrice = MoneyInputFrame_GetCopper(Atr_ItemPrice) * Atr_StackSize();
  2485.  
  2486.     -- check to prevent looping
  2487.  
  2488.     if (calculatedStackPrice ~= new_Stack_BuyoutPrice) then
  2489.         MoneyInputFrame_SetCopper (Atr_ItemPrice,       new_Item_BuyoutPrice);
  2490.         MoneyInputFrame_SetCopper (Atr_StartingPrice,   new_Item_StartPrice * Atr_StackSize());
  2491.     end
  2492.  
  2493. end
  2494.  
  2495. -----------------------------------------
  2496.  
  2497. function Atr_ItemPriceChangedFunc ()
  2498.  
  2499.     local new_Item_BuyoutPrice = MoneyInputFrame_GetCopper (Atr_ItemPrice);
  2500.     local new_Item_StartPrice  = Atr_CalcStartPrice (new_Item_BuyoutPrice);
  2501.  
  2502.     local calculatedItemPrice = math.floor (MoneyInputFrame_GetCopper (Atr_StackPrice) / Atr_StackSize());
  2503.  
  2504.     -- check to prevent looping
  2505.  
  2506.     if (calculatedItemPrice ~= new_Item_BuyoutPrice) then
  2507.         MoneyInputFrame_SetCopper (Atr_StackPrice,      new_Item_BuyoutPrice * Atr_StackSize());
  2508.         MoneyInputFrame_SetCopper (Atr_StartingPrice,   new_Item_StartPrice  * Atr_StackSize());
  2509.     end
  2510.  
  2511. end
  2512.  
  2513. -----------------------------------------
  2514.  
  2515. function Atr_StackSizeChangedFunc ()
  2516.  
  2517.     local item_BuyoutPrice      = MoneyInputFrame_GetCopper (Atr_ItemPrice);
  2518.     local new_Item_StartPrice   = Atr_CalcStartPrice (item_BuyoutPrice);
  2519.  
  2520.     MoneyInputFrame_SetCopper (Atr_StackPrice,      item_BuyoutPrice * Atr_StackSize());
  2521.     MoneyInputFrame_SetCopper (Atr_StartingPrice,   new_Item_StartPrice  * Atr_StackSize());
  2522.  
  2523. --  Atr_MemorizeButton:Show();
  2524.  
  2525.     gSellPane.UINeedsUpdate = true;
  2526.  
  2527. end
  2528.  
  2529. -----------------------------------------
  2530.  
  2531. function Atr_NumAuctionsChangedFunc (x)
  2532.  
  2533. --  Atr_MemorizeButton:Show();
  2534.  
  2535.     gSellPane.UINeedsUpdate = true;
  2536. end
  2537.  
  2538.  
  2539. -----------------------------------------
  2540.  
  2541. function Atr_SetTextureButton (elementName, count, itemlink)
  2542.  
  2543.     local texture = GetItemIcon (itemlink)
  2544.  
  2545.     if (texture == nil) then
  2546.         texture = gBattlePetIconCache[itemlink];
  2547.     end
  2548.  
  2549.     Atr_SetTextureButtonByTexture (elementName, count, texture)
  2550.  
  2551. end
  2552.  
  2553. -----------------------------------------
  2554.  
  2555. function Atr_SetTextureButtonByTexture (elementName, count, texture)
  2556.  
  2557.     local textureElement = _G[elementName]
  2558.  
  2559.     if (texture) then
  2560.         textureElement:Show()
  2561.         textureElement:SetNormalTexture (texture)
  2562.         Atr_SetTextureButtonCount (elementName, count)
  2563.     else
  2564.         Atr_SetTextureButtonCount (elementName, 0)
  2565.     end
  2566.  
  2567. end
  2568.  
  2569.  
  2570. -----------------------------------------
  2571.  
  2572. function Atr_SetTextureButtonCount (elementName, count)
  2573.  
  2574.     local countElement   = _G[elementName.."Count"];
  2575.  
  2576.     if (count > 1) then
  2577.         countElement:SetText (count);
  2578.         countElement:Show();
  2579.     else
  2580.         countElement:Hide();
  2581.     end
  2582.  
  2583. end
  2584.  
  2585. -----------------------------------------
  2586.  
  2587. function Atr_ShowRecTooltip ()
  2588.  
  2589.     local link = gCurrentPane.activeScan.itemLink;
  2590.     local num  = Atr_StackSize();
  2591.  
  2592.     if (not link) then
  2593.         link = gJustPosted.ItemLink;
  2594.         num  = gJustPosted.StackSize;
  2595.     end
  2596.  
  2597.     if (link) then
  2598.         if (num < 1) then num = 1; end;
  2599.  
  2600.         if (zc.IsBattlePetLink (link)) then
  2601.             local speciesID, level, breedQuality, maxHealth, power, speed, battlePetID, name = zc.ParseBattlePetLink(link)
  2602.  
  2603.             BattlePetToolTip_Show(speciesID, level, breedQuality, maxHealth, power, speed, name)
  2604.  
  2605.             BattlePetTooltip:ClearAllPoints();
  2606.             BattlePetTooltip:SetPoint("BOTTOMLEFT", Atr_RecommendItem_Tex, "BOTTOMRIGHT", 10, 0)
  2607.  
  2608.         else
  2609.             GameTooltip:SetOwner(Atr_RecommendItem_Tex, "ANCHOR_RIGHT");
  2610.             GameTooltip:SetHyperlink (link, num);
  2611.             gCurrentPane.tooltipvisible = true;
  2612.         end
  2613.     end
  2614.  
  2615. end
  2616.  
  2617. -----------------------------------------
  2618.  
  2619. function Atr_HideRecTooltip ()
  2620.  
  2621.     gCurrentPane.tooltipvisible = nil;
  2622.     GameTooltip:Hide();
  2623.     BattlePetTooltip:Hide();
  2624.  
  2625. end
  2626.  
  2627. -----------------------------------------
  2628.  
  2629. function Atr_ClickRecItemTexture ()
  2630.  
  2631.     if ( IsModifiedClick() and gCurrentPane and gCurrentPane.activeScan and gCurrentPane.activeScan.itemLink) then
  2632.         if (IsModifiedClick ("CHATLINK")) then
  2633.             if (auctionator_orig_ChatEdit_InsertLink) then
  2634.                 auctionator_orig_ChatEdit_InsertLink (gCurrentPane.activeScan.itemLink)
  2635.             end
  2636.         end
  2637.     end
  2638. end
  2639.  
  2640.  
  2641. -----------------------------------------
  2642.  
  2643. function Atr_OnAuctionHouseShow()
  2644.  
  2645.     gOpenAllBags = AUCTIONATOR_OPEN_ALL_BAGS;
  2646.  
  2647.     if (AUCTIONATOR_DEFTAB == 1) then       Atr_SelectPane (SELL_TAB);  end
  2648.     if (AUCTIONATOR_DEFTAB == 2) then       Atr_SelectPane (BUY_TAB);   end
  2649.     if (AUCTIONATOR_DEFTAB == 3) then       Atr_SelectPane (MORE_TAB);  end
  2650.  
  2651.     Atr_ResetDuration();
  2652.  
  2653.     gJustPosted.ItemName = nil;
  2654.     gSellPane:ClearSearch();
  2655.  
  2656.     if (gCurrentPane) then
  2657.         gCurrentPane.UINeedsUpdate = true;
  2658.     end
  2659. end
  2660.  
  2661. -----------------------------------------
  2662.  
  2663. function Atr_OnAuctionHouseClosed()
  2664.  
  2665.     Atr_HideAllDialogs();
  2666.  
  2667.     Atr_CheckingActive_Finish ();
  2668.  
  2669.     Atr_ClearScanCache();
  2670.  
  2671.     gSellPane:ClearSearch();
  2672.     gShopPane:ClearSearch();
  2673.     gMorePane:ClearSearch();
  2674.  
  2675. end
  2676.  
  2677. -----------------------------------------
  2678.  
  2679. function Atr_HideAllDialogs()
  2680.  
  2681.     Atr_CheckActives_Frame:Hide();
  2682.     Atr_Error_Frame:Hide();
  2683.     Atr_Buy_Confirm_Frame:Hide();
  2684.     Atr_FullScanFrame:Hide();
  2685.     Atr_Adv_Search_Dialog:Hide();
  2686.     Atr_Mask:Hide();
  2687.     Atr_SList_Conflict_Frame:Hide()
  2688.     Atr_ShpList_Edit_Frame:Hide()
  2689. end
  2690.  
  2691.  
  2692.  
  2693. -----------------------------------------
  2694.  
  2695. local function Bump_MaxButton_Hack()
  2696.  
  2697.     if (NXInit) then        -- hack seems to interfere with Carbonite
  2698. --      zc.md ("Carbonite detected");
  2699.         return;
  2700.     end
  2701.  
  2702.     if ( UIDROPDOWNMENU_MAXBUTTONS < 29 ) then
  2703.  
  2704.         local toggle;
  2705.         if ( not WorldMapFrame:IsVisible() ) then
  2706.             ToggleFrame(WorldMapFrame);
  2707.             toggle = true;
  2708.         end
  2709.         SetMapZoom(2);
  2710.         if ( toggle ) then
  2711.             ToggleFrame(WorldMapFrame);
  2712.         end
  2713.     end
  2714.  
  2715. end
  2716.  
  2717. -----------------------------------------
  2718.  
  2719. function Atr_OnUpdate(self, elapsed)
  2720.  
  2721.     -- update the global "precision" timer
  2722.  
  2723.     gAtr_ptime = gAtr_ptime and gAtr_ptime + elapsed or 0;
  2724.  
  2725.  
  2726.     -- check deferred call queue
  2727.  
  2728.     if (zc.periodic (self, "dcq_lastUpdate", 0.05, elapsed)) then
  2729.         zc.CheckDeferredCall();
  2730.     end
  2731.  
  2732.     -- make sure all dusts and essences are in memory
  2733.  
  2734.     if (gAtr_dustCacheIndex > 0) then
  2735.         Atr_GetNextDustIntoCache();
  2736.     end
  2737.  
  2738.     -- the core Idle routine
  2739.  
  2740.     if (zc.periodic (self, "idle_lastUpdate", 0.2, elapsed)) then
  2741.         Atr_Idle (self, elapsed);
  2742.     end
  2743.  
  2744.  
  2745. end
  2746.  
  2747.  
  2748. -----------------------------------------
  2749. local verCheckMsgState = 0;
  2750. -----------------------------------------
  2751.  
  2752. function Atr_Idle(self, elapsed)
  2753.  
  2754.     if (gCurrentPane and gCurrentPane.tooltipvisible) then
  2755.         Atr_ShowRecTooltip();
  2756.     end
  2757.  
  2758.     if (Atr_FullScanFrameIdle == nil) then
  2759.         Atr_Error_Display ("Looks like you installed Auctionator\n without quitting out of WoW.\n\nPlease quit and restart\nWoW to complete the install.")
  2760.     else
  2761.         local handled = Atr_FullScanFrameIdle()
  2762.         if (handled) then
  2763.             return
  2764.         end
  2765.     end
  2766.  
  2767.     if (verCheckMsgState == 0) then
  2768.         verCheckMsgState = time();
  2769.     end
  2770.  
  2771.     if (verCheckMsgState > 1 and time() - verCheckMsgState > 5) then    -- wait 5 seconds
  2772.         verCheckMsgState = 1;
  2773.  
  2774.         local guildname = GetGuildInfo ("player");
  2775.         if (guildname) then
  2776.             Atr_SendAddon_VREQ ("GUILD");
  2777.         end
  2778.  
  2779.     end
  2780.  
  2781.     Atr_Update_ShareRequest()
  2782.  
  2783.     if (not Atr_IsTabSelected() or AuctionatorMessageFrame == nil) then
  2784.         return;
  2785.     end
  2786.  
  2787.     if (gHentryTryAgain) then
  2788.         Atr_HEntryOnClick();
  2789.         return;
  2790.     end
  2791.  
  2792.     if (gCurrentPane.activeSearch and gCurrentPane.activeSearch.processing_state == KM_PREQUERY) then       ------- check whether to send a new auction query to get the next page -------
  2793.         gCurrentPane.activeSearch:Continue();
  2794.     end
  2795.  
  2796.     Atr_UpdateUI ();
  2797.  
  2798.     Atr_CheckingActiveIdle();
  2799.  
  2800.     Atr_Buy_Idle();
  2801.  
  2802.     if (gHideAPFrameCheck == nil) then  -- for the addon 'Auction Profit' (flags for efficiency so we only check one time)
  2803.         gHideAPFrameCheck = true;
  2804.         if (AP_Bid_MoneyFrame) then
  2805.             AP_Bid_MoneyFrame:Hide();
  2806.             AP_Buy_MoneyFrame:Hide();
  2807.         end
  2808.     end
  2809. end
  2810.  
  2811. -----------------------------------------
  2812.  
  2813. local gPrevSellItemLink;
  2814.  
  2815. -----------------------------------------
  2816.  
  2817. function Atr_OnNewAuctionUpdate()
  2818.  
  2819.     if (not gAtr_ClickAuctionSell) then
  2820.         gPrevSellItemLink = nil;
  2821.         return;
  2822.     end
  2823.  
  2824.     gAtr_ClickAuctionSell = false;
  2825.  
  2826.     local auctionItemName, auctionCount, auctionLink = Atr_GetSellItemInfo();
  2827.  
  2828.     if (gPrevSellItemLink ~= auctionLink) then
  2829.  
  2830.         gPrevSellItemLink = auctionLink;
  2831.  
  2832.         if (auctionLink) then
  2833.             gJustPosted.ItemName = nil;
  2834.             Atr_ClearList();        -- better UE
  2835.             Atr_SetToShowCurrent();
  2836.         end
  2837.  
  2838.         MoneyInputFrame_SetCopper (Atr_StackPrice, 0);
  2839.         MoneyInputFrame_SetCopper (Atr_StartingPrice,  0);
  2840.         Atr_ResetDuration();
  2841.  
  2842.         if (gJustPosted.ItemName == nil) then
  2843.             local IDstring = zc.ItemIDStrfromLink (auctionLink)
  2844.  
  2845.             local cacheHit = gSellPane:DoSearch (auctionItemName, IDstring, auctionLink, 20);
  2846.  
  2847.             gSellPane.totalItems    = Atr_GetNumItemInBags (auctionLink);
  2848.             gSellPane.fullStackSize = auctionLink and (select (8, GetItemInfo (auctionLink))) or 0;
  2849.  
  2850.             if (zc.IsBattlePetLink (auctionLink)) then    -- multi sell doesn't work with Battle Pets.  Even in Blizzard UI
  2851.                 gSellPane.totalItems = 1;
  2852.                 gSellPane.fullStackSize = 1;
  2853.             end
  2854.  
  2855.         --zz (auctionItemName, IDstring, auctionLink, "totalItems ", gSellPane.totalItems)
  2856.  
  2857.             local prefNumStacks, prefStackSize = Atr_GetSellStacking (auctionLink, auctionCount, gSellPane.totalItems);
  2858.  
  2859.             if (time() - gAutoSingleton < 5) then
  2860.                 Atr_SetInitialStacking (1, 1);
  2861.             else
  2862.                 Atr_SetInitialStacking (prefNumStacks, prefStackSize);
  2863.             end
  2864.  
  2865.             if (cacheHit) then
  2866.                 Atr_OnSearchComplete ();
  2867.             end
  2868.  
  2869. --  zz (auctionItemName, auctionCount, auctionLink, gPrevSellItemLink);
  2870.  
  2871.             Atr_SetTextureButton ("Atr_SellControls_Tex", Atr_StackSize(), auctionLink);
  2872.             Atr_SellControls_TexName:SetText (auctionItemName);
  2873.         else
  2874.             Atr_SetTextureButton ("Atr_SellControls_Tex", 0, nil);
  2875.             Atr_SellControls_TexName:SetText ("");
  2876.         end
  2877.  
  2878.     elseif (Atr_StackSize() ~= auctionCount) then
  2879.  
  2880.         local prefNumStacks, prefStackSize = Atr_GetSellStacking (auctionLink, auctionCount, gSellPane.totalItems);
  2881.  
  2882.         Atr_SetInitialStacking (prefNumStacks, prefStackSize);
  2883.  
  2884.         Atr_SetTextureButton ("Atr_SellControls_Tex", Atr_StackSize(), auctionLink);
  2885.  
  2886.         Atr_FindBestCurrentAuction();
  2887.         Atr_ResetDuration();
  2888.     end
  2889.  
  2890.     gSellPane.UINeedsUpdate = true;
  2891.  
  2892. end
  2893.  
  2894. ---------------------------------------------------------
  2895.  
  2896. function Atr_UpdateUI ()
  2897.  
  2898.     local needsUpdate = gCurrentPane.UINeedsUpdate;
  2899.  
  2900.     if (gCurrentPane.UINeedsUpdate) then
  2901.  
  2902.         gCurrentPane.UINeedsUpdate = false;
  2903.  
  2904.         if (Atr_ShowingSearchSummary()) then
  2905.             Atr_ShowSearchSummary();
  2906.         elseif (Atr_IsSelectedTab_Current()) then
  2907.             Atr_ShowCurrentAuctions();
  2908.         elseif (Atr_IsSelectedTab_History()) then
  2909.             Atr_ShowHistory();
  2910.         else
  2911.             Atr_ShowOldPostings();
  2912.         end
  2913.  
  2914.         Atr_SetMessage ("");
  2915.         local scn = gCurrentPane.activeScan;
  2916.  
  2917.         if (scn == nil or scn:IsNil()) then
  2918.             Atr_ListTabs:Hide();
  2919.         else
  2920.             Atr_ListTabs:Show();
  2921.         end
  2922.  
  2923.         if (Atr_IsModeCreateAuction()) then
  2924.  
  2925.             Atr_UpdateRecommendation (false);
  2926.         else
  2927.             Atr_HideElems (recommendElements);
  2928.  
  2929.             if (scn == nil or scn:IsNil()) then
  2930.                 Atr_ShowItemNameAndTexture (gCurrentPane.activeSearch.searchText);
  2931.             else
  2932.                 Atr_ShowItemNameAndTexture (gCurrentPane.activeScan.itemName);
  2933.             end
  2934.  
  2935.             if (Atr_IsModeBuy()) then
  2936.  
  2937.                 if (gCurrentPane.activeSearch.searchText == "") then
  2938.                     Atr_SetMessage (ZT("Select an item from the list on the left\n or type a search term above to start a scan."));
  2939.                 end
  2940.             end
  2941.  
  2942.         end
  2943.  
  2944.  
  2945.         if (Atr_IsTabSelected(BUY_TAB)) then
  2946.             Atr_Shop_UpdateUI();
  2947.         end
  2948.  
  2949.     end
  2950.  
  2951.     -- update the hlist if needed
  2952.  
  2953.     if (gHlistNeedsUpdate and Atr_IsModeActiveAuctions()) then
  2954.         gHlistNeedsUpdate = false;
  2955.         Atr_DisplayHlist();
  2956.     end
  2957.  
  2958.     if (Atr_IsTabSelected(SELL_TAB)) then
  2959.         Atr_UpdateUI_SellPane (needsUpdate);
  2960.     end
  2961.  
  2962. end
  2963.  
  2964. ---------------------------------------------------------
  2965.  
  2966. function Atr_UpdateUI_SellPane (needsUpdate)
  2967.  
  2968.     local auctionItemName, auctionTexture = GetAuctionSellItemInfo();
  2969.  
  2970.     if (needsUpdate) then
  2971.  
  2972.         if (gCurrentPane.activeSearch and gCurrentPane.activeSearch.processing_state ~= KM_NULL_STATE) then
  2973.             Atr_CreateAuctionButton:Disable();
  2974.             Atr_FullScanButton:Disable();
  2975.             Auctionator1Button:Disable();
  2976.             MoneyInputFrame_SetCopper (Atr_StartingPrice,  0);
  2977.             return;
  2978.         else
  2979.             Atr_FullScanButton:Enable();
  2980.             Auctionator1Button:Enable();
  2981.  
  2982.  
  2983.             if (Atr_Batch_Stacksize.oldStackSize ~= Atr_StackSize()) then
  2984.                 Atr_Batch_Stacksize.oldStackSize = Atr_StackSize();
  2985.                 local itemPrice = MoneyInputFrame_GetCopper(Atr_ItemPrice);
  2986.                 MoneyInputFrame_SetCopper (Atr_StackPrice,  itemPrice * Atr_StackSize());
  2987.             end
  2988.  
  2989.             Atr_StartingPriceDiscountText:SetText (ZT("Starting Price Discount")..":  "..AUCTIONATOR_SAVEDVARS.STARTING_DISCOUNT.."%");
  2990.  
  2991.             if (Atr_Batch_NumAuctions:GetNumber() < 2) then
  2992.                 Atr_Batch_Stacksize_Text:SetText (ZT("stack of"));
  2993.                 Atr_CreateAuctionButton:SetText (ZT("Create Auction"));
  2994.             else
  2995.                 Atr_Batch_Stacksize_Text:SetText (ZT("stacks of"));
  2996.                 Atr_CreateAuctionButton:SetText (string.format (ZT("Create %d Auctions"), Atr_Batch_NumAuctions:GetNumber()));
  2997.             end
  2998.  
  2999.             if (Atr_StackSize() > 1) then
  3000.                 Atr_StackPriceText:SetText (ZT("Buyout Price").." |cff55ddffx"..Atr_StackSize().."|r");
  3001.                 Atr_ItemPriceText:SetText (ZT("Per Item"));
  3002.                 Atr_ItemPriceText:Show();
  3003.                 Atr_ItemPrice:Show();
  3004.             else
  3005.                 Atr_StackPriceText:SetText (ZT("Buyout Price"));
  3006.                 Atr_ItemPriceText:Hide();
  3007.                 Atr_ItemPrice:Hide();
  3008.             end
  3009.  
  3010.             Atr_SetTextureButtonByTexture ("Atr_SellControls_Tex", Atr_StackSize(), auctionTexture);
  3011.  
  3012.  
  3013.             local maxAuctions = 0;
  3014.             if (Atr_StackSize() > 0) then
  3015.                 maxAuctions = math.floor (gCurrentPane.totalItems / Atr_StackSize());
  3016.             end
  3017.  
  3018.             Atr_Batch_MaxAuctions_Text:SetText (ZT("max")..": "..maxAuctions);
  3019.             Atr_Batch_MaxStacksize_Text:SetText (ZT("max")..": "..gCurrentPane.fullStackSize);
  3020.  
  3021.             Atr_SetDepositText();
  3022.         end
  3023.  
  3024.         if (gJustPosted.ItemName ~= nil) then
  3025.  
  3026.             Atr_Recommend_Text:SetText (string.format (ZT("Auction created for %s"), gJustPosted.ItemName));
  3027.             MoneyFrame_Update ("Atr_RecommendPerStack_Price", gJustPosted.BuyoutPrice);
  3028.             Atr_SetTextureButton ("Atr_RecommendItem_Tex", gJustPosted.StackSize, gJustPosted.ItemLink);
  3029.  
  3030.             gCurrentPane.currIndex = gCurrentPane.activeScan:FindInSortedData (gJustPosted.StackSize, gJustPosted.BuyoutPrice);
  3031.  
  3032.             if (Atr_IsSelectedTab_Current()) then
  3033.                 Atr_HighlightEntry (gCurrentPane.currIndex);        -- highlight the newly created auction(s)
  3034.             else
  3035.                 Atr_HighlightEntry (gCurrentPane.histIndex);
  3036.             end
  3037.  
  3038.         elseif (gCurrentPane:IsScanNil()) then
  3039.             Atr_SetMessage (ZT("Drag an item you want to sell to this area."));
  3040.         end
  3041.     end
  3042.  
  3043.     -- stuff we should do every time (not just when needsUpdate is true)
  3044.  
  3045.     local start     = MoneyInputFrame_GetCopper(Atr_StartingPrice);
  3046.     local buyout    = MoneyInputFrame_GetCopper(Atr_StackPrice);
  3047.  
  3048.     local pricesOK  = (start > 0 and (start <= buyout or buyout == 0) and (auctionItemName ~= nil));
  3049.  
  3050.     local numToSell = Atr_Batch_NumAuctions:GetNumber() * Atr_Batch_Stacksize:GetNumber();
  3051.  
  3052.     zc.EnableDisable (Atr_CreateAuctionButton,  pricesOK and (numToSell <= gCurrentPane.totalItems));
  3053.  
  3054. end
  3055.  
  3056. -----------------------------------------
  3057.  
  3058. function Atr_SetDepositText()
  3059.  
  3060.     _, auctionCount = Atr_GetSellItemInfo();
  3061.  
  3062.     if (auctionCount > 0) then
  3063.         local duration = UIDropDownMenu_GetSelectedValue(Atr_Duration);
  3064.  
  3065.         local deposit1 = CalculateAuctionDeposit (duration) / auctionCount;
  3066.         local numAuctionString = "";
  3067.         if (Atr_Batch_NumAuctions:GetNumber() > 1) then
  3068.             numAuctionString = "  |cffff55ff x"..Atr_Batch_NumAuctions:GetNumber();
  3069.         end
  3070.  
  3071.         Atr_Deposit_Text:SetText (ZT("Deposit")..":    "..zc.priceToMoneyString(deposit1 * Atr_StackSize(), true)..numAuctionString);
  3072.     else
  3073.         Atr_Deposit_Text:SetText ("");
  3074.     end
  3075. end
  3076.  
  3077.  
  3078. -----------------------------------------
  3079.  
  3080. function Atr_BuildActiveAuctions ()
  3081.  
  3082.     gActiveAuctions = {};
  3083.  
  3084.     local i = 1;
  3085.     while (true) do
  3086.         local name, _, count = GetAuctionItemInfo ("owner", i);
  3087.         if (name == nil) then
  3088.             break;
  3089.         end
  3090.  
  3091.         if (count > 0) then     -- count is 0 for sold items
  3092.  
  3093.             local link      = GetAuctionItemLink ("owner", i);
  3094.             local IDstring  = zc.ItemIDStrfromLink (link);
  3095.  
  3096.             if (gActiveAuctions[IDstring] == nil) then
  3097.                 gActiveAuctions[IDstring] = { link=link, name=name, count=1 }
  3098.             else
  3099.                 gActiveAuctions[IDstring].count = gActiveAuctions[IDstring].count + 1;
  3100.             end
  3101.         end
  3102.  
  3103.         i = i + 1;
  3104.     end
  3105. end
  3106.  
  3107. -----------------------------------------
  3108.  
  3109. function Atr_GetUCIcon (itemLink)
  3110.  
  3111.     local icon = "|TInterface\\BUTTONS\\\UI-PassiveHighlight:18:18:0:0|t "
  3112.  
  3113.     local undercutFound = false;
  3114.  
  3115.     local IDstring = zc.ItemIDStrfromLink (itemLink);
  3116.     local scan = Atr_FindScan (IDstring);
  3117.     if (scan and scan.absoluteBest and scan.whenScanned ~= 0 and scan.yourBestPrice and scan.yourWorstPrice) then
  3118.  
  3119.         local absBestPrice = scan.absoluteBest.itemPrice;
  3120.  
  3121.         if (scan.yourBestPrice <= absBestPrice and scan.yourWorstPrice > absBestPrice) then
  3122.             icon = "|TInterface\\AddOns\\Auctionator\\Images\\CrossAndCheck:18:18:0:0|t "
  3123.             undercutFound = true;
  3124.         elseif (scan.yourBestPrice <= absBestPrice) then
  3125.             icon = "|TInterface\\RAIDFRAME\\\ReadyCheck-Ready:18:18:0:0|t "
  3126.         else
  3127.             icon = "|TInterface\\RAIDFRAME\\\ReadyCheck-NotReady:18:18:0:0|t "
  3128.             undercutFound = true;
  3129.         end
  3130.     end
  3131.  
  3132.     if (gAtr_CheckingActive_State ~= ATR_CACT_NULL and undercutFound) then
  3133.         gAtr_CheckingActive_NumUndercuts = gAtr_CheckingActive_NumUndercuts + 1;
  3134.     end
  3135.  
  3136.     return icon;
  3137.  
  3138. end
  3139.  
  3140. -----------------------------------------
  3141.  
  3142. function Atr_DisplayHlist ()
  3143.  
  3144.     if (Atr_IsTabSelected (BUY_TAB)) then       -- done this way because OnScrollFrame always calls Atr_DisplayHlist
  3145.         Atr_DisplaySlist();
  3146.         return;
  3147.     end
  3148.  
  3149.     Atr_BuildGlobalHistoryList ();
  3150.  
  3151.     local numrows = #gHistoryItemList;
  3152.  
  3153.     local line;                         -- 1 through NN of our window to scroll
  3154.     local dataOffset;                   -- an index into our data calculated from the scroll offset
  3155.  
  3156.     FauxScrollFrame_Update (Atr_Hlist_ScrollFrame, numrows, ITEM_HIST_NUM_LINES, 16);
  3157.  
  3158.     for line = 1,ITEM_HIST_NUM_LINES do
  3159.  
  3160.         gCurrentPane.hlistScrollOffset = FauxScrollFrame_GetOffset (Atr_Hlist_ScrollFrame);
  3161.  
  3162.         dataOffset = line + gCurrentPane.hlistScrollOffset;
  3163.  
  3164.         local lineEntry = _G["AuctionatorHEntry"..line];
  3165.  
  3166.         lineEntry:SetID(dataOffset);
  3167.  
  3168.         if (dataOffset <= numrows and gHistoryItemList[dataOffset]) then
  3169.  
  3170.             local lineEntry_text = _G["AuctionatorHEntry"..line.."_EntryText"];
  3171.  
  3172.             local iName = gHistoryItemList[dataOffset].name;
  3173.             local iLink = gHistoryItemList[dataOffset].link;
  3174.  
  3175.             local icon = "";
  3176.  
  3177.             if (not doFull) then
  3178.                 icon = Atr_GetUCIcon (iLink);
  3179.             end
  3180.  
  3181.             lineEntry_text:SetText  (icon..Atr_AbbrevItemName (iName));
  3182.  
  3183.             local IDstring = zc.ItemIDStrfromLink (iLink)
  3184.  
  3185.             if (IDstring and IDstring == gCurrentPane.activeSearch.IDstring) then
  3186.                 lineEntry:SetButtonState ("PUSHED", true);
  3187.             else
  3188.                 lineEntry:SetButtonState ("NORMAL", false);
  3189.             end
  3190.  
  3191.             lineEntry:Show();
  3192.         else
  3193.             lineEntry:Hide();
  3194.         end
  3195.     end
  3196.  
  3197.  
  3198. end
  3199.  
  3200. -----------------------------------------
  3201.  
  3202. function Atr_ClearHlist ()
  3203.     local line;
  3204.     for line = 1,ITEM_HIST_NUM_LINES do
  3205.         local lineEntry = _G["AuctionatorHEntry"..line];
  3206.         lineEntry:Hide();
  3207.  
  3208.         local lineEntry_text = _G["AuctionatorHEntry"..line.."_EntryText"];
  3209.         lineEntry_text:SetText      ("");
  3210.         lineEntry_text:SetTextColor (.7,.7,.7);
  3211.     end
  3212.  
  3213. end
  3214.  
  3215. -----------------------------------------
  3216.  
  3217. function Atr_HEntryOnClick(self)
  3218.  
  3219.     Atr_SetToShowCurrent();
  3220.  
  3221.     if (gCurrentPane == gShopPane) then
  3222.         Atr_SEntryOnClick(self);
  3223.         return;
  3224.     end
  3225.  
  3226.     local line = self;
  3227.  
  3228.     if (gHentryTryAgain) then
  3229.         line = gHentryTryAgain;
  3230.         gHentryTryAgain = nil;
  3231.     end
  3232.  
  3233.     local _, itemLink;
  3234.     local IDstring;
  3235.     local entryIndex = line:GetID();
  3236.  
  3237.     itemName = gHistoryItemList[entryIndex].name;
  3238.     itemLink = gHistoryItemList[entryIndex].link;
  3239.  
  3240.     if (IsAltKeyDown() and Atr_IsModeActiveAuctions()) then
  3241.         Atr_Cancel_Undercuts_OnClick (itemName)
  3242.         return;
  3243.     end
  3244.  
  3245. --[[    This was only used when the "All Item" list was supported
  3246.     if (itemLink == nil and AUCTIONATOR_PRICING_HISTORY[itemName]) then
  3247.         local itemId, suffixId, uniqueId = strsplit(":", AUCTIONATOR_PRICING_HISTORY[itemName]["is"])
  3248.  
  3249.         local itemId    = tonumber(itemId);
  3250.  
  3251.         if (suffixId == nil) then   suffixId = 0;
  3252.         else                        suffixId = tonumber(suffixId);
  3253.         end
  3254.  
  3255.         if (uniqueId == nil) then   uniqueId = 0;
  3256.         else                        uniqueId = tonumber(suffixId);
  3257.         end
  3258.  
  3259.         local itemString = "item:"..itemId..":0:0:0:0:0:"..suffixId..":"..uniqueId;
  3260.  
  3261.         _, itemLink = GetItemInfo(itemString);
  3262.  
  3263.         if (itemLink == nil) then       -- pull it into the cache and go back to the idle loop to wait for it to appear
  3264.             AtrScanningTooltip:SetHyperlink(itemString);
  3265.             gHentryTryAgain = line;
  3266.             zc.md ("pulling "..itemName.." into the local cache");
  3267.             return;
  3268.         end
  3269.     end
  3270. ]]--
  3271.  
  3272.     gCurrentPane.UINeedsUpdate = true;
  3273.  
  3274.     Atr_ClearAll();
  3275.  
  3276.     local IDstring = zc.ItemIDStrfromLink (itemLink)
  3277.     local cacheHit = gCurrentPane:DoSearch (itemName, IDstring, itemLink);
  3278.  
  3279.     Atr_ClearHistory();
  3280.  
  3281.     Atr_DisplayHlist();  -- for the highlight
  3282.  
  3283.     if (cacheHit) then
  3284.         Atr_OnSearchComplete();
  3285.     end
  3286.  
  3287.     PlaySound ("igMainMenuOptionCheckBoxOn");
  3288. end
  3289.  
  3290. -----------------------------------------
  3291.  
  3292. function Atr_ListTabOnClick (id)
  3293.  
  3294.     if (gCurrentPane.activeSearch.processing_state ~= KM_NULL_STATE) then       -- if we're scanning auctions don't respond
  3295.         return;
  3296.     end
  3297.  
  3298.     PlaySound("igMainMenuOptionCheckBoxOn");
  3299.  
  3300.     Atr_SetToShowTab (id);
  3301.  
  3302.     Atr_ClearHistory();
  3303.  
  3304. end
  3305.  
  3306. -----------------------------------------
  3307.  
  3308. function Atr_IsSelectedTab_Current ()
  3309.     return (PanelTemplates_GetSelectedTab (Atr_ListTabs) == 1);
  3310. end
  3311.  
  3312. -----------------------------------------
  3313.  
  3314. function Atr_IsSelectedTab_History ()
  3315.     return (PanelTemplates_GetSelectedTab (Atr_ListTabs) == 2);
  3316. end
  3317.  
  3318. -----------------------------------------
  3319.  
  3320. function Atr_IsSelectedTab_Hints ()
  3321.     return (PanelTemplates_GetSelectedTab (Atr_ListTabs) == 3);
  3322. end
  3323.  
  3324. -----------------------------------------
  3325.  
  3326. function Atr_SetToShowTab (which)
  3327.  
  3328.     if (PanelTemplates_GetSelectedTab (Atr_ListTabs) == which) then
  3329.         return;
  3330.     end
  3331.  
  3332.     PanelTemplates_SetTab(Atr_ListTabs, which);
  3333.     gCurrentPane.UINeedsUpdate = true;
  3334. end
  3335.  
  3336. -----------------------------------------
  3337.  
  3338. function Atr_SetToShowCurrent ()
  3339.     Atr_SetToShowTab (1);
  3340. end
  3341.  
  3342. -----------------------------------------
  3343.  
  3344. function Atr_SetToShowHistory ()
  3345.     Atr_SetToShowTab (2);
  3346. end
  3347.  
  3348. -----------------------------------------
  3349.  
  3350. function Atr_SetToShowHints ()
  3351.     Atr_SetToShowTab (3);
  3352. end
  3353.  
  3354. -----------------------------------------
  3355.  
  3356. function Atr_ShowingSearchSummary ()
  3357.  
  3358.     if (gCurrentPane.activeSearch and gCurrentPane.activeSearch.searchText ~= "" and gCurrentPane:IsScanNil() and gCurrentPane.activeSearch:NumScans() > 0) then
  3359.  
  3360.         return true;
  3361.     end
  3362.  
  3363.     return false;
  3364. end
  3365.  
  3366.  
  3367. -----------------------------------------
  3368.  
  3369. function Atr_RedisplayAuctions ()
  3370.  
  3371.     if (Atr_ShowingSearchSummary()) then
  3372.         Atr_ShowSearchSummary();
  3373.     elseif (Atr_IsSelectedTab_Current()) then
  3374.         Atr_ShowCurrentAuctions();
  3375.     elseif Atr_IsSelectedTab_History() then
  3376.         Atr_ShowHistory();
  3377.     else
  3378.         Atr_ShowOldPostings();
  3379.     end
  3380. end
  3381.  
  3382. -----------------------------------------
  3383.  
  3384. function Atr_BuildPostHistText(data)
  3385.  
  3386.     local stacktext = "";
  3387. --  if (data.stackSize > 1) then
  3388. --      stacktext = " (stack of "..data.stackSize..")";
  3389. --  end
  3390.  
  3391.     local now       = time();
  3392.     local nowtime   = date ("*t");
  3393.  
  3394.     local when      = data.when;
  3395.     local whentime  = date ("*t", when);
  3396.  
  3397.     local datestr = "";
  3398.  
  3399.     if (data.type == "hy") then
  3400.         return ZT("average of your auctions for").." "..whentime.year;
  3401.     elseif (data.type == "hm") then
  3402.         if (nowtime.year == whentime.year) then
  3403.             return ZT("average of your auctions for").." "..date("%B", when);
  3404.         else
  3405.             return ZT("average of your auctions for").." "..date("%B %Y", when);
  3406.         end
  3407.     elseif (data.type == "hd") then
  3408.         return ZT("average of your auctions for").." "..monthDay(whentime);
  3409.     else
  3410.         return ZT("your auction on").." "..monthDay(whentime)..date(" at %I:%M %p", when);
  3411.     end
  3412. end
  3413.  
  3414. -----------------------------------------
  3415.  
  3416. function monthDay (when)
  3417.  
  3418.     local t = time(when);
  3419.  
  3420.     local s = date("%b ", t);
  3421.  
  3422.     return s..when.day;
  3423.  
  3424. end
  3425.  
  3426. -----------------------------------------
  3427.  
  3428. function Atr_ShowLineTooltip (self)
  3429.  
  3430.     local itemLink = self.itemLink;
  3431.  
  3432.     if (zc.IsBattlePetLink (itemLink)) then
  3433.  
  3434.         local speciesID, level, breedQuality, maxHealth, power, speed, battlePetID, name = zc.ParseBattlePetLink(itemLink)
  3435.  
  3436.         BattlePetToolTip_Show(speciesID, level, breedQuality, maxHealth, power, speed, name)
  3437.  
  3438.         BattlePetTooltip:ClearAllPoints();
  3439.         BattlePetTooltip:SetPoint("BOTTOMRIGHT", self, "TOPRIGHT", 10, 0)
  3440.  
  3441.     else   -- normal case
  3442.  
  3443.         local fname = self:GetName()
  3444.         local ftname = fname.."_EntryText"
  3445.         local textPart = _G[ftname]
  3446.  
  3447.         if (itemLink) then
  3448.             GameTooltip:SetOwner(self, "ANCHOR_RIGHT", -280)
  3449.             GameTooltip:SetHyperlink (itemLink, 1)
  3450.         end
  3451.     end
  3452. end
  3453.  
  3454.  
  3455.  
  3456.  
  3457. -----------------------------------------
  3458.  
  3459. function Atr_HideLineTooltip (self)
  3460.     GameTooltip:Hide();
  3461.     BattlePetTooltip:Hide();
  3462. end
  3463.  
  3464.  
  3465. -----------------------------------------
  3466.  
  3467. function Atr_Onclick_Back ()
  3468.  
  3469.     gCurrentPane.activeScan = Atr_FindScan (nil);
  3470.     gCurrentPane.UINeedsUpdate = true;
  3471.  
  3472.     if (gCurrentPane.savedScrollOffset) then
  3473.         FauxScrollFrame_SetOffset (AuctionatorScrollFrame, gCurrentPane.savedScrollOffset)
  3474.         AuctionatorScrollFrame:SetVerticalScroll(gCurrentPane.savedVertScroll);
  3475.         gCurrentPane.savedScrollOffset = nil;
  3476.     end
  3477. end
  3478.  
  3479. -----------------------------------------
  3480.  
  3481. function Atr_Onclick_Col1 ()
  3482.  
  3483.     if (gCurrentPane.activeSearch) then
  3484.         gCurrentPane.activeSearch:ClickPriceCol();
  3485.         gCurrentPane.UINeedsUpdate = true;
  3486.     end
  3487.  
  3488. end
  3489.  
  3490. -----------------------------------------
  3491.  
  3492. function Atr_Onclick_Col3 ()
  3493.  
  3494.     if (gCurrentPane.activeSearch) then
  3495.         gCurrentPane.activeSearch:ClickNameCol();
  3496.         gCurrentPane.UINeedsUpdate = true;
  3497.     end
  3498.  
  3499. end
  3500.  
  3501. -----------------------------------------
  3502.  
  3503. function Atr_ShowSearchSummary()
  3504.  
  3505.     Atr_Col1_Heading:Hide();
  3506.     Atr_Col3_Heading:Hide();
  3507.     Atr_Col1_Heading_Button:Show();
  3508.     Atr_Col3_Heading_Button:Show();
  3509.     Atr_Col4_Heading:Show();
  3510.  
  3511.     gCurrentPane.activeSearch:UpdateArrows ();
  3512.  
  3513.     local numrows = gCurrentPane.activeSearch:NumScans();
  3514.  
  3515.     if (gCurrentPane.activeScan.hasStack) then
  3516.         Atr_Col4_Heading:SetText (ZT("Total Price"));
  3517.     else
  3518.         Atr_Col4_Heading:SetText ("");
  3519.     end
  3520.  
  3521.     local iLevelStr;
  3522.     local highIndex  = 0;
  3523.     local line       = 0;                                                           -- 1 through 12 of our window to scroll
  3524.     local dataOffset = FauxScrollFrame_GetOffset (AuctionatorScrollFrame);          -- an index into our data calculated from the scroll offset
  3525.  
  3526.     FauxScrollFrame_Update (AuctionatorScrollFrame, numrows, 12, 16);
  3527.  
  3528.     Atr_HideRecTooltip()
  3529.  
  3530.     while (line < 12) do
  3531.  
  3532.         dataOffset  = dataOffset + 1;
  3533.         line        = line + 1;
  3534.  
  3535.         local lineEntry = _G["AuctionatorEntry"..line];
  3536.  
  3537.         lineEntry:SetID(dataOffset);
  3538.  
  3539.         local scn;
  3540.  
  3541.         if (gCurrentPane.activeSearch and gCurrentPane.activeSearch:NumSortedScans() > 0) then
  3542.             scn = gCurrentPane.activeSearch.sortedScans[dataOffset];
  3543.         end
  3544.  
  3545.         if (dataOffset > numrows or not scn) then
  3546.  
  3547.             lineEntry:Hide();
  3548.  
  3549.         else
  3550.             local data = scn.absoluteBest;
  3551.  
  3552.             local lineEntry_item_tag = "AuctionatorEntry"..line.."_PerItem_Price";
  3553.  
  3554.             local lineEntry_item        = _G[lineEntry_item_tag];
  3555.             local lineEntry_itemtext    = _G["AuctionatorEntry"..line.."_PerItem_Text"];
  3556.             local lineEntry_text        = _G["AuctionatorEntry"..line.."_EntryText"];
  3557.             local lineEntry_stack       = _G["AuctionatorEntry"..line.."_StackPrice"];
  3558.  
  3559.             lineEntry_itemtext:SetText  ("");
  3560.             lineEntry_text:SetText  ("");
  3561.             lineEntry_stack:SetText ("");
  3562.  
  3563.             lineEntry_text:GetParent():SetPoint ("LEFT", 157, 0);
  3564.  
  3565.             Atr_SetMFcolor (lineEntry_item_tag);
  3566.  
  3567.             lineEntry:Show();
  3568.  
  3569.             lineEntry.itemLink = scn.itemLink;
  3570.  
  3571.             local r = scn.itemTextColor[1]
  3572.             local g = scn.itemTextColor[2]
  3573.             local b = scn.itemTextColor[3]
  3574.  
  3575.             lineEntry_text:SetTextColor (r, g, b)
  3576.             lineEntry_stack:SetTextColor (1, 1, 1)
  3577.  
  3578.             local icon = Atr_GetUCIcon (scn.itemLink)
  3579.  
  3580.             if (not scn:IsNil()) then
  3581.  
  3582.                 iLevelStr = ""
  3583.                 if (scn.itemClass == WEAPON or scn.itemClass == ARMOR) then     -- might turn this on soon
  3584.                     iLevelStr = " ("..scn.itemLevel..")"
  3585.                 end
  3586.  
  3587.                 lineEntry_text:SetText (icon.."  "..scn.itemName..iLevelStr)
  3588.                 lineEntry_stack:SetText (scn:GetNumAvailable().." "..ZT("available"))
  3589.             end
  3590.  
  3591.             if (data == nil or scn.sortedData == nil or #scn.sortedData == 0) then
  3592.                 lineEntry_item:Hide();
  3593.                 lineEntry_itemtext:Show();
  3594.                 if (scn.sortedData and #scn.sortedData == 0) then
  3595.                     lineEntry_itemtext:SetText (ZT("none available"));
  3596.                 else
  3597.                     lineEntry_itemtext:SetText (ZT("no buyout price"));
  3598.                 end
  3599.             else
  3600.                 lineEntry_item:Show();
  3601.                 lineEntry_itemtext:Hide();
  3602.                 MoneyFrame_Update (lineEntry_item_tag, zc.round(data.buyoutPrice/data.stackSize) );
  3603.             end
  3604.  
  3605.             if (zc.StringSame (scn.itemName , gCurrentPane.SS_hilite_itemName)) then
  3606.                 highIndex = dataOffset;
  3607.             end
  3608.  
  3609.  
  3610.         end
  3611.     end
  3612.  
  3613.     Atr_HighlightEntry (highIndex);     -- need this for when called from onVerticalScroll
  3614.  
  3615. end
  3616.  
  3617. -----------------------------------------
  3618.  
  3619. function Atr_ShowCurrentAuctions()
  3620.  
  3621.     Atr_Col1_Heading:Hide()
  3622.     Atr_Col3_Heading:Hide()
  3623.     Atr_Col4_Heading:Hide()
  3624.     Atr_Col1_Heading_Button:Hide()
  3625.     Atr_Col3_Heading_Button:Hide()
  3626.  
  3627.     local scn = gCurrentPane.activeScan
  3628.     if (scn == nil) then
  3629.         scn = Atr_FindScan(nil)
  3630.     end
  3631.  
  3632.     numrows = #scn.sortedData
  3633.  
  3634.     if (numrows > 0) then
  3635.         Atr_Col1_Heading:Show();
  3636.         Atr_Col3_Heading:Show();
  3637.         Atr_Col4_Heading:Show();
  3638.     end
  3639.  
  3640.     Atr_Col1_Heading:SetText (ZT("Item Price"));
  3641.     Atr_Col3_Heading:SetText (ZT("Current Auctions"));
  3642.  
  3643.     if (scn.hasStack) then
  3644.         Atr_Col4_Heading:SetText (ZT("Stack Price"));
  3645.     else
  3646.         Atr_Col4_Heading:SetText ("");
  3647.     end
  3648.  
  3649.     local line       = 0;                                                           -- 1 through 12 of our window to scroll
  3650.     local dataOffset = FauxScrollFrame_GetOffset (AuctionatorScrollFrame);          -- an index into our data calculated from the scroll offset
  3651.  
  3652.     FauxScrollFrame_Update (AuctionatorScrollFrame, numrows, 12, 16);
  3653.  
  3654.     while (line < 12) do
  3655.  
  3656.         dataOffset  = dataOffset + 1;
  3657.         line        = line + 1;
  3658.  
  3659.         local lineEntry = _G["AuctionatorEntry"..line];
  3660.  
  3661.         lineEntry:SetID(dataOffset);
  3662.  
  3663.         lineEntry.itemLink = nil;
  3664.  
  3665.         if (dataOffset > numrows or not scn.sortedData[dataOffset]) then
  3666.  
  3667.             lineEntry:Hide();
  3668.  
  3669.         else
  3670.             local data = scn.sortedData[dataOffset];
  3671.  
  3672.             local lineEntry_item_tag = "AuctionatorEntry"..line.."_PerItem_Price";
  3673.  
  3674.             local lineEntry_item        = _G[lineEntry_item_tag];
  3675.             local lineEntry_itemtext    = _G["AuctionatorEntry"..line.."_PerItem_Text"];
  3676.             local lineEntry_text        = _G["AuctionatorEntry"..line.."_EntryText"];
  3677.             local lineEntry_stack       = _G["AuctionatorEntry"..line.."_StackPrice"];
  3678.  
  3679.             lineEntry_itemtext:SetText  ("");
  3680.             lineEntry_text:SetText  ("");
  3681.             lineEntry_stack:SetText ("");
  3682.  
  3683.             lineEntry_text:GetParent():SetPoint ("LEFT", 172, 0);
  3684.  
  3685.             Atr_SetMFcolor (lineEntry_item_tag);
  3686.  
  3687.             local entrytext = "";
  3688.  
  3689.             if (data.type == "n") then
  3690.  
  3691.                 lineEntry:Show();
  3692.  
  3693.                 if (data.count == 1) then
  3694.                     entrytext = string.format ("%i %s %i", data.count, ZT ("stack of"), data.stackSize);
  3695.                 else
  3696.                     entrytext = string.format ("%i %s %i", data.count, ZT ("stacks of"), data.stackSize);
  3697.                 end
  3698.  
  3699.                 lineEntry_text:SetTextColor (0.6, 0.6, 0.6);
  3700.  
  3701.                 if ( data.stackSize == Atr_StackSize() or Atr_StackSize() == 0 or gCurrentPane ~= gSellPane) then
  3702.                     lineEntry_text:SetTextColor (1.0, 1.0, 1.0);
  3703.                 end
  3704.  
  3705.                 if (data.yours) then
  3706.                      entrytext = entrytext.." ("..ZT("yours")..")";
  3707.                 elseif (data.altname) then
  3708.                      entrytext = entrytext.." ("..data.altname..")";
  3709.                 end
  3710.  
  3711.                 lineEntry_text:SetText (entrytext);
  3712.  
  3713.                 if (data.buyoutPrice == 0) then
  3714.                     lineEntry_item:Hide();
  3715.                     lineEntry_itemtext:Show();
  3716.                     lineEntry_itemtext:SetText (ZT("no buyout price"));
  3717.                 else
  3718.                     lineEntry_item:Show();
  3719.                     lineEntry_itemtext:Hide();
  3720.                     MoneyFrame_Update (lineEntry_item_tag, zc.round(data.buyoutPrice/data.stackSize) );
  3721.  
  3722.                     if (data.stackSize > 1) then
  3723.                         lineEntry_stack:SetText (zc.priceToString(data.buyoutPrice));
  3724.                         lineEntry_stack:SetTextColor (0.6, 0.6, 0.6);
  3725.                     end
  3726.                 end
  3727.  
  3728.             else
  3729.                 zc.msg_red ("Unknown datatype:");
  3730.                 zc.msg_red (data.type);
  3731.             end
  3732.         end
  3733.     end
  3734.  
  3735.     Atr_HighlightEntry (gCurrentPane.currIndex);        -- need this for when called from onVerticalScroll
  3736. end
  3737.  
  3738. -----------------------------------------
  3739.  
  3740. function Atr_ClearHistory ()
  3741.     gCurrentPane.sortedHist = nil;
  3742. end
  3743.  
  3744. -----------------------------------------
  3745.  
  3746. function Atr_ShowOldPostings()
  3747.     Atr_ShowHistory (true);
  3748. end
  3749.  
  3750. -----------------------------------------
  3751.  
  3752. function Atr_ShowHistory (showPosts)
  3753.  
  3754.  
  3755.     if (gCurrentPane.sortedHist == nil) then
  3756.  
  3757.         if (showPosts) then
  3758.             Atr_Build_PostingsList();
  3759.             Atr_FindBestHistoricalAuction ();
  3760.         else
  3761.             Atr_BuildSortedScanHistoryList(gCurrentPane.activeScan.itemName);
  3762.         end
  3763.     end
  3764.  
  3765.     local showScanHist = (not showPosts);
  3766.  
  3767.     Atr_Col1_Heading:Hide();
  3768.     Atr_Col3_Heading:Hide();
  3769.     Atr_Col4_Heading:Hide();
  3770.  
  3771.     if (showScanHist) then
  3772.         Atr_Col3_Heading:SetText (ZT("Date"));
  3773.         Atr_Col4_Heading:SetText (ZT("Low Low Price"));
  3774.     end
  3775.  
  3776.     local numrows = gCurrentPane.sortedHist and #gCurrentPane.sortedHist or 0;
  3777.  
  3778. --zc.msg ("gCurrentPane.sortedHist: "..numrows,1,0,0);
  3779.  
  3780.     if (numrows > 0) then
  3781.         Atr_Col1_Heading:Show();
  3782.         Atr_Col3_Heading:Show();
  3783. --      if (showScanHist) then
  3784. --          Atr_Col4_Heading:Show();
  3785. --      end
  3786.     end
  3787.  
  3788.     local line;                         -- 1 through 12 of our window to scroll
  3789.     local dataOffset;                   -- an index into our data calculated from the scroll offset
  3790.  
  3791.     FauxScrollFrame_Update (AuctionatorScrollFrame, numrows, 12, 16);
  3792.  
  3793.     for line = 1,12 do
  3794.  
  3795.         dataOffset = line + FauxScrollFrame_GetOffset (AuctionatorScrollFrame);
  3796.  
  3797.         local lineEntry = _G["AuctionatorEntry"..line];
  3798.  
  3799.         lineEntry:SetID(dataOffset);
  3800.  
  3801.         if (dataOffset <= numrows and gCurrentPane.sortedHist[dataOffset]) then
  3802.  
  3803.             local data = gCurrentPane.sortedHist[dataOffset];
  3804.  
  3805.             local lineEntry_item_tag = "AuctionatorEntry"..line.."_PerItem_Price";
  3806.  
  3807.             local lineEntry_item        = _G[lineEntry_item_tag];
  3808.             local lineEntry_itemtext    = _G["AuctionatorEntry"..line.."_PerItem_Text"];
  3809.             local lineEntry_text        = _G["AuctionatorEntry"..line.."_EntryText"];
  3810.             local lineEntry_stack       = _G["AuctionatorEntry"..line.."_StackPrice"];
  3811.  
  3812.             lineEntry_text:GetParent():SetPoint ("LEFT", 172, 0);
  3813.  
  3814.             lineEntry_item:Show();
  3815.             lineEntry_itemtext:Hide();
  3816.  
  3817.             lineEntry_stack:SetText ("");
  3818.  
  3819.             Atr_SetMFcolor (lineEntry_item_tag);
  3820.  
  3821.             MoneyFrame_Update (lineEntry_item_tag, zc.round(data.itemPrice) );
  3822.  
  3823.             lineEntry_text:SetText (data.whenText);
  3824.             lineEntry_text:SetTextColor (0.8, 0.8, 1.0);
  3825.  
  3826.             lineEntry:Show();
  3827.         else
  3828.             lineEntry:Hide();
  3829.         end
  3830.     end
  3831.  
  3832.     if (Atr_IsTabSelected (SELL_TAB)) then
  3833.         Atr_HighlightEntry (gCurrentPane.histIndex);        -- need this for when called from onVerticalScroll
  3834.     else
  3835.         Atr_HighlightEntry (-1);
  3836.     end
  3837. end
  3838.  
  3839.  
  3840. -----------------------------------------
  3841.  
  3842. function Atr_FindBestCurrentAuction()
  3843.  
  3844.     local scan = gCurrentPane.activeScan;
  3845.  
  3846.     if      (Atr_IsModeCreateAuction()) then    gCurrentPane.currIndex = scan:FindCheapest ();
  3847.     elseif  (Atr_IsModeBuy()) then              gCurrentPane.currIndex = scan:FindCheapest ();
  3848.     else                                        gCurrentPane.currIndex = scan:FindMatchByYours ();
  3849.     end
  3850.  
  3851. end
  3852.  
  3853. -----------------------------------------
  3854.  
  3855. function Atr_FindBestHistoricalAuction()
  3856.  
  3857.     gCurrentPane.histIndex = nil;
  3858.  
  3859.     if (gCurrentPane.sortedHist and #gCurrentPane.sortedHist > 0) then
  3860.         gCurrentPane.histIndex = 1;
  3861.     end
  3862. end
  3863.  
  3864. -----------------------------------------
  3865.  
  3866. function Atr_HighlightEntry(entryIndex)
  3867.  
  3868.     local line;             -- 1 through 12 of our window to scroll
  3869.  
  3870.     for line = 1,12 do
  3871.  
  3872.         local lineEntry = _G["AuctionatorEntry"..line];
  3873.  
  3874.         if (lineEntry:GetID() == entryIndex) then
  3875.             lineEntry:SetButtonState ("PUSHED", true);
  3876.         else
  3877.             lineEntry:SetButtonState ("NORMAL", false);
  3878.         end
  3879.     end
  3880.  
  3881.     local doEnableCancel = false;
  3882.     local doEnableBuy = false;
  3883.     local data;
  3884.  
  3885.     if (Atr_IsSelectedTab_Current() and entryIndex ~= nil and entryIndex > 0 and entryIndex <= #gCurrentPane.activeScan.sortedData) then
  3886.         data = gCurrentPane.activeScan.sortedData[entryIndex];
  3887.         if (data.yours) then
  3888.             doEnableCancel = true;
  3889.         end
  3890.  
  3891.         if (not data.yours and not data.altname and data.buyoutPrice > 0) then
  3892.             doEnableBuy = true;
  3893.         end
  3894.     end
  3895.  
  3896.     Atr_Buy1_Button:Disable();
  3897.     Atr_CancelSelectionButton:Disable();
  3898.  
  3899.     if (doEnableCancel) then
  3900.         Atr_CancelSelectionButton:Enable();
  3901.  
  3902.         if (data.count == 1) then
  3903.             Atr_CancelSelectionButton:SetText (CANCEL_AUCTION);
  3904.         else
  3905.             Atr_CancelSelectionButton:SetText (ZT("Cancel Auctions"));
  3906.         end
  3907.     end
  3908.  
  3909.     if (doEnableBuy) then
  3910.         Atr_Buy1_Button:Enable();
  3911.     end
  3912.  
  3913. end
  3914.  
  3915.  
  3916.  
  3917.  
  3918. -----------------------------------------
  3919.  
  3920. function Atr_EntryOnClick(entry)
  3921.  
  3922.     Atr_Clear_Owner_Item_Indices();
  3923.  
  3924.     local entryIndex = entry:GetID();
  3925.  
  3926.     if     (Atr_ShowingSearchSummary())     then
  3927.     elseif (Atr_IsSelectedTab_Current())    then        gCurrentPane.currIndex = entryIndex;
  3928.     else                                                gCurrentPane.histIndex = entryIndex;
  3929.     end
  3930.  
  3931.     if (Atr_ShowingSearchSummary()) then
  3932.         local scn = gCurrentPane.activeSearch.sortedScans[entryIndex];
  3933.  
  3934.         gCurrentPane.savedScrollOffset = FauxScrollFrame_GetOffset (AuctionatorScrollFrame)
  3935.         gCurrentPane.savedVertScroll   = AuctionatorScrollFrame:GetVerticalScroll()
  3936.  
  3937.         FauxScrollFrame_SetOffset (AuctionatorScrollFrame, 0);
  3938.         gCurrentPane.activeScan = scn;
  3939.         gCurrentPane.currIndex = scn:FindMatchByYours ();
  3940.         if (gCurrentPane.currIndex == nil) then
  3941.             gCurrentPane.currIndex = scn:FindCheapest();
  3942.         end
  3943.  
  3944.         gCurrentPane.SS_hilite_itemName = scn.itemName;
  3945.         gCurrentPane.UINeedsUpdate = true;
  3946.     else
  3947.         Atr_HighlightEntry (entryIndex);
  3948.         Atr_UpdateRecommendation(true);
  3949.     end
  3950.  
  3951.     PlaySound ("igMainMenuOptionCheckBoxOn");
  3952. end
  3953.  
  3954. -----------------------------------------
  3955.  
  3956. function AuctionatorMoneyFrame_OnLoad(self)
  3957.  
  3958.     self.small = 1;
  3959.     MoneyFrame_SetType(self, "AUCTION");
  3960. end
  3961.  
  3962.  
  3963. -----------------------------------------
  3964.  
  3965. function Atr_GetNumItemInBags (targItemLink)
  3966.  
  3967.     local numItems = 0;
  3968.     local b, bagID, slotID, numslots;
  3969.  
  3970.     local targItemName, targIsBattlePet = zc.ItemNamefromLink (targItemLink)
  3971.  
  3972.     zz (zc.printableLink(targItemLink))
  3973.     zz (zc.printableLink(targItemName), targIsBattlePet)
  3974.  
  3975.     for b = 1, #kBagIDs do
  3976.         bagID = kBagIDs[b];
  3977.  
  3978.         numslots = GetContainerNumSlots (bagID);
  3979.         for slotID = 1,numslots do
  3980.             local itemLink = GetContainerItemLink(bagID, slotID);
  3981.             if (itemLink) then
  3982.                 local itemName, isBattlePet = zc.ItemNamefromLink (itemLink)
  3983.  
  3984.                 if (itemName == targItemName and isBattlePet == targIsBattlePet) then
  3985.  
  3986.                     local _, itemCount  = GetContainerItemInfo(bagID, slotID)
  3987.                     numItems = numItems + itemCount;
  3988.                 end
  3989.             end
  3990.         end
  3991.     end
  3992.  
  3993.     return numItems;
  3994.  
  3995. end
  3996.  
  3997. -----------------------------------------
  3998.  
  3999. function Atr_DoesAuctionMatch (list, i, name, buyout, stacksize)
  4000.  
  4001.     local aname, _, astacksize, _, _, _, _, _, _, abuyout, _, _, _ = GetAuctionItemInfo (list, i);
  4002.  
  4003.     if (aname and aname == name and abuyout == buyout and astacksize == stacksize) then
  4004.         return true;
  4005.     end
  4006.  
  4007.     return false;
  4008.  
  4009. end
  4010.  
  4011. -----------------------------------------
  4012.  
  4013. function Atr_CancelAuction(x)
  4014.  
  4015.     CancelAuction(x);
  4016.  
  4017. end
  4018.  
  4019. -----------------------------------------
  4020.  
  4021. function Atr_Clear_Owner_Item_Indices()
  4022.  
  4023.     gAtr_Owner_Item_Indices = {};
  4024.  
  4025. end
  4026.  
  4027.  
  4028.  
  4029.  
  4030. -----------------------------------------
  4031.  
  4032. function Atr_LogCancelAuction(numCancelled, itemLink, stackSize)
  4033.  
  4034.     local SSstring = "";
  4035.     if (stackSize and stackSize > 1) then
  4036.         SSstring = "|cff00ddddx"..stackSize;
  4037.     end
  4038.  
  4039.     if (numCancelled > 1) then
  4040.         zc.msg_yellow (numCancelled..ZT(" auctions cancelled for ")..itemLink..SSstring);
  4041.     elseif (numCancelled == 1) then
  4042.         zc.msg_yellow (ZT("Auction cancelled for ")..itemLink..SSstring);
  4043.     end
  4044.  
  4045. end
  4046.  
  4047. -----------------------------------------
  4048.  
  4049. function Atr_CancelSelection_OnClick()
  4050.  
  4051.     if (not Atr_IsSelectedTab_Current()) then
  4052.         return;
  4053.     end
  4054.  
  4055.     Atr_CancelAuction_ByIndex (gCurrentPane.currIndex);
  4056. end
  4057.  
  4058. -----------------------------------------
  4059.  
  4060. function Atr_CancelAuction_ByIndex(index)
  4061.  
  4062.     local data = gCurrentPane.activeScan.sortedData[index];
  4063.  
  4064.     if (data == nil or not data.yours) then
  4065.         return;
  4066.     end
  4067.  
  4068.     local numCancelled  = 0;
  4069.     local itemLink      = gCurrentPane.activeScan.itemLink;
  4070.     local itemName      = gCurrentPane.activeScan.itemName;
  4071.  
  4072.     -- build a list of indices if we don't currently have one
  4073.  
  4074.     if (#gAtr_Owner_Item_Indices == 0) then
  4075.  
  4076.         local numInList = Atr_GetNumAuctionItems ("owner");
  4077.         local i;
  4078.         local x = 1;
  4079.  
  4080.         for i = 1,numInList do
  4081.  
  4082.             if (Atr_DoesAuctionMatch ("owner", i, itemName, data.buyoutPrice, data.stackSize)) then
  4083.                 gAtr_Owner_Item_Indices[x] = i;
  4084.                 x = x + 1;
  4085.             end
  4086.         end
  4087.     end
  4088.  
  4089.     -- cancel the last item in the list and remove it
  4090.  
  4091.     local numInMatchList = #gAtr_Owner_Item_Indices;
  4092.  
  4093.     for x = numInMatchList,1,-1 do
  4094.  
  4095.         i = gAtr_Owner_Item_Indices[x];
  4096.  
  4097.         table.remove (gAtr_Owner_Item_Indices);
  4098.  
  4099.         if (Atr_DoesAuctionMatch ("owner", i, itemName, data.buyoutPrice, data.stackSize)) then
  4100.             Atr_CancelAuction (i);
  4101.             numCancelled = numCancelled + 1;
  4102.             AuctionatorSubtractFromScan (itemLink, data.stackSize, data.buyoutPrice);
  4103.             gJustPosted.ItemName = nil;
  4104.             Atr_LogCancelAuction (numCancelled, itemLink, data.stackSize);
  4105.             break;
  4106.         end
  4107.     end
  4108. end
  4109.  
  4110. -----------------------------------------
  4111.  
  4112. function Atr_StackingPrefs_Init ()
  4113.  
  4114.     AUCTIONATOR_STACKING_PREFS = {};
  4115. end
  4116.  
  4117. -----------------------------------------
  4118.  
  4119. function Atr_Has_StackingPrefs (key)
  4120.  
  4121.     local lkey = key:lower();
  4122.  
  4123.     return (AUCTIONATOR_STACKING_PREFS[lkey] ~= nil);
  4124. end
  4125.  
  4126. -----------------------------------------
  4127.  
  4128. function Atr_Clear_StackingPrefs (key)
  4129.  
  4130.     local lkey = key:lower();
  4131.  
  4132.     AUCTIONATOR_STACKING_PREFS[lkey] = nil;
  4133. end
  4134.  
  4135. -----------------------------------------
  4136.  
  4137. function Atr_Get_StackingPrefs (key)
  4138.  
  4139.     local lkey = key:lower();
  4140.  
  4141.     if (Atr_Has_StackingPrefs(lkey)) then
  4142.         return AUCTIONATOR_STACKING_PREFS[lkey].numstacks, AUCTIONATOR_STACKING_PREFS[lkey].stacksize;
  4143.     end
  4144.  
  4145.     return nil, nil;
  4146.  
  4147. end
  4148.  
  4149. -----------------------------------------
  4150.  
  4151. function Atr_Set_StackingPrefs_numstacks (key, numstacks)
  4152.  
  4153.     local lkey = key:lower();
  4154.  
  4155.     if (not Atr_Has_StackingPrefs(lkey)) then
  4156.         AUCTIONATOR_STACKING_PREFS[lkey] = { stacksize = 0 };
  4157.     end
  4158.  
  4159.     AUCTIONATOR_STACKING_PREFS[lkey].numstacks = zc.Val (numstacks, 1);
  4160.     zz ("Setting stacking prefs (numstacks): ", lkey, AUCTIONATOR_STACKING_PREFS[lkey].numstacks)
  4161. end
  4162.  
  4163. -----------------------------------------
  4164.  
  4165. function Atr_Set_StackingPrefs_stacksize (key, stacksize)
  4166.  
  4167.     local lkey = key:lower();
  4168.  
  4169.     if (not Atr_Has_StackingPrefs(lkey)) then
  4170.         AUCTIONATOR_STACKING_PREFS[lkey] = { numstacks = 0};
  4171.     end
  4172.  
  4173.     AUCTIONATOR_STACKING_PREFS[lkey].stacksize = zc.Val (stacksize, 1);
  4174.  
  4175.     zz ("Setting stacking prefs (stacksize): ", lkey, AUCTIONATOR_STACKING_PREFS[lkey].stacksize)
  4176. end
  4177.  
  4178. -----------------------------------------
  4179.  
  4180. function Atr_GetStackingPrefs_ByItem (itemLink)
  4181.  
  4182.     local SP_NumStacks, SP_StackSize, isUserSpecified
  4183.  
  4184.     if (itemLink) then
  4185.  
  4186.         SP_NumStacks, SP_StackSize, isUserSpecified =  Atr_Special_SP_ByItem (itemLink);
  4187.  
  4188. --zz ("SP_NumStacks, SP_StackSize, isUserSpecified", SP_NumStacks, SP_StackSize, isUserSpecified)
  4189.  
  4190.         if (isUserSpecified) then
  4191.             return SP_NumStacks, SP_StackSize
  4192.         end
  4193.  
  4194.         local itemName = GetItemInfo (itemLink);
  4195.         local text, spinfo;
  4196.  
  4197.         for text, spinfo in pairs (AUCTIONATOR_STACKING_PREFS) do
  4198.  
  4199.             if (zc.StringContains (itemName, text)) then
  4200.                 return spinfo.numstacks, spinfo.stacksize
  4201.             end
  4202.         end
  4203.  
  4204.     end
  4205.  
  4206.     return SP_NumStacks, SP_StackSize;
  4207. end
  4208.  
  4209. -----------------------------------------
  4210.  
  4211. function Atr_Special_SP_ByItem (itemLink)
  4212.  
  4213.     if (itemLink) then
  4214.  
  4215.         local itemName = GetItemInfo (itemLink);
  4216.  
  4217.         local text, spinfo
  4218.  
  4219.         for text, spinfo in pairs (AUCTIONATOR_STACKING_PREFS) do
  4220.  
  4221.             -- skip over any that were set automatically rather than explicitly by the user
  4222.  
  4223.             if (spinfo.numstacks ~= 0) then
  4224.                 if (zc.StringSame (text, itemName)) then
  4225.                     return spinfo.numstacks, spinfo.stacksize, true
  4226.                 end
  4227.             end
  4228.         end
  4229.  
  4230.         if (itemLink) then
  4231.             if      (Atr_IsGlyph (itemLink))                                then        return Atr_Special_SP (ATR_SK_GLYPHS, 0, 1)
  4232.             elseif  (Atr_IsCutGem (itemLink))                               then        return Atr_Special_SP (ATR_SK_GEMS_CUT, 0, 1)
  4233.             elseif  (Atr_IsGem (itemLink))                                  then        return Atr_Special_SP (ATR_SK_GEMS_UNCUT, 1, 0)
  4234.             elseif  (Atr_IsItemEnhancement (itemLink))                      then        return Atr_Special_SP (ATR_SK_ITEM_ENH, 0, 1)
  4235.             elseif  (Atr_IsPotion (itemLink) or Atr_IsElixir (itemLink))    then        return Atr_Special_SP (ATR_SK_POT_ELIX, 1, 0)
  4236.             elseif  (Atr_IsFlask (itemLink))                                then        return Atr_Special_SP (ATR_SK_FLASKS, 1, 0)
  4237.             elseif  (Atr_IsHerb (itemLink))                                 then        return Atr_Special_SP (ATR_SK_HERBS, 1, 0)
  4238.             end
  4239.         end
  4240.     end
  4241.  
  4242.     return nil, nil, false
  4243. end
  4244.  
  4245.  
  4246. -----------------------------------------
  4247.  
  4248. function Atr_Special_SP (key, default_numstack, default_stacksize)
  4249.  
  4250.     if (Atr_Has_StackingPrefs (key)) then
  4251.         local numstacks, stacksize = Atr_Get_StackingPrefs(key)
  4252.         return numstacks, stacksize, true
  4253.     end
  4254.  
  4255.     return default_numstack, default_stacksize, false;
  4256. end
  4257.  
  4258. -----------------------------------------
  4259.  
  4260. function Atr_GetSellStacking (itemLink, numDragged, numTotal)
  4261.  
  4262.     local prefNumStacks, prefStackSize = Atr_GetStackingPrefs_ByItem (itemLink);
  4263.  
  4264.     if (prefNumStacks == nil) then
  4265.         return 1, numDragged;
  4266.     end
  4267.  
  4268.     if (prefNumStacks <= 0 and prefStackSize <= 0) then     -- shouldn't happen but just in case
  4269.         prefStackSize = 1;
  4270.     end
  4271.  
  4272. --zc.msg (prefNumStacks, prefStackSize);
  4273.  
  4274.     local numStacks = prefNumStacks;
  4275.     local stackSize = prefStackSize;
  4276.     local numToSell = numDragged;
  4277.  
  4278.     if (numStacks == -1) then       -- max number of stacks
  4279.         numToSell = numTotal;
  4280.  
  4281.     elseif (stackSize == 0) then        -- auto stacksize
  4282.         stackSize = math.floor (numDragged / numStacks);
  4283.  
  4284.     elseif (numStacks > 0) then
  4285.         numToSell = math.min (numStacks * stackSize, numTotal);
  4286.     end
  4287.  
  4288.     numStacks = math.floor (numToSell / stackSize);
  4289.  
  4290. --zc.msg_pink (numStacks, stackSize);
  4291.  
  4292.     if (numStacks == 0) then
  4293.         numStacks = 1;
  4294.         stackSize = numToSell;
  4295. --zc.msg_red (numStacks, stackSize);
  4296.     end
  4297.  
  4298.     return numStacks, stackSize;
  4299.  
  4300. end
  4301.  
  4302.  
  4303.  
  4304. -----------------------------------------
  4305.  
  4306. local gInitial_NumStacks;
  4307. local gInitial_StackSize;
  4308.  
  4309. -----------------------------------------
  4310.  
  4311. function Atr_SetInitialStacking (numStacks, stackSize)
  4312.  
  4313.     gInitial_NumStacks = numStacks;
  4314.     gInitial_StackSize = stackSize;
  4315.  
  4316.     Atr_Batch_NumAuctions:SetText (numStacks);
  4317.     Atr_SetStackSize (stackSize);
  4318. end
  4319.  
  4320. -----------------------------------------
  4321.  
  4322. function Atr_Memorize_Stacking_If ()
  4323.  
  4324.     local _, _, isUserSpecified =  Atr_Special_SP_ByItem (gCurrentPane.activeScan.itemLink);
  4325.     if (isUserSpecified) then
  4326. --      zz ("Not memorizing stacking for ", gCurrentPane.activeScan.itemLink)
  4327.         return
  4328.     end
  4329.  
  4330.     local newNumStacks = Atr_Batch_NumAuctions:GetNumber();
  4331.     local newStackSize = tonumber (Atr_StackSize());
  4332.  
  4333. --zz (gInitial_NumStacks, newNumStacks, gInitial_StackSize, newStackSize)
  4334.  
  4335.     local stackSizeChanged = (tonumber (gInitial_StackSize) ~= newStackSize);
  4336.  
  4337.     if (stackSizeChanged) then
  4338.  
  4339.         local itemName = string.lower(gCurrentPane.activeScan.itemName);
  4340.         if (itemName) then
  4341.  
  4342.             -- see if user is trying to set it back to default
  4343.  
  4344.             if (newNumStacks == 1) then
  4345.                 local _, _, auctionCount = GetAuctionSellItemInfo();
  4346.                 if (auctionCount == newStackSize) then
  4347.                     Atr_Clear_StackingPrefs (itemName);
  4348.                     return;
  4349.                 end
  4350.             end
  4351.  
  4352.             -- else remember the new stack size
  4353.  
  4354.             Atr_Set_StackingPrefs_stacksize (itemName, Atr_StackSize());
  4355.         end
  4356.     end
  4357. end
  4358.  
  4359.  
  4360.  
  4361.  
  4362. -----------------------------------------
  4363.  
  4364. function Atr_Duration_OnShow(self)
  4365.     UIDropDownMenu_Initialize (self, Atr_Duration_Initialize);
  4366.     local val = UIDropDownMenu_GetSelectedValue(self)
  4367.  
  4368.     if (val == nil) then
  4369.         UIDropDownMenu_SetSelectedValue (self, 1);
  4370.     end
  4371. end
  4372.  
  4373. -----------------------------------------
  4374.  
  4375. function Atr_Duration_Initialize(self)
  4376.  
  4377.     Atr_Dropdown_AddPick (self, AUCTION_DURATION_ONE,   1, Atr_Duration_OnClick);
  4378.     Atr_Dropdown_AddPick (self, AUCTION_DURATION_TWO,   2, Atr_Duration_OnClick);
  4379.     Atr_Dropdown_AddPick (self, AUCTION_DURATION_THREE, 3, Atr_Duration_OnClick);
  4380.  
  4381. end
  4382.  
  4383. -----------------------------------------
  4384.  
  4385. function Atr_Duration_OnClick(self)
  4386.  
  4387.     UIDropDownMenu_SetSelectedValue (self.owner, self.value);
  4388.     Atr_SetDepositText();
  4389. end
  4390.  
  4391.  
  4392. ----------------------------------------------------------------------------------
  4393. --------------------------   Dropdown Menu Functions  ----------------------------
  4394. ----------------------------------------------------------------------------------
  4395.  
  4396. local _atr_info = {};       -- table reuse
  4397. -----------------------------------------
  4398.  
  4399. function Atr_Dropdown_AddPick (frame, text, value, func)
  4400.  
  4401. --  if (_atr_info == nil) then
  4402. --      _atr_info = {}
  4403.         --zc.CopyDeep (_atr_info, UIDropDownMenu_CreateInfo());
  4404. --  end
  4405.  
  4406.     _atr_info.owner         = frame;
  4407.     _atr_info.text          = text;
  4408.     _atr_info.value         = value;
  4409.     _atr_info.checked       = nil;
  4410.  
  4411.     if (func) then
  4412.         _atr_info.func = func;
  4413.     else
  4414.         _atr_info.func = Atr_Dropdown_OnClick;
  4415.     end
  4416.  
  4417.     UIDropDownMenu_AddButton(_atr_info);
  4418.  
  4419.     --zc.md (UIDROPDOWNMENU_MAXBUTTONS);
  4420.  
  4421. end
  4422.  
  4423. -----------------------------------------
  4424.  
  4425. function Atr_Dropdown_OnClick (info)
  4426.  
  4427.     UIDropDownMenu_SetSelectedValue (info.owner, info.value);
  4428. end
  4429.  
  4430. -----------------------------------------
  4431.  
  4432. function Atr_Dropdown_Refresh (frame)       -- useful for forcing the initialization function to be called again
  4433.  
  4434.     frame:Hide();
  4435.     frame:Show();
  4436. end
  4437.  
  4438. ----------------------------------------------------------------------------------
  4439. ----------------------------------------------------------------------------------
  4440. ----------------------------------------------------------------------------------
  4441.  
  4442.  
  4443. function Atr_IsTabSelected(whichTab)
  4444.  
  4445.     if (not AuctionFrame or not AuctionFrame:IsShown()) then
  4446.         return false;
  4447.     end
  4448.  
  4449.     if (not whichTab) then
  4450.         return (Atr_IsTabSelected(SELL_TAB) or Atr_IsTabSelected(MORE_TAB) or Atr_IsTabSelected(BUY_TAB));
  4451.     end
  4452.  
  4453.     return (PanelTemplates_GetSelectedTab (AuctionFrame) == Atr_FindTabIndex(whichTab));
  4454. end
  4455.  
  4456. -----------------------------------------
  4457.  
  4458. function Atr_IsAuctionatorTab (tabIndex)
  4459.  
  4460.     if (tabIndex == Atr_FindTabIndex(SELL_TAB) or tabIndex == Atr_FindTabIndex(MORE_TAB) or tabIndex == Atr_FindTabIndex(BUY_TAB) ) then
  4461.  
  4462.         return true;
  4463.  
  4464.     end
  4465.  
  4466.     return false;
  4467. end
  4468.  
  4469. -----------------------------------------
  4470.  
  4471. function Atr_Confirm_Yes()
  4472.  
  4473.     if (Atr_Confirm_Proc_Yes) then
  4474.         Atr_Confirm_Proc_Yes();
  4475.         Atr_Confirm_Proc_Yes = nil;
  4476.     end
  4477.  
  4478.     Atr_Confirm_Frame:Hide();
  4479.  
  4480. end
  4481.  
  4482.  
  4483. -----------------------------------------
  4484.  
  4485. function Atr_Confirm_No()
  4486.  
  4487.     Atr_Confirm_Frame:Hide();
  4488.  
  4489. end
  4490.  
  4491.  
  4492. -----------------------------------------
  4493.  
  4494. function Atr_AddHistoricalPrice (itemName, price, stacksize, itemLink, testwhen)
  4495.  
  4496.     if (itemName == nil) then
  4497.         zz (" !!!!!!!!!!!!!!   itemName == nil");
  4498.         return;
  4499.     end
  4500.  
  4501.     if (not AUCTIONATOR_PRICING_HISTORY[itemName] ) then
  4502.         AUCTIONATOR_PRICING_HISTORY[itemName] = {};
  4503.     end
  4504.  
  4505.     local itemId, suffixId, uniqueId = zc.ItemIDfromLink (itemLink);
  4506.  
  4507.     local is = itemId;
  4508.  
  4509.     if (suffixId ~= 0) then
  4510.         is = is..":"..suffixId;
  4511.         if (tonumber(suffixId) < 0) then
  4512.             is = is..":"..uniqueId;
  4513.         end
  4514.     end
  4515.  
  4516.     AUCTIONATOR_PRICING_HISTORY[itemName]["is"]  = is;
  4517.  
  4518.     local hist = tostring (zc.round (price))..":"..stacksize;
  4519.  
  4520.     local roundtime = floor (time() / 60) * 60;     -- so multiple auctions close together don't generate too many entries
  4521.  
  4522.     local tag = tostring(ToTightTime(roundtime));
  4523.  
  4524.     if (testwhen) then
  4525.         tag = tostring(ToTightTime(testwhen));
  4526.     end
  4527.  
  4528.     AUCTIONATOR_PRICING_HISTORY[itemName][tag] = hist;
  4529.  
  4530.     gCurrentPane.sortedHist = nil;
  4531.  
  4532. end
  4533.  
  4534. -----------------------------------------
  4535.  
  4536. function Atr_HasHistoricalData (itemName)
  4537.  
  4538.     if (AUCTIONATOR_PRICING_HISTORY[itemName] ) then
  4539.         return true;
  4540.     end
  4541.  
  4542.     return false;
  4543. end
  4544.  
  4545.  
  4546. -----------------------------------------
  4547.  
  4548. local function sortHistoryList (x, y)
  4549.  
  4550.     return (x.name < y.name)
  4551.  
  4552. end
  4553.  
  4554. -----------------------------------------
  4555.  
  4556. function Atr_BuildGlobalHistoryList()
  4557.  
  4558.     gHistoryItemList    = {};
  4559.  
  4560.     if (zc.tableIsEmpty (gActiveAuctions)) then
  4561.         Atr_BuildActiveAuctions()
  4562.     end
  4563.  
  4564.     local info, IDstring
  4565.     for IDstring, info in pairs (gActiveAuctions) do
  4566.         if (info.link and info.count ~= 0) then
  4567.             table.insert (gHistoryItemList, info)
  4568.         end
  4569.     end
  4570.  
  4571.     table.sort (gHistoryItemList, sortHistoryList);
  4572. end
  4573.  
  4574.  
  4575.  
  4576. -----------------------------------------
  4577.  
  4578. function Atr_FindHListIndexByLink (itemLink)
  4579.  
  4580.     local x;
  4581.  
  4582.     for x = 1, #gHistoryItemList do
  4583.         if (itemLink == gHistoryItemList[x].link) then
  4584.             return x;
  4585.         end
  4586.     end
  4587.  
  4588.     return 0;
  4589.  
  4590. end
  4591.  
  4592. -----------------------------------------
  4593.  
  4594. local gAtr_CheckingActive_State         = ATR_CACT_NULL
  4595. local gAtr_CheckingActive_AndCancel     = false
  4596. local gAtr_CheckingActive_Index
  4597. local gAtr_CheckingActive_NextItemName
  4598. local gAtr_CheckingActive_NextItemLink
  4599.  
  4600. gAtr_CheckingActive_NumUndercuts    = 0;
  4601.  
  4602.  
  4603. -----------------------------------------
  4604.  
  4605. function Atr_CheckActive_OnClick (andCancel)
  4606.  
  4607.     if (gAtr_CheckingActive_State == ATR_CACT_NULL) then
  4608.  
  4609.         Atr_CheckActiveList (andCancel);
  4610.  
  4611.     else        -- stop checking
  4612.         Atr_CheckingActive_Finish ();
  4613.         gCurrentPane.activeSearch:Abort();
  4614.         gCurrentPane:ClearSearch();
  4615.         Atr_SetMessage(ZT("Checking stopped"));
  4616.     end
  4617.  
  4618. end
  4619.  
  4620.  
  4621. -----------------------------------------
  4622.  
  4623. function Atr_CheckActiveList (andCancel)
  4624.  
  4625.     if (#gHistoryItemList == 0) then
  4626.         return
  4627.     end
  4628.  
  4629.     gAtr_CheckingActive_State           = ATR_CACT_READY;
  4630.     gAtr_CheckingActive_NextItemName    = gHistoryItemList[1].name;
  4631.     gAtr_CheckingActive_NextItemLink    = gHistoryItemList[1].link;
  4632.     gAtr_CheckingActive_AndCancel       = andCancel;
  4633.     gAtr_CheckingActive_NumUndercuts    = 0;
  4634.  
  4635.     Atr_SetToShowCurrent();
  4636.  
  4637.     Atr_CheckingActiveIdle ();
  4638.  
  4639. end
  4640.  
  4641. -----------------------------------------
  4642.  
  4643. function Atr_CheckingActive_Finish()
  4644.  
  4645.     gAtr_CheckingActive_State = ATR_CACT_NULL;      -- done
  4646.  
  4647.     Atr_CheckActiveButton:SetText(ZT("Check for Undercuts"));
  4648.  
  4649. end
  4650.  
  4651.  
  4652.  
  4653. -----------------------------------------
  4654.  
  4655. function Atr_CheckingActiveIdle()
  4656.  
  4657.     if (gAtr_CheckingActive_State == ATR_CACT_READY) then
  4658.         if (gAtr_CheckingActive_NextItemName == nil) then
  4659.  
  4660.             Atr_CheckingActive_Finish ();
  4661.  
  4662.             if (gAtr_CheckingActive_NumUndercuts > 0) then
  4663.                 Atr_ResetMassCancel();
  4664.                 Atr_CheckActives_Frame:Show();
  4665.             end
  4666.  
  4667.         else
  4668.             gAtr_CheckingActive_State = ATR_CACT_PROCESSING;
  4669.  
  4670.             Atr_CheckActiveButton:SetText(ZT("Stop Checking"))
  4671.  
  4672.             local itemName = gAtr_CheckingActive_NextItemName
  4673.             local itemLink = gAtr_CheckingActive_NextItemLink
  4674.  
  4675.             local x = Atr_FindHListIndexByLink (itemLink);
  4676.  
  4677.             gAtr_CheckingActive_NextItemName = nil
  4678.             gAtr_CheckingActive_NextItemLink = nil
  4679.  
  4680.             if ((x > 0 and #gHistoryItemList >= x+1)) then
  4681.                 gAtr_CheckingActive_NextItemName = gHistoryItemList[x+1].name
  4682.                 gAtr_CheckingActive_NextItemLink = gHistoryItemList[x+1].link
  4683.             end
  4684.  
  4685.             local IDstring = zc.ItemIDStrfromLink (itemLink)
  4686.  
  4687.             gCurrentPane:DoSearch (itemName, IDstring, itemLink)   -- don't use a rescanThreshold as events won't fire properly for different items with the same name
  4688.  
  4689.             Atr_Hilight_Hentry (itemLink);
  4690.         end
  4691.     end
  4692. end
  4693.  
  4694.  
  4695. -----------------------------------------
  4696.  
  4697. function Atr_CheckActive_IsBusy()
  4698.  
  4699.     return (gAtr_CheckingActive_State ~= ATR_CACT_NULL);
  4700.  
  4701. end
  4702.  
  4703. -----------------------------------------
  4704.  
  4705. function Atr_CheckingActive_OnSearchComplete()
  4706.  
  4707.     if (gAtr_CheckingActive_State == ATR_CACT_PROCESSING) then
  4708.  
  4709.         if (gAtr_CheckingActive_AndCancel) then
  4710.             zc.AddDeferredCall (0.1, "Atr_CheckingActive_CheckCancel");     -- need to defer so UI can update and show auctions about to be canceled
  4711.         else
  4712.             zc.AddDeferredCall (0.1, "Atr_CheckingActive_Next");            -- need to defer so UI can update
  4713.         end
  4714.     end
  4715. end
  4716.  
  4717. -----------------------------------------
  4718.  
  4719. function Atr_CheckingActive_CheckCancel()
  4720.  
  4721.     if (gAtr_CheckingActive_State == ATR_CACT_PROCESSING) then
  4722.  
  4723.         Atr_CancelUndercuts_CurrentScan(false);
  4724.  
  4725.         if (gAtr_CheckingActive_State ~= ATR_CACT_WAITING_ON_CANCEL_CONFIRM) then
  4726.             zc.AddDeferredCall (0.1, "Atr_CheckingActive_Next");        -- need to defer so UI can update
  4727.         end
  4728.     end
  4729.  
  4730. end
  4731.  
  4732. -----------------------------------------
  4733.  
  4734. function Atr_CheckingActive_Next ()
  4735.  
  4736.     if (gAtr_CheckingActive_State == ATR_CACT_PROCESSING) then
  4737.         gAtr_CheckingActive_State = ATR_CACT_READY;
  4738.     end
  4739. end
  4740.  
  4741.  
  4742. -----------------------------------------
  4743.  
  4744. function Atr_CancelUndercut_Confirm (yesCancel)
  4745.     gAtr_CheckingActive_State = ATR_CACT_PROCESSING;
  4746.     Atr_CancelAuction_Confirm_Frame:Hide();
  4747.     if (yesCancel) then
  4748.         Atr_CancelUndercuts_CurrentScan(true);
  4749.     end
  4750.     zc.AddDeferredCall (0.1, "Atr_CheckingActive_Next");
  4751. end
  4752.  
  4753. -----------------------------------------
  4754.  
  4755. function Atr_CancelUndercuts_CurrentScan(confirmed)
  4756.  
  4757.     local scan = gCurrentPane.activeScan;
  4758.  
  4759.     for x = #scan.sortedData,1,-1 do
  4760.  
  4761.         local data = scan.sortedData[x];
  4762.  
  4763.         if (data.yours and data.itemPrice > scan.absoluteBest.itemPrice) then
  4764.  
  4765.             if (not confirmed) then
  4766.                 gAtr_CheckingActive_State = ATR_CACT_WAITING_ON_CANCEL_CONFIRM;
  4767.                 Atr_CancelAuction_Confirm_Frame_text:SetText (string.format (ZT("Your auction has been undercut:\n%s%s"), "|cffffffff", scan.itemName));
  4768.                 Atr_CancelAuction_Confirm_Frame:Show ();
  4769.                 return;
  4770.             end
  4771.  
  4772.             Atr_CancelAuction_ByIndex (x);
  4773.         end
  4774.     end
  4775.  
  4776. end
  4777.  
  4778. -----------------------------------------
  4779.  
  4780. local gAtr_MassCancelList = {};
  4781.  
  4782. -----------------------------------------
  4783.  
  4784. function Atr_ResetMassCancel ()
  4785.  
  4786.     gAtr_MassCancelList = {};
  4787.  
  4788.     local i;
  4789.     local num = Atr_GetNumAuctionItems ("owner");
  4790.     local x = 1;
  4791.  
  4792.     -- build the list of items to cancel
  4793.  
  4794.     for i = 1, num do
  4795.         local name, _, stackSize, _, _, _, _, _, _, buyoutPrice = GetAuctionItemInfo ("owner", i);
  4796.  
  4797.         if (name) then
  4798.             local itemLink = GetAuctionItemLink ("owner", i)
  4799.             local IDstring = zc.ItemIDStrfromLink (itemLink)
  4800.  
  4801.             local scan = Atr_FindScan (IDstring);
  4802.             if (scan and scan.absoluteBest and scan.whenScanned ~= 0 and scan.yourBestPrice and scan.yourWorstPrice) then
  4803.  
  4804.                 local absBestPrice = scan.absoluteBest.itemPrice;
  4805.  
  4806.                 if (stackSize > 0) then
  4807.                     local itemPrice = math.floor (buyoutPrice / stackSize);
  4808.  
  4809. --                  zc.md (i, name, "itemPrice: ", itemPrice, "absBestPrice: ", absBestPrice);
  4810.  
  4811.                     if (itemPrice > absBestPrice) then
  4812.  
  4813.                         gAtr_MassCancelList[x] = {};
  4814.                         gAtr_MassCancelList[x].index        = i;
  4815.                         gAtr_MassCancelList[x].name         = name;
  4816.                         gAtr_MassCancelList[x].link         = itemLink;
  4817.                         gAtr_MassCancelList[x].buyout       = buyoutPrice;
  4818.                         gAtr_MassCancelList[x].stackSize    = stackSize;
  4819.                         gAtr_MassCancelList[x].itemPrice    = itemPrice;
  4820.                         gAtr_MassCancelList[x].absBestPrice = absBestPrice;
  4821.                         x = x + 1;
  4822.  
  4823.                     end
  4824.                 end
  4825.             end
  4826.         end
  4827.     end
  4828.  
  4829.     Atr_CheckActives_Text:SetText (string.format (ZT("%d of your auctions are not the lowest priced.\n\nWould you like to cancel them?"), #gAtr_MassCancelList));
  4830.  
  4831.     Atr_CheckActives_Yes_Button:Enable();
  4832.     Atr_CheckActives_Yes_Button:SetText (ZT("Start canceling"));
  4833.     Atr_CheckActives_No_Button:SetText (ZT("No, leave them"));
  4834. end
  4835.  
  4836. -----------------------------------------
  4837.  
  4838. function Atr_Cancel_Undercuts_OnClick ()
  4839.  
  4840.     if (#gAtr_MassCancelList == 0) then
  4841.         return;
  4842.     end
  4843.  
  4844.     local success = Atr_Cancel_One_Undercuts_OnClick ()
  4845.  
  4846.     if (not success) then
  4847.         Atr_ResetMassCancel();
  4848.     end
  4849.  
  4850.     Atr_CheckActives_Text:SetText (string.format (ZT("%d of your auctions are not the lowest priced.\n\nWould you like to cancel them?"), #gAtr_MassCancelList));
  4851.  
  4852.     if (#gAtr_MassCancelList == 0) then
  4853.         Atr_CheckActives_Yes_Button:Disable();
  4854.         PlaySound ("AuctionWindowClose");
  4855.     else
  4856.         Atr_CheckActives_Yes_Button:Enable();
  4857.     end
  4858.  
  4859.     Atr_CheckActives_Yes_Button:SetText (ZT("Keep going"));
  4860.     Atr_CheckActives_No_Button:SetText (ZT("Done"));
  4861.  
  4862. end
  4863.  
  4864. -----------------------------------------
  4865.  
  4866. function Atr_Cancel_One_Undercuts_OnClick ()
  4867.  
  4868.     local x = #gAtr_MassCancelList;
  4869.  
  4870.     local i             = gAtr_MassCancelList[x].index;
  4871.     local name          = gAtr_MassCancelList[x].name;
  4872.     local link          = gAtr_MassCancelList[x].link;
  4873.     local buyout        = gAtr_MassCancelList[x].buyout;
  4874.     local stackSize     = gAtr_MassCancelList[x].stackSize;
  4875.     local itemPrice     = gAtr_MassCancelList[x].itemPrice;
  4876.     local absBestPrice  = gAtr_MassCancelList[x].absBestPrice;
  4877.  
  4878.     if (not Atr_DoesAuctionMatch ("owner", i, name, buyout, stackSize)) then
  4879.         return false;
  4880.     end
  4881.  
  4882.     table.remove ( gAtr_MassCancelList);
  4883.  
  4884.     Atr_CancelAuction (i);
  4885.  
  4886. --  zc.md (" index:", i, "  ", name, " price:", itemPrice, "  best price:", absBestPrice);
  4887.  
  4888.     AuctionatorSubtractFromScan (link, stackSize, buyout);
  4889.     Atr_LogCancelAuction (1, link, stackSize);
  4890.     gJustPosted.ItemName = nil;
  4891.  
  4892.     Atr_DisplayHlist();
  4893.  
  4894.     return true;
  4895.  
  4896. end
  4897.  
  4898. -----------------------------------------
  4899.  
  4900. function Atr_Hilight_Hentry(itemLink)
  4901.  
  4902.     for line = 1,ITEM_HIST_NUM_LINES do
  4903.  
  4904.         dataOffset = line + FauxScrollFrame_GetOffset (Atr_Hlist_ScrollFrame);
  4905.  
  4906.         local lineEntry = _G["AuctionatorHEntry"..line];
  4907.  
  4908.         if (dataOffset <= #gHistoryItemList and gHistoryItemList[dataOffset]) then
  4909.  
  4910.             if (gHistoryItemList[dataOffset].link == itemLink) then
  4911.                 lineEntry:SetButtonState ("PUSHED", true);
  4912.             else
  4913.                 lineEntry:SetButtonState ("NORMAL", false);
  4914.             end
  4915.         end
  4916.     end
  4917. end
  4918.  
  4919. -----------------------------------------
  4920.  
  4921. function Atr_Item_Autocomplete(self)
  4922.  
  4923.     local text = self:GetText();
  4924.     local textlen = strlen(text);
  4925.     local name;
  4926.  
  4927.     -- first search shopping lists
  4928.  
  4929.     local numLists = #AUCTIONATOR_SHOPPING_LISTS;
  4930.     local n;
  4931.  
  4932.     for n = 1,numLists do
  4933.         local slist = AUCTIONATOR_SHOPPING_LISTS[n];
  4934.  
  4935.         local numItems = #slist.items;
  4936.  
  4937.         if ( numItems > 0 ) then
  4938.             for i=1, numItems do
  4939.                 name = slist.items[i];
  4940.                 if ( name and text and (strfind(strupper(name), strupper(text), 1, 1) == 1) ) then
  4941.                     self:SetText(name);
  4942.                     if ( self:IsInIMECompositionMode() ) then
  4943.                         self:HighlightText(textlen - strlen(arg1), -1);
  4944.                     else
  4945.                         self:HighlightText(textlen, -1);
  4946.                     end
  4947.                     return;
  4948.                 end
  4949.             end
  4950.         end
  4951.     end
  4952.  
  4953.     -- next search posted DB
  4954.  
  4955.     numItems = #gHistoryItemList;
  4956.  
  4957.     if ( numItems > 0 ) then
  4958.         for i=1, numItems do
  4959.             name = gHistoryItemList[i].name;
  4960.             if ( name and text and (strfind(strupper(name), strupper(text), 1, 1) == 1) ) then
  4961.                 self:SetText(name);
  4962.                 if ( self:IsInIMECompositionMode() ) then
  4963.                     self:HighlightText(textlen - strlen(arg1), -1);
  4964.                 else
  4965.                     self:HighlightText(textlen, -1);
  4966.                 end
  4967.                 return;
  4968.             end
  4969.         end
  4970.     end
  4971.  
  4972.     -- next search the scan db
  4973. --[[
  4974.     local info;
  4975.     for name, info in pairs(gAtr_ScanDB) do
  4976.         if ( name and text and (strfind(strupper(name), strupper(text), 1, 1) == 1) ) then
  4977.             self:SetText(name);
  4978.             if ( self:IsInIMECompositionMode() ) then
  4979.                 self:HighlightText(textlen - strlen(arg1), -1);
  4980.             else
  4981.                 self:HighlightText(textlen, -1);
  4982.             end
  4983.             return;
  4984.         end
  4985.     end
  4986. ]]--
  4987.  
  4988. end
  4989.  
  4990. -----------------------------------------
  4991.  
  4992. function Atr_GetCurrentPane ()          -- so other modules can use gCurrentPane
  4993.     return gCurrentPane;
  4994. end
  4995.  
  4996. -----------------------------------------
  4997.  
  4998. function Atr_SetUINeedsUpdate ()            -- so other modules can easily set
  4999.     gCurrentPane.UINeedsUpdate = true;
  5000. end
  5001.  
  5002.  
  5003. -----------------------------------------
  5004.  
  5005. function Atr_CalcUndercutPrice (price)
  5006.  
  5007.     if  (price > 5000000)   then return roundPriceDown (price, AUCTIONATOR_SAVEDVARS._5000000); end;
  5008.     if  (price > 1000000)   then return roundPriceDown (price, AUCTIONATOR_SAVEDVARS._1000000); end;
  5009.     if  (price >  200000)   then return roundPriceDown (price, AUCTIONATOR_SAVEDVARS._200000);  end;
  5010.     if  (price >   50000)   then return roundPriceDown (price, AUCTIONATOR_SAVEDVARS._50000);   end;
  5011.     if  (price >   10000)   then return roundPriceDown (price, AUCTIONATOR_SAVEDVARS._10000);   end;
  5012.     if  (price >    2000)   then return roundPriceDown (price, AUCTIONATOR_SAVEDVARS._2000);    end;
  5013.     if  (price >     500)   then return roundPriceDown (price, AUCTIONATOR_SAVEDVARS._500);     end;
  5014.     if  (price >       0)   then return math.floor (price - 1); end;
  5015.  
  5016.     return 0;
  5017. end
  5018.  
  5019. -----------------------------------------
  5020.  
  5021. function Atr_CalcStartPrice (buyoutPrice)
  5022.  
  5023.     local discount = 1.00 - (AUCTIONATOR_SAVEDVARS.STARTING_DISCOUNT / 100);
  5024.  
  5025.     local newStartPrice = math.floor(buyoutPrice * discount);
  5026.  
  5027.     if (AUCTIONATOR_SAVEDVARS.STARTING_DISCOUNT == 0) then      -- zero means zero
  5028.         newStartPrice = buyoutPrice;
  5029.     end
  5030.  
  5031.     return newStartPrice;
  5032.  
  5033. end
  5034.  
  5035. -----------------------------------------
  5036.  
  5037. function Atr_AbbrevItemName (itemName)
  5038.  
  5039.     return string.gsub (itemName, "Scroll of Enchant", "SoE");
  5040.  
  5041. end
  5042.  
  5043. -----------------------------------------
  5044.  
  5045. function Atr_IsMyToon (name)
  5046.  
  5047.     if (name and (AUCTIONATOR_TOONS[name] or AUCTIONATOR_TOONS[string.lower(name)])) then
  5048.         return true;
  5049.     end
  5050.  
  5051.     return false;
  5052. end
  5053.  
  5054. -----------------------------------------
  5055.  
  5056. function Atr_Error_Display (errmsg)
  5057.     if (errmsg) then
  5058.         Atr_Error_Text:SetText (errmsg);
  5059.         Atr_Error_Frame:Show ();
  5060.         return;
  5061.     end
  5062. end
  5063.  
  5064.  
  5065.  
  5066. -----------------------------------------
  5067. -- roundPriceDown - rounds a price down to the next lowest multiple of a.
  5068. --                - if the result is not at least a/2 lower, rounds down by a/2.
  5069. --
  5070. --  examples:   (128790, 500)  ->  128500
  5071. --              (128700, 500)  ->  128000
  5072. --              (128400, 500)  ->  128000
  5073. -----------------------------------------
  5074.  
  5075. function roundPriceDown (price, a)
  5076.  
  5077.     if (a == 0) then
  5078.         return price;
  5079.     end
  5080.  
  5081.     local newprice = math.floor((price-1) / a) * a;
  5082.  
  5083.     if ((price - newprice) < a/2) then
  5084.         newprice = newprice - a;
  5085.     end
  5086.  
  5087.     if (newprice == price) then
  5088.         newprice = newprice - 1;
  5089.     end
  5090.  
  5091.     return newprice;
  5092.  
  5093. end
  5094.  
  5095. -----------------------------------------
  5096.  
  5097. function ToTightHour(t)
  5098.  
  5099.     return floor((t - gTimeTightZero)/3600);
  5100.  
  5101. end
  5102.  
  5103. -----------------------------------------
  5104.  
  5105. function FromTightHour(tt)
  5106.  
  5107.     return (tt*3600) + gTimeTightZero;
  5108.  
  5109. end
  5110.  
  5111.  
  5112. -----------------------------------------
  5113.  
  5114. function ToTightTime(t)
  5115.  
  5116.     return floor((t - gTimeTightZero)/60);
  5117.  
  5118. end
  5119.  
  5120. -----------------------------------------
  5121.  
  5122. function FromTightTime(tt)
  5123.  
  5124.     return (tt*60) + gTimeTightZero;
  5125.  
  5126. end
  5127.  
  5128.  
  5129. ------------ Modified code by j311yf1sh --------------
  5130. function Atr_SwitchSizeButton_OnClick()
  5131.     local NumOf = Atr_Batch_NumAuctions:GetNumber()
  5132.     local StackSize = Atr_Batch_Stacksize:GetNumber()
  5133.     Atr_Batch_NumAuctions:SetNumber(StackSize)
  5134.     Atr_Batch_Stacksize:SetNumber(NumOf)
  5135.  
  5136.     --print(NumOf,StackSize)
  5137. end
  5138. ------------ End modified code by j311yf1sh ---------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement