post refactoring and listing changes

This commit is contained in:
Manuel Simon Hirsig
2016-11-28 21:17:11 +01:00
parent 1e5a1ef106
commit ea7150289d
4 changed files with 81 additions and 175 deletions
-1
View File
@@ -65,7 +65,6 @@ function M.TAB(name)
function env.set_CLOSE(f) tab.CLOSE = f end
function env.set_USE_ITEM(f) tab.USE_ITEM = f end
function env.set_CLICK_LINK(f) tab.CLICK_LINK = f end
function env.M.get_ACTIVE() return tab == active_tab end
tinsert(tab_info, tab)
end
+12 -48
View File
@@ -13,25 +13,7 @@ local ST_HEAD_HEIGHT = 26.3
local ST_HEAD_SPACE = 2
local DEFAULT_COL_INFO = {{width=1}}
local function OnColumnClick()
local button = arg1
if this.st.sortInfo.enabled and button == 'LeftButton' then
if this.st.sortInfo.col == this.colNum then
this.st.sortInfo.ascending = not this.st.sortInfo.ascending
else
this.st.sortInfo.col = this.colNum
this.st.sortInfo.ascending = true
end
this.st.updateSort = true
this.st:RefreshRows()
end
if this.st.handlers.OnColumnClick then
this.st.handlers.OnColumnClick(this, button)
end
end
local defaultColScripts = {
local handlers = {
OnEnter = function()
this.row.mouseover = true
if not this.row.data then return end
@@ -58,7 +40,7 @@ local defaultColScripts = {
end
end,
OnClick = function()
OnMouseDown = function()
if not this.row.data then return end
this.st:ClearSelection()
this.st.selected = key(this.st.rowData, this.row.data)
@@ -69,14 +51,6 @@ local defaultColScripts = {
handler(this.st, this.row.data, this, arg1)
end
end,
OnDoubleClick = function()
if not this.row.data then return end
local handler = this.st.handlers.OnDoubleClick
if handler then
handler(this.st, this.row.data, this, arg1)
end
end,
}
local methods = {
@@ -125,9 +99,9 @@ local methods = {
if st.colInfo[j] then
local colData = data.cols[j]
if type(colData.value) == 'function' then
col:SetText(colData.value(unpack(colData.args)))
col.text:SetText(colData.value(unpack(colData.args)))
else
col:SetText(colData.value)
col.text:SetText(colData.value)
end
end
end
@@ -242,7 +216,7 @@ local methods = {
col:Show()
col:SetWidth(st.colInfo[i].width * width)
col:SetHeight(st.sizes.headHeight)
col:SetText(st.colInfo[i].name or "")
col.text:SetText(st.colInfo[i].name or "")
col.text:SetJustifyH(st.colInfo[i].headAlign or 'CENTER')
else
col:Hide()
@@ -282,7 +256,7 @@ local methods = {
AddColumn = function(st)
local colNum = getn(st.headCols) + 1
local col = CreateFrame('Button', st:GetName() .. 'HeadCol' .. colNum, st.contentFrame)
local col = CreateFrame('Frame', st:GetName() .. 'HeadCol' .. colNum, st.contentFrame)
if colNum == 1 then
col:SetPoint('TOPLEFT', 0, -1)
else
@@ -290,23 +264,14 @@ local methods = {
end
col.st = st
col.colNum = colNum
col:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
col:SetScript('OnClick', OnColumnClick)
local text = col:CreateFontString()
text:SetAllPoints()
text:SetJustifyV('CENTER')
text:SetFont(gui.font, 16)
text:SetTextColor(color.text.enabled())
text:SetAllPoints()
col.text = text
col:SetFontString(text)
local tex = col:CreateTexture()
tex:SetAllPoints()
tex:SetTexture([[Interface\Buttons\UI-Listbox-Highlight]])
tex:SetTexCoord(.025, .957, .087, .931)
tex:SetAlpha(.2)
col:SetHighlightTexture(tex)
tinsert(st.headCols, col)
@@ -321,17 +286,16 @@ local methods = {
AddRowCol = function(st, rowNum)
local row = st.rows[rowNum]
local colNum = getn(row.cols) + 1
local col = CreateFrame('Button', nil, row)
local col = CreateFrame('Frame', nil, row)
local text = col:CreateFontString()
col.text = text
text:SetFont(gui.font, ST_ROW_TEXT_SIZE)
text:SetJustifyV('CENTER')
text:SetPoint('TOPLEFT', 1, -1)
text:SetPoint('BOTTOMRIGHT', -1, 1)
col.text = text
col:SetFontString(text)
col:SetHeight(ST_ROW_HEIGHT)
col:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
for name, func in defaultColScripts do
col:EnableMouse(true)
for name, func in handlers do
col:SetScript(name, func)
end
col.st = st
@@ -363,7 +327,7 @@ local methods = {
row.highlight = highlight
row.st = st
row.cols = {}
row.cols = T
st.rows[rowNum] = row
for i = 1, getn(st.colInfo) do
st:AddRowCol(rowNum)
+63 -108
View File
@@ -107,104 +107,61 @@ function update_inventory_listing()
item_listing.populate(inventory_listing, records)
end
function price_color(record, reference)
local unit_undercut = undercut(record, stack_size_slider:GetValue())
unit_undercut = money.from_string(money.to_string(unit_undercut, true, nil, 3))
local stack_undercut = undercut(record, stack_size_slider:GetValue(), true)
stack_undercut = money.from_string(money.to_string(stack_undercut, true, nil, 3))
if unit_undercut < reference and stack_undercut < reference then
return color.red
elseif unit_undercut < reference then
return color.orange
elseif stack_undercut < reference then
return color.yellow
end
end
function update_auction_listing(listing, records, reference)
local rows = T
if selected_item then
local historical_value = history.value(selected_item.key)
for i = 1, getn(records[selected_item.key] or empty) do
local record = records[selected_item.key][i]
tinsert(rows, O(
'cols', A(
O('value', record.own and color.yellow(record.count) or record.count),
O('value', al.time_left(record.duration)),
O('value', record.stack_size == stack_size and color.yellow(record.stack_size) or record.stack_size),
O('value', money.to_string(record.unit_price, true, nil, 3, price_color(record, reference, stack_size_slider:GetValue()))),
O('value', historical_value and al.percentage_historical(round(record.unit_price / historical_value * 100)) or '---')
),
'record', record
))
end
sort(rows, function(a, b)
return sort_util.multi_lt(
a.record.unit_price,
b.record.unit_price,
a.record.stack_size,
b.record.stack_size,
b.record.own and 1 or 0,
a.record.own and 1 or 0,
a.record.duration,
b.record.duration
)
end)
end
listing:SetData(rows)
end
function update_auction_listings()
if not ACTIVE then return end
local bid_rows, buyout_rows = T, T
if selected_item then
local unit_start_price = get_unit_start_price()
local unit_buyout_price = get_unit_buyout_price()
local stack_size = stack_size_slider:GetValue()
local historical_value = history.value(selected_item.key)
for i = 1, getn(bid_records[selected_item.key] or empty) do
local record = bid_records[selected_item.key][i]
local blizzard_bid_undercut = undercut(record, stack_size)
blizzard_bid_undercut = money.from_string(money.to_string(blizzard_bid_undercut, true, nil, 3))
local stack_blizzard_bid_undercut = undercut(record, stack_size, true)
stack_blizzard_bid_undercut = money.from_string(money.to_string(stack_blizzard_bid_undercut, true, nil, 3))
local bid_color
if blizzard_bid_undercut < unit_start_price and stack_blizzard_bid_undercut < unit_start_price then
bid_color = color.red
elseif blizzard_bid_undercut < unit_start_price then
bid_color = color.orange
elseif stack_blizzard_bid_undercut < unit_start_price then
bid_color = color.yellow
end
tinsert(bid_rows, O(
'cols', A(
O('value', record.own and color.yellow(record.count) or record.count),
O('value', al.time_left(record.duration)),
O('value', record.stack_size == stack_size and color.yellow(record.stack_size) or record.stack_size),
O('value', money.to_string(record.unit_price, true, nil, 3, bid_color)),
O('value', historical_value and al.percentage_historical(round(record.unit_price / historical_value * 100)) or '---')
),
'record', record
))
end
sort(bid_rows, function(a, b)
return sort_util.multi_lt(
a.record.unit_price,
b.record.unit_price,
a.record.stack_size,
b.record.stack_size,
b.record.own and 1 or 0,
a.record.own and 1 or 0,
a.record.duration,
b.record.duration
)
end)
for i = 1, getn(buyout_records[selected_item.key] or empty) do
local record = buyout_records[selected_item.key][i]
local buyout_price_undercut = undercut(record, stack_size)
buyout_price_undercut = money.from_string(money.to_string(buyout_price_undercut, true, nil, 3))
local stack_buyout_price_undercut = undercut(record, stack_size, true)
stack_buyout_price_undercut = money.from_string(money.to_string(stack_buyout_price_undercut, true, nil, 3))
local buyout_color
if buyout_price_undercut < unit_buyout_price and stack_buyout_price_undercut < unit_buyout_price then
buyout_color = color.red
elseif buyout_price_undercut < unit_buyout_price then
buyout_color = color.orange
elseif stack_buyout_price_undercut < unit_buyout_price then
buyout_color = color.yellow
end
tinsert(buyout_rows, O(
'cols', A(
O('value', record.own and color.yellow(record.count) or record.count),
O('value', al.time_left(record.duration)),
O('value', record.stack_size == stack_size and color.yellow(record.stack_size) or record.stack_size),
O('value', money.to_string(record.unit_price, true, nil, 3, buyout_color)),
O('value', historical_value and al.percentage_historical(round(record.unit_price / historical_value * 100)))
),
'record', record
))
end
sort(buyout_rows, function(a, b)
return sort_util.multi_lt(
a.record.unit_price,
b.record.unit_price,
a.record.stack_size,
b.record.stack_size,
b.record.own and 1 or 0,
a.record.own and 1 or 0,
a.record.duration,
b.record.duration
)
end)
end
bid_listing:SetData(bid_rows)
buyout_listing:SetData(buyout_rows)
update_auction_listing(bid_listing, bid_records, unit_start_price)
update_auction_listing(buyout_listing, buyout_records, unit_buyout_price)
end
function M.select_item(item_key)
@@ -220,15 +177,13 @@ function price_update()
if selected_item then
local settings = read_settings()
local start_price_input = get_unit_start_price()
settings.start_price = start_price_input
local historical_value = history.value(selected_item.key)
start_price_percentage:SetText(historical_value and al.percentage_historical(round(start_price_input / historical_value * 100)) or '---')
local buyout_price_input = get_unit_buyout_price()
settings.buyout_price = buyout_price_input
local historical_value = history.value(selected_item.key)
buyout_price_percentage:SetText(historical_value and al.percentage_historical(round(buyout_price_input / historical_value * 100)) or '---')
settings.start_price = unit_start_price
start_price_percentage:SetText(historical_value and al.percentage_historical(round(unit_start_price / historical_value * 100)) or '---')
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
@@ -236,8 +191,8 @@ end
function post_auctions()
if selected_item then
local unit_start_price = get_unit_start_price()
local unit_buyout_price = get_unit_buyout_price()
local unit_start_price = unit_start_price
local unit_buyout_price = unit_buyout_price
local stack_size = stack_size_slider:GetValue()
local stack_count
stack_count = stack_count_slider:GetValue()
@@ -283,11 +238,11 @@ function validate_parameters()
post_button:Disable()
return
end
if get_unit_buyout_price() > 0 and get_unit_start_price() > get_unit_buyout_price() then
if unit_buyout_price > 0 and unit_start_price > unit_buyout_price then
post_button:Disable()
return
end
if get_unit_start_price() == 0 then
if unit_start_price == 0 then
post_button:Disable()
return
end
+6 -18
View File
@@ -78,13 +78,7 @@ bid_listing:SetColInfo{
bid_listing:EnableSorting(false)
bid_listing:DisableSelection(true)
bid_listing:SetHandler('OnClick', function(table, row_data, column, button)
local column_index = key(column, column.row.cols)
local unit_start_price = undercut(row_data.record, stack_size_slider:GetValue(), button == 'RightButton')
if column_index == 3 then
stack_size_slider:SetValue(row_data.record.stack_size)
elseif column_index == 4 then
set_unit_start_price(unit_start_price)
end
unit_start_price = undercut(row_data.record, stack_size_slider:GetValue(), button == 'RightButton')
end)
buyout_listing = listing.CreateScrollingTable(frame.buyout_listing)
@@ -98,13 +92,7 @@ buyout_listing:SetColInfo{
buyout_listing:EnableSorting(false)
buyout_listing:DisableSelection(true)
buyout_listing:SetHandler('OnClick', function(table, row_data, column, button)
local column_index = key(column, column.row.cols)
local unit_buyout_price = undercut(row_data.record, stack_size_slider:GetValue(), button == 'RightButton')
if column_index == 3 then
stack_size_slider:SetValue(row_data.record.stack_size)
elseif column_index == 4 then
set_unit_buyout_price(unit_buyout_price)
end
unit_buyout_price = undercut(row_data.record, stack_size_slider:GetValue(), button == 'RightButton')
end)
do
@@ -242,11 +230,11 @@ do
unit_buyout_price_input:SetFocus()
end
end)
editbox.formatter = function() return money.to_string(get_unit_start_price(), true, nil, 3) end
editbox.formatter = function() return money.to_string(unit_start_price, true, nil, 3) end
editbox.change = function() refresh = true end
editbox.enter = function() this:ClearFocus() end
editbox.focus_loss = function()
this:SetText(money.to_string(get_unit_start_price(), true, nil, 3, nil, true))
this:SetText(money.to_string(unit_start_price, true, nil, 3, nil, true))
end
do
local label = gui.label(editbox, gui.font_size.small)
@@ -305,8 +293,8 @@ do
btn:GetFontString():SetPoint('RIGHT', -2, 0)
btn:SetScript('OnClick', function()
if this.amount then
set_unit_start_price(this.amount)
set_unit_buyout_price(this.amount)
unit_start_price = this.amount
unit_buyout_price = this.amount
end
end)
local label = gui.label(btn, gui.font_size.small)