refactoring

This commit is contained in:
Manuel Simon Hirsig
2017-03-10 21:31:59 +01:00
parent 91aef2560d
commit fa40875faa
2 changed files with 51 additions and 49 deletions
+51 -47
View File
@@ -16,14 +16,6 @@ local price_per_unit = false
local HEAD_HEIGHT = 27
local HEAD_SPACE = 2
local AUCTION_PCT_COLORS = {
{color=color.blue, value=50},
{color=color.green, value=80},
{color=color.yellow, value=110},
{color=color.orange, value=135},
{color=color.red, value=huge},
}
local TIME_LEFT_STRINGS = {
color.red'30m', -- Short
color.orange'2h', -- Medium
@@ -529,16 +521,21 @@ function record_percentage(record)
end
end
function percentage_color(pct)
for i = 1, getn(AUCTION_PCT_COLORS) do
if pct < AUCTION_PCT_COLORS[i].value then
return AUCTION_PCT_COLORS[i].color
end
end
end
function M.percentage_historical(pct, bid)
return (bid and color.gray or percentage_color(pct)) .. (pct > 10000 and '>10000' or pct) .. '%' .. FONT_COLOR_CODE_CLOSE
local text = (pct > 10000 and '>10000' or pct) .. '%'
if bid then
return color.gray(text)
elseif pct < 50 then
return color.blue(text)
elseif pct < 80 then
return color.green(text)
elseif pct < 110 then
return color.yellow(text)
elseif pct < 135 then
return color.orange(text)
else
return color.red(text)
end
end
function M.time_left(code)
@@ -548,13 +545,16 @@ end
local methods = {
ResizeColumns = function(self)
local width = self.contentFrame:GetRight() - self.contentFrame:GetLeft()
local weight = 0
for _, cell in self.headCells do
cell:SetWidth(cell.info.width * width)
weight = weight + cell.info.width
end
for _, row in self.rows do
for i, cell in row.cells do
cell:SetWidth(self.headCells[i].info.width * width)
weight = (self.contentFrame:GetRight() - self.contentFrame:GetLeft()) / weight
for i, cell in self.headCells do
local width = cell.info.width * weight
cell:SetWidth(width)
for _, row in self.rows do
row.cells[i]:SetWidth(width)
end
end
end,
@@ -583,12 +583,12 @@ local methods = {
OnIconEnter = function()
local rt = this:GetParent().row.rt
local rowData = this:GetParent().row.data
if rowData and rowData.record then
local row = this:GetParent().row
if row.record then
GameTooltip:SetOwner(this, 'ANCHOR_RIGHT')
info.load_tooltip(GameTooltip, rowData.record.tooltip)
tooltip.extend_tooltip(GameTooltip, rowData.record.link, rowData.record.aux_quantity)
info.set_shopping_tooltip(rowData.record.slot)
info.load_tooltip(GameTooltip, row.record.tooltip)
tooltip.extend_tooltip(GameTooltip, row.record.link, row.record.aux_quantity)
info.set_shopping_tooltip(row.record.slot)
end
end,
@@ -598,11 +598,11 @@ local methods = {
OnEnter = function()
local rt = this.rt
if rt.expanded[this.data.expandKey] then
if rt.expanded[this.expandKey] then
GameTooltip_SetDefaultAnchor(GameTooltip, UIParent)
GameTooltip:AddLine('Double-click to collapse this item and show only the cheapest auction.', 1, 1, 1, true)
GameTooltip:Show()
elseif this.data.expandable then
elseif this.expandable then
GameTooltip_SetDefaultAnchor(GameTooltip, UIParent)
GameTooltip:AddLine('Double-click to expand this item and show all the auctions.', 1, 1, 1, true)
GameTooltip:Show()
@@ -613,7 +613,7 @@ local methods = {
OnLeave = function()
GameTooltip:Hide()
if not this.rt.selected or this.rt.selected.search_signature ~= this.data.record.search_signature then
if not this.rt.selected or this.rt.selected.search_signature ~= this.record.search_signature then
this.highlight:Hide()
end
end,
@@ -621,17 +621,17 @@ local methods = {
OnClick = function()
local button = arg1
if IsControlKeyDown() then
DressUpItemLink(this.data.record.link)
DressUpItemLink(this.record.link)
elseif IsShiftKeyDown() and ChatFrameEditBox:IsVisible() then
ChatFrameEditBox:Insert(this.data.record.link)
ChatFrameEditBox:Insert(this.record.link)
elseif not modified and button == 'RightButton' then -- TODO not when alt (how?)
tab = 1
search_tab.filter = strlower(info.item(this.data.record.item_id).name) .. '/exact'
search_tab.filter = strlower(info.item(this.record.item_id).name) .. '/exact'
search_tab.execute(nil, false)
else
local selection = this.rt:GetSelection()
if not selection or selection.record ~= this.data.record then
this.rt:SetSelectedRecord(this.data.record)
if not selection or selection.record ~= this.record then
this.rt:SetSelectedRecord(this.record)
elseif this.rt.handlers.OnClick then
this.rt.handlers.OnClick(this, button)
end
@@ -640,14 +640,13 @@ local methods = {
OnDoubleClick = function()
local rt = this.rt
local rowData = this.data
local expand = not rt.expanded[rowData.expandKey]
local expand = not rt.expanded[this.expandKey]
rt.expanded[rowData.expandKey] = expand
rt.expanded[this.expandKey] = expand
rt:UpdateRowInfo()
rt:UpdateRows()
if not rowData.indented then
rt:SetSelectedRecord(this.data.record)
if not this.indented then
rt:SetSelectedRecord(this.record)
end
end,
@@ -792,7 +791,12 @@ local methods = {
else
row.highlight:Hide()
end
row.data = {record=record, expandable=expandable, indented=indented, numAuctions=numAuctions, expandKey=expandKey}
row.record = record
row.expandable = expandable
row.indented = indented
row.numAuctions = numAuctions
row.expandKey = expandKey
for i, column in self.columns do
column.fill(row.cells[i], record, displayNumAuctions, numPlayerAuctions, expandable, indented)
@@ -805,7 +809,7 @@ local methods = {
self.selected = selectedData and self.selected or nil
for _, row in self.rows do
if self.selected and row.data and row.data.record.search_signature == self.selected.search_signature then
if self.selected and row.record and row.record.search_signature == self.selected.search_signature then
row.highlight:Show()
else
row.highlight:Hide()
@@ -832,7 +836,7 @@ local methods = {
local prevSelectedIndex
if self.selected then
for i, row in self.rows do
if row:IsVisible() and row.data and row.data.record == self.selected then
if row:IsVisible() and row.record == self.selected then
prevSelectedIndex = i
end
end
@@ -844,14 +848,14 @@ local methods = {
if not self.selected and prevSelectedIndex then
-- try to select the same row
local row = self.rows[prevSelectedIndex]
if row and row:IsVisible() and row.data and row.data.record then
self:SetSelectedRecord(row.data.record)
if row and row:IsVisible() and row.record then
self:SetSelectedRecord(row.record)
end
if not self.selected then
-- select the first row
row = self.rows[1]
if row and row:IsVisible() and row.data and row.data.record then
self:SetSelectedRecord(row.data.record)
if row and row:IsVisible() and row.record then
self:SetSelectedRecord(row.record)
end
end
end
-2
View File
@@ -236,7 +236,6 @@ do
end
do
local editbox = gui.editbox(frame.parameters)
editbox.name = 'start'
editbox:SetPoint('TOPRIGHT', -71, -60)
editbox:SetWidth(180)
editbox:SetHeight(22)
@@ -272,7 +271,6 @@ do
end
do
local editbox = gui.editbox(frame.parameters)
editbox.name = 'buy'
editbox:SetPoint('TOPRIGHT', unit_start_price_input, 'BOTTOMRIGHT', 0, -19)
editbox:SetWidth(180)
editbox:SetHeight(22)