2011-11-10 06:29:25 +01:00
|
|
|
Inventory = {}
|
|
|
|
|
|
|
|
-- private variables
|
2012-01-24 19:39:16 +01:00
|
|
|
local inventoryWindow
|
|
|
|
local inventoryButton
|
2011-11-10 06:29:25 +01:00
|
|
|
|
|
|
|
-- public functions
|
|
|
|
function Inventory.create()
|
2012-01-24 19:39:16 +01:00
|
|
|
inventoryWindow = displayUI('inventory.otui', { parent = Game.gameRightPanel })
|
2012-02-03 07:20:58 +01:00
|
|
|
inventoryButton = TopMenu.addGameButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle)
|
2012-01-24 19:39:16 +01:00
|
|
|
inventoryButton:setOn(true)
|
2012-02-06 05:39:52 +01:00
|
|
|
Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
|
2011-11-10 06:29:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Inventory.destroy()
|
2012-02-06 05:39:52 +01:00
|
|
|
Keyboard.unbindKeyDown('Ctrl+I')
|
2012-01-24 19:39:16 +01:00
|
|
|
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
|
2011-11-13 23:23:21 +01:00
|
|
|
function Inventory.onInventoryChange(slot, item)
|
2012-01-24 19:39:16 +01:00
|
|
|
local itemWidget = inventoryWindow: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-01-24 19:39:16 +01:00
|
|
|
local widget = inventoryWindow:getChildById('capacity')
|
2011-11-13 23:23:21 +01:00
|
|
|
widget:setText("Cap:\n" .. freeCapacity)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Inventory.onSoulChange(soul)
|
2012-01-24 19:39:16 +01:00
|
|
|
local widget = inventoryWindow:getChildById('soul')
|
2011-11-13 23:23:21 +01:00
|
|
|
widget:setText("Soul:\n" .. soul)
|
|
|
|
end
|
|
|
|
|
2012-02-08 00:54:33 +01:00
|
|
|
connect(Game, { onGameStart = Inventory.create,
|
|
|
|
onGameEnd = Inventory.destroy,
|
2011-11-13 23:23:21 +01:00
|
|
|
onInventoryChange = Inventory.onInventoryChange,
|
|
|
|
onFreeCapacityChange = Inventory.onFreeCapacityChange,
|
|
|
|
onSoulChange = Inventory.onSoulChange })
|
2012-01-09 21:54:37 +01:00
|
|
|
|