Some optimization to the market.
* Market items are not cached to their categories. * Fixed onMarketLeave issue. * Few minor fixes.
This commit is contained in:
parent
3c26555255
commit
2bd1e0f6c4
|
@ -10,12 +10,6 @@
|
||||||
- Current Offers
|
- Current Offers
|
||||||
- Offer History
|
- Offer History
|
||||||
|
|
||||||
* Optimize Offer Updates:
|
|
||||||
- Cache and avoid dead loop runs
|
|
||||||
|
|
||||||
* Optimize loading market items:
|
|
||||||
- Cache items to their categories
|
|
||||||
|
|
||||||
* Clean up the interface building
|
* Clean up the interface building
|
||||||
- Add a new market interface file to handle building?
|
- Add a new market interface file to handle building?
|
||||||
|
|
||||||
|
@ -26,6 +20,10 @@
|
||||||
|
|
||||||
* 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)
|
||||||
|
|
||||||
|
* Make compatible with cipsoft 9.61 (has the protocol changed? creating offer not working)
|
||||||
]]
|
]]
|
||||||
|
|
||||||
Market = {}
|
Market = {}
|
||||||
|
@ -91,17 +89,14 @@ local offerTableHeader = {
|
||||||
{['text'] = 'Ends at', ['width'] = 120}
|
{['text'] = 'Ends at', ['width'] = 120}
|
||||||
}
|
}
|
||||||
|
|
||||||
local function isItemValid(item, category)
|
local function isItemValid(item, category, searchFilter)
|
||||||
local searchFilter = searchEdit:getText():lower()
|
if not item or not item.marketData then
|
||||||
local useSearchFilter = false
|
return false
|
||||||
if searchFilter and searchFilter:len() > 2 then
|
|
||||||
useSearchFilter = true
|
|
||||||
end
|
|
||||||
local filterSearchAll = filterButtons[MarketFilters.SearchAll]:isChecked()
|
|
||||||
if filterSearchAll and useSearchFilter then
|
|
||||||
category = MarketCategory.All
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not category then
|
||||||
|
category = MarketCategory.All
|
||||||
|
end
|
||||||
if item.marketData.category ~= category and category ~= MarketCategory.All then
|
if item.marketData.category ~= category and category ~= MarketCategory.All then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -135,7 +130,7 @@ local function isItemValid(item, category)
|
||||||
if filterDepot and Market.depotContains(item.ptr:getId()) <= 0 then
|
if filterDepot and Market.depotContains(item.ptr:getId()) <= 0 then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if useSearchFilter then
|
if searchFilter then
|
||||||
local checkString = marketData.name:lower()
|
local checkString = marketData.name:lower()
|
||||||
if not checkString:find(searchFilter) then
|
if not checkString:find(searchFilter) then
|
||||||
return false
|
return false
|
||||||
|
@ -251,21 +246,22 @@ local function mergeOffer(offer)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function updateOffers(offers)
|
local function updateOffers(offers)
|
||||||
-- TODO: optimize offer updates
|
|
||||||
selectedOffer[MarketAction.Buy] = nil
|
|
||||||
selectedOffer[MarketAction.Sell] = nil
|
|
||||||
|
|
||||||
if not buyOfferTable or not sellOfferTable then
|
if not buyOfferTable or not sellOfferTable then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
balanceLabel:setColor('#bbbbbb')
|
balanceLabel:setColor('#bbbbbb')
|
||||||
|
selectedOffer[MarketAction.Buy] = nil
|
||||||
|
selectedOffer[MarketAction.Sell] = nil
|
||||||
|
|
||||||
|
-- clear existing offer data
|
||||||
buyOfferTable:clearData()
|
buyOfferTable:clearData()
|
||||||
sellOfferTable:clearData()
|
sellOfferTable:clearData()
|
||||||
|
|
||||||
sellButton:setEnabled(false)
|
sellButton:setEnabled(false)
|
||||||
buyButton:setEnabled(false)
|
buyButton:setEnabled(false)
|
||||||
|
|
||||||
for k, offer in pairs(offers) do
|
for _, offer in pairs(offers) do
|
||||||
mergeOffer(offer)
|
mergeOffer(offer)
|
||||||
end
|
end
|
||||||
for type, offers in pairs(marketOffers) do
|
for type, offers in pairs(marketOffers) do
|
||||||
|
@ -582,21 +578,23 @@ local function onAmountChange()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function initMarketItems()
|
local function initMarketItems(category)
|
||||||
|
-- initialize market category
|
||||||
|
marketItems[category] = {}
|
||||||
|
|
||||||
-- populate all market items
|
-- populate all market items
|
||||||
marketItems = {}
|
|
||||||
local types = g_things.findThingTypeByAttr(ThingAttrMarket, 0)
|
local types = g_things.findThingTypeByAttr(ThingAttrMarket, 0)
|
||||||
for i = 1, #types do
|
for i = 1, #types do
|
||||||
local t = types[i]
|
local t = types[i]
|
||||||
local newItem = Item.create(t:getId())
|
local newItem = Item.create(t:getId())
|
||||||
if newItem then
|
if newItem then
|
||||||
local marketData = t:getMarketData()
|
local marketData = t:getMarketData()
|
||||||
if not table.empty(marketData) then
|
if not table.empty(marketData) and marketData.category == category then
|
||||||
local item = {
|
local item = {
|
||||||
ptr = newItem,
|
ptr = newItem,
|
||||||
marketData = marketData
|
marketData = marketData
|
||||||
}
|
}
|
||||||
marketItems[#marketItems+1] = item
|
marketItems[marketData.category][#marketItems[category]+1] = item
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -733,7 +731,9 @@ function init()
|
||||||
marketWindow:hide()
|
marketWindow:hide()
|
||||||
|
|
||||||
initInterface() -- build interface
|
initInterface() -- build interface
|
||||||
initMarketItems()
|
for category = MarketCategory.First, MarketCategory.Last do
|
||||||
|
initMarketItems(category)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function terminate()
|
function terminate()
|
||||||
|
@ -748,7 +748,7 @@ function terminate()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Market.reset()
|
function Market.reset()
|
||||||
Market.close()
|
Market.close(true)
|
||||||
balanceLabel:setColor('#bbbbbb')
|
balanceLabel:setColor('#bbbbbb')
|
||||||
categoryList:setCurrentOption(getMarketCategoryName(MarketCategory.First))
|
categoryList:setCurrentOption(getMarketCategoryName(MarketCategory.First))
|
||||||
clearFilters()
|
clearFilters()
|
||||||
|
@ -811,7 +811,6 @@ function Market.enableCreateOffer(enable)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Market.close(notify)
|
function Market.close(notify)
|
||||||
local notify = notify or true
|
|
||||||
marketWindow:hide()
|
marketWindow:hide()
|
||||||
marketWindow:unlock()
|
marketWindow:unlock()
|
||||||
Market.clearSelectedItem()
|
Market.clearSelectedItem()
|
||||||
|
@ -894,17 +893,40 @@ end
|
||||||
* Preload items to their categories
|
* Preload items to their categories
|
||||||
]]
|
]]
|
||||||
function Market.loadMarketItems(category)
|
function Market.loadMarketItems(category)
|
||||||
if table.empty(marketItems) then
|
if table.empty(marketItems[category]) then
|
||||||
initMarketItems()
|
initMarketItems(category)
|
||||||
|
end
|
||||||
|
clearItems()
|
||||||
|
|
||||||
|
-- check search filter
|
||||||
|
local searchFilter = searchEdit:getText():lower()
|
||||||
|
if not searchFilter or searchFilter:len() < 3 then
|
||||||
|
searchFilter = nil
|
||||||
|
end
|
||||||
|
local filterSearchAll = filterButtons[MarketFilters.SearchAll]:isChecked()
|
||||||
|
if filterSearchAll and searchFilter then
|
||||||
|
category = MarketCategory.All
|
||||||
end
|
end
|
||||||
|
|
||||||
clearItems()
|
if category == MarketCategory.All then
|
||||||
for i = 1, #marketItems do
|
-- loop all categories
|
||||||
local item = marketItems[i]
|
for category = MarketCategory.First, MarketCategory.Last do
|
||||||
if isItemValid(item, category) then
|
for i = 1, #marketItems[category] do
|
||||||
|
local item = marketItems[category][i]
|
||||||
|
if isItemValid(item, category, searchFilter) then
|
||||||
table.insert(currentItems, item)
|
table.insert(currentItems, item)
|
||||||
end
|
end
|
||||||
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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Market.refreshItemsWidget()
|
Market.refreshItemsWidget()
|
||||||
end
|
end
|
||||||
|
@ -978,6 +1000,7 @@ function Market.createNewOffer()
|
||||||
local amount = amountEdit:getValue()
|
local amount = amountEdit:getValue()
|
||||||
local anonymous = anonymous:isChecked() and 1 or 0
|
local anonymous = anonymous:isChecked() and 1 or 0
|
||||||
|
|
||||||
|
-- error check offer
|
||||||
local errorMsg = ''
|
local errorMsg = ''
|
||||||
if piecePrice > piecePriceEdit.maximum then
|
if piecePrice > piecePriceEdit.maximum then
|
||||||
errorMsg = errorMsg..'Price is too high.\n'
|
errorMsg = errorMsg..'Price is too high.\n'
|
||||||
|
|
|
@ -3,7 +3,7 @@ MarketWindow < MainWindow
|
||||||
!text: tr('Market')
|
!text: tr('Market')
|
||||||
size: 700 510
|
size: 700 510
|
||||||
|
|
||||||
@onEscape: Market.close()
|
@onEscape: Market.close(true)
|
||||||
|
|
||||||
// Main Panel Window
|
// Main Panel Window
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue