2011-11-10 06:29:25 +01:00
|
|
|
Inventory = {}
|
|
|
|
|
|
|
|
-- private variables
|
2012-03-28 16:10:21 +02:00
|
|
|
local inventoryWindow
|
2012-03-28 13:46:15 +02:00
|
|
|
local inventoryPanel
|
2012-01-24 19:39:16 +01:00
|
|
|
local inventoryButton
|
2011-11-10 06:29:25 +01:00
|
|
|
|
|
|
|
-- public functions
|
2012-03-23 14:48:05 +01:00
|
|
|
function Inventory.init()
|
|
|
|
connect(g_game, { onGameEnd = Inventory.clear,
|
|
|
|
onInventoryChange = Inventory.onInventoryChange,
|
|
|
|
onFreeCapacityChange = Inventory.onFreeCapacityChange,
|
|
|
|
onSoulChange = Inventory.onSoulChange })
|
|
|
|
|
|
|
|
Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
|
|
|
|
|
2012-03-28 16:10:21 +02:00
|
|
|
inventoryWindow = displayUI('inventory.otui', GameInterface.getRightPanel())
|
|
|
|
inventoryWindow.onClose = Inventory.toggle
|
|
|
|
inventoryPanel = inventoryWindow:getChildById('contentsPanel')
|
2012-03-23 14:48:05 +01:00
|
|
|
inventoryButton = TopMenu.addGameToggleButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle)
|
2012-01-24 19:39:16 +01:00
|
|
|
inventoryButton:setOn(true)
|
2012-03-23 14:48:05 +01:00
|
|
|
|
|
|
|
if g_game.isOnline() then
|
|
|
|
Inventory.reload()
|
|
|
|
end
|
2011-11-10 06:29:25 +01:00
|
|
|
end
|
|
|
|
|
2012-03-23 14:48:05 +01:00
|
|
|
function Inventory.terminate()
|
|
|
|
connect(g_game, { onGameEnd = Inventory.clear,
|
|
|
|
onInventoryChange = Inventory.onInventoryChange,
|
|
|
|
onFreeCapacityChange = Inventory.onFreeCapacityChange,
|
|
|
|
onSoulChange = Inventory.onSoulChange })
|
|
|
|
|
2012-02-06 05:39:52 +01:00
|
|
|
Keyboard.unbindKeyDown('Ctrl+I')
|
2012-03-23 14:48:05 +01:00
|
|
|
|
2012-03-28 16:10:21 +02:00
|
|
|
inventoryWindow:destroy()
|
2012-01-24 19:39:16 +01:00
|
|
|
inventoryButton:destroy()
|
2012-03-28 16:10:21 +02:00
|
|
|
inventoryWindow = nil
|
2012-01-24 19:39:16 +01:00
|
|
|
inventoryButton = nil
|
2012-03-28 16:10:21 +02:00
|
|
|
inventoryPanel = nil
|
2012-01-24 19:39:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Inventory.toggle()
|
2012-03-28 16:10:21 +02:00
|
|
|
local visible = not inventoryWindow:isExplicitlyVisible()
|
|
|
|
inventoryWindow:setVisible(visible)
|
2012-01-24 19:39:16 +01:00
|
|
|
inventoryButton:setOn(visible)
|
2011-11-10 06:29:25 +01:00
|
|
|
end
|
|
|
|
|
2012-03-23 14:48:05 +01:00
|
|
|
function Inventory.clear()
|
|
|
|
end
|
|
|
|
|
|
|
|
function Inventory.reload()
|
|
|
|
end
|
|
|
|
|
2011-11-10 06:29:25 +01:00
|
|
|
-- hooked events
|
2011-11-13 23:23:21 +01:00
|
|
|
function Inventory.onInventoryChange(slot, item)
|
2012-03-28 13:46:15 +02:00
|
|
|
local itemWidget = inventoryPanel:getChildById('slot' .. slot)
|
2011-11-10 06:29:25 +01:00
|
|
|
itemWidget:setItem(item)
|
|
|
|
end
|
|
|
|
|
2011-11-13 23:23:21 +01:00
|
|
|
function Inventory.onFreeCapacityChange(freeCapacity)
|
2012-03-28 13:46:15 +02:00
|
|
|
local widget = inventoryPanel:getChildById('capacity')
|
2011-11-13 23:23:21 +01:00
|
|
|
widget:setText("Cap:\n" .. freeCapacity)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Inventory.onSoulChange(soul)
|
2012-03-28 13:46:15 +02:00
|
|
|
local widget = inventoryPanel:getChildById('soul')
|
2011-11-13 23:23:21 +01:00
|
|
|
widget:setText("Soul:\n" .. soul)
|
|
|
|
end
|