tibia-client/modules/game_inventory/inventory.lua

66 lines
1.8 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.init()
connect(g_game, { onGameEnd = Inventory.clear,
onInventoryChange = Inventory.onInventoryChange,
onFreeCapacityChange = Inventory.onFreeCapacityChange,
onSoulChange = Inventory.onSoulChange })
Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
inventoryWindow = displayUI('inventory.otui', GameInterface.getRightPanel())
inventoryButton = TopMenu.addGameToggleButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle)
inventoryButton:setOn(true)
if g_game.isOnline() then
Inventory.reload()
end
2011-11-10 06:29:25 +01:00
end
function Inventory.terminate()
connect(g_game, { onGameEnd = Inventory.clear,
onInventoryChange = Inventory.onInventoryChange,
onFreeCapacityChange = Inventory.onFreeCapacityChange,
onSoulChange = Inventory.onSoulChange })
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
function Inventory.clear()
end
function Inventory.reload()
end
2011-11-10 06:29:25 +01:00
-- 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