npctrade reworked, still need skin changes, and grey shader for items

master
Henrique Santiago 12 years ago
parent dc0ade2bd0
commit 8d0f07255d

@ -32,16 +32,16 @@ function UIGameMap:onDrop(widget, mousePos)
local tile = self:getTile(mousePos) local tile = self:getTile(mousePos)
if not tile then return false end if not tile then return false end
local item = widget.currentDragThing local thing = widget.currentDragThing
local toPos = tile:getPosition() local toPos = tile:getPosition()
local itemPos = item:getPosition() local itemPos = thing:getPosition()
if itemPos.x == toPos.x and itemPos.y == toPos.y and itemPos.z == toPos.z then return false end if itemPos.x == toPos.x and itemPos.y == toPos.y and itemPos.z == toPos.z then return false end
if item:getCount() > 1 then if thing:asItem() and thing:getCount() > 1 then
GameInterface.moveStackableItem(item, toPos) GameInterface.moveStackableItem(thing, toPos)
else else
g_game.move(item, toPos, 1) g_game.move(thing, toPos, 1)
end end
return true return true

@ -1,33 +1,201 @@
NPCTrade = {} NPCTrade = {}
-- private variables
local BUY = 1
local SELL = 2
local CURRENCY = 'gold'
local WEIGHT_UNIT = 'oz'
local LAST_INVENTORY = 10
local npcWindow local npcWindow
local itemsPanel local itemsPanel
local radioTabs local radioTabs
local radioItems local radioItems
local buyTab
local sellTab
local searchText local searchText
local setupPanel local setupPanel
local quantity local quantity
local quantityScroll local quantityScroll
local nameLabel local nameLabel
local priceLabel local priceLabel
local moneyGoods
local moneyLabel local moneyLabel
local weightLabel local weightLabel
local capacityLabel local capacityLabel
local offerSelected local tradeButton
local setupButton local buyTab
local cacheItems local sellTab
local cacheGoods
local buyWithBackpack = false local buyWithBackpack
local ignoreCapacity = false local ignoreCapacity
local ignoreEquipped = true local ignoreEquipped
local showOnlyHolding = false local showAllItems
local CURRENCY = 'gold' local playerFreeCapacity
local WEIGHT_UNIT = 'oz' local playerMoney
local tradeItems = {}
local playerItems
local selectedItem
-- private functions
local function clearSelectedItem()
nameLabel:clearText()
weightLabel:clearText()
priceLabel:clearText()
quantityLabel:clearText()
tradeButton:disable()
quantityScroll:setMaximum(1)
if selectedItem then
radioItems:selectWidget(nil)
selectedItem = nil
end
end
local function getCurrentTradeType()
if tradeButton:getText() == tr('Buy') then
return BUY
else
return SELL
end
end
local function getItemPrice(item)
if getCurrentTradeType() == BUY then
if buyWithBackpack:isChecked() then
if item.ptr:isStackable() then
return item.price*quantityScroll:getValue() + 20;
else
return item.price*quantityScroll:getValue() + math.ceil(quantityScroll:getValue()/20)*20
end
end
end
return item.price*quantityScroll:getValue()
end
local function getSellQuantity(item)
if not playerItems[item.ptr:getId()] then
return 0
end
local removeAmount = 0
if ignoreEquipped:isChecked() then
local localPlayer = g_game.getLocalPlayer()
for i=1,LAST_INVENTORY do
local inventoryItem = localPlayer:getInventoryItem(i)
if inventoryItem and inventoryItem:getId() == item.ptr:getId() then
removeAmount = removeAmount + inventoryItem:getCount()
end
end
end
return playerItems[item.ptr:getId()] - removeAmount
end
local function canTradeItem(item)
if getCurrentTradeType() == BUY then
return (ignoreCapacity:isChecked() or (not ignoreCapacity:isChecked() and playerFreeCapacity >= item.weight)) and playerMoney >= getItemPrice(item)
else
return getSellQuantity(item) > 0
end
end
local function refreshItem(item)
nameLabel:setText(item.name)
weightLabel:setText(string.format('%.2f', item.weight) .. ' ' .. WEIGHT_UNIT)
priceLabel:setText(getItemPrice(item) .. ' ' .. CURRENCY)
quantityLabel:setText(1)
quantityScroll:setValue(1)
if getCurrentTradeType() == BUY then
local capacityMaxCount = math.floor(playerFreeCapacity / item.weight)
if ignoreCapacity:isChecked() then
capacityMaxCount = 100
end
local priceMaxCount = math.floor(playerMoney / getItemPrice(item))
quantityScroll:setMaximum(math.max(0, math.min(100, math.min(priceMaxCount, capacityMaxCount))))
else
local removeAmount = 0
if ignoreEquipped:isChecked() then
local localPlayer = g_game.getLocalPlayer()
for i=1,LAST_INVENTORY do
local inventoryItem = localPlayer:getInventoryItem(i)
if inventoryItem and inventoryItem:getId() == item.ptr:getId() then
removeAmount = removeAmount + inventoryItem:getCount()
end
end
end
quantityScroll:setMaximum(math.max(0, math.min(100, getSellQuantity(item))))
end
setupPanel:enable()
end
local function refreshTradeItems()
local layout = itemsPanel:getLayout()
layout:disableUpdates()
clearSelectedItem()
searchText:clearText()
setupPanel:disable()
itemsPanel:destroyChildren()
if radioItems then
radioItems:destroy()
end
radioItems = RadioGroup.create()
local currentTradeItems = tradeItems[getCurrentTradeType()]
for key,item in pairs(currentTradeItems) do
local itemBox = createWidget('NPCItemBox', itemsPanel)
itemBox.item = item
itemBox:getChildById('item'):setItem(item.ptr)
itemBox:getChildById('nameLabel'):setText(item.name)
itemBox:getChildById('weightLabel'):setText(string.format('%.2f', item.weight) .. ' ' .. WEIGHT_UNIT)
itemBox:getChildById('priceLabel'):setText(item.price .. ' ' .. CURRENCY)
itemBox.onMouseRelease = NPCTrade.itemPopup
itemBox:getChildById('item').onMouseRelease = function(self, mousePosition, mouseButton) NPCTrade.itemPopup(itemBox, mousePosition, mouseButton) end
radioItems:addWidget(itemBox)
end
layout:enableUpdates()
layout:update()
end
local function refreshPlayerGoods()
moneyLabel:setText(playerMoney .. ' ' .. CURRENCY)
capacityLabel:setText(string.format('%.2f', playerFreeCapacity) .. ' ' .. WEIGHT_UNIT)
local currentTradeType = getCurrentTradeType()
local searchFilter = searchText:getText()
local foundSelectedItem = false
local items = itemsPanel:getChildCount()
for i=1,items do
local itemWidget = itemsPanel:getChildByIndex(i)
local item = itemWidget.item
local canTrade = canTradeItem(item)
itemWidget:setEnabled(canTrade)
local searchCondition = (searchFilter == '') or (searchFilter ~= '' and string.find(item.name, searchFilter) ~= nil)
local showAllItemsCondition = (currentTradeType == BUY) or (showAllItems:isChecked()) or (currentTradeType == SELL and not showAllItems:isChecked() and canTrade)
itemWidget:setVisible(searchCondition and showAllItemsCondition)
if selectedItem == item and itemWidget:isEnabled() and itemWidget:isVisible() then
foundSelectedItem = true
end
end
if not foundSelectedItem then
clearSelectedItem()
end
if selectedItem then
refreshItem(selectedItem)
end
end
-- public functions -- public functions
function NPCTrade.init() function NPCTrade.init()
@ -38,9 +206,7 @@ function NPCTrade.init()
npcWindow:setVisible(false) npcWindow:setVisible(false)
itemsPanel = npcWindow:recursiveGetChildById('itemsPanel') itemsPanel = npcWindow:recursiveGetChildById('itemsPanel')
buyTab = npcWindow:getChildById('buyTab') searchText = npcWindow:recursiveGetChildById('searchText')
sellTab = npcWindow:getChildById('sellTab')
searchText = npcWindow:getChildById('searchText')
setupPanel = npcWindow:recursiveGetChildById('setupPanel') setupPanel = npcWindow:recursiveGetChildById('setupPanel')
quantityLabel = setupPanel:getChildById('quantity') quantityLabel = setupPanel:getChildById('quantity')
@ -50,18 +216,33 @@ function NPCTrade.init()
moneyLabel = setupPanel:getChildById('money') moneyLabel = setupPanel:getChildById('money')
weightLabel = setupPanel:getChildById('weight') weightLabel = setupPanel:getChildById('weight')
capacityLabel = setupPanel:getChildById('capacity') capacityLabel = setupPanel:getChildById('capacity')
setupButton = setupPanel:getChildById('setupButton') tradeButton = npcWindow:recursiveGetChildById('tradeButton')
buyWithBackpack = npcWindow:recursiveGetChildById('buyWithBackpack')
ignoreCapacity = npcWindow:recursiveGetChildById('ignoreCapacity')
ignoreEquipped = npcWindow:recursiveGetChildById('ignoreEquipped')
showAllItems = npcWindow:recursiveGetChildById('showAllItems')
buyTab = npcWindow:getChildById('buyTab')
sellTab = npcWindow:getChildById('sellTab')
radioTabs = RadioGroup.create() radioTabs = RadioGroup.create()
radioTabs:addWidget(buyTab) radioTabs:addWidget(buyTab)
radioTabs:addWidget(sellTab) radioTabs:addWidget(sellTab)
radioTabs:selectWidget(buyTab) radioTabs:selectWidget(buyTab)
radioTabs.onSelectionChange = NPCTrade.setList radioTabs.onSelectionChange = NPCTrade.onTradeTypeChange
if g_game.isOnline() then -- event wont be sent again when reloading modules
playerFreeCapacity = g_game.getLocalPlayer():getFreeCapacity()
end
connect(g_game, { onGameEnd = NPCTrade.hide, connect(g_game, { onGameEnd = NPCTrade.hide,
onOpenNpcTrade = NPCTrade.onOpenNpcTrade, onOpenNpcTrade = NPCTrade.onOpenNpcTrade,
onPlayerGoods = NPCTrade.onPlayerGoods, onCloseNpcTrade = NPCTrade.onCloseNpcTrade,
onCloseNpcTrade = NPCTrade.onCloseNpcTrade } ) onPlayerGoods = NPCTrade.onPlayerGoods } )
connect(LocalPlayer, { onFreeCapacityChange = NPCTrade.onFreeCapacityChange,
onInventoryChange = NPCTrade.onInventoryChange } )
end end
function NPCTrade.terminate() function NPCTrade.terminate()
@ -73,6 +254,8 @@ function NPCTrade.terminate()
buyButton = nil buyButton = nil
sellButton = nil sellButton = nil
searchText = nil searchText = nil
buyTab = nil
sellTab = nil
setupPanel = nil setupPanel = nil
quantityLabel = nil quantityLabel = nil
@ -83,24 +266,28 @@ function NPCTrade.terminate()
weightLabel = nil weightLabel = nil
capacityLabel = nil capacityLabel = nil
offerSelected = nil offerSelected = nil
setupButton = nil tradeButton = nil
cacheItems = nil
cacheGoods = nil
buyTab = nil
sellTab = nil
disconnect(g_game, { onGameEnd = NPCTrade.hide, disconnect(g_game, { onGameEnd = NPCTrade.hide,
onOpenNpcTrade = NPCTrade.onOpenNpcTrade, onOpenNpcTrade = NPCTrade.onOpenNpcTrade,
onCloseNpcTrade = NPCTrade.onCloseNpcTrade,
onPlayerGoods = NPCTrade.onPlayerGoods, onPlayerGoods = NPCTrade.onPlayerGoods,
onCloseNpcTrade = NPCTrade.onCloseNpcTrade } ) onFreeCapacityChange = NPCTrade.onFreeCapacityChange } )
disconnect(LocalPlayer, { onFreeCapacityChange = NPCTrade.onFreeCapacityChange,
onInventoryChange = NPCTrade.onInventoryChange } )
NPCTrade = nil NPCTrade = nil
end end
-- private functions
function NPCTrade.show() function NPCTrade.show()
if g_game.isOnline() then if g_game.isOnline() then
if #tradeItems[BUY] > 0 then
radioTabs:selectWidget(buyTab)
else
radioTabs:selectWidget(sellTab)
end
npcWindow:show() npcWindow:show()
npcWindow:raise() npcWindow:raise()
end end
@ -110,246 +297,132 @@ function NPCTrade.hide()
npcWindow:hide() npcWindow:hide()
end end
function NPCTrade.setList(radioTabs, selected, deselected) function NPCTrade.onItemBoxChecked(widget)
setupButton:setText(selected:getText()) if widget:isChecked() then
selected:setOn(true) local item = widget.item
deselected:setOn(false) selectedItem = item
NPCTrade.createItemsOnPanel() refreshItem(item)
tradeButton:enable()
NPCTrade.resetSetup()
NPCTrade.refreshItemsPanel()
NPCTrade.refreshFilters()
end
function NPCTrade.resetSetup()
nameLabel:clearText()
weightLabel:clearText()
priceLabel:clearText()
searchText:clearText()
if offerSelected then
radioItems.selectedWidget:setChecked(false)
offerSelected = nil
end end
setupPanel:disable()
end end
function NPCTrade.updateSetup() function NPCTrade.onQuantityValueChange(quantity)
if offerSelected then if quantityLabel and selectedItem then
if radioItems.selectedWidget:isEnabled() then quantityLabel:setText(quantity)
if setupButton:getText() == tr('Buy') then weightLabel:setText(string.format('%.2f', selectedItem.weight*quantity) .. ' ' .. WEIGHT_UNIT)
local capacityMaxCount = math.floor(100*g_game.getLocalPlayer():getFreeCapacity()/offerSelected[3]) priceLabel:setText(getItemPrice(selectedItem) .. ' ' .. CURRENCY)
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()
end
end
end
function NPCTrade.getOfferPrice(offer)
if setupButton:getText() == tr('Buy') then
local price = offer[4]
if buyWithBackpack then
if offer[1]:isStackable() then
return price*quantityScroll:getValue() + 20;
else
return price*quantityScroll:getValue() + math.ceil(quantityScroll:getValue()/20)*20
end
else
return price*quantityScroll:getValue()
end
else
return offer[5]*quantityScroll:getValue()
end end
end end
function NPCTrade.setItem(widget) function NPCTrade.onTradeTypeChange(radioTabs, selected, deselected)
offerSelected = widget.offer tradeButton:setText(selected:getText())
selected:setOn(true)
local offer = widget.offer deselected:setOn(false)
local price = NPCTrade.getOfferPrice(widget.offer)
local freeCapacity = g_game.getLocalPlayer():getFreeCapacity()
nameLabel:setText(offer[2])
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)
NPCTrade.updateSetup()
setupPanel:enable() local currentTradeType = getCurrentTradeType()
end buyWithBackpack:setVisible(currentTradeType == BUY)
ignoreCapacity:setVisible(currentTradeType == BUY)
ignoreEquipped:setVisible(currentTradeType == SELL)
showAllItems:setVisible(currentTradeType == SELL)
function NPCTrade.setQuantity(quantity) refreshTradeItems()
if quantityLabel and offerSelected then refreshPlayerGoods()
local price = NPCTrade.getOfferPrice(offerSelected)
quantityLabel:setText(quantity)
weightLabel:setText(string.format('%.2f', offerSelected[3]*quantity/100) .. ' ' .. WEIGHT_UNIT)
priceLabel:setText(price .. ' ' .. CURRENCY)
end
end end
function NPCTrade.setupButton() function NPCTrade.onTradeClick()
if setupButton:getText() == 'Buy' then if getCurrentTradeType() == BUY then
g_game.buyItem(offerSelected[1], quantityScroll:getValue(), buyWithBackpack, ignoreCapacity) g_game.buyItem(selectedItem.ptr, quantityScroll:getValue(), buyWithBackpack:isChecked(), ignoreCapacity:isChecked())
else else
g_game.sellItem(offerSelected[1], quantityScroll:getValue(), ignoreEquipped) g_game.sellItem(selectedItem.ptr, quantityScroll:getValue(), ignoreEquipped:isChecked())
end end
end end
function NPCTrade.onOpenNpcTrade(items) function NPCTrade.onSearchTextChange()
-- items[item] = item refreshPlayerGoods()
-- item[1] = ItemPtr
-- item[2] = name
-- item[3] = weight
-- item[4] = buyPrice
-- item[5] = sellPrice
cacheItems = items
NPCTrade.createItemsOnPanel()
NPCTrade.show()
end
function NPCTrade.switchBuyWithBackpack()
buyWithBackpack = not buyWithBackpack
if offerSelected then
priceLabel:setText(NPCTrade.getOfferPrice(offerSelected) .. ' ' .. CURRENCY)
end
return true
end end
function NPCTrade.itemPopup(self, mousePosition, mouseButton) function NPCTrade.itemPopup(self, mousePosition, mouseButton)
if mouseButton == MouseRightButton then if mouseButton == MouseRightButton then
local menu = createWidget('PopupMenu') local menu = createWidget('PopupMenu')
menu:addOption(tr('Look'), function() return g_game.inspectNpcTrade(self.offer[1]) end) menu:addOption(tr('Look'), function() return g_game.inspectNpcTrade(self.offer[1]) end)
menu:addSeparator()
if setupButton:getText() == tr('Buy') then
menu:addOption((buyWithBackpack and tr('Buy no backpack') or tr('Buy with backpack')), NPCTrade.switchBuyWithBackpack)
menu:addOption((ignoreCapacity and tr('Consider capacity') or tr('Ignore capacity')), function() ignoreCapacity = not ignoreCapacity return true end)
else
menu:addOption((ignoreEquipped and tr('Consider equipped') or tr('Ignore equipped')), function() ignoreEquipped = not ignoreEquipped return true end)
menu:addOption((showOnlyHolding and tr('Show all items') or tr('Show only holding items')), function() showOnlyHolding = not showOnlyHolding NPCTrade.refreshFilters() return true end)
end
menu:display(mousePosition) menu:display(mousePosition)
end end
end end
function NPCTrade.createItemsOnPanel() function NPCTrade.onBuyWithBackpackChange()
local layout = itemsPanel:getLayout() if selectedItem then
layout:disableUpdates() refreshItem(selectedItem)
NPCTrade.resetSetup()
offerSelected = nil
itemsPanel:destroyChildren()
if radioItems then
radioItems:destroy()
end end
radioItems = RadioGroup.create() end
for i, v in pairs(cacheItems) do
local price = NPCTrade.getOfferPrice(v)
if price > 0 then
local itemBox = createWidget('NPCItemBox', itemsPanel)
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) .. ' ' .. WEIGHT_UNIT)
itemBox:getChildById('priceLabel'):setText(price .. ' ' .. CURRENCY)
itemBox.onMouseRelease = NPCTrade.itemPopup function NPCTrade.onIgnoreCapacityChange()
itemBox:getChildById('item').onMouseRelease = function (self, mousePosition, mouseButton) NPCTrade.itemPopup(itemBox, mousePosition, mouseButton) end refreshPlayerGoods()
end
radioItems:addWidget(itemBox) function NPCTrade.onIgnoreEquippedChange()
end refreshPlayerGoods()
end end
layout:enableUpdates() function NPCTrade.onShowAllItemsChange()
layout:update() refreshPlayerGoods()
end end
function NPCTrade.extraFilters(widget, showOnlyHolding) -- hooked functions
if setupButton:getText() == tr('Sell') then function NPCTrade.onOpenNpcTrade(items)
if not showOnlyHolding or cacheGoods[widget.offer[1]:getId()] then tradeItems[BUY] = {}
return true tradeItems[SELL] = {}
for key,item in pairs(items) do
local newItem = {}
newItem.ptr = item[1]
newItem.name = item[2]
newItem.weight = item[3] / 100
if item[4] >= 0 then
newItem.price = item[4]
table.insert(tradeItems[BUY], newItem)
elseif item[5] >= 0 then
newItem.price = item[5]
table.insert(tradeItems[SELL], newItem)
else else
return false error("server error: item name " .. item[1] .. " has neither buy or sell price.")
end end
end end
return true refreshTradeItems()
addEvent(NPCTrade.show) -- player goods has not been parsed yet
end end
function NPCTrade.refreshFilters() function NPCTrade.onCloseNpcTrade()
local filter = searchText:getText() NPCTrade.hide()
local items = itemsPanel:getChildCount()
for i = 1, items do
local itemWidget = itemsPanel:getChildByIndex(i)
if filter ~= '' then
if string.find(itemWidget.offer[2], filter) and NPCTrade.extraFilters(itemWidget, showOnlyHolding) then
itemWidget:show()
else
itemWidget:hide()
end
else
if NPCTrade.extraFilters(itemWidget, showOnlyHolding) then
itemWidget:show()
else
itemWidget:hide()
end
end
end
end end
function NPCTrade.refreshItemsPanel() function NPCTrade.onPlayerGoods(money, items)
if setupButton:getText() == tr('Buy') then playerMoney = money
local items = itemsPanel:getChildCount()
for i = 1, items do playerItems = {}
local itemWidget = itemsPanel:getChildByIndex(i) for key,item in pairs(items) do
if moneyGoods < NPCTrade.getOfferPrice(itemWidget.offer) then local id = item[1]:getId()
itemWidget:disable() if not playerItems[id] then
else playerItems[id] = item[2]
itemWidget:enable() else
end playerItems[id] = playerItems[id] + item[2]
end
else
local items = itemsPanel:getChildCount()
for i = 1, items do
local itemWidget = itemsPanel:getChildByIndex(i)
if cacheGoods[itemWidget.offer[1]:getId()] then
itemWidget:enable()
else
itemWidget:disable()
end
end end
end end
end
function NPCTrade.onPlayerGoods(money, goods) refreshPlayerGoods()
moneyGoods = money end
moneyLabel:setText(money .. ' ' .. CURRENCY) function NPCTrade.onFreeCapacityChange(localPlayer, freeCapacity, oldFreeCapacity)
local freeCapacity = g_game.getLocalPlayer():getFreeCapacity() playerFreeCapacity = freeCapacity
capacityLabel:setText(string.format('%.2f', freeCapacity) .. ' ' .. WEIGHT_UNIT)
cacheGoods = {} if npcWindow:isVisible() then
for i,v in pairs(goods) do refreshPlayerGoods()
cacheGoods[v[1]:getId()] = v[2]
end end
NPCTrade.refreshItemsPanel()
NPCTrade.updateSetup()
end end
function NPCTrade.onCloseNpcTrade() function NPCTrade.onInventoryChange(inventory, item, oldeItem)
NPCTrade.hide() if selectedItem then
refreshItem(selectedItem)
end
end end

@ -4,21 +4,17 @@ NPCOfferLabel < Label
margin-left: 5 margin-left: 5
text-auto-resize: true text-auto-resize: true
NPCPanel < ScrollablePanel
image-source: /core_styles/styles/images/panel_flat.png
image-border: 1
NPCItemBox < UICheckBox NPCItemBox < UICheckBox
border-width: 1 border-width: 1
border-color: #000000 border-color: #000000
@onCheckChange: NPCTrade.setItem(self) @onCheckChange: NPCTrade.onItemBoxChecked(self)
Item Item
id: item id: item
phantom: true phantom: true
anchors.top: parent.top anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
margin-top: 2 margin-top: 3
Label Label
id: nameLabel id: nameLabel
@ -26,7 +22,7 @@ NPCItemBox < UICheckBox
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
text-auto-resize: true text-auto-resize: true
margin-top: 5 margin-top: 3
Label Label
id: weightLabel id: weightLabel
@ -34,7 +30,7 @@ NPCItemBox < UICheckBox
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
text-auto-resize: true text-auto-resize: true
margin-top: 5 margin-top: 3
Label Label
id: priceLabel id: priceLabel
@ -42,7 +38,7 @@ NPCItemBox < UICheckBox
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
text-auto-resize: true text-auto-resize: true
margin-top: 5 margin-top: 3
$checked: $checked:
border-color: #FFFFFF border-color: #FFFFFF
@ -53,7 +49,7 @@ NPCItemBox < UICheckBox
MainWindow MainWindow
id: npcWindow id: npcWindow
!text: tr('NPC Trade') !text: tr('NPC Trade')
size: 550 550 size: 550 515
@onEscape: NPCTrade.hide() @onEscape: NPCTrade.hide()
@ -79,40 +75,24 @@ MainWindow
margin-left: 5 margin-left: 5
margin-top: 5 margin-top: 5
Label Panel
id: searchLabel
!text: tr('Search:')
anchors.left: parent.left
anchors.top: prev.bottom
text-auto-resize: true
margin-top: 7
margin-left: 2
TextEdit
id: searchText
width: 200
anchors.left: prev.right
anchors.top: prev.top
margin-top: -2
margin-left: 5
@onTextChange: NPCTrade.refreshFilters()
NPCPanel
height: 250 height: 250
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 5 margin-top: 10
image-source: /core_styles/styles/images/panel_flat.png
image-border: 1
VerticalScrollBar VerticalScrollBar
id: itemsPanelListScrollBar id: itemsPanelListScrollBar
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.right: parent.right anchors.right: parent.right
step: 14 step: 16
pixels-scroll: true pixels-scroll: true
NPCPanel ScrollablePanel
id: itemsPanel id: itemsPanel
height: 250 height: 250
anchors.left: parent.left anchors.left: parent.left
@ -120,6 +100,8 @@ MainWindow
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
vertical-scrollbar: itemsPanelListScrollBar vertical-scrollbar: itemsPanelListScrollBar
margin-left: 5
margin-right: 5
layout: layout:
type: grid type: grid
cell-size: 160 90 cell-size: 160 90
@ -128,104 +110,171 @@ MainWindow
FlatPanel FlatPanel
id: setupPanel id: setupPanel
height: 150 height: 140
enabled: false enabled: false
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.horizontalCenter
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 5 margin-top: 10
margin-right: 5
Label Label
id: quantityLabel !text: tr('Name:')
!text: tr('Quantity:')
anchors.left: parent.left anchors.left: parent.left
anchors.top: parent.top anchors.top: parent.top
text-auto-resize: true
margin-top: 5 margin-top: 5
margin-left: 2 margin-left: 5
width: 85
NPCOfferLabel NPCOfferLabel
id: quantity id: name
HorizontalScrollBar Label
id: quantityScroll !text: tr('Price:')
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 2 margin-top: 5
minimum: 1 margin-left: 5
maximum: 100 width: 85
value: 1
step: 1 NPCOfferLabel
@onValueChange: NPCTrade.setQuantity(self:getValue()) id: price
Label Label
id: nameLabel !text: tr('Your Money:')
!text: tr('Name:')
anchors.left: parent.left anchors.left: parent.left
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 5 margin-top: 5
margin-left: 2 margin-left: 5
width: 64 width: 85
NPCOfferLabel NPCOfferLabel
id: name id: money
Label Label
id: priceLabel !text: tr('Weight:')
!text: tr('Price:')
anchors.left: parent.left anchors.left: parent.left
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 5 margin-top: 5
margin-left: 2 margin-left: 5
width: 64 width: 85
NPCOfferLabel NPCOfferLabel
id: price id: weight
Label Label
id: moneyLabel !text: tr('Your Capacity:')
!text: tr('Money:')
anchors.left: parent.left anchors.left: parent.left
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 5 margin-top: 5
margin-left: 2 margin-left: 5
width: 64 width: 85
NPCOfferLabel NPCOfferLabel
id: money id: capacity
Label Label
id: weightLabel !text: tr('Quantity:')
!text: tr('Weight:')
anchors.left: parent.left anchors.left: parent.left
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 5 margin-top: 5
margin-left: 2 margin-left: 5
width: 64 width: 85
NPCOfferLabel NPCOfferLabel
id: weight id: quantity
HorizontalScrollBar
id: quantityScroll
anchors.left: parent.left
anchors.right: parent.right
anchors.top: prev.bottom
margin-top: 5
margin-left: 5
margin-right: 5
minimum: 1
maximum: 100
step: 1
@onValueChange: NPCTrade.onQuantityValueChange(self:getValue())
FlatPanel
id: buyOptions
height: 140
anchors.top: prev.top
anchors.left: parent.horizontalCenter
anchors.right: parent.right
margin-left: 5
Label Label
id: capacityLabel id: searchLabel
!text: tr('Capacity:') !text: tr('Search:')
anchors.left: parent.left anchors.left: parent.left
anchors.top: parent.top
text-auto-resize: true
margin-top: 7
margin-left: 5
TextEdit
id: searchText
anchors.left: prev.right
anchors.top: prev.top
anchors.right: parent.right
margin-top: -2
margin-left: 5
margin-right: 5
@onTextChange: NPCTrade.onSearchTextChange()
CheckBox
id: buyWithBackpack
!text: tr('Buy with backpack')
anchors.top: searchText.bottom
anchors.left: parent.left
anchors.right: parent.right
margin-left: 5
margin-top: 5
@onCheckChange: NPCTrade.onBuyWithBackpackChange()
CheckBox
id: ignoreCapacity
!text: tr('Ignore capacity')
anchors.top: prev.bottom anchors.top: prev.bottom
anchors.left: parent.left
anchors.right: parent.right
margin-left: 5
margin-top: 5 margin-top: 5
margin-left: 2 @onCheckChange: NPCTrade.onIgnoreCapacityChange()
width: 64
NPCOfferLabel CheckBox
id: capacity id: ignoreEquipped
!text: tr('Ignore equipped')
anchors.top: searchText.bottom
anchors.left: parent.left
anchors.right: parent.right
margin-left: 5
margin-top: 5
visible: false
checked: true
@onCheckChange: NPCTrade.onIgnoreEquippedChange()
Button CheckBox
id: setupButton id: showAllItems
!text: tr('Buy') !text: tr('Show all items')
width: 64
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: prev.bottom anchors.top: prev.bottom
@onClick: NPCTrade.setupButton() anchors.left: parent.left
anchors.right: parent.right
margin-left: 5
margin-top: 5
visible: false
@onCheckChange: NPCTrade.onShowAllItemsChange()
Button
id: tradeButton
!text: tr('Buy')
width: 64
anchors.right: next.left
anchors.bottom: parent.bottom
margin-right: 10
@onClick: NPCTrade.onTradeClick()
Button Button
!text: tr('Close') !text: tr('Close')
@ -233,4 +282,3 @@ MainWindow
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@onClick: NPCTrade.hide() @onClick: NPCTrade.hide()

Loading…
Cancel
Save