Added 'sell all' tooltip to show items you can sell

* Now 'sell all' button with enable/disable
* Fixed display issue with 'sell all' button
* Also changed spinbox button click
This commit is contained in:
BeniS 2013-02-20 23:08:03 +13:00
parent b61094c053
commit 88c59afb8c
5 changed files with 53 additions and 2 deletions

View File

@ -13,7 +13,6 @@ SpinBox < TextEdit
image-clip: 0 0 10 10 image-clip: 0 0 10 10
anchors.top: parent.top anchors.top: parent.top
anchors.right: parent.right anchors.right: parent.right
@onPress: self:getParent():up()
$hover: $hover:
image-clip: 0 10 10 10 image-clip: 0 10 10 10
@ -28,7 +27,6 @@ SpinBox < TextEdit
image-clip: 0 0 10 10 image-clip: 0 0 10 10
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.right: parent.right anchors.right: parent.right
@onPress: self:getParent():down()
$hover: $hover:
image-clip: 0 10 10 10 image-clip: 0 10 10 10

View File

@ -138,6 +138,15 @@ function table.findbyfield(t, fieldname, fieldvalue)
return nil return nil
end end
function table.size(t)
local size = 0
for i, n in pairs(table) do
size = size + 1
end
return size
end
function table.tostring(t) function table.tostring(t)
local maxn = #t local maxn = #t
local str = "" local str = ""

View File

@ -15,6 +15,11 @@ function UISpinBox.create()
return spinbox return spinbox
end end
function UISpinBox:onSetup()
g_mouse.bindAutoPress(self:getChildById('up'), function() self:up() end, 300)
g_mouse.bindAutoPress(self:getChildById('down'), function() self:down() end, 300)
end
function UISpinBox:onMouseWheel(mousePos, direction) function UISpinBox:onMouseWheel(mousePos, direction)
if direction == MouseWheelUp then if direction == MouseWheelUp then
self:up() self:up()

View File

@ -436,6 +436,21 @@ function onPlayerGoods(money, items)
end end
end end
local first = true
local info = ''
for key, amount in pairs(playerItems) do
if amount > 0 then
local data = getTradeItemData(key, SELL)
if data then
info = info..(not first and "\n" or "")..amount.." "..data.name.." ("..data.price*amount.." gold)"
if first then first = false end
end
end
end
if info ~= '' then
sellAllButton:setTooltip(info)
end
refreshPlayerGoods() refreshPlayerGoods()
end end
@ -453,6 +468,29 @@ function onInventoryChange(inventory, item, oldItem)
end end
end end
function getTradeItemData(id, type)
if table.empty(tradeItems[type]) then
return false
end
if type then
for key,item in pairs(tradeItems[type]) do
if item.ptr and item.ptr:getId() == id then
return item
end
end
else
for _,items in pairs(tradeItems) do
for key,item in pairs(items) do
if item.ptr and item.ptr:getId() == id then
return item
end
end
end
end
return false
end
function formatCurrency(amount) function formatCurrency(amount)
if CURRENCY_DECIMAL then if CURRENCY_DECIMAL then
return string.format("%.02f", amount/100.0) .. ' ' .. CURRENCY return string.format("%.02f", amount/100.0) .. ' ' .. CURRENCY

View File

@ -250,6 +250,7 @@ MainWindow
anchors.right: next.left anchors.right: next.left
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
margin-right: 10 margin-right: 10
visible: false
@onClick: modules.game_npctrade.sellAll() @onClick: modules.game_npctrade.sellAll()
Button Button