Some more market fixes and ascetics

master
BeniS 12 years ago
parent 487dafb8c0
commit 70fba12d6c

@ -345,7 +345,6 @@ local function updateBalance(balance)
if balance < 0 then balance = 0 end if balance < 0 then balance = 0 end
information.balance = balance information.balance = balance
balanceLabel = marketWindow:recursiveGetChildById('balanceLabel')
balanceLabel:setText('Balance: '..balance..'gp') balanceLabel:setText('Balance: '..balance..'gp')
balanceLabel:resizeToText() balanceLabel:resizeToText()
end end
@ -406,13 +405,15 @@ local function openAmountWindow(callback, type, actionText)
amountWindow:lock() amountWindow:lock()
local spinbox = amountWindow:getChildById('amountSpinBox') local spinbox = amountWindow:getChildById('amountSpinBox')
local scrollbar = amountWindow:getChildById('amountScrollBar')
spinbox:setMaximum(selectedOffer[type]:getAmount()) spinbox:setMaximum(selectedOffer[type]:getAmount())
spinbox:setMinimum(1) spinbox:setMinimum(1)
spinbox:setValue(1) spinbox:setValue(1)
local scrollbar = amountWindow:getChildById('amountScrollBar')
scrollbar:setMaximum(selectedOffer[type]:getAmount()) scrollbar:setMaximum(selectedOffer[type]:getAmount())
scrollbar:setMinimum(1) scrollbar:setMinimum(1)
scrollbar:setValue(1) scrollbar:setValue(1)
scrollbar.onValueChange = function(self, value) spinbox:setValue(value) end scrollbar.onValueChange = function(self, value) spinbox:setValue(value) end
spinbox.onValueChange = function(self, value) scrollbar:setValue(value) end spinbox.onValueChange = function(self, value) scrollbar:setValue(value) end
@ -473,7 +474,11 @@ local function onSelectBuyOffer(table, selectedRow, previousSelectedRow)
for _, offer in pairs(marketOffers[MarketAction.Buy]) do for _, offer in pairs(marketOffers[MarketAction.Buy]) do
if offer:isEqual(selectedRow.ref) then if offer:isEqual(selectedRow.ref) then
selectedOffer[MarketAction.Sell] = offer selectedOffer[MarketAction.Sell] = offer
sellButton:setEnabled(true) if Market.depotContains(offer:getItem():getId()) >= offer:getAmount() then
sellButton:setEnabled(true)
else
sellButton:setEnabled(false)
end
end end
end end
end end
@ -619,6 +624,8 @@ local function initInterface()
offerHistoryPanel = g_ui.loadUI('ui/myoffers/offerhistory.otui') offerHistoryPanel = g_ui.loadUI('ui/myoffers/offerhistory.otui')
offersTabBar:addTab(tr('Offer History'), offerHistoryPanel) offersTabBar:addTab(tr('Offer History'), offerHistoryPanel)
balanceLabel = marketWindow:getChildById('balanceLabel')
-- setup offers -- setup offers
buyButton = itemOffersPanel:getChildById('buyButton') buyButton = itemOffersPanel:getChildById('buyButton')
buyButton.onClick = function() openAmountWindow(Market.buyMarketOffer, MarketAction.Buy, 'Buy') end buyButton.onClick = function() openAmountWindow(Market.buyMarketOffer, MarketAction.Buy, 'Buy') end
@ -715,6 +722,8 @@ end
function Market.reset() function Market.reset()
balanceLabel:setColor('#bbbbbb') balanceLabel:setColor('#bbbbbb')
marketWindow:unlock()
marketWindow:hide()
categoryList:setCurrentOption(getMarketCategoryName(MarketCategory.First)) categoryList:setCurrentOption(getMarketCategoryName(MarketCategory.First))
Market.clearSelectedItem() Market.clearSelectedItem()
clearFilters() clearFilters()
@ -938,20 +947,24 @@ function Market.createNewOffer()
MarketProtocol.sendMarketCreateOffer(type, spriteId, amount, piecePrice, anonymous) MarketProtocol.sendMarketCreateOffer(type, spriteId, amount, piecePrice, anonymous)
if type == MarketAction.Sell then if type == MarketAction.Sell then
updateDepotItemCount(spriteId, amount) -- remove count from depot tmp --[[
This is require due to bot protected protocol (cannot update browse item without user input)
normal way is to use the new retrieved depot items in onMarketEnter and refresh the items widget.
]]
updateDepotItemCount(spriteId, amount)
Market.refreshItemsWidget(spriteId) Market.refreshItemsWidget(spriteId)
end end
Market.resetCreateOffer() Market.resetCreateOffer()
end end
function Market.buyMarketOffer(amount, timestamp, counter) function Market.buyMarketOffer(amount, timestamp, counter)
if timestamp > 0 and counter > 0 and amount > 0 then if timestamp > 0 and amount > 0 then
MarketProtocol.sendMarketAcceptOffer(timestamp, counter, amount) MarketProtocol.sendMarketAcceptOffer(timestamp, counter, amount)
end end
end end
function Market.sellMarketOffer(amount, timestamp, counter) function Market.sellMarketOffer(amount, timestamp, counter)
if timestamp > 0 and counter > 0 and amount > 0 then if timestamp > 0 and amount > 0 then
MarketProtocol.sendMarketAcceptOffer(timestamp, counter, amount) MarketProtocol.sendMarketAcceptOffer(timestamp, counter, amount)
end end
end end
@ -976,12 +989,6 @@ function Market.onMarketEnter(depotItems, offers, balance, vocation)
Market.loadDepotItems(depotItems) Market.loadDepotItems(depotItems)
if table.empty(currentItems) then if table.empty(currentItems) then
Market.loadMarketItems(MarketCategory.First) Market.loadMarketItems(MarketCategory.First)
--[[else
-- TODO: Create function to handle this on showing market (seperate from parsing!)
if Market.isItemSelected() then
local spriteId = selectedItem.item.ptr:getId()
Market.refreshItemsWidget(spriteId)
end]]
end end
-- build offer table header -- build offer table header
@ -999,6 +1006,7 @@ function Market.onMarketEnter(depotItems, offers, balance, vocation)
end end
function Market.onMarketLeave() function Market.onMarketLeave()
marketWindow:unlock()
marketWindow:hide() marketWindow:hide()
end end

@ -205,11 +205,11 @@ function MarketProtocol.sendMarketCreateOffer(type, spriteId, amount, price, ano
end end
end end
function MarketProtocol.sendMarketCancelOffer(counter) function MarketProtocol.sendMarketCancelOffer(timestamp, counter)
if g_game.getFeature(GamePlayerMarket) then if g_game.getFeature(GamePlayerMarket) then
local msg = OutputMessage.create() local msg = OutputMessage.create()
msg:addU8(ClientOpcodes.ClientMarketCancel) msg:addU8(ClientOpcodes.ClientMarketCancel)
msg:addU32(os.time()) msg:addU32(timestamp)
msg:addU16(counter) msg:addU16(counter)
send(msg) send(msg)
else else
@ -224,7 +224,6 @@ function MarketProtocol.sendMarketAcceptOffer(timestamp, counter, amount)
msg:addU32(timestamp) msg:addU32(timestamp)
msg:addU16(counter) msg:addU16(counter)
msg:addU16(amount) msg:addU16(amount)
print('sent')
send(msg) send(msg)
else else
g_logger.error('MarketProtocol.sendMarketAcceptOffer does not support the current protocol.') g_logger.error('MarketProtocol.sendMarketAcceptOffer does not support the current protocol.')

@ -2,8 +2,11 @@ Panel
background-color: #22283399 background-color: #22283399
margin: 1 margin: 1
Label TextEdit
!text: tr('Search') id: searchEdit
anchors.top: parent.top anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
margin-left: 10 anchors.right: parent.right
margin-top: 10
margin-left: 6
margin-right: 6

Loading…
Cancel
Save