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()
|
2012-04-27 08:30:54 +02:00
|
|
|
connect(LocalPlayer, { onInventoryChange = Inventory.onInventoryChange,
|
|
|
|
onFreeCapacityChange = Inventory.onFreeCapacityChange })
|
2012-04-27 22:35:39 +02:00
|
|
|
connect(g_game, { onGameStart = Inventory.refresh })
|
2012-03-23 14:48:05 +01:00
|
|
|
|
|
|
|
Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
|
|
|
|
|
2012-03-28 16:10:21 +02:00
|
|
|
inventoryWindow = displayUI('inventory.otui', GameInterface.getRightPanel())
|
|
|
|
inventoryPanel = inventoryWindow:getChildById('contentsPanel')
|
2012-04-26 21:54:16 +02:00
|
|
|
inventoryButton = TopMenu.addGameToggleButton('inventoryButton', tr('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
|
|
|
|
2012-04-27 08:30:54 +02:00
|
|
|
Inventory.refresh()
|
2011-11-10 06:29:25 +01:00
|
|
|
end
|
|
|
|
|
2012-03-23 14:48:05 +01:00
|
|
|
function Inventory.terminate()
|
2012-04-27 08:30:54 +02:00
|
|
|
disconnect(LocalPlayer, { onInventoryChange = Inventory.onInventoryChange,
|
|
|
|
onFreeCapacityChange = Inventory.onFreeCapacityChange })
|
2012-04-27 22:35:39 +02:00
|
|
|
disconnect(g_game, { onGameStart = Inventory.refresh })
|
2012-03-23 14:48:05 +01:00
|
|
|
|
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-04-27 06:54:14 +02:00
|
|
|
|
|
|
|
Inventory = nil
|
2012-01-24 19:39:16 +01:00
|
|
|
end
|
|
|
|
|
2012-04-27 08:30:54 +02:00
|
|
|
function Inventory.refresh()
|
|
|
|
local player = g_game.getLocalPlayer()
|
|
|
|
for i=1,10 do
|
2012-04-27 22:35:39 +02:00
|
|
|
if player then
|
|
|
|
Inventory.onInventoryChange(player, i, player:getInventoryItem(i))
|
|
|
|
else
|
|
|
|
Inventory.onInventoryChange(player, i, nil)
|
|
|
|
end
|
2012-04-27 08:30:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-24 19:39:16 +01:00
|
|
|
function Inventory.toggle()
|
2012-06-21 21:31:22 +02:00
|
|
|
if inventoryButton:isOn() then
|
|
|
|
inventoryWindow:close()
|
|
|
|
inventoryButton:setOn(false)
|
|
|
|
else
|
|
|
|
inventoryWindow:open()
|
|
|
|
inventoryButton:setOn(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Inventory.onMiniWindowClose()
|
|
|
|
inventoryButton:setOn(false)
|
2011-11-10 06:29:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- hooked events
|
2012-04-27 08:30:54 +02:00
|
|
|
function Inventory.onInventoryChange(player, 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
|
|
|
|
|
2012-04-27 08:30:54 +02:00
|
|
|
function Inventory.onFreeCapacityChange(player, 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
|
|
|
|
|