Market now highlights offers which differ from the average price
This commit is contained in:
parent
eb3c244023
commit
da2762dac3
|
@ -194,7 +194,7 @@ function UITable:removeHeader()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function UITable:addRow(data, ref, height)
|
function UITable:addRow(data, height)
|
||||||
if not self.dataSpace then
|
if not self.dataSpace then
|
||||||
g_logger.error('UITable:addRow - table data space has not been set, cannot add rows.')
|
g_logger.error('UITable:addRow - table data space has not been set, cannot add rows.')
|
||||||
return
|
return
|
||||||
|
@ -206,7 +206,6 @@ function UITable:addRow(data, ref, height)
|
||||||
|
|
||||||
local row = g_ui.createWidget(self.rowBaseStyle)
|
local row = g_ui.createWidget(self.rowBaseStyle)
|
||||||
row.table = self
|
row.table = self
|
||||||
if ref then row.ref = ref end
|
|
||||||
if height then row:setHeight(height) end
|
if height then row:setHeight(height) end
|
||||||
|
|
||||||
local rowId = #self.rows + 1
|
local rowId = #self.rows + 1
|
||||||
|
@ -352,18 +351,24 @@ function UITable:setTableData(tableData)
|
||||||
self.dataSpace:applyStyle({ height = self:getHeight()-headerHeight-self:getMarginTop() })
|
self.dataSpace:applyStyle({ height = self:getHeight()-headerHeight-self:getMarginTop() })
|
||||||
end
|
end
|
||||||
|
|
||||||
function UITable:setRowStyle(style)
|
function UITable:setRowStyle(style, dontUpdate)
|
||||||
self.rowBaseStyle = style
|
self.rowBaseStyle = style
|
||||||
for _, row in pairs(self.rows) do
|
|
||||||
row:setStyle(style)
|
if not dontUpdate then
|
||||||
|
for _, row in pairs(self.rows) do
|
||||||
|
row:setStyle(style)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function UITable:setColumnStyle(style)
|
function UITable:setColumnStyle(style, dontUpdate)
|
||||||
self.columBaseStyle = style
|
self.columBaseStyle = style
|
||||||
for _, columns in pairs(self.columns) do
|
|
||||||
for _, col in pairs(columns) do
|
if not dontUpdate then
|
||||||
col:setStyle(style)
|
for _, columns in pairs(self.columns) do
|
||||||
|
for _, col in pairs(columns) do
|
||||||
|
col:setStyle(style)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
* Extend information features
|
* Extend information features
|
||||||
- Hover over offers for purchase information (balance after transaction, etc)
|
- Hover over offers for purchase information (balance after transaction, etc)
|
||||||
- Display out of trend market offers based on their previous statistics (like cipsoft does)
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
Market = {}
|
Market = {}
|
||||||
|
@ -72,6 +71,7 @@ information = {}
|
||||||
currentItems = {}
|
currentItems = {}
|
||||||
lastCreatedOffer = 0
|
lastCreatedOffer = 0
|
||||||
fee = 0
|
fee = 0
|
||||||
|
averagePrice = 0
|
||||||
|
|
||||||
loaded = false
|
loaded = false
|
||||||
|
|
||||||
|
@ -180,7 +180,18 @@ local function addOffer(offer, offerType)
|
||||||
{text = price},
|
{text = price},
|
||||||
{text = string.gsub(os.date('%c', timestamp), " ", " ")}
|
{text = string.gsub(os.date('%c', timestamp), " ", " ")}
|
||||||
}
|
}
|
||||||
buyOfferTable:addRow(data, id)
|
|
||||||
|
if offer.warn then
|
||||||
|
buyOfferTable:setColumnStyle('OfferTableWarningColumn', true)
|
||||||
|
end
|
||||||
|
|
||||||
|
local row = buyOfferTable:addRow(data)
|
||||||
|
row.ref = id
|
||||||
|
|
||||||
|
if offer.warn then
|
||||||
|
row:setTooltip(tr('This offer is 25%% below the average market price'))
|
||||||
|
buyOfferTable:setColumnStyle('OfferTableColumn', true)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
local data = {
|
local data = {
|
||||||
{text = player},
|
{text = player},
|
||||||
|
@ -189,7 +200,18 @@ local function addOffer(offer, offerType)
|
||||||
{text = price},
|
{text = price},
|
||||||
{text = string.gsub(os.date('%c', timestamp), " ", " "), sortvalue = timestamp}
|
{text = string.gsub(os.date('%c', timestamp), " ", " "), sortvalue = timestamp}
|
||||||
}
|
}
|
||||||
sellOfferTable:addRow(data, id)
|
|
||||||
|
if offer.warn then
|
||||||
|
sellOfferTable:setColumnStyle('OfferTableWarningColumn', true)
|
||||||
|
end
|
||||||
|
|
||||||
|
local row = sellOfferTable:addRow(data)
|
||||||
|
row.ref = id
|
||||||
|
|
||||||
|
if offer.warn then
|
||||||
|
row:setTooltip(tr('This offer is 25%% above the average market price'))
|
||||||
|
sellOfferTable:setColumnStyle('OfferTableColumn', true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
buyOfferTable:toggleSorting(false)
|
buyOfferTable:toggleSorting(false)
|
||||||
|
@ -204,12 +226,17 @@ local function mergeOffer(offer)
|
||||||
if not offer then
|
if not offer then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local id = offer:getId()
|
local id = offer:getId()
|
||||||
local offerType = offer:getType()
|
local offerType = offer:getType()
|
||||||
local amount = offer:getAmount()
|
local amount = offer:getAmount()
|
||||||
local replaced = false
|
local replaced = false
|
||||||
|
|
||||||
if offerType == MarketAction.Buy then
|
if offerType == MarketAction.Buy then
|
||||||
|
if averagePrice > 0 then
|
||||||
|
offer.warn = offer:getPrice() <= averagePrice - math.floor(averagePrice / 4)
|
||||||
|
end
|
||||||
|
|
||||||
for i = 1, #marketOffers[MarketAction.Buy] do
|
for i = 1, #marketOffers[MarketAction.Buy] do
|
||||||
local o = marketOffers[MarketAction.Buy][i]
|
local o = marketOffers[MarketAction.Buy][i]
|
||||||
-- replace existing offer
|
-- replace existing offer
|
||||||
|
@ -222,6 +249,10 @@ local function mergeOffer(offer)
|
||||||
table.insert(marketOffers[MarketAction.Buy], offer)
|
table.insert(marketOffers[MarketAction.Buy], offer)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
if averagePrice > 0 then
|
||||||
|
offer.warn = offer:getPrice() >= averagePrice + math.floor(averagePrice / 4)
|
||||||
|
end
|
||||||
|
|
||||||
for i = 1, #marketOffers[MarketAction.Sell] do
|
for i = 1, #marketOffers[MarketAction.Sell] do
|
||||||
local o = marketOffers[MarketAction.Sell][i]
|
local o = marketOffers[MarketAction.Sell][i]
|
||||||
-- replace existing offer
|
-- replace existing offer
|
||||||
|
@ -285,9 +316,11 @@ local function updateDetails(itemId, descriptions, purchaseStats, saleStats)
|
||||||
if table.empty(saleStats) then
|
if table.empty(saleStats) then
|
||||||
sellStatsTable:addRow({{text = 'No information'}})
|
sellStatsTable:addRow({{text = 'No information'}})
|
||||||
else
|
else
|
||||||
|
local offerAmount = 0
|
||||||
local transactions, totalPrice, highestPrice, lowestPrice = 0, 0, 0, 0
|
local transactions, totalPrice, highestPrice, lowestPrice = 0, 0, 0, 0
|
||||||
for _, stat in pairs(saleStats) do
|
for _, stat in pairs(saleStats) do
|
||||||
if not stat:isNull() then
|
if not stat:isNull() then
|
||||||
|
offerAmount = offerAmount + 1
|
||||||
transactions = transactions + stat:getTransactions()
|
transactions = transactions + stat:getTransactions()
|
||||||
totalPrice = totalPrice + stat:getTotalPrice()
|
totalPrice = totalPrice + stat:getTotalPrice()
|
||||||
local newHigh = stat:getHighestPrice()
|
local newHigh = stat:getHighestPrice()
|
||||||
|
@ -302,6 +335,12 @@ local function updateDetails(itemId, descriptions, purchaseStats, saleStats)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if offerAmount >= 5 and transactions >= 10 then
|
||||||
|
averagePrice = math.round(totalPrice / transactions)
|
||||||
|
else
|
||||||
|
averagePrice = 0
|
||||||
|
end
|
||||||
|
|
||||||
sellStatsTable:addRow({{text = 'Total Transations:'}, {text = transactions}})
|
sellStatsTable:addRow({{text = 'Total Transations:'}, {text = transactions}})
|
||||||
sellStatsTable:addRow({{text = 'Highest Price:'}, {text = highestPrice}})
|
sellStatsTable:addRow({{text = 'Highest Price:'}, {text = highestPrice}})
|
||||||
|
|
||||||
|
@ -1081,6 +1120,7 @@ function Market.onMarketEnter(depotItems, offers, balance, vocation)
|
||||||
end
|
end
|
||||||
|
|
||||||
updateBalance(balance)
|
updateBalance(balance)
|
||||||
|
averagePrice = 0
|
||||||
|
|
||||||
information.totalOffers = offers
|
information.totalOffers = offers
|
||||||
local player = g_game.getLocalPlayer()
|
local player = g_game.getLocalPlayer()
|
||||||
|
|
|
@ -10,6 +10,9 @@ OfferTableColumn < TableColumn
|
||||||
color: #cccccc
|
color: #cccccc
|
||||||
width: 80
|
width: 80
|
||||||
|
|
||||||
|
OfferTableWarningColumn < OfferTableColumn
|
||||||
|
color: #e03d3d
|
||||||
|
|
||||||
OfferTableHeaderRow < TableHeaderRow
|
OfferTableHeaderRow < TableHeaderRow
|
||||||
font: verdana-11px-monochrome
|
font: verdana-11px-monochrome
|
||||||
color: #cccccc
|
color: #cccccc
|
||||||
|
|
Loading…
Reference in New Issue