2012-08-05 16:42:54 +02:00
|
|
|
--[[
|
|
|
|
Finalizing Market:
|
2014-01-18 15:09:26 +01:00
|
|
|
Note: Feel free to work on any area and submit
|
2012-08-05 16:42:54 +02:00
|
|
|
it as a pull request from your git fork.
|
|
|
|
|
|
|
|
BeniS's Skype: benjiz69
|
|
|
|
|
|
|
|
List:
|
|
|
|
* Add offer management:
|
|
|
|
- Current Offers
|
|
|
|
- Offer History
|
|
|
|
|
2012-08-14 17:43:48 +02:00
|
|
|
* Clean up the interface building
|
2014-01-18 15:09:26 +01:00
|
|
|
- Add a new market interface file to handle building?
|
2012-08-14 17:43:48 +02:00
|
|
|
|
|
|
|
* Extend information features
|
|
|
|
- Hover over offers for purchase information (balance after transaction, etc)
|
2012-08-05 16:42:54 +02:00
|
|
|
]]
|
|
|
|
|
2012-07-17 16:36:27 +02:00
|
|
|
Market = {}
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
local protocol = runinsandbox('marketprotocol')
|
2012-07-27 05:53:42 +02:00
|
|
|
|
|
|
|
marketWindow = nil
|
|
|
|
mainTabBar = nil
|
|
|
|
displaysTabBar = nil
|
|
|
|
offersTabBar = nil
|
|
|
|
selectionTabBar = nil
|
|
|
|
|
|
|
|
marketOffersPanel = nil
|
|
|
|
browsePanel = nil
|
2012-08-05 16:42:54 +02:00
|
|
|
overviewPanel = nil
|
2012-07-27 05:53:42 +02:00
|
|
|
itemOffersPanel = nil
|
|
|
|
itemDetailsPanel = nil
|
|
|
|
itemStatsPanel = nil
|
|
|
|
myOffersPanel = nil
|
|
|
|
currentOffersPanel = nil
|
|
|
|
offerHistoryPanel = nil
|
|
|
|
itemsPanel = nil
|
|
|
|
selectedOffer = {}
|
|
|
|
|
|
|
|
nameLabel = nil
|
|
|
|
feeLabel = nil
|
2012-07-29 16:05:32 +02:00
|
|
|
balanceLabel = nil
|
2012-07-27 05:53:42 +02:00
|
|
|
totalPriceEdit = nil
|
|
|
|
piecePriceEdit = nil
|
|
|
|
amountEdit = nil
|
2012-08-05 16:42:54 +02:00
|
|
|
searchEdit = nil
|
2012-07-27 05:53:42 +02:00
|
|
|
radioItemSet = nil
|
|
|
|
selectedItem = nil
|
|
|
|
offerTypeList = nil
|
|
|
|
categoryList = nil
|
|
|
|
subCategoryList = nil
|
|
|
|
slotFilterList = nil
|
|
|
|
createOfferButton = nil
|
2012-07-29 16:05:32 +02:00
|
|
|
buyButton = nil
|
|
|
|
sellButton = nil
|
2012-07-27 05:53:42 +02:00
|
|
|
anonymous = nil
|
|
|
|
filterButtons = {}
|
|
|
|
|
|
|
|
buyOfferTable = nil
|
|
|
|
sellOfferTable = nil
|
|
|
|
detailsTable = nil
|
|
|
|
buyStatsTable = nil
|
|
|
|
sellStatsTable = nil
|
|
|
|
|
2012-08-14 17:43:48 +02:00
|
|
|
offerExhaust = {}
|
2012-07-27 05:53:42 +02:00
|
|
|
marketOffers = {}
|
|
|
|
marketItems = {}
|
|
|
|
information = {}
|
|
|
|
currentItems = {}
|
2012-08-14 17:43:48 +02:00
|
|
|
lastCreatedOffer = 0
|
2012-07-27 05:53:42 +02:00
|
|
|
fee = 0
|
2015-01-25 13:41:00 +01:00
|
|
|
averagePrice = 0
|
2012-07-20 20:20:06 +02:00
|
|
|
|
2013-02-20 02:44:06 +01:00
|
|
|
loaded = false
|
|
|
|
|
2012-08-15 06:58:56 +02:00
|
|
|
local function isItemValid(item, category, searchFilter)
|
|
|
|
if not item or not item.marketData then
|
|
|
|
return false
|
2012-08-05 16:42:54 +02:00
|
|
|
end
|
2012-08-15 06:58:56 +02:00
|
|
|
|
|
|
|
if not category then
|
2012-08-05 16:42:54 +02:00
|
|
|
category = MarketCategory.All
|
|
|
|
end
|
|
|
|
if item.marketData.category ~= category and category ~= MarketCategory.All then
|
2012-07-23 17:11:53 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
-- filter item
|
|
|
|
local slotFilter = false
|
|
|
|
if slotFilterList:isEnabled() then
|
|
|
|
slotFilter = getMarketSlotFilterId(slotFilterList:getCurrentOption().text)
|
|
|
|
end
|
|
|
|
local marketData = item.marketData
|
|
|
|
|
|
|
|
local filterVocation = filterButtons[MarketFilters.Vocation]:isChecked()
|
|
|
|
local filterLevel = filterButtons[MarketFilters.Level]:isChecked()
|
|
|
|
local filterDepot = filterButtons[MarketFilters.Depot]:isChecked()
|
|
|
|
|
|
|
|
if slotFilter then
|
2015-01-23 02:52:05 +01:00
|
|
|
if slotFilter ~= 255 and item.thingType:getClothSlot() ~= slotFilter then
|
2012-07-23 17:11:53 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local player = g_game.getLocalPlayer()
|
|
|
|
if filterLevel and marketData.requiredLevel and player:getLevel() < marketData.requiredLevel then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
if filterVocation and marketData.restrictVocation > 0 then
|
|
|
|
local voc = Bit.bit(information.vocation)
|
|
|
|
if not Bit.hasBit(marketData.restrictVocation, voc) then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2015-01-23 02:52:05 +01:00
|
|
|
if filterDepot and Market.getDepotCount(item.marketData.tradeAs) <= 0 then
|
2012-07-23 17:11:53 +02:00
|
|
|
return false
|
|
|
|
end
|
2012-08-15 06:58:56 +02:00
|
|
|
if searchFilter then
|
2013-02-20 02:44:06 +01:00
|
|
|
return marketData.name:lower():find(searchFilter)
|
2012-08-05 16:42:54 +02:00
|
|
|
end
|
2012-07-23 17:11:53 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
local function clearItems()
|
|
|
|
currentItems = {}
|
|
|
|
Market.refreshItemsWidget()
|
|
|
|
end
|
2012-07-22 16:02:01 +02:00
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
local function clearOffers()
|
|
|
|
marketOffers[MarketAction.Buy] = {}
|
|
|
|
marketOffers[MarketAction.Sell] = {}
|
|
|
|
buyOfferTable:clearData()
|
|
|
|
sellOfferTable:clearData()
|
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
local function clearFilters()
|
|
|
|
for _, filter in pairs(filterButtons) do
|
2015-01-20 14:34:45 +01:00
|
|
|
if filter and filter:isChecked() ~= filter.default then
|
|
|
|
filter:setChecked(filter.default)
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-07-22 16:02:01 +02:00
|
|
|
|
2012-08-25 18:05:33 +02:00
|
|
|
local function clearFee()
|
|
|
|
feeLabel:setText('')
|
2015-01-25 02:28:53 +01:00
|
|
|
fee = 20
|
2012-08-25 18:05:33 +02:00
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
local function refreshTypeList()
|
|
|
|
offerTypeList:clearOptions()
|
|
|
|
offerTypeList:addOption('Buy')
|
|
|
|
|
|
|
|
if Market.isItemSelected() then
|
2015-01-23 02:52:05 +01:00
|
|
|
if Market.getDepotCount(selectedItem.item.marketData.tradeAs) > 0 then
|
2012-07-27 05:53:42 +02:00
|
|
|
offerTypeList:addOption('Sell')
|
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-21 23:40:15 +01:00
|
|
|
local function addOffer(offer, offerType)
|
2012-07-29 16:05:32 +02:00
|
|
|
if not offer then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
local id = offer:getId()
|
|
|
|
local player = offer:getPlayer()
|
|
|
|
local amount = offer:getAmount()
|
|
|
|
local price = offer:getPrice()
|
|
|
|
local timestamp = offer:getTimeStamp()
|
|
|
|
|
2015-01-21 23:40:15 +01:00
|
|
|
buyOfferTable:toggleSorting(false)
|
|
|
|
sellOfferTable:toggleSorting(false)
|
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
if amount < 1 then return false end
|
2015-01-21 23:40:15 +01:00
|
|
|
if offerType == MarketAction.Buy then
|
2012-07-29 16:05:32 +02:00
|
|
|
local data = {
|
2015-01-21 23:40:15 +01:00
|
|
|
{text = player},
|
|
|
|
{text = amount},
|
|
|
|
{text = price*amount},
|
|
|
|
{text = price},
|
|
|
|
{text = string.gsub(os.date('%c', timestamp), " ", " ")}
|
2012-07-29 16:05:32 +02:00
|
|
|
}
|
2015-01-25 13:41:00 +01:00
|
|
|
|
|
|
|
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
|
2012-07-29 16:05:32 +02:00
|
|
|
else
|
|
|
|
local data = {
|
2015-01-21 23:40:15 +01:00
|
|
|
{text = player},
|
|
|
|
{text = amount},
|
|
|
|
{text = price*amount},
|
|
|
|
{text = price},
|
|
|
|
{text = string.gsub(os.date('%c', timestamp), " ", " "), sortvalue = timestamp}
|
2012-07-29 16:05:32 +02:00
|
|
|
}
|
2015-01-25 13:41:00 +01:00
|
|
|
|
|
|
|
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
|
2012-07-29 16:05:32 +02:00
|
|
|
end
|
2015-01-21 23:40:15 +01:00
|
|
|
|
|
|
|
buyOfferTable:toggleSorting(false)
|
|
|
|
sellOfferTable:toggleSorting(false)
|
|
|
|
buyOfferTable:sort()
|
|
|
|
sellOfferTable:sort()
|
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
return true
|
|
|
|
end
|
2012-07-28 15:41:10 +02:00
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
local function mergeOffer(offer)
|
|
|
|
if not offer then
|
|
|
|
return false
|
|
|
|
end
|
2015-01-25 13:41:00 +01:00
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
local id = offer:getId()
|
2015-01-21 23:40:15 +01:00
|
|
|
local offerType = offer:getType()
|
2012-07-29 16:05:32 +02:00
|
|
|
local amount = offer:getAmount()
|
|
|
|
local replaced = false
|
|
|
|
|
2015-01-21 23:40:15 +01:00
|
|
|
if offerType == MarketAction.Buy then
|
2015-01-25 13:41:00 +01:00
|
|
|
if averagePrice > 0 then
|
|
|
|
offer.warn = offer:getPrice() <= averagePrice - math.floor(averagePrice / 4)
|
|
|
|
end
|
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
for i = 1, #marketOffers[MarketAction.Buy] do
|
|
|
|
local o = marketOffers[MarketAction.Buy][i]
|
|
|
|
-- replace existing offer
|
|
|
|
if o:isEqual(id) then
|
|
|
|
marketOffers[MarketAction.Buy][i] = offer
|
|
|
|
replaced = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not replaced then
|
|
|
|
table.insert(marketOffers[MarketAction.Buy], offer)
|
|
|
|
end
|
|
|
|
else
|
2015-01-25 13:41:00 +01:00
|
|
|
if averagePrice > 0 then
|
|
|
|
offer.warn = offer:getPrice() >= averagePrice + math.floor(averagePrice / 4)
|
|
|
|
end
|
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
for i = 1, #marketOffers[MarketAction.Sell] do
|
|
|
|
local o = marketOffers[MarketAction.Sell][i]
|
|
|
|
-- replace existing offer
|
|
|
|
if o:isEqual(id) then
|
|
|
|
marketOffers[MarketAction.Sell][i] = offer
|
|
|
|
replaced = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not replaced then
|
|
|
|
table.insert(marketOffers[MarketAction.Sell], offer)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local function updateOffers(offers)
|
2012-07-27 05:53:42 +02:00
|
|
|
if not buyOfferTable or not sellOfferTable then
|
|
|
|
return
|
|
|
|
end
|
2012-08-15 06:58:56 +02:00
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
balanceLabel:setColor('#bbbbbb')
|
2012-08-15 06:58:56 +02:00
|
|
|
selectedOffer[MarketAction.Buy] = nil
|
|
|
|
selectedOffer[MarketAction.Sell] = nil
|
|
|
|
|
|
|
|
-- clear existing offer data
|
2012-07-27 05:53:42 +02:00
|
|
|
buyOfferTable:clearData()
|
2015-01-21 23:40:15 +01:00
|
|
|
buyOfferTable:setSorting(4, TABLE_SORTING_DESC)
|
2012-07-27 05:53:42 +02:00
|
|
|
sellOfferTable:clearData()
|
2015-01-21 23:40:15 +01:00
|
|
|
sellOfferTable:setSorting(4, TABLE_SORTING_ASC)
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
sellButton:setEnabled(false)
|
|
|
|
buyButton:setEnabled(false)
|
2012-07-27 05:53:42 +02:00
|
|
|
|
2012-08-15 06:58:56 +02:00
|
|
|
for _, offer in pairs(offers) do
|
2012-07-29 16:05:32 +02:00
|
|
|
mergeOffer(offer)
|
|
|
|
end
|
|
|
|
for type, offers in pairs(marketOffers) do
|
|
|
|
for i = 1, #offers do
|
|
|
|
addOffer(offers[i], type)
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function updateDetails(itemId, descriptions, purchaseStats, saleStats)
|
|
|
|
if not selectedItem then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- update item details
|
|
|
|
detailsTable:clearData()
|
|
|
|
for k, desc in pairs(descriptions) do
|
|
|
|
local columns = {
|
2015-01-21 23:40:15 +01:00
|
|
|
{text = getMarketDescriptionName(desc[1])..':'},
|
|
|
|
{text = desc[2]}
|
2012-07-27 05:53:42 +02:00
|
|
|
}
|
|
|
|
detailsTable:addRow(columns)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- update sale item statistics
|
|
|
|
sellStatsTable:clearData()
|
|
|
|
if table.empty(saleStats) then
|
2015-01-21 23:40:15 +01:00
|
|
|
sellStatsTable:addRow({{text = 'No information'}})
|
2012-07-27 05:53:42 +02:00
|
|
|
else
|
2015-01-25 13:41:00 +01:00
|
|
|
local offerAmount = 0
|
2012-07-28 15:41:10 +02:00
|
|
|
local transactions, totalPrice, highestPrice, lowestPrice = 0, 0, 0, 0
|
|
|
|
for _, stat in pairs(saleStats) do
|
|
|
|
if not stat:isNull() then
|
2015-01-25 13:41:00 +01:00
|
|
|
offerAmount = offerAmount + 1
|
2012-07-28 15:41:10 +02:00
|
|
|
transactions = transactions + stat:getTransactions()
|
|
|
|
totalPrice = totalPrice + stat:getTotalPrice()
|
|
|
|
local newHigh = stat:getHighestPrice()
|
|
|
|
if newHigh > highestPrice then
|
|
|
|
highestPrice = newHigh
|
|
|
|
end
|
|
|
|
local newLow = stat:getLowestPrice()
|
2012-07-29 16:05:32 +02:00
|
|
|
-- ?? getting '0xffffffff' result from lowest price in 9.60 cipsoft
|
|
|
|
if (lowestPrice == 0 or newLow < lowestPrice) and newLow ~= 0xffffffff then
|
2012-07-28 15:41:10 +02:00
|
|
|
lowestPrice = newLow
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-07-27 05:53:42 +02:00
|
|
|
|
2015-01-25 13:41:00 +01:00
|
|
|
if offerAmount >= 5 and transactions >= 10 then
|
|
|
|
averagePrice = math.round(totalPrice / transactions)
|
|
|
|
else
|
|
|
|
averagePrice = 0
|
|
|
|
end
|
|
|
|
|
2015-01-21 23:40:15 +01:00
|
|
|
sellStatsTable:addRow({{text = 'Total Transations:'}, {text = transactions}})
|
|
|
|
sellStatsTable:addRow({{text = 'Highest Price:'}, {text = highestPrice}})
|
2012-07-27 05:53:42 +02:00
|
|
|
|
2012-07-28 15:41:10 +02:00
|
|
|
if totalPrice > 0 and transactions > 0 then
|
2015-01-21 23:40:15 +01:00
|
|
|
sellStatsTable:addRow({{text = 'Average Price:'},
|
|
|
|
{text = math.floor(totalPrice/transactions)}})
|
2012-07-28 15:41:10 +02:00
|
|
|
else
|
2015-01-21 23:40:15 +01:00
|
|
|
sellStatsTable:addRow({{text = 'Average Price:'}, {text = 0}})
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
2012-07-28 15:41:10 +02:00
|
|
|
|
2015-01-21 23:40:15 +01:00
|
|
|
sellStatsTable:addRow({{text = 'Lowest Price:'}, {text = lowestPrice}})
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- update buy item statistics
|
|
|
|
buyStatsTable:clearData()
|
|
|
|
if table.empty(purchaseStats) then
|
2015-01-21 23:40:15 +01:00
|
|
|
buyStatsTable:addRow({{text = 'No information'}})
|
2012-07-27 05:53:42 +02:00
|
|
|
else
|
2012-07-28 15:41:10 +02:00
|
|
|
local transactions, totalPrice, highestPrice, lowestPrice = 0, 0, 0, 0
|
|
|
|
for _, stat in pairs(purchaseStats) do
|
|
|
|
if not stat:isNull() then
|
|
|
|
transactions = transactions + stat:getTransactions()
|
|
|
|
totalPrice = totalPrice + stat:getTotalPrice()
|
|
|
|
local newHigh = stat:getHighestPrice()
|
|
|
|
if newHigh > highestPrice then
|
|
|
|
highestPrice = newHigh
|
|
|
|
end
|
|
|
|
local newLow = stat:getLowestPrice()
|
2012-07-29 16:05:32 +02:00
|
|
|
-- ?? getting '0xffffffff' result from lowest price in 9.60 cipsoft
|
|
|
|
if (lowestPrice == 0 or newLow < lowestPrice) and newLow ~= 0xffffffff then
|
2012-07-28 15:41:10 +02:00
|
|
|
lowestPrice = newLow
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-07-27 05:53:42 +02:00
|
|
|
|
2015-01-21 23:40:15 +01:00
|
|
|
buyStatsTable:addRow({{text = 'Total Transations:'},{text = transactions}})
|
|
|
|
buyStatsTable:addRow({{text = 'Highest Price:'}, {text = highestPrice}})
|
2012-07-27 05:53:42 +02:00
|
|
|
|
2012-07-28 15:41:10 +02:00
|
|
|
if totalPrice > 0 and transactions > 0 then
|
2015-01-21 23:40:15 +01:00
|
|
|
buyStatsTable:addRow({{text = 'Average Price:'},
|
|
|
|
{text = math.floor(totalPrice/transactions)}})
|
2012-07-28 15:41:10 +02:00
|
|
|
else
|
2015-01-21 23:40:15 +01:00
|
|
|
buyStatsTable:addRow({{text = 'Average Price:'}, {text = 0}})
|
2012-07-20 20:20:06 +02:00
|
|
|
end
|
2012-07-28 15:41:10 +02:00
|
|
|
|
2015-01-21 23:40:15 +01:00
|
|
|
buyStatsTable:addRow({{text = 'Lowest Price:'}, {text = lowestPrice}})
|
2012-07-20 20:20:06 +02:00
|
|
|
end
|
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-08-02 16:50:40 +02:00
|
|
|
local function updateSelectedItem(widget)
|
|
|
|
selectedItem.item = widget.item
|
|
|
|
selectedItem.ref = widget
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
Market.resetCreateOffer()
|
|
|
|
if Market.isItemSelected() then
|
2015-01-23 02:52:05 +01:00
|
|
|
selectedItem:setItem(selectedItem.item.displayItem)
|
2012-07-27 05:53:42 +02:00
|
|
|
nameLabel:setText(selectedItem.item.marketData.name)
|
2012-07-29 16:05:32 +02:00
|
|
|
clearOffers()
|
2012-07-28 05:54:47 +02:00
|
|
|
|
2012-08-14 18:18:58 +02:00
|
|
|
Market.enableCreateOffer(true) -- update offer types
|
2015-01-23 02:52:05 +01:00
|
|
|
MarketProtocol.sendMarketBrowse(selectedItem.item.marketData.tradeAs) -- send browsed msg
|
2012-07-27 05:53:42 +02:00
|
|
|
else
|
2012-08-02 16:50:40 +02:00
|
|
|
Market.clearSelectedItem()
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
local function updateBalance(balance)
|
|
|
|
local balance = tonumber(balance)
|
|
|
|
if not balance then
|
|
|
|
return
|
2012-07-19 20:54:24 +02:00
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
if balance < 0 then balance = 0 end
|
|
|
|
information.balance = balance
|
2012-07-20 20:20:06 +02:00
|
|
|
|
2012-08-07 01:13:33 +02:00
|
|
|
balanceLabel:setText('Balance: '..balance..' gold')
|
2012-07-27 05:53:42 +02:00
|
|
|
balanceLabel:resizeToText()
|
|
|
|
end
|
2012-07-20 20:20:06 +02:00
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
local function updateFee(price, amount)
|
|
|
|
fee = math.ceil(price / 100 * amount)
|
|
|
|
if fee < 20 then
|
|
|
|
fee = 20
|
|
|
|
elseif fee > 1000 then
|
|
|
|
fee = 1000
|
2012-07-20 20:20:06 +02:00
|
|
|
end
|
2012-07-27 05:53:42 +02:00
|
|
|
feeLabel:setText('Fee: '..fee)
|
|
|
|
feeLabel:resizeToText()
|
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2015-01-20 14:34:45 +01:00
|
|
|
local function destroyAmountWindow()
|
|
|
|
if amountWindow then
|
|
|
|
amountWindow:destroy()
|
|
|
|
amountWindow = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-25 02:28:53 +01:00
|
|
|
local function openAmountWindow(callback, actionType, actionText)
|
|
|
|
if not Market.isOfferSelected(actionType) then
|
2012-07-29 16:05:32 +02:00
|
|
|
return
|
|
|
|
end
|
2015-01-25 02:28:53 +01:00
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
amountWindow = g_ui.createWidget('AmountWindow', rootWidget)
|
|
|
|
amountWindow:lock()
|
2013-02-12 17:14:16 +01:00
|
|
|
|
2015-01-25 02:28:53 +01:00
|
|
|
local offer = selectedOffer[actionType]
|
|
|
|
local item = offer:getItem()
|
|
|
|
|
|
|
|
local maximum = offer:getAmount()
|
|
|
|
if actionType == MarketAction.Sell then
|
2015-01-23 02:52:05 +01:00
|
|
|
local depot = Market.getDepotCount(item:getId())
|
2015-01-25 02:28:53 +01:00
|
|
|
if maximum > depot then
|
|
|
|
maximum = depot
|
2012-08-02 16:50:40 +02:00
|
|
|
end
|
2015-01-25 02:28:53 +01:00
|
|
|
else
|
|
|
|
maximum = math.min(maximum, math.floor(information.balance / offer:getPrice()))
|
|
|
|
end
|
|
|
|
|
|
|
|
if item:isStackable() then
|
|
|
|
maximum = math.min(maximum, MarketMaxAmountStackable)
|
|
|
|
else
|
|
|
|
maximum = math.min(maximum, MarketMaxAmount)
|
2012-08-02 16:50:40 +02:00
|
|
|
end
|
2012-07-29 16:05:32 +02:00
|
|
|
|
2013-02-12 17:14:16 +01:00
|
|
|
local itembox = amountWindow:getChildById('item')
|
|
|
|
itembox:setItemId(item:getId())
|
2012-07-30 10:02:02 +02:00
|
|
|
|
|
|
|
local scrollbar = amountWindow:getChildById('amountScrollBar')
|
2015-01-25 02:28:53 +01:00
|
|
|
scrollbar:setText(offer:getPrice()..'gp')
|
2012-07-30 10:02:02 +02:00
|
|
|
|
2013-02-12 17:14:16 +01:00
|
|
|
scrollbar.onValueChange = function(widget, value)
|
2015-01-25 02:28:53 +01:00
|
|
|
widget:setText((value*offer:getPrice())..'gp')
|
|
|
|
itembox:setText(value)
|
2013-02-12 17:14:16 +01:00
|
|
|
end
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2015-01-25 02:28:53 +01:00
|
|
|
scrollbar:setRange(1, maximum)
|
|
|
|
scrollbar:setValue(1)
|
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
local okButton = amountWindow:getChildById('buttonOk')
|
2015-01-25 02:28:53 +01:00
|
|
|
if actionText then
|
2013-02-12 17:14:16 +01:00
|
|
|
okButton:setText(actionText)
|
|
|
|
end
|
2012-07-29 16:05:32 +02:00
|
|
|
|
|
|
|
local okFunc = function()
|
2015-01-25 02:28:53 +01:00
|
|
|
local counter = offer:getCounter()
|
|
|
|
local timestamp = offer:getTimeStamp()
|
2013-02-12 17:14:16 +01:00
|
|
|
callback(scrollbar:getValue(), timestamp, counter)
|
2015-01-20 14:34:45 +01:00
|
|
|
destroyAmountWindow()
|
2012-07-29 16:05:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local cancelButton = amountWindow:getChildById('buttonCancel')
|
|
|
|
local cancelFunc = function()
|
2015-01-20 14:34:45 +01:00
|
|
|
destroyAmountWindow()
|
2012-07-29 16:05:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
amountWindow.onEnter = okFunc
|
|
|
|
amountWindow.onEscape = cancelFunc
|
|
|
|
|
|
|
|
okButton.onClick = okFunc
|
|
|
|
cancelButton.onClick = cancelFunc
|
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
local function onSelectSellOffer(table, selectedRow, previousSelectedRow)
|
|
|
|
updateBalance()
|
|
|
|
for _, offer in pairs(marketOffers[MarketAction.Sell]) do
|
|
|
|
if offer:isEqual(selectedRow.ref) then
|
2012-07-29 16:05:32 +02:00
|
|
|
selectedOffer[MarketAction.Buy] = offer
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
local offer = selectedOffer[MarketAction.Buy]
|
2012-07-27 05:53:42 +02:00
|
|
|
if offer then
|
2012-07-29 16:05:32 +02:00
|
|
|
local price = offer:getPrice()
|
|
|
|
if price > information.balance then
|
2012-08-19 03:19:43 +02:00
|
|
|
balanceLabel:setColor('#b22222') -- red
|
2012-08-14 17:43:48 +02:00
|
|
|
buyButton:setEnabled(false)
|
2012-07-27 05:53:42 +02:00
|
|
|
else
|
|
|
|
local slice = (information.balance / 2)
|
2012-07-29 16:05:32 +02:00
|
|
|
if (price/slice) * 100 <= 40 then
|
2012-07-27 05:53:42 +02:00
|
|
|
color = '#008b00' -- green
|
2012-07-29 16:05:32 +02:00
|
|
|
elseif (price/slice) * 100 <= 70 then
|
2012-07-27 05:53:42 +02:00
|
|
|
color = '#eec900' -- yellow
|
|
|
|
else
|
|
|
|
color = '#ee9a00' -- orange
|
|
|
|
end
|
|
|
|
balanceLabel:setColor(color)
|
2012-08-14 17:43:48 +02:00
|
|
|
buyButton:setEnabled(true)
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onSelectBuyOffer(table, selectedRow, previousSelectedRow)
|
|
|
|
updateBalance()
|
|
|
|
for _, offer in pairs(marketOffers[MarketAction.Buy]) do
|
|
|
|
if offer:isEqual(selectedRow.ref) then
|
2012-07-29 16:05:32 +02:00
|
|
|
selectedOffer[MarketAction.Sell] = offer
|
2015-01-23 02:52:05 +01:00
|
|
|
if Market.getDepotCount(offer:getItem():getId()) > 0 then
|
2012-07-30 10:02:02 +02:00
|
|
|
sellButton:setEnabled(true)
|
|
|
|
else
|
|
|
|
sellButton:setEnabled(false)
|
|
|
|
end
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
local function onChangeCategory(combobox, option)
|
2012-07-23 17:11:53 +02:00
|
|
|
local id = getMarketCategoryId(option)
|
|
|
|
if id == MarketCategory.MetaWeapons then
|
|
|
|
-- enable and load weapons filter/items
|
|
|
|
subCategoryList:setEnabled(true)
|
|
|
|
slotFilterList:setEnabled(true)
|
|
|
|
local subId = getMarketCategoryId(subCategoryList:getCurrentOption().text)
|
|
|
|
Market.loadMarketItems(subId)
|
|
|
|
else
|
|
|
|
subCategoryList:setEnabled(false)
|
|
|
|
slotFilterList:setEnabled(false)
|
|
|
|
Market.loadMarketItems(id) -- load standard filter
|
|
|
|
end
|
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
local function onChangeSubCategory(combobox, option)
|
2012-07-28 15:41:10 +02:00
|
|
|
Market.loadMarketItems(getMarketCategoryId(option))
|
2012-07-23 17:11:53 +02:00
|
|
|
slotFilterList:clearOptions()
|
2012-07-28 15:41:10 +02:00
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
local subId = getMarketCategoryId(subCategoryList:getCurrentOption().text)
|
|
|
|
local slots = MarketCategoryWeapons[subId].slots
|
|
|
|
for _, slot in pairs(slots) do
|
2013-01-29 07:26:32 +01:00
|
|
|
if table.haskey(MarketSlotFilters, slot) then
|
2012-07-23 17:11:53 +02:00
|
|
|
slotFilterList:addOption(MarketSlotFilters[slot])
|
2012-07-19 20:54:24 +02:00
|
|
|
end
|
|
|
|
end
|
2012-07-23 17:11:53 +02:00
|
|
|
slotFilterList:setEnabled(true)
|
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
local function onChangeSlotFilter(combobox, option)
|
2012-07-23 17:11:53 +02:00
|
|
|
Market.updateCurrentItems()
|
2012-07-19 20:54:24 +02:00
|
|
|
end
|
2012-07-17 16:36:27 +02:00
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
local function onChangeOfferType(combobox, option)
|
2015-01-25 02:28:53 +01:00
|
|
|
local item = selectedItem.item
|
|
|
|
local maximum = item.thingType:isStackable() and MarketMaxAmountStackable or MarketMaxAmount
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
if option == 'Sell' then
|
2015-01-25 02:28:53 +01:00
|
|
|
maximum = math.min(maximum, Market.getDepotCount(item.marketData.tradeAs))
|
|
|
|
amountEdit:setMaximum(maximum)
|
2012-07-27 05:53:42 +02:00
|
|
|
else
|
2015-01-25 02:28:53 +01:00
|
|
|
amountEdit:setMaximum(maximum)
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onTotalPriceChange()
|
|
|
|
local amount = amountEdit:getValue()
|
2015-01-25 02:28:53 +01:00
|
|
|
local totalPrice = totalPriceEdit:getValue()
|
|
|
|
local piecePrice = math.floor(totalPrice/amount)
|
2012-07-27 05:53:42 +02:00
|
|
|
|
2015-01-25 02:28:53 +01:00
|
|
|
piecePriceEdit:setValue(piecePrice, true)
|
2012-07-27 05:53:42 +02:00
|
|
|
if Market.isItemSelected() then
|
2015-01-25 02:28:53 +01:00
|
|
|
updateFee(piecePrice, amount)
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onPiecePriceChange()
|
2015-01-25 02:28:53 +01:00
|
|
|
local amount = amountEdit:getValue()
|
2012-07-27 05:53:42 +02:00
|
|
|
local totalPrice = totalPriceEdit:getValue()
|
|
|
|
local piecePrice = piecePriceEdit:getValue()
|
|
|
|
|
2015-01-25 02:28:53 +01:00
|
|
|
totalPriceEdit:setValue(piecePrice*amount, true)
|
2012-07-27 05:53:42 +02:00
|
|
|
if Market.isItemSelected() then
|
2015-01-25 02:28:53 +01:00
|
|
|
updateFee(piecePrice, amount)
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onAmountChange()
|
|
|
|
local amount = amountEdit:getValue()
|
2015-01-25 02:28:53 +01:00
|
|
|
local piecePrice = piecePriceEdit:getValue()
|
|
|
|
local totalPrice = piecePrice * amount
|
2012-07-27 05:53:42 +02:00
|
|
|
|
2015-01-25 02:28:53 +01:00
|
|
|
totalPriceEdit:setValue(piecePrice*amount, true)
|
2012-07-27 05:53:42 +02:00
|
|
|
if Market.isItemSelected() then
|
2015-01-25 02:28:53 +01:00
|
|
|
updateFee(piecePrice, amount)
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-22 20:38:28 +01:00
|
|
|
local function onMarketMessage(messageMode, message)
|
|
|
|
Market.displayMessage(message)
|
|
|
|
end
|
|
|
|
|
2015-01-23 02:52:05 +01:00
|
|
|
local function initMarketItems()
|
2013-02-20 02:44:06 +01:00
|
|
|
for c = MarketCategory.First, MarketCategory.Last do
|
|
|
|
marketItems[c] = {}
|
|
|
|
end
|
2012-08-15 06:58:56 +02:00
|
|
|
|
2015-01-23 02:52:05 +01:00
|
|
|
-- save a list of items which are already added
|
|
|
|
local itemSet = {}
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
-- populate all market items
|
2012-07-29 14:04:47 +02:00
|
|
|
local types = g_things.findThingTypeByAttr(ThingAttrMarket, 0)
|
2012-07-27 05:53:42 +02:00
|
|
|
for i = 1, #types do
|
2015-01-23 02:52:05 +01:00
|
|
|
local itemType = types[i]
|
|
|
|
|
|
|
|
local item = Item.create(itemType:getId())
|
|
|
|
if item then
|
|
|
|
local marketData = itemType:getMarketData()
|
|
|
|
if not table.empty(marketData) and not itemSet[marketData.tradeAs] then
|
|
|
|
-- Some items use a different sprite in Market
|
|
|
|
item:setId(marketData.showAs)
|
|
|
|
|
|
|
|
-- create new marketItem block
|
|
|
|
local marketItem = {
|
|
|
|
displayItem = item,
|
|
|
|
thingType = itemType,
|
2013-02-20 02:44:06 +01:00
|
|
|
marketData = marketData
|
|
|
|
}
|
|
|
|
|
|
|
|
-- add new market item
|
2015-01-23 02:52:05 +01:00
|
|
|
table.insert(marketItems[marketData.category], marketItem)
|
|
|
|
itemSet[marketData.tradeAs] = true
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
local function initInterface()
|
|
|
|
-- TODO: clean this up
|
2012-07-19 20:54:24 +02:00
|
|
|
-- setup main tabs
|
|
|
|
mainTabBar = marketWindow:getChildById('mainTabBar')
|
|
|
|
mainTabBar:setContentWidget(marketWindow:getChildById('mainTabContent'))
|
|
|
|
|
|
|
|
-- setup 'Market Offer' section tabs
|
2013-01-18 23:39:11 +01:00
|
|
|
marketOffersPanel = g_ui.loadUI('ui/marketoffers')
|
2012-07-19 20:54:24 +02:00
|
|
|
mainTabBar:addTab(tr('Market Offers'), marketOffersPanel)
|
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
selectionTabBar = marketOffersPanel:getChildById('leftTabBar')
|
|
|
|
selectionTabBar:setContentWidget(marketOffersPanel:getChildById('leftTabContent'))
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
browsePanel = g_ui.loadUI('ui/marketoffers/browse')
|
2012-07-22 16:02:01 +02:00
|
|
|
selectionTabBar:addTab(tr('Browse'), browsePanel)
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2015-01-20 14:34:45 +01:00
|
|
|
-- Currently not used
|
|
|
|
-- "Reserved for more functionality later"
|
|
|
|
--overviewPanel = g_ui.loadUI('ui/marketoffers/overview')
|
|
|
|
--selectionTabBar:addTab(tr('Overview'), overviewPanel)
|
2012-07-17 16:36:27 +02:00
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
displaysTabBar = marketOffersPanel:getChildById('rightTabBar')
|
|
|
|
displaysTabBar:setContentWidget(marketOffersPanel:getChildById('rightTabContent'))
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2014-02-06 14:04:22 +01:00
|
|
|
itemStatsPanel = g_ui.loadUI('ui/marketoffers/itemstats')
|
|
|
|
displaysTabBar:addTab(tr('Statistics'), itemStatsPanel)
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
itemDetailsPanel = g_ui.loadUI('ui/marketoffers/itemdetails')
|
2012-07-22 16:02:01 +02:00
|
|
|
displaysTabBar:addTab(tr('Details'), itemDetailsPanel)
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2014-02-06 14:04:22 +01:00
|
|
|
itemOffersPanel = g_ui.loadUI('ui/marketoffers/itemoffers')
|
|
|
|
displaysTabBar:addTab(tr('Offers'), itemOffersPanel)
|
|
|
|
displaysTabBar:selectTab(displaysTabBar:getTab(tr('Offers')))
|
2012-07-19 20:54:24 +02:00
|
|
|
|
|
|
|
-- setup 'My Offer' section tabs
|
2013-01-18 23:39:11 +01:00
|
|
|
myOffersPanel = g_ui.loadUI('ui/myoffers')
|
2012-07-19 20:54:24 +02:00
|
|
|
mainTabBar:addTab(tr('My Offers'), myOffersPanel)
|
2012-07-28 05:54:47 +02:00
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
offersTabBar = myOffersPanel:getChildById('offersTabBar')
|
|
|
|
offersTabBar:setContentWidget(myOffersPanel:getChildById('offersTabContent'))
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
currentOffersPanel = g_ui.loadUI('ui/myoffers/currentoffers')
|
2012-07-22 16:02:01 +02:00
|
|
|
offersTabBar:addTab(tr('Current Offers'), currentOffersPanel)
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
offerHistoryPanel = g_ui.loadUI('ui/myoffers/offerhistory')
|
2012-07-22 16:02:01 +02:00
|
|
|
offersTabBar:addTab(tr('Offer History'), offerHistoryPanel)
|
2012-07-20 20:20:06 +02:00
|
|
|
|
2012-07-30 10:02:02 +02:00
|
|
|
balanceLabel = marketWindow:getChildById('balanceLabel')
|
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
-- setup offers
|
|
|
|
buyButton = itemOffersPanel:getChildById('buyButton')
|
2012-08-14 18:18:58 +02:00
|
|
|
buyButton.onClick = function() openAmountWindow(Market.acceptMarketOffer, MarketAction.Buy, 'Buy') end
|
2012-07-29 16:05:32 +02:00
|
|
|
|
|
|
|
sellButton = itemOffersPanel:getChildById('sellButton')
|
2012-08-14 18:18:58 +02:00
|
|
|
sellButton.onClick = function() openAmountWindow(Market.acceptMarketOffer, MarketAction.Sell, 'Sell') end
|
2012-07-29 16:05:32 +02:00
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
-- setup selected item
|
2012-07-27 05:53:42 +02:00
|
|
|
nameLabel = marketOffersPanel:getChildById('nameLabel')
|
|
|
|
selectedItem = marketOffersPanel:getChildById('selectedItem')
|
2012-07-20 20:20:06 +02:00
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
-- setup create new offer
|
|
|
|
totalPriceEdit = marketOffersPanel:getChildById('totalPriceEdit')
|
|
|
|
piecePriceEdit = marketOffersPanel:getChildById('piecePriceEdit')
|
|
|
|
amountEdit = marketOffersPanel:getChildById('amountEdit')
|
|
|
|
feeLabel = marketOffersPanel:getChildById('feeLabel')
|
|
|
|
totalPriceEdit.onValueChange = onTotalPriceChange
|
|
|
|
piecePriceEdit.onValueChange = onPiecePriceChange
|
|
|
|
amountEdit.onValueChange = onAmountChange
|
|
|
|
|
|
|
|
offerTypeList = marketOffersPanel:getChildById('offerTypeComboBox')
|
|
|
|
offerTypeList.onOptionChange = onChangeOfferType
|
|
|
|
|
|
|
|
anonymous = marketOffersPanel:getChildById('anonymousCheckBox')
|
|
|
|
createOfferButton = marketOffersPanel:getChildById('createOfferButton')
|
|
|
|
createOfferButton.onClick = Market.createNewOffer
|
|
|
|
Market.enableCreateOffer(false)
|
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
-- setup filters
|
|
|
|
filterButtons[MarketFilters.Vocation] = browsePanel:getChildById('filterVocation')
|
|
|
|
filterButtons[MarketFilters.Level] = browsePanel:getChildById('filterLevel')
|
|
|
|
filterButtons[MarketFilters.Depot] = browsePanel:getChildById('filterDepot')
|
2012-08-05 16:42:54 +02:00
|
|
|
filterButtons[MarketFilters.SearchAll] = browsePanel:getChildById('filterSearchAll')
|
2012-07-20 20:20:06 +02:00
|
|
|
|
2015-01-20 14:34:45 +01:00
|
|
|
-- set filter default values
|
|
|
|
clearFilters()
|
|
|
|
|
|
|
|
-- hook filters
|
|
|
|
for _, filter in pairs(filterButtons) do
|
|
|
|
filter.onCheckChange = Market.updateCurrentItems
|
|
|
|
end
|
|
|
|
|
2012-08-05 16:42:54 +02:00
|
|
|
searchEdit = browsePanel:getChildById('searchEdit')
|
2012-07-23 17:11:53 +02:00
|
|
|
categoryList = browsePanel:getChildById('categoryComboBox')
|
|
|
|
subCategoryList = browsePanel:getChildById('subCategoryComboBox')
|
2012-08-05 16:42:54 +02:00
|
|
|
slotFilterList = browsePanel:getChildById('slotComboBox')
|
2012-07-23 17:11:53 +02:00
|
|
|
|
|
|
|
slotFilterList:addOption(MarketSlotFilters[255])
|
|
|
|
slotFilterList:setEnabled(false)
|
|
|
|
|
|
|
|
for i = MarketCategory.First, MarketCategory.Last do
|
|
|
|
if i >= MarketCategory.Ammunition and i <= MarketCategory.WandsRods then
|
|
|
|
subCategoryList:addOption(getMarketCategoryName(i))
|
|
|
|
else
|
|
|
|
categoryList:addOption(getMarketCategoryName(i))
|
|
|
|
end
|
2012-07-20 20:20:06 +02:00
|
|
|
end
|
2012-07-23 17:11:53 +02:00
|
|
|
categoryList:addOption(getMarketCategoryName(255)) -- meta weapons
|
|
|
|
categoryList:setCurrentOption(getMarketCategoryName(MarketCategory.First))
|
|
|
|
subCategoryList:setEnabled(false)
|
2012-07-28 05:54:47 +02:00
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
-- hook item filters
|
2012-07-27 05:53:42 +02:00
|
|
|
categoryList.onOptionChange = onChangeCategory
|
|
|
|
subCategoryList.onOptionChange = onChangeSubCategory
|
|
|
|
slotFilterList.onOptionChange = onChangeSlotFilter
|
2012-07-22 16:02:01 +02:00
|
|
|
|
2012-08-05 16:42:54 +02:00
|
|
|
-- setup tables
|
2012-07-22 16:02:01 +02:00
|
|
|
buyOfferTable = itemOffersPanel:recursiveGetChildById('buyingTable')
|
|
|
|
sellOfferTable = itemOffersPanel:recursiveGetChildById('sellingTable')
|
|
|
|
detailsTable = itemDetailsPanel:recursiveGetChildById('detailsTable')
|
|
|
|
buyStatsTable = itemStatsPanel:recursiveGetChildById('buyStatsTable')
|
|
|
|
sellStatsTable = itemStatsPanel:recursiveGetChildById('sellStatsTable')
|
2012-07-27 05:53:42 +02:00
|
|
|
buyOfferTable.onSelectionChange = onSelectBuyOffer
|
|
|
|
sellOfferTable.onSelectionChange = onSelectSellOffer
|
2015-01-21 23:40:15 +01:00
|
|
|
|
|
|
|
buyStatsTable:setColumnWidth({120, 270})
|
|
|
|
sellStatsTable:setColumnWidth({120, 270})
|
|
|
|
detailsTable:setColumnWidth({80, 330})
|
|
|
|
|
|
|
|
buyOfferTable:setSorting(4, TABLE_SORTING_DESC)
|
|
|
|
sellOfferTable:setSorting(4, TABLE_SORTING_ASC)
|
2012-07-22 16:02:01 +02:00
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
function init()
|
2013-01-18 23:39:11 +01:00
|
|
|
g_ui.importStyle('market')
|
|
|
|
g_ui.importStyle('ui/general/markettabs')
|
|
|
|
g_ui.importStyle('ui/general/marketbuttons')
|
|
|
|
g_ui.importStyle('ui/general/marketcombobox')
|
|
|
|
g_ui.importStyle('ui/general/amountwindow')
|
2012-07-29 14:04:47 +02:00
|
|
|
|
2012-08-14 17:43:48 +02:00
|
|
|
offerExhaust[MarketAction.Sell] = 10
|
2012-08-14 18:18:58 +02:00
|
|
|
offerExhaust[MarketAction.Buy] = 20
|
2012-08-14 17:43:48 +02:00
|
|
|
|
2015-01-22 20:38:28 +01:00
|
|
|
registerMessageMode(MessageModes.Market, onMarketMessage)
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
protocol.initProtocol()
|
|
|
|
connect(g_game, { onGameEnd = Market.reset })
|
2012-08-15 13:56:29 +02:00
|
|
|
connect(g_game, { onGameEnd = Market.close })
|
2012-07-22 16:02:01 +02:00
|
|
|
marketWindow = g_ui.createWidget('MarketWindow', rootWidget)
|
|
|
|
marketWindow:hide()
|
|
|
|
|
|
|
|
initInterface() -- build interface
|
2012-07-17 16:36:27 +02:00
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
function terminate()
|
2015-01-20 14:34:45 +01:00
|
|
|
Market.close()
|
|
|
|
|
2015-01-22 20:38:28 +01:00
|
|
|
unregisterMessageMode(MessageModes.Market, onMarketMessage)
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
protocol.terminateProtocol()
|
|
|
|
disconnect(g_game, { onGameEnd = Market.reset })
|
2012-08-15 13:56:29 +02:00
|
|
|
disconnect(g_game, { onGameEnd = Market.close })
|
2012-07-27 05:53:42 +02:00
|
|
|
|
2015-01-20 14:34:45 +01:00
|
|
|
destroyAmountWindow()
|
2013-02-01 05:32:15 +01:00
|
|
|
marketWindow:destroy()
|
2012-07-28 05:54:47 +02:00
|
|
|
|
2012-07-17 16:36:27 +02:00
|
|
|
Market = nil
|
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
function Market.reset()
|
2012-07-29 16:05:32 +02:00
|
|
|
balanceLabel:setColor('#bbbbbb')
|
2012-07-27 05:53:42 +02:00
|
|
|
categoryList:setCurrentOption(getMarketCategoryName(MarketCategory.First))
|
2012-08-15 23:25:45 +02:00
|
|
|
searchEdit:setText('')
|
2012-07-27 05:53:42 +02:00
|
|
|
clearFilters()
|
2012-08-19 03:40:04 +02:00
|
|
|
if not table.empty(information) then
|
2012-08-19 03:19:43 +02:00
|
|
|
Market.updateCurrentItems()
|
|
|
|
end
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
|
2015-01-22 20:38:28 +01:00
|
|
|
function Market.displayMessage(message)
|
|
|
|
if marketWindow:isHidden() then return end
|
|
|
|
|
|
|
|
local infoBox = displayInfoBox(tr('Market Error'), message)
|
|
|
|
infoBox:lock()
|
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
function Market.clearSelectedItem()
|
2012-07-29 16:05:32 +02:00
|
|
|
if Market.isItemSelected() then
|
2015-01-25 02:28:53 +01:00
|
|
|
Market.resetCreateOffer(true)
|
2012-07-27 05:53:42 +02:00
|
|
|
offerTypeList:clearOptions()
|
|
|
|
offerTypeList:setText('Please Select')
|
|
|
|
offerTypeList:setEnabled(false)
|
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
clearOffers()
|
2012-07-27 05:53:42 +02:00
|
|
|
radioItemSet:selectWidget(nil)
|
|
|
|
nameLabel:setText('No item selected.')
|
|
|
|
selectedItem:setItem(nil)
|
2012-08-02 16:50:40 +02:00
|
|
|
selectedItem.item = nil
|
|
|
|
selectedItem.ref:setChecked(false)
|
|
|
|
selectedItem.ref = nil
|
2012-07-27 05:53:42 +02:00
|
|
|
|
|
|
|
detailsTable:clearData()
|
|
|
|
buyStatsTable:clearData()
|
|
|
|
sellStatsTable:clearData()
|
|
|
|
|
|
|
|
Market.enableCreateOffer(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Market.isItemSelected()
|
2015-01-23 02:52:05 +01:00
|
|
|
return selectedItem and selectedItem.item
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
|
2012-07-29 16:05:32 +02:00
|
|
|
function Market.isOfferSelected(type)
|
|
|
|
return selectedOffer[type] and not selectedOffer[type]:isNull()
|
|
|
|
end
|
|
|
|
|
2015-01-23 02:52:05 +01:00
|
|
|
function Market.getDepotCount(itemId)
|
|
|
|
return information.depotItems[itemId] or 0
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Market.enableCreateOffer(enable)
|
|
|
|
offerTypeList:setEnabled(enable)
|
|
|
|
totalPriceEdit:setEnabled(enable)
|
|
|
|
piecePriceEdit:setEnabled(enable)
|
|
|
|
amountEdit:setEnabled(enable)
|
|
|
|
anonymous:setEnabled(enable)
|
|
|
|
createOfferButton:setEnabled(enable)
|
2013-02-12 17:30:00 +01:00
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
local prevAmountButton = marketOffersPanel:recursiveGetChildById('prevAmountButton')
|
|
|
|
local nextAmountButton = marketOffersPanel:recursiveGetChildById('nextAmountButton')
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
prevAmountButton:setEnabled(enable)
|
|
|
|
nextAmountButton:setEnabled(enable)
|
|
|
|
end
|
|
|
|
|
2012-08-05 16:42:54 +02:00
|
|
|
function Market.close(notify)
|
2012-08-15 13:56:29 +02:00
|
|
|
if notify == nil then notify = true end
|
2012-08-23 04:59:42 +02:00
|
|
|
if not marketWindow:isHidden() then
|
|
|
|
marketWindow:hide()
|
|
|
|
marketWindow:unlock()
|
2015-01-23 02:52:05 +01:00
|
|
|
Market.clearSelectedItem(
|
|
|
|
) Market.reset()
|
2012-08-23 04:59:42 +02:00
|
|
|
if notify then
|
|
|
|
MarketProtocol.sendMarketLeave()
|
|
|
|
end
|
2012-08-02 16:50:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
function Market.incrementAmount()
|
|
|
|
amountEdit:setValue(amountEdit:getValue() + 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Market.decrementAmount()
|
|
|
|
amountEdit:setValue(amountEdit:getValue() - 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Market.updateCurrentItems()
|
|
|
|
local id = getMarketCategoryId(categoryList:getCurrentOption().text)
|
|
|
|
if id == MarketCategory.MetaWeapons then
|
|
|
|
id = getMarketCategoryId(subCategoryList:getCurrentOption().text)
|
|
|
|
end
|
|
|
|
Market.loadMarketItems(id)
|
|
|
|
end
|
|
|
|
|
2015-01-25 02:28:53 +01:00
|
|
|
function Market.resetCreateOffer(resetFee)
|
2012-07-27 05:53:42 +02:00
|
|
|
piecePriceEdit:setValue(1)
|
|
|
|
totalPriceEdit:setValue(1)
|
|
|
|
amountEdit:setValue(1)
|
|
|
|
refreshTypeList()
|
2015-01-25 02:28:53 +01:00
|
|
|
|
|
|
|
if resetFee then
|
|
|
|
clearFee()
|
|
|
|
else
|
|
|
|
updateFee(0, 0)
|
|
|
|
end
|
2012-07-27 05:53:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Market.refreshItemsWidget(selectItem)
|
|
|
|
local selectItem = selectItem or 0
|
2012-08-07 01:13:33 +02:00
|
|
|
itemsPanel = browsePanel:recursiveGetChildById('itemsPanel')
|
2013-02-12 17:30:00 +01:00
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
local layout = itemsPanel:getLayout()
|
|
|
|
layout:disableUpdates()
|
|
|
|
|
|
|
|
Market.clearSelectedItem()
|
|
|
|
itemsPanel:destroyChildren()
|
|
|
|
|
|
|
|
if radioItemSet then
|
|
|
|
radioItemSet:destroy()
|
|
|
|
end
|
|
|
|
radioItemSet = UIRadioGroup.create()
|
|
|
|
|
|
|
|
local select = nil
|
|
|
|
for i = 1, #currentItems do
|
|
|
|
local item = currentItems[i]
|
|
|
|
local itemBox = g_ui.createWidget('MarketItemBox', itemsPanel)
|
|
|
|
itemBox.onCheckChange = Market.onItemBoxChecked
|
|
|
|
itemBox.item = item
|
2012-08-14 18:18:58 +02:00
|
|
|
|
2015-01-23 02:52:05 +01:00
|
|
|
if selectItem > 0 and item.marketData.tradeAs == selectItem then
|
2012-07-27 05:53:42 +02:00
|
|
|
select = itemBox
|
2015-01-23 02:52:05 +01:00
|
|
|
selectItem = 0
|
2012-07-23 17:11:53 +02:00
|
|
|
end
|
2012-07-27 05:53:42 +02:00
|
|
|
|
|
|
|
local itemWidget = itemBox:getChildById('item')
|
2015-01-23 02:52:05 +01:00
|
|
|
itemWidget:setItem(item.displayItem)
|
2012-08-14 18:18:58 +02:00
|
|
|
|
2015-01-23 02:52:05 +01:00
|
|
|
local amount = Market.getDepotCount(item.marketData.tradeAs)
|
2012-07-27 05:53:42 +02:00
|
|
|
if amount > 0 then
|
|
|
|
itemWidget:setText(amount)
|
|
|
|
itemBox:setTooltip('You have '.. amount ..' in your depot.')
|
|
|
|
end
|
|
|
|
|
|
|
|
radioItemSet:addWidget(itemBox)
|
|
|
|
end
|
2015-01-23 02:52:05 +01:00
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
if select then
|
2015-01-23 02:52:05 +01:00
|
|
|
radioItemSet:selectWidget(select, false)
|
2012-07-23 17:11:53 +02:00
|
|
|
end
|
2012-07-27 05:53:42 +02:00
|
|
|
|
|
|
|
layout:enableUpdates()
|
|
|
|
layout:update()
|
2012-07-23 17:11:53 +02:00
|
|
|
end
|
|
|
|
|
2012-08-15 13:56:29 +02:00
|
|
|
function Market.refreshOffers()
|
|
|
|
if Market.isItemSelected() then
|
|
|
|
Market.onItemBoxChecked(selectedItem.ref)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
function Market.loadMarketItems(category)
|
2012-07-27 05:53:42 +02:00
|
|
|
clearItems()
|
2012-08-15 06:58:56 +02:00
|
|
|
|
|
|
|
-- check search filter
|
2013-02-20 02:44:06 +01:00
|
|
|
local searchFilter = searchEdit:getText()
|
|
|
|
if searchFilter and searchFilter:len() > 2 then
|
|
|
|
if filterButtons[MarketFilters.SearchAll]:isChecked() then
|
|
|
|
category = MarketCategory.All
|
|
|
|
end
|
2012-08-15 06:58:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if category == MarketCategory.All then
|
|
|
|
-- loop all categories
|
|
|
|
for category = MarketCategory.First, MarketCategory.Last do
|
|
|
|
for i = 1, #marketItems[category] do
|
|
|
|
local item = marketItems[category][i]
|
|
|
|
if isItemValid(item, category, searchFilter) then
|
2015-01-23 02:52:05 +01:00
|
|
|
|
2012-08-15 06:58:56 +02:00
|
|
|
table.insert(currentItems, item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- loop specific category
|
|
|
|
for i = 1, #marketItems[category] do
|
|
|
|
local item = marketItems[category][i]
|
|
|
|
if isItemValid(item, category, searchFilter) then
|
|
|
|
table.insert(currentItems, item)
|
|
|
|
end
|
2012-07-20 20:20:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
Market.refreshItemsWidget()
|
2012-07-20 20:20:06 +02:00
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
function Market.createNewOffer()
|
|
|
|
local type = offerTypeList:getCurrentOption().text
|
|
|
|
if type == 'Sell' then
|
|
|
|
type = MarketAction.Sell
|
|
|
|
else
|
|
|
|
type = MarketAction.Buy
|
2012-07-23 17:11:53 +02:00
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
if not Market.isItemSelected() then
|
2012-07-22 16:02:01 +02:00
|
|
|
return
|
|
|
|
end
|
2015-01-23 02:52:05 +01:00
|
|
|
|
|
|
|
local spriteId = selectedItem.item.marketData.tradeAs
|
2012-07-28 15:41:10 +02:00
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
local piecePrice = piecePriceEdit:getValue()
|
|
|
|
local amount = amountEdit:getValue()
|
|
|
|
local anonymous = anonymous:isChecked() and 1 or 0
|
2012-07-20 20:20:06 +02:00
|
|
|
|
2012-08-22 16:21:02 +02:00
|
|
|
-- error checking
|
2012-07-27 05:53:42 +02:00
|
|
|
local errorMsg = ''
|
2012-08-22 16:21:02 +02:00
|
|
|
if type == MarketAction.Buy then
|
|
|
|
if information.balance < ((piecePrice * amount) + fee) then
|
|
|
|
errorMsg = errorMsg..'Not enough balance to create this offer.\n'
|
|
|
|
end
|
|
|
|
elseif type == MarketAction.Sell then
|
2015-01-25 02:28:53 +01:00
|
|
|
if information.balance < fee then
|
|
|
|
errorMsg = errorMsg..'Not enough balance to create this offer.\n'
|
|
|
|
end
|
2015-01-23 02:52:05 +01:00
|
|
|
if Market.getDepotCount(spriteId) < amount then
|
2012-08-22 16:21:02 +02:00
|
|
|
errorMsg = errorMsg..'Not enough items in your depot to create this offer.\n'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
if piecePrice > piecePriceEdit.maximum then
|
|
|
|
errorMsg = errorMsg..'Price is too high.\n'
|
|
|
|
elseif piecePrice < piecePriceEdit.minimum then
|
|
|
|
errorMsg = errorMsg..'Price is too low.\n'
|
2012-07-20 20:20:06 +02:00
|
|
|
end
|
2015-01-25 02:28:53 +01:00
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
if amount > amountEdit.maximum then
|
|
|
|
errorMsg = errorMsg..'Amount is too high.\n'
|
|
|
|
elseif amount < amountEdit.minimum then
|
|
|
|
errorMsg = errorMsg..'Amount is too low.\n'
|
2012-07-22 16:02:01 +02:00
|
|
|
end
|
2012-08-22 16:21:02 +02:00
|
|
|
|
2015-01-25 02:28:53 +01:00
|
|
|
if amount * piecePrice > MarketMaxPrice then
|
|
|
|
errorMsg = errorMsg..'Total price is too high.\n'
|
|
|
|
end
|
|
|
|
|
|
|
|
if information.totalOffers >= MarketMaxOffers then
|
|
|
|
errorMsg = errorMsg..'You cannot create more offers.\n'
|
|
|
|
end
|
|
|
|
|
2012-08-14 17:43:48 +02:00
|
|
|
local timeCheck = os.time() - lastCreatedOffer
|
|
|
|
if timeCheck < offerExhaust[type] then
|
2012-08-22 16:21:02 +02:00
|
|
|
local waitTime = math.ceil(offerExhaust[type] - timeCheck)
|
2012-08-14 17:43:48 +02:00
|
|
|
errorMsg = errorMsg..'You must wait '.. waitTime ..' seconds before creating a new offer.\n'
|
|
|
|
end
|
2012-07-22 16:02:01 +02:00
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
if errorMsg ~= '' then
|
2015-01-22 20:38:28 +01:00
|
|
|
Market.displayMessage(errorMsg)
|
2012-07-27 05:53:42 +02:00
|
|
|
return
|
2012-07-22 16:02:01 +02:00
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
MarketProtocol.sendMarketCreateOffer(type, spriteId, amount, piecePrice, anonymous)
|
2012-08-14 17:43:48 +02:00
|
|
|
lastCreatedOffer = os.time()
|
2012-07-27 05:53:42 +02:00
|
|
|
Market.resetCreateOffer()
|
2012-07-19 20:54:24 +02:00
|
|
|
end
|
|
|
|
|
2012-08-14 18:18:58 +02:00
|
|
|
function Market.acceptMarketOffer(amount, timestamp, counter)
|
2012-07-30 10:02:02 +02:00
|
|
|
if timestamp > 0 and amount > 0 then
|
2012-07-29 16:05:32 +02:00
|
|
|
MarketProtocol.sendMarketAcceptOffer(timestamp, counter, amount)
|
2012-08-15 13:56:29 +02:00
|
|
|
Market.refreshOffers()
|
2012-07-29 16:05:32 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
function Market.onItemBoxChecked(widget)
|
|
|
|
if widget:isChecked() then
|
2012-08-02 16:50:40 +02:00
|
|
|
updateSelectedItem(widget)
|
2012-07-19 20:54:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-05 16:42:54 +02:00
|
|
|
-- protocol callback functions
|
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
function Market.onMarketEnter(depotItems, offers, balance, vocation)
|
2013-02-20 02:44:06 +01:00
|
|
|
if not loaded then
|
2015-01-23 02:52:05 +01:00
|
|
|
initMarketItems()
|
2013-02-20 02:44:06 +01:00
|
|
|
loaded = true
|
|
|
|
end
|
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
updateBalance(balance)
|
2015-01-25 13:41:00 +01:00
|
|
|
averagePrice = 0
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2012-07-19 20:54:24 +02:00
|
|
|
information.totalOffers = offers
|
2012-08-05 16:42:54 +02:00
|
|
|
local player = g_game.getLocalPlayer()
|
|
|
|
if player then
|
|
|
|
information.player = player
|
|
|
|
end
|
2013-02-20 03:03:45 +01:00
|
|
|
if vocation == -1 then
|
2012-08-05 16:42:54 +02:00
|
|
|
if player then
|
|
|
|
information.vocation = player:getVocation()
|
|
|
|
end
|
2012-07-23 17:11:53 +02:00
|
|
|
else
|
|
|
|
-- vocation must be compatible with < 950
|
|
|
|
information.vocation = vocation
|
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2015-01-23 02:52:05 +01:00
|
|
|
-- set list of depot items
|
|
|
|
information.depotItems = depotItems
|
|
|
|
|
2012-08-14 17:43:48 +02:00
|
|
|
-- update the items widget to match depot items
|
|
|
|
if Market.isItemSelected() then
|
2015-01-23 02:52:05 +01:00
|
|
|
local spriteId = selectedItem.item.marketData.tradeAs
|
2012-08-14 17:43:48 +02:00
|
|
|
MarketProtocol.silent(true) -- disable protocol messages
|
|
|
|
Market.refreshItemsWidget(spriteId)
|
|
|
|
MarketProtocol.silent(false) -- enable protocol messages
|
2012-08-15 23:25:45 +02:00
|
|
|
else
|
|
|
|
Market.refreshItemsWidget()
|
2012-08-14 17:43:48 +02:00
|
|
|
end
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2012-07-20 20:20:06 +02:00
|
|
|
if table.empty(currentItems) then
|
|
|
|
Market.loadMarketItems(MarketCategory.First)
|
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-27 05:53:42 +02:00
|
|
|
if g_game.isOnline() then
|
|
|
|
marketWindow:lock()
|
|
|
|
marketWindow:show()
|
2012-07-19 20:54:24 +02:00
|
|
|
end
|
2012-07-17 16:36:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Market.onMarketLeave()
|
2012-08-02 16:50:40 +02:00
|
|
|
Market.close(false)
|
2012-07-17 16:36:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Market.onMarketDetail(itemId, descriptions, purchaseStats, saleStats)
|
2012-07-27 05:53:42 +02:00
|
|
|
updateDetails(itemId, descriptions, purchaseStats, saleStats)
|
2012-07-17 16:36:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Market.onMarketBrowse(offers)
|
2012-07-27 05:53:42 +02:00
|
|
|
updateOffers(offers)
|
2012-07-20 20:56:08 +02:00
|
|
|
end
|