From bd4676d8626445f8bf6b680f7fe3372956becc89 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Tue, 28 Mar 2017 07:25:56 +0200 Subject: [PATCH] no more decimals in post --- gui/core.lua | 2 +- tabs/post/core.lua | 43 ++++++++++++++++--------------------------- tabs/post/frame.lua | 4 ++-- util/money.lua | 31 +++++++++++++++++++------------ 4 files changed, 38 insertions(+), 42 deletions(-) diff --git a/gui/core.lua b/gui/core.lua index f91f724..de1b8d9 100644 --- a/gui/core.lua +++ b/gui/core.lua @@ -291,7 +291,7 @@ function M.editbox(parent) set_content_style(editbox) editbox:SetScript('OnEscapePressed', function() this:ClearFocus() - ;(this.escape or nop)() + do (this.escape or nop)() end end) editbox:SetScript('OnEnterPressed', function() (this.enter or nop)() end) editbox:SetScript('OnEditFocusGained', function() diff --git a/tabs/post/core.lua b/tabs/post/core.lua index e477579..9f4172b 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -34,7 +34,6 @@ function read_settings(item_key) item_key = item_key or selected_item.key return data[item_key] and persistence.read(settings_schema, data[item_key]) or default_settings end - function write_settings(settings, item_key) item_key = item_key or selected_item.key data[item_key] = persistence.write(settings_schema, settings) @@ -42,19 +41,15 @@ end do local bid_selections, buyout_selections = {}, {} - function get_bid_selection() return bid_selections[selected_item.key] end - function set_bid_selection(record) bid_selections[selected_item.key] = record end - function get_buyout_selection() return buyout_selections[selected_item.key] end - function set_buyout_selection(record) buyout_selections[selected_item.key] = record end @@ -94,21 +89,23 @@ function USE_ITEM(item_info) end function get_unit_start_price() - local money_text = unit_start_price_input:GetText() - return money.from_string(money_text) or 0 + return selected_item and read_settings().start_price or 0 end function set_unit_start_price(amount) - unit_start_price_input:SetText(money.to_string(amount, true, nil, nil, true)) + local settings = read_settings() + settings.start_price = amount + write_settings(settings) end function get_unit_buyout_price() - local money_text = unit_buyout_price_input:GetText() - return money.from_string(money_text) or 0 + return selected_item and read_settings().buyout_price or 0 end function set_unit_buyout_price(amount) - unit_buyout_price_input:SetText(money.to_string(amount, true, nil, nil, true)) + local settings = read_settings() + settings.buyout_price = amount + write_settings(settings) end function update_inventory_listing() @@ -127,7 +124,7 @@ function update_auction_listing(listing, records, reference) local stack_size = stack_size_slider:GetValue() for i = 1, getn(records[selected_item.key] or empty) do local record = records[selected_item.key][i] - local price_color = money.from_string(money.to_string(undercut(record, stack_size_slider:GetValue(), listing == 'bid'), true)) < reference and color.red + local price_color = undercut(record, stack_size_slider:GetValue(), listing == 'bid') < reference and color.red local price = record.unit_price * (listing == 'bid' and record.stack_size / stack_size_slider:GetValue() or 1) tinsert(rows, O( 'cols', A( @@ -194,25 +191,17 @@ end function price_update() if selected_item then - local settings = read_settings() - local historical_value = history.value(selected_item.key) - - if bid_selection then - unit_start_price = undercut(bid_selection, stack_size_slider:GetValue(), true) - elseif buyout_selection then - unit_start_price = undercut(buyout_selection, stack_size_slider:GetValue()) + if bid_selection or buyout_selection then + unit_start_price = undercut(bid_selection or buyout_selection, stack_size_slider:GetValue(), bid_selection) + unit_start_price_input:SetText(money.to_string(unit_start_price, true, nil, nil, true)) + start_price_percentage:SetText(historical_value and al.percentage_historical(round(unit_start_price / historical_value * 100)) or '---') end - settings.start_price = unit_start_price - start_price_percentage:SetText(historical_value and al.percentage_historical(round(unit_start_price / historical_value * 100)) or '---') - if buyout_selection then unit_buyout_price = undercut(buyout_selection, stack_size_slider:GetValue()) + unit_buyout_price_input:SetText(money.to_string(unit_buyout_price, true, nil, nil, true)) + buyout_price_percentage:SetText(historical_value and al.percentage_historical(round(unit_buyout_price / historical_value * 100)) or '---') end - settings.buyout_price = unit_buyout_price - buyout_price_percentage:SetText(historical_value and al.percentage_historical(round(unit_buyout_price / historical_value * 100)) or '---') - - write_settings(settings) end end @@ -382,7 +371,7 @@ function update_item(item) item.unit_vendor_price = unit_vendor_price(item.key) if not item.unit_vendor_price then - settings.hidden = 1 + settings.hidden = true write_settings(settings, item.key) refresh = true return diff --git a/tabs/post/frame.lua b/tabs/post/frame.lua index 4c3425c..20a62f3 100644 --- a/tabs/post/frame.lua +++ b/tabs/post/frame.lua @@ -249,7 +249,7 @@ do end end) editbox.formatter = function() return money.to_string(unit_start_price, true) end - editbox.char = function() bid_selection, buyout_selection = nil, nil end + editbox.char = function() bid_selection, buyout_selection = nil, nil; unit_start_price = money.from_string(this:GetText()) end editbox.change = function() refresh = true end editbox.enter = function() this:ClearFocus() end editbox.focus_loss = function() @@ -284,7 +284,7 @@ do end end) editbox.formatter = function() return money.to_string(unit_buyout_price, true) end - editbox.char = function() buyout_selection = nil end + editbox.char = function() buyout_selection = nil; unit_buyout_price = money.from_string(this:GetText()) end editbox.change = function() refresh = true end editbox.enter = function() this:ClearFocus() end editbox.focus_loss = function() diff --git a/util/money.lua b/util/money.lua index 0400e44..cc7661f 100644 --- a/util/money.lua +++ b/util/money.lua @@ -34,7 +34,7 @@ function M.to_string2(money, exact, color) local NONE = '|cffa0a0a0' .. TEXT_NONE .. FONT_COLOR_CODE_CLOSE if not exact and money >= COPPER_PER_GOLD then - money = floor(money / COPPER_PER_SILVER + .5) * COPPER_PER_SILVER + money = round(money / COPPER_PER_SILVER) * COPPER_PER_SILVER end local g, s, c = to_gsc(money) @@ -58,45 +58,43 @@ function M.to_string2(money, exact, color) return str end -function M.to_string(money, pad, trim, number_color, no_coin_color) +function M.to_string(money, pad, trim, color, no_color) local is_negative = money < 0 money = abs(money) local gold, silver, copper = to_gsc(money) local gold_text, silver_text, copper_text - if no_coin_color then + if no_color then gold_text, silver_text, copper_text = 'g', 's', 'c' else gold_text, silver_text, copper_text = GOLD_TEXT, SILVER_TEXT, COPPER_TEXT end - number_color = number_color or color.none - local text if trim then local parts = temp-T if gold > 0 then - tinsert(parts, number_color(gold) .. gold_text) + tinsert(parts, format_number(gold, false, color) .. gold_text) end if silver > 0 then - tinsert(parts, number_color(silver) .. silver_text) + tinsert(parts, format_number(silver, pad, color) .. silver_text) end if copper > 0 or gold == 0 and silver == 0 then - tinsert(parts, number_color(copper) .. copper_text) + tinsert(parts, format_number(copper, pad, color) .. copper_text) end text = join(parts, ' ') else if gold > 0 then - text = number_color(gold) .. gold_text .. ' ' .. number_color(silver) .. silver_text .. ' ' .. number_color(copper) .. copper_text + text = format_number(gold, false, color) .. gold_text .. ' ' .. format_number(silver, pad, color) .. silver_text .. ' ' .. format_number(copper, pad, color) .. copper_text elseif silver > 0 then - text = number_color(silver) .. silver_text .. ' ' .. number_color(copper) .. copper_text + text = format_number(silver, false, color) .. silver_text .. ' ' .. format_number(copper, pad, color) .. copper_text else - text = number_color(copper) .. copper_text + text = format_number(copper, false, color) .. copper_text end end if is_negative then - text = number_color'-' .. text + text = (color and color'-' or '-') .. text end return text @@ -121,4 +119,13 @@ function M.from_string(value) if strfind(value, '%S') then return end return from_gsc(gold or 0, silver or 0, copper or 0) +end + +function M.format_number(num, pad, color) + num = format('%0' .. (pad and 2 or 0) .. 'd', num) + if color then + return color .. num .. FONT_COLOR_CODE_CLOSE + else + return num + end end \ No newline at end of file