More market work (getting close to completion)

* Can now create market offers with fully working UI.
* All filtering is now completed (just need to finish word searching).
* Added some user friendly features to offer selections and item displays (show amount in depot).
* Some more UI ascetics.
* Some other minor market fixes.

TODO:
* Finishing applying changes for latest module updates by edubart.
* Finish buying/selling existing offers.
* Word searching items.
* Offer management.
* Full cipsoft tibia testing.
This commit is contained in:
BeniS 2012-07-27 15:53:42 +12:00
parent 2b2f5b33ff
commit 7aba117cf2
14 changed files with 851 additions and 461 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,9 @@
Module Module
name: game_market name: game_market
description: Manage the Players Market system description: Global item market system
author: BeniS author: BeniS
website: www.otclient.info website: www.otclient.info
sandboxed: true
@onLoad: | scripts: [marketoffer.lua, marketprotocol.lua, market.lua]
dofile 'marketoffer' @onLoad: init()
dofile 'marketprotocol' @onUnload: terminate()
dofile 'market'
MarketProtocol.init()
Market.init()
@onUnload: |
MarketProtocol.terminate()
Market.terminate()

View File

@ -3,8 +3,8 @@ MarketWindow < MainWindow
!text: tr('Market') !text: tr('Market')
size: 700 510 size: 700 510
@onEnter: self:hide() self:unlock() @onEnter: self:hide() self:unlock() Market.clearSelectedItem()
@onEscape: self:hide() self:unlock() @onEscape: self:hide() self:unlock() Market.clearSelectedItem()
// Main Panel Window // Main Panel Window
@ -24,3 +24,11 @@ MarketWindow < MainWindow
padding: 3 padding: 3
border-width: 1 border-width: 1
border-color: #000000 border-color: #000000
Label
id: balanceLabel
!text: tr('Balance: 10000')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: parent.top
anchors.right: parent.right

View File

@ -46,15 +46,15 @@ MarketOffer.new = function(offerId, action, item, amount, price, playerName, sta
return offer return offer
end end
function MarketOffer:isEqual(offer) function MarketOffer:isEqual(id)
return self.offer[OFFER_TIMESTAMP] == offer[OFFER_TIMESTAMP] and self.offer[OFFER_COUNTER] == offer[OFFER_COUNTER] return self.id[OFFER_TIMESTAMP] == id[OFFER_TIMESTAMP] and self.id[OFFER_COUNTER] == id[OFFER_COUNTER]
end end
function MarketOffer:isLessThan(offer) function MarketOffer:isLessThan(id)
return self.offer[OFFER_TIMESTAMP] <= offer[OFFER_TIMESTAMP] and self.offer[OFFER_COUNTER] < offer[OFFER_COUNTER] return self.id[OFFER_TIMESTAMP] <= id[OFFER_TIMESTAMP] and self.id[OFFER_COUNTER] < id[OFFER_COUNTER]
end end
function MarketOffer:isNull(offer) function MarketOffer:isNull()
return table.empty(self.id) return table.empty(self.id)
end end

View File

@ -44,8 +44,8 @@ local function parseMarketEnter(msg)
local offers = msg:getU8() local offers = msg:getU8()
local depotItems = {} local depotItems = {}
local depotCount = (msg:getU16() - 1) local depotCount = msg:getU16()
for i = 0, depotCount do for i = 1, depotCount do
local itemId = msg:getU16() -- item id local itemId = msg:getU16() -- item id
local itemCount = msg:getU16() -- item count local itemCount = msg:getU16() -- item count
@ -103,13 +103,13 @@ local function parseMarketBrowse(msg)
local var = msg:getU16() local var = msg:getU16()
local offers = {} local offers = {}
local buyOfferCount = (msg:getU32() - 1) local buyOfferCount = msg:getU32()
for i = 0, buyOfferCount do for i = 1, buyOfferCount do
table.insert(offers, readMarketOffer(msg, MarketAction.Buy, var)) table.insert(offers, readMarketOffer(msg, MarketAction.Buy, var))
end end
local sellOfferCount = (msg:getU32() - 1) local sellOfferCount = msg:getU32()
for i = 0, sellOfferCount do for i = 1, sellOfferCount do
table.insert(offers, readMarketOffer(msg, MarketAction.Sell, var)) table.insert(offers, readMarketOffer(msg, MarketAction.Sell, var))
end end
@ -118,7 +118,7 @@ local function parseMarketBrowse(msg)
end end
-- public functions -- public functions
function MarketProtocol.init() function initProtocol()
connect(g_game, { onGameStart = MarketProtocol.registerProtocol, connect(g_game, { onGameStart = MarketProtocol.registerProtocol,
onGameEnd = MarketProtocol.unregisterProtocol }) onGameEnd = MarketProtocol.unregisterProtocol })
@ -128,7 +128,7 @@ function MarketProtocol.init()
end end
end end
function MarketProtocol.terminate() function terminateProtocol()
disconnect(g_game, { onGameStart = MarketProtocol.registerProtocol, disconnect(g_game, { onGameStart = MarketProtocol.registerProtocol,
onGameEnd = MarketProtocol.unregisterProtocol }) onGameEnd = MarketProtocol.unregisterProtocol })

View File

@ -1,8 +1,8 @@
MarketButtonBox < UICheckBox MarketButtonBox < UICheckBox
font: verdana-11px-antialised font: verdana-11px-rounded
color: #f55e5ebb color: #f55e5ebb
size: 106 22 size: 106 22
text-offset: 0 0 text-offset: 0 2
text-align: center text-align: center
image-source: /images/tabbutton_rounded.png image-source: /images/tabbutton_rounded.png
image-clip: 0 0 20 20 image-clip: 0 0 20 20

View File

@ -1,8 +1,8 @@
MarketComboBoxPopupMenuButton < UIButton MarketComboBoxPopupMenuButton < UIButton
height: 18 height: 18
font: verdana-11px-antialised font: verdana-11px-rounded
text-align: left text-align: left
text-offset: 2 0 text-offset: 2 2
color: #aaaaaa color: #aaaaaa
background-color: alpha background-color: alpha
@ -28,10 +28,10 @@ MarketComboBoxPopupMenu < UIPopupMenu
padding: 1 padding: 1
MarketComboBox < UIComboBox MarketComboBox < UIComboBox
font: verdana-11px-antialised font: verdana-11px-rounded
color: #aaaaaa color: #aaaaaa
size: 86 20 size: 86 20
text-offset: 3 0 text-offset: 3 2
text-align: left text-align: left
image-source: /images/combobox_rounded.png image-source: /images/combobox_rounded.png
image-border: 1 image-border: 1

View File

@ -4,6 +4,8 @@ MarketTabBarPanel < Panel
MarketTabBarButton < UIButton MarketTabBarButton < UIButton
size: 20 25 size: 20 25
image-source: /images/tabbutton_square.png image-source: /images/tabbutton_square.png
font: verdana-11px-rounded
text-offset: 0 2
image-clip: 0 0 20 20 image-clip: 0 0 20 20
image-border: 2 image-border: 2
icon-color: white icon-color: white

View File

@ -18,7 +18,7 @@ Panel
MarketTabBar MarketTabBar
id: rightTabBar id: rightTabBar
width: 157 width: 166
height:25 height:25
anchors.top: parent.top anchors.top: parent.top
anchors.right: parent.right anchors.right: parent.right
@ -48,7 +48,142 @@ Panel
Label Label
id: nameLabel id: nameLabel
!text: tr('No item selected.') !text: tr('No item selected.')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: prev.top anchors.top: prev.top
anchors.left: prev.right anchors.left: prev.right
anchors.right: parent.right anchors.right: parent.right
margin-left: 5 margin-left: 5
Label
id: createLabel
!text: tr('Create New Offer')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: rightTabBar.top
anchors.left: rightTabContent.left
margin-top: 355
margin-left: 6
Label
id: offerTypeLabel
!text: tr('Offer Type:')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: prev.bottom
anchors.left: prev.left
margin-top: 7
MarketComboBox
id: offerTypeComboBox
!text: tr('Please Select')
anchors.top: prev.bottom
anchors.left: createLabel.left
margin-top: 3
width: 105
$disabled:
color: #aaaaaa44
Label
id: totalPriceLabel
!text: tr('Total Price:')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: offerTypeLabel.top
anchors.left: prev.right
margin-left: 7
SpinBox
id: totalPriceEdit
anchors.top: prev.bottom
anchors.left: prev.left
margin-top: 3
width: 75
minimum: 1
maximum: 99999999
$disabled:
color: #aaaaaa44
Label
id: piecePriceLabel
!text: tr('Piece Price:')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: offerTypeLabel.top
anchors.left: prev.right
margin-left: 7
SpinBox
id: piecePriceEdit
anchors.top: prev.bottom
anchors.left: prev.left
margin-top: 3
width: 75
minimum: 1
maximum: 99999999
$disabled:
color: #aaaaaa44
Label
id: amountLabel
!text: tr('Amount:')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: offerTypeLabel.top
anchors.left: prev.right
margin-left: 32
PreviousButton
id: prevAmountButton
anchors.verticalCenter: piecePriceEdit.verticalCenter
anchors.left: piecePriceEdit.right
margin-left: 7
@onClick: Market.decrementAmount()
SpinBox
id: amountEdit
anchors.verticalCenter: prev.verticalCenter
anchors.left: prev.right
margin-left: 3
width: 55
minimum: 1
maximum: 999999
NextButton
id: nextAmountButton
anchors.verticalCenter: piecePriceEdit.verticalCenter
anchors.left: prev.right
margin-left: 3
@onClick: Market.incrementAmount()
Button
id: createOfferButton
!text: tr('Create Offer')
anchors.verticalCenter: prev.verticalCenter
anchors.left: prev.right
margin-left: 7
width: 90
//@onClick: g_game.closeNpcTrade()
CheckBox
id: anonymousCheckBox
!text: tr('Anonymous')
anchors.left: prev.left
anchors.bottom: prev.top
margin-bottom: 6
@onSetup: self:setChecked(false)
height: 16
width: 70
Label
id: feeLabel
!text: tr('')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: createOfferButton.bottom
anchors.right: parent.right
margin-right: 8
margin-top: 3

View File

@ -1,14 +1,15 @@
MarketItemBox < UICheckBox MarketItemBox < UICheckBox
id: itemBox
border-width: 1 border-width: 1
border-color: #000000 border-color: #000000
color: #aaaaaa color: #aaaaaa
text-align: center text-align: center
text-offset: 0 20
@onCheckChange: Market.onItemBoxChecked(self)
Item Item
id: item id: item
phantom: true phantom: true
text-offset: 0 13
text-align: right
anchors.top: parent.top anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
margin: 1 margin: 1

View File

@ -25,9 +25,9 @@ Panel
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
margin-top: 55 margin-top: 63
margin-left: 6 margin-left: 6
margin-bottom: 75 margin-bottom: 85
margin-right: 6 margin-right: 6
padding: 1 padding: 1
focusable: false focusable: false

View File

@ -49,6 +49,8 @@ Panel
Label Label
!text: tr('Sell Offers') !text: tr('Sell Offers')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: parent.top anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
margin-top: 44 margin-top: 44
@ -59,7 +61,7 @@ Panel
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.left: prev.left anchors.left: prev.left
anchors.right: parent.right anchors.right: parent.right
height: 120 height: 115
margin-top: 5 margin-top: 5
margin-bottom: 5 margin-bottom: 5
margin-right: 6 margin-right: 6
@ -101,6 +103,8 @@ Panel
Label Label
!text: tr('Buy Offers') !text: tr('Buy Offers')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: prev.top anchors.top: prev.top
anchors.left: parent.left anchors.left: parent.left
margin-top: 9 margin-top: 9
@ -114,7 +118,7 @@ Panel
margin-top: 5 margin-top: 5
margin-bottom: 5 margin-bottom: 5
margin-right: 6 margin-right: 6
height: 120 height: 115
padding: 1 padding: 1
focusable: false focusable: false
background-color: #222833 background-color: #222833

View File

@ -20,6 +20,8 @@ Panel
Label Label
!text: tr('Buy Offers') !text: tr('Buy Offers')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: parent.top anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
@ -62,6 +64,8 @@ Panel
Label Label
!text: tr('Sell Offers') !text: tr('Sell Offers')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: buyStatsTable.bottom anchors.top: buyStatsTable.bottom
anchors.left: parent.left anchors.left: parent.left
margin-top: 9 margin-top: 9
@ -73,7 +77,7 @@ Panel
anchors.left: buyStatsTable.left anchors.left: buyStatsTable.left
anchors.right: buyStatsTable.right anchors.right: buyStatsTable.right
margin-top: 6 margin-top: 6
height: 122 height: 112
padding: 1 padding: 1
focusable: false focusable: false
background-color: #222833 background-color: #222833

View File

@ -1,3 +1,21 @@
MarketAction = {
Buy = 0,
Sell = 1
}
MarketRequest = {
MyOffers = 0xFFFE,
MyHistory = 0xFFFF
}
MarketOfferState = {
Active = 0,
Cancelled = 1,
Expired = 2,
Accepted = 3,
AcceptedEx = 255
}
MarketCategory = { MarketCategory = {
All = 0, All = 0,
Armors = 1, Armors = 1,
@ -64,23 +82,18 @@ MarketCategoryStrings = {
[255] = 'Weapons' [255] = 'Weapons'
} }
MarketAction = { function getMarketCategoryName(id)
Buy = 0, if table.hasKey(MarketCategoryStrings, id) then
Sell = 1 return MarketCategoryStrings[id]
} end
end
MarketRequest = { function getMarketCategoryId(name)
MyOffers = 0xFFFE, local id = table.find(MarketCategoryStrings, name)
MyHistory = 0xFFFF if id then
} return id
end
MarketOfferState = { end
Active = 0,
Cancelled = 1,
Expired = 2,
Accepted = 3,
AcceptedEx = 255
}
MarketItemDescription = { MarketItemDescription = {
Armor = 1, Armor = 1,
@ -121,6 +134,19 @@ MarketItemDescriptionStrings = {
[15] = 'Weight' [15] = 'Weight'
} }
function getMarketDescriptionName(id)
if table.hasKey(MarketItemDescriptionStrings, id) then
return MarketItemDescriptionStrings[id]
end
end
function getMarketDescriptionId(name)
local id = table.find(MarketItemDescriptionStrings, name)
if id then
return id
end
end
MarketSlotFilters = { MarketSlotFilters = {
[InventorySlotOther] = "Two-Handed", [InventorySlotOther] = "Two-Handed",
[InventorySlotLeft] = "One-Handed", [InventorySlotLeft] = "One-Handed",
@ -135,3 +161,16 @@ MarketFilters = {
MarketFilters.First = MarketFilters.vocation MarketFilters.First = MarketFilters.vocation
MarketFilters.Last = MarketFilters.depot MarketFilters.Last = MarketFilters.depot
function getMarketSlotFilterId(name)
local id = table.find(MarketSlotFilters, name)
if id then
return id
end
end
function getMarketSlotFilterName(id)
if table.hasKey(MarketSlotFilters, id) then
return MarketSlotFilters[id]
end
end