big refactoring
This commit is contained in:
@@ -18,6 +18,7 @@ function C(r, g, b, a)
|
|||||||
end
|
end
|
||||||
|
|
||||||
M.color = immutable-{
|
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)},
|
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)},
|
label = immutable-{enabled = C(216, 225, 211, 1), disabled = C(150, 148, 140, 1)},
|
||||||
link = C(153, 255, 255, 1),
|
link = C(153, 255, 255, 1),
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ M.search_columns = {
|
|||||||
else
|
else
|
||||||
price = price_per_unit and ceil(record.unit_bid_price) or record.bid_price
|
price = price_per_unit and ceil(record.unit_bid_price) or record.bid_price
|
||||||
end
|
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,
|
end,
|
||||||
cmp = function(record_a, record_b, desc)
|
cmp = function(record_a, record_b, desc)
|
||||||
local price_a
|
local price_a
|
||||||
@@ -209,7 +209,7 @@ M.search_columns = {
|
|||||||
isPrice = true,
|
isPrice = true,
|
||||||
fill = function(cell, record)
|
fill = function(cell, record)
|
||||||
local price = price_per_unit and ceil(record.unit_buyout_price) or record.buyout_price
|
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,
|
end,
|
||||||
cmp = function(record_a, record_b, desc)
|
cmp = function(record_a, record_b, desc)
|
||||||
local price_a = price_per_unit and record_a.unit_buyout_price or record_a.buyout_price
|
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
|
else
|
||||||
price = price_per_unit and ceil(record.start_price / record.aux_quantity) or record.start_price
|
price = price_per_unit and ceil(record.start_price / record.aux_quantity) or record.start_price
|
||||||
end
|
end
|
||||||
cell.text:SetText(money.to_string(price, true, false))
|
cell.text:SetText(money.to_string(price, true))
|
||||||
end,
|
end,
|
||||||
cmp = function(record_a, record_b, desc)
|
cmp = function(record_a, record_b, desc)
|
||||||
local price_a
|
local price_a
|
||||||
@@ -339,7 +339,7 @@ M.auctions_columns = {
|
|||||||
isPrice = true,
|
isPrice = true,
|
||||||
fill = function(cell, record)
|
fill = function(cell, record)
|
||||||
local price = price_per_unit and ceil(record.unit_buyout_price) or record.buyout_price
|
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,
|
end,
|
||||||
cmp = function(record_a, record_b, desc)
|
cmp = function(record_a, record_b, desc)
|
||||||
local price_a = price_per_unit and record_a.unit_buyout_price or record_a.buyout_price
|
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,
|
isPrice = true,
|
||||||
fill = function(cell, record)
|
fill = function(cell, record)
|
||||||
local price = price_per_unit and ceil(record.unit_buyout_price) or record.buyout_price
|
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,
|
end,
|
||||||
cmp = function(record_a, record_b, desc)
|
cmp = function(record_a, record_b, desc)
|
||||||
local price_a = price_per_unit and record_a.unit_buyout_price or record_a.buyout_price
|
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
|
end
|
||||||
|
|
||||||
function set_unit_start_price(amount)
|
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
|
end
|
||||||
|
|
||||||
function get_unit_buyout_price()
|
function get_unit_buyout_price()
|
||||||
@@ -108,7 +108,7 @@ function get_unit_buyout_price()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function set_unit_buyout_price(amount)
|
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
|
end
|
||||||
|
|
||||||
function update_inventory_listing()
|
function update_inventory_listing()
|
||||||
@@ -127,14 +127,14 @@ function update_auction_listing(listing, records, reference)
|
|||||||
local stack_size = stack_size_slider:GetValue()
|
local stack_size = stack_size_slider:GetValue()
|
||||||
for i = 1, getn(records[selected_item.key] or empty) do
|
for i = 1, getn(records[selected_item.key] or empty) do
|
||||||
local record = records[selected_item.key][i]
|
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)
|
local price = record.unit_price * (listing == 'bid' and record.stack_size / stack_size_slider:GetValue() or 1)
|
||||||
tinsert(rows, O(
|
tinsert(rows, O(
|
||||||
'cols', A(
|
'cols', A(
|
||||||
O('value', record.own and color.green(record.count) or record.count),
|
O('value', record.own and color.green(record.count) or record.count),
|
||||||
O('value', al.time_left(record.duration)),
|
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', 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 '---')
|
O('value', historical_value and al.percentage_historical(round(price / historical_value * 100)) or '---')
|
||||||
),
|
),
|
||||||
'record', record
|
'record', record
|
||||||
@@ -146,7 +146,7 @@ function update_auction_listing(listing, records, reference)
|
|||||||
O('value', '---'),
|
O('value', '---'),
|
||||||
O('value', '---'),
|
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 '---')
|
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)
|
'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 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 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
|
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
|
end
|
||||||
|
|
||||||
refresh_button:Enable()
|
refresh_button:Enable()
|
||||||
@@ -382,7 +382,7 @@ function update_item(item)
|
|||||||
|
|
||||||
item.unit_vendor_price = unit_vendor_price(item.key)
|
item.unit_vendor_price = unit_vendor_price(item.key)
|
||||||
if not item.unit_vendor_price then
|
if not item.unit_vendor_price then
|
||||||
settings.hidden = true
|
settings.hidden = 1
|
||||||
write_settings(settings, item.key)
|
write_settings(settings, item.key)
|
||||||
refresh = true
|
refresh = true
|
||||||
return
|
return
|
||||||
@@ -410,8 +410,8 @@ function update_item(item)
|
|||||||
stack_size_slider:SetValue(huge)
|
stack_size_slider:SetValue(huge)
|
||||||
quantity_update(true)
|
quantity_update(true)
|
||||||
|
|
||||||
unit_start_price_input:SetText(money.to_string(settings.start_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, 3, 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
|
if not bid_records[selected_item.key] then
|
||||||
refresh_entries()
|
refresh_entries()
|
||||||
|
|||||||
+4
-4
@@ -248,12 +248,12 @@ do
|
|||||||
unit_buyout_price_input:SetFocus()
|
unit_buyout_price_input:SetFocus()
|
||||||
end
|
end
|
||||||
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.char = function() bid_selection, buyout_selection = nil, nil end
|
||||||
editbox.change = function() refresh = true end
|
editbox.change = function() refresh = true end
|
||||||
editbox.enter = function() this:ClearFocus() end
|
editbox.enter = function() this:ClearFocus() end
|
||||||
editbox.focus_loss = function()
|
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
|
end
|
||||||
do
|
do
|
||||||
local label = gui.label(editbox, gui.font_size.small)
|
local label = gui.label(editbox, gui.font_size.small)
|
||||||
@@ -283,12 +283,12 @@ do
|
|||||||
stack_size_slider.editbox:SetFocus()
|
stack_size_slider.editbox:SetFocus()
|
||||||
end
|
end
|
||||||
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.char = function() buyout_selection = nil end
|
||||||
editbox.change = function() refresh = true end
|
editbox.change = function() refresh = true end
|
||||||
editbox.enter = function() this:ClearFocus() end
|
editbox.enter = function() this:ClearFocus() end
|
||||||
editbox.focus_loss = function()
|
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
|
end
|
||||||
do
|
do
|
||||||
local label = gui.label(editbox, gui.font_size.small)
|
local label = gui.label(editbox, gui.font_size.small)
|
||||||
|
|||||||
+2
-2
@@ -415,7 +415,7 @@ function M.filter_string(components)
|
|||||||
local parameter = component[3]
|
local parameter = component[3]
|
||||||
if parameter then
|
if parameter then
|
||||||
if filter_util.filters[component[2]].input_type == 'money' 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
|
end
|
||||||
query_builder.append(parameter)
|
query_builder.append(parameter)
|
||||||
end
|
end
|
||||||
@@ -450,7 +450,7 @@ function prettified_filter_string(filter)
|
|||||||
prettified.append(info.display_name(cache.item_id(parameter)) or color.label.enabled('[' .. parameter .. ']'))
|
prettified.append(info.display_name(cache.item_id(parameter)) or color.label.enabled('[' .. parameter .. ']'))
|
||||||
else
|
else
|
||||||
if filters[component[2]].input_type == 'money' then
|
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
|
else
|
||||||
prettified.append(color.label.enabled(parameter))
|
prettified.append(color.label.enabled(parameter))
|
||||||
end
|
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 PART = color .. '.|cff%s%02d' .. FONT_COLOR_CODE_CLOSE
|
||||||
local NONE = '|cffa0a0a0' .. TEXT_NONE .. FONT_COLOR_CODE_CLOSE
|
local NONE = '|cffa0a0a0' .. TEXT_NONE .. FONT_COLOR_CODE_CLOSE
|
||||||
|
|
||||||
if not exact and money >= 10000 then
|
if not exact and money >= COPPER_PER_GOLD then
|
||||||
-- Round to nearest silver
|
money = floor(money / COPPER_PER_SILVER + .5) * COPPER_PER_SILVER
|
||||||
money = floor(money / 100 + .5) * 100
|
|
||||||
end
|
end
|
||||||
local g, s, c = to_gsc(money)
|
local g, s, c = to_gsc(money)
|
||||||
|
|
||||||
@@ -59,57 +58,45 @@ function M.to_string2(money, exact, color)
|
|||||||
return str
|
return str
|
||||||
end
|
end
|
||||||
|
|
||||||
--function M.to_string(params) -- TODO
|
function M.to_string(money, pad, trim, number_color, no_coin_color)
|
||||||
-- 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)
|
|
||||||
local is_negative = money < 0
|
local is_negative = money < 0
|
||||||
money = abs(money)
|
money = abs(money)
|
||||||
local gold, silver, copper = to_gsc(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
|
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'
|
gold_text, silver_text, copper_text = 'g', 's', 'c'
|
||||||
else
|
else
|
||||||
gold_text, silver_text, copper_text = GOLD_TEXT, SILVER_TEXT, COPPER_TEXT
|
gold_text, silver_text, copper_text = GOLD_TEXT, SILVER_TEXT, COPPER_TEXT
|
||||||
end
|
end
|
||||||
|
|
||||||
|
number_color = number_color or color.none
|
||||||
|
|
||||||
local text
|
local text
|
||||||
if trim then
|
if trim then
|
||||||
local parts = temp-T
|
local parts = temp-T
|
||||||
if gold > 0 then
|
if gold > 0 then
|
||||||
tinsert(parts, format_number(gold, false, nil, color) .. gold_text)
|
tinsert(parts, number_color(gold) .. gold_text)
|
||||||
end
|
end
|
||||||
if silver > 0 then
|
if silver > 0 then
|
||||||
tinsert(parts, format_number(silver, pad, nil, color) .. silver_text)
|
tinsert(parts, number_color(silver) .. silver_text)
|
||||||
end
|
end
|
||||||
if copper > 0 or gold == 0 and silver == 0 then
|
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
|
end
|
||||||
text = join(parts, ' ')
|
text = join(parts, ' ')
|
||||||
else
|
else
|
||||||
if gold > 0 then
|
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
|
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
|
else
|
||||||
text = format_number(copper, false, decimal_points, color) .. copper_text
|
text = number_color(copper) .. copper_text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_negative then
|
if is_negative then
|
||||||
if color then
|
text = number_color'-' .. text
|
||||||
text = color .. '-' .. FONT_COLOR_CODE_CLOSE .. text
|
|
||||||
else
|
|
||||||
text = '-' .. text
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return text
|
return text
|
||||||
@@ -121,16 +108,13 @@ function M.from_string(value)
|
|||||||
return number * COPPER_PER_GOLD
|
return number * COPPER_PER_GOLD
|
||||||
end
|
end
|
||||||
|
|
||||||
-- remove any colors
|
|
||||||
value = gsub(gsub(strlower(value), '|c%x%x%x%x%x%x%x%x', ''), FONT_COLOR_CODE_CLOSE, '')
|
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 gold = tonumber(select(3, strfind(value, '(%d*%.?%d+)g')))
|
||||||
local silver = tonumber(select(3, strfind(value, '(%d*%.?%d+)s')))
|
local silver = tonumber(select(3, strfind(value, '(%d*%.?%d+)s')))
|
||||||
local copper = tonumber(select(3, strfind(value, '(%d*%.?%d+)c')))
|
local copper = tonumber(select(3, strfind(value, '(%d*%.?%d+)c')))
|
||||||
if not gold and not silver and not copper then return end
|
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+g', '', 1)
|
||||||
value = gsub(value, '%d*%.?%d+s', '', 1)
|
value = gsub(value, '%d*%.?%d+s', '', 1)
|
||||||
value = gsub(value, '%d*%.?%d+c', '', 1)
|
value = gsub(value, '%d*%.?%d+c', '', 1)
|
||||||
@@ -138,13 +122,3 @@ function M.from_string(value)
|
|||||||
|
|
||||||
return from_gsc(gold or 0, silver or 0, copper or 0)
|
return from_gsc(gold or 0, silver or 0, copper or 0)
|
||||||
end
|
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