源战役客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

142 行
3.5 KiB

--正方形cd 30 * 30
SquareCdView = SquareCdView or BaseClass(BaseComponent)
local SquareCdView = SquareCdView
local math_ceil = math.ceil
local string_format = string.format
function SquareCdView:__init(handle_wnd, callback, id, width, height, font_size)
self:InitData(callback, id, width, height, font_size)
self:CreateGameObject(UIType.SquareCd)
end
function SquareCdView: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 SquareCdView:LoadSuccess()
self.mask = self:GetChild("mask"):GetComponent("Image")
self.cdTimeText = self:GetChild("cdTimeText"):GetComponent("Text")
SetSizeDelta(self:GetChild("mask"), self.width,self.height)
-- self:GetChild("mask").sizeDelta = Vector2(self.width,self.height)
self:InitEvent()
self:Show(0, 0, false)
end
function SquareCdView:InitEvent()
end
function SquareCdView:__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,
show_type = nil,
}
end
function SquareCdView:IsPlaying()
return self.is_playing
end
function SquareCdView:Show(all_time, last_time, show_text, show_type, fillClockwise)
self:RemoveTimer()
self.all_time = all_time
self.last_time = last_time or 0
self.curr_show_time = 0
self.show_text = show_text
self.show_type = show_type or 1
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
if self.show_type == 2 then
cur_percent = 1 - self.last_time / self.all_time
end
self.mask.fillAmount = cur_percent
if fillClockwise ~= nil then
self.mask.fillClockwise = fillClockwise
end
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 SquareCdView:AddTimer()
Runner.Instance:AddRunObj(self, 3)
self.is_playing = true
end
function SquareCdView:RemoveTimer()
Runner.Instance:RemoveRunObj(self)
self.is_playing = false
end
--暂停cd
function SquareCdView:PauseCD()
self.is_pause = true
end
function SquareCdView:ContinueCD()
self.is_pause = false
end
function SquareCdView: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 self.show_type == 2 then
cur_percent = 1 - (self.last_time + self.curr_show_time) / self.all_time
end
if cur_percent <= 0 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 = 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 SquareCdView:__delete( )
self:RemoveTimer()
end