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 = {}
|
||||
|
||||
local protocol = runinsandbox('marketprotocol.lua')
|
||||
|
@ -10,7 +41,7 @@ selectionTabBar = nil
|
|||
|
||||
marketOffersPanel = nil
|
||||
browsePanel = nil
|
||||
searchPanel = nil
|
||||
overviewPanel = nil
|
||||
itemOffersPanel = nil
|
||||
itemDetailsPanel = nil
|
||||
itemStatsPanel = nil
|
||||
|
@ -26,6 +57,7 @@ balanceLabel = nil
|
|||
totalPriceEdit = nil
|
||||
piecePriceEdit = nil
|
||||
amountEdit = nil
|
||||
searchEdit = nil
|
||||
radioItemSet = nil
|
||||
selectedItem = nil
|
||||
offerTypeList = nil
|
||||
|
@ -59,7 +91,17 @@ local offerTableHeader = {
|
|||
}
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -92,6 +134,12 @@ local function isItemValid(item, category)
|
|||
if filterDepot and Market.depotContains(item.ptr:getId()) <= 0 then
|
||||
return false
|
||||
end
|
||||
if useSearchFilter then
|
||||
local checkString = marketData.name:lower()
|
||||
if not checkString:find(searchFilter) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -202,7 +250,7 @@ local function mergeOffer(offer)
|
|||
end
|
||||
|
||||
local function updateOffers(offers)
|
||||
-- TODO: optimize offer updates later
|
||||
-- TODO: optimize offer updates
|
||||
selectedOffer[MarketAction.Buy] = nil
|
||||
selectedOffer[MarketAction.Sell] = nil
|
||||
|
||||
|
@ -612,8 +660,8 @@ local function initInterface()
|
|||
browsePanel = g_ui.loadUI('ui/marketoffers/browse.otui')
|
||||
selectionTabBar:addTab(tr('Browse'), browsePanel)
|
||||
|
||||
searchPanel = g_ui.loadUI('ui/marketoffers/search.otui')
|
||||
selectionTabBar:addTab(tr('Search'), searchPanel)
|
||||
overviewPanel = g_ui.loadUI('ui/marketoffers/overview.otui')
|
||||
selectionTabBar:addTab(tr('Overview'), overviewPanel)
|
||||
|
||||
displaysTabBar = marketOffersPanel:getChildById('rightTabBar')
|
||||
displaysTabBar:setContentWidget(marketOffersPanel:getChildById('rightTabContent'))
|
||||
|
@ -675,10 +723,12 @@ local function initInterface()
|
|||
filterButtons[MarketFilters.Vocation] = browsePanel:getChildById('filterVocation')
|
||||
filterButtons[MarketFilters.Level] = browsePanel:getChildById('filterLevel')
|
||||
filterButtons[MarketFilters.Depot] = browsePanel:getChildById('filterDepot')
|
||||
filterButtons[MarketFilters.SearchAll] = browsePanel:getChildById('filterSearchAll')
|
||||
|
||||
searchEdit = browsePanel:getChildById('searchEdit')
|
||||
categoryList = browsePanel:getChildById('categoryComboBox')
|
||||
subCategoryList = browsePanel:getChildById('subCategoryComboBox')
|
||||
slotFilterList = browsePanel:getChildById('typeComboBox')
|
||||
slotFilterList = browsePanel:getChildById('slotComboBox')
|
||||
|
||||
slotFilterList:addOption(MarketSlotFilters[255])
|
||||
slotFilterList:setEnabled(false)
|
||||
|
@ -699,7 +749,7 @@ local function initInterface()
|
|||
subCategoryList.onOptionChange = onChangeSubCategory
|
||||
slotFilterList.onOptionChange = onChangeSlotFilter
|
||||
|
||||
-- get tables
|
||||
-- setup tables
|
||||
buyOfferTable = itemOffersPanel:recursiveGetChildById('buyingTable')
|
||||
sellOfferTable = itemOffersPanel:recursiveGetChildById('sellingTable')
|
||||
detailsTable = itemDetailsPanel:recursiveGetChildById('detailsTable')
|
||||
|
@ -799,12 +849,12 @@ function Market.enableCreateOffer(enable)
|
|||
nextAmountButton:setEnabled(enable)
|
||||
end
|
||||
|
||||
function Market.close(message)
|
||||
local message = message or false
|
||||
function Market.close(notify)
|
||||
local notify = notify or true
|
||||
marketWindow:hide()
|
||||
marketWindow:unlock()
|
||||
Market.clearSelectedItem()
|
||||
if message then
|
||||
if notify then
|
||||
MarketProtocol.sendMarketLeave()
|
||||
end
|
||||
end
|
||||
|
@ -835,7 +885,7 @@ end
|
|||
|
||||
function Market.refreshItemsWidget(selectItem)
|
||||
local selectItem = selectItem or 0
|
||||
itemsPanel = browsePanel:recursiveGetChildById('itemsPanel')
|
||||
itemsPanel = marketOffersPanel:recursiveGetChildById('itemsPanel')
|
||||
local layout = itemsPanel:getLayout()
|
||||
layout:disableUpdates()
|
||||
|
||||
|
@ -878,6 +928,10 @@ function Market.refreshItemsWidget(selectItem)
|
|||
layout:update()
|
||||
end
|
||||
|
||||
--[[
|
||||
TODO: Optimize loading market items
|
||||
* Preload items to their categories
|
||||
]]
|
||||
function Market.loadMarketItems(category)
|
||||
if table.empty(marketItems) then
|
||||
initMarketItems()
|
||||
|
@ -1014,12 +1068,19 @@ function Market.onItemBoxChecked(widget)
|
|||
end
|
||||
end
|
||||
|
||||
-- protocol callback functions
|
||||
|
||||
function Market.onMarketEnter(depotItems, offers, balance, vocation)
|
||||
updateBalance(balance)
|
||||
information.totalOffers = offers
|
||||
local player = g_game.getLocalPlayer()
|
||||
if player then
|
||||
information.player = player
|
||||
end
|
||||
if vocation < 0 then
|
||||
local player = g_game.getLocalPlayer()
|
||||
if player then information.vocation = player:getVocation() end
|
||||
if player then
|
||||
information.vocation = player:getVocation()
|
||||
end
|
||||
else
|
||||
-- vocation must be compatible with < 950
|
||||
information.vocation = vocation
|
||||
|
|
|
@ -77,7 +77,7 @@ Panel
|
|||
@onCheckChange: Market.updateCurrentItems()
|
||||
|
||||
MarketComboBox
|
||||
id: typeComboBox
|
||||
id: slotComboBox
|
||||
anchors.top: prev.top
|
||||
anchors.left: prev.right
|
||||
anchors.right: parent.right
|
||||
|
@ -101,13 +101,14 @@ Panel
|
|||
@onCheckChange: Market.updateCurrentItems()
|
||||
|
||||
Panel
|
||||
id: itemsContainer
|
||||
anchors.top: prev.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
margin-top: 10
|
||||
margin-left: 3
|
||||
margin-bottom: 5
|
||||
margin-bottom: 30
|
||||
margin-right: 3
|
||||
|
||||
VerticalScrollBar
|
||||
|
@ -129,4 +130,32 @@ Panel
|
|||
type: grid
|
||||
cell-size: 36 36
|
||||
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
|
||||
margin: 1
|
||||
|
||||
TextEdit
|
||||
id: searchEdit
|
||||
Label
|
||||
!text: tr('Reserved for more functionality later.')
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
margin-top: 10
|
||||
margin-top: 6
|
||||
margin-left: 6
|
||||
margin-right: 6
|
||||
font: verdana-11px-rounded
|
||||
text-offset: 0 2
|
||||
height: 50
|
||||
text-wrap: true
|
|
@ -156,7 +156,8 @@ MarketSlotFilters = {
|
|||
MarketFilters = {
|
||||
Vocation = 1,
|
||||
Level = 2,
|
||||
Depot = 3
|
||||
Depot = 3,
|
||||
SearchAll = 4
|
||||
}
|
||||
|
||||
MarketFilters.First = MarketFilters.vocation
|
||||
|
|
Loading…
Reference in New Issue