From c4fb4be1c6cd5a4948b0b38bbd91180c17daf9a1 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Sat, 26 Sep 2015 00:35:09 +0200 Subject: [PATCH] implemented auto stack and multi post, auctions can now be cancelled with right click, posting an auction now adds it to the list without refresh necessary and selects it, charges not working yet --- Aux-Addon.toc | 5 +- core.lua | 51 ++++++++++++++- post.lua | 171 +++++++++++++++++++++--------------------------- post.xml | 11 ++++ sell.lua | 64 +++++++++++++++--- stack.lua | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++ stack.xml | 19 ++++++ 7 files changed, 388 insertions(+), 108 deletions(-) create mode 100644 post.xml create mode 100644 stack.lua create mode 100644 stack.xml diff --git a/Aux-Addon.toc b/Aux-Addon.toc index efcae28..2481d85 100644 --- a/Aux-Addon.toc +++ b/Aux-Addon.toc @@ -4,9 +4,10 @@ ## SavedVariablesPerCharacter: AUX_ENABLE_ALT, AUX_OPEN_FIRST, AUX_INSTANT_BUYOUT, AUX_AUCTION_DURATION ## SavedVariables: auxSellEntries core.xml -scan.xml sell.xml buy.xml +scan.xml +stack.xml +post.xml options.xml about.xml -post.lua diff --git a/core.lua b/core.lua index f477661..87af9e7 100644 --- a/core.lua +++ b/core.lua @@ -1,6 +1,8 @@ AuxVersion = "1.1.2" AuxAuthors = "shirsig; Zerf; Zirco (AUX); Nimeral (AUX backport)" +local lastRightClickAction = GetTime() + Aux = { loaded = false, orig = {}, @@ -117,6 +119,25 @@ function Aux_SetupHookFunctions() Aux.orig.BrowseButton_OnClick = BrowseButton_OnClick BrowseButton_OnClick = Aux_BrowseButton_OnClick + + AuctionsButton1:RegisterForClicks("LeftButtonUp", "RightButtonDown") + AuctionsButton1:SetScript("OnMouseDown", Aux_AuctionsButton_OnMouseDown) + AuctionsButton2:RegisterForClicks("LeftButtonUp", "RightButtonDown") + AuctionsButton2:SetScript("OnMouseDown", Aux_AuctionsButton_OnMouseDown) + AuctionsButton3:RegisterForClicks("LeftButtonUp", "RightButtonDown") + AuctionsButton3:SetScript("OnMouseDown", Aux_AuctionsButton_OnMouseDown) + AuctionsButton4:RegisterForClicks("LeftButtonUp", "RightButtonDown") + AuctionsButton4:SetScript("OnMouseDown", Aux_AuctionsButton_OnMouseDown) + AuctionsButton5:RegisterForClicks("LeftButtonUp", "RightButtonDown") + AuctionsButton5:SetScript("OnMouseDown", Aux_AuctionsButton_OnMouseDown) + AuctionsButton6:RegisterForClicks("LeftButtonUp", "RightButtonDown") + AuctionsButton6:SetScript("OnMouseDown", Aux_AuctionsButton_OnMouseDown) + AuctionsButton7:RegisterForClicks("LeftButtonUp", "RightButtonDown") + AuctionsButton7:SetScript("OnMouseDown", Aux_AuctionsButton_OnMouseDown) + AuctionsButton8:RegisterForClicks("LeftButtonUp", "RightButtonDown") + AuctionsButton8:SetScript("OnMouseDown", Aux_AuctionsButton_OnMouseDown) + AuctionsButton9:RegisterForClicks("LeftButtonUp", "RightButtonDown") + AuctionsButton9:SetScript("OnMouseDown", Aux_AuctionsButton_OnMouseDown) BrowseButton1:RegisterForClicks("LeftButtonUp", "RightButtonDown") BrowseButton1:SetScript("OnMouseDown", Aux_BrowseButton_OnMouseDown) @@ -170,6 +191,8 @@ end function Aux_OnAuctionHouseClosed() + Aux.post.stop() + Aux.stack.stop() if not Aux_Scan_IsIdle() then Aux_Scan_Abort() end @@ -190,6 +213,8 @@ function Aux_AuctionFrameTab_OnClick(index) index = this:GetID() end + Aux.post.stop() + Aux.stack.stop() if not Aux_Scan_IsIdle() then Aux_Scan_Abort() end @@ -375,8 +400,16 @@ end ----------------------------------------- +function Aux_AuctionsButton_OnClick(button) + if arg1 == "LeftButton" then -- because we additionally registered right clicks we only let left ones pass here + Aux.orig.BrowseButton_OnClick(button) + end +end + +----------------------------------------- + function Aux_BrowseButton_OnMouseDown() - if arg1 == "RightButton" and AUX_INSTANT_BUYOUT then + if arg1 == "RightButton" and AUX_INSTANT_BUYOUT and GetTime() - lastRightClickAction > 0.5 then local index = this:GetID() + FauxScrollFrame_GetOffset(BrowseScrollFrame) SetSelectedAuctionItem("list", index) @@ -387,6 +420,22 @@ function Aux_BrowseButton_OnMouseDown() end AuctionFrameBrowse_Update() + lastRightClickAction = GetTime() + end +end + +----------------------------------------- + +function Aux_AuctionsButton_OnMouseDown() + if arg1 == "RightButton" and GetTime() - lastRightClickAction > 0.5 then + local index = this:GetID() + FauxScrollFrame_GetOffset(AuctionsScrollFrame) + + SetSelectedAuctionItem("owner", index) + + CancelAuction(index) + + AuctionFrameAuctions_Update() + lastRightClickAction = GetTime() end end diff --git a/post.lua b/post.lua index 39e1d73..9c4ead7 100644 --- a/post.lua +++ b/post.lua @@ -1,106 +1,83 @@ -local target_size -local slot +Aux.post = {} +local state --- iterator for inventory -function inventory() - local inventory = {} - for bag = 0, 4 do - if GetBagName(bag) then - for bagSlot = 1, GetContainerNumSlots(bag) do - tinsert(inventory, { bag = bag, bagSlot = bagSlot }) +local post_auction + +function Aux.post.onupdate() + if state then + if state.auctioning then + if not GetContainerItemInfo(state.auctioning.bag, state.auctioning.bag_slot) then + state.auctioning = nil + state.posted = state.posted + 1 end end - end - - local i = 0 - local n = getn(inventory) - return function() - i = i + 1 - if i <= n then - return inventory[i] - end - end -end - -function findEmptySlot() - for slot in inventory() do - if not GetContainerItemInfo(slot.bag, slot.bagSlot) then - return slot - end - end -end - -function findItem(name) - local slots = {} - for slot in inventory() do - if itemName(slot) == name then - tinsert(slots, slot) - end - end - return slots -end - -function sameSlot(slot1, slot2) - return slot1.bag == slot2.bag and slot1.bagSlot == slot2.bagSlot -end - -function moveItem(fromSlot, toSlot, amount) - ClearCursor() - SplitContainerItem(fromSlot.bag, fromSlot.bagSlot, amount) - PickupContainerItem(toSlot.bag, toSlot.bagSlot) - ClearCursor() -end - -function itemName(slot) - local itemLink = GetContainerItemLink(slot.bag, slot.bagSlot) - if itemLink then - return string.gsub(itemLink, "^.-%[(.*)%].*", "%1") - end -end - -function stackSize(slot) - local _, itemCount = GetContainerItemInfo(slot.bag, slot.bagSlot) - return itemCount -end - -function postAuction(slot) - ClearCursor() - pickupContainerItem(slot.bag, slot.bagSlot) - ClickAuctionSellItemButton() - ClearCursor() - Aux.orig.AuctionsCreateAuctionButton_OnClick() - -- StartAuction(request.bid, request.buyout, request.duration); -end - -function createStack(name, size) - ClearCursor() - ClickAuctionSellItemButton() - ClearCursor() - - local slots = findItem(name) - local stackSlot = slots[1] - tremove(slots, 1) - - for _, slot in ipairs(slots) do - if stackSize(stackSlot) < size then - moveItem(slot, stackSlot, size - stackSize(stackSlot)) - elseif stackSize(stackSlot) > size then - moveItem(stackSlot, slot, stackSize(stackSlot) - size) + if state.posted < state.count then + if not state.stacking and not state.auctioning then + state.stacking = true + Aux.stack.start( + state.name, + state.stack_size, + function(slot) + if slot then + post_auction(slot) + else + Aux.post.stop() + end + end + ) + end else - return stackSlot - end - end - - if stackSize(stackSlot) > size then - local emptySlot = findEmptySlot() - Aux_Log(stackSize(stackSlot) .. ' : ' .. emptySlot.bag .. ' ' .. emptySlot.bagSlot) - moveItem(stackSlot, emptySlot, stackSize(stackSlot) - size) - Aux_Log(stackSize(stackSlot) .. ' : ' .. emptySlot.bag .. ' ' .. emptySlot.bagSlot) - if stackSize(stackSlot) == size then - return stackSlot + Aux.post.stop() end end end --- /script createStack('Dried King Bolete', 3) \ No newline at end of file +function Aux.post.stop() + if state then + local callback = state.callback + local posted = state.posted + + state = nil + PickupContainerItem = Aux.stack.orig.PickupContainerItem + SplitContainerItem = Aux.stack.orig.SplitContainerItem + + if callback then + callback(posted) + end + end +end + +function post_auction(slot) + ClearCursor() + ClickAuctionSellItemButton() + ClearCursor() + PickupContainerItem(slot.bag, slot.bag_slot) + ClickAuctionSellItemButton() + ClearCursor() + StartAuction(state.bid, state.buyout, state.duration) + state.auctioning = slot + state.stacking = false +end + +function Aux.post.start(name, stack_size, duration, bid, buyout, count, callback) + Aux.post.stop() + + ClearCursor() + ClickAuctionSellItemButton() + ClearCursor() + + PickupContainerItem = function() end + SplitContainerItem = function() end + + state = { + name = name, + stack_size = stack_size, + duration = duration, + bid = bid, + buyout = buyout, + count = count, + posted = 0, + callback = callback, + } +end \ No newline at end of file diff --git a/post.xml b/post.xml new file mode 100644 index 0000000..1bbdaa3 --- /dev/null +++ b/post.xml @@ -0,0 +1,11 @@ + +