From 67d013f494bdb2d0555e905ba326408f5b77d7d3 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Mon, 25 Jan 2016 18:35:05 +0100 Subject: [PATCH] multiple refactorings --- Aux-AddOn.toc | 4 +- about.xml | 49 ----- core.lua | 15 +- filter_search_frame.lua | 21 ++- item_search_frame.lua | 38 ++-- money.lua | 122 +++++++++++++ options.lua | 114 ------------ options.xml | 386 ---------------------------------------- post_frame.lua | 84 +++++---- post_frame.xml | 22 +-- 10 files changed, 204 insertions(+), 651 deletions(-) delete mode 100644 about.xml create mode 100644 money.lua delete mode 100644 options.lua delete mode 100644 options.xml diff --git a/Aux-AddOn.toc b/Aux-AddOn.toc index 1df94b8..8239341 100644 --- a/Aux-AddOn.toc +++ b/Aux-AddOn.toc @@ -10,6 +10,7 @@ gui.lua control.xml persistence.lua util.lua +money.lua scan.lua scan_util.lua @@ -28,8 +29,5 @@ auctions_frame.xml bids_frame.xml scan_frame.xml -options.xml -about.xml - static.xml diff --git a/about.xml b/about.xml deleted file mode 100644 index 2da6c62..0000000 --- a/about.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/core.lua b/core.lua index 1024951..2c8d7f7 100644 --- a/core.lua +++ b/core.lua @@ -67,7 +67,7 @@ function Aux_OnLoad() tab_group:create_tab('Auctions') tab_group:create_tab('Bids') tab_group.on_select = Aux.on_tab_click - tab_group:set_tab(1) + Aux.tab_group = tab_group end do local btn = Aux.gui.button(AuxFrame, 12) @@ -236,12 +236,7 @@ function Aux_OnAuctionHouseShow() AuxFrame:Show() - Aux.on_tab_click(1) - if AUX_OPEN_SELL then - Aux.on_tab_click(2) - elseif AUX_OPEN_BUY then - - end + Aux.tab_group:set_tab(1) end @@ -251,7 +246,7 @@ function Aux_OnAuctionHouseClosed() Aux.scan.abort() Aux.filter_search_frame.on_close() - Aux.sell.on_close() + Aux.post_frame.on_close() AuxFrame:Hide() end @@ -262,7 +257,7 @@ function Aux.on_tab_click(index) Aux.scan.abort(function() Aux.item_search_frame.on_close() Aux.filter_search_frame.on_close() - Aux.sell.on_close() + Aux.post_frame.on_close() Aux.auctions_frame.on_close() Aux.bids_frame.on_close() Aux.history_frame.on_close() @@ -282,7 +277,7 @@ function Aux.on_tab_click(index) Aux.filter_search_frame.on_open() elseif index == 3 then AuxSellFrame:Show() - Aux.sell.on_open() + Aux.post_frame.on_open() elseif index == 4 then AuxAuctionsFrame:Show() Aux.auctions_frame.on_open() diff --git a/filter_search_frame.lua b/filter_search_frame.lua index ea667bc..bb42001 100644 --- a/filter_search_frame.lua +++ b/filter_search_frame.lua @@ -3,7 +3,6 @@ Aux.buy = {} local private, public = {}, {} Aux.filter_search_frame = public -local create_auction_record, find_auction, update_listing local auctions local search_query local tooltip_patterns = {} @@ -625,7 +624,7 @@ function public.stop_search() Aux.scan.abort() end -function update_listing() +function private.update_listing() if not AuxFilterSearchFrame:IsVisible() then return @@ -660,7 +659,7 @@ function public.set_view(view) private.bid_button:Disable() private.clear_selection() aux_view = view - update_listing() + private.update_listing() end function public.set_item(item_id) @@ -717,7 +716,7 @@ function public.start_search() on_read_auction = function(auction_info) if Aux.info.tooltip_match(tooltip_patterns, auction_info.tooltip) then auctions = auctions or {} - tinsert(auctions, create_auction_record(auction_info, current_page)) + tinsert(auctions, private.create_auction_record(auction_info, current_page)) end end, on_complete = function() @@ -753,7 +752,7 @@ function private.clear_selection() private.listings[aux_view]:clear_selection() end -function find_auction(entry, express_mode, buyout_mode) +function private.find_auction(entry, express_mode, buyout_mode) if buyout_mode and not entry.buyout_price then return @@ -769,7 +768,7 @@ function find_auction(entry, express_mode, buyout_mode) PlaySound('igMainMenuOptionCheckBoxOn') local function test(index) - return create_auction_record(Aux.info.auction(index)).signature == entry.signature + return private.create_auction_record(Aux.info.auction(index)).signature == entry.signature end Aux.scan_util.find_auction(test, search_query, entry.page, private.status_bar, function(index) @@ -781,7 +780,7 @@ function find_auction(entry, express_mode, buyout_mode) end if not test(index) then - return find_auction(entry, express_mode, buyout_mode) -- try again + return private.find_auction(entry, express_mode, buyout_mode) -- try again end if express_mode then @@ -805,7 +804,7 @@ function find_auction(entry, express_mode, buyout_mode) if not test(index) then private.buyout_button:Disable() private.bid_button:Disable() - return find_auction(entry, express_mode, buyout_mode) -- try again + return private.find_auction(entry, express_mode, buyout_mode) -- try again end if GetMoney() >= amount then @@ -849,11 +848,11 @@ function private.on_row_click(sheet, datum, grouped) sheet:clear_selection() sheet:select(datum) end - find_auction(entry, express_mode, buyout_mode) + private.find_auction(entry, express_mode, buyout_mode) end end -function create_auction_record(auction_info, current_page) +function private.create_auction_record(auction_info, current_page) local aux_quantity = auction_info.charges or auction_info.count local bid = (auction_info.current_bid > 0 and auction_info.current_bid or auction_info.min_bid) + auction_info.min_increment @@ -903,7 +902,7 @@ end function Aux.buy.onupdate() if refresh then refresh = false - update_listing() + private.update_listing() end end diff --git a/item_search_frame.lua b/item_search_frame.lua index d0f5d0a..d4d39f2 100644 --- a/item_search_frame.lua +++ b/item_search_frame.lua @@ -3,19 +3,11 @@ Aux.item_search_frame = public aux_recently_searched = {} -local create_auction_record, find_auction, hide_sheet, update_listing, auction_alpha_setter, group_alpha_setter, create_auction_record +local hide_sheet local auctions local search_query local refresh -function auction_alpha_setter(cell, auction) - cell:SetAlpha(auction.gone and 0.3 or 1) -end - -function group_alpha_setter(cell, group) - cell:SetAlpha(Aux.util.all(group, function(auction) return auction.gone end) and 0.3 or 1) -end - function public.on_close() private.clear_selection() private.buyout_button:Disable() @@ -448,7 +440,7 @@ function public.stop_search() Aux.scan.abort() end -function update_listing() +function private.update_listing() if not AuxItemSearchFrame:IsVisible() then return @@ -489,7 +481,7 @@ function public.set_view(view) private.bid_button:Disable() private.clear_selection() aux_view = view - update_listing() + private.update_listing() end function private.update_recently_searched() @@ -578,7 +570,7 @@ function public.start_search() on_read_auction = function(auction_info) if auction_info.item_id == item_id then auctions = auctions or {} - tinsert(auctions, create_auction_record(auction_info, current_page)) + tinsert(auctions, private.create_auction_record(auction_info, current_page)) end end, on_complete = function() @@ -615,8 +607,8 @@ function private.clear_selection() private.listings[aux_view]:clear_selection() end -function find_auction(entry, express_mode, buyout_mode) - +function private.find_auction(entry, express_mode, buyout_mode) + if buyout_mode and not entry.buyout_price then return end @@ -631,7 +623,7 @@ function find_auction(entry, express_mode, buyout_mode) PlaySound('igMainMenuOptionCheckBoxOn') local function test(index) - return create_auction_record(Aux.info.auction(index)).signature == entry.signature + return private.create_auction_record(Aux.info.auction(index)).signature == entry.signature end Aux.scan_util.find_auction(test, search_query, entry.page, private.status_bar, function(index) @@ -644,7 +636,7 @@ function find_auction(entry, express_mode, buyout_mode) end if not test(index) then - return find_auction(entry, express_mode, buyout_mode) -- try again + return private.find_auction(entry, express_mode, buyout_mode) -- try again end if express_mode then @@ -668,7 +660,7 @@ function find_auction(entry, express_mode, buyout_mode) if not test(index) then private.buyout_button:Disable() private.bid_button:Disable() - return find_auction(entry, express_mode, buyout_mode) -- try again + return private.find_auction(entry, express_mode, buyout_mode) -- try again end if GetMoney() >= amount then @@ -698,8 +690,8 @@ function private.on_row_click(sheet, datum, grouped) local express_mode = IsAltKeyDown() local buyout_mode = express_mode and arg1 == 'LeftButton' - - if IsControlKeyDown() then + + if IsControlKeyDown() then DressUpItemLink(entry.hyperlink) elseif IsShiftKeyDown() then if ChatFrameEditBox:IsVisible() then @@ -712,12 +704,12 @@ function private.on_row_click(sheet, datum, grouped) sheet:clear_selection() sheet:select(datum) end - find_auction(entry, express_mode, buyout_mode) + private.find_auction(entry, express_mode, buyout_mode) end end -function create_auction_record(auction_info, current_page) - +function private.create_auction_record(auction_info, current_page) + local aux_quantity = auction_info.charges or auction_info.count local bid = (auction_info.current_bid > 0 and auction_info.current_bid or auction_info.min_bid) + auction_info.min_increment local buyout_price = auction_info.buyout_price > 0 and auction_info.buyout_price or nil @@ -764,6 +756,6 @@ end function public.on_update() if refresh then refresh = false - update_listing() + private.update_listing() end end \ No newline at end of file diff --git a/money.lua b/money.lua new file mode 100644 index 0000000..b90cce0 --- /dev/null +++ b/money.lua @@ -0,0 +1,122 @@ +local m = {} +Aux.money = m + +local private = {textMoneyParts={} } + +local GOLD_TEXT = '|cffffd70ag|r' +local SILVER_TEXT = '|cffc7c7cfs|r' +local COPPER_TEXT = '|cffeda55fc|r' +local COPPER_PER_SILVER = 100 +local COPPER_PER_GOLD = 10000 + + +-- ============================================================================ +-- TSMAPI Functions +-- ============================================================================ + +function m:MoneyToString(money) -- ,...) + money = tonumber(money) + if not money then return end + local color, pad, trim, disabled +-- for i=1, select('#', ...) do +-- local opt = select(i, ...) +-- if type(opt) == 'string' then +-- if opt == 'OPT_PAD' then -- left-pad all but the highest denomination with zeros (i.e. "1g 00s 02c" instead of "1g 0s 2c") +-- pad = true +-- elseif opt == 'OPT_TRIM' then -- removes any 0 valued denominations (i.e. "1g" instead of "1g 0s 0c") - 0 will still be represented as "0c" +-- trim = true +-- elseif opt == 'OPT_DISABLE' then -- removes color from denomination text +-- disabled = true +-- elseif strmatch(strlower(opt), '^|c[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$') then -- color the numbers +-- color = opt +-- end +-- end +-- end + + local isNegative = money < 0 + money = abs(money) + local gold = floor(money / COPPER_PER_GOLD) + local silver = floor(mod(money, COPPER_PER_GOLD) / COPPER_PER_SILVER) + local copper = floor(mod(money, COPPER_PER_SILVER)) + local goldText, silverText, copperText = nil, nil, nil + if disabled then + goldText, silverText, copperText = "g", "s", "c" + else + goldText, silverText, copperText = TSM.GOLD_TEXT, TSM.SILVER_TEXT, TSM.COPPER_TEXT + end + + if money == 0 then + return private:FormatNumber(0, false, color)..copperText + end + + local text = nil + local shouldPad = false + if trim then + wipe(private.textMoneyParts) -- avoid creating a new table every time + -- add gold + if gold > 0 then + tinsert(private.textMoneyParts, private:FormatNumber(gold, false, color)..goldText) + shouldPad = pad + end + -- add silver + if silver > 0 then + tinsert(private.textMoneyParts, private:FormatNumber(silver, shouldPad, color)..silverText) + shouldPad = pad + end + -- add copper + if copper > 0 then + tinsert(private.textMoneyParts, private:FormatNumber(copper, shouldPad, color)..copperText) + shouldPad = pad + end + text = table.concat(private.textMoneyParts, " ") + else + if gold > 0 then + text = private:FormatNumber(gold, false, color)..goldText.." "..private:FormatNumber(silver, pad, color)..silverText.." "..private:FormatNumber(copper, pad, color)..copperText + elseif silver > 0 then + text = private:FormatNumber(silver, false, color)..silverText.." "..private:FormatNumber(copper, pad, color)..copperText + else + text = private:FormatNumber(copper, false, color)..copperText + end + end + + if isNegative then + if color then + return color..'-|r'..text + else + return '-'..text + end + else + return text + end +end + +function m:MoneyFromString(value) + -- remove any colors + value = gsub(gsub(value:trim(), '\124c([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])', ''), '\124r', '') + + -- extract gold/silver/copper values + local gold = tonumber(strmatch(value, '([0-9]+)g')) + local silver = tonumber(strmatch(value, '([0-9]+)s')) + local copper = tonumber(strmatch(value, '([0-9]+)c')) + if not gold and not silver and not copper then return end + + -- test that there are no extra characters (other than spaces) + value = gsub(value, '[0-9]+g', '', 1) + value = gsub(value, '[0-9]+s', '', 1) + value = gsub(value, '[0-9]+c', '', 1) + if value:trim() ~= '' then return end + + return ((gold or 0) * COPPER_PER_GOLD) + ((silver or 0) * COPPER_PER_SILVER) + (copper or 0) +end + +function m:format_number(num, pad, color) + if num < 10 and pad then + num = '0'..num + end + + if color then + return color..num..'|r' + else + return num + end +end \ No newline at end of file diff --git a/options.lua b/options.lua deleted file mode 100644 index d2c2b69..0000000 --- a/options.lua +++ /dev/null @@ -1,114 +0,0 @@ -Aux.options = {} - -AUX_SELL_SHORTCUT = true -AUX_BUY_SHORTCUT = true -AUX_OPEN_SELL = false -AUX_OPEN_BUY = false -AUX_INSTANT_BUYOUT = false - -AUX_AUCTION_DURATION = 'long' - -function Aux.options.show_description() - - AuxAboutFrame:Show() - - AuxAboutDescriptionHTML:SetText("" - .."

What is Aux?


" - .."

" - .."Aux adds two tabs to the traditional auction house layout, Aux Sell and Aux Buy, which make selling and buying respectively a much more streamlined experience by automating a lot of the annoying little tasks involved in managing your auctions and providing you with much better information to base decisions on." - .."


Aux Sell


" - .."The Aux Sell panel gives you pricing suggestions based on existing auctions (undercutting by 1 copper) when you put an item in the auction slot. Aux will cache search results so that you don't have to wait several seconds to minutes between auctions. If you need to update the information there's a refresh button. You can further select a specific entry from the list to base the pricing suggestion on if you don't like its default choice." - .."


Aux Buy


" - .."The Aux Buy panel makes a multi-page search for you and lists all items with the most relevant information sorted by unit price. From that list you can select all the auctions you want to buy and after your confirmation Aux then makes another multi-page search, picking up all the selected auctions in the process. At the end you're presented with a report about what has been purchased." - .."

" - .."") - AuxAboutDescriptionHTML:SetSpacing(3) - AuxAboutAuthorText:SetText("Authors: "..AuxAuthors) - -end - ------------------------------------------ - -function Aux.options.show() - - AuxOptionsFrame:Show() - AuxOptionsFrame:SetBackdropColor(0,0,0,100) - - AuxOptionsConfigTitleText:SetText("Aux Options for "..UnitName("player")) - AuxOptionsSummary:SetText("Aux is an addon designed to make it easier and faster to setup your auctions and find the best deals at the auction house.") - AuxOptionsVersionText:SetText("Version: "..AuxVersion) - - AuxOptionsSellShortcut:SetChecked(AUX_SELL_SHORTCUT) - AuxOptionsBuyShortcut:SetChecked(AUX_BUY_SHORTCUT) - AuxOptionsOpenSell:SetChecked(AUX_OPEN_SELL) - AuxOptionsOpenBuy:SetChecked(AUX_OPEN_BUY) - AuxOptionsInstantBuyout:SetChecked(AUX_INSTANT_BUYOUT) - -end - ------------------------------------------ - -function Aux.options.save() - - AUX_SELL_SHORTCUT = AuxOptionsSellShortcut:GetChecked() - AUX_BUY_SHORTCUT = AuxOptionsBuyShortcut:GetChecked() - AUX_OPEN_SELL = AuxOptionsOpenSell:GetChecked() - AUX_OPEN_BUY = AuxOptionsOpenBuy:GetChecked() - AUX_INSTANT_BUYOUT = AuxOptionsInstantBuyout:GetChecked() - -end - ------------------------------------------ - -function Aux.options.show_sell_shortcut_tooltip() - - GameTooltip:SetOwner(this, "ANCHOR_BOTTOM") - GameTooltip:SetText("Aux Sell shortcut", 0.9, 1.0, 1.0) - GameTooltip:AddLine("If this option is checked, holding the Alt key down while clicking an item in your bags will switch to the Aux Sell panel, place the item in the Auction Item area and suggest a price.", 0.5, 0.5, 1.0, 1) - GameTooltip:Show() - -end - ------------------------------------------ - -function Aux.options.show_buy_shortcut_tooltip() - - GameTooltip:SetOwner(this, "ANCHOR_BOTTOM") - GameTooltip:SetText("Aux Buy Shortcut", 0.9, 1.0, 1.0) - GameTooltip:AddLine("If this option is checked, holding the Control key down while clicking an item in your bags will switch to the Aux Buy panel and start a search.", 0.5, 0.5, 1.0, 1) - GameTooltip:Show() - -end - ------------------------------------------ - -function Aux.options.show_open_sell_tooltip() - - GameTooltip:SetOwner(this, "ANCHOR_BOTTOM") - GameTooltip:SetText("Start on Aux Sell panel", 0.9, 1.0, 1.0) - GameTooltip:AddLine("If this option is checked, the Aux Sell panel will display first whenever you open the Auction House window.", 0.5, 0.5, 1.0, 1) - GameTooltip:Show() - -end - ------------------------------------------ - -function Aux.options.show_open_buy_tooltip() - - GameTooltip:SetOwner(this, "ANCHOR_BOTTOM") - GameTooltip:SetText("Start on Aux Buy panel", 0.9, 1.0, 1.0) - GameTooltip:AddLine("If this option is checked, the Aux Buy panel will display first whenever you open the Auction House window.", 0.5, 0.5, 1.0, 1) - GameTooltip:Show() - -end - ------------------------------------------ - -function Aux.options.show_instant_buyout_tooltip() - - GameTooltip:SetOwner(this, "ANCHOR_BOTTOM") - GameTooltip:SetText("Instant buyout", 0.9, 1.0, 1.0) - GameTooltip:AddLine("If this option is checked, right-clicking on an auction in the Browse tab will instantly buy it out.", 0.5, 0.5, 1.0, 1) - GameTooltip:Show() - -end diff --git a/options.xml b/options.xml deleted file mode 100644 index b703553..0000000 --- a/options.xml +++ /dev/null @@ -1,386 +0,0 @@ - - -