More fixes to spell cooldown module:
* Fixed duration issues. * Fixed referencing after destroyed issue. * Using callbacks for progress rect now.
This commit is contained in:
parent
26c6217bc3
commit
f492d291eb
|
@ -1,3 +1,8 @@
|
||||||
|
local ProgressCallback = {
|
||||||
|
update = 1,
|
||||||
|
finish = 2
|
||||||
|
}
|
||||||
|
|
||||||
cooldownWindow = nil
|
cooldownWindow = nil
|
||||||
cooldownButton = nil
|
cooldownButton = nil
|
||||||
contentsPanel = nil
|
contentsPanel = nil
|
||||||
|
@ -5,7 +10,6 @@ spellCooldownPanel = nil
|
||||||
|
|
||||||
function init()
|
function init()
|
||||||
connect(g_game, { onGameStart = online,
|
connect(g_game, { onGameStart = online,
|
||||||
onGameEnd = offline,
|
|
||||||
onSpellGroupCooldown = onSpellGroupCooldown,
|
onSpellGroupCooldown = onSpellGroupCooldown,
|
||||||
onSpellCooldown = onSpellCooldown })
|
onSpellCooldown = onSpellCooldown })
|
||||||
|
|
||||||
|
@ -27,7 +31,6 @@ end
|
||||||
|
|
||||||
function terminate()
|
function terminate()
|
||||||
disconnect(g_game, { onGameStart = online,
|
disconnect(g_game, { onGameStart = online,
|
||||||
onGameEnd = offline,
|
|
||||||
onSpellGroupCooldown = onSpellGroupCooldown,
|
onSpellGroupCooldown = onSpellGroupCooldown,
|
||||||
onSpellCooldown = onSpellCooldown })
|
onSpellCooldown = onSpellCooldown })
|
||||||
|
|
||||||
|
@ -58,19 +61,42 @@ function online()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function offline()
|
function removeCooldown(progressRect)
|
||||||
|
removeEvent(progressRect.event)
|
||||||
|
if progressRect.icon then
|
||||||
|
progressRect.icon:destroy()
|
||||||
|
progressRect.icon = nil
|
||||||
|
end
|
||||||
|
progressRect = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function updateProgressRect(progressRect, interval, init)
|
function turnOffCooldown(progressRect)
|
||||||
if init then
|
removeEvent(progressRect.event)
|
||||||
progressRect:setPercent(0)
|
if progressRect.icon then
|
||||||
else
|
progressRect.icon:setOn(false)
|
||||||
progressRect:setPercent(progressRect:getPercent() + 5)
|
progressRect.icon = nil
|
||||||
end
|
end
|
||||||
|
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)
|
||||||
|
|
||||||
if progressRect:getPercent() < 100 then
|
if progressRect:getPercent() < 100 then
|
||||||
removeEvent(progressRect.event)
|
removeEvent(progressRect.event)
|
||||||
progressRect.event = scheduleEvent(function() updateProgressRect(progressRect, interval) end, interval)
|
progressRect.event = scheduleEvent(function() progressRect.callback[ProgressCallback.update]() end, interval)
|
||||||
|
else
|
||||||
|
progressRect.callback[ProgressCallback.finish]()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -78,8 +104,8 @@ function onSpellCooldown(iconId, duration)
|
||||||
local spell, profile, spellName = Spells.getSpellByIcon(iconId)
|
local spell, profile, spellName = Spells.getSpellByIcon(iconId)
|
||||||
if not spellName then return end
|
if not spellName then return end
|
||||||
|
|
||||||
local ping = g_game.getPing()
|
--local ping = g_game.getPing()
|
||||||
if ping > 0 then duration = duration - (ping/2) end
|
--if ping > 0 then duration = duration + ping end
|
||||||
|
|
||||||
clientIconId = Spells.getClientId(spellName)
|
clientIconId = Spells.getClientId(spellName)
|
||||||
if not clientIconId then return end
|
if not clientIconId then return end
|
||||||
|
@ -90,30 +116,44 @@ function onSpellCooldown(iconId, duration)
|
||||||
icon:setId(spellName)
|
icon:setId(spellName)
|
||||||
icon:setImageSource('/images/game/spells/' .. SpelllistSettings[profile].iconFile)
|
icon:setImageSource('/images/game/spells/' .. SpelllistSettings[profile].iconFile)
|
||||||
icon:setImageClip(Spells.getImageClip(clientIconId, profile))
|
icon:setImageClip(Spells.getImageClip(clientIconId, profile))
|
||||||
icon.event = scheduleEvent(function() icon:destroy() icon = nil end, duration)
|
|
||||||
|
|
||||||
local progressRect = g_ui.createWidget('SpellProgressRect', icon)
|
local progressRect = g_ui.createWidget('SpellProgressRect', icon)
|
||||||
|
progressRect.icon = icon
|
||||||
progressRect:fill('parent')
|
progressRect:fill('parent')
|
||||||
progressRect:setTooltip(spellName)
|
progressRect:setTooltip(spellName)
|
||||||
updateProgressRect(progressRect, duration/25, true)
|
|
||||||
|
local updateFunc = function()
|
||||||
|
updateCooldown(progressRect, duration/25)
|
||||||
|
end
|
||||||
|
local finishFunc = function()
|
||||||
|
removeCooldown(progressRect)
|
||||||
|
end
|
||||||
|
initCooldown(progressRect, updateFunc, finishFunc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function onSpellGroupCooldown(groupId, duration)
|
function onSpellGroupCooldown(groupId, duration)
|
||||||
if not SpellGroups[groupId] then return end
|
if not SpellGroups[groupId] then return end
|
||||||
|
|
||||||
local ping = g_game.getPing()
|
--local ping = g_game.getPing()
|
||||||
if ping > 0 then duration = duration - (ping/2) end
|
--if ping > 0 then duration = duration + ping end
|
||||||
|
|
||||||
local icon = contentsPanel:getChildById('groupIcon' .. SpellGroups[groupId])
|
local icon = contentsPanel:getChildById('groupIcon' .. SpellGroups[groupId])
|
||||||
local progressRect = contentsPanel:getChildById('progressRect' .. SpellGroups[groupId])
|
local progressRect = contentsPanel:getChildById('progressRect' .. SpellGroups[groupId])
|
||||||
if icon then
|
if icon then
|
||||||
icon:setOn(true)
|
icon:setOn(true)
|
||||||
removeEvent(icon.event)
|
removeEvent(icon.event)
|
||||||
icon.event = scheduleEvent(function() icon:setOn(false) end, duration)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
progressRect.icon = icon
|
||||||
if progressRect then
|
if progressRect then
|
||||||
removeEvent(progressRect.event)
|
removeEvent(progressRect.event)
|
||||||
updateProgressRect(progressRect, duration/25, true)
|
local updateFunc = function()
|
||||||
|
updateCooldown(progressRect, duration/25)
|
||||||
|
end
|
||||||
|
local finishFunc = function()
|
||||||
|
turnOffCooldown(progressRect)
|
||||||
|
end
|
||||||
|
initCooldown(progressRect, updateFunc, finishFunc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue