--正方形cd 30 * 30
|
|
NormalCirCleCdView = NormalCirCleCdView or BaseClass(BaseComponent)
|
|
local NormalCirCleCdView = NormalCirCleCdView
|
|
local math_ceil = math.ceil
|
|
local string_format = string.format
|
|
function NormalCirCleCdView:__init(handle_wnd, callback, id, width, height, font_size)
|
|
self:InitData(callback, id, width, height, font_size)
|
|
self:CreateGameObject(UIType.CircleCd)
|
|
end
|
|
function NormalCirCleCdView:InitData(callback, id, width, height, font_size)
|
|
self.callback = callback
|
|
self.id = id
|
|
self.width = width or 30
|
|
self.height = height or 30
|
|
self.font_size = font_size
|
|
end
|
|
|
|
function NormalCirCleCdView:LoadSuccess()
|
|
self.mask = self:GetChild("mask"):GetComponent("Image")
|
|
self.cdTimeText = self:GetChild("cdTimeText"):GetComponent("Text")
|
|
self:GetChild("mask").sizeDelta = Vector2(self.width,self.height)
|
|
self:InitEvent()
|
|
self:Show(0, 0, false)
|
|
end
|
|
|
|
function NormalCirCleCdView:InitEvent()
|
|
|
|
end
|
|
|
|
function NormalCirCleCdView:__defineVar()
|
|
return {
|
|
_class_type = self,
|
|
--_cid = self._id,
|
|
_iid = _in_obj_ins_id,
|
|
_use_delete_method = false,
|
|
id = nil,
|
|
width = nil,
|
|
height = nil,
|
|
font_size = nil,
|
|
callback = nil,
|
|
all_time = 0,
|
|
last_time = 0,
|
|
curr_show_time = 0,
|
|
is_public_cd = false,
|
|
is_dead = false,
|
|
is_playing = false,
|
|
is_pause = false,
|
|
show_text = false,
|
|
}
|
|
end
|
|
function NormalCirCleCdView:IsPlaying()
|
|
return self.is_playing
|
|
end
|
|
|
|
function NormalCirCleCdView:Show(all_time, last_time, show_text)
|
|
self:RemoveTimer()
|
|
self.all_time = all_time
|
|
self.last_time = last_time or 0
|
|
self.curr_show_time = 0
|
|
self.show_text = show_text
|
|
if self.all_time == 0 or self.last_time >= self.all_time then
|
|
self.cdTimeText.text = ""
|
|
self.mask.fillAmount = 0
|
|
return
|
|
end
|
|
local cur_percent = self.last_time / self.all_time
|
|
self.mask.fillAmount = 1 - cur_percent
|
|
if show_text ~= false then
|
|
local left_time = self.all_time - self.last_time - self.curr_show_time
|
|
if left_time > 1 then
|
|
self.cdTimeText.text = math_ceil(left_time)
|
|
else
|
|
self.cdTimeText.text = string_format("%.1f", left_time)
|
|
end
|
|
end
|
|
self:AddTimer()
|
|
end
|
|
|
|
|
|
function NormalCirCleCdView:AddTimer()
|
|
Runner.Instance:AddRunObj(self, 3)
|
|
self.is_playing = true
|
|
end
|
|
|
|
function NormalCirCleCdView:RemoveTimer()
|
|
Runner.Instance:RemoveRunObj(self)
|
|
self.is_playing = false
|
|
end
|
|
|
|
--暂停cd
|
|
function NormalCirCleCdView:PauseCD()
|
|
self.is_pause = true
|
|
end
|
|
|
|
function NormalCirCleCdView:ContinueCD()
|
|
self.is_pause = false
|
|
end
|
|
|
|
function NormalCirCleCdView:Update(now_time, elapse_time)
|
|
if self.is_pause then return end
|
|
self.curr_show_time = elapse_time + self.curr_show_time
|
|
local cur_percent = (self.last_time + self.curr_show_time) / self.all_time
|
|
if cur_percent >= 1 then
|
|
cur_percent = 0
|
|
self:RemoveTimer()
|
|
self.cdTimeText.text = ""
|
|
self.mask.fillAmount = 0
|
|
|
|
if self.callback then
|
|
self.callback()
|
|
end
|
|
return
|
|
end
|
|
|
|
if not self.is_base_skill then
|
|
self.mask.fillAmount = 1 - cur_percent
|
|
if self.show_text ~= false then
|
|
local left_time = self.all_time - self.last_time - self.curr_show_time
|
|
if left_time > 1 then
|
|
self.cdTimeText.text = math_.ceil(left_time)
|
|
else
|
|
self.cdTimeText.text = string_format("%.1f", left_time)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
function NormalCirCleCdView:__delete( )
|
|
self:RemoveTimer()
|
|
|
|
end
|