refactoring
This commit is contained in:
@@ -83,7 +83,7 @@ function private.extend_tooltip(tooltip, hyperlink, quantity)
|
|||||||
local color = {r=0.1, g=0.6, b=0.6}
|
local color = {r=0.1, g=0.6, b=0.6}
|
||||||
|
|
||||||
local disenchant_value = aux.disenchant.value(item_info.slot, item_info.quality, item_info.level)
|
local disenchant_value = aux.disenchant.value(item_info.slot, item_info.quality, item_info.level)
|
||||||
tooltip:AddLine('Disenchant Value: '..(disenchant_value and aux.util.format_money(disenchant_value) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
|
tooltip:AddLine('Disenchant Value: '..(disenchant_value and aux.money.format(disenchant_value) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -93,7 +93,7 @@ function private.extend_tooltip(tooltip, hyperlink, quantity)
|
|||||||
|
|
||||||
local _, price, limited = aux.cache.merchant_info(item_id)
|
local _, price, limited = aux.cache.merchant_info(item_id)
|
||||||
if price then
|
if price then
|
||||||
tooltip:AddLine('Vendor Buy '..(limited and '(limited): ' or ': ')..aux.util.format_money(price * quantity), color.r, color.g, color.b)
|
tooltip:AddLine('Vendor Buy '..(limited and '(limited): ' or ': ')..aux.money.format(price * quantity), color.r, color.g, color.b)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if aux_tooltip_vendor_sell then
|
if aux_tooltip_vendor_sell then
|
||||||
@@ -101,7 +101,7 @@ function private.extend_tooltip(tooltip, hyperlink, quantity)
|
|||||||
|
|
||||||
local price = aux.cache.merchant_info(item_id)
|
local price = aux.cache.merchant_info(item_id)
|
||||||
if price ~= 0 then
|
if price ~= 0 then
|
||||||
tooltip:AddLine('Vendor Sell: '..(price and aux.util.format_money(price * quantity) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
|
tooltip:AddLine('Vendor Sell: '..(price and aux.money.format(price * quantity) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -113,11 +113,11 @@ function private.extend_tooltip(tooltip, hyperlink, quantity)
|
|||||||
local value = aux.history.value(item_key)
|
local value = aux.history.value(item_key)
|
||||||
if auctionable then
|
if auctionable then
|
||||||
if aux_tooltip_value then
|
if aux_tooltip_value then
|
||||||
tooltip:AddLine('Value: '..(value and aux.util.format_money(value * quantity) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
|
tooltip:AddLine('Value: '..(value and aux.money.format(value * quantity) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
|
||||||
end
|
end
|
||||||
if aux_tooltip_daily then
|
if aux_tooltip_daily then
|
||||||
local market_value = aux.history.market_value(item_key)
|
local market_value = aux.history.market_value(item_key)
|
||||||
tooltip:AddLine('Today: '..(market_value and aux.util.format_money(market_value * quantity)..' ('..aux.auction_listing.percentage_historical(aux.util.round(market_value / value * 100))..')' or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
|
tooltip:AddLine('Today: '..(market_value and aux.money.format(market_value * quantity)..' ('..aux.auction_listing.percentage_historical(aux.util.round(market_value / value * 100))..')' or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -7,17 +7,17 @@ public.last_owner_page_requested = nil
|
|||||||
do
|
do
|
||||||
local mt = {
|
local mt = {
|
||||||
__newindex = function(self, key, value)
|
__newindex = function(self, key, value)
|
||||||
self._f()[key] = value
|
self._getter()[key] = value
|
||||||
end,
|
end,
|
||||||
__index = function(self, key)
|
__index = function(self, key)
|
||||||
return self._f()[key]
|
return self._getter()[key]
|
||||||
end,
|
end,
|
||||||
__call = function(self)
|
__call = function(self)
|
||||||
return self._f()
|
return self._getter()
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
function public.dynamic_table(f)
|
function public.dynamic_table(getter)
|
||||||
return setmetatable({_f=f}, mt)
|
return setmetatable({_getter=getter}, mt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ end
|
|||||||
do
|
do
|
||||||
local function cost_label(cost)
|
local function cost_label(cost)
|
||||||
local label = LIGHTYELLOW_FONT_COLOR_CODE..'(Total Cost: '..FONT_COLOR_CODE_CLOSE
|
local label = LIGHTYELLOW_FONT_COLOR_CODE..'(Total Cost: '..FONT_COLOR_CODE_CLOSE
|
||||||
label = label..(cost and m.util.format_money(cost, nil, LIGHTYELLOW_FONT_COLOR_CODE) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE)
|
label = label..(cost and m.money.format(cost, nil, LIGHTYELLOW_FONT_COLOR_CODE) or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE)
|
||||||
label = label..LIGHTYELLOW_FONT_COLOR_CODE..')'..FONT_COLOR_CODE_CLOSE
|
label = label..LIGHTYELLOW_FONT_COLOR_CODE..')'..FONT_COLOR_CODE_CLOSE
|
||||||
return label
|
return label
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,28 +21,37 @@ public.config = {
|
|||||||
huge_font_size = 23,
|
huge_font_size = 23,
|
||||||
}
|
}
|
||||||
|
|
||||||
public.color = aux.index_function(function(_, key)
|
do
|
||||||
local t = m.config.color
|
local self = aux_module()
|
||||||
return aux.index_function(function(self, key)
|
function private.color2(r, g, b, a)
|
||||||
t = t[key]
|
return aux.index_function(function(_, key)
|
||||||
if getn(t) == 0 then
|
|
||||||
return self
|
end)
|
||||||
end
|
end
|
||||||
local color = aux.util.copy(t)
|
end
|
||||||
for i=1,3 do
|
|
||||||
color[i] = color[i]/255
|
function private.color_accessor(callback)
|
||||||
end
|
return aux.index_function(function(_, key)
|
||||||
return color
|
local t = m.config.color
|
||||||
end)[key]
|
return aux.index_function(function(self, key)
|
||||||
|
t = t[key]
|
||||||
|
if getn(t) == 0 then
|
||||||
|
return self
|
||||||
|
else
|
||||||
|
return callback(aux.util.copy(t))
|
||||||
|
end
|
||||||
|
end)[key]
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
public.color = m.color_accessor(function(color)
|
||||||
|
for i=1,3 do
|
||||||
|
color[i] = color[i]/255
|
||||||
|
end
|
||||||
|
return color
|
||||||
end)
|
end)
|
||||||
|
|
||||||
public.inline_color = aux.index_function(function(self, key)
|
public.inline_color = m.color_accessor(function(color)
|
||||||
self._t = (rawget(self, '_t') or m.config.color)[key]
|
|
||||||
if getn(self._t) == 0 then
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
local color = aux.util.copy(self._t)
|
|
||||||
self._t = nil
|
|
||||||
tinsert(color, 1, tremove(color))
|
tinsert(color, 1, tremove(color))
|
||||||
return format('|c%02X%02X%02X%02X', unpack(color))
|
return format('|c%02X%02X%02X%02X', unpack(color))
|
||||||
end)
|
end)
|
||||||
@@ -69,11 +78,11 @@ do
|
|||||||
local orig = menu:GetScript('OnShow')
|
local orig = menu:GetScript('OnShow')
|
||||||
menu:SetScript('OnShow', function()
|
menu:SetScript('OnShow', function()
|
||||||
UIMenu_Initialize()
|
UIMenu_Initialize()
|
||||||
for _, element in ipairs(structure) do
|
for i=1,getn(structure) do
|
||||||
UIMenu_AddButton(
|
UIMenu_AddButton(
|
||||||
element[1],
|
structure[i][1],
|
||||||
element[2],
|
structure[i],
|
||||||
type(element[3]) == 'string' and structure[element[3]] or element[3]
|
type(structure[i]) == 'string' and structure[element[3]] or element[3]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
return orig()
|
return orig()
|
||||||
|
|||||||
+10
-15
@@ -10,6 +10,7 @@ public.COLORS = {
|
|||||||
YELLOW = '|cffffff00',
|
YELLOW = '|cffffff00',
|
||||||
ORANGE = '|cffff9218',
|
ORANGE = '|cffff9218',
|
||||||
RED = '|cffff0000',
|
RED = '|cffff0000',
|
||||||
|
GRAY = '|cffbbbbbb',
|
||||||
}
|
}
|
||||||
|
|
||||||
local AUCTION_PCT_COLORS = {
|
local AUCTION_PCT_COLORS = {
|
||||||
@@ -535,25 +536,19 @@ function private.record_percentage(record)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.percentage_historical(pct, based_on_bid)
|
function private.percentage_color(pct)
|
||||||
local pctColor = '|cffffffff'
|
for i=1,getn(AUCTION_PCT_COLORS) do
|
||||||
|
if pct < AUCTION_PCT_COLORS[i].value then
|
||||||
if based_on_bid then
|
return AUCTION_PCT_COLORS[i].color
|
||||||
pctColor = '|cffbbbbbb'
|
end
|
||||||
else
|
end
|
||||||
for i=1, getn(AUCTION_PCT_COLORS) do
|
end
|
||||||
if pct < AUCTION_PCT_COLORS[i].value then
|
|
||||||
pctColor = AUCTION_PCT_COLORS[i].color
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
function public.percentage_historical(pct, bid)
|
||||||
if pct > 10000 then
|
if pct > 10000 then
|
||||||
pct = '>10000'
|
pct = '>10000'
|
||||||
end
|
end
|
||||||
|
return (bid and m.COLORS.GRAY or m.percentage_color(pct))..pct..'%'..FONT_COLOR_CODE_CLOSE
|
||||||
return format('%s%s%%|r', pctColor, pct)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.time_left(code)
|
function public.time_left(code)
|
||||||
|
|||||||
+55
-95
@@ -1,15 +1,42 @@
|
|||||||
local m, public, private = aux.module'util'
|
local m, public, private = aux.module'util'
|
||||||
|
|
||||||
function public.bound(lower_bound, upper_bound, number)
|
function public.pack(table, ...)
|
||||||
return max(lower_bound, min(upper_bound, number))
|
local array = {}
|
||||||
|
for i=1,arg.n do
|
||||||
|
tinsert(array, table[arg[i]])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function public.unpack(array, ...)
|
||||||
|
local table, index = {}, {}
|
||||||
|
for i=1,arg.n do
|
||||||
|
table[arg[i]] = array[i]
|
||||||
|
tinsert(index, arg[i])
|
||||||
|
end
|
||||||
|
return table, index
|
||||||
|
end
|
||||||
|
|
||||||
|
function public.pick(indices, ...)
|
||||||
|
local t = {}
|
||||||
|
for _, index in indices do
|
||||||
|
tinsert(t, arg[index])
|
||||||
|
end
|
||||||
|
return unpack(t)
|
||||||
|
end
|
||||||
|
|
||||||
|
function public.select(i, ...)
|
||||||
|
for _=1,i-1 do
|
||||||
|
tremove(arg, 1)
|
||||||
|
end
|
||||||
|
return unpack(arg)
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.size(t)
|
function public.size(t)
|
||||||
local x = 0
|
local size = 0
|
||||||
for _ in t do
|
for _ in t do
|
||||||
x = x + 1
|
size = size + 1
|
||||||
end
|
end
|
||||||
return x
|
return size
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.key(value, t)
|
function public.key(value, t)
|
||||||
@@ -36,13 +63,6 @@ function public.values(t)
|
|||||||
return vs
|
return vs
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.select(i, ...)
|
|
||||||
for _=1,i-1 do
|
|
||||||
tremove(arg, 1)
|
|
||||||
end
|
|
||||||
return unpack(arg)
|
|
||||||
end
|
|
||||||
|
|
||||||
function public.eq(t1, t2)
|
function public.eq(t1, t2)
|
||||||
if not t1 or not t2 then
|
if not t1 or not t2 then
|
||||||
return false
|
return false
|
||||||
@@ -63,6 +83,23 @@ function public.eq(t1, t2)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function public.wipe(t)
|
||||||
|
while getn(t) > 0 do
|
||||||
|
tremove(t)
|
||||||
|
end
|
||||||
|
for k, _ in t do
|
||||||
|
t[k] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function public.copy(t)
|
||||||
|
local copy = {}
|
||||||
|
for k, v in t do
|
||||||
|
copy[k] = v
|
||||||
|
end
|
||||||
|
return copy
|
||||||
|
end
|
||||||
|
|
||||||
function public.any(xs, p)
|
function public.any(xs, p)
|
||||||
local holds = false
|
local holds = false
|
||||||
for _, x in xs do
|
for _, x in xs do
|
||||||
@@ -112,32 +149,6 @@ do
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- local methods = {}
|
|
||||||
--
|
|
||||||
-- function methods:add(key)
|
|
||||||
-- self[key] = true
|
|
||||||
-- end
|
|
||||||
--
|
|
||||||
-- function methods:remove(key)
|
|
||||||
-- self[key] = nil
|
|
||||||
-- end
|
|
||||||
--
|
|
||||||
-- function methods:size()
|
|
||||||
-- local size = 0
|
|
||||||
-- for _,_ in self do
|
|
||||||
-- size = size + 1
|
|
||||||
-- end
|
|
||||||
-- return size
|
|
||||||
-- end
|
|
||||||
--
|
|
||||||
-- function methods:elements()
|
|
||||||
-- local elements = {}
|
|
||||||
-- for element, _ in self do
|
|
||||||
-- tinsert(elements, element)
|
|
||||||
-- end
|
|
||||||
-- return elements
|
|
||||||
-- end
|
|
||||||
|
|
||||||
function public.set(...)
|
function public.set(...)
|
||||||
local self = {}
|
local self = {}
|
||||||
for i=1,arg.n do
|
for i=1,arg.n do
|
||||||
@@ -147,6 +158,10 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function public.trim(str)
|
||||||
|
return gsub(str, '^%s*(.-)%s*$', '%1')
|
||||||
|
end
|
||||||
|
|
||||||
function public.join(parts, separator)
|
function public.join(parts, separator)
|
||||||
local str = parts[1] or ''
|
local str = parts[1] or ''
|
||||||
for i=2,getn(parts) do
|
for i=2,getn(parts) do
|
||||||
@@ -181,31 +196,14 @@ function public.tokenize(str)
|
|||||||
return tokens
|
return tokens
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.wipe(t)
|
function public.bound(lower_bound, upper_bound, number)
|
||||||
while getn(t) > 0 do
|
return max(lower_bound, min(upper_bound, number))
|
||||||
tremove(t)
|
|
||||||
end
|
|
||||||
for k, _ in t do
|
|
||||||
t[k] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function public.copy(t)
|
|
||||||
local copy = {}
|
|
||||||
for k, v in t do
|
|
||||||
copy[k] = v
|
|
||||||
end
|
|
||||||
return copy
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.round(x)
|
function public.round(x)
|
||||||
return floor(x + 0.5)
|
return floor(x + 0.5)
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.trim(str)
|
|
||||||
return gsub(str, '^%s*(.-)%s*$', '%1')
|
|
||||||
end
|
|
||||||
|
|
||||||
function public.inventory()
|
function public.inventory()
|
||||||
local bag, slot = 0, 0
|
local bag, slot = 0, 0
|
||||||
|
|
||||||
@@ -251,41 +249,3 @@ function public.signal()
|
|||||||
return params
|
return params
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.format_money(money, exact, color)
|
|
||||||
color = color or FONT_COLOR_CODE_CLOSE
|
|
||||||
|
|
||||||
local TEXT_NONE = '0'
|
|
||||||
|
|
||||||
local GSC_GOLD = 'ffd100'
|
|
||||||
local GSC_SILVER = 'e6e6e6'
|
|
||||||
local GSC_COPPER = 'c8602c'
|
|
||||||
local GSC_START = '|cff%s%d|r'
|
|
||||||
local GSC_PART = color..'.|cff%s%02d|r'
|
|
||||||
local GSC_NONE = '|cffa0a0a0'..TEXT_NONE..FONT_COLOR_CODE_CLOSE
|
|
||||||
|
|
||||||
if not exact and money >= 10000 then
|
|
||||||
-- Round to nearest silver
|
|
||||||
money = floor(money / 100 + 0.5) * 100
|
|
||||||
end
|
|
||||||
local g, s, c = aux.money.to_GSC(money)
|
|
||||||
|
|
||||||
local gsc = ''
|
|
||||||
|
|
||||||
local fmt = GSC_START
|
|
||||||
if g > 0 then
|
|
||||||
gsc = gsc..format(fmt, GSC_GOLD, g)
|
|
||||||
fmt = GSC_PART
|
|
||||||
end
|
|
||||||
if s > 0 or c > 0 then
|
|
||||||
gsc = gsc..format(fmt, GSC_SILVER, s)
|
|
||||||
fmt = GSC_PART
|
|
||||||
end
|
|
||||||
if c > 0 then
|
|
||||||
gsc = gsc..format(fmt, GSC_COPPER, c)
|
|
||||||
end
|
|
||||||
if gsc == '' then
|
|
||||||
gsc = GSC_NONE
|
|
||||||
end
|
|
||||||
return gsc
|
|
||||||
end
|
|
||||||
@@ -20,6 +20,44 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function public.format(money, exact, color)
|
||||||
|
color = color or FONT_COLOR_CODE_CLOSE
|
||||||
|
|
||||||
|
local TEXT_NONE = '0'
|
||||||
|
|
||||||
|
local GSC_GOLD = 'ffd100'
|
||||||
|
local GSC_SILVER = 'e6e6e6'
|
||||||
|
local GSC_COPPER = 'c8602c'
|
||||||
|
local GSC_START = '|cff%s%d'..FONT_COLOR_CODE_CLOSE
|
||||||
|
local GSC_PART = color..'.|cff%s%02d'..FONT_COLOR_CODE_CLOSE
|
||||||
|
local GSC_NONE = '|cffa0a0a0'..TEXT_NONE..FONT_COLOR_CODE_CLOSE
|
||||||
|
|
||||||
|
if not exact and money >= 10000 then
|
||||||
|
-- Round to nearest silver
|
||||||
|
money = floor(money / 100 + 0.5) * 100
|
||||||
|
end
|
||||||
|
local g, s, c = aux.money.to_GSC(money)
|
||||||
|
|
||||||
|
local gsc = ''
|
||||||
|
|
||||||
|
local fmt = GSC_START
|
||||||
|
if g > 0 then
|
||||||
|
gsc = gsc..format(fmt, GSC_GOLD, g)
|
||||||
|
fmt = GSC_PART
|
||||||
|
end
|
||||||
|
if s > 0 or c > 0 then
|
||||||
|
gsc = gsc..format(fmt, GSC_SILVER, s)
|
||||||
|
fmt = GSC_PART
|
||||||
|
end
|
||||||
|
if c > 0 then
|
||||||
|
gsc = gsc..format(fmt, GSC_COPPER, c)
|
||||||
|
end
|
||||||
|
if gsc == '' then
|
||||||
|
gsc = GSC_NONE
|
||||||
|
end
|
||||||
|
return gsc
|
||||||
|
end
|
||||||
|
|
||||||
function public.to_string(money, pad, trim, decimal_points, color, no_color)
|
function public.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)
|
||||||
|
|||||||
Reference in New Issue
Block a user