Some more work on the Market.
* Added Finalizing TODO list for anyone that wants to work on some missing areas (I am busy with work so any help from the community will speed it up). * Added market item key word searching. * Removed the search tab in replace for overview tab that can be used for extended functionality later. * Few minor additions.
This commit is contained in:
parent
18c882f1a0
commit
26c196cdb0
|
@ -1,3 +1,34 @@
|
||||||
|
--[[
|
||||||
|
Finalizing Market:
|
||||||
|
Note: Feel free to work on any area and submit
|
||||||
|
it as a pull request from your git fork.
|
||||||
|
|
||||||
|
BeniS's Skype: benjiz69
|
||||||
|
|
||||||
|
List:
|
||||||
|
* Add constraints for creating/buying offers:
|
||||||
|
- Add max market offers or a new method for updating depot items
|
||||||
|
- Add a check for buying offers (if you do not have enough balance)
|
||||||
|
|
||||||
|
* Add offer management:
|
||||||
|
- Current Offers
|
||||||
|
- Offer History
|
||||||
|
|
||||||
|
* Optimize Offer Updates:
|
||||||
|
- Cache and avoid dead loop runs
|
||||||
|
|
||||||
|
* Clean up the interface building
|
||||||
|
- Add a new market interface file to handle building?
|
||||||
|
|
||||||
|
* Optimize loading market items:
|
||||||
|
- Cache items to their categories
|
||||||
|
|
||||||
|
* Add offer table column ordering.
|
||||||
|
- Player Name, Amount, Total Price, Peice Price and Ends At
|
||||||
|
|
||||||
|
* Add simple close button.
|
||||||
|
]]
|
||||||
|
|
||||||
Market = {}
|
Market = {}
|
||||||
|
|
||||||
local protocol = runinsandbox('marketprotocol.lua')
|
local protocol = runinsandbox('marketprotocol.lua')
|
||||||
|
@ -10,7 +41,7 @@ selectionTabBar = nil
|
||||||
|
|
||||||
marketOffersPanel = nil
|
marketOffersPanel = nil
|
||||||
browsePanel = nil
|
browsePanel = nil
|
||||||
searchPanel = nil
|
overviewPanel = nil
|
||||||
itemOffersPanel = nil
|
itemOffersPanel = nil
|
||||||
itemDetailsPanel = nil
|
itemDetailsPanel = nil
|
||||||
itemStatsPanel = nil
|
itemStatsPanel = nil
|
||||||
|
@ -26,6 +57,7 @@ balanceLabel = nil
|
||||||
totalPriceEdit = nil
|
totalPriceEdit = nil
|
||||||
piecePriceEdit = nil
|
piecePriceEdit = nil
|
||||||
amountEdit = nil
|
amountEdit = nil
|
||||||
|
searchEdit = nil
|
||||||
radioItemSet = nil
|
radioItemSet = nil
|
||||||
selectedItem = nil
|
selectedItem = nil
|
||||||
offerTypeList = nil
|
offerTypeList = nil
|
||||||
|
@ -59,7 +91,17 @@ local offerTableHeader = {
|
||||||
}
|
}
|
||||||
|
|
||||||
local function isItemValid(item, category)
|
local function isItemValid(item, category)
|
||||||
if item.marketData.category ~= category and category ~= MarketCategory[0] then
|
local searchFilter = searchEdit:getText():lower()
|
||||||
|
local useSearchFilter = 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
|
||||||
|
|
||||||
|
if item.marketData.category ~= category and category ~= MarketCategory.All then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -92,6 +134,12 @@ 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
|
||||||
|
local checkString = marketData.name:lower()
|
||||||
|
if not checkString:find(searchFilter) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -202,7 +250,7 @@ local function mergeOffer(offer)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function updateOffers(offers)
|
local function updateOffers(offers)
|
||||||
-- TODO: optimize offer updates later
|
-- TODO: optimize offer updates
|
||||||
selectedOffer[MarketAction.Buy] = nil
|
selectedOffer[MarketAction.Buy] = nil
|
||||||
selectedOffer[MarketAction.Sell] = nil
|
selectedOffer[MarketAction.Sell] = nil
|
||||||
|
|
||||||
|
@ -612,8 +660,8 @@ local function initInterface()
|
||||||
browsePanel = g_ui.loadUI('ui/marketoffers/browse.otui')
|
browsePanel = g_ui.loadUI('ui/marketoffers/browse.otui')
|
||||||
selectionTabBar:addTab(tr('Browse'), browsePanel)
|
selectionTabBar:addTab(tr('Browse'), browsePanel)
|
||||||
|
|
||||||
searchPanel = g_ui.loadUI('ui/marketoffers/search.otui')
|
overviewPanel = g_ui.loadUI('ui/marketoffers/overview.otui')
|
||||||
selectionTabBar:addTab(tr('Search'), searchPanel)
|
selectionTabBar:addTab(tr('Overview'), overviewPanel)
|
||||||
|
|
||||||
displaysTabBar = marketOffersPanel:getChildById('rightTabBar')
|
displaysTabBar = marketOffersPanel:getChildById('rightTabBar')
|
||||||
displaysTabBar:setContentWidget(marketOffersPanel:getChildById('rightTabContent'))
|
displaysTabBar:setContentWidget(marketOffersPanel:getChildById('rightTabContent'))
|
||||||
|
@ -675,10 +723,12 @@ local function initInterface()
|
||||||
filterButtons[MarketFilters.Vocation] = browsePanel:getChildById('filterVocation')
|
filterButtons[MarketFilters.Vocation] = browsePanel:getChildById('filterVocation')
|
||||||
filterButtons[MarketFilters.Level] = browsePanel:getChildById('filterLevel')
|
filterButtons[MarketFilters.Level] = browsePanel:getChildById('filterLevel')
|
||||||
filterButtons[MarketFilters.Depot] = browsePanel:getChildById('filterDepot')
|
filterButtons[MarketFilters.Depot] = browsePanel:getChildById('filterDepot')
|
||||||
|
filterButtons[MarketFilters.SearchAll] = browsePanel:getChildById('filterSearchAll')
|
||||||
|
|
||||||
|
searchEdit = browsePanel:getChildById('searchEdit')
|
||||||
categoryList = browsePanel:getChildById('categoryComboBox')
|
categoryList = browsePanel:getChildById('categoryComboBox')
|
||||||
subCategoryList = browsePanel:getChildById('subCategoryComboBox')
|
subCategoryList = browsePanel:getChildById('subCategoryComboBox')
|
||||||
slotFilterList = browsePanel:getChildById('typeComboBox')
|
slotFilterList = browsePanel:getChildById('slotComboBox')
|
||||||
|
|
||||||
slotFilterList:addOption(MarketSlotFilters[255])
|
slotFilterList:addOption(MarketSlotFilters[255])
|
||||||
slotFilterList:setEnabled(false)
|
slotFilterList:setEnabled(false)
|
||||||
|
@ -699,7 +749,7 @@ local function initInterface()
|
||||||
subCategoryList.onOptionChange = onChangeSubCategory
|
subCategoryList.onOptionChange = onChangeSubCategory
|
||||||
slotFilterList.onOptionChange = onChangeSlotFilter
|
slotFilterList.onOptionChange = onChangeSlotFilter
|
||||||
|
|
||||||
-- get tables
|
-- setup tables
|
||||||
buyOfferTable = itemOffersPanel:recursiveGetChildById('buyingTable')
|
buyOfferTable = itemOffersPanel:recursiveGetChildById('buyingTable')
|
||||||
sellOfferTable = itemOffersPanel:recursiveGetChildById('sellingTable')
|
sellOfferTable = itemOffersPanel:recursiveGetChildById('sellingTable')
|
||||||
detailsTable = itemDetailsPanel:recursiveGetChildById('detailsTable')
|
detailsTable = itemDetailsPanel:recursiveGetChildById('detailsTable')
|
||||||
|
@ -799,12 +849,12 @@ function Market.enableCreateOffer(enable)
|
||||||
nextAmountButton:setEnabled(enable)
|
nextAmountButton:setEnabled(enable)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Market.close(message)
|
function Market.close(notify)
|
||||||
local message = message or false
|
local notify = notify or true
|
||||||
marketWindow:hide()
|
marketWindow:hide()
|
||||||
marketWindow:unlock()
|
marketWindow:unlock()
|
||||||
Market.clearSelectedItem()
|
Market.clearSelectedItem()
|
||||||
if message then
|
if notify then
|
||||||
MarketProtocol.sendMarketLeave()
|
MarketProtocol.sendMarketLeave()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -835,7 +885,7 @@ end
|
||||||
|
|
||||||
function Market.refreshItemsWidget(selectItem)
|
function Market.refreshItemsWidget(selectItem)
|
||||||
local selectItem = selectItem or 0
|
local selectItem = selectItem or 0
|
||||||
itemsPanel = browsePanel:recursiveGetChildById('itemsPanel')
|
itemsPanel = marketOffersPanel:recursiveGetChildById('itemsPanel')
|
||||||
local layout = itemsPanel:getLayout()
|
local layout = itemsPanel:getLayout()
|
||||||
layout:disableUpdates()
|
layout:disableUpdates()
|
||||||
|
|
||||||
|
@ -878,6 +928,10 @@ function Market.refreshItemsWidget(selectItem)
|
||||||
layout:update()
|
layout:update()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
TODO: Optimize loading market items
|
||||||
|
* Preload items to their categories
|
||||||
|
]]
|
||||||
function Market.loadMarketItems(category)
|
function Market.loadMarketItems(category)
|
||||||
if table.empty(marketItems) then
|
if table.empty(marketItems) then
|
||||||
initMarketItems()
|
initMarketItems()
|
||||||
|
@ -1014,12 +1068,19 @@ function Market.onItemBoxChecked(widget)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- protocol callback functions
|
||||||
|
|
||||||
function Market.onMarketEnter(depotItems, offers, balance, vocation)
|
function Market.onMarketEnter(depotItems, offers, balance, vocation)
|
||||||
updateBalance(balance)
|
updateBalance(balance)
|
||||||
information.totalOffers = offers
|
information.totalOffers = offers
|
||||||
|
local player = g_game.getLocalPlayer()
|
||||||
|
if player then
|
||||||
|
information.player = player
|
||||||
|
end
|
||||||
if vocation < 0 then
|
if vocation < 0 then
|
||||||
local player = g_game.getLocalPlayer()
|
if player then
|
||||||
if player then information.vocation = player:getVocation() end
|
information.vocation = player:getVocation()
|
||||||
|
end
|
||||||
else
|
else
|
||||||
-- vocation must be compatible with < 950
|
-- vocation must be compatible with < 950
|
||||||
information.vocation = vocation
|
information.vocation = vocation
|
||||||
|
|
|
@ -77,7 +77,7 @@ Panel
|
||||||
@onCheckChange: Market.updateCurrentItems()
|
@onCheckChange: Market.updateCurrentItems()
|
||||||
|
|
||||||
MarketComboBox
|
MarketComboBox
|
||||||
id: typeComboBox
|
id: slotComboBox
|
||||||
anchors.top: prev.top
|
anchors.top: prev.top
|
||||||
anchors.left: prev.right
|
anchors.left: prev.right
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
|
@ -101,13 +101,14 @@ Panel
|
||||||
@onCheckChange: Market.updateCurrentItems()
|
@onCheckChange: Market.updateCurrentItems()
|
||||||
|
|
||||||
Panel
|
Panel
|
||||||
|
id: itemsContainer
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
margin-top: 10
|
margin-top: 10
|
||||||
margin-left: 3
|
margin-left: 3
|
||||||
margin-bottom: 5
|
margin-bottom: 30
|
||||||
margin-right: 3
|
margin-right: 3
|
||||||
|
|
||||||
VerticalScrollBar
|
VerticalScrollBar
|
||||||
|
@ -129,4 +130,32 @@ Panel
|
||||||
type: grid
|
type: grid
|
||||||
cell-size: 36 36
|
cell-size: 36 36
|
||||||
flow: true
|
flow: true
|
||||||
auto-spacing: true
|
auto-spacing: true
|
||||||
|
|
||||||
|
Label
|
||||||
|
!text: tr('Find:')
|
||||||
|
anchors.top: prev.bottom
|
||||||
|
anchors.left: prev.left
|
||||||
|
margin-top: 9
|
||||||
|
width: 30
|
||||||
|
font: verdana-11px-rounded
|
||||||
|
text-offset: 0 2
|
||||||
|
|
||||||
|
TextEdit
|
||||||
|
id: searchEdit
|
||||||
|
anchors.verticalCenter: prev.verticalCenter
|
||||||
|
anchors.left: prev.right
|
||||||
|
margin-left: 3
|
||||||
|
width: 113
|
||||||
|
@onTextChange: Market.updateCurrentItems()
|
||||||
|
|
||||||
|
MarketButtonBox
|
||||||
|
id: filterSearchAll
|
||||||
|
checked: false
|
||||||
|
!text: tr('All')
|
||||||
|
!tooltip: tr('Search all items')
|
||||||
|
anchors.verticalCenter: prev.verticalCenter
|
||||||
|
anchors.left: prev.right
|
||||||
|
anchors.right: itemsContainer.right
|
||||||
|
margin-left: 3
|
||||||
|
@onCheckChange: Market.updateCurrentItems()
|
||||||
|
|
|
@ -2,11 +2,15 @@ Panel
|
||||||
background-color: #22283399
|
background-color: #22283399
|
||||||
margin: 1
|
margin: 1
|
||||||
|
|
||||||
TextEdit
|
Label
|
||||||
id: searchEdit
|
!text: tr('Reserved for more functionality later.')
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
margin-top: 10
|
margin-top: 6
|
||||||
margin-left: 6
|
margin-left: 6
|
||||||
margin-right: 6
|
margin-right: 6
|
||||||
|
font: verdana-11px-rounded
|
||||||
|
text-offset: 0 2
|
||||||
|
height: 50
|
||||||
|
text-wrap: true
|
|
@ -156,7 +156,8 @@ MarketSlotFilters = {
|
||||||
MarketFilters = {
|
MarketFilters = {
|
||||||
Vocation = 1,
|
Vocation = 1,
|
||||||
Level = 2,
|
Level = 2,
|
||||||
Depot = 3
|
Depot = 3,
|
||||||
|
SearchAll = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
MarketFilters.First = MarketFilters.vocation
|
MarketFilters.First = MarketFilters.vocation
|
||||||
|
|
Loading…
Reference in New Issue