2011-11-10 06:29:25 +01:00
|
|
|
Inventory = {}
|
|
|
|
|
|
|
|
-- private variables
|
|
|
|
local window = nil
|
|
|
|
|
|
|
|
local InventorySlotHead = 1
|
|
|
|
local InventorySlotNecklace = 2
|
|
|
|
local InventorySlotBackpack = 3
|
|
|
|
local InventorySlotArmor = 4
|
|
|
|
local InventorySlotRight = 5
|
|
|
|
local InventorySlotLeft = 6
|
|
|
|
local InventorySlotLegs = 7
|
|
|
|
local InventorySlotFeet = 8
|
|
|
|
local InventorySlotRing = 9
|
|
|
|
local InventorySlotAmmo = 10
|
|
|
|
|
|
|
|
-- public functions
|
|
|
|
function Inventory.create()
|
2011-11-17 21:40:31 +01:00
|
|
|
window = UI.display('inventory.otui', { parent = Game.gameRightPanel })
|
2011-11-16 00:47:32 +01:00
|
|
|
|
2011-11-10 06:29:25 +01:00
|
|
|
local itemWidget = window:getChildById('feet')
|
|
|
|
window:setHeight(itemWidget:getPosition().y + itemWidget:getHeight() - window:getPosition().y)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Inventory.destroy()
|
|
|
|
window:destroy()
|
|
|
|
window = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
-- hooked events
|
2011-11-13 23:23:21 +01:00
|
|
|
function Inventory.onInventoryChange(slot, item)
|
2011-11-10 06:29:25 +01:00
|
|
|
local slotId
|
|
|
|
if slot == InventorySlotHead then
|
|
|
|
slotId = 'head'
|
|
|
|
elseif slot == InventorySlotNecklace then
|
|
|
|
slotId = 'necklace'
|
|
|
|
elseif slot == InventorySlotBackpack then
|
|
|
|
slotId = 'backpack'
|
|
|
|
elseif slot == InventorySlotArmor then
|
|
|
|
slotId = 'armor'
|
|
|
|
elseif slot == InventorySlotRight then
|
|
|
|
slotId = 'right'
|
|
|
|
elseif slot == InventorySlotLeft then
|
|
|
|
slotId = 'left'
|
|
|
|
elseif slot == InventorySlotLegs then
|
|
|
|
slotId = 'legs'
|
|
|
|
elseif slot == InventorySlotFeet then
|
|
|
|
slotId = 'feet'
|
|
|
|
elseif slot == InventorySlotRing then
|
|
|
|
slotId = 'ring'
|
|
|
|
elseif slot == InventorySlotAmmo then
|
|
|
|
slotId = 'ammo'
|
|
|
|
end
|
2011-11-16 00:47:32 +01:00
|
|
|
|
2011-11-10 06:29:25 +01:00
|
|
|
local itemWidget = window:getChildById(slotId)
|
|
|
|
itemWidget:setItem(item)
|
|
|
|
end
|
|
|
|
|
2011-11-13 23:23:21 +01:00
|
|
|
function Inventory.onFreeCapacityChange(freeCapacity)
|
|
|
|
local widget = window:getChildById('capacity')
|
|
|
|
widget:setText("Cap:\n" .. freeCapacity)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Inventory.onSoulChange(soul)
|
|
|
|
local widget = window:getChildById('soul')
|
|
|
|
widget:setText("Soul:\n" .. soul)
|
|
|
|
end
|
|
|
|
|
2011-11-10 06:29:25 +01:00
|
|
|
connect(Game, { onLogin = Inventory.create,
|
2011-11-13 23:23:21 +01:00
|
|
|
onLogout = Inventory.destroy,
|
|
|
|
onInventoryChange = Inventory.onInventoryChange,
|
|
|
|
onFreeCapacityChange = Inventory.onFreeCapacityChange,
|
|
|
|
onSoulChange = Inventory.onSoulChange })
|