mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 20:14:54 +02:00
More work on Market functionality and UI
* Now loads all market items. * Can filter market items. * Will load market offers on items. * Edited some UI images.
This commit is contained in:
@@ -3,6 +3,7 @@ Market = {}
|
||||
g_ui.importStyle('market.otui')
|
||||
g_ui.importStyle('ui/general/markettabs.otui')
|
||||
g_ui.importStyle('ui/general/marketbuttons.otui')
|
||||
g_ui.importStyle('ui/general/marketcombobox.otui')
|
||||
|
||||
local marketWindow
|
||||
local mainTabBar
|
||||
@@ -23,25 +24,62 @@ local currentOffersPanel
|
||||
local offerHistoryPanel
|
||||
|
||||
local marketOffers = {}
|
||||
local marketItems = {}
|
||||
local depot = {}
|
||||
local information ={}
|
||||
local selectedItem
|
||||
local nameLabel
|
||||
|
||||
local currentItems = {}
|
||||
local itemsPanel
|
||||
local radioItems
|
||||
local radioItemSet
|
||||
local filterBox
|
||||
|
||||
local function clearSelectedItem()
|
||||
if selectedItem then
|
||||
nameLabel:clearText()
|
||||
radioItems:selectWidget(nil)
|
||||
selectedItem.setItem(nil)
|
||||
local function getMarketCategoryName(category)
|
||||
if table.hasKey(MarketCategoryStrings, category) then
|
||||
return MarketCategoryStrings[category]
|
||||
end
|
||||
end
|
||||
|
||||
local function loadMarketItems()
|
||||
itemsPanel = marketWindow:recursiveGetChildById('itemsPanel')
|
||||
local function getMarketCategoryId(name)
|
||||
local id = table.find(MarketCategoryStrings, name)
|
||||
if id then
|
||||
return id
|
||||
end
|
||||
end
|
||||
|
||||
local function clearSelectedItem()
|
||||
if selectedItem and selectedItem.item.ptr then
|
||||
Market.updateOffers({})
|
||||
radioItemSet:selectWidget(nil)
|
||||
nameLabel:clearText()
|
||||
selectedItem:setItem(nil)
|
||||
selectedItem.item = {}
|
||||
end
|
||||
end
|
||||
|
||||
local function initMarketItems()
|
||||
-- populate all market items
|
||||
marketItems = {}
|
||||
local types = g_things.findThingTypeByAttr(ThingAttrMarket)
|
||||
for k,t in pairs(types) do
|
||||
local newItem = Item.create(t:getId())
|
||||
if newItem then
|
||||
local item = {
|
||||
ptr = newItem,
|
||||
marketData = t:getMarketData()
|
||||
}
|
||||
table.insert(marketItems, item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function updateItemsWidget()
|
||||
if table.empty(currentItems) then
|
||||
return
|
||||
end
|
||||
|
||||
itemsPanel = marketWindow:recursiveGetChildById('itemsPanel')
|
||||
local layout = itemsPanel:getLayout()
|
||||
layout:disableUpdates()
|
||||
|
||||
@@ -53,8 +91,15 @@ local function loadMarketItems()
|
||||
end
|
||||
radioItemSet = UIRadioGroup.create()
|
||||
|
||||
-- TODO: populate with dat items
|
||||
|
||||
for _, item in pairs(currentItems) do
|
||||
local itemBox = g_ui.createWidget('MarketItemBox', itemsPanel)
|
||||
local itemWidget = itemBox:getChildById('item')
|
||||
|
||||
itemBox.item = item
|
||||
itemWidget:setItem(item.ptr)
|
||||
|
||||
radioItemSet:addWidget(itemBox)
|
||||
end
|
||||
|
||||
layout:enableUpdates()
|
||||
layout:update()
|
||||
@@ -84,7 +129,7 @@ function Market.init()
|
||||
marketWindow = g_ui.createWidget('MarketWindow', rootWidget)
|
||||
marketWindow:hide()
|
||||
|
||||
nameLabel = marketWindow:recursiveGetChildById('nameLabel')
|
||||
initMarketItems()
|
||||
|
||||
-- TODO: clean this up into functions
|
||||
-- setup main tabs
|
||||
@@ -128,6 +173,20 @@ function Market.init()
|
||||
|
||||
offerHistoryPanel = g_ui.loadUI('ui/myoffers/offerhistory.otui')
|
||||
offersTabBar:addTab(tr('Offer History'), offerHistoryPanel)
|
||||
|
||||
nameLabel = marketWindow:recursiveGetChildById('nameLabel')
|
||||
selectedItem = marketWindow:recursiveGetChildById('selectedItem')
|
||||
selectedItem.item = {}
|
||||
|
||||
filterBox = browsePanel:getChildById('filterComboBox')
|
||||
for i = MarketCategory.First, MarketCategory.Last do
|
||||
filterBox:addOption(getMarketCategoryName(i))
|
||||
end
|
||||
filterBox:setCurrentOption(getMarketCategoryName(MarketCategory.First))
|
||||
|
||||
filterBox.onOptionChange = function(combobox, option)
|
||||
Market.loadMarketItems(getMarketCategoryId(option))
|
||||
end
|
||||
end
|
||||
|
||||
function Market.terminate()
|
||||
@@ -150,66 +209,101 @@ function Market.terminate()
|
||||
currentOffersPanel = nil
|
||||
offerHistoryPanel = nil
|
||||
marketOffers = {}
|
||||
marketItems = {}
|
||||
depotItems = {}
|
||||
information = {}
|
||||
currentItems = {}
|
||||
itemsPanel = nil
|
||||
nameLabel = nil
|
||||
radioItems = nil
|
||||
radioItemSet = nil
|
||||
selectedItem = nil
|
||||
filterBox = nil
|
||||
|
||||
Market = nil
|
||||
end
|
||||
|
||||
function Market.loadMarketItems(_category)
|
||||
if table.empty(marketItems) then
|
||||
initMarketItems()
|
||||
end
|
||||
|
||||
currentItems = {}
|
||||
for _, item in pairs(marketItems) do
|
||||
-- filter items here
|
||||
local category = item.marketData.category
|
||||
if category == _category or _category == MarketCategory[0] then
|
||||
table.insert(currentItems, item)
|
||||
end
|
||||
end
|
||||
|
||||
updateItemsWidget()
|
||||
end
|
||||
|
||||
function Market.updateOffers(offers)
|
||||
marketOffers[MarketAction.Buy] = {}
|
||||
marketOffers[MarketAction.Sell] = {}
|
||||
|
||||
local buyOfferList = marketWindow:recursiveGetChildById('buyingList')
|
||||
buyOfferList:destroyChildren()
|
||||
|
||||
local sellOfferList = marketWindow:recursiveGetChildById('sellingList')
|
||||
sellOfferList:destroyChildren()
|
||||
|
||||
for k, offer in pairs(offers) do
|
||||
if offer and offer:getAction() == MarketAction.Buy then
|
||||
local label = g_ui.createWidget('OfferListLabel', buyOfferList)
|
||||
label:setText(offer:getPlayer()..' '..offer:getAmount()..' '..(offer:getPrice()*offer:getAmount())..' '..offer:getPrice()..' '..offer:getTimeStamp())
|
||||
table.insert(marketOffers[MarketAction.Buy], offer)
|
||||
else
|
||||
local label = g_ui.createWidget('OfferListLabel', sellOfferList)
|
||||
label:setText(offer:getPlayer()..' '..offer:getAmount()..' '..(offer:getPrice()*offer:getAmount())..' '..offer:getPrice()..' '..offer:getTimeStamp())
|
||||
table.insert(marketOffers[MarketAction.Sell], offer)
|
||||
end
|
||||
end
|
||||
|
||||
for _, offers in pairs(marketOffers) do
|
||||
for _, offer in pairs(offers) do
|
||||
print(' counter: '..offer:getCounter()..' | timestamp: '..offer:getTimeStamp()..' | item: '..offer:getItem():getId()..' | action: '..offer:getAction()..' | amount: '..offer:getAmount()..' | price: '..offer:getPrice()..' | player: '..offer:getPlayer()..' | state: '..offer:getState())
|
||||
end
|
||||
end
|
||||
-- TODO: refresh all widget windows
|
||||
end
|
||||
|
||||
function Market.updateDetails(itemId, descriptions, purchaseStats, saleStats)
|
||||
-- TODO: refresh all widget windows
|
||||
if not selectedItem then
|
||||
return
|
||||
end
|
||||
selectedItem.item.details = {
|
||||
serverItemId = itemId,
|
||||
descriptions = descriptions,
|
||||
purchaseStats = purchaseStats,
|
||||
saleStats = saleStats
|
||||
}
|
||||
|
||||
-- TODO: refresh all widget windows
|
||||
end
|
||||
|
||||
function Market.updateSelectedItem(newItem)
|
||||
local itemDisplay = marketWindow:recursiveGetChildById('selectedItem')
|
||||
local itemName = marketWindow:recursiveGetChildById('nameLabel')
|
||||
selectedItem = newItem
|
||||
if not table.empty(selectedItem) then
|
||||
if selectedItem.ptr then
|
||||
itemDisplay:setItem(selectedItem.ptr)
|
||||
itemName:setText(tr(selectedItem.name))
|
||||
MarketProtocol.sendMarketBrowse(selectedItem.ptr:getId()) -- send sprite id browsed
|
||||
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)
|
||||
MarketProtocol.sendMarketBrowse(selectedItem.item.ptr:getId()) -- send sprite id browsed
|
||||
end
|
||||
else
|
||||
itemDisplay:setItem(nil)
|
||||
itemName:setText(tr('No item selected.'))
|
||||
selectedItem:setItem(nil)
|
||||
nameLabel:setText(tr('No item selected.'))
|
||||
end
|
||||
end
|
||||
|
||||
function Market.onMarketEnter(depotItems, offers, balance)
|
||||
-- TODO: populate market?
|
||||
if marketWindow:isVisible() then
|
||||
return
|
||||
end
|
||||
marketWindow:lock()
|
||||
marketOffers[MarketAction.Buy] = {}
|
||||
marketOffers[MarketAction.Sell] = {}
|
||||
|
||||
information.balance = balance
|
||||
information.totalOffers = offers
|
||||
|
||||
loadMarketItems()
|
||||
if table.empty(currentItems) then
|
||||
Market.loadMarketItems(MarketCategory.First)
|
||||
end
|
||||
loadDepotItems(depotItems)
|
||||
|
||||
-- TODO: if you are already viewing an item on market enter it must recheck the current item
|
||||
@@ -217,7 +311,6 @@ function Market.onMarketEnter(depotItems, offers, balance)
|
||||
selectedItem:setChecked(false)
|
||||
selectedItem:setChecked(true)
|
||||
end
|
||||
--MarketProtocol.sendMarketBrowse(645)
|
||||
marketWindow:show()
|
||||
end
|
||||
|
||||
|
@@ -1,10 +1,10 @@
|
||||
MarketWindow < MainWindow
|
||||
id: marketWindow
|
||||
!text: tr('Market')
|
||||
size: 680 460
|
||||
size: 700 510
|
||||
|
||||
@onEnter: self:hide()
|
||||
@onEscape: self:hide()
|
||||
@onEnter: self:hide() self:unlock()
|
||||
@onEscape: self:hide() self:unlock()
|
||||
|
||||
// Main Panel Window
|
||||
|
||||
|
@@ -7,7 +7,6 @@ local protocol
|
||||
local function send(msg)
|
||||
if protocol then
|
||||
print(msg:getMessageSize())
|
||||
--protocol:safeSend(msg)
|
||||
protocol:send(msg)
|
||||
end
|
||||
end
|
||||
@@ -53,7 +52,7 @@ local function parseMarketEnter(msg)
|
||||
table.insert(depotItems, {itemId, itemCount})
|
||||
end
|
||||
|
||||
Market.onMarketEnter(depotItems, offers, balance)
|
||||
signalcall(Market.onMarketEnter, depotItems, offers, balance)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -81,7 +80,7 @@ local function parseMarketDetail(msg)
|
||||
local highestPrice = msg:getU32() -- highest price
|
||||
local lowestPrice = msg: getU32() -- lowest price
|
||||
|
||||
table.insert(purchaseStats, {transaction, totalPrice, highestPrice, lowestPrice})
|
||||
table.insert(purchaseStats, {transactions, totalPrice, highestPrice, lowestPrice})
|
||||
end
|
||||
|
||||
local saleStats = {}
|
||||
@@ -91,10 +90,10 @@ local function parseMarketDetail(msg)
|
||||
local highestPrice = msg:getU32() -- highest price
|
||||
local lowestPrice = msg: getU32() -- lowest price
|
||||
|
||||
table.insert(saleStats, {transaction, totalPrice, highestPrice, lowestPrice})
|
||||
table.insert(saleStats, {transactions, totalPrice, highestPrice, lowestPrice})
|
||||
end
|
||||
|
||||
Market.onMarketDetail(itemId, descriptions, purchaseStats, saleStats)
|
||||
signalcall(Market.onMarketDetail, itemId, descriptions, purchaseStats, saleStats)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -112,7 +111,7 @@ local function parseMarketBrowse(msg)
|
||||
table.insert(offers, readMarketOffer(msg, MarketAction.Sell, var))
|
||||
end
|
||||
|
||||
Market.onMarketBrowse(offers)
|
||||
signalcall(Market.onMarketBrowse, offers)
|
||||
return true
|
||||
end
|
||||
|
||||
|
@@ -1,10 +1,10 @@
|
||||
MarketButtonBox < UICheckBox
|
||||
font: verdana-11px-antialised
|
||||
color: #ffffffff
|
||||
color: #f55e5ecc
|
||||
size: 106 22
|
||||
text-offset: 0 0
|
||||
text-align: center
|
||||
image-source: /images/tabbutton.png
|
||||
image-source: /images/tabbutton_rounded.png
|
||||
image-clip: 0 0 20 20
|
||||
image-border: 2
|
||||
|
||||
|
45
modules/game_market/ui/general/marketcombobox.otui
Normal file
45
modules/game_market/ui/general/marketcombobox.otui
Normal file
@@ -0,0 +1,45 @@
|
||||
MarketComboBoxPopupMenuButton < UIButton
|
||||
height: 18
|
||||
font: verdana-11px-antialised
|
||||
text-align: left
|
||||
text-offset: 2 0
|
||||
color: #aaaaaa
|
||||
background-color: alpha
|
||||
|
||||
$hover !disabled:
|
||||
color: #ffffff
|
||||
background-color: #ffffff44
|
||||
|
||||
$disabled:
|
||||
color: #555555
|
||||
|
||||
MarketComboBoxPopupMenuSeparator < UIWidget
|
||||
image-source: /images/combobox_rounded.png
|
||||
image-repeated: true
|
||||
image-clip: 1 59 89 1
|
||||
height: 1
|
||||
phantom: true
|
||||
|
||||
MarketComboBoxPopupMenu < UIPopupMenu
|
||||
image-source: /images/combobox_rounded.png
|
||||
image-clip: 0 60 89 20
|
||||
image-border: 1
|
||||
image-border-top: 0
|
||||
padding: 1
|
||||
|
||||
MarketComboBox < UIComboBox
|
||||
font: verdana-11px-antialised
|
||||
color: #aaaaaa
|
||||
size: 86 20
|
||||
text-offset: 3 0
|
||||
text-align: left
|
||||
image-source: /images/combobox_rounded.png
|
||||
image-border: 1
|
||||
image-border-right: 17
|
||||
image-clip: 0 0 89 20
|
||||
|
||||
$hover !disabled:
|
||||
image-clip: 0 20 89 20
|
||||
|
||||
$on:
|
||||
image-clip: 0 40 89 20
|
@@ -3,7 +3,7 @@ MarketTabBar < UITabBar
|
||||
MarketTabBarPanel < Panel
|
||||
MarketTabBarButton < UIButton
|
||||
size: 20 25
|
||||
image-source: /images/tabbutton.png
|
||||
image-source: /images/tabbutton_square.png
|
||||
image-clip: 0 0 20 20
|
||||
image-border: 2
|
||||
icon-color: white
|
||||
|
@@ -33,17 +33,22 @@ Panel
|
||||
border-width: 1
|
||||
border-color: #000000
|
||||
|
||||
Item
|
||||
UIItem
|
||||
id: selectedItem
|
||||
phantom: true
|
||||
size: 34 34
|
||||
padding: 1
|
||||
font: verdana-11px-rounded
|
||||
border-color: white
|
||||
anchors.top: rightTabBar.bottom
|
||||
anchors.left: rightTabContent.left
|
||||
margin-top: 3
|
||||
margin-left: 3
|
||||
margin-top: 6
|
||||
margin-left: 6
|
||||
|
||||
Label
|
||||
id: nameLabel
|
||||
!text: tr('No item selected.')
|
||||
anchors.top: prev.top
|
||||
anchors.left: prev.right
|
||||
anchors.right: parent.right
|
||||
margin-left: 5
|
||||
|
@@ -11,7 +11,7 @@ MarketItemBox < UICheckBox
|
||||
phantom: true
|
||||
anchors.top: parent.top
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
margin-top: 5
|
||||
margin: 1
|
||||
|
||||
$checked:
|
||||
border-color: #ffffff
|
||||
@@ -27,7 +27,7 @@ Panel
|
||||
background-color: #22283399
|
||||
margin: 1
|
||||
|
||||
ComboBox
|
||||
MarketComboBox
|
||||
id: filterComboBox
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
@@ -36,7 +36,7 @@ Panel
|
||||
margin-right: 3
|
||||
margin-left: 3
|
||||
|
||||
ComboBox
|
||||
MarketComboBox
|
||||
id: weaponComboBox
|
||||
anchors.top: prev.bottom
|
||||
anchors.left: parent.left
|
||||
@@ -72,7 +72,7 @@ Panel
|
||||
height: 20
|
||||
//@onClick: Market.filterMatchVocation()
|
||||
|
||||
ComboBox
|
||||
MarketComboBox
|
||||
id: typeComboBox
|
||||
anchors.top: prev.top
|
||||
anchors.left: prev.right
|
||||
@@ -88,7 +88,7 @@ Panel
|
||||
anchors.top: prev.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
margin-top: 3
|
||||
margin-top: 6
|
||||
margin-right: 3
|
||||
margin-left: 3
|
||||
//@onClick: Market.setDisplayDepot()
|
||||
@@ -100,7 +100,7 @@ Panel
|
||||
anchors.bottom: parent.bottom
|
||||
margin-top: 10
|
||||
margin-left: 3
|
||||
margin-bottom: 10
|
||||
margin-bottom: 5
|
||||
margin-right: 3
|
||||
|
||||
VerticalScrollBar
|
||||
@@ -108,7 +108,7 @@ Panel
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.right: parent.right
|
||||
step: 16
|
||||
step: 28
|
||||
pixels-scroll: true
|
||||
|
||||
ScrollablePanel
|
||||
@@ -120,6 +120,6 @@ Panel
|
||||
vertical-scrollbar: itemsPanelListScrollBar
|
||||
layout:
|
||||
type: grid
|
||||
cell-size: 34 34
|
||||
cell-size: 36 36
|
||||
flow: true
|
||||
auto-spacing: true
|
@@ -1,10 +1,87 @@
|
||||
OfferListLabel < Label
|
||||
font: verdana-11px-monochrome
|
||||
background-color: alpha
|
||||
text-offset: 2 0
|
||||
focusable: true
|
||||
color: #cccccc
|
||||
|
||||
$focus:
|
||||
background-color: #294f6d
|
||||
color: #ffffff
|
||||
|
||||
Panel
|
||||
background-color: #22283399
|
||||
margin: 1
|
||||
|
||||
Button
|
||||
!text: tr('Buy Now')
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: next.bottom
|
||||
margin-right: 6
|
||||
width: 80
|
||||
//@onClick: g_game.closeNpcTrade()
|
||||
|
||||
Label
|
||||
!text: tr('Item Offers')
|
||||
!text: tr('Sell Offers')
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
margin-top: 45
|
||||
margin-left: 3
|
||||
margin-top: 44
|
||||
margin-left: 6
|
||||
|
||||
TextList
|
||||
id: sellingList
|
||||
anchors.top: prev.bottom
|
||||
anchors.left: prev.left
|
||||
anchors.right: parent.right
|
||||
height: 120
|
||||
margin-top: 5
|
||||
margin-bottom: 5
|
||||
margin-right: 6
|
||||
padding: 1
|
||||
focusable: false
|
||||
vertical-scrollbar: sellingListScrollBar
|
||||
|
||||
VerticalScrollBar
|
||||
id: sellingListScrollBar
|
||||
anchors.top: prev.top
|
||||
anchors.bottom: prev.bottom
|
||||
anchors.right: prev.right
|
||||
step: 28
|
||||
pixels-scroll: true
|
||||
|
||||
Button
|
||||
!text: tr('Sell Now')
|
||||
anchors.right: parent.right
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 5
|
||||
margin-right: 6
|
||||
width: 80
|
||||
//@onClick: g_game.closeNpcTrade()
|
||||
|
||||
Label
|
||||
!text: tr('Buy Offers')
|
||||
anchors.top: prev.top
|
||||
anchors.left: parent.left
|
||||
margin-top: 9
|
||||
margin-left: 6
|
||||
|
||||
TextList
|
||||
id: buyingList
|
||||
anchors.top: prev.bottom
|
||||
anchors.left: prev.left
|
||||
anchors.right: parent.right
|
||||
margin-top: 5
|
||||
margin-bottom: 5
|
||||
margin-right: 6
|
||||
height: 120
|
||||
padding: 1
|
||||
focusable: false
|
||||
vertical-scrollbar: buyingListScrollBar
|
||||
|
||||
VerticalScrollBar
|
||||
id: buyingListScrollBar
|
||||
anchors.top: prev.top
|
||||
anchors.bottom: prev.bottom
|
||||
anchors.right: prev.right
|
||||
step: 28
|
||||
pixels-scroll: true
|
Reference in New Issue
Block a user