Market my offers
This commit is contained in:
parent
ff0947c270
commit
01c107ba62
|
@ -38,6 +38,7 @@ currentOffersPanel = nil
|
|||
offerHistoryPanel = nil
|
||||
itemsPanel = nil
|
||||
selectedOffer = {}
|
||||
selectedMyOffer = {}
|
||||
|
||||
nameLabel = nil
|
||||
feeLabel = nil
|
||||
|
@ -64,6 +65,11 @@ detailsTable = nil
|
|||
buyStatsTable = nil
|
||||
sellStatsTable = nil
|
||||
|
||||
buyCancelButton = nil
|
||||
sellCancelButton = nil
|
||||
buyMyOfferTable = nil
|
||||
sellMyOfferTable = nil
|
||||
|
||||
offerExhaust = {}
|
||||
marketOffers = {}
|
||||
marketItems = {}
|
||||
|
@ -134,6 +140,13 @@ local function clearOffers()
|
|||
sellOfferTable:clearData()
|
||||
end
|
||||
|
||||
local function clearMyOffers()
|
||||
marketOffers[MarketAction.Buy] = {}
|
||||
marketOffers[MarketAction.Sell] = {}
|
||||
buyMyOfferTable:clearData()
|
||||
sellMyOfferTable:clearData()
|
||||
end
|
||||
|
||||
local function clearFilters()
|
||||
for _, filter in pairs(filterButtons) do
|
||||
if filter and filter:isChecked() ~= filter.default then
|
||||
|
@ -167,25 +180,38 @@ local function addOffer(offer, offerType)
|
|||
local amount = offer:getAmount()
|
||||
local price = offer:getPrice()
|
||||
local timestamp = offer:getTimeStamp()
|
||||
local itemName = offer:getItem():getMarketData().name
|
||||
|
||||
buyOfferTable:toggleSorting(false)
|
||||
sellOfferTable:toggleSorting(false)
|
||||
|
||||
buyMyOfferTable:toggleSorting(false)
|
||||
sellMyOfferTable:toggleSorting(false)
|
||||
|
||||
if amount < 1 then return false end
|
||||
if offerType == MarketAction.Buy then
|
||||
local data = {
|
||||
if offer.warn then
|
||||
buyOfferTable:setColumnStyle('OfferTableWarningColumn', true)
|
||||
end
|
||||
|
||||
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), " ", " ")}
|
||||
}
|
||||
|
||||
if offer.warn then
|
||||
buyOfferTable:setColumnStyle('OfferTableWarningColumn', true)
|
||||
})
|
||||
end
|
||||
|
||||
local row = buyOfferTable:addRow(data)
|
||||
row.ref = id
|
||||
|
||||
if offer.warn then
|
||||
|
@ -193,19 +219,28 @@ local function addOffer(offer, offerType)
|
|||
buyOfferTable:setColumnStyle('OfferTableColumn', true)
|
||||
end
|
||||
else
|
||||
local data = {
|
||||
if offer.warn then
|
||||
sellOfferTable:setColumnStyle('OfferTableWarningColumn', true)
|
||||
end
|
||||
|
||||
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}
|
||||
}
|
||||
|
||||
if offer.warn then
|
||||
sellOfferTable:setColumnStyle('OfferTableWarningColumn', true)
|
||||
})
|
||||
end
|
||||
|
||||
local row = sellOfferTable:addRow(data)
|
||||
row.ref = id
|
||||
|
||||
if offer.warn then
|
||||
|
@ -219,6 +254,11 @@ local function addOffer(offer, offerType)
|
|||
buyOfferTable:sort()
|
||||
sellOfferTable:sort()
|
||||
|
||||
buyMyOfferTable:toggleSorting(false)
|
||||
sellMyOfferTable:toggleSorting(false)
|
||||
buyMyOfferTable:sort()
|
||||
sellMyOfferTable:sort()
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -277,6 +317,9 @@ local function updateOffers(offers)
|
|||
selectedOffer[MarketAction.Buy] = nil
|
||||
selectedOffer[MarketAction.Sell] = nil
|
||||
|
||||
selectedMyOffer[MarketAction.Buy] = nil
|
||||
selectedMyOffer[MarketAction.Sell] = nil
|
||||
|
||||
-- clear existing offer data
|
||||
buyOfferTable:clearData()
|
||||
buyOfferTable:setSorting(4, TABLE_SORTING_DESC)
|
||||
|
@ -286,6 +329,9 @@ local function updateOffers(offers)
|
|||
sellButton:setEnabled(false)
|
||||
buyButton:setEnabled(false)
|
||||
|
||||
buyCancelButton:setEnabled(false)
|
||||
sellCancelButton:setEnabled(false)
|
||||
|
||||
for _, offer in pairs(offers) do
|
||||
mergeOffer(offer)
|
||||
end
|
||||
|
@ -438,6 +484,12 @@ local function destroyAmountWindow()
|
|||
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)
|
||||
if not Market.isOfferSelected(actionType) then
|
||||
return
|
||||
|
@ -546,6 +598,24 @@ local function onSelectBuyOffer(table, selectedRow, previousSelectedRow)
|
|||
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 id = getMarketCategoryId(option)
|
||||
if id == MarketCategory.MetaWeapons then
|
||||
|
@ -787,12 +857,28 @@ local function initInterface()
|
|||
buyOfferTable.onSelectionChange = onSelectBuyOffer
|
||||
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})
|
||||
sellStatsTable:setColumnWidth({120, 270})
|
||||
detailsTable:setColumnWidth({80, 330})
|
||||
|
||||
buyOfferTable:setSorting(4, TABLE_SORTING_DESC)
|
||||
sellOfferTable:setSorting(4, TABLE_SORTING_ASC)
|
||||
|
||||
buyMyOfferTable:setSorting(3, TABLE_SORTING_DESC)
|
||||
sellMyOfferTable:setSorting(3, TABLE_SORTING_DESC)
|
||||
end
|
||||
|
||||
function init()
|
||||
|
@ -836,6 +922,7 @@ function Market.reset()
|
|||
categoryList:setCurrentOption(getMarketCategoryName(MarketCategory.First))
|
||||
searchEdit:setText('')
|
||||
clearFilters()
|
||||
clearMyOffers()
|
||||
if not table.empty(information) then
|
||||
Market.updateCurrentItems()
|
||||
end
|
||||
|
@ -903,8 +990,8 @@ function Market.close(notify)
|
|||
if not marketWindow:isHidden() then
|
||||
marketWindow:hide()
|
||||
marketWindow:unlock()
|
||||
Market.clearSelectedItem(
|
||||
) Market.reset()
|
||||
Market.clearSelectedItem()
|
||||
Market.reset()
|
||||
if notify then
|
||||
MarketProtocol.sendMarketLeave()
|
||||
end
|
||||
|
@ -990,9 +1077,16 @@ end
|
|||
function Market.refreshOffers()
|
||||
if Market.isItemSelected() then
|
||||
Market.onItemBoxChecked(selectedItem.ref)
|
||||
else
|
||||
Market.refreshMyOffers()
|
||||
end
|
||||
end
|
||||
|
||||
function Market.refreshMyOffers()
|
||||
clearMyOffers()
|
||||
MarketProtocol.sendMarketBrowseMyOffers()
|
||||
end
|
||||
|
||||
|
||||
function Market.loadMarketItems(category)
|
||||
clearItems()
|
||||
|
|
|
@ -4,7 +4,7 @@ MarketOffer.__index = MarketOffer
|
|||
local OFFER_TIMESTAMP = 1
|
||||
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 = {
|
||||
id = {},
|
||||
type = nil,
|
||||
|
@ -12,7 +12,8 @@ MarketOffer.new = function(offerId, t, item, amount, price, playerName, state)
|
|||
amount = 0,
|
||||
price = 0,
|
||||
player = '',
|
||||
state = 0
|
||||
state = 0,
|
||||
var = nil
|
||||
}
|
||||
|
||||
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.')
|
||||
end
|
||||
offer.state = state
|
||||
offer.var = var
|
||||
|
||||
setmetatable(offer, MarketOffer)
|
||||
return offer
|
||||
|
|
|
@ -29,11 +29,12 @@ local function readMarketOffer(msg, action, var)
|
|||
local state = MarketOfferState.Active
|
||||
if var == MarketRequest.MyHistory then
|
||||
state = msg:getU8()
|
||||
elseif var == MarketRequest.MyOffers then
|
||||
else
|
||||
playerName = msg:getString()
|
||||
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
|
||||
|
||||
-- parsing protocols
|
||||
|
@ -201,6 +202,10 @@ function MarketProtocol.sendMarketBrowse(browseId)
|
|||
end
|
||||
end
|
||||
|
||||
function MarketProtocol.sendMarketBrowseMyOffers()
|
||||
MarketProtocol.sendMarketBrowse(MarketRequest.MyOffers)
|
||||
end
|
||||
|
||||
function MarketProtocol.sendMarketCreateOffer(type, spriteId, amount, price, anonymous)
|
||||
if g_game.getFeature(GamePlayerMarket) then
|
||||
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
|
||||
background-color: #22283399
|
||||
margin: 1
|
||||
|
||||
Button
|
||||
id: sellCancelButton
|
||||
!text: tr('Cancel')
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: next.bottom
|
||||
margin-right: 6
|
||||
width: 80
|
||||
enabled: false
|
||||
|
||||
Label
|
||||
!text: tr('Current Offers')
|
||||
!text: tr('Sell Offers')
|
||||
font: verdana-11px-rounded
|
||||
text-offset: 0 2
|
||||
anchors.top: parent.top
|
||||
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…
Reference in New Issue