some changes to npctrade. still needs another rev

master
Henrique Santiago 12 years ago
parent 9afe4e012b
commit c89665848d

@ -26,6 +26,9 @@ local ignoreCapacity = false
local ignoreEquipped = true
local showOnlyHolding = false
local CURRENCY = 'gold'
local WEIGHT_UNIT = 'oz'
-- public functions
function NPCTrade.init()
cacheItems = {}
@ -85,7 +88,8 @@ function NPCTrade.terminate()
cacheItems = nil
cacheGoods = nil
disconnect(g_game, { onOpenNpcTrade = NPCTrade.onOpenNpcTrade,
disconnect(g_game, { onGameEnd = NPCTrade.hide,
onOpenNpcTrade = NPCTrade.onOpenNpcTrade,
onPlayerGoods = NPCTrade.onPlayerGoods,
onCloseNpcTrade = NPCTrade.onCloseNpcTrade } )
end
@ -129,9 +133,13 @@ function NPCTrade.updateSetup()
if offerSelected then
if radioItems.selectedWidget:isEnabled() then
if setupButton:getText() == 'Buy' then
quantityScroll:setMaximum(math.max(0, math.min(100, math.floor(moneyGoods/NPCTrade.getOfferPrice(offerSelected)))))
else
quantityScroll:setMaximum(math.max(0, math.min(100, cacheGoods[offerSelected[1]:getId()])))
local capacityMaxCount = math.floor(100*g_game.getLocalPlayer():getFreeCapacity()/offerSelected[3])
local priceMaxCount = math.floor(moneyGoods/NPCTrade.getOfferPrice(offerSelected))
quantityScroll:setMaximum(math.max(0, math.min(100, math.min(priceMaxCount, capacityMaxCount))))
else
if cacheGoods[offerSelected[1]:getId()] then -- list might be empty.
quantityScroll:setMaximum(math.max(0, math.min(100, cacheGoods[offerSelected[1]:getId()])))
end
end
else
NPCTrade.resetSetup()
@ -163,9 +171,9 @@ function NPCTrade.setItem(widget)
local price = NPCTrade.getOfferPrice(widget.offer)
local freeCapacity = g_game.getLocalPlayer():getFreeCapacity()
nameLabel:setText(offer[2])
weightLabel:setText(string.format("%.2f", offer[3]/100) .. " oz")
priceLabel:setText(price .. " gold")
capacityLabel:setText(string.format("%.2f", freeCapacity) .. " oz")
weightLabel:setText(string.format('%.2f', offer[3]/100) .. ' ' .. WEIGHT_UNIT)
priceLabel:setText(price .. ' ' .. CURRENCY)
capacityLabel:setText(string.format('%.2f', freeCapacity) .. ' ' .. WEIGHT_UNIT)
quantityLabel:setText(1)
quantityScroll:setValue(1)
@ -178,8 +186,8 @@ function NPCTrade.setQuantity(quantity)
if quantityLabel and offerSelected then
local price = NPCTrade.getOfferPrice(offerSelected)
quantityLabel:setText(quantity)
weightLabel:setText(string.format("%.2f", offerSelected[3]*quantity/100) .. " oz")
priceLabel:setText(price .. " gold")
weightLabel:setText(string.format('%.2f', offerSelected[3]*quantity/100) .. ' ' .. WEIGHT_UNIT)
priceLabel:setText(price .. ' ' .. CURRENCY)
end
end
@ -209,7 +217,7 @@ end
function NPCTrade.switchBuyWithBackpack()
buyWithBackpack = not buyWithBackpack
if offerSelected then
priceLabel:setText(NPCTrade.getOfferPrice(offerSelected) .. " gold")
priceLabel:setText(NPCTrade.getOfferPrice(offerSelected) .. ' ' .. CURRENCY)
end
return true
end
@ -251,8 +259,8 @@ function NPCTrade.createItemsOnPanel()
itemBox.offer = v
itemBox:getChildById('item'):setItem(v[1])
itemBox:getChildById('nameLabel'):setText(v[2])
itemBox:getChildById('weightLabel'):setText(string.format("%.2f", v[3]/100) .. " oz")
itemBox:getChildById('priceLabel'):setText(price .. " gold")
itemBox:getChildById('weightLabel'):setText(string.format('%.2f', v[3]/100) .. ' ' .. WEIGHT_UNIT)
itemBox:getChildById('priceLabel'):setText(price .. ' ' .. CURRENCY)
itemBox.onMouseRelease = NPCTrade.itemPopup
itemBox:getChildById('item').onMouseRelease = function (self, mousePosition, mouseButton) NPCTrade.itemPopup(itemBox, mousePosition, mouseButton) end
@ -282,7 +290,7 @@ function NPCTrade.refreshFilters()
local items = itemsPanel:getChildCount()
for i = 1, items do
local itemWidget = itemsPanel:getChildByIndex(i)
if filter ~= "" then
if filter ~= '' then
if string.find(itemWidget.offer[2], filter) and NPCTrade.extraFilters(itemWidget, showOnlyHolding) then
itemWidget:show()
else
@ -325,9 +333,9 @@ end
function NPCTrade.onPlayerGoods(money, goods)
moneyGoods = money
moneyLabel:setText(money .. " gold")
moneyLabel:setText(money .. ' ' .. CURRENCY)
local freeCapacity = g_game.getLocalPlayer():getFreeCapacity()
capacityLabel:setText(string.format("%.2f", freeCapacity) .. " oz")
capacityLabel:setText(string.format('%.2f', freeCapacity) .. ' ' .. WEIGHT_UNIT)
cacheGoods = {}
for i,v in pairs(goods) do

@ -85,7 +85,7 @@ MainWindow
anchors.left: parent.left
anchors.top: prev.bottom
text-auto-resize: true
margin-top: 5
margin-top: 7
margin-left: 2
TextEdit
@ -93,6 +93,7 @@ MainWindow
width: 200
anchors.left: prev.right
anchors.top: prev.top
margin-top: -2
margin-left: 5
@onTextChange: NPCTrade.refreshFilters()
@ -136,7 +137,7 @@ MainWindow
Label
id: quantityLabel
text: Quantity
text: Quantity:
anchors.left: parent.left
anchors.top: parent.top
text-auto-resize: true
@ -160,60 +161,60 @@ MainWindow
Label
id: nameLabel
text: Name
text: Name:
anchors.left: parent.left
anchors.top: prev.bottom
text-auto-resize: true
margin-top: 5
margin-left: 2
width: 64
NPCOfferLabel
id: name
Label
id: priceLabel
text: Price
text: Price:
anchors.left: parent.left
anchors.top: prev.bottom
text-auto-resize: true
margin-top: 5
margin-left: 2
width: 64
NPCOfferLabel
id: price
Label
id: moneyLabel
text: Money
text: Money:
anchors.left: parent.left
anchors.top: prev.bottom
text-auto-resize: true
margin-top: 5
margin-left: 2
margin-left: 2
width: 64
NPCOfferLabel
id: money
Label
id: weightLabel
text: Weight
text: Weight:
anchors.left: parent.left
anchors.top: prev.bottom
text-auto-resize: true
margin-top: 5
margin-left: 2
width: 64
NPCOfferLabel
id: weight
Label
id: capacityLabel
text: Capacity
text: Capacity:
anchors.left: parent.left
anchors.top: prev.bottom
text-auto-resize: true
margin-top: 5
margin-left: 2
width: 64
NPCOfferLabel
id: capacity
@ -232,3 +233,4 @@ MainWindow
anchors.right: parent.right
anchors.bottom: parent.bottom
@onClick: NPCTrade.hide()

Loading…
Cancel
Save