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.

cooldown.lua 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. local ProgressCallback = {
  2. update = 1,
  3. finish = 2
  4. }
  5. cooldownWindow = nil
  6. cooldownButton = nil
  7. contentsPanel = nil
  8. spellCooldownPanel = nil
  9. function init()
  10. connect(g_game, { onGameStart = online,
  11. onSpellGroupCooldown = onSpellGroupCooldown,
  12. onSpellCooldown = onSpellCooldown })
  13. cooldownButton = modules.client_topmenu.addRightGameToggleButton('cooldownButton', tr('Cooldowns'), '/images/topbuttons/cooldowns', toggle)
  14. cooldownButton:setOn(true)
  15. cooldownButton:hide()
  16. cooldownWindow = g_ui.loadUI('cooldown', modules.game_interface.getRightPanel())
  17. cooldownWindow:disableResize()
  18. cooldownWindow:setup()
  19. contentsPanel = cooldownWindow:getChildById('contentsPanel')
  20. spellCooldownPanel = contentsPanel:getChildById('spellCooldownPanel')
  21. if g_game.isOnline() then
  22. online()
  23. end
  24. end
  25. function terminate()
  26. disconnect(g_game, { onGameStart = online,
  27. onSpellGroupCooldown = onSpellGroupCooldown,
  28. onSpellCooldown = onSpellCooldown })
  29. cooldownButton:destroy()
  30. cooldownWindow:destroy()
  31. end
  32. function onMiniWindowClose()
  33. cooldownButton:setOn(false)
  34. end
  35. function toggle()
  36. if cooldownButton:isOn() then
  37. cooldownWindow:close()
  38. cooldownButton:setOn(false)
  39. else
  40. cooldownWindow:open()
  41. cooldownButton:setOn(true)
  42. end
  43. end
  44. function online()
  45. if g_game.getFeature(GameSpellList) then
  46. cooldownButton:show()
  47. else
  48. cooldownButton:hide()
  49. cooldownWindow:close()
  50. end
  51. end
  52. function removeCooldown(progressRect)
  53. removeEvent(progressRect.event)
  54. if progressRect.icon then
  55. progressRect.icon:destroy()
  56. progressRect.icon = nil
  57. end
  58. progressRect = nil
  59. end
  60. function turnOffCooldown(progressRect)
  61. removeEvent(progressRect.event)
  62. if progressRect.icon then
  63. progressRect.icon:setOn(false)
  64. progressRect.icon = nil
  65. end
  66. -- create particles
  67. --[[local particle = g_ui.createWidget('GroupCooldownParticles', progressRect)
  68. particle:fill('parent')
  69. scheduleEvent(function() particle:destroy() end, 1000) -- hack until onEffectEnd]]
  70. progressRect = nil
  71. end
  72. function initCooldown(progressRect, updateCallback, finishCallback)
  73. progressRect:setPercent(0)
  74. progressRect.callback = {}
  75. progressRect.callback[ProgressCallback.update] = updateCallback
  76. progressRect.callback[ProgressCallback.finish] = finishCallback
  77. updateCallback()
  78. end
  79. function updateCooldown(progressRect, interval)
  80. progressRect:setPercent(progressRect:getPercent() + 5)
  81. if progressRect:getPercent() < 100 then
  82. removeEvent(progressRect.event)
  83. progressRect.event = scheduleEvent(function() progressRect.callback[ProgressCallback.update]() end, interval)
  84. else
  85. progressRect.callback[ProgressCallback.finish]()
  86. end
  87. end
  88. function onSpellCooldown(iconId, duration)
  89. local spell, profile, spellName = Spells.getSpellByIcon(iconId)
  90. if not spellName then return end
  91. clientIconId = Spells.getClientId(spellName)
  92. if not clientIconId then return end
  93. local icon = spellCooldownPanel:getChildById(spellName)
  94. if not icon then
  95. icon = g_ui.createWidget('SpellIcon', spellCooldownPanel)
  96. icon:setId(spellName)
  97. end
  98. icon:setImageSource('/images/game/spells/' .. SpelllistSettings[profile].iconFile)
  99. icon:setImageClip(Spells.getImageClip(clientIconId, profile))
  100. local progressRect = icon:getChildById(spellName)
  101. if not progressRect then
  102. progressRect = g_ui.createWidget('SpellProgressRect', icon)
  103. progressRect:setId(spellName)
  104. progressRect.icon = icon
  105. progressRect:fill('parent')
  106. else
  107. progressRect:setPercent(0)
  108. end
  109. progressRect:setTooltip(spellName)
  110. local updateFunc = function()
  111. updateCooldown(progressRect, duration/20)
  112. end
  113. local finishFunc = function()
  114. removeCooldown(progressRect)
  115. end
  116. initCooldown(progressRect, updateFunc, finishFunc)
  117. end
  118. function onSpellGroupCooldown(groupId, duration)
  119. if not SpellGroups[groupId] then return end
  120. local icon = contentsPanel:getChildById('groupIcon' .. SpellGroups[groupId])
  121. local progressRect = contentsPanel:getChildById('progressRect' .. SpellGroups[groupId])
  122. if icon then
  123. icon:setOn(true)
  124. removeEvent(icon.event)
  125. end
  126. progressRect.icon = icon
  127. if progressRect then
  128. removeEvent(progressRect.event)
  129. local updateFunc = function()
  130. updateCooldown(progressRect, duration/20)
  131. end
  132. local finishFunc = function()
  133. turnOffCooldown(progressRect)
  134. end
  135. initCooldown(progressRect, updateFunc, finishFunc)
  136. end
  137. end