2012-10-13 21:33:04 +02:00
|
|
|
cooldownWindow = nil
|
|
|
|
cooldownButton = nil
|
|
|
|
contentsPanel = nil
|
2012-10-09 02:46:23 +02:00
|
|
|
spellCooldownPanel = nil
|
|
|
|
|
|
|
|
function init()
|
|
|
|
connect(g_game, { onGameStart = show,
|
|
|
|
onGameEnd = hide,
|
|
|
|
onSpellGroupCooldown = onSpellGroupCooldown,
|
|
|
|
onSpellCooldown = onSpellCooldown })
|
|
|
|
|
2012-10-13 21:33:04 +02:00
|
|
|
cooldownButton = TopMenu.addRightGameToggleButton('cooldownButton', tr('Cooldowns'), 'cooldown.png', toggle)
|
|
|
|
cooldownButton:setOn(true)
|
|
|
|
cooldownButton:hide()
|
2012-10-09 02:46:23 +02:00
|
|
|
|
2012-10-13 21:33:04 +02:00
|
|
|
cooldownWindow = g_ui.loadUI('cooldown.otui', modules.game_interface.getRightPanel())
|
|
|
|
cooldownWindow:disableResize()
|
|
|
|
cooldownWindow:setup()
|
|
|
|
|
|
|
|
contentsPanel = cooldownWindow:getChildById('contentsPanel')
|
|
|
|
spellCooldownPanel = contentsPanel:getChildById('spellCooldownPanel')
|
|
|
|
|
2012-10-09 02:46:23 +02:00
|
|
|
if g_game.isOnline() then
|
|
|
|
show()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function terminate()
|
|
|
|
disconnect(g_game, { onGameStart = show,
|
|
|
|
onGameEnd = hide,
|
|
|
|
onSpellGroupCooldown = onSpellGroupCooldown,
|
|
|
|
onSpellCooldown = onSpellCooldown })
|
|
|
|
|
2012-10-13 21:33:04 +02:00
|
|
|
cooldownButton:destroy()
|
|
|
|
cooldownWindow:destroy()
|
|
|
|
end
|
|
|
|
|
|
|
|
function onMiniWindowClose()
|
|
|
|
cooldownButton:setOn(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
function toggle()
|
|
|
|
if cooldownButton:isOn() then
|
|
|
|
cooldownWindow:close()
|
|
|
|
cooldownButton:setOn(false)
|
|
|
|
else
|
|
|
|
cooldownWindow:open()
|
|
|
|
cooldownButton:setOn(true)
|
|
|
|
end
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function show()
|
|
|
|
if g_game.getFeature(GameSpellList) then
|
2012-10-13 21:33:04 +02:00
|
|
|
cooldownWindow:show()
|
|
|
|
cooldownButton:show()
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function hide()
|
2012-10-13 21:33:04 +02:00
|
|
|
cooldownWindow:hide()
|
|
|
|
cooldownButton:hide()
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function updateProgressRect(progressRect, interval, init)
|
2012-10-09 20:34:39 +02:00
|
|
|
if init then
|
|
|
|
progressRect:setPercent(0)
|
|
|
|
else
|
2013-01-06 16:04:49 +01:00
|
|
|
progressRect:setPercent(progressRect:getPercent() + 5)
|
2012-10-09 20:34:39 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if progressRect:getPercent() < 100 then
|
|
|
|
removeEvent(progressRect.event)
|
|
|
|
progressRect.event = scheduleEvent(function() updateProgressRect(progressRect, interval) end, interval)
|
|
|
|
end
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function onSpellCooldown(iconId, duration)
|
|
|
|
local spellName = SpelllistSettings[modules.game_spelllist.getSpelllistProfile()].spellIcons[iconId]
|
|
|
|
if not spellName then return end
|
2012-10-09 20:34:39 +02:00
|
|
|
|
2013-01-07 18:17:01 +01:00
|
|
|
local ping = g_game.getPing()
|
2013-01-08 03:55:41 +01:00
|
|
|
if ping > 0 then duration = duration - (ping/2) end
|
2012-10-09 02:46:23 +02:00
|
|
|
local otcIconId = tonumber(SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon)
|
|
|
|
if not otcIconId and SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon] then
|
|
|
|
otcIconId = SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon][1]
|
|
|
|
end
|
2012-10-09 20:34:39 +02:00
|
|
|
|
2012-10-09 02:46:23 +02:00
|
|
|
if not otcIconId then return end
|
2012-10-09 20:34:39 +02:00
|
|
|
|
2012-10-13 21:33:04 +02:00
|
|
|
local icon = spellCooldownPanel:getChildById(spellName)
|
2012-10-09 02:46:23 +02:00
|
|
|
if not icon then
|
|
|
|
icon = g_ui.createWidget('SpellIcon', spellCooldownPanel)
|
|
|
|
icon:setId(spellName)
|
|
|
|
icon:setImageSource('/game_cooldown/icons/' .. SpelllistSettings[modules.game_spelllist.getSpelllistProfile()].iconFile)
|
|
|
|
icon:setImageClip(modules.game_spelllist.getIconImageClip(otcIconId))
|
2012-12-28 17:15:57 +01:00
|
|
|
icon.event = scheduleEvent(function() icon:destroy() icon = nil end, duration)
|
2012-10-09 20:34:39 +02:00
|
|
|
|
2012-12-28 17:15:57 +01:00
|
|
|
local progressRect = g_ui.createWidget('SpellProgressRect')
|
2012-10-09 20:34:39 +02:00
|
|
|
updateProgressRect(progressRect, duration/25, true)
|
2012-10-09 03:43:52 +02:00
|
|
|
progressRect:setTooltip(spellName)
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function onSpellGroupCooldown(groupId, duration)
|
|
|
|
if not SpellGroups[groupId] then return end
|
|
|
|
|
2013-01-07 18:17:01 +01:00
|
|
|
local ping = g_game.getPing()
|
2013-01-08 03:55:41 +01:00
|
|
|
if ping > 0 then duration = duration - (ping/2) end
|
2012-10-13 21:33:04 +02:00
|
|
|
local icon = contentsPanel:getChildById('groupIcon' .. SpellGroups[groupId])
|
|
|
|
local progressRect = contentsPanel:getChildById('progressRect' .. SpellGroups[groupId])
|
2012-10-09 02:46:23 +02:00
|
|
|
if icon then
|
|
|
|
icon:setOn(true)
|
|
|
|
removeEvent(icon.event)
|
2012-10-09 20:34:39 +02:00
|
|
|
icon.event = scheduleEvent(function() icon:setOn(false) end, duration)
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if progressRect then
|
|
|
|
removeEvent(progressRect.event)
|
2012-10-09 20:34:39 +02:00
|
|
|
updateProgressRect(progressRect, duration/25, true)
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
|
|
|
end
|