diff --git a/Aux-Addon.toc b/Aux-Addon.toc index fd902ab..e1334f2 100644 --- a/Aux-Addon.toc +++ b/Aux-Addon.toc @@ -4,6 +4,7 @@ ## SavedVariablesPerCharacter: AUX_SELL_SHORTCUT, AUX_BUY_SHORTCUT, AUX_OPEN_SELL, AUX_OPEN_BUY, AUX_INSTANT_BUYOUT, AUX_AUCTION_DURATION ## SavedVariables: auxSellEntries core.xml +control.xml sell.xml buy.xml diff --git a/buy.lua b/buy.lua index 37710f3..24d5ab0 100644 --- a/buy.lua +++ b/buy.lua @@ -1,6 +1,6 @@ Aux.buy = {} -local record_auction, set_message, report, tooltip_match, show_buyout_dialog, show_bid_dialog +local process_auction, set_message, report, tooltip_match, show_dialog local entries local selectedEntries = {} local search_query @@ -10,15 +10,14 @@ local refresh function Aux.buy.exit() - - Aux.buy.buyout_dialog_cancel() + Aux.buy.dialog_cancel() current_page = nil end ----------------------------------------- -function Aux_AuctionFrameBids_Update() - Aux.orig.AuctionFrameBids_Update() +function Aux_AuctionFrameBid_Update() + Aux.orig.AuctionFrameBid_Update() if PanelTemplates_GetSelectedTab(AuctionFrame) == Aux.tabs.buy.index and AuctionFrame:IsShown() then Aux_HideElems(Aux.tabs.buy.hiddenElements) end @@ -26,9 +25,9 @@ end ----------------------------------------- -function Aux.buy.buyout_dialog_cancel() +function Aux.buy.dialog_cancel() Aux.scan.abort() - AuxBuyBuyoutDialog:Hide() + AuxBuyDialog:Hide() AuxBuySearchButton:Enable() end @@ -69,30 +68,19 @@ function Aux.buy.SearchButton_onclick() Aux.scan.start{ query = search_query, page = 0, - on_start_page = function(k, i) - current_page = i - set_message('Scanning auctions: page ' .. i + 1 .. ' ...') - k() + on_start_page = function(k, page) + current_page = page + set_message('Scanning auctions: page ' .. page + 1 .. ' ...') + return k() end, on_read_auction = function(k, i) local auction_item = Aux.info.auction_item(i) if auction_item then - local stack_size = auction_item.charges or auction_item.count if (auction_item.name == search_query.name or search_query.name == '' or not AuxBuyExactCheckButton:GetChecked()) and tooltip_match(tooltip_patterns, auction_item.tooltip) then - record_auction( - auction_item.name, - auction_item.tooltip, - stack_size, - auction_item.buyout_price, - auction_item.quality, - auction_item.owner, - auction_item.hyperlink, - auction_item.itemstring, - current_page - ) + process_auction(auction_item, current_page) end end - k() + return k() end, on_complete = function() entries = entries or {} @@ -123,11 +111,12 @@ function set_message(msg) end ----------------------------------------- -function show_buyout_dialog(hyperlink, stack_size, buyout_price) - AuxBuyBuyoutDialogBuyButton:Disable() - AuxBuyBuyoutDialogHTML:SetFontObject('h1', GameFontWhite) - AuxBuyBuyoutDialogHTML:SetScript('OnHyperlinkClick', function() SetItemRef(arg1) end) - AuxBuyBuyoutDialogHTML:SetText(string.format( + +function show_dialog(buyout_mode, hyperlink, stack_size, amount) + AuxBuyDialogActionButton:Disable() + AuxBuyDialogHTML:SetFontObject('h1', GameFontWhite) + AuxBuyDialogHTML:SetScript('OnHyperlinkClick', function() SetItemRef(arg1) end) + AuxBuyDialogHTML:SetText(string.format( [[ @@ -138,108 +127,116 @@ function show_buyout_dialog(hyperlink, stack_size, buyout_price) hyperlink, stack_size )) - --MoneyFrame_Update('AuxBuyBuyoutDialogBuyoutPrice', Aux_Round(buyout_price)) - AuxBuyBuyoutDialog:Show() + if buyout_mode then + AuxBuyDialogActionButton:SetText('Buy') + MoneyFrame_Update('AuxBuyDialogBuyoutPrice', amount) + AuxBuyDialogBid:Hide() + AuxBuyDialogBuyoutPrice:Show() + else + AuxBuyDialogActionButton:SetText('Bid') + MoneyInputFrame_SetCopper(AuxBuyDialogBid, amount) + AuxBuyDialogBuyoutPrice:Hide() + AuxBuyDialogBid:Show() + end + AuxBuyDialog:Show() end -function show_bid_dialog(hyperlink, stack_size, bid) - AuxBuyBidDialogBidButton:Disable() - AuxBuyBidDialogHTML:SetFontObject('h1', GameFontWhite) - AuxBuyBidDialogHTML:SetScript('OnHyperlinkClick', function() SetItemRef(arg1) end) - AuxBuyBidDialogHTML:SetText(string.format( - [[ - - -

%s x %i

- - - ]], - hyperlink, - stack_size - )) - AuxBuyBidDialog:Show() - MoneyInputFrame_SetCopper(AuxBuyBidDialogBid, 5) -end +----------------------------------------- -function AuxBuyEntry_OnClick() - local express_mode = IsControlKeyDown() +function AuxBuyEntry_OnClick(entry_index) + local express_mode = IsAltKeyDown() + local buyout_mode = arg1 == "LeftButton" + + local entry = entries[entry_index] + + if buyout_mode and not entry.buyout_price then + return + end + + if IsControlKeyDown() then + DressUpItemLink(entry.hyperlink) + return + end AuxBuySearchButton:Disable() - local entry_index = this:GetID() - local entry = entries[entry_index] + local amount + if buyout_mode then + amount = entry.buyout_price + else + amount = entry.bid + end if not express_mode then - if arg1 == "LeftButton" then - show_buyout_dialog(entry.hyperlink, entry.stack_size, entry.buyout_price) - elseif arg1 == "RightButton" then - show_bid_dialog(entry.hyperlink, entry.stack_size, entry.buyout_price) - end + show_dialog(buyout_mode, entry.hyperlink, entry.stack_size, amount) end PlaySound("igMainMenuOptionCheckBoxOn") local found - local order_key = Aux.auction_key(entry.tooltip, entry.stack_size, entry.buyout_price) + local order_key = Aux.auction_key(entry.tooltip, entry.stack_size, amount) Aux.scan.start{ query = search_query, page = entry.page ~= current_page and entry.page, - on_start_page = function(k, page) + on_start_page = function(ok, page) current_page = page - k() + return ok() end, - on_read_auction = function(k, i) + on_read_auction = function(ok, i) local auction_item = Aux.info.auction_item(i) if not auction_item then - k() - return + return ok() end local stack_size = auction_item.charges or auction_item.count - - if not auction_item.tooltip or not stack_size or not auction_item.buyout_price then - k() - return - end + local bid = (auction_item.current_bid > 0 and auction_item.current_bid or auction_item.min_bid) + auction_item.min_increment - local key = Aux.auction_key(auction_item.tooltip, stack_size, auction_item.buyout_price) + local auction_amount + if buyout_mode then + auction_amount = auction_item.buyout_price + else + auction_amount = bid + end + + local key = Aux.auction_key(auction_item.tooltip, stack_size, auction_amount) + if key == order_key then found = true - - if express_mode then - if GetMoney() >= auction_item.buyout_price then + + if express_mode then + if GetMoney() >= amount then tremove(entries, entry_index) refresh = true end - PlaceAuctionBid("list", i, auction_item.buyout_price) + PlaceAuctionBid("list", i, amount) Aux.scan.abort() else - Aux.buy.buyout_dialog_buy = function() - if GetMoney() >= auction_item.buyout_price then + Aux.buy.dialog_action = function() + if GetMoney() >= amount then tremove(entries, entry_index) refresh = true end - PlaceAuctionBid("list", i, auction_item.buyout_price) + PlaceAuctionBid("list", i, amount) Aux.scan.abort() AuxBuySearchButton:Enable() - AuxBuyBuyoutDialog:Hide() + AuxBuyDialog:Hide() end - AuxBuyBuyoutDialogBuyButton:Enable() + AuxBuyDialogActionButton:Enable() end end - k() + return ok() end, on_complete = function() if not found then tremove(entries, entry_index) refresh = true - Aux.buy.buyout_dialog_cancel() + Aux.buy.dialog_cancel() end if express_mode then AuxBuySearchButton:Enable() @@ -253,9 +250,8 @@ function AuxBuyEntry_OnClick() } end -function AuxBuyEntry_OnEnter() - local i = this:GetID() - local entry = entries[i] +function AuxBuyEntry_OnEnter(entry_index) + local entry = entries[entry_index] Aux.info.set_game_tooltip(this, entry.tooltip) @@ -266,24 +262,31 @@ end ----------------------------------------- -function record_auction(name, tooltip, stack_size, buyout_price, quality, owner, hyperlink, itemstring, page) +function process_auction(auction_item, current_page) entries = entries or {} - if buyout_price > 0 and owner ~= UnitName("player") then + local stack_size = auction_item.charges or auction_item.count + local bid = auction_item.current_bid > 0 and auction_item.current_bid or auction_item.min_bid + auction_item.min_increment + local buyout_price = auction_item.buyout_price > 0 and auction_item.buyout_price or nil + local buyout_price_per_unit = buyout_price and Aux_Round(auction_item.buyout_price / stack_size) + + if auction_item.owner ~= UnitName("player") then tinsert(entries, { - name = name, - tooltip = tooltip, + name = auction_item.name, + tooltip = auction_item.tooltip, stack_size = stack_size, buyout_price = buyout_price, - item_price = buyout_price / stack_size, - quality = quality, - hyperlink = hyperlink, - itemstring = itemstring, + buyout_price_per_unit = buyout_price_per_unit, + quality = auction_item.quality, + hyperlink = auction_item.hyperlink, + itemstring = auction_item.itemstring, page = current_page, + bid = bid, + bid_per_unit = Aux_Round(bid / stack_size), + owner = auction_item.owner, + duration = auction_item.duration, }) end - - table.sort(entries, function(a,b) return a.item_price < b.item_price end) end ----------------------------------------- @@ -298,64 +301,17 @@ end ----------------------------------------- function Aux_Buy_ScrollbarUpdate() + Aux.list.populate(AuxBuyList, entries or {}) + + -- if entries then + -- table.sort(entries, function(a,b) return a.buyout_price_per_unit < b.buyout_price_per_unit end) + -- end + if entries and getn(entries) == 0 then set_message("No auctions were found") else AuxBuyMessage:Hide() end - - local numrows - if not entries then - numrows = 0 - else - numrows = getn(entries) - end - - FauxScrollFrame_Update(AuxBuyScrollFrame, numrows, 19, 16); - - for line = 1,19 do - - local dataOffset = line + FauxScrollFrame_GetOffset(AuxBuyScrollFrame) - local lineEntry = getglobal("AuxBuyEntry"..line) - - if numrows <= 19 then - lineEntry:SetWidth(800) - else - lineEntry:SetWidth(782) - end - - lineEntry:SetID(dataOffset) - - if dataOffset <= numrows and entries[dataOffset] then - - local entry = entries[dataOffset] - - local lineEntry_name = getglobal("AuxBuyEntry"..line.."_Name") - local lineEntry_stack_size = getglobal("AuxBuyEntry"..line.."_StackSize") - - local color = "ffffffff" - if Aux_QualityColor(entry.quality) then - color = Aux_QualityColor(entry.quality) - end - - lineEntry_name:SetText("\124c" .. color .. entry.name .. "\124r") - - if Aux.util.set_contains(selectedEntries, entry) then - lineEntry:LockHighlight() - else - lineEntry:UnlockHighlight() - end - - lineEntry_stack_size:SetText(entry.stack_size) - - MoneyFrame_Update("AuxBuyEntry"..line.."_UnitPrice", Aux_Round(entry.buyout_price/entry.stack_size)) - MoneyFrame_Update("AuxBuyEntry"..line.."_TotalPrice", Aux_Round(entry.buyout_price)) - - lineEntry:Show() - else - lineEntry:Hide() - end - end end ----------------------------------------- diff --git a/buy.xml b/buy.xml index 577fca5..d52f47f 100644 --- a/buy.xml +++ b/buy.xml @@ -10,95 +10,48 @@ - - - - - - - - + + @@ -109,47 +62,154 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -335,47 +395,10 @@ - - - - - - - - FauxScrollFrame_OnVerticalScroll(16, Aux_Buy_ScrollbarUpdate) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + this:RegisterForDrag("LeftButton") this:StartMoving() @@ -388,88 +411,37 @@ - + - - - - - - - - - - - SmallMoneyFrame_OnLoad() - MoneyFrame_SetType("STATIC") - snipe.log('kek'..this:GetName()) - - - - - - - - - - - - - - - - - - this:RegisterForDrag("LeftButton") - this:StartMoving() - this:StopMovingOrSizing() - - - - - - - - - - - - - - @@ -477,32 +449,4 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/control.lua b/control.lua index 2916c5a..b6a3bc5 100644 --- a/control.lua +++ b/control.lua @@ -1,45 +1,49 @@ Aux.control = {} local event_listeners = {} - local update_listeners = {} function Aux.control.on_event() for listener, _ in pairs(event_listeners) do - if event == listener.event then + if event == listener.event and not listener.deleted then listener.action() end end end function Aux.control.on_update() + event_listeners = Aux.util.set_filter(event_listeners, function(l) return not l.deleted end) + update_listeners = Aux.util.set_filter(update_listeners, function(l) return not l.deleted end) + for listener, _ in pairs(update_listeners) do - listener.action() + if not listener.deleted then + listener.action() + end end end -function Aux.control.event_listener(event, action) -- async! +function Aux.control.event_listener(event, action) local self = {} local listener = { event=event, action=action } - function self:set_action(self, action) + function self.set_action(action) listener.action = action end - function self:start(self) + function self.start() Aux.util.set_add(event_listeners, listener) - if not Aux.util.any(event_listeners, function(l) l.event == event end then + if not Aux.util.any(event_listeners, function(l) return l.event == event end) then AuxControlFrame:RegisterEvent(event) end return self end - function self:stop(self) - Aux.util.set_remove(event_listeners, listener) - if not Aux.util.any(event_listeners, function(l) l.event == event end then + function self.stop() + listener.deleted = true + if not Aux.util.any(event_listeners, function(l) return l.event == event end) then AuxControlFrame:UnregisterEvent(event) end return self @@ -53,84 +57,87 @@ function Aux.control.update_listener(action) local listener = { action=action } - function self:set_action(self, action) + function self.set_action(action) listener.action = action end - function self:start(self) + function self.start() Aux.util.set_add(update_listeners, listener) return self end - function self:stop(self) - Aux.util.set_remove(update_listeners, listener) + function self.stop() + listener.deleted = true return self end return self end - + function Aux.control.on_next_update(callback) local listener = Aux.control.update_listener() - listener:set_action(function() + listener.set_action(function() listener:stop() - callback() - end + return callback() + end) - listener:start() + listener.start() +end + +function Aux.control.on_next_event(event, callback) + local listener = Aux.control.event_listener(event) + + listener.set_action(function() + listener:stop() + return callback() + end) + + listener.start() end function Aux.control.as_soon_as(p, callback) local listener = Aux.control.update_listener() - listener:set_action(function() + listener.set_action(function() if p() then - callback() - listener:stop() + listener.stop() + return callback() end end) - listener:start() -end - -function Aux.control.on_next_event(event, callback) - local ok - - local listener = Aux.control.event_listener(event) - - listener:set_action(function() - listener:stop() - ok = true - end - - listener:start() - - Aux.control.as_soon_as(function() return ok end, callback) + listener.start() end -function Aux.control.timer() +function Aux.control.controller() local self = {} - local t_0 + local state - function self:start(self) - t_0 = GetTime() + local listener = Aux.control.update_listener() + listener.set_action(function() + if state and state.p() then + local k = state.k + state = nil + return k() + end + end) + listener.start() + + function self.wait(p, k) + state = { + k = k, + p = p, + } end - function self:after(self, t, callback) - Aux.util.as_soon_as(function() return t_0 and GetTime() - t_0 > t end, callback) + function self.cleanup() + listener.stop() end return self end - -function Aux.control.after_time(t, callback) - local timer = Aux.control.timer() - timer:start() - timer:after(t, callback) -end diff --git a/control.xml b/control.xml index e69de29..52db94d 100644 --- a/control.xml +++ b/control.xml @@ -0,0 +1,15 @@ + + +