big refactoring
This commit is contained in:
@@ -18,6 +18,7 @@ function C(r, g, b, a)
|
||||
end
|
||||
|
||||
M.color = immutable-{
|
||||
none = setmetatable({}, {__metatable=false, __newindex=nop, __call=function(_, v) return v end, __concat=function(_, v) return v end}),
|
||||
text = immutable-{enabled = C(255, 254, 250, 1), disabled = C(147, 151, 139, 1)},
|
||||
label = immutable-{enabled = C(216, 225, 211, 1), disabled = C(150, 148, 140, 1)},
|
||||
link = C(153, 255, 255, 1),
|
||||
|
||||
@@ -172,7 +172,7 @@ M.search_columns = {
|
||||
else
|
||||
price = price_per_unit and ceil(record.unit_bid_price) or record.bid_price
|
||||
end
|
||||
cell.text:SetText(money.to_string(price, true, false, nil, price_color))
|
||||
cell.text:SetText(money.to_string(price, true, false, price_color))
|
||||
end,
|
||||
cmp = function(record_a, record_b, desc)
|
||||
local price_a
|
||||
@@ -209,7 +209,7 @@ M.search_columns = {
|
||||
isPrice = true,
|
||||
fill = function(cell, record)
|
||||
local price = price_per_unit and ceil(record.unit_buyout_price) or record.buyout_price
|
||||
cell.text:SetText(price > 0 and money.to_string(price, true, false) or '---')
|
||||
cell.text:SetText(price > 0 and money.to_string(price, true) or '---')
|
||||
end,
|
||||
cmp = function(record_a, record_b, desc)
|
||||
local price_a = price_per_unit and record_a.unit_buyout_price or record_a.buyout_price
|
||||
@@ -314,7 +314,7 @@ M.auctions_columns = {
|
||||
else
|
||||
price = price_per_unit and ceil(record.start_price / record.aux_quantity) or record.start_price
|
||||
end
|
||||
cell.text:SetText(money.to_string(price, true, false))
|
||||
cell.text:SetText(money.to_string(price, true))
|
||||
end,
|
||||
cmp = function(record_a, record_b, desc)
|
||||
local price_a
|
||||
@@ -339,7 +339,7 @@ M.auctions_columns = {
|
||||
isPrice = true,
|
||||
fill = function(cell, record)
|
||||
local price = price_per_unit and ceil(record.unit_buyout_price) or record.buyout_price
|
||||
cell.text:SetText(price > 0 and money.to_string(price, true, false) or '---')
|
||||
cell.text:SetText(price > 0 and money.to_string(price, true) or '---')
|
||||
end,
|
||||
cmp = function(record_a, record_b, desc)
|
||||
local price_a = price_per_unit and record_a.unit_buyout_price or record_a.buyout_price
|
||||
@@ -480,7 +480,7 @@ M.bids_columns = {
|
||||
isPrice = true,
|
||||
fill = function(cell, record)
|
||||
local price = price_per_unit and ceil(record.unit_buyout_price) or record.buyout_price
|
||||
cell.text:SetText(price > 0 and money.to_string(price, true, false) or '---')
|
||||
cell.text:SetText(price > 0 and money.to_string(price, true) or '---')
|
||||
end,
|
||||
cmp = function(record_a, record_b, desc)
|
||||
local price_a = price_per_unit and record_a.unit_buyout_price or record_a.buyout_price
|
||||
|
||||
+9
-9
@@ -99,7 +99,7 @@ function get_unit_start_price()
|
||||
end
|
||||
|
||||
function set_unit_start_price(amount)
|
||||
unit_start_price_input:SetText(money.to_string(amount, true, nil, 3, nil, true))
|
||||
unit_start_price_input:SetText(money.to_string(amount, true, nil, nil, true))
|
||||
end
|
||||
|
||||
function get_unit_buyout_price()
|
||||
@@ -108,7 +108,7 @@ function get_unit_buyout_price()
|
||||
end
|
||||
|
||||
function set_unit_buyout_price(amount)
|
||||
unit_buyout_price_input:SetText(money.to_string(amount, true, nil, 3, nil, true))
|
||||
unit_buyout_price_input:SetText(money.to_string(amount, true, nil, nil, true))
|
||||
end
|
||||
|
||||
function update_inventory_listing()
|
||||
@@ -127,14 +127,14 @@ 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, nil, 3)) < reference and color.red
|
||||
local price_color = money.from_string(money.to_string(undercut(record, stack_size_slider:GetValue(), listing == 'bid'), true)) < 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(
|
||||
O('value', record.own and color.green(record.count) or record.count),
|
||||
O('value', al.time_left(record.duration)),
|
||||
O('value', record.stack_size == stack_size and color.green(record.stack_size) or record.stack_size),
|
||||
O('value', money.to_string(price, true, nil, 3, price_color)),
|
||||
O('value', money.to_string(price, true, nil, price_color)),
|
||||
O('value', historical_value and al.percentage_historical(round(price / historical_value * 100)) or '---')
|
||||
),
|
||||
'record', record
|
||||
@@ -146,7 +146,7 @@ function update_auction_listing(listing, records, reference)
|
||||
O('value', '---'),
|
||||
O('value', '---'),
|
||||
O('value', '---'),
|
||||
O('value', money.to_string(historical_value, true, nil, 3, color.green)),
|
||||
O('value', money.to_string(historical_value, true, nil, color.green)),
|
||||
O('value', historical_value and al.percentage_historical(100) or '---')
|
||||
),
|
||||
'record', O('historical_value', true, 'stack_size', stack_size, 'unit_price', historical_value, 'own', true)
|
||||
@@ -330,7 +330,7 @@ function update_item_configuration()
|
||||
local duration_factor = UIDropDownMenu_GetSelectedValue(duration_dropdown) / 120
|
||||
local stack_size, stack_count = selected_item.max_charges and 1 or stack_size_slider:GetValue(), stack_count_slider:GetValue()
|
||||
local amount = floor(selected_item.unit_vendor_price * deposit_factor * stack_size) * stack_count * duration_factor
|
||||
deposit:SetText('Deposit: ' .. money.to_string(amount, nil, nil, nil, color.text.enabled))
|
||||
deposit:SetText('Deposit: ' .. money.to_string(amount, nil, nil, color.text.enabled))
|
||||
end
|
||||
|
||||
refresh_button:Enable()
|
||||
@@ -382,7 +382,7 @@ function update_item(item)
|
||||
|
||||
item.unit_vendor_price = unit_vendor_price(item.key)
|
||||
if not item.unit_vendor_price then
|
||||
settings.hidden = true
|
||||
settings.hidden = 1
|
||||
write_settings(settings, item.key)
|
||||
refresh = true
|
||||
return
|
||||
@@ -410,8 +410,8 @@ function update_item(item)
|
||||
stack_size_slider:SetValue(huge)
|
||||
quantity_update(true)
|
||||
|
||||
unit_start_price_input:SetText(money.to_string(settings.start_price, true, nil, 3, nil, true))
|
||||
unit_buyout_price_input:SetText(money.to_string(settings.buyout_price, true, nil, 3, nil, true))
|
||||
unit_start_price_input:SetText(money.to_string(settings.start_price, true, nil, nil, true))
|
||||
unit_buyout_price_input:SetText(money.to_string(settings.buyout_price, true, nil, nil, true))
|
||||
|
||||
if not bid_records[selected_item.key] then
|
||||
refresh_entries()
|
||||
|
||||
+4
-4
@@ -248,12 +248,12 @@ do
|
||||
unit_buyout_price_input:SetFocus()
|
||||
end
|
||||
end)
|
||||
editbox.formatter = function() return money.to_string(unit_start_price, true, nil, 3) end
|
||||
editbox.formatter = function() return money.to_string(unit_start_price, true) end
|
||||
editbox.char = function() bid_selection, buyout_selection = nil, nil end
|
||||
editbox.change = function() refresh = true end
|
||||
editbox.enter = function() this:ClearFocus() end
|
||||
editbox.focus_loss = function()
|
||||
this:SetText(money.to_string(unit_start_price, true, nil, 3, nil, true))
|
||||
this:SetText(money.to_string(unit_start_price, true, nil, nil, true))
|
||||
end
|
||||
do
|
||||
local label = gui.label(editbox, gui.font_size.small)
|
||||
@@ -283,12 +283,12 @@ do
|
||||
stack_size_slider.editbox:SetFocus()
|
||||
end
|
||||
end)
|
||||
editbox.formatter = function() return money.to_string(unit_buyout_price, true, nil, 3) end
|
||||
editbox.formatter = function() return money.to_string(unit_buyout_price, true) end
|
||||
editbox.char = function() buyout_selection = nil end
|
||||
editbox.change = function() refresh = true end
|
||||
editbox.enter = function() this:ClearFocus() end
|
||||
editbox.focus_loss = function()
|
||||
this:SetText(money.to_string(unit_buyout_price, true, nil, 3, nil, true))
|
||||
this:SetText(money.to_string(unit_buyout_price, true, nil, nil, true))
|
||||
end
|
||||
do
|
||||
local label = gui.label(editbox, gui.font_size.small)
|
||||
|
||||
+2
-2
@@ -415,7 +415,7 @@ function M.filter_string(components)
|
||||
local parameter = component[3]
|
||||
if parameter then
|
||||
if filter_util.filters[component[2]].input_type == 'money' then
|
||||
parameter = money.to_string(money.from_string(parameter), nil, true, nil, nil, true)
|
||||
parameter = money.to_string(money.from_string(parameter), nil, true, nil, true)
|
||||
end
|
||||
query_builder.append(parameter)
|
||||
end
|
||||
@@ -450,7 +450,7 @@ function prettified_filter_string(filter)
|
||||
prettified.append(info.display_name(cache.item_id(parameter)) or color.label.enabled('[' .. parameter .. ']'))
|
||||
else
|
||||
if filters[component[2]].input_type == 'money' then
|
||||
prettified.append(money.to_string(money.from_string(parameter), nil, true, nil, color.label.enabled))
|
||||
prettified.append(money.to_string(money.from_string(parameter), nil, true, color.label.enabled))
|
||||
else
|
||||
prettified.append(color.label.enabled(parameter))
|
||||
end
|
||||
|
||||
+13
-39
@@ -33,9 +33,8 @@ function M.to_string2(money, exact, color)
|
||||
local PART = color .. '.|cff%s%02d' .. FONT_COLOR_CODE_CLOSE
|
||||
local NONE = '|cffa0a0a0' .. TEXT_NONE .. FONT_COLOR_CODE_CLOSE
|
||||
|
||||
if not exact and money >= 10000 then
|
||||
-- Round to nearest silver
|
||||
money = floor(money / 100 + .5) * 100
|
||||
if not exact and money >= COPPER_PER_GOLD then
|
||||
money = floor(money / COPPER_PER_SILVER + .5) * COPPER_PER_SILVER
|
||||
end
|
||||
local g, s, c = to_gsc(money)
|
||||
|
||||
@@ -59,57 +58,45 @@ function M.to_string2(money, exact, color)
|
||||
return str
|
||||
end
|
||||
|
||||
--function M.to_string(params) -- TODO
|
||||
-- local gold, silver, copper = to_gsc(params.copper or 0 + )
|
||||
-- local settings = set(unpack(arg))
|
||||
--end
|
||||
|
||||
function M.to_string(money, pad, trim, decimal_points, color, no_color)
|
||||
function M.to_string(money, pad, trim, number_color, no_coin_color)
|
||||
local is_negative = money < 0
|
||||
money = abs(money)
|
||||
local gold, silver, copper = to_gsc(money)
|
||||
|
||||
-- rounding
|
||||
if decimal_points then
|
||||
copper = tonumber(format('%.' .. decimal_points .. 'f', copper))
|
||||
end
|
||||
|
||||
local gold_text, silver_text, copper_text
|
||||
if no_color then
|
||||
if no_coin_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, format_number(gold, false, nil, color) .. gold_text)
|
||||
tinsert(parts, number_color(gold) .. gold_text)
|
||||
end
|
||||
if silver > 0 then
|
||||
tinsert(parts, format_number(silver, pad, nil, color) .. silver_text)
|
||||
tinsert(parts, number_color(silver) .. silver_text)
|
||||
end
|
||||
if copper > 0 or gold == 0 and silver == 0 then
|
||||
tinsert(parts, format_number(copper, pad, decimal_points, color) .. copper_text)
|
||||
tinsert(parts, number_color(copper) .. copper_text)
|
||||
end
|
||||
text = join(parts, ' ')
|
||||
else
|
||||
if gold > 0 then
|
||||
text = format_number(gold, false, nil, color) .. gold_text .. ' ' .. format_number(silver, pad, nil, color) .. silver_text .. ' ' .. format_number(copper, pad, decimal_points, color) .. copper_text
|
||||
text = number_color(gold) .. gold_text .. ' ' .. number_color(silver) .. silver_text .. ' ' .. number_color(copper) .. copper_text
|
||||
elseif silver > 0 then
|
||||
text = format_number(silver, false, nil, color) .. silver_text .. ' ' .. format_number(copper, pad, decimal_points, color) .. copper_text
|
||||
text = number_color(silver) .. silver_text .. ' ' .. number_color(copper) .. copper_text
|
||||
else
|
||||
text = format_number(copper, false, decimal_points, color) .. copper_text
|
||||
text = number_color(copper) .. copper_text
|
||||
end
|
||||
end
|
||||
|
||||
if is_negative then
|
||||
if color then
|
||||
text = color .. '-' .. FONT_COLOR_CODE_CLOSE .. text
|
||||
else
|
||||
text = '-' .. text
|
||||
end
|
||||
text = number_color'-' .. text
|
||||
end
|
||||
|
||||
return text
|
||||
@@ -121,30 +108,17 @@ function M.from_string(value)
|
||||
return number * COPPER_PER_GOLD
|
||||
end
|
||||
|
||||
-- remove any colors
|
||||
value = gsub(gsub(strlower(value), '|c%x%x%x%x%x%x%x%x', ''), FONT_COLOR_CODE_CLOSE, '')
|
||||
|
||||
-- extract gold/silver/copper values
|
||||
local gold = tonumber(select(3, strfind(value, '(%d*%.?%d+)g')))
|
||||
local silver = tonumber(select(3, strfind(value, '(%d*%.?%d+)s')))
|
||||
local copper = tonumber(select(3, strfind(value, '(%d*%.?%d+)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, '%d*%.?%d+g', '', 1)
|
||||
value = gsub(value, '%d*%.?%d+s', '', 1)
|
||||
value = gsub(value, '%d*%.?%d+c', '', 1)
|
||||
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, decimal_padding, color)
|
||||
local padding = pad and 2 + (decimal_padding and decimal_padding + 1 or 0) or 0
|
||||
num = format('%0' .. padding .. '.0' .. (decimal_padding or 0) .. 'f', num)
|
||||
if color then
|
||||
return color .. num .. FONT_COLOR_CODE_CLOSE
|
||||
else
|
||||
return num
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user