Merge pull request #654 from crackcomm/market-myoffers

Market myoffers + NPC start block
master
Ben Dol 9 years ago
commit 0e0da9ecbf

@ -987,6 +987,9 @@ function applyMessagePrefixies(name, level, message)
end end
function onTalk(name, level, mode, message, channelId, creaturePos) function onTalk(name, level, mode, message, channelId, creaturePos)
if mode == MessageModes.NpcFromStartBlock then
mode = MessageModes.NpcFrom
end
if mode == MessageModes.GamemasterBroadcast then if mode == MessageModes.GamemasterBroadcast then
modules.game_textmessage.displayBroadcastMessage(name .. ': ' .. message) modules.game_textmessage.displayBroadcastMessage(name .. ': ' .. message)
return return

@ -38,6 +38,7 @@ currentOffersPanel = nil
offerHistoryPanel = nil offerHistoryPanel = nil
itemsPanel = nil itemsPanel = nil
selectedOffer = {} selectedOffer = {}
selectedMyOffer = {}
nameLabel = nil nameLabel = nil
feeLabel = nil feeLabel = nil
@ -64,6 +65,11 @@ detailsTable = nil
buyStatsTable = nil buyStatsTable = nil
sellStatsTable = nil sellStatsTable = nil
buyCancelButton = nil
sellCancelButton = nil
buyMyOfferTable = nil
sellMyOfferTable = nil
offerExhaust = {} offerExhaust = {}
marketOffers = {} marketOffers = {}
marketItems = {} marketItems = {}
@ -134,6 +140,13 @@ local function clearOffers()
sellOfferTable:clearData() sellOfferTable:clearData()
end end
local function clearMyOffers()
marketOffers[MarketAction.Buy] = {}
marketOffers[MarketAction.Sell] = {}
buyMyOfferTable:clearData()
sellMyOfferTable:clearData()
end
local function clearFilters() local function clearFilters()
for _, filter in pairs(filterButtons) do for _, filter in pairs(filterButtons) do
if filter and filter:isChecked() ~= filter.default then if filter and filter:isChecked() ~= filter.default then
@ -167,25 +180,38 @@ local function addOffer(offer, offerType)
local amount = offer:getAmount() local amount = offer:getAmount()
local price = offer:getPrice() local price = offer:getPrice()
local timestamp = offer:getTimeStamp() local timestamp = offer:getTimeStamp()
local itemName = offer:getItem():getMarketData().name
buyOfferTable:toggleSorting(false) buyOfferTable:toggleSorting(false)
sellOfferTable:toggleSorting(false) sellOfferTable:toggleSorting(false)
buyMyOfferTable:toggleSorting(false)
sellMyOfferTable:toggleSorting(false)
if amount < 1 then return false end if amount < 1 then return false end
if offerType == MarketAction.Buy then if offerType == MarketAction.Buy then
local data = {
{text = player},
{text = amount},
{text = price*amount},
{text = price},
{text = string.gsub(os.date('%c', timestamp), " ", " ")}
}
if offer.warn then if offer.warn then
buyOfferTable:setColumnStyle('OfferTableWarningColumn', true) buyOfferTable:setColumnStyle('OfferTableWarningColumn', true)
end end
local row = buyOfferTable:addRow(data) local row = nil
if offer.var == MarketRequest.MyOffers then
row = buyMyOfferTable:addRow({
{text = itemName},
{text = price*amount},
{text = price},
{text = amount},
{text = string.gsub(os.date('%c', timestamp), " ", " "), sortvalue = timestamp}
})
else
row = buyOfferTable:addRow({
{text = player},
{text = amount},
{text = price*amount},
{text = price},
{text = string.gsub(os.date('%c', timestamp), " ", " ")}
})
end
row.ref = id row.ref = id
if offer.warn then if offer.warn then
@ -193,19 +219,28 @@ local function addOffer(offer, offerType)
buyOfferTable:setColumnStyle('OfferTableColumn', true) buyOfferTable:setColumnStyle('OfferTableColumn', true)
end end
else else
local data = {
{text = player},
{text = amount},
{text = price*amount},
{text = price},
{text = string.gsub(os.date('%c', timestamp), " ", " "), sortvalue = timestamp}
}
if offer.warn then if offer.warn then
sellOfferTable:setColumnStyle('OfferTableWarningColumn', true) sellOfferTable:setColumnStyle('OfferTableWarningColumn', true)
end end
local row = sellOfferTable:addRow(data) local row = nil
if offer.var == MarketRequest.MyOffers then
row = sellMyOfferTable:addRow({
{text = itemName},
{text = price*amount},
{text = price},
{text = amount},
{text = string.gsub(os.date('%c', timestamp), " ", " "), sortvalue = timestamp}
})
else
row = sellOfferTable:addRow({
{text = player},
{text = amount},
{text = price*amount},
{text = price},
{text = string.gsub(os.date('%c', timestamp), " ", " "), sortvalue = timestamp}
})
end
row.ref = id row.ref = id
if offer.warn then if offer.warn then
@ -219,6 +254,11 @@ local function addOffer(offer, offerType)
buyOfferTable:sort() buyOfferTable:sort()
sellOfferTable:sort() sellOfferTable:sort()
buyMyOfferTable:toggleSorting(false)
sellMyOfferTable:toggleSorting(false)
buyMyOfferTable:sort()
sellMyOfferTable:sort()
return true return true
end end
@ -277,6 +317,9 @@ local function updateOffers(offers)
selectedOffer[MarketAction.Buy] = nil selectedOffer[MarketAction.Buy] = nil
selectedOffer[MarketAction.Sell] = nil selectedOffer[MarketAction.Sell] = nil
selectedMyOffer[MarketAction.Buy] = nil
selectedMyOffer[MarketAction.Sell] = nil
-- clear existing offer data -- clear existing offer data
buyOfferTable:clearData() buyOfferTable:clearData()
buyOfferTable:setSorting(4, TABLE_SORTING_DESC) buyOfferTable:setSorting(4, TABLE_SORTING_DESC)
@ -286,6 +329,9 @@ local function updateOffers(offers)
sellButton:setEnabled(false) sellButton:setEnabled(false)
buyButton:setEnabled(false) buyButton:setEnabled(false)
buyCancelButton:setEnabled(false)
sellCancelButton:setEnabled(false)
for _, offer in pairs(offers) do for _, offer in pairs(offers) do
mergeOffer(offer) mergeOffer(offer)
end end
@ -438,6 +484,12 @@ local function destroyAmountWindow()
end end
end end
local function cancelMyOffer(actionType)
local offer = selectedMyOffer[actionType]
MarketProtocol.sendMarketCancelOffer(offer:getTimeStamp(), offer:getCounter())
Market.refreshMyOffers()
end
local function openAmountWindow(callback, actionType, actionText) local function openAmountWindow(callback, actionType, actionText)
if not Market.isOfferSelected(actionType) then if not Market.isOfferSelected(actionType) then
return return
@ -546,6 +598,24 @@ local function onSelectBuyOffer(table, selectedRow, previousSelectedRow)
end end
end end
local function onSelectMyBuyOffer(table, selectedRow, previousSelectedRow)
for _, offer in pairs(marketOffers[MarketAction.Buy]) do
if offer:isEqual(selectedRow.ref) then
selectedMyOffer[MarketAction.Buy] = offer
buyCancelButton:setEnabled(true)
end
end
end
local function onSelectMySellOffer(table, selectedRow, previousSelectedRow)
for _, offer in pairs(marketOffers[MarketAction.Sell]) do
if offer:isEqual(selectedRow.ref) then
selectedMyOffer[MarketAction.Sell] = offer
sellCancelButton:setEnabled(true)
end
end
end
local function onChangeCategory(combobox, option) local function onChangeCategory(combobox, option)
local id = getMarketCategoryId(option) local id = getMarketCategoryId(option)
if id == MarketCategory.MetaWeapons then if id == MarketCategory.MetaWeapons then
@ -787,12 +857,28 @@ local function initInterface()
buyOfferTable.onSelectionChange = onSelectBuyOffer buyOfferTable.onSelectionChange = onSelectBuyOffer
sellOfferTable.onSelectionChange = onSelectSellOffer sellOfferTable.onSelectionChange = onSelectSellOffer
-- setup my offers
buyMyOfferTable = currentOffersPanel:recursiveGetChildById('myBuyingTable')
sellMyOfferTable = currentOffersPanel:recursiveGetChildById('mySellingTable')
buyMyOfferTable.onSelectionChange = onSelectMyBuyOffer
sellMyOfferTable.onSelectionChange = onSelectMySellOffer
buyCancelButton = currentOffersPanel:getChildById('buyCancelButton')
buyCancelButton.onClick = function() cancelMyOffer(MarketAction.Buy) end
sellCancelButton = currentOffersPanel:getChildById('sellCancelButton')
sellCancelButton.onClick = function() cancelMyOffer(MarketAction.Sell) end
buyStatsTable:setColumnWidth({120, 270}) buyStatsTable:setColumnWidth({120, 270})
sellStatsTable:setColumnWidth({120, 270}) sellStatsTable:setColumnWidth({120, 270})
detailsTable:setColumnWidth({80, 330}) detailsTable:setColumnWidth({80, 330})
buyOfferTable:setSorting(4, TABLE_SORTING_DESC) buyOfferTable:setSorting(4, TABLE_SORTING_DESC)
sellOfferTable:setSorting(4, TABLE_SORTING_ASC) sellOfferTable:setSorting(4, TABLE_SORTING_ASC)
buyMyOfferTable:setSorting(3, TABLE_SORTING_DESC)
sellMyOfferTable:setSorting(3, TABLE_SORTING_DESC)
end end
function init() function init()
@ -836,6 +922,7 @@ function Market.reset()
categoryList:setCurrentOption(getMarketCategoryName(MarketCategory.First)) categoryList:setCurrentOption(getMarketCategoryName(MarketCategory.First))
searchEdit:setText('') searchEdit:setText('')
clearFilters() clearFilters()
clearMyOffers()
if not table.empty(information) then if not table.empty(information) then
Market.updateCurrentItems() Market.updateCurrentItems()
end end
@ -903,8 +990,8 @@ function Market.close(notify)
if not marketWindow:isHidden() then if not marketWindow:isHidden() then
marketWindow:hide() marketWindow:hide()
marketWindow:unlock() marketWindow:unlock()
Market.clearSelectedItem( Market.clearSelectedItem()
) Market.reset() Market.reset()
if notify then if notify then
MarketProtocol.sendMarketLeave() MarketProtocol.sendMarketLeave()
end end
@ -990,9 +1077,16 @@ end
function Market.refreshOffers() function Market.refreshOffers()
if Market.isItemSelected() then if Market.isItemSelected() then
Market.onItemBoxChecked(selectedItem.ref) Market.onItemBoxChecked(selectedItem.ref)
else
Market.refreshMyOffers()
end end
end end
function Market.refreshMyOffers()
clearMyOffers()
MarketProtocol.sendMarketBrowseMyOffers()
end
function Market.loadMarketItems(category) function Market.loadMarketItems(category)
clearItems() clearItems()

@ -4,7 +4,7 @@ MarketOffer.__index = MarketOffer
local OFFER_TIMESTAMP = 1 local OFFER_TIMESTAMP = 1
local OFFER_COUNTER = 2 local OFFER_COUNTER = 2
MarketOffer.new = function(offerId, t, item, amount, price, playerName, state) MarketOffer.new = function(offerId, t, item, amount, price, playerName, state, var)
local offer = { local offer = {
id = {}, id = {},
type = nil, type = nil,
@ -12,7 +12,8 @@ MarketOffer.new = function(offerId, t, item, amount, price, playerName, state)
amount = 0, amount = 0,
price = 0, price = 0,
player = '', player = '',
state = 0 state = 0,
var = nil
} }
if not offerId or type(offerId) ~= 'table' then if not offerId or type(offerId) ~= 'table' then
@ -41,6 +42,7 @@ MarketOffer.new = function(offerId, t, item, amount, price, playerName, state)
g_logger.error('MarketOffer.new - invalid state provided.') g_logger.error('MarketOffer.new - invalid state provided.')
end end
offer.state = state offer.state = state
offer.var = var
setmetatable(offer, MarketOffer) setmetatable(offer, MarketOffer)
return offer return offer
@ -153,4 +155,4 @@ function MarketOffer:getCounter()
return return
end end
return self.id[OFFER_COUNTER] return self.id[OFFER_COUNTER]
end end

@ -29,11 +29,12 @@ local function readMarketOffer(msg, action, var)
local state = MarketOfferState.Active local state = MarketOfferState.Active
if var == MarketRequest.MyHistory then if var == MarketRequest.MyHistory then
state = msg:getU8() state = msg:getU8()
elseif var == MarketRequest.MyOffers then
else else
playerName = msg:getString() playerName = msg:getString()
end end
return MarketOffer.new({timestamp, counter}, action, Item.create(itemId), amount, price, playerName, state) return MarketOffer.new({timestamp, counter}, action, Item.create(itemId), amount, price, playerName, state, var)
end end
-- parsing protocols -- parsing protocols
@ -201,6 +202,10 @@ function MarketProtocol.sendMarketBrowse(browseId)
end end
end end
function MarketProtocol.sendMarketBrowseMyOffers()
MarketProtocol.sendMarketBrowse(MarketRequest.MyOffers)
end
function MarketProtocol.sendMarketCreateOffer(type, spriteId, amount, price, anonymous) function MarketProtocol.sendMarketCreateOffer(type, spriteId, amount, price, anonymous)
if g_game.getFeature(GamePlayerMarket) then if g_game.getFeature(GamePlayerMarket) then
local msg = OutputMessage.create() local msg = OutputMessage.create()

@ -1,9 +1,176 @@
OfferTableRow < TableRow
font: verdana-11px-monochrome
color: #cccccc
height: 15
OfferTableColumn < TableColumn
font: verdana-11px-monochrome
background-color: alpha
text-offset: 5 0
color: #cccccc
width: 80
OfferTableWarningColumn < OfferTableColumn
color: #e03d3d
OfferTableHeaderRow < TableHeaderRow
font: verdana-11px-monochrome
color: #cccccc
height: 20
OfferTableHeaderColumn < SortableTableHeaderColumn
font: verdana-11px-monochrome
text-offset: 2 0
color: #cccccc
$focus:
background-color: #294f6d
color: #ffffff
Panel Panel
background-color: #22283399 background-color: #22283399
margin: 1 margin: 1
Button
id: sellCancelButton
!text: tr('Cancel')
anchors.right: parent.right
anchors.bottom: next.bottom
margin-right: 6
width: 80
enabled: false
Label Label
!text: tr('Current 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-left: 10 margin-top: 44
margin-left: 6
Table
id: mySellingTable
anchors.top: prev.bottom
anchors.left: prev.left
anchors.right: parent.right
height: 150
margin-top: 5
margin-bottom: 5
margin-right: 6
padding: 1
focusable: false
background-color: #222833
border-width: 1
border-color: #191f27
table-data: mySellingTableData
row-style: OfferTableRow
column-style: OfferTableColumn
header-column-style: false
header-row-style: false
OfferTableHeaderRow
id: header
OfferTableHeaderColumn
!text: tr('Item Name')
width: 160
OfferTableHeaderColumn
!text: tr('Total Price')
width: 125
OfferTableHeaderColumn
!text: tr('Piece Price')
width: 125
OfferTableHeaderColumn
!text: tr('Amount')
width: 110
OfferTableHeaderColumn
!text: tr('Auction End')
width: 110
TableData
id: mySellingTableData
anchors.bottom: mySellingTable.bottom
anchors.left: mySellingTable.left
anchors.right: mySellingTable.right
margin-top: 2
vertical-scrollbar: mySellingTableScrollBar
VerticalScrollBar
id: mySellingTableScrollBar
anchors.top: mySellingTable.top
anchors.bottom: mySellingTable.bottom
anchors.right: mySellingTable.right
step: 28
pixels-scroll: true
Button
id: buyCancelButton
!text: tr('Cancel')
anchors.right: parent.right
anchors.top: prev.bottom
margin-top: 5
margin-right: 6
width: 80
enabled: false
Label
!text: tr('Buy Offers')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: prev.top
anchors.left: parent.left
margin-top: 9
margin-left: 6
Table
id: myBuyingTable
anchors.top: prev.bottom
anchors.left: prev.left
anchors.right: parent.right
margin-top: 5
margin-bottom: 5
margin-right: 6
height: 150
padding: 1
focusable: false
background-color: #222833
border-width: 1
border-color: #191f27
table-data: myBuyingTableData
row-style: OfferTableRow
column-style: OfferTableColumn
header-column-style: false
header-row-style: false
OfferTableHeaderRow
id: header
OfferTableHeaderColumn
!text: tr('Item Name')
width: 160
OfferTableHeaderColumn
!text: tr('Total Price')
width: 125
OfferTableHeaderColumn
!text: tr('Piece Price')
width: 125
OfferTableHeaderColumn
!text: tr('Amount')
width: 110
OfferTableHeaderColumn
!text: tr('Auction End')
width: 110
TableData
id: myBuyingTableData
anchors.bottom: myBuyingTable.bottom
anchors.left: myBuyingTable.left
anchors.right: myBuyingTable.right
vertical-scrollbar: myBuyingTableScrollBar
VerticalScrollBar
id: myBuyingTableScrollBar
anchors.top: myBuyingTable.top
anchors.bottom: myBuyingTable.bottom
anchors.right: myBuyingTable.right
step: 28
pixels-scroll: true

Loading…
Cancel
Save