diff --git a/bids_frame.lua b/bids_frame.lua index 9d1a38e..d135b0a 100644 --- a/bids_frame.lua +++ b/bids_frame.lua @@ -136,6 +136,15 @@ function public.on_load() btn:Disable() private.buyout_button = btn end + do + local btn = Aux.gui.button(AuxBidsFrame, 15) + btn:SetPoint('TOPLEFT', private.buyout_button, 'TOPRIGHT', 5, 0) + btn:SetWidth(80) + btn:SetHeight(24) + btn:SetText('Bid') + btn:Disable() + private.bid_button = btn + end end function public.on_open() @@ -146,7 +155,7 @@ end function public.on_close() private.listing:clear_selection() private.buyout_button:Disable() --- private.bid_button:Disable() + private.bid_button:Disable() end function public.update_bid_records() @@ -286,7 +295,7 @@ function private.find_auction(entry, express_mode, buyout_mode) if not test(index) then private.buyout_button:Disable() --- private.bid_button:Disable() + private.bid_button:Disable() return private.find_auction(entry, express_mode, buyout_mode) -- try again end @@ -296,12 +305,12 @@ function private.find_auction(entry, express_mode, buyout_mode) Aux.place_bid('bidder', index, entry.buyout_price) private.buyout_button:Disable() --- private.bid_button:Disable() + private.bid_button:Disable() private.listing:clear_selection() refresh = true end) private.buyout_button:Enable() --- private.bid_button:Enable() + private.bid_button:Enable() end end) end @@ -320,7 +329,7 @@ function public.on_bid_click(bid_record) elseif not bid_record.gone then if not express_mode then private.buyout_button:Disable() --- private.bid_button:Disable() + private.bid_button:Disable() private.listing:clear_selection() private.listing:select(bid_record) end diff --git a/core.xml b/core.xml index 4b22bf0..f934043 100644 --- a/core.xml +++ b/core.xml @@ -333,7 +333,7 @@ - + diff --git a/listing_util.lua b/listing_util.lua index 86b6fd8..1a1de6c 100644 --- a/listing_util.lua +++ b/listing_util.lua @@ -8,7 +8,7 @@ function m.money_column(name, getter) comparator = function(datum1, datum2) return Aux.util.compare(getter(datum1), getter(datum2), Aux.util.GT) end, cell_initializer = Aux.sheet.default_cell_initializer('RIGHT'), cell_setter = function(cell, datum) - cell.text:SetText(Aux.util.money_string(getter(datum))) + cell.text:SetText(getter(datum) and Aux.util.money_string(getter(datum)) or 'N/A') -- group_alpha_setter(cell, getter(datum)) end, } @@ -51,9 +51,10 @@ function m.percentage_market_column(item_key_getter, value_getter) cell_setter = function(cell, datum) local market_price = Aux.history.market_value(item_key_getter(datum)) - local pct = market_price and market_price > 0 and ceil(100 / market_price * value_getter(datum)) + local pct = value_getter(datum) and market_price and market_price > 0 and ceil(100 / market_price * value_getter(datum)) if not pct then cell.text:SetText('N/A') + cell.text:SetTextColor(0.8, 0.8, 0.8) elseif pct > 999 then cell.text:SetText('>999%') else diff --git a/money.lua b/money.lua index b90cce0..c75b734 100644 --- a/money.lua +++ b/money.lua @@ -1,115 +1,84 @@ 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 +function m.to_string(money, pad, trim, color, no_color) --- ============================================================================ --- 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 + local is_negative = 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" + local copper = Aux.round(mod(money, COPPER_PER_SILVER)) + local gold_text, silver_text, copper_text + if no_color then + gold_text, silver_text, copper_text = 'g', 's', 'c' else - goldText, silverText, copperText = TSM.GOLD_TEXT, TSM.SILVER_TEXT, TSM.COPPER_TEXT + gold_text, silver_text, copper_text = GOLD_TEXT, SILVER_TEXT, COPPER_TEXT end if money == 0 then - return private:FormatNumber(0, false, color)..copperText + return m.format_number(0, false, color)..copper_text end - local text = nil - local shouldPad = false + local text if trim then - wipe(private.textMoneyParts) -- avoid creating a new table every time - -- add gold + local parts = {} if gold > 0 then - tinsert(private.textMoneyParts, private:FormatNumber(gold, false, color)..goldText) - shouldPad = pad + tinsert(parts, private:format_number(gold, false, color)..gold_text) end - -- add silver if silver > 0 then - tinsert(private.textMoneyParts, private:FormatNumber(silver, shouldPad, color)..silverText) - shouldPad = pad + tinsert(parts, private:format_number(silver, pad, color)..silver_text) end - -- add copper if copper > 0 then - tinsert(private.textMoneyParts, private:FormatNumber(copper, shouldPad, color)..copperText) - shouldPad = pad + tinsert(parts, private:format_number(copper, pad, color)..copper_text) end - text = table.concat(private.textMoneyParts, " ") + text = Aux.persistence.serialize(parts, ' ') else if gold > 0 then - text = private:FormatNumber(gold, false, color)..goldText.." "..private:FormatNumber(silver, pad, color)..silverText.." "..private:FormatNumber(copper, pad, color)..copperText + text = m.format_number(gold, false, color)..gold_text..' '..m.format_number(silver, pad, color)..silver_text..' '..m.format_number(copper, pad, color)..copper_text elseif silver > 0 then - text = private:FormatNumber(silver, false, color)..silverText.." "..private:FormatNumber(copper, pad, color)..copperText + text = m.format_number(silver, false, color)..silver_text..' '..m.format_number(copper, pad, color)..copper_text else - text = private:FormatNumber(copper, false, color)..copperText + text = m.format_number(copper, false, color)..copper_text end end - if isNegative then + if is_negative then if color then - return color..'-|r'..text + text = color..'-|r'..text else - return '-'..text + text = '-'..text end - else - return text end + + return text end -function m:MoneyFromString(value) +function m.from_string(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', '') - + value = gsub(gsub(value, '\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 - + local gold = tonumber(({strfind(value, '([0-9]+)g')})[3]) + local silver = tonumber(({strfind(value, '([0-9]+)s')})[3]) + local copper = tonumber(({strfind(value, '([0-9]+)c')})[3]) +-- 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 + if strfind(value, '%S') then return 0 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) +function m.format_number(num, pad, color) if num < 10 and pad then num = '0'..num end diff --git a/post_frame.lua b/post_frame.lua index 19c51cd..0811d90 100644 --- a/post_frame.lua +++ b/post_frame.lua @@ -191,6 +191,56 @@ function public.on_load() btn:SetScript('OnClick', private.refresh) private.refresh_button = btn end + do + local editbox = Aux.gui.editbox(AuxSellParameters) + editbox:SetPoint('TOPLEFT', 16, -181) + editbox:SetWidth(150) + editbox:SetScript('OnTextChanged', function() + private.validate_parameters() + end) + editbox:SetScript('OnTabPressed', function() + private.buyout_price:SetFocus() + private.buyout_price:HighlightText() + end) + editbox:SetScript('OnEnterPressed', function() + this:ClearFocus() + end) + editbox:SetScript('OnEscapePressed', function() + this:ClearFocus() + end) + editbox:SetScript('OnEditFocusLost', function() + this:SetText(Aux.money.to_string(Aux.money.from_string(this:GetText()))) + end) + local label = Aux.gui.label(editbox, 13) + label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1) + label:SetText('Starting Stack Price') + private.start_price = editbox + end + do + local editbox = Aux.gui.editbox(AuxSellParameters) + editbox:SetPoint('TOPLEFT', 16, -216) + editbox:SetWidth(150) + editbox:SetScript('OnTextChanged', function() + private.validate_parameters() + end) + editbox:SetScript('OnTabPressed', function() + private.start_price:SetFocus() + private.start_price:HighlightText() + end) + editbox:SetScript('OnEnterPressed', function() + this:ClearFocus() + end) + editbox:SetScript('OnEscapePressed', function() + this:ClearFocus() + end) + editbox:SetScript('OnEditFocusLost', function() + this:SetText(Aux.money.to_string(Aux.money.from_string(this:GetText()))) + end) + local label = Aux.gui.label(editbox, 13) + label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1) + label:SetText('Buyout Stack Price |cff808080(optional)|r') + private.buyout_price = editbox + end end function public.on_open() @@ -209,14 +259,10 @@ function public.on_open() AuxSellStackCountSliderText:SetText('Stack Count') -- so that it's initialized with zeroes, not sometimes zero, sometimes empty - MoneyInputFrame_SetCopper(AuxSellParametersBuyoutPrice, 100000) - MoneyInputFrame_SetCopper(AuxSellParametersStartPrice, 100000) - MoneyInputFrame_SetCopper(AuxSellParametersBuyoutPrice, 1000) - MoneyInputFrame_SetCopper(AuxSellParametersStartPrice, 1000) - MoneyInputFrame_SetCopper(AuxSellParametersBuyoutPrice, 1) - MoneyInputFrame_SetCopper(AuxSellParametersStartPrice, 1) + private.start_price:SetText(Aux.money.to_string(0)) + private.buyout_price:SetText(Aux.money.to_string(0)) - public.validate_parameters() + private.validate_parameters() private.update_inventory_data() @@ -263,7 +309,7 @@ end function private.post_auctions() local auction = private.current_item() if auction then - local key, hyperlink, stack_size, buyout_price, stack_count = auction.key, auction.hyperlink, private.get_stack_size_slider_value(), MoneyInputFrame_GetCopper(AuxSellParametersBuyoutPrice), AuxSellStackCountSlider:GetValue() + local key, hyperlink, stack_size, buyout_price, stack_count = auction.key, auction.hyperlink, private.get_stack_size_slider_value(), Aux.money.from_string(private.buyout_price:GetText()), AuxSellStackCountSlider:GetValue() local duration if AuctionFrameAuctions.duration == 120 then duration = 2 @@ -277,7 +323,7 @@ function private.post_auctions() key, stack_size, AuctionFrameAuctions.duration, - MoneyInputFrame_GetCopper(AuxSellParametersStartPrice), + Aux.money.from_string(private.start_price:GetText()), buyout_price, stack_count, function(posted) @@ -334,20 +380,19 @@ function private.get_stack_size_slider_value() end end -function public.validate_parameters() +function private.validate_parameters() private.post_button:Disable() - AuxSellParametersBuyoutPriceErrorText:Hide() if not private.current_item() then return end - if MoneyInputFrame_GetCopper(AuxSellParametersBuyoutPrice) > 0 and MoneyInputFrame_GetCopper(AuxSellParametersStartPrice) > MoneyInputFrame_GetCopper(AuxSellParametersBuyoutPrice) then + if Aux.money.from_string(private.buyout_price:GetText()) > 0 and Aux.money.from_string(private.start_price:GetText()) > Aux.money.from_string(private.buyout_price:GetText()) then -- AuxSellParametersBuyoutPriceErrorText:Show() return end - if MoneyInputFrame_GetCopper(AuxSellParametersStartPrice) < 1 then + if Aux.money.from_string(private.start_price:GetText()) < 1 then return end @@ -363,8 +408,8 @@ function private.update_recommendation() AuxSellParametersItemCount:SetText() AuxSellParametersItemName:SetText() - MoneyInputFrame_SetCopper(AuxSellParametersBuyoutPrice, 0) - MoneyInputFrame_SetCopper(AuxSellParametersStartPrice, 0) + private.start_price:SetText(Aux.money.to_string(0)) + private.buyout_price:SetText(Aux.money.to_string(0)) AuxSellStackSizeSlider:SetMinMaxValues(0, 0) AuxSellStackSize:SetNumber(0) @@ -402,23 +447,23 @@ function private.update_recommendation() new_buyout_price = private.undercut(new_buyout_price) end - MoneyInputFrame_SetCopper(AuxSellParametersStartPrice, max(1, Aux.round(new_buyout_price * 0.95))) - MoneyInputFrame_SetCopper(AuxSellParametersBuyoutPrice, max(1, Aux.round(new_buyout_price))) + private.start_price:SetText(Aux.money.to_string(max(1, new_buyout_price * 0.95))) + private.buyout_price:SetText(Aux.money.to_string(max(1, new_buyout_price))) elseif existing_auctions[private.current_item().key] then -- unsuccessful search local market_value = Aux.history.market_value(private.current_item().key) if market_value then - MoneyInputFrame_SetCopper(AuxSellParametersStartPrice, max(1, Aux.round(market_value * 0.95))) - MoneyInputFrame_SetCopper(AuxSellParametersBuyoutPrice, max(1, Aux.round(market_value))) + private.start_price:SetText(Aux.money.to_string(max(1, market_value * 0.95))) + private.buyout_price:SetText(Aux.money.to_string(max(1, market_value))) else - MoneyInputFrame_SetCopper(AuxSellParametersStartPrice, max(1, Aux.round(private.current_item().unit_vendor_price * (private.current_item().charges and 1 or private.get_stack_size_slider_value()) * 1.053))) - MoneyInputFrame_SetCopper(AuxSellParametersBuyoutPrice, max(1, Aux.round(private.current_item().unit_vendor_price * (private.current_item().charges and 1 or private.get_stack_size_slider_value()) * 4))) + private.start_price:SetText(Aux.money.to_string(max(1, private.current_item().unit_vendor_price * (private.current_item().charges and 1 or private.get_stack_size_slider_value()) * 1.053))) + private.buyout_price:SetText(Aux.money.to_string(max(1, private.current_item().unit_vendor_price * (private.current_item().charges and 1 or private.get_stack_size_slider_value()) * 4))) end end else -- no search yet - MoneyInputFrame_SetCopper(AuxSellParametersStartPrice, 0) - MoneyInputFrame_SetCopper(AuxSellParametersBuyoutPrice, 0) + private.start_price:SetText(Aux.money.to_string(0)) + private.buyout_price:SetText(Aux.money.to_string(0)) end end end diff --git a/post_frame.xml b/post_frame.xml index 5b2b523..0d212e1 100644 --- a/post_frame.xml +++ b/post_frame.xml @@ -182,43 +182,43 @@ - - - - - - - - - - - - MoneyInputFrame_SetOnvalueChangedFunc(this, Aux.post_frame.validate_parameters) - - - - - - - - - - - - - - - - - - MoneyInputFrame_SetPreviousFocus(getglobal(this:GetParent():GetName()..'StartPrice'), getglobal(this:GetName()..'Copper')) - MoneyInputFrame_SetNextFocus(getglobal(this:GetParent():GetName()..'StartPrice'), getglobal(this:GetName()..'Gold')) - MoneyInputFrame_SetPreviousFocus(this, getglobal(this:GetParent():GetName()..'StartPriceCopper')) - MoneyInputFrame_SetNextFocus(this, getglobal(this:GetParent():GetName()..'StartPriceGold')) - MoneyInputFrame_SetOnvalueChangedFunc(this, Aux.post_frame.validate_parameters) - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/util.lua b/util.lua index e4f001c..9a56dbf 100644 --- a/util.lua +++ b/util.lua @@ -73,25 +73,6 @@ function Aux.util.iter(array) end end -function Aux.util.format_money(val) - - local g = math.floor(val / 10000) - - val = val - g * 10000 - - local s = math.floor(val / 100) - - val = val - s * 100 - - local c = math.floor(val) - - local g_string = g ~= 0 and g .. 'g' or '' - local s_string = s ~= 0 and s .. 's' or '' - local c_string = (c ~= 0 or g == 0 and s == 0) and c .. 'c' or '' - - return g_string .. s_string .. c_string -end - function Aux.util.set_add(set, key) set[key] = true end