diff --git a/modules/game/widgets/uigamemap.lua b/modules/game/widgets/uigamemap.lua index 5bf80788..367da448 100644 --- a/modules/game/widgets/uigamemap.lua +++ b/modules/game/widgets/uigamemap.lua @@ -32,16 +32,16 @@ function UIGameMap:onDrop(widget, mousePos) local tile = self:getTile(mousePos) if not tile then return false end - local item = widget.currentDragThing + local thing = widget.currentDragThing 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 item:getCount() > 1 then - GameInterface.moveStackableItem(item, toPos) + if thing:asItem() and thing:getCount() > 1 then + GameInterface.moveStackableItem(thing, toPos) else - g_game.move(item, toPos, 1) + g_game.move(thing, toPos, 1) end return true diff --git a/modules/game_npctrade/npctrade.lua b/modules/game_npctrade/npctrade.lua index b9d0e1da..82285c5e 100644 --- a/modules/game_npctrade/npctrade.lua +++ b/modules/game_npctrade/npctrade.lua @@ -1,33 +1,201 @@ NPCTrade = {} +-- private variables +local BUY = 1 +local SELL = 2 +local CURRENCY = 'gold' +local WEIGHT_UNIT = 'oz' +local LAST_INVENTORY = 10 + local npcWindow local itemsPanel local radioTabs local radioItems -local buyTab -local sellTab local searchText local setupPanel local quantity local quantityScroll local nameLabel local priceLabel -local moneyGoods local moneyLabel local weightLabel local capacityLabel -local offerSelected -local setupButton -local cacheItems -local cacheGoods +local tradeButton +local buyTab +local sellTab -local buyWithBackpack = false -local ignoreCapacity = false -local ignoreEquipped = true -local showOnlyHolding = false +local buyWithBackpack +local ignoreCapacity +local ignoreEquipped +local showAllItems -local CURRENCY = 'gold' -local WEIGHT_UNIT = 'oz' +local playerFreeCapacity +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 function NPCTrade.init() @@ -38,9 +206,7 @@ function NPCTrade.init() npcWindow:setVisible(false) itemsPanel = npcWindow:recursiveGetChildById('itemsPanel') - buyTab = npcWindow:getChildById('buyTab') - sellTab = npcWindow:getChildById('sellTab') - searchText = npcWindow:getChildById('searchText') + searchText = npcWindow:recursiveGetChildById('searchText') setupPanel = npcWindow:recursiveGetChildById('setupPanel') quantityLabel = setupPanel:getChildById('quantity') @@ -50,18 +216,33 @@ function NPCTrade.init() moneyLabel = setupPanel:getChildById('money') weightLabel = setupPanel:getChildById('weight') 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:addWidget(buyTab) radioTabs:addWidget(sellTab) 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, onOpenNpcTrade = NPCTrade.onOpenNpcTrade, - onPlayerGoods = NPCTrade.onPlayerGoods, - onCloseNpcTrade = NPCTrade.onCloseNpcTrade } ) + onCloseNpcTrade = NPCTrade.onCloseNpcTrade, + onPlayerGoods = NPCTrade.onPlayerGoods } ) + + connect(LocalPlayer, { onFreeCapacityChange = NPCTrade.onFreeCapacityChange, + onInventoryChange = NPCTrade.onInventoryChange } ) end function NPCTrade.terminate() @@ -73,6 +254,8 @@ function NPCTrade.terminate() buyButton = nil sellButton = nil searchText = nil + buyTab = nil + sellTab = nil setupPanel = nil quantityLabel = nil @@ -83,24 +266,28 @@ function NPCTrade.terminate() weightLabel = nil capacityLabel = nil offerSelected = nil - setupButton = nil - - cacheItems = nil - cacheGoods = nil - buyTab = nil - sellTab = nil + tradeButton = nil disconnect(g_game, { onGameEnd = NPCTrade.hide, onOpenNpcTrade = NPCTrade.onOpenNpcTrade, + onCloseNpcTrade = NPCTrade.onCloseNpcTrade, onPlayerGoods = NPCTrade.onPlayerGoods, - onCloseNpcTrade = NPCTrade.onCloseNpcTrade } ) + onFreeCapacityChange = NPCTrade.onFreeCapacityChange } ) + + disconnect(LocalPlayer, { onFreeCapacityChange = NPCTrade.onFreeCapacityChange, + onInventoryChange = NPCTrade.onInventoryChange } ) NPCTrade = nil end --- private functions function NPCTrade.show() if g_game.isOnline() then + if #tradeItems[BUY] > 0 then + radioTabs:selectWidget(buyTab) + else + radioTabs:selectWidget(sellTab) + end + npcWindow:show() npcWindow:raise() end @@ -110,246 +297,132 @@ function NPCTrade.hide() npcWindow:hide() end -function NPCTrade.setList(radioTabs, selected, deselected) - setupButton:setText(selected:getText()) - selected:setOn(true) - deselected:setOn(false) - NPCTrade.createItemsOnPanel() - - 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 +function NPCTrade.onItemBoxChecked(widget) + if widget:isChecked() then + local item = widget.item + selectedItem = item + refreshItem(item) + tradeButton:enable() end - setupPanel:disable() end -function NPCTrade.updateSetup() - if offerSelected then - if radioItems.selectedWidget:isEnabled() then - if setupButton:getText() == tr('Buy') then - 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() - 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() +function NPCTrade.onQuantityValueChange(quantity) + if quantityLabel and selectedItem then + quantityLabel:setText(quantity) + weightLabel:setText(string.format('%.2f', selectedItem.weight*quantity) .. ' ' .. WEIGHT_UNIT) + priceLabel:setText(getItemPrice(selectedItem) .. ' ' .. CURRENCY) end end -function NPCTrade.setItem(widget) - offerSelected = widget.offer - - local offer = widget.offer - 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() +function NPCTrade.onTradeTypeChange(radioTabs, selected, deselected) + tradeButton:setText(selected:getText()) + selected:setOn(true) + deselected:setOn(false) - setupPanel:enable() -end + local currentTradeType = getCurrentTradeType() + buyWithBackpack:setVisible(currentTradeType == BUY) + ignoreCapacity:setVisible(currentTradeType == BUY) + ignoreEquipped:setVisible(currentTradeType == SELL) + showAllItems:setVisible(currentTradeType == SELL) -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) .. ' ' .. WEIGHT_UNIT) - priceLabel:setText(price .. ' ' .. CURRENCY) - end + refreshTradeItems() + refreshPlayerGoods() end -function NPCTrade.setupButton() - if setupButton:getText() == 'Buy' then - g_game.buyItem(offerSelected[1], quantityScroll:getValue(), buyWithBackpack, ignoreCapacity) +function NPCTrade.onTradeClick() + if getCurrentTradeType() == BUY then + g_game.buyItem(selectedItem.ptr, quantityScroll:getValue(), buyWithBackpack:isChecked(), ignoreCapacity:isChecked()) else - g_game.sellItem(offerSelected[1], quantityScroll:getValue(), ignoreEquipped) + g_game.sellItem(selectedItem.ptr, quantityScroll:getValue(), ignoreEquipped:isChecked()) end end -function NPCTrade.onOpenNpcTrade(items) - -- items[item] = item - -- 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 +function NPCTrade.onSearchTextChange() + refreshPlayerGoods() end function NPCTrade.itemPopup(self, mousePosition, mouseButton) if mouseButton == MouseRightButton then local menu = createWidget('PopupMenu') 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) end end -function NPCTrade.createItemsOnPanel() - local layout = itemsPanel:getLayout() - layout:disableUpdates() - - NPCTrade.resetSetup() - - offerSelected = nil - itemsPanel:destroyChildren() - - if radioItems then - radioItems:destroy() +function NPCTrade.onBuyWithBackpackChange() + if selectedItem then + refreshItem(selectedItem) end - radioItems = RadioGroup.create() - - 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) +end - itemBox.onMouseRelease = NPCTrade.itemPopup - itemBox:getChildById('item').onMouseRelease = function (self, mousePosition, mouseButton) NPCTrade.itemPopup(itemBox, mousePosition, mouseButton) end +function NPCTrade.onIgnoreCapacityChange() + refreshPlayerGoods() +end - radioItems:addWidget(itemBox) - end - end +function NPCTrade.onIgnoreEquippedChange() + refreshPlayerGoods() +end - layout:enableUpdates() - layout:update() +function NPCTrade.onShowAllItemsChange() + refreshPlayerGoods() end -function NPCTrade.extraFilters(widget, showOnlyHolding) - if setupButton:getText() == tr('Sell') then - if not showOnlyHolding or cacheGoods[widget.offer[1]:getId()] then - return true +-- hooked functions +function NPCTrade.onOpenNpcTrade(items) + tradeItems[BUY] = {} + 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 - return false + error("server error: item name " .. item[1] .. " has neither buy or sell price.") end end - return true + refreshTradeItems() + addEvent(NPCTrade.show) -- player goods has not been parsed yet end -function NPCTrade.refreshFilters() - local filter = searchText:getText() - 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 +function NPCTrade.onCloseNpcTrade() + NPCTrade.hide() end -function NPCTrade.refreshItemsPanel() - if setupButton:getText() == tr('Buy') then - local items = itemsPanel:getChildCount() - for i = 1, items do - local itemWidget = itemsPanel:getChildByIndex(i) - if moneyGoods < NPCTrade.getOfferPrice(itemWidget.offer) then - itemWidget:disable() - else - itemWidget:enable() - end - 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 +function NPCTrade.onPlayerGoods(money, items) + playerMoney = money + + playerItems = {} + for key,item in pairs(items) do + local id = item[1]:getId() + if not playerItems[id] then + playerItems[id] = item[2] + else + playerItems[id] = playerItems[id] + item[2] end end -end -function NPCTrade.onPlayerGoods(money, goods) - moneyGoods = money + refreshPlayerGoods() +end - moneyLabel:setText(money .. ' ' .. CURRENCY) - local freeCapacity = g_game.getLocalPlayer():getFreeCapacity() - capacityLabel:setText(string.format('%.2f', freeCapacity) .. ' ' .. WEIGHT_UNIT) +function NPCTrade.onFreeCapacityChange(localPlayer, freeCapacity, oldFreeCapacity) + playerFreeCapacity = freeCapacity - cacheGoods = {} - for i,v in pairs(goods) do - cacheGoods[v[1]:getId()] = v[2] + if npcWindow:isVisible() then + refreshPlayerGoods() end - - NPCTrade.refreshItemsPanel() - NPCTrade.updateSetup() end -function NPCTrade.onCloseNpcTrade() - NPCTrade.hide() +function NPCTrade.onInventoryChange(inventory, item, oldeItem) + if selectedItem then + refreshItem(selectedItem) + end end diff --git a/modules/game_npctrade/npctrade.otui b/modules/game_npctrade/npctrade.otui index f31a7aeb..07511fd7 100644 --- a/modules/game_npctrade/npctrade.otui +++ b/modules/game_npctrade/npctrade.otui @@ -4,21 +4,17 @@ NPCOfferLabel < Label margin-left: 5 text-auto-resize: true -NPCPanel < ScrollablePanel - image-source: /core_styles/styles/images/panel_flat.png - image-border: 1 - NPCItemBox < UICheckBox border-width: 1 border-color: #000000 - @onCheckChange: NPCTrade.setItem(self) + @onCheckChange: NPCTrade.onItemBoxChecked(self) Item id: item phantom: true anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter - margin-top: 2 + margin-top: 3 Label id: nameLabel @@ -26,7 +22,7 @@ NPCItemBox < UICheckBox anchors.top: prev.bottom anchors.horizontalCenter: parent.horizontalCenter text-auto-resize: true - margin-top: 5 + margin-top: 3 Label id: weightLabel @@ -34,7 +30,7 @@ NPCItemBox < UICheckBox anchors.top: prev.bottom anchors.horizontalCenter: parent.horizontalCenter text-auto-resize: true - margin-top: 5 + margin-top: 3 Label id: priceLabel @@ -42,7 +38,7 @@ NPCItemBox < UICheckBox anchors.top: prev.bottom anchors.horizontalCenter: parent.horizontalCenter text-auto-resize: true - margin-top: 5 + margin-top: 3 $checked: border-color: #FFFFFF @@ -53,7 +49,7 @@ NPCItemBox < UICheckBox MainWindow id: npcWindow !text: tr('NPC Trade') - size: 550 550 + size: 550 515 @onEscape: NPCTrade.hide() @@ -79,40 +75,24 @@ MainWindow margin-left: 5 margin-top: 5 - Label - 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 + Panel height: 250 anchors.left: parent.left anchors.right: parent.right anchors.top: prev.bottom - margin-top: 5 + margin-top: 10 + image-source: /core_styles/styles/images/panel_flat.png + image-border: 1 VerticalScrollBar id: itemsPanelListScrollBar anchors.top: parent.top anchors.bottom: parent.bottom anchors.right: parent.right - step: 14 + step: 16 pixels-scroll: true - NPCPanel + ScrollablePanel id: itemsPanel height: 250 anchors.left: parent.left @@ -120,6 +100,8 @@ MainWindow anchors.top: parent.top anchors.bottom: parent.bottom vertical-scrollbar: itemsPanelListScrollBar + margin-left: 5 + margin-right: 5 layout: type: grid cell-size: 160 90 @@ -128,104 +110,171 @@ MainWindow FlatPanel id: setupPanel - height: 150 + height: 140 enabled: false anchors.left: parent.left - anchors.right: parent.right + anchors.right: parent.horizontalCenter anchors.top: prev.bottom - margin-top: 5 + margin-top: 10 + margin-right: 5 Label - id: quantityLabel - !text: tr('Quantity:') + !text: tr('Name:') anchors.left: parent.left anchors.top: parent.top - text-auto-resize: true margin-top: 5 - margin-left: 2 + margin-left: 5 + width: 85 NPCOfferLabel - id: quantity + id: name - HorizontalScrollBar - id: quantityScroll + Label + !text: tr('Price:') anchors.left: parent.left - anchors.right: parent.right anchors.top: prev.bottom - margin-top: 2 - minimum: 1 - maximum: 100 - value: 1 - step: 1 - @onValueChange: NPCTrade.setQuantity(self:getValue()) + margin-top: 5 + margin-left: 5 + width: 85 + + NPCOfferLabel + id: price Label - id: nameLabel - !text: tr('Name:') + !text: tr('Your Money:') anchors.left: parent.left anchors.top: prev.bottom margin-top: 5 - margin-left: 2 - width: 64 + margin-left: 5 + width: 85 NPCOfferLabel - id: name + id: money Label - id: priceLabel - !text: tr('Price:') + !text: tr('Weight:') anchors.left: parent.left anchors.top: prev.bottom margin-top: 5 - margin-left: 2 - width: 64 + margin-left: 5 + width: 85 NPCOfferLabel - id: price + id: weight Label - id: moneyLabel - !text: tr('Money:') + !text: tr('Your Capacity:') anchors.left: parent.left anchors.top: prev.bottom margin-top: 5 - margin-left: 2 - width: 64 + margin-left: 5 + width: 85 NPCOfferLabel - id: money + id: capacity Label - id: weightLabel - !text: tr('Weight:') + !text: tr('Quantity:') anchors.left: parent.left anchors.top: prev.bottom margin-top: 5 - margin-left: 2 - width: 64 + margin-left: 5 + width: 85 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 - id: capacityLabel - !text: tr('Capacity:') + id: searchLabel + !text: tr('Search:') 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.left: parent.left + anchors.right: parent.right + margin-left: 5 margin-top: 5 - margin-left: 2 - width: 64 + @onCheckChange: NPCTrade.onIgnoreCapacityChange() - NPCOfferLabel - id: capacity + CheckBox + 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 - id: setupButton - !text: tr('Buy') - width: 64 - anchors.horizontalCenter: parent.horizontalCenter + CheckBox + id: showAllItems + !text: tr('Show all items') 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 !text: tr('Close') @@ -233,4 +282,3 @@ MainWindow anchors.right: parent.right anchors.bottom: parent.bottom @onClick: NPCTrade.hide() -