tibia-client/modules/game_inventory/inventory.lua

51 lines
1.5 KiB
Lua
Raw Normal View History

2011-11-10 06:29:25 +01:00
Inventory = {}
-- private variables
local inventoryWindow
local inventoryButton
2011-11-10 06:29:25 +01:00
-- public functions
function Inventory.create()
inventoryWindow = displayUI('inventory.otui', { parent = Game.gameRightPanel })
inventoryButton = TopMenu.addGameButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle)
inventoryButton:setOn(true)
Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
2011-11-10 06:29:25 +01:00
end
function Inventory.destroy()
Keyboard.unbindKeyDown('Ctrl+I')
inventoryWindow:destroy()
inventoryWindow = nil
inventoryButton:destroy()
inventoryButton = nil
end
function Inventory.toggle()
local visible = not inventoryWindow:isExplicitlyVisible()
inventoryWindow:setVisible(visible)
inventoryButton:setOn(visible)
2011-11-10 06:29:25 +01:00
end
-- hooked events
function Inventory.onInventoryChange(slot, item)
local itemWidget = inventoryWindow:getChildById('slot' .. slot)
2011-11-10 06:29:25 +01:00
itemWidget:setItem(item)
end
function Inventory.onFreeCapacityChange(freeCapacity)
local widget = inventoryWindow:getChildById('capacity')
widget:setText("Cap:\n" .. freeCapacity)
end
function Inventory.onSoulChange(soul)
local widget = inventoryWindow:getChildById('soul')
widget:setText("Soul:\n" .. soul)
end
connect(Game, { onGameStart = Inventory.create,
onGameEnd = Inventory.destroy,
onInventoryChange = Inventory.onInventoryChange,
onFreeCapacityChange = Inventory.onFreeCapacityChange,
onSoulChange = Inventory.onSoulChange })
2012-01-09 21:54:37 +01:00