From 3eb28c428175f2147cf29d3bd5a907e85b3f2ed8 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Mon, 1 Feb 2016 19:25:17 +0100 Subject: [PATCH] perfected the buying mechanism --- Aux-AddOn.toc | 10 +- auction_listing.lua | 144 ++++---- core.lua | 114 +----- core.xml | 2 +- item_search_frame.xml | 2 +- listing.lua | 9 +- post_frame.lua | 8 +- scan_util.lua | 2 +- filter_search_frame.lua => search_frame.lua | 375 ++++++++++---------- filter_search_frame.xml => search_frame.xml | 17 +- slash.lua | 4 +- groups.lua => test.lua | 72 ++-- 12 files changed, 331 insertions(+), 428 deletions(-) rename filter_search_frame.lua => search_frame.lua (78%) rename filter_search_frame.xml => search_frame.xml (86%) rename groups.lua => test.lua (84%) diff --git a/Aux-AddOn.toc b/Aux-AddOn.toc index a0c0b28..d211c68 100644 --- a/Aux-AddOn.toc +++ b/Aux-AddOn.toc @@ -1,7 +1,7 @@ ## Interface: 11200 ## Title: Aux ## Notes: A lightweight addon designed to help manage auctions -## SavedVariablesPerCharacter: aux_recent_searches, aux_favorite_searches, AUX_AUCTION_DURATION +## SavedVariablesPerCharacter: aux_recent_searches, aux_favorite_searches, aux_auction_duration, aux_scale ## SavedVariables: aux_database, aux_auctionable_items slash.lua @@ -11,7 +11,6 @@ control.xml persistence.lua util.lua money.lua -groups.lua scan.lua scan_util.lua @@ -25,12 +24,13 @@ history.lua info.xml completion.xml -item_search_frame.xml -filter_search_frame.xml +search_frame.xml post_frame.xml auctions_frame.xml bids_frame.xml -scan_frame.xml static.xml +test.lua + + diff --git a/auction_listing.lua b/auction_listing.lua index 580e5b4..d4fa137 100644 --- a/auction_listing.lua +++ b/auction_listing.lua @@ -119,7 +119,19 @@ local methods = { OnCellClick = function() local button = arg1 if this.rt.disabled then return end - this.rt:SetSelectedRecord(this.row.data.record) + if IsControlKeyDown() then + DressUpItemLink(this.row.data.record.hyperlink) + elseif IsShiftKeyDown() then + if ChatFrameEditBox:IsVisible() then + ChatFrameEditBox:Insert(this.row.data.record.hyperlink) + end + elseif IsAltKeyDown() then + if this.rt.handlers.OnCellAltClick then + this.rt.handlers.OnCellAltClick(this, button) + end + else + this.rt:SetSelectedRecord(this.row.data.record) + end end, OnCellDoubleClick = function() @@ -152,10 +164,10 @@ local methods = { end, - GetRecordPercent = function(rt, record) + GetRecordPercent = function(self, record) if not record then return end -- cache the market value on the record --- record.market_value = record.market_value or rt.GetMarketValue(record.item_key) or 0 +-- record.market_value = record.market_value or self.GetMarketValue(record.item_key) or 0 -- if record.marketValue > 0 then -- if record.itemBuyout > 0 then -- return Aux.round(100 * record.itemBuyout / record.marketValue, 1) @@ -172,15 +184,15 @@ local methods = { end end, - UpdateRowInfo = function(rt) - Aux.util.wipe(rt.rowInfo) - rt.rowInfo.numDisplayRows = 0 - rt.sortInfo.isSorted = nil - rt:SetSelectedRecord(nil, true) + UpdateRowInfo = function(self) + Aux.util.wipe(self.rowInfo) + self.rowInfo.numDisplayRows = 0 + self.sortInfo.isSorted = nil + self:SetSelectedRecord(nil, true) - sort(rt.records, function(a,b) return a.search_signature < b.search_signature end) + sort(self.records, function(a,b) return a.search_signature < b.search_signature end) - local records = rt.records + local records = self.records if getn(records) == 0 then return end -- Populate the row info from the database by combining identical auctions and auctions @@ -190,21 +202,21 @@ local methods = { local prevRecord = records[i-1] if prevRecord and record.search_signature == prevRecord.search_signature then -- it's an identical auction to the previous row so increment the number of auctions - rt.rowInfo[getn(rt.rowInfo)].children[getn(rt.rowInfo[getn(rt.rowInfo)].children)].numAuctions = rt.rowInfo[getn(rt.rowInfo)].children[getn(rt.rowInfo[getn(rt.rowInfo)].children)].numAuctions + 1 + self.rowInfo[getn(self.rowInfo)].children[getn(self.rowInfo[getn(self.rowInfo)].children)].numAuctions = self.rowInfo[getn(self.rowInfo)].children[getn(self.rowInfo[getn(self.rowInfo)].children)].numAuctions + 1 elseif prevRecord and record.item_key == prevRecord.item_key then -- it's the same base item as the previous row so insert a new auction - tinsert(rt.rowInfo[getn(rt.rowInfo)].children, {numAuctions=1, record=record}) - if rt.expanded[rt.rowInfo[getn(rt.rowInfo)].expandKey] then - rt.rowInfo.numDisplayRows = rt.rowInfo.numDisplayRows + 1 + tinsert(self.rowInfo[getn(self.rowInfo)].children, {numAuctions=1, record=record}) + if self.expanded[self.rowInfo[getn(self.rowInfo)].expandKey] then + self.rowInfo.numDisplayRows = self.rowInfo.numDisplayRows + 1 end else -- it's a different base item from the previous row - tinsert(rt.rowInfo, {item_key=record.item_key, expandKey=record.item_key, children={{numAuctions=1, record=record}}}) - rt.rowInfo.numDisplayRows = rt.rowInfo.numDisplayRows + 1 + tinsert(self.rowInfo, {item_key=record.item_key, expandKey=record.item_key, children={{numAuctions=1, record=record}}}) + self.rowInfo.numDisplayRows = self.rowInfo.numDisplayRows + 1 end end - for _, info in ipairs(rt.rowInfo) do + for _, info in ipairs(self.rowInfo) do local totalAuctions, totalPlayerAuctions = 0, 0 for _, childInfo in ipairs(info.children) do totalAuctions = totalAuctions + childInfo.numAuctions @@ -217,36 +229,36 @@ local methods = { end end, - UpdateRows = function(rt) + UpdateRows = function(self) -- hide all the rows - for _, row in ipairs(rt.rows) do row:Hide() end + for _, row in ipairs(self.rows) do row:Hide() end -- update sorting highlights - for _, cell in ipairs(rt.headCells) do + for _, cell in ipairs(self.headCells) do local tex = cell:GetNormalTexture() tex:SetTexture([[Interface\AddOns\Aux-AddOn\WorldStateFinalScore-Highlight]]) tex:SetTexCoord(0.017, 1, 0.083, 0.909) tex:SetAlpha(0.5) end - if rt.sortInfo.descending then - rt.headCells[rt.sortInfo.columnIndex]:GetNormalTexture():SetTexture(0.8, 0.6, 1, 0.8) + if self.sortInfo.descending then + self.headCells[self.sortInfo.columnIndex]:GetNormalTexture():SetTexture(0.8, 0.6, 1, 0.8) else - rt.headCells[rt.sortInfo.columnIndex]:GetNormalTexture():SetTexture(0.6, 0.8, 1, 0.8) + self.headCells[self.sortInfo.columnIndex]:GetNormalTexture():SetTexture(0.6, 0.8, 1, 0.8) end -- update the scroll frame - FauxScrollFrame_Update(rt.scrollFrame, rt.rowInfo.numDisplayRows, getn(rt.rows), rt.ROW_HEIGHT) + FauxScrollFrame_Update(self.scrollFrame, self.rowInfo.numDisplayRows, getn(self.rows), self.ROW_HEIGHT) -- make sure the offset is not too high - local maxOffset = max(rt.rowInfo.numDisplayRows - getn(rt.rows), 0) - if FauxScrollFrame_GetOffset(rt.scrollFrame) > maxOffset then - FauxScrollFrame_SetOffset(rt.scrollFrame, maxOffset) + local maxOffset = max(self.rowInfo.numDisplayRows - getn(self.rows), 0) + if FauxScrollFrame_GetOffset(self.scrollFrame) > maxOffset then + FauxScrollFrame_SetOffset(self.scrollFrame, maxOffset) end - if not rt.sortInfo.isSorted then + if not self.sortInfo.isSorted then local function SortHelperFunc(a, b, sortKey) local hadSortKey = sortKey and true or false - sortKey = sortKey or rt.sortInfo.sortKey + sortKey = sortKey or self.sortInfo.sortKey local aVal, bVal if a.children then aVal = a.children[1].record @@ -261,17 +273,17 @@ local methods = { return false end if sortKey == "percent" then - aVal = rt:GetRecordPercent(aVal) - bVal = rt:GetRecordPercent(bVal) + aVal = self:GetRecordPercent(aVal) + bVal = self:GetRecordPercent(bVal) elseif sortKey == "numAuctions" then aVal = a.totalAuctions bVal = b.totalAuctions elseif sortKey == "itemDisplayedBid" or sortKey == "displayedBid" then - aVal = rt.GetRowPrices(aVal, sortKey == "itemDisplayedBid") - bVal = rt.GetRowPrices(bVal, sortKey == "itemDisplayedBid") + aVal = self.GetRowPrices(aVal, sortKey == "itemDisplayedBid") + bVal = self.GetRowPrices(bVal, sortKey == "itemDisplayedBid") elseif sortKey == "itemBuyout" or sortKey == "buyout" then - aVal = ({ rt.GetRowPrices(aVal, sortKey == "itemBuyout") })[2] - bVal = ({ rt.GetRowPrices(bVal, sortKey == "itemBuyout") })[2] + aVal = ({ self.GetRowPrices(aVal, sortKey == "itemBuyout") })[2] + bVal = ({ self.GetRowPrices(bVal, sortKey == "itemBuyout") })[2] else aVal = aVal[sortKey] bVal = bVal[sortKey] @@ -279,15 +291,15 @@ local methods = { if sortKey == 'buyout' or sortKey == 'itemBuyout' then -- for buyout, put bid-only auctions at the bottom if not aVal or aVal == 0 then - aVal = (rt.sortInfo.descending and -1 or 1) * Aux.huge + aVal = (self.sortInfo.descending and -1 or 1) * Aux.huge end if not bVal or bVal == 0 then - bVal = (rt.sortInfo.descending and -1 or 1) * Aux.huge + bVal = (self.sortInfo.descending and -1 or 1) * Aux.huge end elseif sortKey == "percent" then -- for percent, put bid-only auctions at the bottom - aVal = aVal or ((rt.sortInfo.descending and -1 or 1) * Aux.huge) - bVal = bVal or ((rt.sortInfo.descending and -1 or 1) * Aux.huge) + aVal = aVal or ((self.sortInfo.descending and -1 or 1) * Aux.huge) + bVal = bVal or ((self.sortInfo.descending and -1 or 1) * Aux.huge) end if type(aVal) == "string" or type(bVal) == "string" then aVal = aVal or "" @@ -321,43 +333,43 @@ local methods = { -- sort arbitrarily, but make sure the sort is stable return tostring(a) < tostring(b) end - if rt.sortInfo.descending then + if self.sortInfo.descending then return aVal > bVal else return aVal < bVal end end -- sort the row info - for i, info in ipairs(rt.rowInfo) do + for i, info in ipairs(self.rowInfo) do sort(info.children, SortHelperFunc) end - sort(rt.rowInfo, SortHelperFunc) - rt.sortInfo.isSorted = true + sort(self.rowInfo, SortHelperFunc) + self.sortInfo.isSorted = true end -- update all the rows - local rowIndex = 1 - FauxScrollFrame_GetOffset(rt.scrollFrame) - for i, info in ipairs(rt.rowInfo) do - if rt.expanded[info.expandKey] then + local rowIndex = 1 - FauxScrollFrame_GetOffset(self.scrollFrame) + for i, info in ipairs(self.rowInfo) do + if self.expanded[info.expandKey] then -- show each of the rows for this base item since it's expanded for j, childInfo in ipairs(info.children) do - rt:SetRowInfo(rowIndex, childInfo.record, childInfo.numAuctions, 0, j > 1, false, info.expandKey, childInfo.numAuctions) + self:SetRowInfo(rowIndex, childInfo.record, childInfo.numAuctions, 0, j > 1, false, info.expandKey, childInfo.numAuctions) rowIndex = rowIndex + 1 end else -- just show one row for this base item since it's not expanded - rt:SetRowInfo(rowIndex, info.children[1].record, info.totalAuctions, getn(info.children) > 1 and info.totalPlayerAuctions or 0, false, getn(info.children) > 1, info.expandKey, info.children[1].numAuctions) + self:SetRowInfo(rowIndex, info.children[1].record, info.totalAuctions, getn(info.children) > 1 and info.totalPlayerAuctions or 0, false, getn(info.children) > 1, info.expandKey, info.children[1].numAuctions) rowIndex = rowIndex + 1 end end end, - SetRowInfo = function(rt, rowIndex, record, displayNumAuctions, numPlayerAuctions, indented, expandable, expandKey, numAuctions) - if rowIndex <= 0 or rowIndex > getn(rt.rows) then return end - local row = rt.rows[rowIndex] + SetRowInfo = function(self, rowIndex, record, displayNumAuctions, numPlayerAuctions, indented, expandable, expandKey, numAuctions) + if rowIndex <= 0 or rowIndex > getn(self.rows) then return end + local row = self.rows[rowIndex] -- show this row row:Show() - if rt.selected and record.search_signature == rt.selected.search_signature then + if self.selected and record.search_signature == self.selected.search_signature then row.highlight:Show() else row.highlight:Hide() @@ -394,10 +406,10 @@ local methods = { row.cells[4]:SetText(record.aux_quantity) row.cells[5]:SetText(TIME_LEFT_STRINGS[record.duration or 0] or "---") row.cells[6]:SetText(Aux.is_player(record.owner) and ("|cffffff00"..record.owner.."|r") or record.owner) - local bid, buyout, colorBid, colorBuyout = rt.GetRowPrices(record, aux_price_per_unit) + local bid, buyout, colorBid, colorBuyout = self.GetRowPrices(record, aux_price_per_unit) row.cells[7]:SetText(bid > 0 and Aux.money.to_string(bid, true, false, colorBid) or "---") row.cells[8]:SetText(buyout > 0 and Aux.money.to_string(buyout, true, false, colorBuyout) or "---") - local pct, bidPct = rt:GetRecordPercent(record) + local pct, bidPct = self:GetRecordPercent(record) local pctColor = '|cffffffff' if pct then for i=1, getn(AUCTION_PCT_COLORS) do @@ -417,25 +429,25 @@ local methods = { end end, - SetSelectedRecord = function(rt, record, silent) - if rt.disabled then return end + SetSelectedRecord = function(self, record, silent) + if self.disabled then return end -- make sure the selected record still exists and get the data for the callback - rt.selected = record - local selectedData = rt:GetSelection() - rt.selected = selectedData and rt.selected or nil + self.selected = record + local selectedData = self:GetSelection() + self.selected = selectedData and self.selected or nil -- show / hide highlight accordingly - for _, row in ipairs(rt.rows) do - if rt.selected and row.data and row.data.record.search_signature == rt.selected.search_signature then + for _, row in ipairs(self.rows) do + if self.selected and row.data and row.data.record.search_signature == self.selected.search_signature then row.highlight:Show() else row.highlight:Hide() end end - if not silent and rt.handlers.OnSelectionChanged and not rt.scrollDisabled then - rt.handlers.OnSelectionChanged(rt, selectedData or nil) + if not silent and self.handlers.OnSelectionChanged and not self.scrollDisabled then + self.handlers.OnSelectionChanged(self, selectedData or nil) end end, @@ -463,7 +475,7 @@ local methods = { -- rt.dbView:SetFilter(filterFunc, filterHash) -- TODO -- get index of selected row - local prevSelectedIndex = nil + local prevSelectedIndex if rt.selected then for index, row in ipairs(rt.rows) do if row:IsVisible() and row.data and row.data.record == rt.selected then @@ -494,7 +506,6 @@ local methods = { end, RemoveSelectedRecord = function(rt, count) --- TSMAPI:Assert(rt.selected) count = count or 1 for i=1, count do local index = Aux.util.index_of(rt.selected, rt.records) @@ -537,7 +548,6 @@ local methods = { end, SetHandler = function(rt, event, handler) --- TSMAPI:Assert(event == "OnSelectionChanged") rt.handlers[event] = handler end, @@ -718,7 +728,7 @@ function CreateAuctionResultsTable(parent) local text = cell:CreateFontString() text:SetFont(Aux.gui.config.content_font, min(14, rt.ROW_HEIGHT)) text:SetJustifyH(colInfo[j].align or 'LEFT') - text:SetJustifyV('MIDDLE') + text:SetJustifyV('CENTER') text:SetPoint('TOPLEFT', 1, -1) text:SetPoint('BOTTOMRIGHT', -1, 1) cell:SetFontString(text) diff --git a/core.lua b/core.lua index 6f5d2a4..a7ba211 100644 --- a/core.lua +++ b/core.lua @@ -1,15 +1,13 @@ AuxVersion = '2.4.0' AuxAuthors = 'shirsig; Zerf; Zirco (Auctionator); Nimeral (Auctionator backport)' -local lastRightClickAction = GetTime() - Aux = { blizzard_ui_shown = false, loaded = false, orig = {}, } -function Aux_OnLoad() +function Aux.on_load() Aux.log('Aux v'..AuxVersion..' loaded.') Aux.loaded = true tinsert(UISpecialFrames, 'AuxFrame') @@ -88,22 +86,21 @@ function Aux_OnLoad() -- AuxFrameContent:SetBackdropColor(unpack(Aux.gui.config.content_color)) -- AuxFrameContent:SetBackdropBorderColor(unpack(Aux.gui.config.content_border_color)) --- Aux.item_search_frame.on_load() - Aux.filter_search_frame.on_load() + Aux.search_frame.on_load() Aux.post_frame.on_load() Aux.auctions_frame.on_load() Aux.bids_frame.on_load() end -function Aux_OnEvent() +function Aux.on_event() if event == 'VARIABLES_LOADED' then - Aux_OnLoad() + Aux.on_load() elseif event == 'ADDON_LOADED' then - Aux_OnAddonLoaded() + Aux.on_addon_loaded() elseif event == 'AUCTION_HOUSE_SHOW' then - Aux_OnAuctionHouseShow() + Aux.on_auction_house_show() elseif event == 'AUCTION_HOUSE_CLOSED' then - Aux_OnAuctionHouseClosed() + Aux.on_auction_house_closed() Aux.bids_loaded = false Aux.current_owner_page = nil elseif event == 'AUCTION_BIDDER_LIST_UPDATE' then @@ -113,12 +110,9 @@ function Aux_OnEvent() end end -function Aux_OnAddonLoaded() - if string.lower(arg1) == "blizzard_auctionui" then - Aux_SetupHookFunctions() - end - if string.lower(arg1) == "EnhTooltip" then - +function Aux.on_addon_loaded() + if string.lower(arg1) == 'blizzard_auctionui' then + Aux.setup_hooks() end end @@ -146,53 +140,11 @@ do end end -function Aux.log_frame_load() - this:SetFading(false) - this:EnableMouseWheel() - -- this.flashTimer = 0 TODO remove -end - -function Aux.log_frame_update(elapsedSec) - if not this:IsVisible() then - return - end - - local flash = getglobal(this:GetName()..'BottomButtonFlash') - - if not flash then - return - end - - if this:AtBottom() then - if flash:IsVisible() then - flash:Hide() - end - return - end - - local flashTimer = this.flashTimer + elapsedSec - if flashTimer < CHAT_BUTTON_FLASH_TIME then - this.flashTimer = flashTimer - return - end - - while flashTimer >= CHAT_BUTTON_FLASH_TIME do - flashTimer = flashTimer - CHAT_BUTTON_FLASH_TIME - end - this.flashTimer = flashTimer - - if flash:IsVisible() then - flash:Hide() - else - flash:Show() - end -end - function Aux.log(msg) DEFAULT_CHAT_FRAME:AddMessage(msg, 1, 1, 0) end -function Aux_SetupHookFunctions() +function Aux.setup_hooks() local blizzard_ui_on_hide = function() Aux.blizzard_ui_shown = false @@ -216,7 +168,7 @@ function Aux_SetupHookFunctions() PickupContainerItem = Aux.PickupContainerItem Aux.orig.ContainerFrameItemButton_OnClick = ContainerFrameItemButton_OnClick - ContainerFrameItemButton_OnClick = Aux_ContainerFrameItemButton_OnClick + ContainerFrameItemButton_OnClick = Aux.ContainerFrameItemButton_OnClick Aux.orig.AuctionFrameAuctions_OnEvent = AuctionFrameAuctions_OnEvent AuctionFrameAuctions_OnEvent = Aux.AuctionFrameAuctions_OnEvent @@ -237,23 +189,21 @@ function Aux.AuctionFrameAuctions_OnEvent() end end -function Aux_OnAuctionHouseShow() +function Aux.on_auction_house_show() AuxFrame:Show() Aux.tab_group:set_tab(1) end -function Aux_OnAuctionHouseClosed() +function Aux.on_auction_house_closed() Aux.post.stop() Aux.stack.stop() Aux.scan.abort() --- Aux.item_search_frame.on_close() - Aux.filter_search_frame.on_close() + Aux.search_frame.on_close() Aux.post_frame.on_close() Aux.auctions_frame.on_close() Aux.bids_frame.on_close() - Aux.history_frame.on_close() - + AuxFrame:Hide() end @@ -261,23 +211,19 @@ function Aux.on_tab_click(index) Aux.post.stop() Aux.stack.stop() Aux.scan.abort(function() --- Aux.item_search_frame.on_close() - Aux.filter_search_frame.on_close() + Aux.search_frame.on_close() Aux.post_frame.on_close() Aux.auctions_frame.on_close() Aux.bids_frame.on_close() - Aux.history_frame.on_close() --- AuxItemSearchFrame:Hide() AuxFilterSearchFrame:Hide() AuxPostFrame:Hide() AuxAuctionsFrame:Hide() AuxBidsFrame:Hide() - AuxHistoryFrame:Hide() if index == 1 then AuxFilterSearchFrame:Show() - Aux.filter_search_frame.on_open() + Aux.search_frame.on_open() elseif index == 2 then AuxPostFrame:Show() Aux.post_frame.on_open() @@ -287,9 +233,6 @@ function Aux.on_tab_click(index) elseif index == 4 then AuxBidsFrame:Show() Aux.bids_frame.on_open() --- elseif index == 5 then --- AuxItemSearchFrame:Show() --- Aux.item_search_frame.on_open() end Aux.active_panel = index @@ -314,25 +257,6 @@ function Aux.price_level_color(pct) end 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_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 - do local last_picked_up function Aux.PickupContainerItem(bag, slot) @@ -346,7 +270,7 @@ do end end -function Aux_ContainerFrameItemButton_OnClick(button) +function Aux.ContainerFrameItemButton_OnClick(button) local bag, slot = this:GetParent():GetID(), this:GetID() local item_info = Aux.info.container_item(bag, slot) diff --git a/core.xml b/core.xml index e061bf3..026dfb1 100644 --- a/core.xml +++ b/core.xml @@ -13,7 +13,7 @@ this:RegisterEvent('AUCTION_OWNED_LIST_UPDATE') - Aux_OnEvent() + Aux.on_event() diff --git a/item_search_frame.xml b/item_search_frame.xml index 150510f..684af94 100644 --- a/item_search_frame.xml +++ b/item_search_frame.xml @@ -1,6 +1,6 @@ -