Advertisement
Oskar1121

Untitled

Oct 2nd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. InventorySlotStyles = {
  2. [InventorySlotHead] = "HeadSlot",
  3. [InventorySlotNeck] = "NeckSlot",
  4. [InventorySlotBack] = "BackSlot",
  5. [InventorySlotBody] = "BodySlot",
  6. [InventorySlotRight] = "RightSlot",
  7. [InventorySlotLeft] = "LeftSlot",
  8. [InventorySlotLeg] = "LegSlot",
  9. [InventorySlotFeet] = "FeetSlot",
  10. [InventorySlotFinger] = "FingerSlot",
  11. [InventorySlotAmmo] = "AmmoSlot"
  12. }
  13.  
  14. inventoryWindow = nil
  15. inventoryPanel = nil
  16. inventoryButton = nil
  17. purseButton = nil
  18.  
  19. function init()
  20. connect(LocalPlayer, {
  21. onInventoryChange = onInventoryChange,
  22. onBlessingsChange = onBlessingsChange
  23. })
  24. connect(g_game, { onGameStart = refresh })
  25.  
  26. g_keyboard.bindKeyDown('Ctrl+I', toggle)
  27.  
  28. inventoryButton = modules.client_topmenu.addRightGameToggleButton('inventoryButton', tr('Inventory') .. ' (Ctrl+I)', '/images/topbuttons/inventory', toggle)
  29. inventoryButton:setOn(true)
  30.  
  31. inventoryWindow = g_ui.loadUI('inventory', modules.game_interface.getRightPanel())
  32. inventoryWindow:disableResize()
  33. inventoryPanel = inventoryWindow:getChildById('contentsPanel')
  34.  
  35. purseButton = inventoryPanel:getChildById('purseButton')
  36. local function purseFunction()
  37. local purse = g_game.getLocalPlayer():getInventoryItem(InventorySlotPurse)
  38. if purse then
  39. g_game.use(purse)
  40. end
  41. end
  42. purseButton.onClick = purseFunction
  43.  
  44. refresh()
  45. inventoryWindow:setup()
  46. end
  47.  
  48. function terminate()
  49. disconnect(LocalPlayer, {
  50. onInventoryChange = onInventoryChange,
  51. onBlessingsChange = onBlessingsChange
  52. })
  53. disconnect(g_game, { onGameStart = refresh })
  54.  
  55. g_keyboard.unbindKeyDown('Ctrl+I')
  56.  
  57. inventoryWindow:destroy()
  58. inventoryButton:destroy()
  59. end
  60.  
  61. function toggleAdventurerStyle(hasBlessing)
  62. for slot = InventorySlotFirst, InventorySlotLast do
  63. local itemWidget = inventoryPanel:getChildById('slot' .. slot)
  64. if itemWidget then
  65. itemWidget:setOn(hasBlessing)
  66. end
  67. end
  68. end
  69.  
  70. function refresh()
  71. scheduleEvent(function()
  72. modules.game_interface.gameMapPanel:setVisibleDimension({ width = 27, height = 23 })
  73. end, 100)
  74.  
  75. local player = g_game.getLocalPlayer()
  76. for i = InventorySlotFirst, InventorySlotPurse do
  77. if g_game.isOnline() then
  78. onInventoryChange(player, i, player:getInventoryItem(i))
  79. else
  80. onInventoryChange(player, i, nil)
  81. end
  82. toggleAdventurerStyle(player and Bit.hasBit(player:getBlessings(), Blessings.Adventurer) or false)
  83. end
  84.  
  85. purseButton:setVisible(g_game.getFeature(GamePurseSlot))
  86. end
  87.  
  88. function toggle()
  89. if inventoryButton:isOn() then
  90. inventoryWindow:close()
  91. inventoryButton:setOn(false)
  92. else
  93. inventoryWindow:open()
  94. inventoryButton:setOn(true)
  95. end
  96. end
  97.  
  98. function onMiniWindowClose()
  99. inventoryButton:setOn(false)
  100. end
  101.  
  102. -- hooked events
  103. function onInventoryChange(player, slot, item, oldItem)
  104. if slot > InventorySlotPurse then return end
  105.  
  106. if slot == InventorySlotPurse then
  107. if g_game.getFeature(GamePurseSlot) then
  108. purseButton:setEnabled(item and true or false)
  109. end
  110. return
  111. end
  112.  
  113. local itemWidget = inventoryPanel:getChildById('slot' .. slot)
  114. if item then
  115. itemWidget:setStyle('InventoryItem')
  116. itemWidget:setItem(item)
  117. else
  118. itemWidget:setStyle(InventorySlotStyles[slot])
  119. itemWidget:setItem(nil)
  120. end
  121. end
  122.  
  123. function onBlessingsChange(player, blessings, oldBlessings)
  124. local hasAdventurerBlessing = Bit.hasBit(blessings, Blessings.Adventurer)
  125. if hasAdventurerBlessing ~= Bit.hasBit(oldBlessings, Blessings.Adventurer) then
  126. toggleAdventurerStyle(hasAdventurerBlessing)
  127. end
  128. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement