No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

inventory.lua 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. Inventory = {}
  2. -- private variables
  3. local inventoryWindow
  4. local inventoryButton
  5. -- public functions
  6. function Inventory.create()
  7. inventoryWindow = displayUI('inventory.otui', { parent = Game.gameRightPanel })
  8. inventoryButton = TopMenu.addGameButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle)
  9. inventoryButton:setOn(true)
  10. Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
  11. end
  12. function Inventory.destroy()
  13. Keyboard.unbindKeyDown('Ctrl+I')
  14. inventoryWindow:destroy()
  15. inventoryWindow = nil
  16. inventoryButton:destroy()
  17. inventoryButton = nil
  18. end
  19. function Inventory.toggle()
  20. local visible = not inventoryWindow:isExplicitlyVisible()
  21. inventoryWindow:setVisible(visible)
  22. inventoryButton:setOn(visible)
  23. end
  24. -- hooked events
  25. function Inventory.onInventoryChange(slot, item)
  26. local itemWidget = inventoryWindow:getChildById('slot' .. slot)
  27. itemWidget:setItem(item)
  28. end
  29. function Inventory.onFreeCapacityChange(freeCapacity)
  30. local widget = inventoryWindow:getChildById('capacity')
  31. widget:setText("Cap:\n" .. freeCapacity)
  32. end
  33. function Inventory.onSoulChange(soul)
  34. local widget = inventoryWindow:getChildById('soul')
  35. widget:setText("Soul:\n" .. soul)
  36. end
  37. connect(Game, { onGameStart = Inventory.create,
  38. onGameEnd = Inventory.destroy,
  39. onInventoryChange = Inventory.onInventoryChange,
  40. onFreeCapacityChange = Inventory.onFreeCapacityChange,
  41. onSoulChange = Inventory.onSoulChange })