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
|
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-27 00:24:01 +02:00
|
|
|
inventoryWindow = displayUI('inventory.otui', GameInterface.getRightPanel()):getChildById('inventoryWindow')
|
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-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
|
|
|
|
|
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-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
|