diff --git a/data/styles/20-spinboxes.otui b/data/styles/20-spinboxes.otui index 5b2576f0..61461be7 100644 --- a/data/styles/20-spinboxes.otui +++ b/data/styles/20-spinboxes.otui @@ -13,7 +13,6 @@ SpinBox < TextEdit image-clip: 0 0 10 10 anchors.top: parent.top anchors.right: parent.right - @onPress: self:getParent():up() $hover: image-clip: 0 10 10 10 @@ -28,7 +27,6 @@ SpinBox < TextEdit image-clip: 0 0 10 10 anchors.bottom: parent.bottom anchors.right: parent.right - @onPress: self:getParent():down() $hover: image-clip: 0 10 10 10 diff --git a/modules/corelib/table.lua b/modules/corelib/table.lua index 8c7babc7..d0270e59 100644 --- a/modules/corelib/table.lua +++ b/modules/corelib/table.lua @@ -138,6 +138,15 @@ function table.findbyfield(t, fieldname, fieldvalue) return nil 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) local maxn = #t local str = "" diff --git a/modules/corelib/ui/uispinbox.lua b/modules/corelib/ui/uispinbox.lua index eab838e6..30eb23fd 100644 --- a/modules/corelib/ui/uispinbox.lua +++ b/modules/corelib/ui/uispinbox.lua @@ -15,6 +15,11 @@ function UISpinBox.create() return spinbox 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) if direction == MouseWheelUp then self:up() diff --git a/modules/game_npctrade/npctrade.lua b/modules/game_npctrade/npctrade.lua index 9a39931e..24faf31b 100644 --- a/modules/game_npctrade/npctrade.lua +++ b/modules/game_npctrade/npctrade.lua @@ -436,6 +436,21 @@ function onPlayerGoods(money, items) 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() end @@ -453,6 +468,29 @@ function onInventoryChange(inventory, item, oldItem) 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) if CURRENCY_DECIMAL then return string.format("%.02f", amount/100.0) .. ' ' .. CURRENCY diff --git a/modules/game_npctrade/npctrade.otui b/modules/game_npctrade/npctrade.otui index 13450047..7c766a10 100644 --- a/modules/game_npctrade/npctrade.otui +++ b/modules/game_npctrade/npctrade.otui @@ -250,6 +250,7 @@ MainWindow anchors.right: next.left anchors.bottom: parent.bottom margin-right: 10 + visible: false @onClick: modules.game_npctrade.sellAll() Button