another massive refactoring, only post panel missing

This commit is contained in:
Manuel Simon Hirsig
2016-01-26 17:45:39 +01:00
parent 6474b1716f
commit 0d448e12c7
13 changed files with 433 additions and 480 deletions
+99 -116
View File
@@ -3,15 +3,27 @@ Aux.item_search_frame = public
aux_recently_searched = {}
local hide_sheet
local auctions
local search_query
local refresh
local selected_auction
function private.select_auction(entry)
selected_auction = entry
refresh = true
private.buyout_button:Disable()
private.bid_button:Disable()
end
function private.clear_selection(entry)
selected_auction = nil
refresh = true
private.buyout_button:Disable()
private.bid_button:Disable()
end
function public.on_close()
private.clear_selection()
private.buyout_button:Disable()
private.bid_button:Disable()
end
function public.on_open()
@@ -79,14 +91,14 @@ function public.on_load()
private.views = {
[Aux.view.BUYOUT] = {
frame = AuxItemSearchFrameAuctionsBuyListing,
on_row_click = function (sheet, row_index)
on_row_click = function(sheet, row_index)
local data_index = row_index + FauxScrollFrame_GetOffset(sheet.scroll_frame)
private.on_row_click(sheet, sheet.data[data_index], true)
private.on_row_click(sheet.data[data_index], true)
end,
on_row_enter = function (sheet, row_index)
on_row_enter = function(sheet, row_index)
Aux.info.set_tooltip(sheet.rows[row_index].itemstring, sheet.rows[row_index].EnhTooltip_info, this, 'ANCHOR_RIGHT', 0, 0)
end,
on_row_leave = function (sheet, row_index)
on_row_leave = function(sheet, row_index)
AuxTooltip:Hide()
ResetCursor()
end,
@@ -99,6 +111,9 @@ function public.on_load()
ResetCursor()
end
end,
selected = function(datum)
return Aux.util.any(datum, function(entry) return entry == selected_auction end)
end,
row_setter = function(row, group)
row:SetAlpha(Aux.util.all(group, function(auction) return auction.gone end) and 0.3 or 1)
row.itemstring = Aux.info.itemstring(group[1].item_id, group[1].suffix_id, nil, group[1].enchant_id)
@@ -115,7 +130,7 @@ function public.on_load()
end,
},
Aux.listing_util.money_column('Buy', function(group) return group[1].buyout_price end),
Aux.listing_util.money_column('Buy/ea', function(group) return group[1].buyout_price_per_unit end),
Aux.listing_util.money_column('Buy/ea', function(group) return group[1].unit_buyout_price end),
{
title = 'Avail',
width = 40,
@@ -125,20 +140,20 @@ function public.on_load()
cell.text:SetText(getn(Aux.util.filter(group, function(auction) return not auction.gone end)))
end,
},
Aux.listing_util.percentage_market_column(function(group) return group[1].item_key end, function(group) return group[1].buyout_price_per_unit end),
Aux.listing_util.percentage_market_column(function(group) return group[1].item_key end, function(group) return group[1].unit_buyout_price end),
},
sort_order = {{column = 3, order = 'ascending' }},
},
[Aux.view.BID] = {
frame = AuxItemSearchFrameAuctionsBidListing,
on_row_click = function (sheet, row_index)
on_row_click = function(sheet, row_index)
local data_index = row_index + FauxScrollFrame_GetOffset(sheet.scroll_frame)
private.on_row_click(sheet, sheet.data[data_index])
private.on_row_click(sheet.data[data_index])
end,
on_row_enter = function (sheet, row_index)
on_row_enter = function(sheet, row_index)
Aux.info.set_tooltip(sheet.rows[row_index].itemstring, sheet.rows[row_index].EnhTooltip_info, this, 'ANCHOR_RIGHT', 0, 0)
end,
on_row_leave = function (sheet, row_index)
on_row_leave = function(sheet, row_index)
AuxTooltip:Hide()
ResetCursor()
end,
@@ -151,6 +166,9 @@ function public.on_load()
ResetCursor()
end
end,
selected = function(datum)
return datum == selected_auction
end,
row_setter = function(row, datum)
row:SetAlpha(datum.gone and 0.3 or 1)
row.itemstring = Aux.info.itemstring(datum.item_id, datum.suffix_id, datum.unique_id, datum.enchant_id)
@@ -166,8 +184,8 @@ function public.on_load()
cell.text:SetText(datum.aux_quantity)
end,
},
Aux.listing_util.money_column('Bid', function(entry) return entry.bid end),
Aux.listing_util.money_column('Bid/ea', function(entry) return entry.bid_per_unit end),
Aux.listing_util.money_column('Bid', function(entry) return entry.bid_price end),
Aux.listing_util.money_column('Bid/ea', function(entry) return entry.unit_bid_price end),
{
title = 'Status',
width = 70,
@@ -212,12 +230,12 @@ function public.on_load()
frame = AuxItemSearchFrameAuctionsFullListing,
on_row_click = function (sheet, row_index)
local data_index = row_index + FauxScrollFrame_GetOffset(sheet.scroll_frame)
private.on_row_click(sheet, sheet.data[data_index])
private.on_row_click(sheet.data[data_index])
end,
on_row_enter = function (sheet, row_index)
on_row_enter = function(sheet, row_index)
Aux.info.set_tooltip(sheet.rows[row_index].itemstring, sheet.rows[row_index].EnhTooltip_info, this, 'ANCHOR_RIGHT', 0, 0)
end,
on_row_leave = function (sheet, row_index)
on_row_leave = function(sheet, row_index)
AuxTooltip:Hide()
ResetCursor()
end,
@@ -230,6 +248,9 @@ function public.on_load()
ResetCursor()
end
end,
selected = function(datum)
return datum == selected_auction
end,
row_setter = function(row, datum)
row:SetAlpha(datum.gone and 0.3 or 1)
row.itemstring = Aux.info.itemstring(datum.item_id, datum.suffix_id, datum.unique_id, datum.enchant_id)
@@ -245,10 +266,10 @@ function public.on_load()
cell.text:SetText(datum.aux_quantity)
end,
},
Aux.listing_util.money_column('Bid', function(entry) return entry.bid end),
Aux.listing_util.money_column('Bid', function(entry) return entry.bid_price end),
Aux.listing_util.money_column('Buy', function(entry) return entry.buyout_price end),
Aux.listing_util.money_column('Bid/ea', function(entry) return entry.bid_per_unit end),
Aux.listing_util.money_column('Buy/ea', function(entry) return entry.buyout_price_per_unit end),
Aux.listing_util.money_column('Bid/ea', function(entry) return entry.unit_bid_price end),
Aux.listing_util.money_column('Buy/ea', function(entry) return entry.unit_buyout_price end),
{
title = 'Lvl',
width = 25,
@@ -303,7 +324,7 @@ function public.on_load()
cell.text:SetText(datum.page)
end,
},
Aux.listing_util.percentage_market_column(function(entry) return entry.item_key end, function(entry) return entry.buyout_price_per_unit end),
Aux.listing_util.percentage_market_column(function(entry) return entry.item_key end, function(entry) return entry.unit_buyout_price end),
},
sort_order = {{column = 5, order = 'ascending'}},
},
@@ -462,18 +483,10 @@ function private.update_listing()
end
end
function hide_sheet()
AuxItemSearchFrameAuctionsBuyListing:Hide()
AuxItemSearchFrameAuctionsBidListing:Hide()
AuxItemSearchFrameAuctionsFullListing:Hide()
end
function public.set_view(view)
private.buyout_button:Disable()
private.bid_button:Disable()
private.clear_selection()
aux_view = view
private.update_listing()
refresh = true
end
function private.update_recently_searched()
@@ -523,6 +536,8 @@ function public.start_search()
Aux.scan.abort(function()
private.clear_selection()
private.status_bar:update_status(0,0)
private.status_bar:set_text('Scanning auctions...')
@@ -595,83 +610,60 @@ function public.start_search()
end)
end
function private.clear_selection()
private.listings[aux_view]:clear_selection()
end
function private.process_request(entry, express_mode, buyout_mode)
function private.find_auction(entry, express_mode, buyout_mode)
if buyout_mode and not entry.buyout_price then
return
end
local amount
if buyout_mode then
amount = entry.buyout_price
else
amount = entry.bid
if entry.gone or (buyout_mode and not entry.buyout_price) or (express_mode and not buyout_mode and entry.high_bidder) or entry.owner == UnitName('player') then
return
end
PlaySound('igMainMenuOptionCheckBoxOn')
local function test(index)
return private.create_auction_record(Aux.info.auction(index)).signature == entry.signature
local auction_record = private.create_auction_record(Aux.info.auction(index))
return auction_record.signature == entry.signature and auction_record.bid_price == entry.bid_price and auction_record.owner ~= UnitName('player')
end
Aux.scan_util.find_auction('list', test, search_query, entry.page, private.status_bar, function(index)
local function remove_entry()
entry.gone = true
refresh = true
private.clear_selection()
end
if not index then
entry.gone = true
private.clear_selection()
refresh = true
return
end
if express_mode then
Aux.scan_util.find('list', test, search_query, entry.page, private.status_bar, remove_entry, function(index)
if not entry.gone then
Aux.place_bid('list', index, buyout_mode and entry.buyout_price or entry.bid_price, remove_entry)
end
end)
else
private.select_auction(entry)
if not test(index) then
return private.find_auction(entry, express_mode, buyout_mode) -- try again
end
Aux.scan_util.find('list', test, search_query, entry.page, private.status_bar, remove_entry, function(index)
if express_mode then
if Aux.bid_lock then
return
if not entry.high_bidder then
private.bid_button:SetScript('OnClick', function()
if test(index) and not entry.gone then
Aux.place_bid('list', index, entry.bid_price, remove_entry)
end
private.clear_selection()
end)
private.bid_button:Enable()
end
if GetMoney() >= amount then
entry.gone = true
if entry.buyout_price then
private.buyout_button:SetScript('OnClick', function()
if test(index) and not entry.gone then
Aux.place_bid('list', index, entry.buyout_price, remove_entry)
end
private.clear_selection()
end)
private.buyout_button:Enable()
end
Aux.place_bid('list', index, amount)
private.clear_selection()
refresh = true
else
private.buyout_button:SetScript('OnClick', function()
if Aux.bid_lock then
return
end
if not test(index) then
private.buyout_button:Disable()
private.bid_button:Disable()
return private.find_auction(entry, express_mode, buyout_mode) -- try again
end
if GetMoney() >= amount then
entry.gone = true
end
Aux.place_bid('list', index, entry.buyout_price)
private.buyout_button:Disable()
private.bid_button:Disable()
private.clear_selection()
refresh = true
end)
private.buyout_button:Enable()
private.bid_button:Enable()
end
end)
end)
end
end
function private.on_row_click(sheet, datum, grouped)
function private.on_row_click(datum, grouped)
local entry
if grouped then
@@ -680,32 +672,23 @@ function private.on_row_click(sheet, datum, grouped)
entry = datum
end
local express_mode = IsAltKeyDown()
local buyout_mode = express_mode and arg1 == 'LeftButton'
if IsControlKeyDown() then
DressUpItemLink(entry.hyperlink)
if IsControlKeyDown() then
DressUpItemLink(entry.hyperlink)
elseif IsShiftKeyDown() then
if ChatFrameEditBox:IsVisible() then
ChatFrameEditBox:Insert(entry.hyperlink)
end
elseif not entry.gone and entry.owner ~= UnitName('player') then
if not express_mode then
private.buyout_button:Disable()
private.bid_button:Disable()
sheet:clear_selection()
sheet:select(datum)
end
private.find_auction(entry, express_mode, buyout_mode)
else
local express_mode = IsAltKeyDown()
local buyout_mode = express_mode and arg1 == 'LeftButton'
private.process_request(entry, express_mode, buyout_mode)
end
end
function private.create_auction_record(auction_info, current_page)
function private.create_auction_record(auction_info, page)
local aux_quantity = auction_info.charges or auction_info.count
local bid = (auction_info.current_bid > 0 and auction_info.current_bid or auction_info.min_bid) + auction_info.min_increment
local buyout_price = auction_info.buyout_price > 0 and auction_info.buyout_price or nil
local buyout_price_per_unit = buyout_price and Aux.round(auction_info.buyout_price / aux_quantity)
local unit_buyout_price = buyout_price and Aux.round(auction_info.buyout_price / auction_info.aux_quantity)
local status
if auction_info.current_bid == 0 then
status = 'No Bid'
@@ -716,25 +699,25 @@ function private.create_auction_record(auction_info, current_page)
end
return {
page = page,
item_id = auction_info.item_id,
suffix_id = auction_info.suffix_id,
unique_id = auction_info.unique_id,
enchant_id = auction_info.enchant_id,
item_key = auction_info.item_key,
signature = Aux.auction_signature(auction_info.hyperlink, aux_quantity, bid, auction_info.buyout_price),
signature = auction_info.signature,
name = auction_info.name,
level = auction_info.level,
aux_quantity = aux_quantity,
aux_quantity = auction_info.aux_quantity,
buyout_price = buyout_price,
buyout_price_per_unit = buyout_price_per_unit,
unit_buyout_price = unit_buyout_price,
quality = auction_info.quality,
hyperlink = auction_info.hyperlink,
page = current_page,
bid = bid,
bid_per_unit = Aux.round(bid / aux_quantity),
bid_price = auction_info.bid_price,
unit_bid_price = Aux.round(auction_info.bid_price / auction_info.aux_quantity),
owner = auction_info.owner,
duration = auction_info.duration,
usable = auction_info.usable,