color and module refactoring
This commit is contained in:
@@ -1,61 +1,40 @@
|
|||||||
module 'aux'
|
module 'aux'
|
||||||
|
|
||||||
local COLORS = {
|
function C(r, g, b, a)
|
||||||
text = {enabled = {255, 254, 250, 1}, disabled = {147, 151, 139, 1}},
|
local mt = O('__metatable', false, '__newindex', nop, 'color', A(r, g, b, a))
|
||||||
label = {enabled = {216, 225, 211, 1}, disabled = {150, 148, 140, 1}},
|
function mt:__call(text)
|
||||||
link = {153, 255, 255, 1},
|
local r, g, b, a = unpack(mt.color)
|
||||||
window = {background = {24, 24, 24, .93}, border = {30, 30, 30, 1}},
|
if text then
|
||||||
panel = {background = {24, 24, 24, 1}, border = {255, 255, 255, .03}},
|
return format('|c%02X%02X%02X%02X', a, r, g, b) .. text .. FONT_COLOR_CODE_CLOSE
|
||||||
content = {background = {42, 42, 42, 1}, border = {0, 0, 0, 0}},
|
|
||||||
state = {enabled = {70, 140, 70, 1}, disabled = {140, 70, 70, 1}},
|
|
||||||
|
|
||||||
blue = {41, 146, 255, 1},
|
|
||||||
green = {22, 255, 22, 1},
|
|
||||||
yellow = {255, 255, 0, 1},
|
|
||||||
orange = {255, 146, 24, 1},
|
|
||||||
red = {255, 0, 0, 1},
|
|
||||||
gray = {187, 187, 187, 1},
|
|
||||||
|
|
||||||
blizzard = {0, 180, 255, 1},
|
|
||||||
aux = {255, 255, 154, 1},
|
|
||||||
}
|
|
||||||
|
|
||||||
do
|
|
||||||
local function index_handler(self, key)
|
|
||||||
self.private.table = self.private.table[key]
|
|
||||||
if getn(self.private.table) == 0 then
|
|
||||||
return self.public
|
|
||||||
else
|
else
|
||||||
local color = copy(self.private.table)
|
return r/255, g/255, b/255, a
|
||||||
self.private.table = COLORS
|
|
||||||
return self.private.callback(color)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function color_accessor(callback)
|
function mt:__concat(text)
|
||||||
return function()
|
local r, g, b, a = unpack(mt.color)
|
||||||
return index_function({callback=callback, table=COLORS}, index_handler)
|
return format('|c%02X%02X%02X%02X', a, r, g, b) .. text
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
return setmetatable(T, mt)
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
W = wrapper
|
||||||
local mt = {
|
|
||||||
__call = function(self, text)
|
|
||||||
local r, g, b, a = unpack(self)
|
|
||||||
if text then
|
|
||||||
return format('|c%02X%02X%02X%02X', a, r*255, g*255, b*255) .. text .. FONT_COLOR_CODE_CLOSE
|
|
||||||
else
|
|
||||||
return r, g, b, a
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
|
||||||
M.get_color = color_accessor(function(color)
|
|
||||||
local r, g, b, a = unpack(color)
|
|
||||||
return setmetatable(A(r/255, g/255, b/255, a), mt)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
M.get_inline_color = color_accessor(function(color)
|
M.color = W-{
|
||||||
local r, g, b, a = unpack(color)
|
text = W-{enabled = C(255, 254, 250, 1), disabled = C(147, 151, 139, 1)},
|
||||||
return format('|c%02X%02X%02X%02X', a, r, g, b)
|
label = W-{enabled = C(216, 225, 211, 1), disabled = C(150, 148, 140, 1)},
|
||||||
end)
|
link = C(153, 255, 255, 1),
|
||||||
|
window = W-{background = C(24, 24, 24, .93), border = C(30, 30, 30, 1)},
|
||||||
|
panel = W-{background = C(24, 24, 24, 1), border = C(255, 255, 255, .03)},
|
||||||
|
content = W-{background = C(42, 42, 42, 1), border = C(0, 0, 0, 0)},
|
||||||
|
state = W-{enabled = C(70, 140, 70, 1), disabled = C(140, 70, 70, 1)},
|
||||||
|
|
||||||
|
blue = C(41, 146, 255, 1),
|
||||||
|
green = C(22, 255, 22, 1),
|
||||||
|
yellow = C(255, 255, 0, 1),
|
||||||
|
orange = C(255, 146, 24, 1),
|
||||||
|
red = C(255, 0, 0, 1),
|
||||||
|
gray = C(187, 187, 187, 1),
|
||||||
|
|
||||||
|
blizzard = C(0, 180, 255, 1),
|
||||||
|
aux = C(255, 255, 154, 1),
|
||||||
|
}
|
||||||
|
|||||||
+4
-4
@@ -90,7 +90,7 @@ function M.value(item_key)
|
|||||||
end
|
end
|
||||||
value = weighted_median(weighted_values)
|
value = weighted_median(weighted_values)
|
||||||
else
|
else
|
||||||
value = calculate_market_value(item_record)
|
value = market_value(item_record)
|
||||||
end
|
end
|
||||||
value_cache[item_key] = O('value', value, 'next_push', item_record.next_push)
|
value_cache[item_key] = O('value', value, 'next_push', item_record.next_push)
|
||||||
end
|
end
|
||||||
@@ -98,10 +98,10 @@ function M.value(item_key)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.market_value(item_key)
|
function M.market_value(item_key)
|
||||||
return calculate_market_value(read_record(item_key))
|
return market_value(read_record(item_key))
|
||||||
end
|
end
|
||||||
|
|
||||||
function calculate_market_value(item_record)
|
function market_value(item_record)
|
||||||
return item_record.daily_min_buyout and min(ceil(item_record.daily_min_buyout * 1.15), item_record.daily_max_price)
|
return item_record.daily_min_buyout and min(ceil(item_record.daily_min_buyout * 1.15), item_record.daily_max_price)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ function weighted_median(list)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function push_record(item_record)
|
function push_record(item_record)
|
||||||
for market_value in present(calculate_market_value(item_record)) do
|
for market_value in present(market_value(item_record)) do
|
||||||
tinsert(item_record.data_points, 1, weak-O('market_value', market_value, 'time', item_record.next_push))
|
tinsert(item_record.data_points, 1, weak-O('market_value', market_value, 'time', item_record.next_push))
|
||||||
while getn(item_record.data_points) > 11 do
|
while getn(item_record.data_points) > 11 do
|
||||||
release(item_record.data_points[getn(item_record.data_points)])
|
release(item_record.data_points[getn(item_record.data_points)])
|
||||||
|
|||||||
+10
-10
@@ -17,11 +17,11 @@ local HEAD_HEIGHT = 27
|
|||||||
local HEAD_SPACE = 2
|
local HEAD_SPACE = 2
|
||||||
|
|
||||||
local AUCTION_PCT_COLORS = {
|
local AUCTION_PCT_COLORS = {
|
||||||
{color=inline_color.blue, value=50},
|
{color=color.blue, value=50},
|
||||||
{color=inline_color.green, value=80},
|
{color=color.green, value=80},
|
||||||
{color=inline_color.yellow, value=110},
|
{color=color.yellow, value=110},
|
||||||
{color=inline_color.orange, value=135},
|
{color=color.orange, value=135},
|
||||||
{color=inline_color.red, value=huge},
|
{color=color.red, value=huge},
|
||||||
}
|
}
|
||||||
|
|
||||||
local TIME_LEFT_STRINGS = {
|
local TIME_LEFT_STRINGS = {
|
||||||
@@ -168,9 +168,9 @@ M.search_config = {
|
|||||||
fill = function(cell, record)
|
fill = function(cell, record)
|
||||||
local color
|
local color
|
||||||
if record.high_bidder then
|
if record.high_bidder then
|
||||||
color = inline_color.green
|
color = color.green
|
||||||
elseif record.high_bid ~= 0 then
|
elseif record.high_bid ~= 0 then
|
||||||
color = inline_color.orange
|
color = color.orange
|
||||||
end
|
end
|
||||||
local price
|
local price
|
||||||
if record.high_bidder then
|
if record.high_bidder then
|
||||||
@@ -270,7 +270,7 @@ M.auctions_config = {
|
|||||||
width = .06,
|
width = .06,
|
||||||
align = 'CENTER',
|
align = 'CENTER',
|
||||||
fill = function(cell, record, count, own, expandable)
|
fill = function(cell, record, count, own, expandable)
|
||||||
local numAuctionsText = expandable and inline_color.link .. count .. FONT_COLOR_CODE_CLOSE or count
|
local numAuctionsText = expandable and color.link(count) or count
|
||||||
cell:SetText(numAuctionsText)
|
cell:SetText(numAuctionsText)
|
||||||
end,
|
end,
|
||||||
cmp = function(record_a, record_b, desc)
|
cmp = function(record_a, record_b, desc)
|
||||||
@@ -404,7 +404,7 @@ M.bids_config = {
|
|||||||
width = .06,
|
width = .06,
|
||||||
align = 'CENTER',
|
align = 'CENTER',
|
||||||
fill = function(cell, record, count, own, expandable)
|
fill = function(cell, record, count, own, expandable)
|
||||||
local numAuctionsText = expandable and inline_color.link .. count .. FONT_COLOR_CODE_CLOSE or count
|
local numAuctionsText = expandable and color.link(count) or count
|
||||||
cell:SetText(numAuctionsText)
|
cell:SetText(numAuctionsText)
|
||||||
end,
|
end,
|
||||||
cmp = function(record_a, record_b, desc)
|
cmp = function(record_a, record_b, desc)
|
||||||
@@ -549,7 +549,7 @@ function percentage_color(pct)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.percentage_historical(pct, bid)
|
function M.percentage_historical(pct, bid)
|
||||||
return (bid and inline_color.gray or percentage_color(pct)) .. (pct > 10000 and '>10000' or pct) .. '%' .. FONT_COLOR_CODE_CLOSE
|
return (bid and color.gray or percentage_color(pct)) .. (pct > 10000 and '>10000' or pct) .. '%' .. FONT_COLOR_CODE_CLOSE
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.time_left(code)
|
function M.time_left(code)
|
||||||
|
|||||||
+6
-3
@@ -11,9 +11,12 @@ function define(self, k, v, private)
|
|||||||
if type(k) ~= 'string' or not strfind(k, '^[_%a][_%w]*') then error('Invalid identifier "%s".', k) end
|
if type(k) ~= 'string' or not strfind(k, '^[_%a][_%w]*') then error('Invalid identifier "%s".', k) end
|
||||||
local _, _, prefix, suffix = strfind(k, '^(.?.?.?.?)([_%a].*)')
|
local _, _, prefix, suffix = strfind(k, '^(.?.?.?.?)([_%a].*)')
|
||||||
local module = loaded[self]
|
local module = loaded[self]
|
||||||
module.defined[k] = module.defined[k] and error('Duplicate identifier "%s".', k) or true
|
local signature = (private and '-' or '+') .. k
|
||||||
module.fields[k] = v
|
module.defined[signature] = module.defined[signature] and error('Duplicate identifier "%s".', signature) or true
|
||||||
if prefix == 'get_' then module.accessors[suffix] = v elseif prefix == 'set_' then module.mutators[suffix] = v end
|
if private or not module.defined['-' .. k] then
|
||||||
|
module.fields[k] = v
|
||||||
|
if prefix == 'get_' then module.accessors[suffix] = v elseif prefix == 'set_' then module.mutators[suffix] = v end
|
||||||
|
end
|
||||||
if not private then
|
if not private then
|
||||||
module.public_fields[k] = v
|
module.public_fields[k] = v
|
||||||
if prefix == 'get_' then module.public_accessors[suffix] = v elseif prefix == 'set_' then module.public_mutators[suffix] = v end
|
if prefix == 'get_' then module.public_accessors[suffix] = v elseif prefix == 'set_' then module.public_mutators[suffix] = v end
|
||||||
|
|||||||
+11
-9
@@ -130,20 +130,20 @@ function update_auction_listing()
|
|||||||
|
|
||||||
local bid_color
|
local bid_color
|
||||||
if blizzard_bid_undercut < unit_start_price and stack_blizzard_bid_undercut < unit_start_price then
|
if blizzard_bid_undercut < unit_start_price and stack_blizzard_bid_undercut < unit_start_price then
|
||||||
bid_color = inline_color.red
|
bid_color = color.red
|
||||||
elseif blizzard_bid_undercut < unit_start_price then
|
elseif blizzard_bid_undercut < unit_start_price then
|
||||||
bid_color = inline_color.orange
|
bid_color = color.orange
|
||||||
elseif stack_blizzard_bid_undercut < unit_start_price then
|
elseif stack_blizzard_bid_undercut < unit_start_price then
|
||||||
bid_color = inline_color.yellow
|
bid_color = color.yellow
|
||||||
end
|
end
|
||||||
|
|
||||||
local buyout_color
|
local buyout_color
|
||||||
if buyout_price_undercut < unit_buyout_price and stack_buyout_price_undercut < unit_buyout_price then
|
if buyout_price_undercut < unit_buyout_price and stack_buyout_price_undercut < unit_buyout_price then
|
||||||
buyout_color = inline_color.red
|
buyout_color = color.red
|
||||||
elseif buyout_price_undercut < unit_buyout_price then
|
elseif buyout_price_undercut < unit_buyout_price then
|
||||||
buyout_color = inline_color.orange
|
buyout_color = color.orange
|
||||||
elseif stack_buyout_price_undercut < unit_buyout_price then
|
elseif stack_buyout_price_undercut < unit_buyout_price then
|
||||||
buyout_color = inline_color.yellow
|
buyout_color = color.yellow
|
||||||
end
|
end
|
||||||
|
|
||||||
tinsert(auction_rows, O(
|
tinsert(auction_rows, O(
|
||||||
@@ -301,8 +301,10 @@ function update_item_configuration()
|
|||||||
|
|
||||||
item.texture:SetTexture(selected_item.texture)
|
item.texture:SetTexture(selected_item.texture)
|
||||||
item.name:SetText('[' .. selected_item.name .. ']')
|
item.name:SetText('[' .. selected_item.name .. ']')
|
||||||
local color = ITEM_QUALITY_COLORS[selected_item.quality]
|
do
|
||||||
item.name:SetTextColor(color.r, color.g, color.b)
|
local color = ITEM_QUALITY_COLORS[selected_item.quality]
|
||||||
|
item.name:SetTextColor(color.r, color.g, color.b)
|
||||||
|
end
|
||||||
if selected_item.aux_quantity > 1 then
|
if selected_item.aux_quantity > 1 then
|
||||||
item.count:SetText(selected_item.aux_quantity)
|
item.count:SetText(selected_item.aux_quantity)
|
||||||
else
|
else
|
||||||
@@ -316,7 +318,7 @@ function update_item_configuration()
|
|||||||
local deposit_factor = neutral_faction() and .25 or .05
|
local deposit_factor = neutral_faction() and .25 or .05
|
||||||
local stack_size, stack_count = stack_size_slider:GetValue(), stack_count_slider:GetValue()
|
local stack_size, stack_count = stack_size_slider:GetValue(), stack_count_slider:GetValue()
|
||||||
local amount = floor(selected_item.unit_vendor_price * deposit_factor * (selected_item.max_charges and 1 or stack_size)) * stack_count * UIDropDownMenu_GetSelectedValue(duration_dropdown) / 120
|
local amount = floor(selected_item.unit_vendor_price * deposit_factor * (selected_item.max_charges and 1 or stack_size)) * stack_count * UIDropDownMenu_GetSelectedValue(duration_dropdown) / 120
|
||||||
deposit:SetText('Deposit: ' .. money.to_string(amount, nil, nil, nil, inline_color.text.enabled))
|
deposit:SetText('Deposit: ' .. money.to_string(amount, nil, nil, nil, color.text.enabled))
|
||||||
end
|
end
|
||||||
|
|
||||||
refresh_button:Enable()
|
refresh_button:Enable()
|
||||||
|
|||||||
@@ -1,58 +1,13 @@
|
|||||||
module 'aux'
|
module 'aux'
|
||||||
|
|
||||||
do
|
do
|
||||||
local classes, constructors, interfaces, objects = {}, {}, {}, setmetatable({}, {__mode='k'})
|
local mt = {__metatable=false, __newindex=nop, __mode='k'}
|
||||||
local private_mt = {__metatable=false}
|
|
||||||
function private_mt:__newindex(k, v)
|
|
||||||
classes[self][k] = v
|
|
||||||
end
|
|
||||||
local public_mt = {__metatable=false}
|
|
||||||
function public_mt:__newindex(k, v)
|
|
||||||
classes[self][k] = v
|
|
||||||
interfaces[self][k] = function(self, ...)
|
|
||||||
return classes[self][k](objects[self], unpack(arg))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local proxy_mt = {__metatable=false, __newindex=nop}
|
|
||||||
function proxy_mt:__call()
|
|
||||||
local object = setmetatable({}, {__metatable=false, __newindex=nop, __index=interfaces[self]})
|
|
||||||
classes[object] = classes[self]
|
|
||||||
objects[object] = setmetatable({}, {__index=classes[self]})
|
|
||||||
constructors[self](objects[object])
|
|
||||||
return object
|
|
||||||
end
|
|
||||||
function M.class()
|
|
||||||
local class, interface = {}, {}
|
|
||||||
local private, public, proxy = setmetatable({}, private_mt), setmetatable({}, public_mt), setmetatable({}, proxy_mt)
|
|
||||||
classes[private], classes[public], classes[proxy] = class, class, class
|
|
||||||
interfaces[public], interfaces[proxy] = interface, interface
|
|
||||||
return private, public, function(constructor)
|
|
||||||
constructors[proxy] = constructor or nop
|
|
||||||
return proxy
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
do
|
|
||||||
local _state = setmetatable({}, {__mode='kv'})
|
|
||||||
local __index = function(self, k)
|
|
||||||
return _state[self].handler({public=self, private=_state[self].state}, k)
|
|
||||||
end
|
|
||||||
function M.index_function(state, handler) -- TODO rename table-accessor, use predicate to stop
|
|
||||||
local state, self = {handler=handler, state=state}, T
|
|
||||||
_state[self] = state
|
|
||||||
return setmetatable(self, {__metatable=false, __index=__index, state=state})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
do
|
|
||||||
local mt = {__metatable=false, __newindex=nop}
|
|
||||||
function mt:__sub(table)
|
function mt:__sub(table)
|
||||||
local proxy = setmetatable(T, O('__metatable', false, '__newindex', nop, '__index', table))
|
local proxy = setmetatable(T, O('__metatable', false, '__newindex', nop, '__index', table))
|
||||||
self[proxy] = table
|
self[proxy] = table
|
||||||
return proxy
|
return proxy
|
||||||
end
|
end
|
||||||
function M.wrapper() -- TODO replace index function
|
function M.get_wrapper()
|
||||||
return setmetatable(T, mt)
|
return setmetatable(T, mt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+1
-1
@@ -473,7 +473,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, inline_color.label.enabled))
|
prettified.append(money.to_string(money.from_string(parameter), nil, true, nil, color.label.enabled))
|
||||||
else
|
else
|
||||||
prettified.append(color.label.enabled(parameter))
|
prettified.append(color.label.enabled(parameter))
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user