2011-11-10 06:29:25 +01:00
|
|
|
Inventory = {}
|
|
|
|
|
|
|
|
-- private variables
|
|
|
|
local window = nil
|
|
|
|
|
|
|
|
-- public functions
|
|
|
|
function Inventory.create()
|
2012-01-03 01:42:53 +01:00
|
|
|
window = displayUI('inventory.otui', { parent = Game.gameRightPanel })
|
2011-11-10 06:29:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Inventory.destroy()
|
|
|
|
window:destroy()
|
|
|
|
window = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
-- hooked events
|
2011-11-13 23:23:21 +01:00
|
|
|
function Inventory.onInventoryChange(slot, item)
|
2012-01-03 01:10:39 +01:00
|
|
|
local itemWidget = window: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)
|
|
|
|
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
|
|
|
|
|
2012-01-02 23:09:49 +01:00
|
|
|
function Inventory.onInventoryItemMousePress(itemWidget, mousePos, mouseButton)
|
2012-01-03 01:10:39 +01:00
|
|
|
if mouseButton ~= MouseRightButton then return end
|
2012-01-03 01:42:53 +01:00
|
|
|
|
2012-01-03 00:08:04 +01:00
|
|
|
local item = itemWidget:getItem()
|
2012-01-03 01:10:39 +01:00
|
|
|
if not item then return end
|
2012-01-03 01:42:53 +01:00
|
|
|
|
2012-01-04 14:02:35 +01:00
|
|
|
Game.createThingMenu(mousePos, item, item, nil)
|
2012-01-02 23:09:49 +01:00
|
|
|
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 })
|