2013-01-29 14:01:06 +01:00
|
|
|
local ProgressCallback = {
|
|
|
|
update = 1,
|
|
|
|
finish = 2
|
|
|
|
}
|
|
|
|
|
2012-10-13 21:33:04 +02:00
|
|
|
cooldownWindow = nil
|
|
|
|
cooldownButton = nil
|
|
|
|
contentsPanel = nil
|
2013-02-23 06:53:27 +01:00
|
|
|
cooldownPanel = nil
|
2013-01-31 13:30:36 +01:00
|
|
|
lastPlayer = nil
|
2012-10-09 02:46:23 +02:00
|
|
|
|
|
|
|
function init()
|
2013-01-26 21:40:03 +01:00
|
|
|
connect(g_game, { onGameStart = online,
|
2012-10-09 02:46:23 +02:00
|
|
|
onSpellGroupCooldown = onSpellGroupCooldown,
|
|
|
|
onSpellCooldown = onSpellCooldown })
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
cooldownButton = modules.client_topmenu.addRightGameToggleButton('cooldownButton', tr('Cooldowns'), '/images/topbuttons/cooldowns', toggle)
|
2012-10-13 21:33:04 +02:00
|
|
|
cooldownButton:setOn(true)
|
|
|
|
cooldownButton:hide()
|
2012-10-09 02:46:23 +02:00
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
cooldownWindow = g_ui.loadUI('cooldown', modules.game_interface.getRightPanel())
|
2012-10-13 21:33:04 +02:00
|
|
|
cooldownWindow:disableResize()
|
|
|
|
cooldownWindow:setup()
|
|
|
|
|
|
|
|
contentsPanel = cooldownWindow:getChildById('contentsPanel')
|
2013-02-23 06:53:27 +01:00
|
|
|
cooldownPanel = contentsPanel:getChildById('cooldownPanel')
|
|
|
|
|
2013-02-23 07:16:42 +01:00
|
|
|
-- preload cooldown images
|
|
|
|
for k,v in pairs(SpelllistSettings) do
|
|
|
|
g_textures.preload(v.iconFile)
|
2013-02-23 06:53:27 +01:00
|
|
|
end
|
2013-01-26 21:40:03 +01:00
|
|
|
|
2012-10-09 02:46:23 +02:00
|
|
|
if g_game.isOnline() then
|
2013-01-26 21:40:03 +01:00
|
|
|
online()
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function terminate()
|
2013-01-26 21:40:03 +01:00
|
|
|
disconnect(g_game, { onGameStart = online,
|
2012-10-09 02:46:23 +02:00
|
|
|
onSpellGroupCooldown = onSpellGroupCooldown,
|
|
|
|
onSpellCooldown = onSpellCooldown })
|
|
|
|
|
2012-10-13 21:33:04 +02:00
|
|
|
cooldownWindow:destroy()
|
2013-02-01 05:32:15 +01:00
|
|
|
cooldownButton:destroy()
|
2012-10-13 21:33:04 +02:00
|
|
|
end
|
|
|
|
|
2013-02-23 06:53:27 +01:00
|
|
|
function loadIcon(iconId)
|
|
|
|
local spell, profile, spellName = Spells.getSpellByIcon(iconId)
|
|
|
|
if not spellName then return end
|
|
|
|
|
|
|
|
clientIconId = Spells.getClientId(spellName)
|
|
|
|
if not clientIconId then return end
|
|
|
|
|
|
|
|
local icon = cooldownPanel:getChildById(iconId)
|
|
|
|
if not icon then
|
|
|
|
icon = g_ui.createWidget('SpellIcon')
|
|
|
|
icon:setId(iconId)
|
|
|
|
end
|
|
|
|
|
2013-02-23 07:23:18 +01:00
|
|
|
icon:setImageSource(SpelllistSettings[profile].iconFile)
|
2013-02-23 06:53:27 +01:00
|
|
|
icon:setImageClip(Spells.getImageClip(clientIconId, profile))
|
|
|
|
return icon
|
|
|
|
end
|
|
|
|
|
2012-10-13 21:33:04 +02:00
|
|
|
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
|
|
|
|
|
2013-01-26 21:40:03 +01:00
|
|
|
function online()
|
2012-10-09 02:46:23 +02:00
|
|
|
if g_game.getFeature(GameSpellList) then
|
2012-10-13 21:33:04 +02:00
|
|
|
cooldownButton:show()
|
2013-01-23 01:15:46 +01:00
|
|
|
else
|
2013-01-26 21:40:03 +01:00
|
|
|
cooldownButton:hide()
|
|
|
|
cooldownWindow:close()
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
2013-01-31 13:30:36 +01:00
|
|
|
|
2013-02-01 00:46:44 +01:00
|
|
|
if not lastPlayer or lastPlayer ~= g_game.getCharacterName() then
|
2013-01-31 13:30:36 +01:00
|
|
|
refresh()
|
|
|
|
lastPlayer = g_game.getCharacterName()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function refresh()
|
2013-02-23 06:53:27 +01:00
|
|
|
cooldownPanel:destroyChildren()
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
|
|
|
|
2013-01-29 14:01:06 +01:00
|
|
|
function removeCooldown(progressRect)
|
|
|
|
removeEvent(progressRect.event)
|
|
|
|
if progressRect.icon then
|
|
|
|
progressRect.icon:destroy()
|
|
|
|
progressRect.icon = nil
|
|
|
|
end
|
|
|
|
progressRect = nil
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
|
|
|
|
2013-01-29 14:01:06 +01:00
|
|
|
function turnOffCooldown(progressRect)
|
|
|
|
removeEvent(progressRect.event)
|
|
|
|
if progressRect.icon then
|
|
|
|
progressRect.icon:setOn(false)
|
|
|
|
progressRect.icon = nil
|
2012-10-09 20:34:39 +02:00
|
|
|
end
|
2013-01-30 00:00:13 +01:00
|
|
|
|
|
|
|
-- create particles
|
2013-01-31 08:31:21 +01:00
|
|
|
--[[local particle = g_ui.createWidget('GroupCooldownParticles', progressRect)
|
2013-01-30 00:00:13 +01:00
|
|
|
particle:fill('parent')
|
2013-01-31 08:31:21 +01:00
|
|
|
scheduleEvent(function() particle:destroy() end, 1000) -- hack until onEffectEnd]]
|
2013-01-30 00:00:13 +01:00
|
|
|
|
2013-01-29 14:01:06 +01:00
|
|
|
progressRect = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function initCooldown(progressRect, updateCallback, finishCallback)
|
|
|
|
progressRect:setPercent(0)
|
|
|
|
|
|
|
|
progressRect.callback = {}
|
|
|
|
progressRect.callback[ProgressCallback.update] = updateCallback
|
|
|
|
progressRect.callback[ProgressCallback.finish] = finishCallback
|
|
|
|
|
|
|
|
updateCallback()
|
|
|
|
end
|
|
|
|
|
|
|
|
function updateCooldown(progressRect, interval)
|
|
|
|
progressRect:setPercent(progressRect:getPercent() + 5)
|
2012-10-09 20:34:39 +02:00
|
|
|
|
|
|
|
if progressRect:getPercent() < 100 then
|
2013-01-29 14:01:06 +01:00
|
|
|
removeEvent(progressRect.event)
|
|
|
|
progressRect.event = scheduleEvent(function() progressRect.callback[ProgressCallback.update]() end, interval)
|
|
|
|
else
|
|
|
|
progressRect.callback[ProgressCallback.finish]()
|
2012-10-09 20:34:39 +02:00
|
|
|
end
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function onSpellCooldown(iconId, duration)
|
2013-02-23 06:53:27 +01:00
|
|
|
local icon = loadIcon(iconId)
|
2012-10-09 02:46:23 +02:00
|
|
|
if not icon then
|
2013-02-23 06:53:27 +01:00
|
|
|
return
|
2013-01-31 08:31:21 +01:00
|
|
|
end
|
2013-02-23 06:53:27 +01:00
|
|
|
icon:setParent(cooldownPanel)
|
2013-01-31 08:31:21 +01:00
|
|
|
|
2013-02-23 06:53:27 +01:00
|
|
|
local progressRect = icon:getChildById(iconId)
|
2013-01-31 08:31:21 +01:00
|
|
|
if not progressRect then
|
|
|
|
progressRect = g_ui.createWidget('SpellProgressRect', icon)
|
2013-02-23 06:53:27 +01:00
|
|
|
progressRect:setId(iconId)
|
2013-01-29 14:01:06 +01:00
|
|
|
progressRect.icon = icon
|
2013-01-29 07:26:32 +01:00
|
|
|
progressRect:fill('parent')
|
2013-01-31 08:31:21 +01:00
|
|
|
else
|
|
|
|
progressRect:setPercent(0)
|
|
|
|
end
|
|
|
|
progressRect:setTooltip(spellName)
|
2013-01-29 14:01:06 +01:00
|
|
|
|
2013-01-31 08:31:21 +01:00
|
|
|
local updateFunc = function()
|
2013-01-31 12:07:28 +01:00
|
|
|
updateCooldown(progressRect, duration/19)
|
2013-01-31 08:31:21 +01:00
|
|
|
end
|
|
|
|
local finishFunc = function()
|
|
|
|
removeCooldown(progressRect)
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
2013-01-31 08:31:21 +01:00
|
|
|
initCooldown(progressRect, updateFunc, finishFunc)
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function onSpellGroupCooldown(groupId, duration)
|
|
|
|
if not SpellGroups[groupId] then return end
|
2013-01-29 14:01:06 +01:00
|
|
|
|
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)
|
|
|
|
end
|
2013-01-29 14:01:06 +01:00
|
|
|
|
|
|
|
progressRect.icon = icon
|
2012-10-09 02:46:23 +02:00
|
|
|
if progressRect then
|
|
|
|
removeEvent(progressRect.event)
|
2013-01-29 14:01:06 +01:00
|
|
|
local updateFunc = function()
|
2013-01-31 12:07:28 +01:00
|
|
|
updateCooldown(progressRect, duration/19)
|
2013-01-29 14:01:06 +01:00
|
|
|
end
|
|
|
|
local finishFunc = function()
|
|
|
|
turnOffCooldown(progressRect)
|
|
|
|
end
|
|
|
|
initCooldown(progressRect, updateFunc, finishFunc)
|
2012-10-09 02:46:23 +02:00
|
|
|
end
|
|
|
|
end
|