2012-07-17 16:36:27 +02:00
|
|
|
Market = {}
|
|
|
|
|
2012-07-19 20:54:24 +02:00
|
|
|
g_ui.importStyle('market.otui')
|
|
|
|
g_ui.importStyle('ui/general/markettabs.otui')
|
|
|
|
g_ui.importStyle('ui/general/marketbuttons.otui')
|
2012-07-20 20:20:06 +02:00
|
|
|
g_ui.importStyle('ui/general/marketcombobox.otui')
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-17 16:36:27 +02:00
|
|
|
local marketWindow
|
2012-07-19 20:54:24 +02:00
|
|
|
local mainTabBar
|
|
|
|
|
|
|
|
local marketOffersPanel
|
|
|
|
local selectionTabBar
|
2012-07-23 17:11:53 +02:00
|
|
|
local displaysTabBar
|
|
|
|
local offersTabBar
|
|
|
|
|
|
|
|
local itemsPanel
|
2012-07-19 20:54:24 +02:00
|
|
|
local browsePanel
|
|
|
|
local searchPanel
|
|
|
|
local itemOffersPanel
|
|
|
|
local itemDetailsPanel
|
|
|
|
local itemStatsPanel
|
|
|
|
local myOffersPanel
|
|
|
|
local currentOffersPanel
|
|
|
|
local offerHistoryPanel
|
|
|
|
|
|
|
|
local selectedItem
|
|
|
|
local nameLabel
|
2012-07-23 17:11:53 +02:00
|
|
|
local radioItemSet
|
|
|
|
local categoryList
|
|
|
|
local subCategoryList
|
|
|
|
local slotFilterList
|
|
|
|
local filterButtons = {}
|
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
local buyOfferTable
|
|
|
|
local sellOfferTable
|
|
|
|
local detailsTable
|
|
|
|
local buyStatsTable
|
|
|
|
local sellStatsTable
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
local marketOffers = {}
|
|
|
|
local marketItems = {}
|
|
|
|
local depot = {}
|
|
|
|
local information = {}
|
2012-07-20 20:20:06 +02:00
|
|
|
local currentItems = {}
|
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
local offerTableHeader = {
|
|
|
|
{['text'] = 'Player Name', ['width'] = 100},
|
|
|
|
{['text'] = 'Amount', ['width'] = 60},
|
|
|
|
{['text'] = 'Total Price', ['width'] = 90},
|
|
|
|
{['text'] = 'Peice Price', ['width'] = 80},
|
|
|
|
{['text'] = 'Ends at', ['width'] = 120}
|
|
|
|
}
|
|
|
|
|
|
|
|
local function getMarketCategoryName(id)
|
|
|
|
if table.hasKey(MarketCategoryStrings, id) then
|
|
|
|
return MarketCategoryStrings[id]
|
2012-07-20 20:20:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function getMarketCategoryId(name)
|
|
|
|
local id = table.find(MarketCategoryStrings, name)
|
|
|
|
if id then
|
|
|
|
return id
|
|
|
|
end
|
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
local function getMarketDescriptionName(id)
|
|
|
|
if table.hasKey(MarketItemDescriptionStrings, id) then
|
|
|
|
return MarketItemDescriptionStrings[id]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function getMarketDescriptionId(name)
|
|
|
|
local id = table.find(MarketItemDescriptionStrings, name)
|
|
|
|
if id then
|
|
|
|
return id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
local function getMarketSlotFilterId(name)
|
|
|
|
local id = table.find(MarketSlotFilters, name)
|
|
|
|
if id then
|
|
|
|
return id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function getMarketSlotFilterName(id)
|
|
|
|
if table.hasKey(MarketSlotFilters, id) then
|
|
|
|
return MarketSlotFilters[id]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function isValidItem(item, category)
|
|
|
|
if item.marketData.category ~= category and category ~= MarketCategory[0] then
|
|
|
|
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
|
|
|
|
if slotFilter ~= 255 and item.ptr:getClothSlot() ~= slotFilter then
|
|
|
|
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
|
|
|
|
if filterDepot and not Market.depotContains(item.ptr:getId()) then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-07-19 20:54:24 +02:00
|
|
|
local function clearSelectedItem()
|
2012-07-20 20:20:06 +02:00
|
|
|
if selectedItem and selectedItem.item.ptr then
|
|
|
|
Market.updateOffers({})
|
|
|
|
radioItemSet:selectWidget(nil)
|
2012-07-22 16:02:01 +02:00
|
|
|
nameLabel:setText('No item selected.')
|
|
|
|
|
2012-07-20 20:20:06 +02:00
|
|
|
selectedItem:setItem(nil)
|
|
|
|
selectedItem.item = {}
|
2012-07-22 16:02:01 +02:00
|
|
|
|
|
|
|
detailsTable:clearData()
|
|
|
|
buyStatsTable:clearData()
|
|
|
|
sellStatsTable:clearData()
|
2012-07-19 20:54:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-20 20:20:06 +02:00
|
|
|
local function initMarketItems()
|
|
|
|
-- populate all market items
|
|
|
|
marketItems = {}
|
|
|
|
local types = g_things.findThingTypeByAttr(ThingAttrMarket)
|
2012-07-21 14:15:29 +02:00
|
|
|
for i = 1, #types do
|
|
|
|
local t = types[i]
|
2012-07-20 20:20:06 +02:00
|
|
|
local newItem = Item.create(t:getId())
|
|
|
|
if newItem then
|
2012-07-23 17:11:53 +02:00
|
|
|
local marketData = t:getMarketData()
|
|
|
|
if not table.empty(marketData) then
|
|
|
|
local item = {
|
|
|
|
ptr = newItem,
|
|
|
|
marketData = marketData
|
|
|
|
}
|
|
|
|
marketItems[#marketItems+1] = item
|
|
|
|
end
|
2012-07-20 20:20:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-20 20:20:06 +02:00
|
|
|
local function updateItemsWidget()
|
2012-07-22 16:02:01 +02:00
|
|
|
itemsPanel = browsePanel:recursiveGetChildById('itemsPanel')
|
2012-07-19 20:54:24 +02:00
|
|
|
local layout = itemsPanel:getLayout()
|
|
|
|
layout:disableUpdates()
|
|
|
|
|
|
|
|
clearSelectedItem()
|
|
|
|
itemsPanel:destroyChildren()
|
|
|
|
|
|
|
|
if radioItemSet then
|
|
|
|
radioItemSet:destroy()
|
|
|
|
end
|
|
|
|
radioItemSet = UIRadioGroup.create()
|
|
|
|
|
2012-07-21 14:15:29 +02:00
|
|
|
for i = 1, #currentItems do
|
|
|
|
local item = currentItems[i]
|
2012-07-20 20:20:06 +02:00
|
|
|
local itemBox = g_ui.createWidget('MarketItemBox', itemsPanel)
|
|
|
|
local itemWidget = itemBox:getChildById('item')
|
|
|
|
|
|
|
|
itemBox.item = item
|
|
|
|
itemWidget:setItem(item.ptr)
|
|
|
|
|
|
|
|
radioItemSet:addWidget(itemBox)
|
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
|
|
|
|
layout:enableUpdates()
|
|
|
|
layout:update()
|
|
|
|
end
|
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
local function onUpdateCategory(combobox, option)
|
|
|
|
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-23 17:11:53 +02:00
|
|
|
local function onUpdateSubCategory(combobox, option)
|
|
|
|
local id = getMarketCategoryId(option)
|
|
|
|
Market.loadMarketItems(id)
|
|
|
|
-- setup slot filter
|
|
|
|
slotFilterList:clearOptions()
|
|
|
|
local subId = getMarketCategoryId(subCategoryList:getCurrentOption().text)
|
|
|
|
local slots = MarketCategoryWeapons[subId].slots
|
|
|
|
for _, slot in pairs(slots) do
|
|
|
|
if table.hasKey(MarketSlotFilters, slot) then
|
|
|
|
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
|
|
|
|
|
|
|
|
local function onUpdateSlotFilter(combobox, option)
|
|
|
|
Market.updateCurrentItems()
|
2012-07-19 20:54:24 +02:00
|
|
|
end
|
2012-07-17 16:36:27 +02:00
|
|
|
|
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
|
|
|
|
marketOffersPanel = g_ui.loadUI('ui/marketoffers.otui')
|
|
|
|
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
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
browsePanel = g_ui.loadUI('ui/marketoffers/browse.otui')
|
|
|
|
selectionTabBar:addTab(tr('Browse'), browsePanel)
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
searchPanel = g_ui.loadUI('ui/marketoffers/search.otui')
|
|
|
|
selectionTabBar:addTab(tr('Search'), searchPanel)
|
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
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
itemOffersPanel = g_ui.loadUI('ui/marketoffers/itemoffers.otui')
|
|
|
|
displaysTabBar:addTab(tr('Offers'), itemOffersPanel)
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
itemDetailsPanel = g_ui.loadUI('ui/marketoffers/itemdetails.otui')
|
|
|
|
displaysTabBar:addTab(tr('Details'), itemDetailsPanel)
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
itemStatsPanel = g_ui.loadUI('ui/marketoffers/itemstats.otui')
|
|
|
|
displaysTabBar:addTab(tr('Statistics'), itemStatsPanel)
|
2012-07-19 20:54:24 +02:00
|
|
|
|
|
|
|
-- setup 'My Offer' section tabs
|
|
|
|
myOffersPanel = g_ui.loadUI('ui/myoffers.otui')
|
|
|
|
mainTabBar:addTab(tr('My Offers'), myOffersPanel)
|
|
|
|
|
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
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
currentOffersPanel = g_ui.loadUI('ui/myoffers/currentoffers.otui')
|
|
|
|
offersTabBar:addTab(tr('Current Offers'), currentOffersPanel)
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
offerHistoryPanel = g_ui.loadUI('ui/myoffers/offerhistory.otui')
|
|
|
|
offersTabBar:addTab(tr('Offer History'), offerHistoryPanel)
|
2012-07-20 20:20:06 +02:00
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
-- setup selected item
|
|
|
|
nameLabel = marketOffersPanel:recursiveGetChildById('nameLabel')
|
|
|
|
selectedItem = marketOffersPanel:recursiveGetChildById('selectedItem')
|
2012-07-20 20:20:06 +02:00
|
|
|
selectedItem.item = {}
|
|
|
|
|
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-07-20 20:20:06 +02:00
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
categoryList = browsePanel:getChildById('categoryComboBox')
|
|
|
|
subCategoryList = browsePanel:getChildById('subCategoryComboBox')
|
|
|
|
slotFilterList = browsePanel:getChildById('typeComboBox')
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
-- hook item filters
|
|
|
|
categoryList.onOptionChange = onUpdateCategory
|
|
|
|
subCategoryList.onOptionChange = onUpdateSubCategory
|
|
|
|
slotFilterList.onOptionChange = onUpdateSlotFilter
|
2012-07-22 16:02:01 +02:00
|
|
|
|
|
|
|
-- get tables
|
|
|
|
buyOfferTable = itemOffersPanel:recursiveGetChildById('buyingTable')
|
|
|
|
sellOfferTable = itemOffersPanel:recursiveGetChildById('sellingTable')
|
|
|
|
detailsTable = itemDetailsPanel:recursiveGetChildById('detailsTable')
|
|
|
|
buyStatsTable = itemStatsPanel:recursiveGetChildById('buyStatsTable')
|
|
|
|
sellStatsTable = itemStatsPanel:recursiveGetChildById('sellStatsTable')
|
|
|
|
end
|
|
|
|
|
|
|
|
function Market.init()
|
|
|
|
marketWindow = g_ui.createWidget('MarketWindow', rootWidget)
|
|
|
|
marketWindow:hide()
|
|
|
|
|
|
|
|
initInterface() -- build interface
|
|
|
|
initMarketItems()
|
2012-07-17 16:36:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Market.terminate()
|
2012-07-19 20:54:24 +02:00
|
|
|
if marketWindow then
|
|
|
|
marketWindow:destroy()
|
|
|
|
marketWindow = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
mainTabBar = nil
|
2012-07-23 17:11:53 +02:00
|
|
|
displaysTabBar = nil
|
|
|
|
offersTabBar = nil
|
2012-07-19 20:54:24 +02:00
|
|
|
selectionTabBar = nil
|
2012-07-23 17:11:53 +02:00
|
|
|
|
|
|
|
marketOffersPanel = nil
|
2012-07-19 20:54:24 +02:00
|
|
|
browsePanel = nil
|
|
|
|
searchPanel = nil
|
|
|
|
itemOffersPanel = nil
|
|
|
|
itemDetailsPanel = nil
|
|
|
|
itemStatsPanel = nil
|
|
|
|
myOffersPanel = nil
|
|
|
|
currentOffersPanel = nil
|
|
|
|
offerHistoryPanel = nil
|
|
|
|
itemsPanel = nil
|
2012-07-23 17:11:53 +02:00
|
|
|
|
2012-07-19 20:54:24 +02:00
|
|
|
nameLabel = nil
|
2012-07-23 17:11:53 +02:00
|
|
|
radioItemSet = nil
|
|
|
|
selectedItem = nil
|
|
|
|
categoryList = nil
|
|
|
|
subCategoryList = nil
|
|
|
|
slotFilterList = nil
|
|
|
|
filterButtons = {}
|
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
buyOfferTable = nil
|
|
|
|
sellOfferTable = nil
|
|
|
|
detailsTable = nil
|
|
|
|
buyStatsTable = nil
|
|
|
|
sellStatsTable = nil
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
marketOffers = {}
|
|
|
|
marketItems = {}
|
|
|
|
information = {}
|
|
|
|
currentItems = {}
|
|
|
|
|
2012-07-17 16:36:27 +02:00
|
|
|
Market = nil
|
|
|
|
end
|
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
function Market.depotContains(itemId)
|
|
|
|
for i = 1, #information.depotItems do
|
|
|
|
local item = information.depotItems[i]
|
|
|
|
if item.ptr:getId() == itemId then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
function Market.loadMarketItems(category)
|
2012-07-20 20:20:06 +02:00
|
|
|
if table.empty(marketItems) then
|
|
|
|
initMarketItems()
|
|
|
|
end
|
|
|
|
|
|
|
|
currentItems = {}
|
2012-07-21 14:15:29 +02:00
|
|
|
for i = 1, #marketItems do
|
|
|
|
local item = marketItems[i]
|
2012-07-23 17:11:53 +02:00
|
|
|
if isValidItem(item, category) then
|
2012-07-20 20:20:06 +02:00
|
|
|
table.insert(currentItems, item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
updateItemsWidget()
|
|
|
|
end
|
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
function Market.loadDepotItems(depotItems)
|
|
|
|
information.depotItems = {}
|
|
|
|
for i = 1, #depotItems do
|
|
|
|
local data = depotItems[i]
|
|
|
|
local newItem = Item.create(data[1])
|
|
|
|
if not newItem then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
newItem:setCount(data[2])
|
|
|
|
local marketData = newItem:getMarketData()
|
|
|
|
|
|
|
|
if not table.empty(marketData) then
|
|
|
|
local item = {
|
|
|
|
ptr = newItem,
|
|
|
|
marketData = marketData
|
|
|
|
}
|
|
|
|
table.insert(information.depotItems, item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Market.updateCurrentItems()
|
|
|
|
-- get market category
|
|
|
|
local id = getMarketCategoryId(categoryList:getCurrentOption().text)
|
|
|
|
if id == MarketCategory.MetaWeapons then
|
|
|
|
id = getMarketCategoryId(subCategoryList:getCurrentOption().text)
|
|
|
|
end
|
|
|
|
Market.loadMarketItems(id)
|
|
|
|
end
|
|
|
|
|
2012-07-19 20:54:24 +02:00
|
|
|
function Market.updateOffers(offers)
|
2012-07-20 20:20:06 +02:00
|
|
|
marketOffers[MarketAction.Buy] = {}
|
|
|
|
marketOffers[MarketAction.Sell] = {}
|
2012-07-22 16:02:01 +02:00
|
|
|
if not buyOfferTable or not sellOfferTable then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
buyOfferTable:clearData()
|
|
|
|
sellOfferTable:clearData()
|
2012-07-20 20:20:06 +02:00
|
|
|
|
2012-07-19 20:54:24 +02:00
|
|
|
for k, offer in pairs(offers) do
|
|
|
|
if offer and offer:getAction() == MarketAction.Buy then
|
2012-07-21 14:15:29 +02:00
|
|
|
local data = {
|
2012-07-22 16:02:01 +02:00
|
|
|
{['text'] = offer:getPlayer(), ['width'] = 100},
|
|
|
|
{['text'] = offer:getAmount(), ['width'] = 60},
|
|
|
|
{['text'] = offer:getPrice()*offer:getAmount(), ['width'] = 90},
|
|
|
|
{['text'] = offer:getPrice(), ['width'] = 80},
|
|
|
|
{['text'] = offer:getTimeStamp(), ['width'] = 120}
|
2012-07-21 14:15:29 +02:00
|
|
|
}
|
2012-07-22 16:02:01 +02:00
|
|
|
buyOfferTable:addRow(data)
|
2012-07-19 20:54:24 +02:00
|
|
|
table.insert(marketOffers[MarketAction.Buy], offer)
|
|
|
|
else
|
2012-07-21 14:15:29 +02:00
|
|
|
local data = {
|
2012-07-22 16:02:01 +02:00
|
|
|
{['text'] = offer:getPlayer(), ['width'] = 100},
|
|
|
|
{['text'] = offer:getAmount(), ['width'] = 60},
|
|
|
|
{['text'] = offer:getPrice()*offer:getAmount(), ['width'] = 90},
|
|
|
|
{['text'] = offer:getPrice(), ['width'] = 80},
|
|
|
|
{['text'] = offer:getTimeStamp(), ['width'] = 120}
|
2012-07-21 14:15:29 +02:00
|
|
|
}
|
2012-07-22 16:02:01 +02:00
|
|
|
sellOfferTable:addRow(data)
|
2012-07-19 20:54:24 +02:00
|
|
|
table.insert(marketOffers[MarketAction.Sell], offer)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Market.updateDetails(itemId, descriptions, purchaseStats, saleStats)
|
2012-07-20 20:20:06 +02:00
|
|
|
if not selectedItem then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
selectedItem.item.details = {
|
|
|
|
descriptions = descriptions,
|
|
|
|
purchaseStats = purchaseStats,
|
|
|
|
saleStats = saleStats
|
|
|
|
}
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
-- update item details
|
|
|
|
detailsTable:clearData()
|
|
|
|
for k, desc in pairs(descriptions) do
|
|
|
|
local columns = {
|
2012-07-23 17:11:53 +02:00
|
|
|
{['text'] = getMarketDescriptionName(desc[1])..':'},
|
2012-07-22 16:02:01 +02:00
|
|
|
{['text'] = desc[2], ['width'] = 330}
|
|
|
|
}
|
|
|
|
detailsTable:addRow(columns)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- update sale item statistics
|
|
|
|
sellStatsTable:clearData()
|
|
|
|
if table.empty(saleStats) then
|
2012-07-23 17:11:53 +02:00
|
|
|
sellStatsTable:addRow({{['text'] = 'No information'}})
|
2012-07-22 16:02:01 +02:00
|
|
|
else
|
|
|
|
for k, stat in pairs(saleStats) do
|
|
|
|
if not table.empty(stat) then
|
2012-07-23 17:11:53 +02:00
|
|
|
sellStatsTable:addRow({{['text'] = 'Total Transations:'},
|
2012-07-22 16:02:01 +02:00
|
|
|
{['text'] = stat[1], ['width'] = 270}})
|
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
sellStatsTable:addRow({{['text'] = 'Highest Price:'},
|
2012-07-22 16:02:01 +02:00
|
|
|
{['text'] = stat[3], ['width'] = 270}})
|
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
sellStatsTable:addRow({{['text'] = 'Average Price:'},
|
|
|
|
{['text'] = math.floor(stat[2]/stat[1])}})
|
2012-07-22 16:02:01 +02:00
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
sellStatsTable:addRow({{['text'] = 'Lowest Price:'},
|
2012-07-22 16:02:01 +02:00
|
|
|
{['text'] = stat[4], ['width'] = 270}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- update buy item statistics
|
|
|
|
buyStatsTable:clearData()
|
|
|
|
if table.empty(purchaseStats) then
|
2012-07-23 17:11:53 +02:00
|
|
|
buyStatsTable:addRow({{['text'] = 'No information'}})
|
2012-07-22 16:02:01 +02:00
|
|
|
else
|
|
|
|
for k, stat in pairs(purchaseStats) do
|
|
|
|
if not table.empty(stat) then
|
2012-07-23 17:11:53 +02:00
|
|
|
buyStatsTable:addRow({{['text'] = 'Total Transations:'},
|
2012-07-22 16:02:01 +02:00
|
|
|
{['text'] = stat[1], ['width'] = 270}})
|
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
buyStatsTable:addRow({{['text'] = 'Highest Price:'},
|
2012-07-22 16:02:01 +02:00
|
|
|
{['text'] = stat[3], ['width'] = 270}})
|
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
buyStatsTable:addRow({{['text'] = 'Average Price:'},
|
2012-07-22 16:02:01 +02:00
|
|
|
{['text'] = math.floor(stat[2]/stat[1]), ['width'] = 270}})
|
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
buyStatsTable:addRow({{['text'] = 'Lowest Price:'},
|
2012-07-22 16:02:01 +02:00
|
|
|
{['text'] = stat[4], ['width'] = 270}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Market.updateSelectedItem(newItem)
|
2012-07-20 20:20:06 +02:00
|
|
|
selectedItem.item = newItem
|
|
|
|
if selectedItem and not table.empty(selectedItem.item) then
|
|
|
|
if selectedItem.item.ptr then
|
|
|
|
selectedItem:setItem(selectedItem.item.ptr)
|
|
|
|
nameLabel:setText(selectedItem.item.marketData.name)
|
2012-07-23 17:11:53 +02:00
|
|
|
MarketProtocol.sendMarketBrowse(selectedItem.item.ptr:getId()) -- send browsed msg
|
2012-07-19 20:54:24 +02:00
|
|
|
end
|
|
|
|
else
|
2012-07-20 20:20:06 +02:00
|
|
|
selectedItem:setItem(nil)
|
|
|
|
nameLabel:setText(tr('No item selected.'))
|
2012-07-19 20:54:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
function Market.onMarketEnter(depotItems, offers, balance, vocation)
|
2012-07-19 20:54:24 +02:00
|
|
|
if marketWindow:isVisible() then
|
|
|
|
return
|
2012-07-17 16:36:27 +02:00
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
marketOffers[MarketAction.Buy] = {}
|
|
|
|
marketOffers[MarketAction.Sell] = {}
|
|
|
|
|
2012-07-23 17:11:53 +02:00
|
|
|
--[[
|
|
|
|
TODO:
|
|
|
|
* clear filters on enter
|
|
|
|
* add market reset function
|
|
|
|
]]
|
2012-07-19 20:54:24 +02:00
|
|
|
information.balance = balance
|
|
|
|
information.totalOffers = offers
|
2012-07-23 17:11:53 +02:00
|
|
|
if vocation < 0 then
|
|
|
|
local player = g_game.getLocalPlayer()
|
|
|
|
if player then information.vocation = player:getVocation() end
|
|
|
|
else
|
|
|
|
-- vocation must be compatible with < 950
|
|
|
|
information.vocation = vocation
|
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-20 20:20:06 +02:00
|
|
|
if table.empty(currentItems) then
|
|
|
|
Market.loadMarketItems(MarketCategory.First)
|
|
|
|
end
|
2012-07-23 17:11:53 +02:00
|
|
|
Market.loadDepotItems(depotItems)
|
2012-07-19 20:54:24 +02:00
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
-- build offer table header
|
|
|
|
if buyOfferTable and not buyOfferTable:hasHeader() then
|
|
|
|
buyOfferTable:addHeaderRow(offerTableHeader)
|
|
|
|
end
|
|
|
|
if sellOfferTable and not sellOfferTable:hasHeader() then
|
|
|
|
sellOfferTable:addHeaderRow(offerTableHeader)
|
|
|
|
end
|
|
|
|
|
|
|
|
local currentItem = radioItemSet:getSelectedWidget()
|
|
|
|
if currentItem then
|
|
|
|
-- Uncheck selected item, cannot make protocol calls to resend marketBrowsing
|
|
|
|
clearSelectedItem()
|
2012-07-19 20:54:24 +02:00
|
|
|
end
|
2012-07-23 17:11:53 +02:00
|
|
|
|
|
|
|
marketWindow:lock()
|
2012-07-19 20:54:24 +02:00
|
|
|
marketWindow:show()
|
2012-07-17 16:36:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Market.onMarketLeave()
|
2012-07-19 20:54:24 +02:00
|
|
|
marketWindow:hide()
|
2012-07-17 16:36:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Market.onMarketDetail(itemId, descriptions, purchaseStats, saleStats)
|
2012-07-19 20:54:24 +02:00
|
|
|
Market.updateDetails(itemId, descriptions, purchaseStats, saleStats)
|
2012-07-17 16:36:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Market.onMarketBrowse(offers)
|
2012-07-19 20:54:24 +02:00
|
|
|
Market.updateOffers(offers)
|
2012-07-17 16:36:27 +02:00
|
|
|
end
|
2012-07-19 20:54:24 +02:00
|
|
|
|
|
|
|
function Market.onItemBoxChecked(widget)
|
|
|
|
if widget:isChecked() then
|
|
|
|
Market.updateSelectedItem(widget.item)
|
|
|
|
end
|
2012-07-20 20:56:08 +02:00
|
|
|
end
|